@contember/client-content-generator 2.0.0-alpha.9 → 2.0.0-beta.2
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/development/generate.cjs +1 -0
- package/dist/development/generate.cjs.map +1 -1
- package/dist/development/generate.js +1 -0
- package/dist/development/generate.js.map +1 -1
- package/dist/development/src/ContemberClientGenerator.cjs.map +1 -1
- package/dist/development/src/ContemberClientGenerator.js.map +1 -1
- package/dist/development/src/EntityTypeSchemaGenerator.cjs +3 -2
- package/dist/development/src/EntityTypeSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/EntityTypeSchemaGenerator.js +3 -2
- package/dist/development/src/EntityTypeSchemaGenerator.js.map +1 -1
- package/dist/development/src/EnumTypeSchemaGenerator.cjs +10 -2
- package/dist/development/src/EnumTypeSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/EnumTypeSchemaGenerator.js +10 -2
- package/dist/development/src/EnumTypeSchemaGenerator.js.map +1 -1
- package/dist/development/src/NameSchemaGenerator.cjs +3 -0
- package/dist/development/src/NameSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/NameSchemaGenerator.js +3 -0
- package/dist/development/src/NameSchemaGenerator.js.map +1 -1
- 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 -0
- package/dist/production/generate.cjs.map +1 -1
- package/dist/production/generate.js +1 -0
- package/dist/production/generate.js.map +1 -1
- package/dist/production/src/ContemberClientGenerator.cjs.map +1 -1
- package/dist/production/src/ContemberClientGenerator.js.map +1 -1
- package/dist/production/src/EntityTypeSchemaGenerator.cjs +3 -2
- package/dist/production/src/EntityTypeSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/EntityTypeSchemaGenerator.js +3 -2
- package/dist/production/src/EntityTypeSchemaGenerator.js.map +1 -1
- package/dist/production/src/EnumTypeSchemaGenerator.cjs +10 -2
- package/dist/production/src/EnumTypeSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/EnumTypeSchemaGenerator.js +10 -2
- package/dist/production/src/EnumTypeSchemaGenerator.js.map +1 -1
- package/dist/production/src/NameSchemaGenerator.cjs +3 -0
- package/dist/production/src/NameSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/NameSchemaGenerator.js +3 -0
- package/dist/production/src/NameSchemaGenerator.js.map +1 -1
- 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/NameSchemaGenerator.d.ts.map +1 -1
- package/dist/types/generate.d.ts +1 -0
- 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 +7 -7
- package/src/EntityTypeSchemaGenerator.ts +4 -2
- package/src/EnumTypeSchemaGenerator.ts +8 -3
- package/src/NameSchemaGenerator.ts +3 -0
- package/src/generate.ts +1 -0
- package/src/utils.ts +3 -0
- package/tests/__snapshots__/generateEnittyTypes.test.ts.snap +278 -0
- package/tests/__snapshots__/generateEnumTypes.test.ts.snap +17 -0
- package/tests/generateEnittyTypes.test.ts +7 -272
- package/tests/generateEnumTypes.test.ts +3 -12
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`generate entities generate for scalars 1`] = `
|
|
4
|
+
"
|
|
5
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
6
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
7
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
8
|
+
export type JSONArray = readonly JSONValue[]
|
|
9
|
+
|
|
10
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
11
|
+
\tname: 'Foo'
|
|
12
|
+
\tunique:
|
|
13
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
14
|
+
\tcolumns: {
|
|
15
|
+
\t\tid: string
|
|
16
|
+
\t\tstringCol: string | null
|
|
17
|
+
\t\tintCol: number | null
|
|
18
|
+
\t\tdoubleCol: number | null
|
|
19
|
+
\t\tdateCol: string | null
|
|
20
|
+
\t\tdatetimeCol: string | null
|
|
21
|
+
\t\tbooleanCol: boolean | null
|
|
22
|
+
\t\tjsonCol: JSONValue | null
|
|
23
|
+
\t\tuuidCol: string | null
|
|
24
|
+
\t}
|
|
25
|
+
\thasOne: {
|
|
26
|
+
\t}
|
|
27
|
+
\thasMany: {
|
|
28
|
+
\t}
|
|
29
|
+
\thasManyBy: {
|
|
30
|
+
\t}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ContemberClientEntities = {
|
|
34
|
+
\tFoo: Foo
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ContemberClientSchema = {
|
|
38
|
+
\tentities: ContemberClientEntities
|
|
39
|
+
}
|
|
40
|
+
"
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports[`generate entities generate for has enum 1`] = `
|
|
44
|
+
"import type { FooEnumCol } from './enums'
|
|
45
|
+
|
|
46
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
47
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
48
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
49
|
+
export type JSONArray = readonly JSONValue[]
|
|
50
|
+
|
|
51
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
52
|
+
\tname: 'Foo'
|
|
53
|
+
\tunique:
|
|
54
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
55
|
+
\tcolumns: {
|
|
56
|
+
\t\tid: string
|
|
57
|
+
\t\tenumCol: FooEnumCol | null
|
|
58
|
+
\t}
|
|
59
|
+
\thasOne: {
|
|
60
|
+
\t}
|
|
61
|
+
\thasMany: {
|
|
62
|
+
\t}
|
|
63
|
+
\thasManyBy: {
|
|
64
|
+
\t}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ContemberClientEntities = {
|
|
68
|
+
\tFoo: Foo
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ContemberClientSchema = {
|
|
72
|
+
\tentities: ContemberClientEntities
|
|
73
|
+
}
|
|
74
|
+
"
|
|
75
|
+
`;
|
|
76
|
+
|
|
77
|
+
exports[`generate entities generate one has one 1`] = `
|
|
78
|
+
"
|
|
79
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
80
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
81
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
82
|
+
export type JSONArray = readonly JSONValue[]
|
|
83
|
+
|
|
84
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
85
|
+
\tname: 'Foo'
|
|
86
|
+
\tunique:
|
|
87
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
88
|
+
\t\t| Omit<{ oneHasOneInverseRel: Bar['unique']}, OverRelation>
|
|
89
|
+
\tcolumns: {
|
|
90
|
+
\t\tid: string
|
|
91
|
+
\t}
|
|
92
|
+
\thasOne: {
|
|
93
|
+
\t\toneHasOneInverseRel: Bar
|
|
94
|
+
\t}
|
|
95
|
+
\thasMany: {
|
|
96
|
+
\t}
|
|
97
|
+
\thasManyBy: {
|
|
98
|
+
\t}
|
|
99
|
+
}
|
|
100
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
101
|
+
\tname: 'Bar'
|
|
102
|
+
\tunique:
|
|
103
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
104
|
+
\t\t| Omit<{ oneHasOneOwningRel: Foo['unique']}, OverRelation>
|
|
105
|
+
\tcolumns: {
|
|
106
|
+
\t\tid: string
|
|
107
|
+
\t}
|
|
108
|
+
\thasOne: {
|
|
109
|
+
\t\toneHasOneOwningRel: Foo
|
|
110
|
+
\t}
|
|
111
|
+
\thasMany: {
|
|
112
|
+
\t}
|
|
113
|
+
\thasManyBy: {
|
|
114
|
+
\t}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type ContemberClientEntities = {
|
|
118
|
+
\tFoo: Foo
|
|
119
|
+
\tBar: Bar
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type ContemberClientSchema = {
|
|
123
|
+
\tentities: ContemberClientEntities
|
|
124
|
+
}
|
|
125
|
+
"
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
exports[`generate entities generate one has many 1`] = `
|
|
129
|
+
"
|
|
130
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
131
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
132
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
133
|
+
export type JSONArray = readonly JSONValue[]
|
|
134
|
+
|
|
135
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
136
|
+
\tname: 'Foo'
|
|
137
|
+
\tunique:
|
|
138
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
139
|
+
\t\t| Omit<{ oneHasManyRel: Bar['unique']}, OverRelation>
|
|
140
|
+
\tcolumns: {
|
|
141
|
+
\t\tid: string
|
|
142
|
+
\t}
|
|
143
|
+
\thasOne: {
|
|
144
|
+
\t}
|
|
145
|
+
\thasMany: {
|
|
146
|
+
\t\toneHasManyRel: Bar<'manyHasOneRel'>
|
|
147
|
+
\t}
|
|
148
|
+
\thasManyBy: {
|
|
149
|
+
\t}
|
|
150
|
+
}
|
|
151
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
152
|
+
\tname: 'Bar'
|
|
153
|
+
\tunique:
|
|
154
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
155
|
+
\tcolumns: {
|
|
156
|
+
\t\tid: string
|
|
157
|
+
\t}
|
|
158
|
+
\thasOne: {
|
|
159
|
+
\t\tmanyHasOneRel: Foo
|
|
160
|
+
\t}
|
|
161
|
+
\thasMany: {
|
|
162
|
+
\t}
|
|
163
|
+
\thasManyBy: {
|
|
164
|
+
\t}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type ContemberClientEntities = {
|
|
168
|
+
\tFoo: Foo
|
|
169
|
+
\tBar: Bar
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type ContemberClientSchema = {
|
|
173
|
+
\tentities: ContemberClientEntities
|
|
174
|
+
}
|
|
175
|
+
"
|
|
176
|
+
`;
|
|
177
|
+
|
|
178
|
+
exports[`generate entities generate many has many 1`] = `
|
|
179
|
+
"
|
|
180
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
181
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
182
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
183
|
+
export type JSONArray = readonly JSONValue[]
|
|
184
|
+
|
|
185
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
186
|
+
\tname: 'Foo'
|
|
187
|
+
\tunique:
|
|
188
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
189
|
+
\tcolumns: {
|
|
190
|
+
\t\tid: string
|
|
191
|
+
\t}
|
|
192
|
+
\thasOne: {
|
|
193
|
+
\t}
|
|
194
|
+
\thasMany: {
|
|
195
|
+
\t\tmanyHasManyRel: Bar
|
|
196
|
+
\t}
|
|
197
|
+
\thasManyBy: {
|
|
198
|
+
\t}
|
|
199
|
+
}
|
|
200
|
+
export type Bar <OverRelation extends string | never = never> = {
|
|
201
|
+
\tname: 'Bar'
|
|
202
|
+
\tunique:
|
|
203
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
204
|
+
\tcolumns: {
|
|
205
|
+
\t\tid: string
|
|
206
|
+
\t}
|
|
207
|
+
\thasOne: {
|
|
208
|
+
\t}
|
|
209
|
+
\thasMany: {
|
|
210
|
+
\t\tmanyHasManyInverseRel: Foo
|
|
211
|
+
\t}
|
|
212
|
+
\thasManyBy: {
|
|
213
|
+
\t}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type ContemberClientEntities = {
|
|
217
|
+
\tFoo: Foo
|
|
218
|
+
\tBar: Bar
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type ContemberClientSchema = {
|
|
222
|
+
\tentities: ContemberClientEntities
|
|
223
|
+
}
|
|
224
|
+
"
|
|
225
|
+
`;
|
|
226
|
+
|
|
227
|
+
exports[`generate entities generate reduced has by 1`] = `
|
|
228
|
+
"
|
|
229
|
+
export type JSONPrimitive = string | number | boolean | null
|
|
230
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
231
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
232
|
+
export type JSONArray = readonly JSONValue[]
|
|
233
|
+
|
|
234
|
+
export type Foo <OverRelation extends string | never = never> = {
|
|
235
|
+
\tname: 'Foo'
|
|
236
|
+
\tunique:
|
|
237
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
238
|
+
\t\t| Omit<{ locales: FooLocale['unique']}, OverRelation>
|
|
239
|
+
\tcolumns: {
|
|
240
|
+
\t\tid: string
|
|
241
|
+
\t}
|
|
242
|
+
\thasOne: {
|
|
243
|
+
\t}
|
|
244
|
+
\thasMany: {
|
|
245
|
+
\t\tlocales: FooLocale<'foo'>
|
|
246
|
+
\t}
|
|
247
|
+
\thasManyBy: {
|
|
248
|
+
\t\tlocalesByLocale: { entity: FooLocale; by: {locale: string} }
|
|
249
|
+
\t}
|
|
250
|
+
}
|
|
251
|
+
export type FooLocale <OverRelation extends string | never = never> = {
|
|
252
|
+
\tname: 'FooLocale'
|
|
253
|
+
\tunique:
|
|
254
|
+
\t\t| Omit<{ id: string}, OverRelation>
|
|
255
|
+
\t\t| Omit<{ locale: string, foo: Foo['unique']}, OverRelation>
|
|
256
|
+
\tcolumns: {
|
|
257
|
+
\t\tid: string
|
|
258
|
+
\t\tlocale: string
|
|
259
|
+
\t}
|
|
260
|
+
\thasOne: {
|
|
261
|
+
\t\tfoo: Foo
|
|
262
|
+
\t}
|
|
263
|
+
\thasMany: {
|
|
264
|
+
\t}
|
|
265
|
+
\thasManyBy: {
|
|
266
|
+
\t}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export type ContemberClientEntities = {
|
|
270
|
+
\tFoo: Foo
|
|
271
|
+
\tFooLocale: FooLocale
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export type ContemberClientSchema = {
|
|
275
|
+
\tentities: ContemberClientEntities
|
|
276
|
+
}
|
|
277
|
+
"
|
|
278
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`generate enums 1`] = `
|
|
4
|
+
"export type OrderStatus =
|
|
5
|
+
\t | "new"
|
|
6
|
+
\t | "paid"
|
|
7
|
+
\t | "cancelled"
|
|
8
|
+
export type OrderType =
|
|
9
|
+
\t | "normal"
|
|
10
|
+
\t | "express"
|
|
11
|
+
export type ContemberClientEnums = {
|
|
12
|
+
\tOrderStatus: OrderStatus
|
|
13
|
+
\torderType: OrderType
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
"
|
|
17
|
+
`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, test } from '
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
2
|
import { EntityTypeSchemaGenerator } from '../src'
|
|
3
3
|
import { schemas } from './schemas'
|
|
4
4
|
|
|
@@ -8,296 +8,31 @@ describe('generate entities', () => {
|
|
|
8
8
|
const entityGenerator = new EntityTypeSchemaGenerator()
|
|
9
9
|
test('generate for scalars', () => {
|
|
10
10
|
|
|
11
|
-
expect(entityGenerator.generate(schemas.scalarsSchema.model)).
|
|
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
|
-
`)
|
|
11
|
+
expect(entityGenerator.generate(schemas.scalarsSchema.model)).toMatchSnapshot()
|
|
50
12
|
})
|
|
51
13
|
|
|
52
14
|
test('generate for has enum', () => {
|
|
53
15
|
|
|
54
|
-
expect(entityGenerator.generate(schemas.enumSchema.model)).
|
|
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
|
-
`)
|
|
16
|
+
expect(entityGenerator.generate(schemas.enumSchema.model)).toMatchSnapshot()
|
|
87
17
|
})
|
|
88
18
|
test('generate one has one', () => {
|
|
89
19
|
|
|
90
|
-
expect(entityGenerator.generate(schemas.oneHasOneSchema.model)).
|
|
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
|
-
`)
|
|
20
|
+
expect(entityGenerator.generate(schemas.oneHasOneSchema.model)).toMatchSnapshot()
|
|
140
21
|
})
|
|
141
22
|
|
|
142
23
|
test('generate one has many', () => {
|
|
143
24
|
|
|
144
|
-
expect(entityGenerator.generate(schemas.oneHasManySchema.model)).
|
|
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
|
-
`)
|
|
25
|
+
expect(entityGenerator.generate(schemas.oneHasManySchema.model)).toMatchSnapshot()
|
|
193
26
|
})
|
|
194
27
|
|
|
195
28
|
test('generate many has many', () => {
|
|
196
29
|
|
|
197
|
-
expect(entityGenerator.generate(schemas.manyHasManySchema.model)).
|
|
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
|
-
`)
|
|
30
|
+
expect(entityGenerator.generate(schemas.manyHasManySchema.model)).toMatchSnapshot()
|
|
245
31
|
})
|
|
246
32
|
|
|
247
33
|
test('generate reduced has by', () => {
|
|
248
34
|
|
|
249
|
-
expect(entityGenerator.generate(schemas.reducedHasManySchema.model)).
|
|
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
|
-
`)
|
|
35
|
+
expect(entityGenerator.generate(schemas.reducedHasManySchema.model)).toMatchSnapshot()
|
|
301
36
|
})
|
|
302
37
|
|
|
303
38
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, test } from '
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
2
|
import { EnumTypeSchemaGenerator } from '../src'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -8,16 +8,7 @@ test('generate enums', () => {
|
|
|
8
8
|
entities: {},
|
|
9
9
|
enums: {
|
|
10
10
|
OrderStatus: ['new', 'paid', 'cancelled'],
|
|
11
|
-
|
|
11
|
+
orderType: ['normal', 'express'],
|
|
12
12
|
},
|
|
13
|
-
})).
|
|
14
|
-
"export type OrderStatus =
|
|
15
|
-
| "new"
|
|
16
|
-
| "paid"
|
|
17
|
-
| "cancelled"
|
|
18
|
-
export type OrderType =
|
|
19
|
-
| "normal"
|
|
20
|
-
| "express"
|
|
21
|
-
"
|
|
22
|
-
`)
|
|
13
|
+
})).toMatchSnapshot()
|
|
23
14
|
})
|