@contember/schema-definition 1.3.0-alpha.2 → 1.3.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/actions/definition/index.d.ts +5 -0
- package/dist/src/actions/definition/index.d.ts.map +1 -0
- package/dist/src/actions/definition/index.js +26 -0
- package/dist/src/actions/definition/index.js.map +1 -0
- package/dist/src/actions/definition/internal/ActionsFactory.d.ts +11 -0
- package/dist/src/actions/definition/internal/ActionsFactory.d.ts.map +1 -0
- package/dist/src/actions/definition/internal/ActionsFactory.js +182 -0
- package/dist/src/actions/definition/internal/ActionsFactory.js.map +1 -0
- package/dist/src/actions/definition/internal/store.d.ts +11 -0
- package/dist/src/actions/definition/internal/store.d.ts.map +1 -0
- package/dist/src/actions/definition/internal/store.js +6 -0
- package/dist/src/actions/definition/internal/store.js.map +1 -0
- package/dist/src/actions/definition/targets.d.ts +10 -0
- package/dist/src/actions/definition/targets.d.ts.map +1 -0
- package/dist/src/actions/definition/targets.js +13 -0
- package/dist/src/actions/definition/targets.js.map +1 -0
- package/dist/src/actions/definition/triggers.d.ts +27 -0
- package/dist/src/actions/definition/triggers.d.ts.map +1 -0
- package/dist/src/actions/definition/triggers.js +13 -0
- package/dist/src/actions/definition/triggers.js.map +1 -0
- package/dist/src/createSchema.d.ts.map +1 -1
- package/dist/src/createSchema.js +3 -1
- package/dist/src/createSchema.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/unit/readActions.test.d.ts +2 -0
- package/dist/tests/unit/readActions.test.d.ts.map +1 -0
- package/dist/tests/unit/readActions.test.js +78 -0
- package/dist/tests/unit/readActions.test.js.map +1 -0
- package/package.json +9 -4
- package/src/actions/definition/index.ts +13 -0
- package/src/actions/definition/internal/ActionsFactory.ts +190 -0
- package/src/actions/definition/internal/store.ts +8 -0
- package/src/actions/definition/targets.ts +15 -0
- package/src/actions/definition/triggers.ts +45 -0
- package/src/createSchema.ts +3 -1
- package/src/index.ts +1 -0
- package/tests/unit/readActions.test.ts +54 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Actions } from '@contember/schema'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export class ActionsTarget {
|
|
5
|
+
constructor(
|
|
6
|
+
public readonly name: string | undefined,
|
|
7
|
+
public readonly definition: Omit<Actions.AnyTarget, 'name'>,
|
|
8
|
+
) {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const createTarget = ({
|
|
13
|
+
name,
|
|
14
|
+
...definition
|
|
15
|
+
}: Actions.AnyTarget & { name?: string }) => new ActionsTarget(name, definition)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DecoratorFunction, EntityConstructor } from '../../utils'
|
|
2
|
+
import { Actions } from '@contember/schema'
|
|
3
|
+
import { triggersStore } from './internal/store'
|
|
4
|
+
import { ActionsTarget } from './targets'
|
|
5
|
+
|
|
6
|
+
export type TriggerWebhookDefinition = {
|
|
7
|
+
webhook:
|
|
8
|
+
| string
|
|
9
|
+
| Omit<Actions.WebhookTarget, 'type'>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type TriggerTargetDefinition = {
|
|
13
|
+
target: (Omit<Actions.AnyTarget, 'name'> & { name?: string }) | ActionsTarget
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type TargetDefinition =
|
|
17
|
+
| TriggerWebhookDefinition
|
|
18
|
+
| TriggerTargetDefinition
|
|
19
|
+
|
|
20
|
+
export type BasicTriggerDefinition =
|
|
21
|
+
& {
|
|
22
|
+
readonly name: string
|
|
23
|
+
readonly create?: boolean
|
|
24
|
+
readonly delete?: boolean
|
|
25
|
+
readonly update?: boolean | readonly string[]
|
|
26
|
+
readonly selection?: Actions.SelectionNode | string
|
|
27
|
+
}
|
|
28
|
+
& TargetDefinition
|
|
29
|
+
|
|
30
|
+
export type WatchTriggerDefinition =
|
|
31
|
+
& {
|
|
32
|
+
readonly name: string
|
|
33
|
+
readonly watch: Actions.SelectionNode | string
|
|
34
|
+
readonly selection?: Actions.SelectionNode | string
|
|
35
|
+
}
|
|
36
|
+
& TargetDefinition
|
|
37
|
+
|
|
38
|
+
export const trigger = <T>(definition: BasicTriggerDefinition): DecoratorFunction<T> => (entity: EntityConstructor<T>) => {
|
|
39
|
+
triggersStore.update(entity, it => [...it, { type: 'basic', definition }])
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const watch = <T>(definition: WatchTriggerDefinition): DecoratorFunction<T> => (entity: EntityConstructor<T>) => {
|
|
43
|
+
triggersStore.update(entity, it => [...it, { type: 'watch', definition }])
|
|
44
|
+
}
|
|
45
|
+
|
package/src/createSchema.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SchemaDefinition } from './model'
|
|
2
2
|
import * as InputValidation from './validation'
|
|
3
3
|
import * as AclDefinition from './acl/definition'
|
|
4
|
+
import * as ActionsDefinition from './actions/definition'
|
|
4
5
|
import { Schema } from '@contember/schema'
|
|
5
6
|
import { emptySchema } from '@contember/schema-utils'
|
|
6
7
|
|
|
@@ -8,6 +9,7 @@ export const createSchema = (definitions: Record<string, any>, modifyCallback?:
|
|
|
8
9
|
const model = SchemaDefinition.createModel(definitions)
|
|
9
10
|
const validation = InputValidation.parseDefinition(definitions)
|
|
10
11
|
const acl = AclDefinition.createAcl(definitions, model)
|
|
11
|
-
const
|
|
12
|
+
const actions = ActionsDefinition.createActions(definitions)
|
|
13
|
+
const schema = { ...emptySchema, model, validation, acl, actions }
|
|
12
14
|
return modifyCallback ? modifyCallback(schema) : schema
|
|
13
15
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { AllowAllPermissionFactory } from '@contember/schema-utils'
|
|
|
2
2
|
export { PermissionsBuilder } from './acl/builder/PermissionsBuilder'
|
|
3
3
|
export * as InputValidation from './validation'
|
|
4
4
|
export * as AclDefinition from './acl/definition'
|
|
5
|
+
export * as ActionsDefinition from './actions/definition'
|
|
5
6
|
export * from './createSchema'
|
|
6
7
|
export * from './model'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SchemaDefinition as def, ActionsDefinition as actions } from '../../src'
|
|
2
|
+
import { Model } from '@contember/schema'
|
|
3
|
+
import { test } from 'vitest'
|
|
4
|
+
import { createActions } from '../../src/actions/definition'
|
|
5
|
+
|
|
6
|
+
namespace SimpleActions {
|
|
7
|
+
|
|
8
|
+
@actions.watch({
|
|
9
|
+
name: 'book_watch',
|
|
10
|
+
watch: `
|
|
11
|
+
title
|
|
12
|
+
tags {
|
|
13
|
+
name
|
|
14
|
+
}
|
|
15
|
+
`,
|
|
16
|
+
webhook: '%webhookUrl%/book/updated',
|
|
17
|
+
})
|
|
18
|
+
export class Book {
|
|
19
|
+
title = def.stringColumn()
|
|
20
|
+
tags = def.manyHasMany(Tag)
|
|
21
|
+
category = def.manyHasOne(Category)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Tag {
|
|
25
|
+
locales = def.oneHasMany(TagLocale, 'tag')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@def.Unique('tag', 'locale')
|
|
29
|
+
export class TagLocale {
|
|
30
|
+
tag = def.manyHasOne(Tag, 'locales')
|
|
31
|
+
name = def.stringColumn()
|
|
32
|
+
locale = def.manyHasOne(Locale)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export class Category {
|
|
37
|
+
locales = def.oneHasMany(CategoryLocale, 'category')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@def.Unique('category', 'locale')
|
|
41
|
+
export class CategoryLocale {
|
|
42
|
+
category = def.manyHasOne(Category, 'locales')
|
|
43
|
+
name = def.stringColumn()
|
|
44
|
+
locale = def.manyHasOne(Locale)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class Locale {
|
|
48
|
+
code = def.stringColumn().notNull().unique()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
test('xxx', () => {
|
|
53
|
+
createActions(SimpleActions)
|
|
54
|
+
})
|