@contember/client-content-generator 2.0.0-alpha.2 → 2.0.0-alpha.20
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/api-extractor.json +3 -0
- package/dist/development/generate.cjs +1 -2
- package/dist/development/generate.cjs.map +1 -1
- package/dist/development/generate.js +1 -2
- package/dist/development/generate.js.map +1 -1
- package/dist/development/index.cjs +4 -4
- package/dist/development/index.js +4 -4
- package/dist/development/src/ContemberClientGenerator.cjs.map +1 -0
- package/dist/development/src/ContemberClientGenerator.js.map +1 -0
- package/dist/development/{EntityTypeSchemaGenerator.cjs → src/EntityTypeSchemaGenerator.cjs} +3 -2
- package/dist/development/src/EntityTypeSchemaGenerator.cjs.map +1 -0
- package/dist/development/{EntityTypeSchemaGenerator.js → src/EntityTypeSchemaGenerator.js} +3 -2
- package/dist/development/src/EntityTypeSchemaGenerator.js.map +1 -0
- package/dist/development/{EnumTypeSchemaGenerator.cjs → src/EnumTypeSchemaGenerator.cjs} +2 -1
- package/dist/development/src/EnumTypeSchemaGenerator.cjs.map +1 -0
- package/dist/development/{EnumTypeSchemaGenerator.js → src/EnumTypeSchemaGenerator.js} +2 -1
- package/dist/development/src/EnumTypeSchemaGenerator.js.map +1 -0
- package/dist/development/src/NameSchemaGenerator.cjs.map +1 -0
- package/dist/development/src/NameSchemaGenerator.js.map +1 -0
- package/dist/development/src/utils.cjs +6 -0
- package/dist/development/src/utils.cjs.map +1 -0
- package/dist/development/src/utils.js +6 -0
- package/dist/development/src/utils.js.map +1 -0
- package/dist/production/generate.cjs +1 -2
- package/dist/production/generate.cjs.map +1 -1
- package/dist/production/generate.js +1 -2
- package/dist/production/generate.js.map +1 -1
- package/dist/production/index.cjs +4 -4
- package/dist/production/index.js +4 -4
- package/dist/production/src/ContemberClientGenerator.cjs.map +1 -0
- package/dist/production/src/ContemberClientGenerator.js.map +1 -0
- package/dist/production/{EntityTypeSchemaGenerator.cjs → src/EntityTypeSchemaGenerator.cjs} +3 -2
- package/dist/production/src/EntityTypeSchemaGenerator.cjs.map +1 -0
- package/dist/production/{EntityTypeSchemaGenerator.js → src/EntityTypeSchemaGenerator.js} +3 -2
- package/dist/production/src/EntityTypeSchemaGenerator.js.map +1 -0
- package/dist/production/{EnumTypeSchemaGenerator.cjs → src/EnumTypeSchemaGenerator.cjs} +2 -1
- package/dist/production/src/EnumTypeSchemaGenerator.cjs.map +1 -0
- package/dist/production/{EnumTypeSchemaGenerator.js → src/EnumTypeSchemaGenerator.js} +2 -1
- package/dist/production/src/EnumTypeSchemaGenerator.js.map +1 -0
- package/dist/production/src/NameSchemaGenerator.cjs.map +1 -0
- package/dist/production/src/NameSchemaGenerator.js.map +1 -0
- package/dist/production/src/utils.cjs +6 -0
- package/dist/production/src/utils.cjs.map +1 -0
- package/dist/production/src/utils.js +6 -0
- package/dist/production/src/utils.js.map +1 -0
- package/dist/types/EntityTypeSchemaGenerator.d.ts.map +1 -1
- package/dist/types/EnumTypeSchemaGenerator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +11 -17
- package/src/EntityTypeSchemaGenerator.ts +4 -2
- package/src/EnumTypeSchemaGenerator.ts +2 -1
- package/src/tsconfig.json +3 -1
- package/src/utils.ts +3 -0
- package/tests/generateEnittyTypes.test.ts +303 -0
- package/tests/generateEnumTypes.test.ts +23 -0
- package/tests/schemas.ts +73 -0
- package/tests/tsconfig.json +11 -0
- package/tsconfig.json +8 -0
- package/tsdoc.json +6 -0
- package/vitest.config.ts +3 -0
- package/dist/development/ContemberClientGenerator.cjs.map +0 -1
- package/dist/development/ContemberClientGenerator.js.map +0 -1
- package/dist/development/EntityTypeSchemaGenerator.cjs.map +0 -1
- package/dist/development/EntityTypeSchemaGenerator.js.map +0 -1
- package/dist/development/EnumTypeSchemaGenerator.cjs.map +0 -1
- package/dist/development/EnumTypeSchemaGenerator.js.map +0 -1
- package/dist/development/NameSchemaGenerator.cjs.map +0 -1
- package/dist/development/NameSchemaGenerator.js.map +0 -1
- package/dist/production/ContemberClientGenerator.cjs.map +0 -1
- package/dist/production/ContemberClientGenerator.js.map +0 -1
- package/dist/production/EntityTypeSchemaGenerator.cjs.map +0 -1
- package/dist/production/EntityTypeSchemaGenerator.js.map +0 -1
- package/dist/production/EnumTypeSchemaGenerator.cjs.map +0 -1
- package/dist/production/EnumTypeSchemaGenerator.js.map +0 -1
- package/dist/production/NameSchemaGenerator.cjs.map +0 -1
- package/dist/production/NameSchemaGenerator.js.map +0 -1
- /package/dist/development/{ContemberClientGenerator.cjs → src/ContemberClientGenerator.cjs} +0 -0
- /package/dist/development/{ContemberClientGenerator.js → src/ContemberClientGenerator.js} +0 -0
- /package/dist/development/{NameSchemaGenerator.cjs → src/NameSchemaGenerator.cjs} +0 -0
- /package/dist/development/{NameSchemaGenerator.js → src/NameSchemaGenerator.js} +0 -0
- /package/dist/production/{ContemberClientGenerator.cjs → src/ContemberClientGenerator.cjs} +0 -0
- /package/dist/production/{ContemberClientGenerator.js → src/ContemberClientGenerator.js} +0 -0
- /package/dist/production/{NameSchemaGenerator.cjs → src/NameSchemaGenerator.cjs} +0 -0
- /package/dist/production/{NameSchemaGenerator.js → src/NameSchemaGenerator.js} +0 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import { EntityTypeSchemaGenerator } from '../src'
|
|
3
|
+
import { schemas } from './schemas'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('generate entities', () => {
|
|
7
|
+
|
|
8
|
+
const entityGenerator = new EntityTypeSchemaGenerator()
|
|
9
|
+
test('generate for scalars', () => {
|
|
10
|
+
|
|
11
|
+
expect(entityGenerator.generate(schemas.scalarsSchema.model)).toMatchInlineSnapshot(`
|
|
12
|
+
"
|
|
13
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
14
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
15
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
16
|
+
export type JSONArray = readonly JSONValue[]
|
|
17
|
+
|
|
18
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
19
|
+
name: 'Foo'
|
|
20
|
+
unique:
|
|
21
|
+
| Omit<{ id: string}, OverRelation>
|
|
22
|
+
columns: {
|
|
23
|
+
id: string
|
|
24
|
+
stringCol: string | null
|
|
25
|
+
intCol: number | null
|
|
26
|
+
doubleCol: number | null
|
|
27
|
+
dateCol: string | null
|
|
28
|
+
datetimeCol: string | null
|
|
29
|
+
booleanCol: boolean | null
|
|
30
|
+
jsonCol: JSONValue | null
|
|
31
|
+
uuidCol: string | null
|
|
32
|
+
}
|
|
33
|
+
hasOne: {
|
|
34
|
+
}
|
|
35
|
+
hasMany: {
|
|
36
|
+
}
|
|
37
|
+
hasManyBy: {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ContemberClientEntities = {
|
|
42
|
+
Foo: Foo
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type ContemberClientSchema = {
|
|
46
|
+
entities: ContemberClientEntities
|
|
47
|
+
}
|
|
48
|
+
"
|
|
49
|
+
`)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('generate for has enum', () => {
|
|
53
|
+
|
|
54
|
+
expect(entityGenerator.generate(schemas.enumSchema.model)).toMatchInlineSnapshot(`
|
|
55
|
+
"import type { FooEnumCol } from './enums'
|
|
56
|
+
|
|
57
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
58
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
59
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
60
|
+
export type JSONArray = readonly JSONValue[]
|
|
61
|
+
|
|
62
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
63
|
+
name: 'Foo'
|
|
64
|
+
unique:
|
|
65
|
+
| Omit<{ id: string}, OverRelation>
|
|
66
|
+
columns: {
|
|
67
|
+
id: string
|
|
68
|
+
enumCol: FooEnumCol | null
|
|
69
|
+
}
|
|
70
|
+
hasOne: {
|
|
71
|
+
}
|
|
72
|
+
hasMany: {
|
|
73
|
+
}
|
|
74
|
+
hasManyBy: {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type ContemberClientEntities = {
|
|
79
|
+
Foo: Foo
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type ContemberClientSchema = {
|
|
83
|
+
entities: ContemberClientEntities
|
|
84
|
+
}
|
|
85
|
+
"
|
|
86
|
+
`)
|
|
87
|
+
})
|
|
88
|
+
test('generate one has one', () => {
|
|
89
|
+
|
|
90
|
+
expect(entityGenerator.generate(schemas.oneHasOneSchema.model)).toMatchInlineSnapshot(`
|
|
91
|
+
"
|
|
92
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
93
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
94
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
95
|
+
export type JSONArray = readonly JSONValue[]
|
|
96
|
+
|
|
97
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
98
|
+
name: 'Foo'
|
|
99
|
+
unique:
|
|
100
|
+
| Omit<{ id: string}, OverRelation>
|
|
101
|
+
| Omit<{ oneHasOneInverseRel: Bar['unique']}, OverRelation>
|
|
102
|
+
columns: {
|
|
103
|
+
id: string
|
|
104
|
+
}
|
|
105
|
+
hasOne: {
|
|
106
|
+
oneHasOneInverseRel: Bar
|
|
107
|
+
}
|
|
108
|
+
hasMany: {
|
|
109
|
+
}
|
|
110
|
+
hasManyBy: {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
114
|
+
name: 'Bar'
|
|
115
|
+
unique:
|
|
116
|
+
| Omit<{ id: string}, OverRelation>
|
|
117
|
+
| Omit<{ oneHasOneOwningRel: Foo['unique']}, OverRelation>
|
|
118
|
+
columns: {
|
|
119
|
+
id: string
|
|
120
|
+
}
|
|
121
|
+
hasOne: {
|
|
122
|
+
oneHasOneOwningRel: Foo
|
|
123
|
+
}
|
|
124
|
+
hasMany: {
|
|
125
|
+
}
|
|
126
|
+
hasManyBy: {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type ContemberClientEntities = {
|
|
131
|
+
Foo: Foo
|
|
132
|
+
Bar: Bar
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type ContemberClientSchema = {
|
|
136
|
+
entities: ContemberClientEntities
|
|
137
|
+
}
|
|
138
|
+
"
|
|
139
|
+
`)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('generate one has many', () => {
|
|
143
|
+
|
|
144
|
+
expect(entityGenerator.generate(schemas.oneHasManySchema.model)).toMatchInlineSnapshot(`
|
|
145
|
+
"
|
|
146
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
147
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
148
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
149
|
+
export type JSONArray = readonly JSONValue[]
|
|
150
|
+
|
|
151
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
152
|
+
name: 'Foo'
|
|
153
|
+
unique:
|
|
154
|
+
| Omit<{ id: string}, OverRelation>
|
|
155
|
+
| Omit<{ oneHasManyRel: Bar['unique']}, OverRelation>
|
|
156
|
+
columns: {
|
|
157
|
+
id: string
|
|
158
|
+
}
|
|
159
|
+
hasOne: {
|
|
160
|
+
}
|
|
161
|
+
hasMany: {
|
|
162
|
+
oneHasManyRel: Bar<'manyHasOneRel'>
|
|
163
|
+
}
|
|
164
|
+
hasManyBy: {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
168
|
+
name: 'Bar'
|
|
169
|
+
unique:
|
|
170
|
+
| Omit<{ id: string}, OverRelation>
|
|
171
|
+
columns: {
|
|
172
|
+
id: string
|
|
173
|
+
}
|
|
174
|
+
hasOne: {
|
|
175
|
+
manyHasOneRel: Foo
|
|
176
|
+
}
|
|
177
|
+
hasMany: {
|
|
178
|
+
}
|
|
179
|
+
hasManyBy: {
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type ContemberClientEntities = {
|
|
184
|
+
Foo: Foo
|
|
185
|
+
Bar: Bar
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type ContemberClientSchema = {
|
|
189
|
+
entities: ContemberClientEntities
|
|
190
|
+
}
|
|
191
|
+
"
|
|
192
|
+
`)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('generate many has many', () => {
|
|
196
|
+
|
|
197
|
+
expect(entityGenerator.generate(schemas.manyHasManySchema.model)).toMatchInlineSnapshot(`
|
|
198
|
+
"
|
|
199
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
200
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
201
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
202
|
+
export type JSONArray = readonly JSONValue[]
|
|
203
|
+
|
|
204
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
205
|
+
name: 'Foo'
|
|
206
|
+
unique:
|
|
207
|
+
| Omit<{ id: string}, OverRelation>
|
|
208
|
+
columns: {
|
|
209
|
+
id: string
|
|
210
|
+
}
|
|
211
|
+
hasOne: {
|
|
212
|
+
}
|
|
213
|
+
hasMany: {
|
|
214
|
+
manyHasManyRel: Bar
|
|
215
|
+
}
|
|
216
|
+
hasManyBy: {
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
220
|
+
name: 'Bar'
|
|
221
|
+
unique:
|
|
222
|
+
| Omit<{ id: string}, OverRelation>
|
|
223
|
+
columns: {
|
|
224
|
+
id: string
|
|
225
|
+
}
|
|
226
|
+
hasOne: {
|
|
227
|
+
}
|
|
228
|
+
hasMany: {
|
|
229
|
+
manyHasManyInverseRel: Foo
|
|
230
|
+
}
|
|
231
|
+
hasManyBy: {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export type ContemberClientEntities = {
|
|
236
|
+
Foo: Foo
|
|
237
|
+
Bar: Bar
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export type ContemberClientSchema = {
|
|
241
|
+
entities: ContemberClientEntities
|
|
242
|
+
}
|
|
243
|
+
"
|
|
244
|
+
`)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
test('generate reduced has by', () => {
|
|
248
|
+
|
|
249
|
+
expect(entityGenerator.generate(schemas.reducedHasManySchema.model)).toMatchInlineSnapshot(`
|
|
250
|
+
"
|
|
251
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
252
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
253
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
254
|
+
export type JSONArray = readonly JSONValue[]
|
|
255
|
+
|
|
256
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
257
|
+
name: 'Foo'
|
|
258
|
+
unique:
|
|
259
|
+
| Omit<{ id: string}, OverRelation>
|
|
260
|
+
| Omit<{ locales: FooLocale['unique']}, OverRelation>
|
|
261
|
+
columns: {
|
|
262
|
+
id: string
|
|
263
|
+
}
|
|
264
|
+
hasOne: {
|
|
265
|
+
}
|
|
266
|
+
hasMany: {
|
|
267
|
+
locales: FooLocale<'foo'>
|
|
268
|
+
}
|
|
269
|
+
hasManyBy: {
|
|
270
|
+
localesByLocale: { entity: FooLocale; by: {locale: string} }
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
export type FooLocale <OverRelation extends string | never = never> = {
|
|
274
|
+
name: 'FooLocale'
|
|
275
|
+
unique:
|
|
276
|
+
| Omit<{ id: string}, OverRelation>
|
|
277
|
+
| Omit<{ locale: string, foo: Foo['unique']}, OverRelation>
|
|
278
|
+
columns: {
|
|
279
|
+
id: string
|
|
280
|
+
locale: string
|
|
281
|
+
}
|
|
282
|
+
hasOne: {
|
|
283
|
+
foo: Foo
|
|
284
|
+
}
|
|
285
|
+
hasMany: {
|
|
286
|
+
}
|
|
287
|
+
hasManyBy: {
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export type ContemberClientEntities = {
|
|
292
|
+
Foo: Foo
|
|
293
|
+
FooLocale: FooLocale
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export type ContemberClientSchema = {
|
|
297
|
+
entities: ContemberClientEntities
|
|
298
|
+
}
|
|
299
|
+
"
|
|
300
|
+
`)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import { EnumTypeSchemaGenerator } from '../src'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
test('generate enums', () => {
|
|
6
|
+
const enumGenerator = new EnumTypeSchemaGenerator()
|
|
7
|
+
expect(enumGenerator.generate({
|
|
8
|
+
entities: {},
|
|
9
|
+
enums: {
|
|
10
|
+
OrderStatus: ['new', 'paid', 'cancelled'],
|
|
11
|
+
orderType: ['normal', 'express'],
|
|
12
|
+
},
|
|
13
|
+
})).toMatchInlineSnapshot(`
|
|
14
|
+
"export type OrderStatus =
|
|
15
|
+
| "new"
|
|
16
|
+
| "paid"
|
|
17
|
+
| "cancelled"
|
|
18
|
+
export type OrderType =
|
|
19
|
+
| "normal"
|
|
20
|
+
| "express"
|
|
21
|
+
"
|
|
22
|
+
`)
|
|
23
|
+
})
|
package/tests/schemas.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SchemaDefinition as def, createSchema } from '@contember/schema-definition'
|
|
2
|
+
|
|
3
|
+
namespace ManyScalarsSchema {
|
|
4
|
+
export class Foo {
|
|
5
|
+
stringCol = def.stringColumn()
|
|
6
|
+
intCol = def.intColumn()
|
|
7
|
+
doubleCol = def.doubleColumn()
|
|
8
|
+
dateCol = def.dateColumn()
|
|
9
|
+
datetimeCol = def.dateTimeColumn()
|
|
10
|
+
booleanCol = def.boolColumn()
|
|
11
|
+
jsonCol = def.jsonColumn()
|
|
12
|
+
uuidCol = def.uuidColumn()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace EnumSchema {
|
|
18
|
+
export class Foo {
|
|
19
|
+
enumCol = def.enumColumn(def.createEnum('foo', 'bar'))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
namespace OneHasOneSchema {
|
|
24
|
+
export class Foo {
|
|
25
|
+
oneHasOneInverseRel = def.oneHasOneInverse(Bar, 'oneHasOne')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class Bar {
|
|
29
|
+
oneHasOneOwningRel = def.oneHasOne(Foo, 'oneHasOneInverseRel')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
namespace OneHasManySchema {
|
|
34
|
+
export class Foo {
|
|
35
|
+
oneHasManyRel = def.oneHasMany(Bar, 'manyHasOneRel')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Bar {
|
|
39
|
+
manyHasOneRel = def.manyHasOne(Foo, 'oneHasManyRel')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
namespace ManyHasManySchema {
|
|
45
|
+
export class Foo {
|
|
46
|
+
manyHasManyRel = def.manyHasMany(Bar, 'manyHasManyInverseRel')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class Bar {
|
|
50
|
+
manyHasManyInverseRel = def.manyHasManyInverse(Foo, 'manyHasManyRel')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
namespace ReducedHasManySchema {
|
|
55
|
+
export class Foo {
|
|
56
|
+
locales = def.oneHasMany(FooLocale, 'foo')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@def.Unique('locale', 'foo')
|
|
60
|
+
export class FooLocale {
|
|
61
|
+
locale = def.stringColumn().notNull()
|
|
62
|
+
foo = def.manyHasOne(Foo, 'locales')
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const schemas = {
|
|
67
|
+
scalarsSchema: createSchema(ManyScalarsSchema),
|
|
68
|
+
enumSchema: createSchema(EnumSchema),
|
|
69
|
+
oneHasOneSchema: createSchema(OneHasOneSchema),
|
|
70
|
+
oneHasManySchema: createSchema(OneHasManySchema),
|
|
71
|
+
manyHasManySchema: createSchema(ManyHasManySchema),
|
|
72
|
+
reducedHasManySchema: createSchema(ReducedHasManySchema),
|
|
73
|
+
}
|
package/tsconfig.json
ADDED
package/tsdoc.json
ADDED
package/vitest.config.ts
ADDED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContemberClientGenerator.cjs","sources":["../../src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":["NameSchemaGenerator","EnumTypeSchemaGenerator","EntityTypeSchemaGenerator"],"mappings":";;;;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAIA,oBAAAA,uBAC/C,0BAAmD,IAAIC,wBAAAA,2BACvD,4BAAuD,IAAIC,0BAAAA,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContemberClientGenerator.js","sources":["../../src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAI,uBAC/C,0BAAmD,IAAI,2BACvD,4BAAuD,IAAI,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityTypeSchemaGenerator.cjs","sources":["../../src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${enumName} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn column.columnType\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["acceptEveryFieldVisitor","Model","entity","acceptFieldVisitor","schema"],"mappings":";;;;AAGO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,iBAAiB,QAAQ;AAAA;AAAA,IAClC;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;AACA,YAAA;AAAA;AACR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,cAAQ,IAAK,OAAO,IAAI,KAAK,OAAO,IAAI;AAAA;AAAA,IACzC;AACQ,YAAA;AACA,YAAA;AAAA;AACA,YAAA;AACA,YAAA;AACD,WAAA;AAAA,EACR;AAAA,EAEQ,uBAAuB,OAAqB,QAA8B;AAC7E,QAAA,OAAO,eAAe,OAAO,IAAI;AAAA;AAC7B,YAAA,aAAe,OAAO,OAAO;AAC7B,YAAA;AACA,YAAA,KAAK,mBAAmB,OAAO,MAAM;AAC7C,QAAI,cAAc;AAClB,QAAI,aAAa;AACjB,QAAI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C,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityTypeSchemaGenerator.js","sources":["../../src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${enumName} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn column.columnType\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["entity"],"mappings":";;AAGO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,iBAAiB,QAAQ;AAAA;AAAA,IAClC;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;A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MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EnumTypeSchemaGenerator.cjs","sources":["../../src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${enumName} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\n\t\treturn code || 'export {}\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,QAAQ,MAAM,OAAO,IAAI,CAAM,OAAA,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAC/F;AAEA,WAAO,QAAQ;AAAA,EAChB;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EnumTypeSchemaGenerator.js","sources":["../../src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${enumName} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\n\t\treturn code || 'export {}\\n'\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,QAAQ,MAAM,OAAO,IAAI,CAAM,OAAA,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAC/F;AAEA,WAAO,QAAQ;AAAA,EAChB;AACD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NameSchemaGenerator.cjs","sources":["../../src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":["acceptEveryFieldVisitor"],"mappings":";;;AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1BA,sBAAA,wBAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NameSchemaGenerator.js","sources":["../../src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":[],"mappings":";AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1B,kCAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContemberClientGenerator.cjs","sources":["../../src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":["NameSchemaGenerator","EnumTypeSchemaGenerator","EntityTypeSchemaGenerator"],"mappings":";;;;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAIA,oBAAAA,uBAC/C,0BAAmD,IAAIC,wBAAAA,2BACvD,4BAAuD,IAAIC,0BAAAA,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContemberClientGenerator.js","sources":["../../src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAI,uBAC/C,0BAAmD,IAAI,2BACvD,4BAAuD,IAAI,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityTypeSchemaGenerator.cjs","sources":["../../src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${enumName} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn column.columnType\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["acceptEveryFieldVisitor","Model","entity","acceptFieldVisitor","schema"],"mappings":";;;;AAGO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,iBAAiB,QAAQ;AAAA;AAAA,IAClC;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;AACA,YAAA;AAAA;AACR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,cAAQ,IAAK,OAAO,IAAI,KAAK,OAAO,IAAI;AAAA;AAAA,IACzC;AACQ,YAAA;AACA,YAAA;AAAA;AACA,YAAA;AACA,YAAA;AACD,WAAA;AAAA,EACR;AAAA,EAEQ,uBAAuB,OAAqB,QAA8B;AAC7E,QAAA,OAAO,eAAe,OAAO,IAAI;AAAA;AAC7B,YAAA,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AAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityTypeSchemaGenerator.js","sources":["../../src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${enumName} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn column.columnType\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["entity"],"mappings":";;AAGO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,iBAAiB,QAAQ;AAAA;AAAA,IAClC;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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Y,OAAO;AAAA,IACxB,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EnumTypeSchemaGenerator.cjs","sources":["../../src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${enumName} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\n\t\treturn code || 'export {}\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,QAAQ,MAAM,OAAO,IAAI,CAAM,OAAA,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAC/F;AAEA,WAAO,QAAQ;AAAA,EAChB;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EnumTypeSchemaGenerator.js","sources":["../../src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${enumName} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\n\t\treturn code || 'export {}\\n'\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,QAAQ,MAAM,OAAO,IAAI,CAAM,OAAA,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAC/F;AAEA,WAAO,QAAQ;AAAA,EAChB;AACD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NameSchemaGenerator.cjs","sources":["../../src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":["acceptEveryFieldVisitor"],"mappings":";;;AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1BA,sBAAA,wBAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NameSchemaGenerator.js","sources":["../../src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":[],"mappings":";AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1B,kCAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|