@contember/schema-utils 1.2.0-beta.1 → 1.2.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/src/definition-generator/TsDefinitionGenerator.d.ts +26 -0
- package/dist/src/definition-generator/TsDefinitionGenerator.d.ts.map +1 -0
- package/dist/src/definition-generator/TsDefinitionGenerator.js +246 -0
- package/dist/src/definition-generator/TsDefinitionGenerator.js.map +1 -0
- package/dist/src/definition-generator/index.d.ts +2 -0
- package/dist/src/definition-generator/index.d.ts.map +1 -0
- package/dist/src/definition-generator/index.js +18 -0
- package/dist/src/definition-generator/index.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lax/LaxSchemaConverter.d.ts +10 -0
- package/dist/src/lax/LaxSchemaConverter.d.ts.map +1 -0
- package/dist/src/lax/LaxSchemaConverter.js +204 -0
- package/dist/src/lax/LaxSchemaConverter.js.map +1 -0
- package/dist/src/lax/index.d.ts +3 -0
- package/dist/src/lax/index.d.ts.map +1 -0
- package/dist/src/lax/index.js +6 -0
- package/dist/src/lax/index.js.map +1 -0
- package/dist/src/lax/schema.d.ts +284 -0
- package/dist/src/lax/schema.d.ts.map +1 -0
- package/dist/src/lax/schema.js +67 -0
- package/dist/src/lax/schema.js.map +1 -0
- package/dist/src/model/NamingConventions.d.ts +17 -0
- package/dist/src/model/NamingConventions.d.ts.map +1 -0
- package/dist/src/model/NamingConventions.js +29 -0
- package/dist/src/model/NamingConventions.js.map +1 -0
- package/dist/src/model/index.d.ts +2 -0
- package/dist/src/model/index.d.ts.map +1 -1
- package/dist/src/model/index.js +2 -0
- package/dist/src/model/index.js.map +1 -1
- package/dist/src/model/resolveDefaultColumnType.d.ts +3 -0
- package/dist/src/model/resolveDefaultColumnType.d.ts.map +1 -0
- package/dist/src/model/resolveDefaultColumnType.js +29 -0
- package/dist/src/model/resolveDefaultColumnType.js.map +1 -0
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/type-schema/model.js +1 -1
- package/dist/src/type-schema/model.js.map +1 -1
- package/dist/tests/cases/unit/laxSchemaConverter.test.d.ts +2 -0
- package/dist/tests/cases/unit/laxSchemaConverter.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/laxSchemaConverter.test.js +118 -0
- package/dist/tests/cases/unit/laxSchemaConverter.test.js.map +1 -0
- package/dist/tests/cases/unit/schemas/basic.d.ts +5 -0
- package/dist/tests/cases/unit/schemas/basic.d.ts.map +1 -0
- package/dist/tests/cases/unit/schemas/basic.js +11 -0
- package/dist/tests/cases/unit/schemas/basic.js.map +1 -0
- package/dist/tests/cases/unit/schemas/enum.d.ts +7 -0
- package/dist/tests/cases/unit/schemas/enum.d.ts.map +1 -0
- package/dist/tests/cases/unit/schemas/enum.js +13 -0
- package/dist/tests/cases/unit/schemas/enum.js.map +1 -0
- package/dist/tests/cases/unit/schemas/relations.d.ts +15 -0
- package/dist/tests/cases/unit/schemas/relations.d.ts.map +1 -0
- package/dist/tests/cases/unit/schemas/relations.js +27 -0
- package/dist/tests/cases/unit/schemas/relations.js.map +1 -0
- package/dist/tests/cases/unit/schemas/unique.d.ts +5 -0
- package/dist/tests/cases/unit/schemas/unique.d.ts.map +1 -0
- package/dist/tests/cases/unit/schemas/unique.js +20 -0
- package/dist/tests/cases/unit/schemas/unique.js.map +1 -0
- package/dist/tests/cases/unit/tsDefinitionGenerator.test.d.ts +2 -0
- package/dist/tests/cases/unit/tsDefinitionGenerator.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/tsDefinitionGenerator.test.js +56 -0
- package/dist/tests/cases/unit/tsDefinitionGenerator.test.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/definition-generator/TsDefinitionGenerator.ts +275 -0
- package/src/definition-generator/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/lax/LaxSchemaConverter.ts +213 -0
- package/src/lax/index.ts +9 -0
- package/src/lax/schema.ts +62 -0
- package/src/model/NamingConventions.ts +53 -0
- package/src/model/index.ts +2 -0
- package/src/model/resolveDefaultColumnType.ts +25 -0
- package/src/type-schema/model.ts +1 -1
- package/tests/cases/unit/__snapshots__/laxSchemaConverter.test.ts.snap +310 -0
- package/tests/cases/unit/laxSchemaConverter.test.ts +137 -0
- package/tests/cases/unit/schemas/.eslintignore +1 -0
- package/tests/cases/unit/schemas/basic.ts +5 -0
- package/tests/cases/unit/schemas/enum.ts +8 -0
- package/tests/cases/unit/schemas/relations.ts +17 -0
- package/tests/cases/unit/schemas/unique.ts +6 -0
- package/tests/cases/unit/tsDefinitionGenerator.test.ts +31 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import * as Typesafe from '@contember/typesafe';
|
|
2
|
+
export declare const LaxSchemaField: Typesafe.Type<({
|
|
3
|
+
type: "string";
|
|
4
|
+
} & {
|
|
5
|
+
readonly notNull?: boolean | undefined;
|
|
6
|
+
readonly unique?: boolean | undefined;
|
|
7
|
+
}) | ({
|
|
8
|
+
type: "boolean";
|
|
9
|
+
} & {
|
|
10
|
+
readonly notNull?: boolean | undefined;
|
|
11
|
+
readonly unique?: boolean | undefined;
|
|
12
|
+
}) | ({
|
|
13
|
+
type: "manyHasManyInverse";
|
|
14
|
+
} & {
|
|
15
|
+
readonly targetEntity: string;
|
|
16
|
+
readonly targetField: string;
|
|
17
|
+
} & {
|
|
18
|
+
readonly notNull?: boolean | undefined;
|
|
19
|
+
}) | ({
|
|
20
|
+
type: "manyHasOne";
|
|
21
|
+
} & {
|
|
22
|
+
readonly targetEntity: string;
|
|
23
|
+
readonly targetField: string;
|
|
24
|
+
} & {
|
|
25
|
+
readonly notNull?: boolean | undefined;
|
|
26
|
+
}) | ({
|
|
27
|
+
type: "oneHasMany";
|
|
28
|
+
} & {
|
|
29
|
+
readonly targetEntity: string;
|
|
30
|
+
readonly targetField: string;
|
|
31
|
+
} & {
|
|
32
|
+
readonly notNull?: boolean | undefined;
|
|
33
|
+
}) | ({
|
|
34
|
+
type: "oneHasOneInverse";
|
|
35
|
+
} & {
|
|
36
|
+
readonly targetEntity: string;
|
|
37
|
+
readonly targetField: string;
|
|
38
|
+
} & {
|
|
39
|
+
readonly notNull?: boolean | undefined;
|
|
40
|
+
}) | ({
|
|
41
|
+
type: "date";
|
|
42
|
+
} & {
|
|
43
|
+
readonly notNull?: boolean | undefined;
|
|
44
|
+
readonly unique?: boolean | undefined;
|
|
45
|
+
}) | ({
|
|
46
|
+
type: "enum";
|
|
47
|
+
} & {
|
|
48
|
+
readonly values: readonly string[];
|
|
49
|
+
readonly enumName: string;
|
|
50
|
+
} & {
|
|
51
|
+
readonly notNull?: boolean | undefined;
|
|
52
|
+
readonly unique?: boolean | undefined;
|
|
53
|
+
}) | ({
|
|
54
|
+
type: "oneHasOne";
|
|
55
|
+
} & {
|
|
56
|
+
readonly targetEntity: string;
|
|
57
|
+
readonly targetField: string;
|
|
58
|
+
} & {
|
|
59
|
+
readonly notNull?: boolean | undefined;
|
|
60
|
+
}) | ({
|
|
61
|
+
type: "manyHasMany";
|
|
62
|
+
} & {
|
|
63
|
+
readonly targetEntity: string;
|
|
64
|
+
readonly targetField: string;
|
|
65
|
+
} & {
|
|
66
|
+
readonly notNull?: boolean | undefined;
|
|
67
|
+
}) | ({
|
|
68
|
+
type: "int";
|
|
69
|
+
} & {
|
|
70
|
+
readonly notNull?: boolean | undefined;
|
|
71
|
+
readonly unique?: boolean | undefined;
|
|
72
|
+
}) | ({
|
|
73
|
+
type: "float";
|
|
74
|
+
} & {
|
|
75
|
+
readonly notNull?: boolean | undefined;
|
|
76
|
+
readonly unique?: boolean | undefined;
|
|
77
|
+
}) | ({
|
|
78
|
+
type: "json";
|
|
79
|
+
} & {
|
|
80
|
+
readonly notNull?: boolean | undefined;
|
|
81
|
+
readonly unique?: boolean | undefined;
|
|
82
|
+
}) | ({
|
|
83
|
+
type: "datetime";
|
|
84
|
+
} & {
|
|
85
|
+
readonly notNull?: boolean | undefined;
|
|
86
|
+
readonly unique?: boolean | undefined;
|
|
87
|
+
})>;
|
|
88
|
+
export declare type LaxSchemaField = ReturnType<typeof LaxSchemaField>;
|
|
89
|
+
export declare type LaxSchemaEnum = Extract<LaxSchemaField, {
|
|
90
|
+
type: 'enum';
|
|
91
|
+
}>;
|
|
92
|
+
export declare type LaxSchemaColumn = Extract<LaxSchemaField, {
|
|
93
|
+
type: 'int' | 'float' | 'boolean' | 'string' | 'json' | 'datetime' | 'date' | 'uuid';
|
|
94
|
+
}>;
|
|
95
|
+
export declare type LaxSchemaRelation = Extract<LaxSchemaField, {
|
|
96
|
+
type: 'oneHasOne' | 'oneHasOneInverse' | 'manyHasMany' | 'manyHasManyInverse' | 'oneHasMany' | 'manyHasOne';
|
|
97
|
+
}>;
|
|
98
|
+
export declare const LaxSchemaEntity: Typesafe.Type<{
|
|
99
|
+
readonly fields: {
|
|
100
|
+
readonly [x: string]: ({
|
|
101
|
+
type: "string";
|
|
102
|
+
} & {
|
|
103
|
+
readonly notNull?: boolean | undefined;
|
|
104
|
+
readonly unique?: boolean | undefined;
|
|
105
|
+
}) | ({
|
|
106
|
+
type: "boolean";
|
|
107
|
+
} & {
|
|
108
|
+
readonly notNull?: boolean | undefined;
|
|
109
|
+
readonly unique?: boolean | undefined;
|
|
110
|
+
}) | ({
|
|
111
|
+
type: "manyHasManyInverse";
|
|
112
|
+
} & {
|
|
113
|
+
readonly targetEntity: string;
|
|
114
|
+
readonly targetField: string;
|
|
115
|
+
} & {
|
|
116
|
+
readonly notNull?: boolean | undefined;
|
|
117
|
+
}) | ({
|
|
118
|
+
type: "manyHasOne";
|
|
119
|
+
} & {
|
|
120
|
+
readonly targetEntity: string;
|
|
121
|
+
readonly targetField: string;
|
|
122
|
+
} & {
|
|
123
|
+
readonly notNull?: boolean | undefined;
|
|
124
|
+
}) | ({
|
|
125
|
+
type: "oneHasMany";
|
|
126
|
+
} & {
|
|
127
|
+
readonly targetEntity: string;
|
|
128
|
+
readonly targetField: string;
|
|
129
|
+
} & {
|
|
130
|
+
readonly notNull?: boolean | undefined;
|
|
131
|
+
}) | ({
|
|
132
|
+
type: "oneHasOneInverse";
|
|
133
|
+
} & {
|
|
134
|
+
readonly targetEntity: string;
|
|
135
|
+
readonly targetField: string;
|
|
136
|
+
} & {
|
|
137
|
+
readonly notNull?: boolean | undefined;
|
|
138
|
+
}) | ({
|
|
139
|
+
type: "date";
|
|
140
|
+
} & {
|
|
141
|
+
readonly notNull?: boolean | undefined;
|
|
142
|
+
readonly unique?: boolean | undefined;
|
|
143
|
+
}) | ({
|
|
144
|
+
type: "enum";
|
|
145
|
+
} & {
|
|
146
|
+
readonly values: readonly string[];
|
|
147
|
+
readonly enumName: string;
|
|
148
|
+
} & {
|
|
149
|
+
readonly notNull?: boolean | undefined;
|
|
150
|
+
readonly unique?: boolean | undefined;
|
|
151
|
+
}) | ({
|
|
152
|
+
type: "oneHasOne";
|
|
153
|
+
} & {
|
|
154
|
+
readonly targetEntity: string;
|
|
155
|
+
readonly targetField: string;
|
|
156
|
+
} & {
|
|
157
|
+
readonly notNull?: boolean | undefined;
|
|
158
|
+
}) | ({
|
|
159
|
+
type: "manyHasMany";
|
|
160
|
+
} & {
|
|
161
|
+
readonly targetEntity: string;
|
|
162
|
+
readonly targetField: string;
|
|
163
|
+
} & {
|
|
164
|
+
readonly notNull?: boolean | undefined;
|
|
165
|
+
}) | ({
|
|
166
|
+
type: "int";
|
|
167
|
+
} & {
|
|
168
|
+
readonly notNull?: boolean | undefined;
|
|
169
|
+
readonly unique?: boolean | undefined;
|
|
170
|
+
}) | ({
|
|
171
|
+
type: "float";
|
|
172
|
+
} & {
|
|
173
|
+
readonly notNull?: boolean | undefined;
|
|
174
|
+
readonly unique?: boolean | undefined;
|
|
175
|
+
}) | ({
|
|
176
|
+
type: "json";
|
|
177
|
+
} & {
|
|
178
|
+
readonly notNull?: boolean | undefined;
|
|
179
|
+
readonly unique?: boolean | undefined;
|
|
180
|
+
}) | ({
|
|
181
|
+
type: "datetime";
|
|
182
|
+
} & {
|
|
183
|
+
readonly notNull?: boolean | undefined;
|
|
184
|
+
readonly unique?: boolean | undefined;
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
}>;
|
|
188
|
+
export declare type LaxSchemaEntity = ReturnType<typeof LaxSchemaEntity>;
|
|
189
|
+
export declare const LaxSchema: Typesafe.Type<{
|
|
190
|
+
readonly entities: {
|
|
191
|
+
readonly [x: string]: {
|
|
192
|
+
readonly fields: {
|
|
193
|
+
readonly [x: string]: ({
|
|
194
|
+
type: "string";
|
|
195
|
+
} & {
|
|
196
|
+
readonly notNull?: boolean | undefined;
|
|
197
|
+
readonly unique?: boolean | undefined;
|
|
198
|
+
}) | ({
|
|
199
|
+
type: "boolean";
|
|
200
|
+
} & {
|
|
201
|
+
readonly notNull?: boolean | undefined;
|
|
202
|
+
readonly unique?: boolean | undefined;
|
|
203
|
+
}) | ({
|
|
204
|
+
type: "manyHasManyInverse";
|
|
205
|
+
} & {
|
|
206
|
+
readonly targetEntity: string;
|
|
207
|
+
readonly targetField: string;
|
|
208
|
+
} & {
|
|
209
|
+
readonly notNull?: boolean | undefined;
|
|
210
|
+
}) | ({
|
|
211
|
+
type: "manyHasOne";
|
|
212
|
+
} & {
|
|
213
|
+
readonly targetEntity: string;
|
|
214
|
+
readonly targetField: string;
|
|
215
|
+
} & {
|
|
216
|
+
readonly notNull?: boolean | undefined;
|
|
217
|
+
}) | ({
|
|
218
|
+
type: "oneHasMany";
|
|
219
|
+
} & {
|
|
220
|
+
readonly targetEntity: string;
|
|
221
|
+
readonly targetField: string;
|
|
222
|
+
} & {
|
|
223
|
+
readonly notNull?: boolean | undefined;
|
|
224
|
+
}) | ({
|
|
225
|
+
type: "oneHasOneInverse";
|
|
226
|
+
} & {
|
|
227
|
+
readonly targetEntity: string;
|
|
228
|
+
readonly targetField: string;
|
|
229
|
+
} & {
|
|
230
|
+
readonly notNull?: boolean | undefined;
|
|
231
|
+
}) | ({
|
|
232
|
+
type: "date";
|
|
233
|
+
} & {
|
|
234
|
+
readonly notNull?: boolean | undefined;
|
|
235
|
+
readonly unique?: boolean | undefined;
|
|
236
|
+
}) | ({
|
|
237
|
+
type: "enum";
|
|
238
|
+
} & {
|
|
239
|
+
readonly values: readonly string[];
|
|
240
|
+
readonly enumName: string;
|
|
241
|
+
} & {
|
|
242
|
+
readonly notNull?: boolean | undefined;
|
|
243
|
+
readonly unique?: boolean | undefined;
|
|
244
|
+
}) | ({
|
|
245
|
+
type: "oneHasOne";
|
|
246
|
+
} & {
|
|
247
|
+
readonly targetEntity: string;
|
|
248
|
+
readonly targetField: string;
|
|
249
|
+
} & {
|
|
250
|
+
readonly notNull?: boolean | undefined;
|
|
251
|
+
}) | ({
|
|
252
|
+
type: "manyHasMany";
|
|
253
|
+
} & {
|
|
254
|
+
readonly targetEntity: string;
|
|
255
|
+
readonly targetField: string;
|
|
256
|
+
} & {
|
|
257
|
+
readonly notNull?: boolean | undefined;
|
|
258
|
+
}) | ({
|
|
259
|
+
type: "int";
|
|
260
|
+
} & {
|
|
261
|
+
readonly notNull?: boolean | undefined;
|
|
262
|
+
readonly unique?: boolean | undefined;
|
|
263
|
+
}) | ({
|
|
264
|
+
type: "float";
|
|
265
|
+
} & {
|
|
266
|
+
readonly notNull?: boolean | undefined;
|
|
267
|
+
readonly unique?: boolean | undefined;
|
|
268
|
+
}) | ({
|
|
269
|
+
type: "json";
|
|
270
|
+
} & {
|
|
271
|
+
readonly notNull?: boolean | undefined;
|
|
272
|
+
readonly unique?: boolean | undefined;
|
|
273
|
+
}) | ({
|
|
274
|
+
type: "datetime";
|
|
275
|
+
} & {
|
|
276
|
+
readonly notNull?: boolean | undefined;
|
|
277
|
+
readonly unique?: boolean | undefined;
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
}>;
|
|
283
|
+
export declare type LaxSchema = ReturnType<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U,CAAC,OAAO,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LaxSchema = exports.LaxSchemaEntity = exports.LaxSchemaField = void 0;
|
|
27
|
+
const Typesafe = __importStar(require("@contember/typesafe"));
|
|
28
|
+
const LaxSchemaEnumInner = Typesafe.intersection(Typesafe.object({
|
|
29
|
+
values: Typesafe.array(Typesafe.string),
|
|
30
|
+
enumName: Typesafe.string,
|
|
31
|
+
}), Typesafe.partial({
|
|
32
|
+
notNull: Typesafe.boolean,
|
|
33
|
+
unique: Typesafe.boolean,
|
|
34
|
+
}));
|
|
35
|
+
const LaxSchemaColumnInner = Typesafe.partial({
|
|
36
|
+
notNull: Typesafe.boolean,
|
|
37
|
+
unique: Typesafe.boolean,
|
|
38
|
+
});
|
|
39
|
+
const LaxSchemaRelationInner = Typesafe.intersection(Typesafe.object({
|
|
40
|
+
targetEntity: Typesafe.string,
|
|
41
|
+
targetField: Typesafe.string,
|
|
42
|
+
}), Typesafe.partial({
|
|
43
|
+
notNull: Typesafe.boolean,
|
|
44
|
+
}));
|
|
45
|
+
exports.LaxSchemaField = Typesafe.discriminatedUnion('type', {
|
|
46
|
+
oneHasOne: LaxSchemaRelationInner,
|
|
47
|
+
oneHasOneInverse: LaxSchemaRelationInner,
|
|
48
|
+
manyHasMany: LaxSchemaRelationInner,
|
|
49
|
+
manyHasManyInverse: LaxSchemaRelationInner,
|
|
50
|
+
oneHasMany: LaxSchemaRelationInner,
|
|
51
|
+
manyHasOne: LaxSchemaRelationInner,
|
|
52
|
+
int: LaxSchemaColumnInner,
|
|
53
|
+
float: LaxSchemaColumnInner,
|
|
54
|
+
boolean: LaxSchemaColumnInner,
|
|
55
|
+
string: LaxSchemaColumnInner,
|
|
56
|
+
json: LaxSchemaColumnInner,
|
|
57
|
+
date: LaxSchemaColumnInner,
|
|
58
|
+
datetime: LaxSchemaColumnInner,
|
|
59
|
+
enum: LaxSchemaEnumInner,
|
|
60
|
+
});
|
|
61
|
+
exports.LaxSchemaEntity = Typesafe.object({
|
|
62
|
+
fields: Typesafe.record(Typesafe.string, exports.LaxSchemaField),
|
|
63
|
+
});
|
|
64
|
+
exports.LaxSchema = Typesafe.object({
|
|
65
|
+
entities: Typesafe.record(Typesafe.string, exports.LaxSchemaEntity),
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/lax/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAA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,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,sBAAc,CAAC;CACxD,CAAC,CAAA;AAGW,QAAA,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC;IACxC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CACxB,QAAQ,CAAC,MAAM,EACf,uBAAe,CACf;CACD,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface NamingConventions {
|
|
2
|
+
getPrimaryField(): string;
|
|
3
|
+
getColumnName(fieldName: string): string;
|
|
4
|
+
getTableName(entityName: string): string;
|
|
5
|
+
getJoiningColumnName(relationName: string): string;
|
|
6
|
+
getJoiningTableName(entity: string, relation: string): string;
|
|
7
|
+
getJoiningTableColumnNames(owningEntity: string, owningRelation: string, inverseEntity: string, inverseRelation?: string): [string, string];
|
|
8
|
+
}
|
|
9
|
+
export declare class DefaultNamingConventions implements NamingConventions {
|
|
10
|
+
getPrimaryField(): string;
|
|
11
|
+
getColumnName(fieldName: string): string;
|
|
12
|
+
getTableName(entityName: string): string;
|
|
13
|
+
getJoiningColumnName(relationName: string): string;
|
|
14
|
+
getJoiningTableName(entity: string, relation: string): string;
|
|
15
|
+
getJoiningTableColumnNames(owningEntity: string, owningRelation: string, inverseEntity: string, inverseRelation?: string): [string, string];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=NamingConventions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NamingConventions.d.ts","sourceRoot":"","sources":["../../../src/model/NamingConventions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IACjC,eAAe,IAAI,MAAM,CAAA;IAEzB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;IAExC,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;IAExC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAA;IAElD,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IAE7D,0BAA0B,CACzB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,GACtB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACnB;AAGD,qBAAa,wBAAyB,YAAW,iBAAiB;IACjE,eAAe,IAAI,MAAM;IAIzB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAIxC,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAIxC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAIlD,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI7D,0BAA0B,CACzB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,GACtB,CAAC,MAAM,EAAE,MAAM,CAAC;CAMnB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultNamingConventions = void 0;
|
|
4
|
+
const toUnderscore = (s) => s.replace(/([A-Z]+)/g, (x, y) => '_' + y.toLowerCase()).replace(/^_/, '');
|
|
5
|
+
class DefaultNamingConventions {
|
|
6
|
+
getPrimaryField() {
|
|
7
|
+
return 'id';
|
|
8
|
+
}
|
|
9
|
+
getColumnName(fieldName) {
|
|
10
|
+
return toUnderscore(fieldName);
|
|
11
|
+
}
|
|
12
|
+
getTableName(entityName) {
|
|
13
|
+
return toUnderscore(entityName);
|
|
14
|
+
}
|
|
15
|
+
getJoiningColumnName(relationName) {
|
|
16
|
+
return toUnderscore(relationName) + '_id';
|
|
17
|
+
}
|
|
18
|
+
getJoiningTableName(entity, relation) {
|
|
19
|
+
return toUnderscore(entity) + '_' + toUnderscore(relation);
|
|
20
|
+
}
|
|
21
|
+
getJoiningTableColumnNames(owningEntity, owningRelation, inverseEntity, inverseRelation) {
|
|
22
|
+
return [
|
|
23
|
+
toUnderscore(owningEntity) + '_id',
|
|
24
|
+
toUnderscore(inverseEntity === owningEntity ? owningRelation : inverseEntity) + '_id',
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.DefaultNamingConventions = DefaultNamingConventions;
|
|
29
|
+
//# sourceMappingURL=NamingConventions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NamingConventions.js","sourceRoot":"","sources":["../../../src/model/NamingConventions.ts"],"names":[],"mappings":";;;AAmBA,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AAC7G,MAAa,wBAAwB;IACpC,eAAe;QACd,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,aAAa,CAAC,SAAiB;QAC9B,OAAO,YAAY,CAAC,SAAS,CAAC,CAAA;IAC/B,CAAC;IAED,YAAY,CAAC,UAAkB;QAC9B,OAAO,YAAY,CAAC,UAAU,CAAC,CAAA;IAChC,CAAC;IAED,oBAAoB,CAAC,YAAoB;QACxC,OAAO,YAAY,CAAC,YAAY,CAAC,GAAG,KAAK,CAAA;IAC1C,CAAC;IAED,mBAAmB,CAAC,MAAc,EAAE,QAAgB;QACnD,OAAO,YAAY,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;IAC3D,CAAC;IAED,0BAA0B,CACzB,YAAoB,EACpB,cAAsB,EACtB,aAAqB,EACrB,eAAwB;QAExB,OAAO;YACN,YAAY,CAAC,YAAY,CAAC,GAAG,KAAK;YAClC,YAAY,CAAC,aAAa,KAAK,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,KAAK;SACrF,CAAA;IACF,CAAC;CACD;AAhCD,4DAgCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qBAAqB,CAAA"}
|
package/dist/src/model/index.js
CHANGED
|
@@ -16,4 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./modelUtils"), exports);
|
|
18
18
|
__exportStar(require("./NamingHelper"), exports);
|
|
19
|
+
__exportStar(require("./resolveDefaultColumnType"), exports);
|
|
20
|
+
__exportStar(require("./NamingConventions"), exports);
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,iDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,iDAA8B;AAC9B,6DAA0C;AAC1C,sDAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultColumnType.d.ts","sourceRoot":"","sources":["../../../src/model/resolveDefaultColumnType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzC,eAAO,MAAM,wBAAwB,SAAU,QAAQ,MAAM,UAAU,EAAE,MAAM,UAAU,CAAC,IAAI,CAAC,KAAG,MAqBjG,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDefaultColumnType = void 0;
|
|
4
|
+
const schema_1 = require("@contember/schema");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const resolveDefaultColumnType = (type) => {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case schema_1.Model.ColumnType.Int:
|
|
9
|
+
return 'integer';
|
|
10
|
+
case schema_1.Model.ColumnType.Double:
|
|
11
|
+
return 'double precision';
|
|
12
|
+
case schema_1.Model.ColumnType.String:
|
|
13
|
+
return 'text';
|
|
14
|
+
case schema_1.Model.ColumnType.Uuid:
|
|
15
|
+
return 'uuid';
|
|
16
|
+
case schema_1.Model.ColumnType.Bool:
|
|
17
|
+
return 'boolean';
|
|
18
|
+
case schema_1.Model.ColumnType.DateTime:
|
|
19
|
+
return 'timestamptz';
|
|
20
|
+
case schema_1.Model.ColumnType.Date:
|
|
21
|
+
return 'date';
|
|
22
|
+
case schema_1.Model.ColumnType.Json:
|
|
23
|
+
return 'jsonb';
|
|
24
|
+
default:
|
|
25
|
+
return (0, utils_1.assertNever)(type);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.resolveDefaultColumnType = resolveDefaultColumnType;
|
|
29
|
+
//# sourceMappingURL=resolveDefaultColumnType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultColumnType.js","sourceRoot":"","sources":["../../../src/model/resolveDefaultColumnType.ts"],"names":[],"mappings":";;;AAAA,8CAAyC;AACzC,oCAAsC;AAE/B,MAAM,wBAAwB,GAAG,CAAC,IAAsD,EAAU,EAAE;IAC1G,QAAQ,IAAI,EAAE;QACb,KAAK,cAAK,CAAC,UAAU,CAAC,GAAG;YACxB,OAAO,SAAS,CAAA;QACjB,KAAK,cAAK,CAAC,UAAU,CAAC,MAAM;YAC3B,OAAO,kBAAkB,CAAA;QAC1B,KAAK,cAAK,CAAC,UAAU,CAAC,MAAM;YAC3B,OAAO,MAAM,CAAA;QACd,KAAK,cAAK,CAAC,UAAU,CAAC,IAAI;YACzB,OAAO,MAAM,CAAA;QACd,KAAK,cAAK,CAAC,UAAU,CAAC,IAAI;YACzB,OAAO,SAAS,CAAA;QACjB,KAAK,cAAK,CAAC,UAAU,CAAC,QAAQ;YAC7B,OAAO,aAAa,CAAA;QACrB,KAAK,cAAK,CAAC,UAAU,CAAC,IAAI;YACzB,OAAO,MAAM,CAAA;QACd,KAAK,cAAK,CAAC,UAAU,CAAC,IAAI;YACzB,OAAO,OAAO,CAAA;QACf;YACC,OAAO,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAA;KACzB;AACF,CAAC,CAAA;AArBY,QAAA,wBAAwB,4BAqBpC"}
|