cloesce 0.0.4-unstable.0 → 0.0.4-unstable.10
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/README.md → README.md} +212 -67
- package/dist/cli.js +37 -21
- package/dist/common.d.ts +89 -41
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +93 -38
- package/dist/extractor/extract.d.ts +9 -9
- package/dist/extractor/extract.d.ts.map +1 -1
- package/dist/extractor/extract.js +128 -149
- package/dist/generator.wasm +0 -0
- package/dist/orm.wasm +0 -0
- package/dist/router/crud.d.ts.map +1 -1
- package/dist/router/crud.js +25 -20
- package/dist/router/router.d.ts +71 -15
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +190 -109
- package/dist/router/wasm.d.ts +10 -3
- package/dist/router/wasm.d.ts.map +1 -1
- package/dist/router/wasm.js +12 -6
- package/dist/ui/backend.d.ts +431 -41
- package/dist/ui/backend.d.ts.map +1 -1
- package/dist/ui/backend.js +391 -90
- package/dist/ui/client.d.ts +2 -1
- package/dist/ui/client.d.ts.map +1 -1
- package/dist/ui/client.js +1 -0
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node as MorphNode, SyntaxKind, Scope, } from "ts-morph";
|
|
2
|
-
import {
|
|
2
|
+
import { Either, HttpVerb, ExtractorError, ExtractorErrorCode, } from "../common.js";
|
|
3
3
|
import { TypeFormatFlags } from "typescript";
|
|
4
4
|
var AttributeDecoratorKind;
|
|
5
5
|
(function (AttributeDecoratorKind) {
|
|
@@ -38,10 +38,10 @@ export class CidlExtractor {
|
|
|
38
38
|
sourceFile.getBaseName() === "seed__app.cloesce.ts" // hardcoding for tests
|
|
39
39
|
) {
|
|
40
40
|
const app = CidlExtractor.app(sourceFile);
|
|
41
|
-
if (
|
|
41
|
+
if (app.isLeft()) {
|
|
42
42
|
return app;
|
|
43
43
|
}
|
|
44
|
-
app_source = app.
|
|
44
|
+
app_source = app.unwrap();
|
|
45
45
|
}
|
|
46
46
|
for (const classDecl of sourceFile.getClasses()) {
|
|
47
47
|
const notExportedErr = err(ExtractorErrorCode.MissingExport, (e) => {
|
|
@@ -53,11 +53,11 @@ export class CidlExtractor {
|
|
|
53
53
|
return notExportedErr;
|
|
54
54
|
const result = CidlExtractor.model(classDecl, sourceFile);
|
|
55
55
|
// Error: propogate from models
|
|
56
|
-
if (
|
|
56
|
+
if (result.isLeft()) {
|
|
57
57
|
result.value.addContext((prev) => `${classDecl.getName()}.${prev}`);
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
|
-
models[result.
|
|
60
|
+
models[result.unwrap().name] = result.unwrap();
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
63
|
if (hasDecorator(classDecl, ClassDecoratorKind.PlainOldObject)) {
|
|
@@ -65,16 +65,14 @@ export class CidlExtractor {
|
|
|
65
65
|
return notExportedErr;
|
|
66
66
|
const result = CidlExtractor.poo(classDecl, sourceFile);
|
|
67
67
|
// Error: propogate from models
|
|
68
|
-
if (
|
|
68
|
+
if (result.isLeft()) {
|
|
69
69
|
result.value.addContext((prev) => `${classDecl.getName()}.${prev}`);
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
|
-
poos[result.
|
|
72
|
+
poos[result.unwrap().name] = result.unwrap();
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
if (hasDecorator(classDecl, ClassDecoratorKind.WranglerEnv)) {
|
|
76
|
-
if (!classDecl.isExported())
|
|
77
|
-
return notExportedErr;
|
|
78
76
|
// Error: invalid attribute modifier
|
|
79
77
|
for (const prop of classDecl.getProperties()) {
|
|
80
78
|
const modifierRes = checkAttributeModifier(prop);
|
|
@@ -82,10 +80,11 @@ export class CidlExtractor {
|
|
|
82
80
|
return modifierRes;
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
83
|
+
const result = CidlExtractor.env(classDecl, sourceFile);
|
|
84
|
+
if (result.isLeft()) {
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
wranglerEnvs.push(result.unwrap());
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
}
|
|
@@ -97,7 +96,7 @@ export class CidlExtractor {
|
|
|
97
96
|
if (wranglerEnvs.length > 1) {
|
|
98
97
|
return err(ExtractorErrorCode.TooManyWranglerEnvs, (e) => (e.context = wranglerEnvs.map((w) => w.name).toString()));
|
|
99
98
|
}
|
|
100
|
-
return right({
|
|
99
|
+
return Either.right({
|
|
101
100
|
version: this.version,
|
|
102
101
|
project_name: this.projectName,
|
|
103
102
|
language: "TypeScript",
|
|
@@ -114,41 +113,42 @@ export class CidlExtractor {
|
|
|
114
113
|
return err(ExtractorErrorCode.AppMissingDefaultExport);
|
|
115
114
|
}
|
|
116
115
|
const getTypeText = () => {
|
|
116
|
+
let type = undefined;
|
|
117
117
|
if (MorphNode.isExportAssignment(decl)) {
|
|
118
|
-
|
|
118
|
+
type = decl.getExpression()?.getType();
|
|
119
119
|
}
|
|
120
120
|
if (MorphNode.isVariableDeclaration(decl)) {
|
|
121
|
-
|
|
121
|
+
type = decl.getInitializer()?.getType();
|
|
122
122
|
}
|
|
123
|
-
return undefined;
|
|
123
|
+
return type?.getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
|
124
124
|
};
|
|
125
125
|
const typeText = getTypeText();
|
|
126
|
-
if (typeText === CloesceApp
|
|
127
|
-
return right(sourceFile.getFilePath().toString());
|
|
126
|
+
if (typeText === "CloesceApp") {
|
|
127
|
+
return Either.right(sourceFile.getFilePath().toString());
|
|
128
128
|
}
|
|
129
129
|
return err(ExtractorErrorCode.AppMissingDefaultExport);
|
|
130
130
|
}
|
|
131
131
|
static model(classDecl, sourceFile) {
|
|
132
132
|
const name = classDecl.getName();
|
|
133
133
|
const attributes = [];
|
|
134
|
-
const
|
|
135
|
-
const
|
|
134
|
+
const navigation_properties = [];
|
|
135
|
+
const data_sources = {};
|
|
136
136
|
const methods = {};
|
|
137
|
-
|
|
137
|
+
const cruds = new Set();
|
|
138
138
|
let primary_key = undefined;
|
|
139
139
|
// Extract crud methods
|
|
140
140
|
const crudDecorator = classDecl
|
|
141
141
|
.getDecorators()
|
|
142
142
|
.find((d) => getDecoratorName(d) === ClassDecoratorKind.CRUD);
|
|
143
143
|
if (crudDecorator) {
|
|
144
|
-
|
|
144
|
+
setCrudKinds(crudDecorator, cruds);
|
|
145
145
|
}
|
|
146
146
|
// Iterate attribtutes
|
|
147
147
|
for (const prop of classDecl.getProperties()) {
|
|
148
148
|
const decorators = prop.getDecorators();
|
|
149
149
|
const typeRes = CidlExtractor.cidlType(prop.getType());
|
|
150
150
|
// Error: invalid property type
|
|
151
|
-
if (
|
|
151
|
+
if (typeRes.isLeft()) {
|
|
152
152
|
typeRes.value.context = prop.getName();
|
|
153
153
|
typeRes.value.snippet = prop.getText();
|
|
154
154
|
return typeRes;
|
|
@@ -160,7 +160,7 @@ export class CidlExtractor {
|
|
|
160
160
|
if (checkModifierRes !== undefined) {
|
|
161
161
|
return checkModifierRes;
|
|
162
162
|
}
|
|
163
|
-
const cidl_type = typeRes.
|
|
163
|
+
const cidl_type = typeRes.unwrap();
|
|
164
164
|
attributes.push({
|
|
165
165
|
foreign_key_reference: null,
|
|
166
166
|
value: {
|
|
@@ -172,15 +172,15 @@ export class CidlExtractor {
|
|
|
172
172
|
}
|
|
173
173
|
// TODO: Limiting to one decorator. Can't get too fancy on us.
|
|
174
174
|
const decorator = decorators[0];
|
|
175
|
-
const
|
|
175
|
+
const decoratorName = getDecoratorName(decorator);
|
|
176
176
|
// Error: invalid attribute modifier
|
|
177
177
|
if (checkModifierRes !== undefined &&
|
|
178
|
-
|
|
178
|
+
decoratorName !== AttributeDecoratorKind.DataSource) {
|
|
179
179
|
return checkModifierRes;
|
|
180
180
|
}
|
|
181
|
-
// Process
|
|
182
|
-
const cidl_type = typeRes.
|
|
183
|
-
switch (
|
|
181
|
+
// Process decorator
|
|
182
|
+
const cidl_type = typeRes.unwrap();
|
|
183
|
+
switch (decoratorName) {
|
|
184
184
|
case AttributeDecoratorKind.PrimaryKey: {
|
|
185
185
|
primary_key = {
|
|
186
186
|
name: prop.getName(),
|
|
@@ -215,7 +215,7 @@ export class CidlExtractor {
|
|
|
215
215
|
e.context = prop.getName();
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
navigation_properties.push({
|
|
219
219
|
var_name: prop.getName(),
|
|
220
220
|
model_name,
|
|
221
221
|
kind: { OneToOne: { reference } },
|
|
@@ -239,7 +239,7 @@ export class CidlExtractor {
|
|
|
239
239
|
e.context = prop.getName();
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
navigation_properties.push({
|
|
243
243
|
var_name: prop.getName(),
|
|
244
244
|
model_name,
|
|
245
245
|
kind: { OneToMany: { reference } },
|
|
@@ -262,7 +262,7 @@ export class CidlExtractor {
|
|
|
262
262
|
e.context = prop.getName();
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
|
-
|
|
265
|
+
navigation_properties.push({
|
|
266
266
|
var_name: prop.getName(),
|
|
267
267
|
model_name,
|
|
268
268
|
kind: { ManyToMany: { unique_id } },
|
|
@@ -270,23 +270,26 @@ export class CidlExtractor {
|
|
|
270
270
|
break;
|
|
271
271
|
}
|
|
272
272
|
case AttributeDecoratorKind.DataSource: {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
273
|
+
const isIncludeTree = prop
|
|
274
|
+
.getType()
|
|
275
|
+
.getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope) === `IncludeTree<${name}>`;
|
|
276
|
+
// Error: data sources must be static include trees
|
|
277
|
+
if (!prop.isStatic() || !isIncludeTree) {
|
|
278
|
+
return err(ExtractorErrorCode.InvalidDataSourceDefinition, (e) => {
|
|
276
279
|
e.snippet = prop.getText();
|
|
277
280
|
e.context = prop.getName();
|
|
278
281
|
});
|
|
279
282
|
}
|
|
280
283
|
const initializer = prop.getInitializer();
|
|
281
284
|
const treeRes = CidlExtractor.includeTree(initializer, classDecl, sourceFile);
|
|
282
|
-
if (
|
|
285
|
+
if (treeRes.isLeft()) {
|
|
283
286
|
treeRes.value.addContext((prev) => `${prop.getName()} ${prev}`);
|
|
284
287
|
treeRes.value.snippet = prop.getText();
|
|
285
288
|
return treeRes;
|
|
286
289
|
}
|
|
287
|
-
|
|
290
|
+
data_sources[prop.getName()] = {
|
|
288
291
|
name: prop.getName(),
|
|
289
|
-
tree: treeRes.
|
|
292
|
+
tree: treeRes.unwrap(),
|
|
290
293
|
};
|
|
291
294
|
break;
|
|
292
295
|
}
|
|
@@ -307,25 +310,20 @@ export class CidlExtractor {
|
|
|
307
310
|
continue;
|
|
308
311
|
}
|
|
309
312
|
const result = CidlExtractor.method(name, m, httpVerb);
|
|
310
|
-
if (
|
|
313
|
+
if (result.isLeft()) {
|
|
311
314
|
result.value.addContext((prev) => `${m.getName()} ${prev}`);
|
|
312
|
-
return
|
|
315
|
+
return result;
|
|
313
316
|
}
|
|
314
|
-
methods[result.
|
|
315
|
-
}
|
|
316
|
-
// Add CRUD methods
|
|
317
|
-
for (const crud of cruds) {
|
|
318
|
-
// TODO: This overwrites any exisiting impl-- is that what we want?
|
|
319
|
-
const crudMethod = CidlExtractor.crudMethod(crud, primary_key, name);
|
|
320
|
-
methods[crudMethod.name] = crudMethod;
|
|
317
|
+
methods[result.unwrap().name] = result.unwrap();
|
|
321
318
|
}
|
|
322
|
-
return right({
|
|
319
|
+
return Either.right({
|
|
323
320
|
name,
|
|
324
321
|
attributes,
|
|
325
322
|
primary_key,
|
|
326
|
-
navigation_properties
|
|
323
|
+
navigation_properties,
|
|
327
324
|
methods,
|
|
328
|
-
data_sources
|
|
325
|
+
data_sources,
|
|
326
|
+
cruds: Array.from(cruds).sort(),
|
|
329
327
|
source_path: sourceFile.getFilePath().toString(),
|
|
330
328
|
});
|
|
331
329
|
}
|
|
@@ -335,7 +333,7 @@ export class CidlExtractor {
|
|
|
335
333
|
for (const prop of classDecl.getProperties()) {
|
|
336
334
|
const typeRes = CidlExtractor.cidlType(prop.getType());
|
|
337
335
|
// Error: invalid property type
|
|
338
|
-
if (
|
|
336
|
+
if (typeRes.isLeft()) {
|
|
339
337
|
typeRes.value.context = prop.getName();
|
|
340
338
|
typeRes.value.snippet = prop.getText();
|
|
341
339
|
return typeRes;
|
|
@@ -345,35 +343,65 @@ export class CidlExtractor {
|
|
|
345
343
|
if (modifierRes) {
|
|
346
344
|
return modifierRes;
|
|
347
345
|
}
|
|
348
|
-
const cidl_type = typeRes.
|
|
346
|
+
const cidl_type = typeRes.unwrap();
|
|
349
347
|
attributes.push({
|
|
350
348
|
name: prop.getName(),
|
|
351
349
|
cidl_type,
|
|
352
350
|
});
|
|
353
351
|
continue;
|
|
354
352
|
}
|
|
355
|
-
return right({
|
|
353
|
+
return Either.right({
|
|
356
354
|
name,
|
|
357
355
|
attributes,
|
|
358
356
|
source_path: sourceFile.getFilePath().toString(),
|
|
359
357
|
});
|
|
360
358
|
}
|
|
359
|
+
static env(classDecl, sourceFile) {
|
|
360
|
+
const vars = {};
|
|
361
|
+
let binding;
|
|
362
|
+
for (const prop of classDecl.getProperties()) {
|
|
363
|
+
if (prop
|
|
364
|
+
.getType()
|
|
365
|
+
.getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope) === "D1Database") {
|
|
366
|
+
binding = prop.getName();
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const ty = CidlExtractor.cidlType(prop.getType());
|
|
370
|
+
if (ty.isLeft()) {
|
|
371
|
+
ty.value.context = prop.getName();
|
|
372
|
+
ty.value.snippet = prop.getText();
|
|
373
|
+
return ty;
|
|
374
|
+
}
|
|
375
|
+
vars[prop.getName()] = ty.unwrap();
|
|
376
|
+
}
|
|
377
|
+
if (!binding) {
|
|
378
|
+
return err(ExtractorErrorCode.MissingDatabaseBinding);
|
|
379
|
+
}
|
|
380
|
+
return Either.right({
|
|
381
|
+
name: classDecl.getName(),
|
|
382
|
+
source_path: sourceFile.getFilePath().toString(),
|
|
383
|
+
db_binding: binding,
|
|
384
|
+
vars,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
361
387
|
static primTypeMap = {
|
|
362
|
-
number: "
|
|
363
|
-
Number: "
|
|
388
|
+
number: "Real",
|
|
389
|
+
Number: "Real",
|
|
390
|
+
Integer: "Integer",
|
|
364
391
|
string: "Text",
|
|
365
392
|
String: "Text",
|
|
366
|
-
boolean: "
|
|
367
|
-
Boolean: "
|
|
393
|
+
boolean: "Boolean",
|
|
394
|
+
Boolean: "Boolean",
|
|
395
|
+
Date: "DateIso",
|
|
368
396
|
};
|
|
369
397
|
static cidlType(type, inject = false) {
|
|
370
398
|
// Void
|
|
371
399
|
if (type.isVoid()) {
|
|
372
|
-
return right("Void");
|
|
400
|
+
return Either.right("Void");
|
|
373
401
|
}
|
|
374
402
|
// Null
|
|
375
403
|
if (type.isNull()) {
|
|
376
|
-
return right({ Nullable: "Void" });
|
|
404
|
+
return Either.right({ Nullable: "Void" });
|
|
377
405
|
}
|
|
378
406
|
// Nullable via union
|
|
379
407
|
const [unwrappedType, nullable] = unwrapNullable(type);
|
|
@@ -384,7 +412,7 @@ export class CidlExtractor {
|
|
|
384
412
|
// Primitives
|
|
385
413
|
const prim = this.primTypeMap[tyText];
|
|
386
414
|
if (prim) {
|
|
387
|
-
return right(wrapNullable(prim, nullable));
|
|
415
|
+
return Either.right(wrapNullable(prim, nullable));
|
|
388
416
|
}
|
|
389
417
|
const generics = [
|
|
390
418
|
...unwrappedType.getAliasTypeArguments(),
|
|
@@ -397,14 +425,14 @@ export class CidlExtractor {
|
|
|
397
425
|
// No generics -> inject or object
|
|
398
426
|
if (generics.length === 0) {
|
|
399
427
|
const base = inject ? { Inject: tyText } : { Object: tyText };
|
|
400
|
-
return right(wrapNullable(base, nullable));
|
|
428
|
+
return Either.right(wrapNullable(base, nullable));
|
|
401
429
|
}
|
|
402
430
|
// Single generic
|
|
403
431
|
const genericTy = generics[0];
|
|
404
432
|
const symbolName = unwrappedType.getSymbol()?.getName();
|
|
405
433
|
const aliasName = unwrappedType.getAliasSymbol()?.getName();
|
|
406
434
|
if (aliasName === "DataSourceOf") {
|
|
407
|
-
return right(wrapNullable({
|
|
435
|
+
return Either.right(wrapNullable({
|
|
408
436
|
DataSource: genericTy.getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope),
|
|
409
437
|
}, nullable));
|
|
410
438
|
}
|
|
@@ -420,20 +448,21 @@ export class CidlExtractor {
|
|
|
420
448
|
genericTyGenerics.length > 0) {
|
|
421
449
|
return err(ExtractorErrorCode.InvalidPartialType);
|
|
422
450
|
}
|
|
423
|
-
return right(wrapNullable({
|
|
451
|
+
return Either.right(wrapNullable({
|
|
424
452
|
Partial: genericTy
|
|
425
453
|
.getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope)
|
|
426
454
|
.split("|")[0]
|
|
427
455
|
.trim(),
|
|
428
456
|
}, nullable));
|
|
429
457
|
}
|
|
458
|
+
// Ignore
|
|
430
459
|
if (symbolName === "Promise" || aliasName === "IncludeTree") {
|
|
431
460
|
return wrapGeneric(genericTy, nullable, (inner) => inner);
|
|
432
461
|
}
|
|
433
462
|
if (unwrappedType.isArray()) {
|
|
434
463
|
return wrapGeneric(genericTy, nullable, (inner) => ({ Array: inner }));
|
|
435
464
|
}
|
|
436
|
-
if (
|
|
465
|
+
if (symbolName === "HttpResult") {
|
|
437
466
|
return wrapGeneric(genericTy, nullable, (inner) => ({
|
|
438
467
|
HttpResult: inner,
|
|
439
468
|
}));
|
|
@@ -451,19 +480,20 @@ export class CidlExtractor {
|
|
|
451
480
|
function wrapGeneric(t, isNullable, wrapper) {
|
|
452
481
|
const res = CidlExtractor.cidlType(t, inject);
|
|
453
482
|
// Error: propogated from `cidlType`
|
|
454
|
-
|
|
455
|
-
return res;
|
|
456
|
-
}
|
|
457
|
-
return right(wrapNullable(wrapper(res.value), isNullable));
|
|
483
|
+
return res.map((inner) => wrapNullable(wrapper(inner), isNullable));
|
|
458
484
|
}
|
|
459
485
|
function unwrapNullable(ty) {
|
|
460
|
-
if (ty.isUnion())
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
486
|
+
if (!ty.isUnion())
|
|
487
|
+
return [ty, false];
|
|
488
|
+
const unions = ty.getUnionTypes();
|
|
489
|
+
const nonNulls = unions.filter((t) => !t.isNull() && !t.isUndefined());
|
|
490
|
+
const hasNullable = nonNulls.length < unions.length;
|
|
491
|
+
// Booleans seperate into [null, true, false] from the `getUnionTypes` call
|
|
492
|
+
if (nonNulls.length === 2 &&
|
|
493
|
+
nonNulls.every((t) => t.isBooleanLiteral())) {
|
|
494
|
+
return [nonNulls[0].getApparentType(), hasNullable];
|
|
465
495
|
}
|
|
466
|
-
return [ty,
|
|
496
|
+
return [nonNulls[0] ?? ty, hasNullable];
|
|
467
497
|
}
|
|
468
498
|
}
|
|
469
499
|
static includeTree(expr, currentClass, sf) {
|
|
@@ -487,13 +517,13 @@ export class CidlExtractor {
|
|
|
487
517
|
}
|
|
488
518
|
const typeRes = CidlExtractor.cidlType(navProp.getType());
|
|
489
519
|
// Error: invalid referenced nav prop type
|
|
490
|
-
if (
|
|
520
|
+
if (typeRes.isLeft()) {
|
|
491
521
|
typeRes.value.snippet = navProp.getText();
|
|
492
522
|
typeRes.value.context = prop.getName();
|
|
493
523
|
return typeRes;
|
|
494
524
|
}
|
|
495
525
|
// Error: invalid referenced nav prop type
|
|
496
|
-
const cidl_type = typeRes.
|
|
526
|
+
const cidl_type = typeRes.unwrap();
|
|
497
527
|
if (typeof cidl_type === "string") {
|
|
498
528
|
return err(ExtractorErrorCode.InvalidNavigationPropertyReference, (e) => {
|
|
499
529
|
((e.snippet = navProp.getText()), (e.context = prop.getName()));
|
|
@@ -513,16 +543,16 @@ export class CidlExtractor {
|
|
|
513
543
|
if (targetClass) {
|
|
514
544
|
const treeRes = CidlExtractor.includeTree(initializer, targetClass, sf);
|
|
515
545
|
// Error: Propogated from `includeTree`
|
|
516
|
-
if (
|
|
546
|
+
if (treeRes.isLeft()) {
|
|
517
547
|
treeRes.value.snippet = expr.getText();
|
|
518
548
|
return treeRes;
|
|
519
549
|
}
|
|
520
|
-
nestedTree = treeRes.
|
|
550
|
+
nestedTree = treeRes.unwrap();
|
|
521
551
|
}
|
|
522
552
|
}
|
|
523
553
|
result[navProp.getName()] = nestedTree;
|
|
524
554
|
}
|
|
525
|
-
return right(result);
|
|
555
|
+
return Either.right(result);
|
|
526
556
|
}
|
|
527
557
|
static method(modelName, method, httpVerb) {
|
|
528
558
|
// Error: invalid method scope, must be public
|
|
@@ -539,37 +569,36 @@ export class CidlExtractor {
|
|
|
539
569
|
if (param.getDecorator(ParameterDecoratorKind.Inject)) {
|
|
540
570
|
const typeRes = CidlExtractor.cidlType(param.getType(), true);
|
|
541
571
|
// Error: invalid type
|
|
542
|
-
if (
|
|
572
|
+
if (typeRes.isLeft()) {
|
|
543
573
|
typeRes.value.snippet = method.getText();
|
|
544
574
|
typeRes.value.context = param.getName();
|
|
545
575
|
return typeRes;
|
|
546
576
|
}
|
|
547
577
|
parameters.push({
|
|
548
578
|
name: param.getName(),
|
|
549
|
-
cidl_type: typeRes.
|
|
579
|
+
cidl_type: typeRes.unwrap(),
|
|
550
580
|
});
|
|
551
581
|
continue;
|
|
552
582
|
}
|
|
553
583
|
// Handle all other params
|
|
554
584
|
const typeRes = CidlExtractor.cidlType(param.getType());
|
|
555
585
|
// Error: invalid type
|
|
556
|
-
if (
|
|
586
|
+
if (typeRes.isLeft()) {
|
|
557
587
|
typeRes.value.snippet = method.getText();
|
|
558
588
|
typeRes.value.context = param.getName();
|
|
559
589
|
return typeRes;
|
|
560
590
|
}
|
|
561
|
-
|
|
562
|
-
if (typeof rootType !== "string" && "DataSource" in rootType) {
|
|
591
|
+
if (typeof typeRes.value !== "string" && "DataSource" in typeRes.value) {
|
|
563
592
|
needsDataSource = false;
|
|
564
593
|
}
|
|
565
594
|
parameters.push({
|
|
566
595
|
name: param.getName(),
|
|
567
|
-
cidl_type: typeRes.
|
|
596
|
+
cidl_type: typeRes.unwrap(),
|
|
568
597
|
});
|
|
569
598
|
}
|
|
570
599
|
const typeRes = CidlExtractor.cidlType(method.getReturnType());
|
|
571
600
|
// Error: invalid type
|
|
572
|
-
if (
|
|
601
|
+
if (typeRes.isLeft()) {
|
|
573
602
|
typeRes.value.snippet = method.getText();
|
|
574
603
|
return typeRes;
|
|
575
604
|
}
|
|
@@ -580,71 +609,21 @@ export class CidlExtractor {
|
|
|
580
609
|
cidl_type: { DataSource: modelName },
|
|
581
610
|
});
|
|
582
611
|
}
|
|
583
|
-
return right({
|
|
612
|
+
return Either.right({
|
|
584
613
|
name: method.getName(),
|
|
585
614
|
is_static: method.isStatic(),
|
|
586
615
|
http_verb: httpVerb,
|
|
587
|
-
return_type: typeRes.
|
|
616
|
+
return_type: typeRes.unwrap(),
|
|
588
617
|
parameters,
|
|
589
618
|
});
|
|
590
619
|
}
|
|
591
|
-
static crudMethod(crud, primaryKey, modelName) {
|
|
592
|
-
// TODO: Should this impementation be in some JSON project file s.t. other
|
|
593
|
-
// langs can use it?
|
|
594
|
-
return {
|
|
595
|
-
POST: {
|
|
596
|
-
name: "post",
|
|
597
|
-
is_static: true,
|
|
598
|
-
http_verb: HttpVerb.POST,
|
|
599
|
-
return_type: { HttpResult: { Object: modelName } },
|
|
600
|
-
parameters: [
|
|
601
|
-
{
|
|
602
|
-
name: "obj",
|
|
603
|
-
cidl_type: { Partial: modelName },
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
name: "dataSource",
|
|
607
|
-
cidl_type: { DataSource: modelName },
|
|
608
|
-
},
|
|
609
|
-
],
|
|
610
|
-
},
|
|
611
|
-
GET: {
|
|
612
|
-
name: "get",
|
|
613
|
-
is_static: true,
|
|
614
|
-
http_verb: HttpVerb.GET,
|
|
615
|
-
return_type: { HttpResult: { Object: modelName } },
|
|
616
|
-
parameters: [
|
|
617
|
-
{
|
|
618
|
-
name: "id",
|
|
619
|
-
cidl_type: primaryKey.cidl_type,
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
name: "dataSource",
|
|
623
|
-
cidl_type: { DataSource: modelName },
|
|
624
|
-
},
|
|
625
|
-
],
|
|
626
|
-
},
|
|
627
|
-
LIST: {
|
|
628
|
-
name: "list",
|
|
629
|
-
is_static: true,
|
|
630
|
-
http_verb: HttpVerb.GET,
|
|
631
|
-
return_type: { HttpResult: { Array: { Object: modelName } } },
|
|
632
|
-
parameters: [
|
|
633
|
-
{
|
|
634
|
-
name: "dataSource",
|
|
635
|
-
cidl_type: { DataSource: modelName },
|
|
636
|
-
},
|
|
637
|
-
],
|
|
638
|
-
},
|
|
639
|
-
}[crud];
|
|
640
|
-
}
|
|
641
620
|
}
|
|
642
621
|
function err(code, fn) {
|
|
643
622
|
let e = new ExtractorError(code);
|
|
644
623
|
if (fn) {
|
|
645
624
|
fn(e);
|
|
646
625
|
}
|
|
647
|
-
return left(e);
|
|
626
|
+
return Either.left(e);
|
|
648
627
|
}
|
|
649
628
|
function getDecoratorName(decorator) {
|
|
650
629
|
const name = decorator.getName() ?? decorator.getExpression().getText();
|
|
@@ -682,18 +661,18 @@ function getObjectName(t) {
|
|
|
682
661
|
}
|
|
683
662
|
return undefined;
|
|
684
663
|
}
|
|
685
|
-
function
|
|
664
|
+
function setCrudKinds(d, cruds) {
|
|
686
665
|
const arg = d.getArguments()[0];
|
|
687
|
-
if (!arg)
|
|
688
|
-
return
|
|
666
|
+
if (!arg) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
689
669
|
if (MorphNode.isArrayLiteralExpression(arg)) {
|
|
690
|
-
|
|
691
|
-
.
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
670
|
+
for (const a of arg.getElements()) {
|
|
671
|
+
cruds.add((MorphNode.isStringLiteral(a)
|
|
672
|
+
? a.getLiteralValue()
|
|
673
|
+
: a.getText()));
|
|
674
|
+
}
|
|
695
675
|
}
|
|
696
|
-
return [];
|
|
697
676
|
}
|
|
698
677
|
function findPropertyByName(cls, name) {
|
|
699
678
|
const exactMatch = cls.getProperties().find((p) => p.getName() === name);
|
package/dist/generator.wasm
CHANGED
|
Binary file
|
package/dist/orm.wasm
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/router/crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAC;AAG1D;;GAEG;AACH,qBAAa,WAAW;IAEpB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;IAHd,OAAO;IAMP,MAAM,CAAC,YAAY,CACjB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,UAAU,MAAM,GACrB,WAAW;IAId,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,MAAM,GAAG,WAAW;IAIpE;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;IAWrC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/router/crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAC;AAG1D;;GAEG;AACH,qBAAa,WAAW;IAEpB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;IAHd,OAAO;IAMP,MAAM,CAAC,YAAY,CACjB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,UAAU,MAAM,GACrB,WAAW;IAId,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,MAAM,GAAG,WAAW;IAIpE;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;IAWrC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAiBrE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAU9D,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;CAY7D"}
|