@contember/schema 1.1.0-alpha.4 → 1.1.0-alpha.7

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.
@@ -1,24 +1,30 @@
1
1
  import Input from './input'
2
2
 
3
3
  namespace Model {
4
- export interface Entity {
5
- name: string
6
- primary: string
7
- primaryColumn: string
8
- tableName: string
9
- fields: { [name: string]: AnyField }
10
- unique: UniqueConstraints
11
- view?: View
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 interface View {
15
- sql: string
16
- dependencies?: string[]
21
+ export type EventLogConfig = {
22
+ readonly enabled: boolean
17
23
  }
18
24
 
19
25
  export type FieldType = RelationType | ColumnType
20
- export interface Field<T extends FieldType> {
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 interface ColumnTypeDefinition<T extends ColumnType = ColumnType> extends Field<T> {
45
- columnType: string
46
- typeAlias?: string
47
- nullable: boolean
48
- default?: string | number | boolean | null
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 interface Relation<T extends RelationType = RelationType> extends Field<T> {
145
- name: string
146
- type: T
147
- target: string
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 interface InverseRelation extends Relation {
151
- ownedBy: string
152
- }
164
+ export type InverseRelation =
165
+ & Relation
166
+ & {
167
+ readonly ownedBy: string
168
+ }
153
169
 
154
170
  /** @deprecated */
155
- export interface InversedRelation extends InverseRelation {}
171
+ export type InversedRelation = InverseRelation
156
172
 
157
- export interface OwningRelation extends Relation {
158
- inversedBy?: string
159
- }
173
+ export type OwningRelation =
174
+ & Relation
175
+ & {
176
+ readonly inversedBy?: string
177
+ }
160
178
 
161
179
  /** @deprecated */
162
- export interface OwnerRelation extends OwningRelation {}
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 interface JoiningColumnRelation {
176
- joiningColumn: JoiningColumn
193
+ export type JoiningColumnRelation = {
194
+ readonly joiningColumn: JoiningColumn
177
195
  }
178
196
 
179
- export interface NullableRelation {
180
- nullable: boolean
197
+ export type NullableRelation = {
198
+ readonly nullable: boolean
181
199
  }
182
200
 
183
- export interface JoiningTable {
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 interface JoiningTableRelation {
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 = { path: string[]; direction: OrderDirection }
213
+ export type OrderBy = {
214
+ readonly path: readonly string[]
215
+ readonly direction: OrderDirection
216
+ }
195
217
 
196
- export interface OrderableRelation {
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 interface Schema {
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 interface UniqueConstraints {
250
- [name: string]: UniqueConstraint
271
+ export type UniqueConstraints = {
272
+ readonly [name: string]: UniqueConstraint
251
273
  }
252
274
 
253
- export interface UniqueConstraint {
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
 
@@ -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 = { type: ArgumentType.validator; validator: Validator }
11
- export type PathArgument = { type: ArgumentType.path; path: ContextPath }
12
- export type LiteralArgument<V = any> = { type: ArgumentType.literal; value: V }
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<any>]
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 = { [N in keyof ValidatorArguments]: SpecificValidator<N> }[keyof ValidatorArguments]
47
+ export type Validator = {
48
+ readonly [N in keyof ValidatorArguments]: SpecificValidator<N>
49
+ }[keyof ValidatorArguments]
37
50
 
38
- export type Message = { text: string; parameters?: (string | number)[] }
51
+ export type Message = {
52
+ readonly text: string
53
+ readonly parameters?: readonly (string | number)[]
54
+ }
39
55
 
40
- export interface ValidationRule {
41
- validator: Validator
42
- message: Message
56
+ export type ValidationRule = {
57
+ readonly validator: Validator
58
+ readonly message: Message
43
59
  }
44
60
 
45
- export interface EntityRules {
46
- [field: string]: ValidationRule[]
61
+ export type EntityRules = {
62
+ readonly [field: string]: readonly ValidationRule[]
47
63
  }
48
64
 
49
- export interface Schema {
50
- [entity: string]: EntityRules
65
+ export type Schema = {
66
+ readonly [entity: string]: EntityRules
51
67
  }
52
68
  }
53
69
 
@@ -1,9 +1,9 @@
1
1
  namespace Value {
2
- export interface Object<E = never> {
3
- [key: string]: FieldValue<E>
2
+ export type Object<E = never> = {
3
+ readonly [key: string]: FieldValue<E>
4
4
  }
5
5
 
6
- export interface List<E = never> extends Array<FieldValue<E>> {}
6
+ export type List<E = never> = readonly FieldValue<E>[]
7
7
 
8
8
  export type PrimaryValue<E = never> = string | number | E
9
9