Skip to content

Commit 76452a2

Browse files
author
Frantz Kati
committed
Filters & Graph QL
1 parent 20c3e7f commit 76452a2

File tree

399 files changed

+18954
-1030
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

399 files changed

+18954
-1030
lines changed

.github/workflows/tests.yml

100644100755
File mode changed.

.gitignore

100644100755
File mode changed.

.prettierignore

100644100755
File mode changed.

.prettierrc

100644100755
File mode changed.

README.md

100644100755
File mode changed.

commitlint.config.js

100644100755
File mode changed.

examples/.DS_Store

100644100755
File mode changed.

examples/blog/.gitignore

100644100755
File mode changed.

examples/blog/.prettierrc

100644100755
File mode changed.

examples/blog/app.js

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('dotenv').config()
22
const { auth } = require('@tensei/auth')
33
const { graphql } = require('@tensei/graphql')
44
const { trixPlugin: trix } = require('@tensei/trix')
5-
const { cashier, plan } = require('@tensei/cashier')
5+
// const { cashier, plan } = require('@tensei/cashier')
66
const { AmazonWebServicesS3Storage } = require('@slynova/flydrive-s3')
77
const { tensei, dashboard, valueMetric, plugin } = require('@tensei/core')
88

@@ -115,4 +115,5 @@ module.exports = tensei()
115115
.databaseConfig({
116116
type: 'mysql',
117117
dbName: 'mikrotensei',
118+
debug: true
118119
})

examples/blog/index.js

100644100755
File mode changed.

examples/blog/mon.js

100644100755
File mode changed.

examples/blog/nodemon.json

100644100755
File mode changed.

examples/blog/package.json

100644100755
File mode changed.

examples/blog/resources/Comment.js

100644100755
+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
const { text, textarea, resource, belongsTo } = require('@tensei/core')
1+
const { text, textarea, resource, belongsTo, filter } = require('@tensei/core')
22

33
module.exports = resource('Comment').fields([
44
text('Title').rules('required').searchable(),
55
textarea('Body').rules('required').hideOnIndex(),
66
textarea('Reply').rules('required', 'max:255').hideOnIndex(),
77
belongsTo('Post'),
8+
]).filters([
9+
filter('Comments on Post')
10+
.dashboardView()
11+
.query((args) => ({
12+
post: {
13+
id: args.id
14+
}
15+
})),
816
])

examples/blog/resources/Post.js

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ module.exports = resource('Post')
9090
},
9191
{
9292
label: 'Mangojs',
93-
value: 'mangojs'
94-
}
93+
value: 'mangojs',
94+
},
9595
])
9696
.rules('required')
9797
.searchable()
@@ -106,7 +106,7 @@ module.exports = resource('Post')
106106
.rules('required', 'date')
107107
.format('do MMM yyyy, hh:mm a')
108108
.hideOnIndex(),
109-
belongsToMany('Tag'),
109+
belongsToMany('Tag').owner(),
110110
hasMany('Comment'),
111111
])
112112
.perPageOptions([25, 50, 100])

examples/blog/resources/Tag.js

100644100755
File mode changed.

examples/blog/resources/User.js

100644100755
File mode changed.

examples/blog/seed.js

