@contember/client-content-generator 2.1.0-alpha.30 → 2.1.0-alpha.36
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.map +1 -1
- package/dist/development/generate.js.map +1 -1
- package/dist/development/src/ContemberClientGenerator.cjs +7 -2
- package/dist/development/src/ContemberClientGenerator.cjs.map +1 -1
- package/dist/development/src/ContemberClientGenerator.js +7 -2
- package/dist/development/src/ContemberClientGenerator.js.map +1 -1
- package/dist/development/src/EntityTypeSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/EntityTypeSchemaGenerator.js.map +1 -1
- package/dist/development/src/EnumTypeSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/EnumTypeSchemaGenerator.js.map +1 -1
- package/dist/development/src/NameSchemaGenerator.cjs.map +1 -1
- package/dist/development/src/NameSchemaGenerator.js.map +1 -1
- package/dist/production/generate.cjs +0 -0
- package/dist/production/generate.cjs.map +1 -1
- package/dist/production/generate.js.map +1 -1
- package/dist/production/src/ContemberClientGenerator.cjs +7 -2
- package/dist/production/src/ContemberClientGenerator.cjs.map +1 -1
- package/dist/production/src/ContemberClientGenerator.js +7 -2
- package/dist/production/src/ContemberClientGenerator.js.map +1 -1
- package/dist/production/src/EntityTypeSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/EntityTypeSchemaGenerator.js.map +1 -1
- package/dist/production/src/EnumTypeSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/EnumTypeSchemaGenerator.js.map +1 -1
- package/dist/production/src/NameSchemaGenerator.cjs.map +1 -1
- package/dist/production/src/NameSchemaGenerator.js.map +1 -1
- package/dist/types/ContemberClientGenerator.d.ts.map +1 -1
- package/dist/types/EntityTypeSchemaGenerator.d.ts.map +1 -1
- package/dist/types/NameSchemaGenerator.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/ContemberClientGenerator.ts +11 -3
- package/src/EntityTypeSchemaGenerator.ts +6 -8
- package/src/NameSchemaGenerator.ts +1 -3
- package/src/generate.ts +3 -5
- package/tests/__snapshots__/generateEnittyTypes.test.ts.snap +161 -161
- package/tests/__snapshots__/generateEnumTypes.test.ts.snap +8 -8
- package/tests/generateEnittyTypes.test.ts +0 -9
- package/tests/generateEnumTypes.test.ts +0 -1
- package/tests/schemas.ts +1 -3
- package/dist/types/tsconfig.tsbuildinfo +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityTypeSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/EntityTypeSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAKzC,qBAAa,yBAAyB;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM;IA6BrC,OAAO,CAAC,sBAAsB;
|
|
1
|
+
{"version":3,"file":"EntityTypeSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/EntityTypeSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAKzC,qBAAa,yBAAyB;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM;IA6BrC,OAAO,CAAC,sBAAsB;IAsC9B,OAAO,CAAC,mBAAmB;IA4C3B,OAAO,CAAC,kBAAkB;CAU1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NameSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/NameSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"NameSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/NameSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzC,qBAAa,mBAAmB;IAC/B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,WAAW;CAoC1C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/client-content-generator",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.1.0-alpha.
|
|
4
|
+
"version": "2.1.0-alpha.36",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"ae:test": "api-extractor run"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@contember/client-content": "
|
|
37
|
-
"@contember/schema": "
|
|
38
|
-
"@contember/schema-utils": "
|
|
36
|
+
"@contember/client-content": "workspace:*",
|
|
37
|
+
"@contember/schema": "workspace:*",
|
|
38
|
+
"@contember/schema-utils": "workspace:*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@contember/schema-definition": "
|
|
42
|
-
"@types/node": "
|
|
41
|
+
"@contember/schema-definition": "workspace:*",
|
|
42
|
+
"@types/node": "catalog:"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/contember/
|
|
46
|
+
"url": "git+https://github.com/contember/contember.git",
|
|
47
47
|
"directory": "packages/client-content-generator"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -3,7 +3,6 @@ import { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'
|
|
|
3
3
|
import { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'
|
|
4
4
|
import { NameSchemaGenerator } from './NameSchemaGenerator'
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
export class ContemberClientGenerator {
|
|
8
7
|
constructor(
|
|
9
8
|
private readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),
|
|
@@ -17,8 +16,17 @@ export class ContemberClientGenerator {
|
|
|
17
16
|
const enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)
|
|
18
17
|
const entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)
|
|
19
18
|
|
|
20
|
-
const namesCode = `import { SchemaNames } from '@contember/client-content'
|
|
21
|
-
|
|
19
|
+
const namesCode = `import type { SchemaNames, SchemaEntityNames } from '@contember/client-content'
|
|
20
|
+
import type { ContemberClientEntities } from './entities'
|
|
21
|
+
import type { ContemberClientEnums } from './enums'
|
|
22
|
+
export const ContemberClientNames = {
|
|
23
|
+
entities: ${
|
|
24
|
+
JSON.stringify(nameSchema.entities, null, '\t').replaceAll('\n', '\n\t')
|
|
25
|
+
} satisfies {[K in keyof ContemberClientEntities]: SchemaEntityNames<K>},
|
|
26
|
+
enums: ${
|
|
27
|
+
JSON.stringify(nameSchema.enums, null, '\t').replaceAll('\n', '\n\t')
|
|
28
|
+
} satisfies {[K in keyof ContemberClientEnums]: readonly ContemberClientEnums[K][]},
|
|
29
|
+
} satisfies SchemaNames`
|
|
22
30
|
|
|
23
31
|
const indexCode = `
|
|
24
32
|
import { ContemberClientNames } from './names'
|
|
@@ -35,7 +35,7 @@ export type JSONArray = readonly JSONValue[]
|
|
|
35
35
|
|
|
36
36
|
private generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {
|
|
37
37
|
let code = `export type ${entity.name} <OverRelation extends string | never = never> = {\n`
|
|
38
|
-
code +=
|
|
38
|
+
code += "\tname: '" + entity.name + "'\n"
|
|
39
39
|
code += '\tunique:\n'
|
|
40
40
|
code += this.formatUniqueFields(model, entity)
|
|
41
41
|
let columnsCode = ''
|
|
@@ -43,7 +43,9 @@ export type JSONArray = readonly JSONValue[]
|
|
|
43
43
|
let hasManyCode = ''
|
|
44
44
|
acceptEveryFieldVisitor(model, entity, {
|
|
45
45
|
visitHasMany: ctx => {
|
|
46
|
-
hasManyCode += `\t\t${ctx.relation.name}: ${ctx.targetEntity.name}${
|
|
46
|
+
hasManyCode += `\t\t${ctx.relation.name}: ${ctx.targetEntity.name}${
|
|
47
|
+
ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''
|
|
48
|
+
}\n`
|
|
47
49
|
},
|
|
48
50
|
visitHasOne: ctx => {
|
|
49
51
|
hasOneCode += `\t\t${ctx.relation.name}: ${ctx.targetEntity.name}\n`
|
|
@@ -78,7 +80,7 @@ export type JSONArray = readonly JSONValue[]
|
|
|
78
80
|
}
|
|
79
81
|
const uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)
|
|
80
82
|
const composedUnique = uniqueConstraints
|
|
81
|
-
.filter(fields => fields.length === 2) //todo support all uniques
|
|
83
|
+
.filter(fields => fields.length === 2) // todo support all uniques
|
|
82
84
|
.filter(fields => fields.includes(targetRelation.name))
|
|
83
85
|
.map(fields => fields.filter(it => it !== targetRelation.name))
|
|
84
86
|
.map(fields => fields[0])
|
|
@@ -86,7 +88,6 @@ export type JSONArray = readonly JSONValue[]
|
|
|
86
88
|
.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)
|
|
87
89
|
.map(fields => fields[0])
|
|
88
90
|
.filter(it => it !== targetRelation.name)
|
|
89
|
-
|
|
90
91
|
;[...composedUnique, ...singleUnique].forEach(fieldName => {
|
|
91
92
|
const capitalizeFirstLetter = (value: string) => {
|
|
92
93
|
return value.charAt(0).toUpperCase() + value.slice(1)
|
|
@@ -96,7 +97,6 @@ export type JSONArray = readonly JSONValue[]
|
|
|
96
97
|
const targetUnique = targetEntity.fields[fieldName]
|
|
97
98
|
|
|
98
99
|
code += `\t\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\n`
|
|
99
|
-
|
|
100
100
|
})
|
|
101
101
|
},
|
|
102
102
|
visitColumn: () => {
|
|
@@ -127,7 +127,6 @@ export type JSONArray = readonly JSONValue[]
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
130
|
const uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {
|
|
132
131
|
return acceptFieldVisitor(model, entity, field, {
|
|
133
132
|
visitColumn: ctx => {
|
|
@@ -139,7 +138,6 @@ const uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyF
|
|
|
139
138
|
})
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
|
|
143
141
|
const columnToTsType = (column: Model.AnyColumn): string => {
|
|
144
142
|
const baseType = (() => {
|
|
145
143
|
switch (column.type) {
|
|
@@ -164,7 +162,7 @@ const columnToTsType = (column: Model.AnyColumn): string => {
|
|
|
164
162
|
case Model.ColumnType.Uuid:
|
|
165
163
|
return 'string'
|
|
166
164
|
default:
|
|
167
|
-
((_: never) => {
|
|
165
|
+
;((_: never) => {
|
|
168
166
|
throw new Error(`Unknown type ${_}`)
|
|
169
167
|
})(column.type)
|
|
170
168
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaEntityNames, SchemaNames } from '@contember/client-content'
|
|
2
2
|
import { Model } from '@contember/schema'
|
|
3
3
|
import { acceptEveryFieldVisitor } from '@contember/schema-utils'
|
|
4
4
|
|
|
@@ -40,5 +40,3 @@ export class NameSchemaGenerator {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
package/src/generate.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as fs from 'node:fs/promises'
|
|
3
|
-
import {
|
|
4
|
-
import { ContemberClientGenerator } from './ContemberClientGenerator'
|
|
5
|
-
|
|
6
|
-
(async () => {
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
|
+
import { ContemberClientGenerator } from './ContemberClientGenerator'
|
|
5
|
+
;(async () => {
|
|
7
6
|
const schemaPath = process.argv[2]
|
|
8
7
|
const outDir = process.argv[3]
|
|
9
8
|
|
|
@@ -46,4 +45,3 @@ yarn run --silent contember project:print-schema --format=schema | yarn contembe
|
|
|
46
45
|
console.error(e)
|
|
47
46
|
process.exit(1)
|
|
48
47
|
})
|
|
49
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Bun Snapshot v1, https://
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
2
|
|
|
3
3
|
exports[`generate entities generate for scalars 1`] = `
|
|
4
4
|
"
|
|
@@ -8,34 +8,34 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
8
8
|
export type JSONArray = readonly JSONValue[]
|
|
9
9
|
|
|
10
10
|
export type Foo <OverRelation extends string | never = never> = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
name: 'Foo'
|
|
12
|
+
unique:
|
|
13
|
+
| Omit<{ id: string}, OverRelation>
|
|
14
|
+
columns: {
|
|
15
|
+
id: string
|
|
16
|
+
stringCol: string | null
|
|
17
|
+
intCol: number | null
|
|
18
|
+
doubleCol: number | null
|
|
19
|
+
dateCol: string | null
|
|
20
|
+
datetimeCol: string | null
|
|
21
|
+
booleanCol: boolean | null
|
|
22
|
+
jsonCol: JSONValue | null
|
|
23
|
+
uuidCol: string | null
|
|
24
|
+
}
|
|
25
|
+
hasOne: {
|
|
26
|
+
}
|
|
27
|
+
hasMany: {
|
|
28
|
+
}
|
|
29
|
+
hasManyBy: {
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export type ContemberClientEntities = {
|
|
34
|
-
|
|
34
|
+
Foo: Foo
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type ContemberClientSchema = {
|
|
38
|
-
|
|
38
|
+
entities: ContemberClientEntities
|
|
39
39
|
}
|
|
40
40
|
"
|
|
41
41
|
`;
|
|
@@ -49,27 +49,27 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
49
49
|
export type JSONArray = readonly JSONValue[]
|
|
50
50
|
|
|
51
51
|
export type Foo <OverRelation extends string | never = never> = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
name: 'Foo'
|
|
53
|
+
unique:
|
|
54
|
+
| Omit<{ id: string}, OverRelation>
|
|
55
|
+
columns: {
|
|
56
|
+
id: string
|
|
57
|
+
enumCol: FooEnumCol | null
|
|
58
|
+
}
|
|
59
|
+
hasOne: {
|
|
60
|
+
}
|
|
61
|
+
hasMany: {
|
|
62
|
+
}
|
|
63
|
+
hasManyBy: {
|
|
64
|
+
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export type ContemberClientEntities = {
|
|
68
|
-
|
|
68
|
+
Foo: Foo
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export type ContemberClientSchema = {
|
|
72
|
-
|
|
72
|
+
entities: ContemberClientEntities
|
|
73
73
|
}
|
|
74
74
|
"
|
|
75
75
|
`;
|
|
@@ -82,45 +82,45 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
82
82
|
export type JSONArray = readonly JSONValue[]
|
|
83
83
|
|
|
84
84
|
export type Foo <OverRelation extends string | never = never> = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
name: 'Foo'
|
|
86
|
+
unique:
|
|
87
|
+
| Omit<{ id: string}, OverRelation>
|
|
88
|
+
| Omit<{ oneHasOneInverseRel: Bar['unique']}, OverRelation>
|
|
89
|
+
columns: {
|
|
90
|
+
id: string
|
|
91
|
+
}
|
|
92
|
+
hasOne: {
|
|
93
|
+
oneHasOneInverseRel: Bar
|
|
94
|
+
}
|
|
95
|
+
hasMany: {
|
|
96
|
+
}
|
|
97
|
+
hasManyBy: {
|
|
98
|
+
}
|
|
99
99
|
}
|
|
100
100
|
export type Bar <OverRelation extends string | never = never> = {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
name: 'Bar'
|
|
102
|
+
unique:
|
|
103
|
+
| Omit<{ id: string}, OverRelation>
|
|
104
|
+
| Omit<{ oneHasOneOwningRel: Foo['unique']}, OverRelation>
|
|
105
|
+
columns: {
|
|
106
|
+
id: string
|
|
107
|
+
}
|
|
108
|
+
hasOne: {
|
|
109
|
+
oneHasOneOwningRel: Foo
|
|
110
|
+
}
|
|
111
|
+
hasMany: {
|
|
112
|
+
}
|
|
113
|
+
hasManyBy: {
|
|
114
|
+
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export type ContemberClientEntities = {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
Foo: Foo
|
|
119
|
+
Bar: Bar
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export type ContemberClientSchema = {
|
|
123
|
-
|
|
123
|
+
entities: ContemberClientEntities
|
|
124
124
|
}
|
|
125
125
|
"
|
|
126
126
|
`;
|
|
@@ -133,44 +133,44 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
133
133
|
export type JSONArray = readonly JSONValue[]
|
|
134
134
|
|
|
135
135
|
export type Foo <OverRelation extends string | never = never> = {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
name: 'Foo'
|
|
137
|
+
unique:
|
|
138
|
+
| Omit<{ id: string}, OverRelation>
|
|
139
|
+
| Omit<{ oneHasManyRel: Bar['unique']}, OverRelation>
|
|
140
|
+
columns: {
|
|
141
|
+
id: string
|
|
142
|
+
}
|
|
143
|
+
hasOne: {
|
|
144
|
+
}
|
|
145
|
+
hasMany: {
|
|
146
|
+
oneHasManyRel: Bar<'manyHasOneRel'>
|
|
147
|
+
}
|
|
148
|
+
hasManyBy: {
|
|
149
|
+
}
|
|
150
150
|
}
|
|
151
151
|
export type Bar <OverRelation extends string | never = never> = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
152
|
+
name: 'Bar'
|
|
153
|
+
unique:
|
|
154
|
+
| Omit<{ id: string}, OverRelation>
|
|
155
|
+
columns: {
|
|
156
|
+
id: string
|
|
157
|
+
}
|
|
158
|
+
hasOne: {
|
|
159
|
+
manyHasOneRel: Foo
|
|
160
|
+
}
|
|
161
|
+
hasMany: {
|
|
162
|
+
}
|
|
163
|
+
hasManyBy: {
|
|
164
|
+
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
export type ContemberClientEntities = {
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
Foo: Foo
|
|
169
|
+
Bar: Bar
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
export type ContemberClientSchema = {
|
|
173
|
-
|
|
173
|
+
entities: ContemberClientEntities
|
|
174
174
|
}
|
|
175
175
|
"
|
|
176
176
|
`;
|
|
@@ -183,43 +183,43 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
183
183
|
export type JSONArray = readonly JSONValue[]
|
|
184
184
|
|
|
185
185
|
export type Foo <OverRelation extends string | never = never> = {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
name: 'Foo'
|
|
187
|
+
unique:
|
|
188
|
+
| Omit<{ id: string}, OverRelation>
|
|
189
|
+
columns: {
|
|
190
|
+
id: string
|
|
191
|
+
}
|
|
192
|
+
hasOne: {
|
|
193
|
+
}
|
|
194
|
+
hasMany: {
|
|
195
|
+
manyHasManyRel: Bar
|
|
196
|
+
}
|
|
197
|
+
hasManyBy: {
|
|
198
|
+
}
|
|
199
199
|
}
|
|
200
200
|
export type Bar <OverRelation extends string | never = never> = {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
name: 'Bar'
|
|
202
|
+
unique:
|
|
203
|
+
| Omit<{ id: string}, OverRelation>
|
|
204
|
+
columns: {
|
|
205
|
+
id: string
|
|
206
|
+
}
|
|
207
|
+
hasOne: {
|
|
208
|
+
}
|
|
209
|
+
hasMany: {
|
|
210
|
+
manyHasManyInverseRel: Foo
|
|
211
|
+
}
|
|
212
|
+
hasManyBy: {
|
|
213
|
+
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
export type ContemberClientEntities = {
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
Foo: Foo
|
|
218
|
+
Bar: Bar
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
export type ContemberClientSchema = {
|
|
222
|
-
|
|
222
|
+
entities: ContemberClientEntities
|
|
223
223
|
}
|
|
224
224
|
"
|
|
225
225
|
`;
|
|
@@ -232,47 +232,47 @@ export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
|
232
232
|
export type JSONArray = readonly JSONValue[]
|
|
233
233
|
|
|
234
234
|
export type Foo <OverRelation extends string | never = never> = {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
235
|
+
name: 'Foo'
|
|
236
|
+
unique:
|
|
237
|
+
| Omit<{ id: string}, OverRelation>
|
|
238
|
+
| Omit<{ locales: FooLocale['unique']}, OverRelation>
|
|
239
|
+
columns: {
|
|
240
|
+
id: string
|
|
241
|
+
}
|
|
242
|
+
hasOne: {
|
|
243
|
+
}
|
|
244
|
+
hasMany: {
|
|
245
|
+
locales: FooLocale<'foo'>
|
|
246
|
+
}
|
|
247
|
+
hasManyBy: {
|
|
248
|
+
localesByLocale: { entity: FooLocale; by: {locale: string} }
|
|
249
|
+
}
|
|
250
250
|
}
|
|
251
251
|
export type FooLocale <OverRelation extends string | never = never> = {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
252
|
+
name: 'FooLocale'
|
|
253
|
+
unique:
|
|
254
|
+
| Omit<{ id: string}, OverRelation>
|
|
255
|
+
| Omit<{ locale: string, foo: Foo['unique']}, OverRelation>
|
|
256
|
+
columns: {
|
|
257
|
+
id: string
|
|
258
|
+
locale: string
|
|
259
|
+
}
|
|
260
|
+
hasOne: {
|
|
261
|
+
foo: Foo
|
|
262
|
+
}
|
|
263
|
+
hasMany: {
|
|
264
|
+
}
|
|
265
|
+
hasManyBy: {
|
|
266
|
+
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
export type ContemberClientEntities = {
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
Foo: Foo
|
|
271
|
+
FooLocale: FooLocale
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
export type ContemberClientSchema = {
|
|
275
|
-
|
|
275
|
+
entities: ContemberClientEntities
|
|
276
276
|
}
|
|
277
277
|
"
|
|
278
278
|
`;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// Bun Snapshot v1, https://
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
2
|
|
|
3
3
|
exports[`generate enums 1`] = `
|
|
4
4
|
"export type OrderStatus =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
| "new"
|
|
6
|
+
| "paid"
|
|
7
|
+
| "cancelled"
|
|
8
8
|
export type OrderType =
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
| "normal"
|
|
10
|
+
| "express"
|
|
11
11
|
export type ContemberClientEnums = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
OrderStatus: OrderStatus
|
|
13
|
+
orderType: OrderType
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
"
|
|
@@ -2,37 +2,28 @@ import { describe, expect, test } from 'bun:test'
|
|
|
2
2
|
import { EntityTypeSchemaGenerator } from '../src'
|
|
3
3
|
import { schemas } from './schemas'
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
describe('generate entities', () => {
|
|
7
|
-
|
|
8
6
|
const entityGenerator = new EntityTypeSchemaGenerator()
|
|
9
7
|
test('generate for scalars', () => {
|
|
10
|
-
|
|
11
8
|
expect(entityGenerator.generate(schemas.scalarsSchema.model)).toMatchSnapshot()
|
|
12
9
|
})
|
|
13
10
|
|
|
14
11
|
test('generate for has enum', () => {
|
|
15
|
-
|
|
16
12
|
expect(entityGenerator.generate(schemas.enumSchema.model)).toMatchSnapshot()
|
|
17
13
|
})
|
|
18
14
|
test('generate one has one', () => {
|
|
19
|
-
|
|
20
15
|
expect(entityGenerator.generate(schemas.oneHasOneSchema.model)).toMatchSnapshot()
|
|
21
16
|
})
|
|
22
17
|
|
|
23
18
|
test('generate one has many', () => {
|
|
24
|
-
|
|
25
19
|
expect(entityGenerator.generate(schemas.oneHasManySchema.model)).toMatchSnapshot()
|
|
26
20
|
})
|
|
27
21
|
|
|
28
22
|
test('generate many has many', () => {
|
|
29
|
-
|
|
30
23
|
expect(entityGenerator.generate(schemas.manyHasManySchema.model)).toMatchSnapshot()
|
|
31
24
|
})
|
|
32
25
|
|
|
33
26
|
test('generate reduced has by', () => {
|
|
34
|
-
|
|
35
27
|
expect(entityGenerator.generate(schemas.reducedHasManySchema.model)).toMatchSnapshot()
|
|
36
28
|
})
|
|
37
|
-
|
|
38
29
|
})
|
package/tests/schemas.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaDefinition as def
|
|
1
|
+
import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
|
|
2
2
|
|
|
3
3
|
namespace ManyScalarsSchema {
|
|
4
4
|
export class Foo {
|
|
@@ -13,7 +13,6 @@ namespace ManyScalarsSchema {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
namespace EnumSchema {
|
|
18
17
|
export class Foo {
|
|
19
18
|
enumCol = def.enumColumn(def.createEnum('foo', 'bar'))
|
|
@@ -40,7 +39,6 @@ namespace OneHasManySchema {
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
42
|
namespace ManyHasManySchema {
|
|
45
43
|
export class Foo {
|
|
46
44
|
manyHasManyRel = def.manyHasMany(Bar, 'manyHasManyInverseRel')
|