@contember/schema 1.1.0-alpha.3 → 1.1.0-alpha.6
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/index.d.ts +7 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/schema/acl.d.ts +59 -55
- package/dist/src/schema/acl.d.ts.map +1 -1
- package/dist/src/schema/acl.js.map +1 -1
- package/dist/src/schema/input.d.ts +30 -30
- package/dist/src/schema/input.d.ts.map +1 -1
- package/dist/src/schema/input.js.map +1 -1
- package/dist/src/schema/json.d.ts +7 -0
- package/dist/src/schema/json.d.ts.map +1 -0
- package/dist/src/schema/json.js +3 -0
- package/dist/src/schema/json.js.map +1 -0
- package/dist/src/schema/model.d.ts +83 -76
- package/dist/src/schema/model.d.ts.map +1 -1
- package/dist/src/schema/model.js.map +1 -1
- package/dist/src/schema/validation.d.ts +38 -37
- package/dist/src/schema/validation.d.ts.map +1 -1
- package/dist/src/schema/validation.js.map +1 -1
- package/dist/src/schema/value.d.ts +4 -5
- package/dist/src/schema/value.d.ts.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -3
- package/src/schema/acl.ts +53 -48
- package/src/schema/input.ts +30 -31
- package/src/schema/json.ts +4 -0
- package/src/schema/model.ts +80 -58
- package/src/schema/validation.ts +45 -29
- package/src/schema/value.ts +3 -3
package/src/schema/model.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import Input from './input'
|
|
2
2
|
|
|
3
3
|
namespace Model {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
|
|
5
|
+
export type Entity = {
|
|
6
|
+
readonly name: string
|
|
7
|
+
readonly primary: string
|
|
8
|
+
readonly primaryColumn: string
|
|
9
|
+
readonly tableName: string
|
|
10
|
+
readonly fields: { readonly [name: string]: AnyField }
|
|
11
|
+
readonly unique: UniqueConstraints
|
|
12
|
+
readonly view?: View
|
|
13
|
+
readonly eventLog: EventLogConfig
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type View = {
|
|
17
|
+
readonly sql: string
|
|
18
|
+
readonly dependencies?: readonly string[]
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
dependencies?: string[]
|
|
21
|
+
export type EventLogConfig = {
|
|
22
|
+
readonly enabled: boolean
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export type FieldType = RelationType | ColumnType
|
|
20
|
-
export
|
|
21
|
-
type: T
|
|
26
|
+
export type Field<T extends FieldType> = {
|
|
27
|
+
readonly type: T
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export type AnyField = AnyColumn | AnyRelation
|
|
@@ -37,16 +43,22 @@ namespace Model {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
export type Column<T extends ColumnType> = ColumnTypeDefinition<T> & {
|
|
40
|
-
name: string
|
|
41
|
-
columnName: string
|
|
46
|
+
readonly name: string
|
|
47
|
+
readonly columnName: string
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
export type ColumnTypeDefinition<T extends ColumnType = ColumnType> =
|
|
51
|
+
& Field<T>
|
|
52
|
+
& {
|
|
53
|
+
readonly columnType: string
|
|
54
|
+
readonly typeAlias?: string
|
|
55
|
+
readonly nullable: boolean
|
|
56
|
+
readonly default?: string | number | boolean | null
|
|
57
|
+
readonly sequence?: {
|
|
58
|
+
readonly precedence: 'ALWAYS' | 'BY DEFAULT'
|
|
59
|
+
readonly start?: number
|
|
60
|
+
}
|
|
61
|
+
}
|
|
50
62
|
|
|
51
63
|
export interface ColumnVisitor<T> {
|
|
52
64
|
visitColumn(entity: Entity, column: AnyColumn): T
|
|
@@ -141,25 +153,31 @@ namespace Model {
|
|
|
141
153
|
|
|
142
154
|
export type AnyRelation = AnyInverseRelation | AnyOwningRelation
|
|
143
155
|
|
|
144
|
-
export
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
export type Relation<T extends RelationType = RelationType>=
|
|
157
|
+
& Field<T>
|
|
158
|
+
& {
|
|
159
|
+
readonly name: string
|
|
160
|
+
readonly type: T
|
|
161
|
+
readonly target: string
|
|
162
|
+
}
|
|
149
163
|
|
|
150
|
-
export
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
export type InverseRelation =
|
|
165
|
+
& Relation
|
|
166
|
+
& {
|
|
167
|
+
readonly ownedBy: string
|
|
168
|
+
}
|
|
153
169
|
|
|
154
170
|
/** @deprecated */
|
|
155
|
-
export
|
|
171
|
+
export type InversedRelation = InverseRelation
|
|
156
172
|
|
|
157
|
-
export
|
|
158
|
-
|
|
159
|
-
|
|
173
|
+
export type OwningRelation =
|
|
174
|
+
& Relation
|
|
175
|
+
& {
|
|
176
|
+
readonly inversedBy?: string
|
|
177
|
+
}
|
|
160
178
|
|
|
161
179
|
/** @deprecated */
|
|
162
|
-
export
|
|
180
|
+
export type OwnerRelation = OwningRelation
|
|
163
181
|
|
|
164
182
|
export enum OnDelete {
|
|
165
183
|
cascade = 'cascade',
|
|
@@ -168,33 +186,37 @@ namespace Model {
|
|
|
168
186
|
}
|
|
169
187
|
|
|
170
188
|
export type JoiningColumn = {
|
|
171
|
-
columnName: string
|
|
172
|
-
onDelete: OnDelete
|
|
189
|
+
readonly columnName: string
|
|
190
|
+
readonly onDelete: OnDelete
|
|
173
191
|
}
|
|
174
192
|
|
|
175
|
-
export
|
|
176
|
-
joiningColumn: JoiningColumn
|
|
193
|
+
export type JoiningColumnRelation = {
|
|
194
|
+
readonly joiningColumn: JoiningColumn
|
|
177
195
|
}
|
|
178
196
|
|
|
179
|
-
export
|
|
180
|
-
nullable: boolean
|
|
197
|
+
export type NullableRelation = {
|
|
198
|
+
readonly nullable: boolean
|
|
181
199
|
}
|
|
182
200
|
|
|
183
|
-
export
|
|
184
|
-
tableName: string
|
|
185
|
-
joiningColumn: JoiningColumn
|
|
186
|
-
inverseJoiningColumn: JoiningColumn
|
|
201
|
+
export type JoiningTable = {
|
|
202
|
+
readonly tableName: string
|
|
203
|
+
readonly joiningColumn: JoiningColumn
|
|
204
|
+
readonly inverseJoiningColumn: JoiningColumn
|
|
205
|
+
readonly eventLog: EventLogConfig
|
|
187
206
|
}
|
|
188
207
|
|
|
189
|
-
export
|
|
190
|
-
joiningTable: JoiningTable
|
|
208
|
+
export type JoiningTableRelation = {
|
|
209
|
+
readonly joiningTable: JoiningTable
|
|
191
210
|
}
|
|
192
211
|
|
|
193
212
|
export import OrderDirection = Input.OrderDirection
|
|
194
|
-
export type OrderBy = {
|
|
213
|
+
export type OrderBy = {
|
|
214
|
+
readonly path: readonly string[]
|
|
215
|
+
readonly direction: OrderDirection
|
|
216
|
+
}
|
|
195
217
|
|
|
196
|
-
export
|
|
197
|
-
orderBy?: OrderBy[]
|
|
218
|
+
export type OrderableRelation = {
|
|
219
|
+
readonly orderBy?: readonly OrderBy[]
|
|
198
220
|
}
|
|
199
221
|
|
|
200
222
|
export type OneHasManyRelation =
|
|
@@ -221,7 +243,7 @@ namespace Model {
|
|
|
221
243
|
& JoiningColumnRelation
|
|
222
244
|
& NullableRelation
|
|
223
245
|
& {
|
|
224
|
-
orphanRemoval?: true
|
|
246
|
+
readonly orphanRemoval?: true
|
|
225
247
|
}
|
|
226
248
|
/** @deprecated */
|
|
227
249
|
export type OneHasOneOwnerRelation = OneHasOneOwningRelation
|
|
@@ -241,18 +263,18 @@ namespace Model {
|
|
|
241
263
|
/** @deprecated */
|
|
242
264
|
export type ManyHasManyOwnerRelation = ManyHasManyOwningRelation
|
|
243
265
|
|
|
244
|
-
export
|
|
245
|
-
enums: { [name: string]: string[] }
|
|
246
|
-
entities: { [name: string]: Entity }
|
|
266
|
+
export type Schema = {
|
|
267
|
+
readonly enums: { readonly [name: string]: readonly string[] }
|
|
268
|
+
readonly entities: { readonly [name: string]: Entity }
|
|
247
269
|
}
|
|
248
270
|
|
|
249
|
-
export
|
|
250
|
-
[name: string]: UniqueConstraint
|
|
271
|
+
export type UniqueConstraints = {
|
|
272
|
+
readonly [name: string]: UniqueConstraint
|
|
251
273
|
}
|
|
252
274
|
|
|
253
|
-
export
|
|
254
|
-
fields: string[]
|
|
255
|
-
name: string
|
|
275
|
+
export type UniqueConstraint = {
|
|
276
|
+
readonly fields: readonly string[]
|
|
277
|
+
readonly name: string
|
|
256
278
|
}
|
|
257
279
|
}
|
|
258
280
|
|
package/src/schema/validation.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { JSONValue } from './json'
|
|
2
|
+
|
|
1
3
|
namespace Validation {
|
|
2
|
-
export type ContextPath = string[]
|
|
4
|
+
export type ContextPath = readonly string[]
|
|
3
5
|
|
|
4
6
|
export enum ArgumentType {
|
|
5
7
|
validator = 'validator',
|
|
@@ -7,47 +9,61 @@ namespace Validation {
|
|
|
7
9
|
literal = 'literal',
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
export type ValidatorArgument = {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
export type ValidatorArgument = {
|
|
13
|
+
readonly type: ArgumentType.validator
|
|
14
|
+
readonly validator: Validator
|
|
15
|
+
}
|
|
16
|
+
export type PathArgument = {
|
|
17
|
+
readonly type: ArgumentType.path
|
|
18
|
+
readonly path: ContextPath
|
|
19
|
+
}
|
|
20
|
+
export type LiteralArgument<V = JSONValue> = {
|
|
21
|
+
readonly type: ArgumentType.literal
|
|
22
|
+
readonly value: V
|
|
23
|
+
}
|
|
13
24
|
|
|
14
25
|
export type ValidatorArguments = {
|
|
15
|
-
and: ValidatorArgument[]
|
|
16
|
-
or: ValidatorArgument[]
|
|
17
|
-
conditional: [ValidatorArgument, ValidatorArgument]
|
|
18
|
-
pattern: [LiteralArgument<[string, string]>]
|
|
19
|
-
lengthRange: [LiteralArgument<number | null>, LiteralArgument<number | null>]
|
|
20
|
-
range: [LiteralArgument<number | null>, LiteralArgument<number | null>]
|
|
21
|
-
equals: [LiteralArgument<
|
|
22
|
-
not: [ValidatorArgument]
|
|
23
|
-
empty: []
|
|
24
|
-
defined: []
|
|
25
|
-
inContext: [PathArgument, ValidatorArgument]
|
|
26
|
-
every: [ValidatorArgument]
|
|
27
|
-
any: [ValidatorArgument]
|
|
28
|
-
filter: [ValidatorArgument, ValidatorArgument]
|
|
26
|
+
readonly and: readonly ValidatorArgument[]
|
|
27
|
+
readonly or: readonly ValidatorArgument[]
|
|
28
|
+
readonly conditional: readonly [ValidatorArgument, ValidatorArgument]
|
|
29
|
+
readonly pattern: readonly [LiteralArgument<readonly [string, string]>]
|
|
30
|
+
readonly lengthRange: readonly [LiteralArgument<number | null>, LiteralArgument<number | null>]
|
|
31
|
+
readonly range: readonly [LiteralArgument<number | null>, LiteralArgument<number | null>]
|
|
32
|
+
readonly equals: readonly [LiteralArgument<JSONValue>]
|
|
33
|
+
readonly not: readonly [ValidatorArgument]
|
|
34
|
+
readonly empty: readonly[]
|
|
35
|
+
readonly defined: readonly[]
|
|
36
|
+
readonly inContext: readonly [PathArgument, ValidatorArgument]
|
|
37
|
+
readonly every: readonly [ValidatorArgument]
|
|
38
|
+
readonly any: readonly [ValidatorArgument]
|
|
39
|
+
readonly filter: readonly [ValidatorArgument, ValidatorArgument]
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
export type SpecificValidator<N extends keyof ValidatorArguments> = {
|
|
32
|
-
operation: N
|
|
33
|
-
args: ValidatorArguments[N]
|
|
43
|
+
readonly operation: N
|
|
44
|
+
readonly args: ValidatorArguments[N]
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
export type Validator = {
|
|
47
|
+
export type Validator = {
|
|
48
|
+
readonly [N in keyof ValidatorArguments]: SpecificValidator<N>
|
|
49
|
+
}[keyof ValidatorArguments]
|
|
37
50
|
|
|
38
|
-
export type Message = {
|
|
51
|
+
export type Message = {
|
|
52
|
+
readonly text: string
|
|
53
|
+
readonly parameters?: readonly (string | number)[]
|
|
54
|
+
}
|
|
39
55
|
|
|
40
|
-
export
|
|
41
|
-
validator: Validator
|
|
42
|
-
message: Message
|
|
56
|
+
export type ValidationRule = {
|
|
57
|
+
readonly validator: Validator
|
|
58
|
+
readonly message: Message
|
|
43
59
|
}
|
|
44
60
|
|
|
45
|
-
export
|
|
46
|
-
[field: string]: ValidationRule[]
|
|
61
|
+
export type EntityRules = {
|
|
62
|
+
readonly [field: string]: readonly ValidationRule[]
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
export
|
|
50
|
-
[entity: string]: EntityRules
|
|
65
|
+
export type Schema = {
|
|
66
|
+
readonly [entity: string]: EntityRules
|
|
51
67
|
}
|
|
52
68
|
}
|
|
53
69
|
|
package/src/schema/value.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
namespace Value {
|
|
2
|
-
export
|
|
3
|
-
[key: string]: FieldValue<E>
|
|
2
|
+
export type Object<E = never> = {
|
|
3
|
+
readonly [key: string]: FieldValue<E>
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type List<E = never> = readonly FieldValue<E>[]
|
|
7
7
|
|
|
8
8
|
export type PrimaryValue<E = never> = string | number | E
|
|
9
9
|
|