100644100755
+68-28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const postBuilder = build('Post', {
3030
category: fake((f) =>
3131
f.random.arrayElement(['angular', 'javascript', 'mysql', 'pg'])
3232
),
33+
slug: fake((f) => `${f.lorem.slug()}-${Date.now()}`),
3334
published_at: fake((f) => f.date.past()),
3435
scheduled_for: fake((f) => f.date.future()),
3536
// created_at: fake((f) => f.date.recent(f.random.number())),
@@ -46,9 +47,9 @@ const tagsBuilder = build('Tag', {
4647

4748
const commentsBuilder = build('Comment', {
4849
fields: {
49-
post_id: sequence(),
5050
title: fake((f) => f.lorem.sentence()),
51-
body: fake((f) => f.lorem.paragraph(2)),
51+
body: fake((f) => f.lorem.sentence()),
52+
reply: fake((f) => f.lorem.sentence()),
5253
// created_at: fake((f) => f.date.recent(f.random.number())),
5354
},
5455
})
@@ -65,7 +66,7 @@ const posts = Array(1000)
6566
.fill(undefined)
6667
.map(() => postBuilder())
6768

68-
const users = Array(1000)
69+
const users = Array(10)
6970
.fill(undefined)
7071
.map(() => userBuilder())
7172

@@ -126,31 +127,70 @@ async function seedMongo(resources, connection) {
126127

127128
require('./app')
128129
.register()
129-
.then(async ({ getDatabaseClient, config }) => {
130-
if (config.database === 'mongodb') {
131-
seedMongo(config.resources, getDatabaseClient())
130+
.then(
131+
async ({
132+
config: {
133+
orm: { em },
134+
},
135+
}) => {
136+
const userObjects = users.map((user) => em.create('User', user))
137+
138+
await em.persistAndFlush(userObjects)
139+
140+
const savedUsers = await em.find('User')
141+
142+
for (let index = 0; index < savedUsers.length; index++) {
143+
const user = savedUsers[index]
144+
145+
const posts = Array(10)
146+
.fill(undefined)
147+
.map(() => em.create('Post', postBuilder()))
148+
.map((post) => {
149+
post.user = user
150+
151+
return post
152+
})
153+
154+
await em.persistAndFlush(posts)
155+
}
156+
157+
const savedPosts = await em.find('Post')
132158

159+
for (let index = 0; index < savedPosts.length; index++) {
160+
const post = savedPosts[index]
161+
162+
const comments = Array(10)
163+
.fill(undefined)
164+
.map(() => em.create('Comment', commentsBuilder()))
165+
.map((comment) => {
166+
comment.post = post
167+
168+
return comment
169+
})
170+
171+
await em.persistAndFlush(comments)
172+
}
173+
174+
// console.log(savedUsers)
133175
return
134-
}
135176

136-
const knex = getDatabaseClient()
137-
138-
await Promise.all([
139-
knex('posts').truncate(),
140-
knex('users').truncate(),
141-
knex('tags').truncate(),
142-
knex('comments').truncate(),
143-
knex('administrators').truncate(),
144-
])
145-
146-
await Promise.all([
147-
knex('posts').insert(posts),
148-
knex('users').insert(users),
149-
knex('tags').insert(tags),
150-
knex('comments').insert(comments),
151-
knex('administrators').insert(administrators),
152-
knex('posts_tags').insert(posts_tags),
153-
])
154-
155-
await knex.destroy()
156-
})
177+
await Promise.all([
178+
knex('posts').truncate(),
179+
knex('users').truncate(),
180+
knex('tags').truncate(),
181+
knex('comments').truncate(),
182+
knex('administrators').truncate(),
183+
])
184+
185+
await Promise.all([
186+
knex('posts').insert(posts),
187+
knex('users').insert(users),
188+
knex('tags').insert(tags),
189+
knex('comments').insert(comments),
190+
knex('administrators').insert(administrators),
191+
knex('posts_tags').insert(posts_tags),
192+
])
193+
194+
await knex.destroy()
195+
}
196+
)

examples/blog/suck.ts

100644100755
File mode changed.

examples/blog/tools/stripe.js

100644100755
File mode changed.

jest-client.config.js

100644100755
File mode changed.

lerna.json

100644100755
File mode changed.

package.json

100644100755
File mode changed.

packages/auth/.gitignore

100644100755
File mode changed.

packages/auth/auth.d.ts

100644100755
File mode changed.

packages/auth/package.json

100644100755
File mode changed.

packages/auth/purest.d.ts

100644100755
File mode changed.

packages/auth/src/Teams.ts

100644100755
File mode changed.

packages/auth/src/config.ts

100644100755
File mode changed.

packages/auth/src/controllers/SocialAuthCallbackController.ts

100644100755
File mode changed.

packages/auth/src/controllers/login.ts

100644100755
File mode changed.

packages/auth/src/controllers/validator.ts

100644100755
File mode changed.

packages/auth/src/index.ts

100644100755
File mode changed.

packages/auth/src/middleware/jwt.ts

100644100755
File mode changed.

packages/auth/src/setup-sql.ts

100644100755
File mode changed.

packages/auth/tsconfig.json

100644100755
File mode changed.

packages/auth/yarn-error.log

100644100755
File mode changed.

packages/cashier/package.json

100644100755
File mode changed.

packages/cashier/src/Plan.ts

100644100755
File mode changed.

packages/cashier/src/index.ts

100644100755
File mode changed.

packages/cashier/tsconfig.json

100644100755
File mode changed.

packages/client/.gitignore

100644100755
File mode changed.

packages/client/.prettierignore

100644100755
File mode changed.

packages/client/Tensei.js

100644100755
File mode changed.

packages/client/__tests__/components/ArrowIcon.spec.js

100644100755
File mode changed.

packages/client/__tests__/components/ResourceTable.spec.js

100644100755
File mode changed.

packages/client/__tests__/fields/AllFields.spec.js

100644100755
File mode changed.

packages/client/__tests__/fields/__snapshots__/AllFields.spec.js.snap

100644100755
File mode changed.

packages/client/__tests__/pages/CreateResource.spec.js

100644100755
File mode changed.

packages/client/__tests__/pages/Dashboard.spec.js

100644100755
File mode changed.

packages/client/__tests__/pages/Login.spec.js

100644100755
File mode changed.

packages/client/__tests__/pages/ResourceIndex.spec.js

100644100755
File mode changed.

packages/client/__tests__/pages/__snapshots__/CreateResource.spec.js.snap

100644100755
File mode changed.

packages/client/__tests__/pages/__snapshots__/Dashboard.spec.js.snap

100644100755
File mode changed.

packages/client/__tests__/pages/__snapshots__/Login.spec.js.snap

100644100755
File mode changed.

packages/client/__tests__/pages/__snapshots__/ResourceIndex.spec.js.snap

100644100755
File mode changed.

packages/client/babel.config.js

100644100755
File mode changed.

packages/client/cards/ValueMetric.js

100644100755
File mode changed.

packages/client/components/ActionsDropdown/ActionsDropdown.js

100644100755
File mode changed.

packages/client/components/ActionsDropdown/index.js

100644100755
File mode changed.

packages/client/components/ArrowIcon/ArrowIcon.js

100644100755
File mode changed.

packages/client/components/ArrowIcon/index.js

100644100755
File mode changed.

packages/client/components/Autocomplete/Autocomplete.js

100644100755
File mode changed.

packages/client/components/Autocomplete/index.js

100644100755
File mode changed.

packages/client/components/Filter/Filter.js

100644100755
File mode changed.

packages/client/components/Filter/index.js

100644100755
File mode changed.

packages/client/components/Filters/Filters.js

100644100755
File mode changed.

packages/client/components/Filters/index.js

100644100755
File mode changed.

packages/client/components/Icon/Icon.js

100644100755
File mode changed.

packages/client/components/Icon/index.js

100644100755
File mode changed.

packages/client/components/IndexSettings/IndexSettings.js

100644100755
File mode changed.

packages/client/components/IndexSettings/index.js

100644100755
File mode changed.

packages/client/components/PageLayout/PageLayout.js

100644100755
File mode changed.

packages/client/components/PageLayout/index.js

100644100755
File mode changed.

packages/client/components/PageTitle/PageTitle.js

100644100755
File mode changed.

packages/client/components/PageTitle/index.js

100644100755
File mode changed.

packages/client/components/ResourceTable/ResourceTable.js

100644100755
File mode changed.

packages/client/components/ResourceTable/index.js

100644100755
File mode changed.

packages/client/components/Wrapper/Wrapper.js

100644100755
File mode changed.

packages/client/components/Wrapper/index.js

100644100755
File mode changed.

packages/client/css/flatpickr.css

100644100755
File mode changed.

packages/client/css/index.css

100644100755
File mode changed.

packages/client/detail-fields/BelongsToField.js

100644100755
File mode changed.

packages/client/detail-fields/BelongsToManyField.js

100644100755
File mode changed.

packages/client/detail-fields/HasManyField.js

100644100755
File mode changed.

packages/client/detail-fields/TextareaField.js

100644100755
File mode changed.

packages/client/fields/BelongsTo.js

100644100755
File mode changed.

packages/client/fields/BelongsToMany.js

100644100755
File mode changed.

packages/client/fields/Boolean.js

100644100755
File mode changed.

packages/client/fields/DateTime.js

100644100755
File mode changed.

packages/client/fields/HasMany.js

100644100755
File mode changed.

packages/client/fields/Select.js

100644100755
File mode changed.

packages/client/fields/Text.js

100644100755
File mode changed.

packages/client/fields/Textarea.js

100644100755
File mode changed.

packages/client/helpers/axios.js

100644100755
File mode changed.

packages/client/index-fields/Boolean.js

100644100755
File mode changed.

packages/client/index-fields/Date.js

100644100755
File mode changed.

packages/client/index-fields/ID.js

100644100755
File mode changed.

packages/client/index-fields/Link.js

100644100755
File mode changed.

packages/client/index-fields/Text.js

100644100755
File mode changed.

packages/client/index.js

100644100755
File mode changed.

packages/client/jest.config.js

100644100755
File mode changed.

packages/client/jsconfig.json

100644100755
File mode changed.

packages/client/package.json

100644100755
File mode changed.

packages/client/pages/CreateResource/CreateResource.js

100644100755
File mode changed.

packages/client/pages/CreateResource/index.js

100644100755
File mode changed.

packages/client/pages/Dashboard/Dashboard.js

100644100755
File mode changed.

packages/client/pages/Dashboard/index.js

100644100755
File mode changed.

packages/client/pages/DashboardIndex/DashboardIndex.js

100644100755
File mode changed.

packages/client/pages/DashboardIndex/index.js

100644100755
File mode changed.

packages/client/pages/ForgotPassword/ForgotPassword.js

100644100755
File mode changed.

packages/client/pages/ForgotPassword/index.js

100644100755
File mode changed.

packages/client/pages/Login/Login.js

100644100755
File mode changed.

packages/client/pages/Login/index.js

100644100755
File mode changed.

packages/client/pages/Register/Register.js

100644100755
File mode changed.

packages/client/pages/Register/index.js

100644100755
File mode changed.

packages/client/pages/ResetPassword/ResetPassword.js

100644100755
File mode changed.

packages/client/pages/ResetPassword/index.js

100644100755
File mode changed.

packages/client/pages/ResourceIndex/ResourceIndex.js

100644100755
File mode changed.

packages/client/pages/ResourceIndex/index.js

100644100755
File mode changed.

packages/client/pages/ShowResource/ShowResource.js

100644100755
File mode changed.

packages/client/pages/ShowResource/index.js

100644100755
File mode changed.

packages/client/store/auth.js

100644100755
File mode changed.

packages/client/store/pages.js

100644100755
File mode changed.

packages/client/store/resources.js

100644100755
File mode changed.

packages/client/tailwind.config.js

100644100755
File mode changed.

packages/client/testSetup/Tensei.js

100644100755
File mode changed.

packages/client/testSetup/data.js

100644100755
File mode changed.

packages/client/testSetup/setupPage.js

100644100755
File mode changed.

packages/client/webpack.mix.js

100644100755
File mode changed.

packages/common/.gitignore

100644100755
File mode changed.

packages/common/.prettierignore

100644100755
File mode changed.

packages/common/babel.config.js

100644100755
File mode changed.

packages/common/jest.config.js

100644100755
File mode changed.

packages/common/package.json

100644100755
File mode changed.

packages/common/src/actions/Action.ts

100644100755
File mode changed.

packages/common/src/dashboard/Card.ts

100644100755
File mode changed.

packages/common/src/dashboard/Dashboard.ts

100644100755
File mode changed.

packages/common/src/fields/Array.ts

100644100755
File mode changed.

packages/common/src/fields/BigInteger.ts

100644100755
File mode changed.

packages/common/src/fields/Boolean.ts

100644100755
File mode changed.

packages/common/src/fields/Date.ts

100644100755
File mode changed.

packages/common/src/fields/DateTime.ts

100644100755
File mode changed.

packages/common/src/fields/Field.ts

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Field implements FieldContract {
4949
public property: FieldProperty = {
5050
name: '',
5151
type: 'string',
52-
primary: false,
52+
primary: false
5353
// nullable: true
5454
}
5555

packages/common/src/fields/HasManyEmbedded.ts

100644100755
File mode changed.

packages/common/src/fields/HasOne.ts

100644100755
File mode changed.

packages/common/src/fields/ID.ts

100644100755
File mode changed.

packages/common/src/fields/Integer.ts

100644100755
File mode changed.

packages/common/src/fields/Json.ts

100644100755
File mode changed.

packages/common/src/fields/Link.ts

100644100755
File mode changed.

packages/common/src/fields/ManyToMany.ts

100644100755
File mode changed.

packages/common/src/fields/ManyToOne.ts

100644100755
File mode changed.

packages/common/src/fields/Number.ts

100644100755
File mode changed.

packages/common/src/fields/OneToMany.ts

100644100755
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { pascalCase, camelCase } from 'change-case'
1+
import Pluralize from 'pluralize'
22
import { ReferenceType } from '@mikro-orm/core'
3+
import { pascalCase, camelCase } from 'change-case'
34
import RelationshipField from './RelationshipField'
45

56
// This would be hasMany in other relationship language.
67
export class OneToMany extends RelationshipField {
78
public component = 'OneToManyField'
89

9-
public constructor(name: string, databaseField = camelCase(name)) {
10+
public constructor(
11+
name: string,
12+
databaseField = Pluralize(camelCase(name))
13+
) {
1014
super(name, databaseField)
1115

1216
this.relatedProperty.type = pascalCase(name)
@@ -16,6 +20,7 @@ export class OneToMany extends RelationshipField {
1620

1721
export const oneToMany = (name: string, databaseField?: string) =>
1822
new OneToMany(name, databaseField)
23+
1924
export const hasMany = oneToMany
2025

2126
export default oneToMany

packages/common/src/fields/OneToOne.ts

100644100755
File mode changed.

packages/common/src/fields/Password.ts

100644100755
File mode changed.

packages/common/src/fields/RelationshipField.ts

100644100755
File mode changed.

packages/common/src/fields/Select.ts

100644100755
File mode changed.

packages/common/src/fields/Text.ts

100644100755
File mode changed.

packages/common/src/fields/Textarea.ts

100644100755
File mode changed.

packages/common/src/fields/Timestamp.ts

100644100755
File mode changed.

packages/common/src/filters/Filter.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { camelCase } from 'change-case'
2+
import { FilterQuery, Dictionary } from '@mikro-orm/core'
3+
import { FilterCondition, FilterConfig, FilterContract } from '@tensei/common/filters'
4+
5+
export class Filter<T = any> implements FilterContract {
6+
public config: FilterConfig<T> = {
7+
name: '',
8+
shortName: '',
9+
default: false,
10+
dashboardView: false,
11+
cond: () => ({})
12+
}
13+
14+
constructor(name: string, shortName = camelCase(name)) {
15+
this.config.name = name
16+
this.config.shortName = shortName
17+
}
18+
19+
query(condition: FilterCondition<T>) {
20+
this.config.cond = condition
21+
22+
return this
23+
}
24+
25+
dashboardView() {
26+
this.config.dashboardView = true
27+
28+
return this
29+
}
30+
31+
noArgs() {
32+
this.config.args = false
33+
34+
return this
35+
}
36+
37+
default() {
38+
this.config.default = true
39+
40+
return this
41+
}
42+
}
43+
44+
export function filter<T = any>(name: string, shortName?: string) {
45+
return new Filter<T>(
46+
name,
47+
shortName
48+
)
49+
}

packages/common/src/helpers/index.ts

100644100755
File mode changed.

packages/common/src/index.ts

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export { oneToMany, OneToMany, hasMany } from './fields/OneToMany'
2020
export { manyToOne, ManyToOne, belongsTo } from './fields/ManyToOne'
2121
export { manyToMany, ManyToMany, belongsToMany } from './fields/ManyToMany'
2222

23+
export { filter } from './filters/Filter'
24+
2325
export { ResourceHelpers } from './helpers'
2426
export { Manager } from './resources/Manager'
2527
export { card, Card } from './dashboard/Card'

packages/common/src/metrics/Value.ts

100644100755
File mode changed.

packages/common/src/metrics/ValueMetricResult.ts

100644100755
File mode changed.

packages/common/src/plugins/Plugin.ts

100644100755
File mode changed.

packages/common/src/resources/Manager.ts

100644100755
File mode changed.

packages/common/src/resources/Resource.ts

100644100755
+11-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import {
55
ResourceData,
66
HookFunction,
77
FieldContract,
8+
FilterContract,
89
ResourceContract,
910
AuthorizeFunction,
1011
ValidationMessages,
11-
SerializedResource
12+
SerializedResource,
1213
} from '@tensei/common'
1314

1415
import Pluralize from 'pluralize'
16+
// import { FilterContract } from '@tensei/filters'
1517
import { snakeCase, paramCase, camelCase, pascalCase } from 'change-case'
1618

1719
interface ResourceDataWithFields extends ResourceData {
@@ -81,21 +83,28 @@ export class Resource<ResourceType = {}> implements ResourceContract {
8183
this.data.camelCaseName = camelCase(name)
8284
this.data.pascalCaseName = pascalCase(name)
8385
this.data.slug = Pluralize(paramCase(name))
84-
this.data.camelCaseNamePlural = Pluralize(camelCase(name))
8586
this.data.table = tableName || Pluralize(snakeCase(name))
87+
this.data.camelCaseNamePlural = Pluralize(camelCase(name))
8688
}
8789

8890
public Model = (): any => {
8991
return null
9092
}
9193

94+
public filters(filters: FilterContract[]) {
95+
this.data.filters = filters
96+
97+
return this
98+
}
99+
92100
public data: ResourceDataWithFields = {
93101
fields: [],
94102
actions: [],
95103
table: '',
96104
name: '',
97105
slug: '',
98106
label: '',
107+
filters: [],
99108
hideFromApi: false,
100109
permissions: [],
101110
group: 'Resources',

packages/common/tsconfig.json

100644100755
File mode changed.

packages/common/typings/actions.d.ts

100644100755
File mode changed.

packages/common/typings/common.d.ts

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ declare module '@tensei/common' {
44
export * from '@tensei/common/actions'
55
export * from '@tensei/common/resources'
66
export * from '@tensei/common/plugins'
7+
export * from '@tensei/common/filters'
78
export * from '@tensei/common/dashboards'
89
}

packages/common/typings/config.d.ts

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ declare module '@tensei/common/config' {
111111
}
112112
export interface Config {
113113
databaseClient: any
114+
schemas: any
114115
serverUrl: string
115116
clientUrl: string
116117
plugins: PluginContract[]

packages/common/typings/dashboards.d.ts

100644100755
File mode changed.

packages/common/typings/express.d.ts

100644100755
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Request } from 'express'
22
import { Mail } from '@tensei/mail'
3+
import { MikroORM, EntityManager } from '@mikro-orm/core'
34
import { StorageManager } from '@slynova/flydrive'
45
import {
56
User,
@@ -13,10 +14,6 @@ import {
1314
declare global {
1415
namespace Express {
1516
export interface Request {
16-
manager: (
17-
resourceSlugOrResource: string | ResourceContract,
18-
request?: Request
19-
) => ManagerContract
2017
resources: {
2118
[key: string]: ResourceContract
2219
}
@@ -26,6 +23,8 @@ declare global {
2623
mailer: Mail
2724
config: Config
2825
admin?: User
26+
orm: MikroORM
27+
manager: EntityManager
2928
scripts: Asset[]
3029
styles: Asset[]
3130
originatedFromDashboard: boolean | undefined

packages/common/typings/fields.d.ts

100644100755
File mode changed.

packages/common/typings/filters.d.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
declare module '@tensei/common/filters' {
2+
import { FilterQuery, Dictionary } from '@mikro-orm/core';
3+
4+
interface FilterConfig<T> {
5+
name: string;
6+
shortName: string;
7+
args?: boolean;
8+
default: boolean;
9+
dashboardView?: boolean;
10+
cond: FilterCondition<T>;
11+
}
12+
13+
type FilterCondition<T = any> = (args: Dictionary, type: 'read' | 'update' | 'delete') => FilterQuery<any> | Promise<FilterQuery<T>>;
14+
15+
export interface FilterContract<T = any> {
16+
config: FilterConfig<T>;
17+
query(condition: FilterCondition<T>): this;
18+
dashboardView(): this;
19+
noArgs(): this;
20+
default(): this;
21+
}
22+
23+
export function filter<T = any>(name: string, slug?: string): FilterContract<T>;
24+
}

packages/common/typings/index.d.ts

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// <reference path="fields.d.ts" />
55
/// <reference path="resources.d.ts" />
66
/// <reference path="common.d.ts" />
7+
/// <reference path="filters.d.ts" />
78
/// <reference path="express.d.ts" />
89
/// <reference path="tensei.d.ts" />
910
/// <reference path="dashboards.d.ts" />

0 commit comments

Comments
 (0)