@zenstackhq/sdk 3.0.0-beta.8 → 3.0.0-beta.9
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/expression-Ce_oulwU.d.cts +44 -0
- package/dist/expression-Ce_oulwU.d.ts +44 -0
- package/dist/index.cjs +375 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -1
- package/dist/index.d.ts +114 -1
- package/dist/index.js +373 -9
- package/dist/index.js.map +1 -1
- package/dist/schema.d.cts +3 -44
- package/dist/schema.d.ts +3 -44
- package/package.json +5 -5
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
2
|
+
type LiteralExpression = {
|
|
3
|
+
kind: 'literal';
|
|
4
|
+
value: string | number | boolean;
|
|
5
|
+
};
|
|
6
|
+
type ArrayExpression = {
|
|
7
|
+
kind: 'array';
|
|
8
|
+
items: Expression[];
|
|
9
|
+
};
|
|
10
|
+
type FieldExpression = {
|
|
11
|
+
kind: 'field';
|
|
12
|
+
field: string;
|
|
13
|
+
};
|
|
14
|
+
type MemberExpression = {
|
|
15
|
+
kind: 'member';
|
|
16
|
+
receiver: Expression;
|
|
17
|
+
members: string[];
|
|
18
|
+
};
|
|
19
|
+
type UnaryExpression = {
|
|
20
|
+
kind: 'unary';
|
|
21
|
+
op: UnaryOperator;
|
|
22
|
+
operand: Expression;
|
|
23
|
+
};
|
|
24
|
+
type BinaryExpression = {
|
|
25
|
+
kind: 'binary';
|
|
26
|
+
op: BinaryOperator;
|
|
27
|
+
left: Expression;
|
|
28
|
+
right: Expression;
|
|
29
|
+
};
|
|
30
|
+
type CallExpression = {
|
|
31
|
+
kind: 'call';
|
|
32
|
+
function: string;
|
|
33
|
+
args?: Expression[];
|
|
34
|
+
};
|
|
35
|
+
type ThisExpression = {
|
|
36
|
+
kind: 'this';
|
|
37
|
+
};
|
|
38
|
+
type NullExpression = {
|
|
39
|
+
kind: 'null';
|
|
40
|
+
};
|
|
41
|
+
type UnaryOperator = '!';
|
|
42
|
+
type BinaryOperator = '&&' | '||' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '?' | '!' | '^' | 'in';
|
|
43
|
+
|
|
44
|
+
export type { ArrayExpression as A, BinaryExpression as B, CallExpression as C, Expression as E, FieldExpression as F, LiteralExpression as L, MemberExpression as M, NullExpression as N, ThisExpression as T, UnaryExpression as U, UnaryOperator as a, BinaryOperator as b };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
2
|
+
type LiteralExpression = {
|
|
3
|
+
kind: 'literal';
|
|
4
|
+
value: string | number | boolean;
|
|
5
|
+
};
|
|
6
|
+
type ArrayExpression = {
|
|
7
|
+
kind: 'array';
|
|
8
|
+
items: Expression[];
|
|
9
|
+
};
|
|
10
|
+
type FieldExpression = {
|
|
11
|
+
kind: 'field';
|
|
12
|
+
field: string;
|
|
13
|
+
};
|
|
14
|
+
type MemberExpression = {
|
|
15
|
+
kind: 'member';
|
|
16
|
+
receiver: Expression;
|
|
17
|
+
members: string[];
|
|
18
|
+
};
|
|
19
|
+
type UnaryExpression = {
|
|
20
|
+
kind: 'unary';
|
|
21
|
+
op: UnaryOperator;
|
|
22
|
+
operand: Expression;
|
|
23
|
+
};
|
|
24
|
+
type BinaryExpression = {
|
|
25
|
+
kind: 'binary';
|
|
26
|
+
op: BinaryOperator;
|
|
27
|
+
left: Expression;
|
|
28
|
+
right: Expression;
|
|
29
|
+
};
|
|
30
|
+
type CallExpression = {
|
|
31
|
+
kind: 'call';
|
|
32
|
+
function: string;
|
|
33
|
+
args?: Expression[];
|
|
34
|
+
};
|
|
35
|
+
type ThisExpression = {
|
|
36
|
+
kind: 'this';
|
|
37
|
+
};
|
|
38
|
+
type NullExpression = {
|
|
39
|
+
kind: 'null';
|
|
40
|
+
};
|
|
41
|
+
type UnaryOperator = '!';
|
|
42
|
+
type BinaryOperator = '&&' | '||' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '?' | '!' | '^' | 'in';
|
|
43
|
+
|
|
44
|
+
export type { ArrayExpression as A, BinaryExpression as B, CallExpression as C, Expression as E, FieldExpression as F, LiteralExpression as L, MemberExpression as M, NullExpression as N, ThisExpression as T, UnaryExpression as U, UnaryOperator as a, BinaryOperator as b };
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
+
DefaultOperationNodeVisitor: () => DefaultOperationNodeVisitor,
|
|
35
|
+
ExpressionVisitor: () => ExpressionVisitor,
|
|
34
36
|
ModelUtils: () => model_utils_exports,
|
|
35
37
|
PrismaSchemaGenerator: () => PrismaSchemaGenerator,
|
|
36
38
|
TsSchemaGenerator: () => TsSchemaGenerator,
|
|
@@ -134,12 +136,365 @@ function getIdFields(dm) {
|
|
|
134
136
|
__name(getIdFields, "getIdFields");
|
|
135
137
|
var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
|
|
136
138
|
|
|
139
|
+
// src/expression-utils.ts
|
|
140
|
+
var import_ts_pattern = require("ts-pattern");
|
|
141
|
+
var ExpressionVisitor = class {
|
|
142
|
+
static {
|
|
143
|
+
__name(this, "ExpressionVisitor");
|
|
144
|
+
}
|
|
145
|
+
visit(expr) {
|
|
146
|
+
(0, import_ts_pattern.match)(expr).with({
|
|
147
|
+
kind: "literal"
|
|
148
|
+
}, (e) => this.visitLiteral(e)).with({
|
|
149
|
+
kind: "array"
|
|
150
|
+
}, (e) => this.visitArray(e)).with({
|
|
151
|
+
kind: "field"
|
|
152
|
+
}, (e) => this.visitField(e)).with({
|
|
153
|
+
kind: "member"
|
|
154
|
+
}, (e) => this.visitMember(e)).with({
|
|
155
|
+
kind: "binary"
|
|
156
|
+
}, (e) => this.visitBinary(e)).with({
|
|
157
|
+
kind: "unary"
|
|
158
|
+
}, (e) => this.visitUnary(e)).with({
|
|
159
|
+
kind: "call"
|
|
160
|
+
}, (e) => this.visitCall(e)).with({
|
|
161
|
+
kind: "this"
|
|
162
|
+
}, (e) => this.visitThis(e)).with({
|
|
163
|
+
kind: "null"
|
|
164
|
+
}, (e) => this.visitNull(e)).exhaustive();
|
|
165
|
+
}
|
|
166
|
+
visitLiteral(_e) {
|
|
167
|
+
}
|
|
168
|
+
visitArray(e) {
|
|
169
|
+
e.items.forEach((item) => this.visit(item));
|
|
170
|
+
}
|
|
171
|
+
visitField(_e) {
|
|
172
|
+
}
|
|
173
|
+
visitMember(e) {
|
|
174
|
+
this.visit(e.receiver);
|
|
175
|
+
}
|
|
176
|
+
visitBinary(e) {
|
|
177
|
+
this.visit(e.left);
|
|
178
|
+
this.visit(e.right);
|
|
179
|
+
}
|
|
180
|
+
visitUnary(e) {
|
|
181
|
+
this.visit(e.operand);
|
|
182
|
+
}
|
|
183
|
+
visitCall(e) {
|
|
184
|
+
e.args?.forEach((arg) => this.visit(arg));
|
|
185
|
+
}
|
|
186
|
+
visitThis(_e) {
|
|
187
|
+
}
|
|
188
|
+
visitNull(_e) {
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/default-operation-node-visitor.ts
|
|
193
|
+
var import_kysely = require("kysely");
|
|
194
|
+
var DefaultOperationNodeVisitor = class extends import_kysely.OperationNodeVisitor {
|
|
195
|
+
static {
|
|
196
|
+
__name(this, "DefaultOperationNodeVisitor");
|
|
197
|
+
}
|
|
198
|
+
defaultVisit(node) {
|
|
199
|
+
Object.values(node).forEach((value) => {
|
|
200
|
+
if (!value) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (Array.isArray(value)) {
|
|
204
|
+
value.forEach((el) => this.defaultVisit(el));
|
|
205
|
+
}
|
|
206
|
+
if (typeof value === "object" && "kind" in value && typeof value.kind === "string") {
|
|
207
|
+
this.visitNode(value);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
visitSelectQuery(node) {
|
|
212
|
+
this.defaultVisit(node);
|
|
213
|
+
}
|
|
214
|
+
visitSelection(node) {
|
|
215
|
+
this.defaultVisit(node);
|
|
216
|
+
}
|
|
217
|
+
visitColumn(node) {
|
|
218
|
+
this.defaultVisit(node);
|
|
219
|
+
}
|
|
220
|
+
visitAlias(node) {
|
|
221
|
+
this.defaultVisit(node);
|
|
222
|
+
}
|
|
223
|
+
visitTable(node) {
|
|
224
|
+
this.defaultVisit(node);
|
|
225
|
+
}
|
|
226
|
+
visitFrom(node) {
|
|
227
|
+
this.defaultVisit(node);
|
|
228
|
+
}
|
|
229
|
+
visitReference(node) {
|
|
230
|
+
this.defaultVisit(node);
|
|
231
|
+
}
|
|
232
|
+
visitAnd(node) {
|
|
233
|
+
this.defaultVisit(node);
|
|
234
|
+
}
|
|
235
|
+
visitOr(node) {
|
|
236
|
+
this.defaultVisit(node);
|
|
237
|
+
}
|
|
238
|
+
visitValueList(node) {
|
|
239
|
+
this.defaultVisit(node);
|
|
240
|
+
}
|
|
241
|
+
visitParens(node) {
|
|
242
|
+
this.defaultVisit(node);
|
|
243
|
+
}
|
|
244
|
+
visitJoin(node) {
|
|
245
|
+
this.defaultVisit(node);
|
|
246
|
+
}
|
|
247
|
+
visitRaw(node) {
|
|
248
|
+
this.defaultVisit(node);
|
|
249
|
+
}
|
|
250
|
+
visitWhere(node) {
|
|
251
|
+
this.defaultVisit(node);
|
|
252
|
+
}
|
|
253
|
+
visitInsertQuery(node) {
|
|
254
|
+
this.defaultVisit(node);
|
|
255
|
+
}
|
|
256
|
+
visitDeleteQuery(node) {
|
|
257
|
+
this.defaultVisit(node);
|
|
258
|
+
}
|
|
259
|
+
visitReturning(node) {
|
|
260
|
+
this.defaultVisit(node);
|
|
261
|
+
}
|
|
262
|
+
visitCreateTable(node) {
|
|
263
|
+
this.defaultVisit(node);
|
|
264
|
+
}
|
|
265
|
+
visitAddColumn(node) {
|
|
266
|
+
this.defaultVisit(node);
|
|
267
|
+
}
|
|
268
|
+
visitColumnDefinition(node) {
|
|
269
|
+
this.defaultVisit(node);
|
|
270
|
+
}
|
|
271
|
+
visitDropTable(node) {
|
|
272
|
+
this.defaultVisit(node);
|
|
273
|
+
}
|
|
274
|
+
visitOrderBy(node) {
|
|
275
|
+
this.defaultVisit(node);
|
|
276
|
+
}
|
|
277
|
+
visitOrderByItem(node) {
|
|
278
|
+
this.defaultVisit(node);
|
|
279
|
+
}
|
|
280
|
+
visitGroupBy(node) {
|
|
281
|
+
this.defaultVisit(node);
|
|
282
|
+
}
|
|
283
|
+
visitGroupByItem(node) {
|
|
284
|
+
this.defaultVisit(node);
|
|
285
|
+
}
|
|
286
|
+
visitUpdateQuery(node) {
|
|
287
|
+
this.defaultVisit(node);
|
|
288
|
+
}
|
|
289
|
+
visitColumnUpdate(node) {
|
|
290
|
+
this.defaultVisit(node);
|
|
291
|
+
}
|
|
292
|
+
visitLimit(node) {
|
|
293
|
+
this.defaultVisit(node);
|
|
294
|
+
}
|
|
295
|
+
visitOffset(node) {
|
|
296
|
+
this.defaultVisit(node);
|
|
297
|
+
}
|
|
298
|
+
visitOnConflict(node) {
|
|
299
|
+
this.defaultVisit(node);
|
|
300
|
+
}
|
|
301
|
+
visitOnDuplicateKey(node) {
|
|
302
|
+
this.defaultVisit(node);
|
|
303
|
+
}
|
|
304
|
+
visitCheckConstraint(node) {
|
|
305
|
+
this.defaultVisit(node);
|
|
306
|
+
}
|
|
307
|
+
visitDataType(node) {
|
|
308
|
+
this.defaultVisit(node);
|
|
309
|
+
}
|
|
310
|
+
visitSelectAll(node) {
|
|
311
|
+
this.defaultVisit(node);
|
|
312
|
+
}
|
|
313
|
+
visitIdentifier(node) {
|
|
314
|
+
this.defaultVisit(node);
|
|
315
|
+
}
|
|
316
|
+
visitSchemableIdentifier(node) {
|
|
317
|
+
this.defaultVisit(node);
|
|
318
|
+
}
|
|
319
|
+
visitValue(node) {
|
|
320
|
+
this.defaultVisit(node);
|
|
321
|
+
}
|
|
322
|
+
visitPrimitiveValueList(node) {
|
|
323
|
+
this.defaultVisit(node);
|
|
324
|
+
}
|
|
325
|
+
visitOperator(node) {
|
|
326
|
+
this.defaultVisit(node);
|
|
327
|
+
}
|
|
328
|
+
visitCreateIndex(node) {
|
|
329
|
+
this.defaultVisit(node);
|
|
330
|
+
}
|
|
331
|
+
visitDropIndex(node) {
|
|
332
|
+
this.defaultVisit(node);
|
|
333
|
+
}
|
|
334
|
+
visitList(node) {
|
|
335
|
+
this.defaultVisit(node);
|
|
336
|
+
}
|
|
337
|
+
visitPrimaryKeyConstraint(node) {
|
|
338
|
+
this.defaultVisit(node);
|
|
339
|
+
}
|
|
340
|
+
visitUniqueConstraint(node) {
|
|
341
|
+
this.defaultVisit(node);
|
|
342
|
+
}
|
|
343
|
+
visitReferences(node) {
|
|
344
|
+
this.defaultVisit(node);
|
|
345
|
+
}
|
|
346
|
+
visitWith(node) {
|
|
347
|
+
this.defaultVisit(node);
|
|
348
|
+
}
|
|
349
|
+
visitCommonTableExpression(node) {
|
|
350
|
+
this.defaultVisit(node);
|
|
351
|
+
}
|
|
352
|
+
visitCommonTableExpressionName(node) {
|
|
353
|
+
this.defaultVisit(node);
|
|
354
|
+
}
|
|
355
|
+
visitHaving(node) {
|
|
356
|
+
this.defaultVisit(node);
|
|
357
|
+
}
|
|
358
|
+
visitCreateSchema(node) {
|
|
359
|
+
this.defaultVisit(node);
|
|
360
|
+
}
|
|
361
|
+
visitDropSchema(node) {
|
|
362
|
+
this.defaultVisit(node);
|
|
363
|
+
}
|
|
364
|
+
visitAlterTable(node) {
|
|
365
|
+
this.defaultVisit(node);
|
|
366
|
+
}
|
|
367
|
+
visitDropColumn(node) {
|
|
368
|
+
this.defaultVisit(node);
|
|
369
|
+
}
|
|
370
|
+
visitRenameColumn(node) {
|
|
371
|
+
this.defaultVisit(node);
|
|
372
|
+
}
|
|
373
|
+
visitAlterColumn(node) {
|
|
374
|
+
this.defaultVisit(node);
|
|
375
|
+
}
|
|
376
|
+
visitModifyColumn(node) {
|
|
377
|
+
this.defaultVisit(node);
|
|
378
|
+
}
|
|
379
|
+
visitAddConstraint(node) {
|
|
380
|
+
this.defaultVisit(node);
|
|
381
|
+
}
|
|
382
|
+
visitDropConstraint(node) {
|
|
383
|
+
this.defaultVisit(node);
|
|
384
|
+
}
|
|
385
|
+
visitForeignKeyConstraint(node) {
|
|
386
|
+
this.defaultVisit(node);
|
|
387
|
+
}
|
|
388
|
+
visitCreateView(node) {
|
|
389
|
+
this.defaultVisit(node);
|
|
390
|
+
}
|
|
391
|
+
visitDropView(node) {
|
|
392
|
+
this.defaultVisit(node);
|
|
393
|
+
}
|
|
394
|
+
visitGenerated(node) {
|
|
395
|
+
this.defaultVisit(node);
|
|
396
|
+
}
|
|
397
|
+
visitDefaultValue(node) {
|
|
398
|
+
this.defaultVisit(node);
|
|
399
|
+
}
|
|
400
|
+
visitOn(node) {
|
|
401
|
+
this.defaultVisit(node);
|
|
402
|
+
}
|
|
403
|
+
visitValues(node) {
|
|
404
|
+
this.defaultVisit(node);
|
|
405
|
+
}
|
|
406
|
+
visitSelectModifier(node) {
|
|
407
|
+
this.defaultVisit(node);
|
|
408
|
+
}
|
|
409
|
+
visitCreateType(node) {
|
|
410
|
+
this.defaultVisit(node);
|
|
411
|
+
}
|
|
412
|
+
visitDropType(node) {
|
|
413
|
+
this.defaultVisit(node);
|
|
414
|
+
}
|
|
415
|
+
visitExplain(node) {
|
|
416
|
+
this.defaultVisit(node);
|
|
417
|
+
}
|
|
418
|
+
visitDefaultInsertValue(node) {
|
|
419
|
+
this.defaultVisit(node);
|
|
420
|
+
}
|
|
421
|
+
visitAggregateFunction(node) {
|
|
422
|
+
this.defaultVisit(node);
|
|
423
|
+
}
|
|
424
|
+
visitOver(node) {
|
|
425
|
+
this.defaultVisit(node);
|
|
426
|
+
}
|
|
427
|
+
visitPartitionBy(node) {
|
|
428
|
+
this.defaultVisit(node);
|
|
429
|
+
}
|
|
430
|
+
visitPartitionByItem(node) {
|
|
431
|
+
this.defaultVisit(node);
|
|
432
|
+
}
|
|
433
|
+
visitSetOperation(node) {
|
|
434
|
+
this.defaultVisit(node);
|
|
435
|
+
}
|
|
436
|
+
visitBinaryOperation(node) {
|
|
437
|
+
this.defaultVisit(node);
|
|
438
|
+
}
|
|
439
|
+
visitUnaryOperation(node) {
|
|
440
|
+
this.defaultVisit(node);
|
|
441
|
+
}
|
|
442
|
+
visitUsing(node) {
|
|
443
|
+
this.defaultVisit(node);
|
|
444
|
+
}
|
|
445
|
+
visitFunction(node) {
|
|
446
|
+
this.defaultVisit(node);
|
|
447
|
+
}
|
|
448
|
+
visitCase(node) {
|
|
449
|
+
this.defaultVisit(node);
|
|
450
|
+
}
|
|
451
|
+
visitWhen(node) {
|
|
452
|
+
this.defaultVisit(node);
|
|
453
|
+
}
|
|
454
|
+
visitJSONReference(node) {
|
|
455
|
+
this.defaultVisit(node);
|
|
456
|
+
}
|
|
457
|
+
visitJSONPath(node) {
|
|
458
|
+
this.defaultVisit(node);
|
|
459
|
+
}
|
|
460
|
+
visitJSONPathLeg(node) {
|
|
461
|
+
this.defaultVisit(node);
|
|
462
|
+
}
|
|
463
|
+
visitJSONOperatorChain(node) {
|
|
464
|
+
this.defaultVisit(node);
|
|
465
|
+
}
|
|
466
|
+
visitTuple(node) {
|
|
467
|
+
this.defaultVisit(node);
|
|
468
|
+
}
|
|
469
|
+
visitMergeQuery(node) {
|
|
470
|
+
this.defaultVisit(node);
|
|
471
|
+
}
|
|
472
|
+
visitMatched(node) {
|
|
473
|
+
this.defaultVisit(node);
|
|
474
|
+
}
|
|
475
|
+
visitAddIndex(node) {
|
|
476
|
+
this.defaultVisit(node);
|
|
477
|
+
}
|
|
478
|
+
visitCast(node) {
|
|
479
|
+
this.defaultVisit(node);
|
|
480
|
+
}
|
|
481
|
+
visitFetch(node) {
|
|
482
|
+
this.defaultVisit(node);
|
|
483
|
+
}
|
|
484
|
+
visitTop(node) {
|
|
485
|
+
this.defaultVisit(node);
|
|
486
|
+
}
|
|
487
|
+
visitOutput(node) {
|
|
488
|
+
this.defaultVisit(node);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
137
492
|
// src/prisma/prisma-schema-generator.ts
|
|
138
493
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
139
494
|
var import_ast2 = require("@zenstackhq/language/ast");
|
|
140
495
|
var import_utils2 = require("@zenstackhq/language/utils");
|
|
141
496
|
var import_langium = require("langium");
|
|
142
|
-
var
|
|
497
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
143
498
|
|
|
144
499
|
// src/prisma/indent-string.ts
|
|
145
500
|
function indentString(string, count = 4) {
|
|
@@ -619,13 +974,20 @@ var PrismaSchemaGenerator = class {
|
|
|
619
974
|
}
|
|
620
975
|
}
|
|
621
976
|
const allAttributes = (0, import_utils2.getAllAttributes)(decl);
|
|
622
|
-
for (const attr of allAttributes.filter((attr2) => this.isPrismaAttribute(attr2))) {
|
|
977
|
+
for (const attr of allAttributes.filter((attr2) => this.isPrismaAttribute(attr2) && !this.isInheritedMapAttribute(attr2, decl))) {
|
|
623
978
|
this.generateContainerAttribute(model, attr);
|
|
624
979
|
}
|
|
625
980
|
decl.comments.forEach((c) => model.addComment(c));
|
|
626
981
|
this.generateDelegateRelationForBase(model, decl);
|
|
627
982
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
628
983
|
}
|
|
984
|
+
isInheritedMapAttribute(attr, contextModel) {
|
|
985
|
+
if (attr.$container === contextModel) {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
|
|
989
|
+
return attrName === "@@map";
|
|
990
|
+
}
|
|
629
991
|
isPrismaAttribute(attr) {
|
|
630
992
|
if (!attr.decl.ref) {
|
|
631
993
|
return false;
|
|
@@ -703,7 +1065,7 @@ var PrismaSchemaGenerator = class {
|
|
|
703
1065
|
}
|
|
704
1066
|
makeAttributeArgValue(node) {
|
|
705
1067
|
if ((0, import_ast2.isLiteralExpr)(node)) {
|
|
706
|
-
const argType = (0,
|
|
1068
|
+
const argType = (0, import_ts_pattern2.match)(node.$type).with(import_ast2.StringLiteral, () => "String").with(import_ast2.NumberLiteral, () => "Number").with(import_ast2.BooleanLiteral, () => "Boolean").exhaustive();
|
|
707
1069
|
return new AttributeArgValue(argType, node.value);
|
|
708
1070
|
} else if ((0, import_ast2.isArrayExpr)(node)) {
|
|
709
1071
|
return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
|
|
@@ -722,7 +1084,7 @@ var PrismaSchemaGenerator = class {
|
|
|
722
1084
|
}
|
|
723
1085
|
makeFunctionCall(node) {
|
|
724
1086
|
return new FunctionCall(node.function.ref.name, node.args.map((arg) => {
|
|
725
|
-
const val = (0,
|
|
1087
|
+
const val = (0, import_ts_pattern2.match)(arg.value).when(import_ast2.isStringLiteral, (v) => `"${v.value}"`).when(import_ast2.isLiteralExpr, (v) => v.value.toString()).when(import_ast2.isNullExpr, () => "null").otherwise(() => {
|
|
726
1088
|
throw new Error("Function call argument must be literal or null");
|
|
727
1089
|
});
|
|
728
1090
|
return new FunctionCallArg(val);
|
|
@@ -811,7 +1173,7 @@ var import_ast3 = require("@zenstackhq/language/ast");
|
|
|
811
1173
|
var import_utils3 = require("@zenstackhq/language/utils");
|
|
812
1174
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
813
1175
|
var import_node_path = __toESM(require("path"), 1);
|
|
814
|
-
var
|
|
1176
|
+
var import_ts_pattern3 = require("ts-pattern");
|
|
815
1177
|
var ts = __toESM(require("typescript"), 1);
|
|
816
1178
|
var TsSchemaGenerator = class {
|
|
817
1179
|
static {
|
|
@@ -980,7 +1342,7 @@ var TsSchemaGenerator = class {
|
|
|
980
1342
|
], true))), true);
|
|
981
1343
|
}
|
|
982
1344
|
mapFieldTypeToTSType(type) {
|
|
983
|
-
let result = (0,
|
|
1345
|
+
let result = (0, import_ts_pattern3.match)(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
|
|
984
1346
|
if (type.array) {
|
|
985
1347
|
result = `${result}[]`;
|
|
986
1348
|
}
|
|
@@ -1028,7 +1390,9 @@ var TsSchemaGenerator = class {
|
|
|
1028
1390
|
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("call", [
|
|
1029
1391
|
ts.factory.createStringLiteral(defaultValue.call),
|
|
1030
1392
|
...defaultValue.args.length > 0 ? [
|
|
1031
|
-
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.
|
|
1393
|
+
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [
|
|
1394
|
+
this.createLiteralNode(arg)
|
|
1395
|
+
])))
|
|
1032
1396
|
] : []
|
|
1033
1397
|
])));
|
|
1034
1398
|
} else if ("authMember" in defaultValue) {
|
|
@@ -1342,7 +1706,7 @@ var TsSchemaGenerator = class {
|
|
|
1342
1706
|
]);
|
|
1343
1707
|
}
|
|
1344
1708
|
createExpression(value) {
|
|
1345
|
-
return (0,
|
|
1709
|
+
return (0, import_ts_pattern3.match)(value).when(import_ast3.isLiteralExpr, (expr) => this.createLiteralExpression(expr.$type, expr.value)).when(import_ast3.isInvocationExpr, (expr) => this.createCallExpression(expr)).when(import_ast3.isReferenceExpr, (expr) => this.createRefExpression(expr)).when(import_ast3.isArrayExpr, (expr) => this.createArrayExpression(expr)).when(import_ast3.isUnaryExpr, (expr) => this.createUnaryExpression(expr)).when(import_ast3.isBinaryExpr, (expr) => this.createBinaryExpression(expr)).when(import_ast3.isMemberAccessExpr, (expr) => this.createMemberExpression(expr)).when(import_ast3.isNullExpr, () => this.createNullExpression()).when(import_ast3.isThisExpr, () => this.createThisExpression()).otherwise(() => {
|
|
1346
1710
|
throw new Error(`Unsupported attribute arg value: ${value.$type}`);
|
|
1347
1711
|
});
|
|
1348
1712
|
}
|
|
@@ -1404,7 +1768,7 @@ var TsSchemaGenerator = class {
|
|
|
1404
1768
|
]);
|
|
1405
1769
|
}
|
|
1406
1770
|
createLiteralExpression(type, value) {
|
|
1407
|
-
return (0,
|
|
1771
|
+
return (0, import_ts_pattern3.match)(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1408
1772
|
this.createLiteralNode(value)
|
|
1409
1773
|
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1410
1774
|
ts.factory.createIdentifier(value)
|
|
@@ -2061,6 +2425,8 @@ _ts_decorate([
|
|
|
2061
2425
|
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
2062
2426
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2063
2427
|
0 && (module.exports = {
|
|
2428
|
+
DefaultOperationNodeVisitor,
|
|
2429
|
+
ExpressionVisitor,
|
|
2064
2430
|
ModelUtils,
|
|
2065
2431
|
PrismaSchemaGenerator,
|
|
2066
2432
|
TsSchemaGenerator,
|