cloesce 0.0.4-unstable.2 → 0.0.4-unstable.4

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.
@@ -1,17 +1,17 @@
1
- import { Project } from "ts-morph";
2
- import { CloesceAst, Either, ExtractorError } from "../common.js";
1
+ import { Project, Type, SourceFile, MethodDeclaration, ClassDeclaration, Expression } from "ts-morph";
2
+ import { CidlIncludeTree, CloesceAst, CidlType, Either, HttpVerb, Model, ModelMethod, WranglerEnv, ExtractorError, PlainOldObject } from "../common.js";
3
3
  export declare class CidlExtractor {
4
4
  projectName: string;
5
5
  version: string;
6
6
  constructor(projectName: string, version: string);
7
7
  extract(project: Project): Either<ExtractorError, CloesceAst>;
8
- private static app;
9
- private static model;
10
- private static poo;
8
+ static app(sourceFile: SourceFile): Either<ExtractorError, string>;
9
+ static model(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, Model>;
10
+ static poo(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, PlainOldObject>;
11
+ static env(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, WranglerEnv>;
11
12
  private static readonly primTypeMap;
12
- private static cidlType;
13
- private static includeTree;
14
- private static method;
15
- private static crudMethod;
13
+ static cidlType(type: Type, inject?: boolean): Either<ExtractorError, CidlType>;
14
+ static includeTree(expr: Expression | undefined, currentClass: ClassDeclaration, sf: SourceFile): Either<ExtractorError, CidlIncludeTree>;
15
+ static method(modelName: string, method: MethodDeclaration, httpVerb: HttpVerb): Either<ExtractorError, ModelMethod>;
16
16
  }
17
17
  //# sourceMappingURL=extract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extractor/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAUR,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EAGV,MAAM,EAUN,cAAc,EAKf,MAAM,cAAc,CAAC;A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UAAU,GACrB,MAAM,CAAC,cAAc,EAAE,KAAK,CAAC;IAgQhC,MAAM,CAAC,GAAG,CACR,SAAS,EAAE,gBAAgB,EAC3B,UAAU,EAAE,UAAU,GACrB,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC;IAmCzC,MAAM,CAAC,GAAG,CACR,SAAS,EAAE,gBAAgB,EAC3B,UAAU,EAAE,UAAU,GACrB,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC;IAuBtC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CASjC;IAEF,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,OAAe,GACtB,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC;IAsJnC,MAAM,CAAC,WAAW,CAChB,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,YAAY,EAAE,gBAAgB,EAC9B,EAAE,EAAE,UAAU,GACb,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC;IAiF1C,MAAM,CAAC,MAAM,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC;CA0EvC"}
@@ -73,8 +73,6 @@ export class CidlExtractor {
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
- wranglerEnvs.push({
86
- name: classDecl.getName(),
87
- source_path: sourceFile.getFilePath().toString(),
88
- });
83
+ const result = CidlExtractor.env(classDecl, sourceFile);
84
+ if (!result.ok) {
85
+ return result;
86
+ }
87
+ wranglerEnvs.push(result.value);
89
88
  }
90
89
  }
91
90
  }
@@ -114,13 +113,14 @@ 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
- return decl.getExpression()?.getType().getText();
118
+ type = decl.getExpression()?.getType();
119
119
  }
120
120
  if (MorphNode.isVariableDeclaration(decl)) {
121
- return decl.getInitializer()?.getType().getText();
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
126
  if (typeText === CloesceApp.name) {
@@ -131,17 +131,17 @@ export class CidlExtractor {
131
131
  static model(classDecl, sourceFile) {
132
132
  const name = classDecl.getName();
133
133
  const attributes = [];
134
- const navigationProperties = [];
135
- const dataSources = {};
134
+ const navigation_properties = [];
135
+ const data_sources = {};
136
136
  const methods = {};
137
- let cruds = [];
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
- cruds = getCrudKinds(crudDecorator);
144
+ setCrudKinds(crudDecorator, cruds);
145
145
  }
146
146
  // Iterate attribtutes
147
147
  for (const prop of classDecl.getProperties()) {
@@ -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 name = getDecoratorName(decorator);
175
+ const decoratorName = getDecoratorName(decorator);
176
176
  // Error: invalid attribute modifier
177
177
  if (checkModifierRes !== undefined &&
178
- name !== AttributeDecoratorKind.DataSource) {
178
+ decoratorName !== AttributeDecoratorKind.DataSource) {
179
179
  return checkModifierRes;
180
180
  }
181
- // Process decorators
181
+ // Process decorator
182
182
  const cidl_type = typeRes.value;
183
- switch (name) {
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
- navigationProperties.push({
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
- navigationProperties.push({
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
- navigationProperties.push({
265
+ navigation_properties.push({
266
266
  var_name: prop.getName(),
267
267
  model_name,
268
268
  kind: { ManyToMany: { unique_id } },
@@ -270,9 +270,12 @@ export class CidlExtractor {
270
270
  break;
271
271
  }
272
272
  case AttributeDecoratorKind.DataSource: {
273
- // Error: data sources must be static
274
- if (!prop.isStatic()) {
275
- return err(ExtractorErrorCode.DataSourceMissingStatic, (e) => {
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
  });
@@ -284,7 +287,7 @@ export class CidlExtractor {
284
287
  treeRes.value.snippet = prop.getText();
285
288
  return treeRes;
286
289
  }
287
- dataSources[prop.getName()] = {
290
+ data_sources[prop.getName()] = {
288
291
  name: prop.getName(),
289
292
  tree: treeRes.value,
290
293
  };
@@ -313,19 +316,14 @@ export class CidlExtractor {
313
316
  }
314
317
  methods[result.value.name] = result.value;
315
318
  }
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;
321
- }
322
319
  return right({
323
320
  name,
324
321
  attributes,
325
322
  primary_key,
326
- navigation_properties: navigationProperties,
323
+ navigation_properties,
327
324
  methods,
328
- data_sources: dataSources,
325
+ data_sources,
326
+ cruds: Array.from(cruds).sort(),
329
327
  source_path: sourceFile.getFilePath().toString(),
330
328
  });
331
329
  }
@@ -358,6 +356,21 @@ export class CidlExtractor {
358
356
  source_path: sourceFile.getFilePath().toString(),
359
357
  });
360
358
  }
359
+ static env(classDecl, sourceFile) {
360
+ const binding = classDecl.getProperties().find((p) => {
361
+ return (p
362
+ .getType()
363
+ .getText(undefined, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope) === "D1Database");
364
+ });
365
+ if (!binding) {
366
+ return err(ExtractorErrorCode.MissingDatabaseBinding);
367
+ }
368
+ return right({
369
+ name: classDecl.getName(),
370
+ source_path: sourceFile.getFilePath().toString(),
371
+ db_binding: binding.getName(),
372
+ });
373
+ }
361
374
  static primTypeMap = {
362
375
  number: "Real",
363
376
  Number: "Real",
@@ -459,13 +472,17 @@ export class CidlExtractor {
459
472
  return right(wrapNullable(wrapper(res.value), isNullable));
460
473
  }
461
474
  function unwrapNullable(ty) {
462
- if (ty.isUnion()) {
463
- const nonNull = ty.getUnionTypes().filter((t) => !t.isNull());
464
- if (nonNull.length === 1) {
465
- return [nonNull[0], true];
466
- }
475
+ if (!ty.isUnion())
476
+ return [ty, false];
477
+ const unions = ty.getUnionTypes();
478
+ const nonNulls = unions.filter((t) => !t.isNull() && !t.isUndefined());
479
+ const hasNullable = nonNulls.length < unions.length;
480
+ // Booleans seperate into [null, true, false] from the `getUnionTypes` call
481
+ if (nonNulls.length === 2 &&
482
+ nonNulls.every((t) => t.isBooleanLiteral())) {
483
+ return [nonNulls[0].getApparentType(), hasNullable];
467
484
  }
468
- return [ty, false];
485
+ return [nonNulls[0] ?? ty, hasNullable];
469
486
  }
470
487
  }
471
488
  static includeTree(expr, currentClass, sf) {
@@ -560,8 +577,7 @@ export class CidlExtractor {
560
577
  typeRes.value.context = param.getName();
561
578
  return typeRes;
562
579
  }
563
- const rootType = getRootType(typeRes.value);
564
- if (typeof rootType !== "string" && "DataSource" in rootType) {
580
+ if (typeof typeRes.value !== "string" && "DataSource" in typeRes.value) {
565
581
  needsDataSource = false;
566
582
  }
567
583
  parameters.push({
@@ -590,56 +606,6 @@ export class CidlExtractor {
590
606
  parameters,
591
607
  });
592
608
  }
593
- static crudMethod(crud, primaryKey, modelName) {
594
- // TODO: Should this impementation be in some JSON project file s.t. other
595
- // langs can use it?
596
- return {
597
- POST: {
598
- name: "post",
599
- is_static: true,
600
- http_verb: HttpVerb.POST,
601
- return_type: { HttpResult: { Object: modelName } },
602
- parameters: [
603
- {
604
- name: "obj",
605
- cidl_type: { Partial: modelName },
606
- },
607
- {
608
- name: "dataSource",
609
- cidl_type: { DataSource: modelName },
610
- },
611
- ],
612
- },
613
- GET: {
614
- name: "get",
615
- is_static: true,
616
- http_verb: HttpVerb.GET,
617
- return_type: { HttpResult: { Object: modelName } },
618
- parameters: [
619
- {
620
- name: "id",
621
- cidl_type: primaryKey.cidl_type,
622
- },
623
- {
624
- name: "dataSource",
625
- cidl_type: { DataSource: modelName },
626
- },
627
- ],
628
- },
629
- LIST: {
630
- name: "list",
631
- is_static: true,
632
- http_verb: HttpVerb.GET,
633
- return_type: { HttpResult: { Array: { Object: modelName } } },
634
- parameters: [
635
- {
636
- name: "dataSource",
637
- cidl_type: { DataSource: modelName },
638
- },
639
- ],
640
- },
641
- }[crud];
642
- }
643
609
  }
644
610
  function err(code, fn) {
645
611
  let e = new ExtractorError(code);
@@ -684,18 +650,18 @@ function getObjectName(t) {
684
650
  }
685
651
  return undefined;
686
652
  }
687
- function getCrudKinds(d) {
653
+ function setCrudKinds(d, cruds) {
688
654
  const arg = d.getArguments()[0];
689
- if (!arg)
690
- return [];
655
+ if (!arg) {
656
+ return;
657
+ }
691
658
  if (MorphNode.isArrayLiteralExpression(arg)) {
692
- return arg
693
- .getElements()
694
- .map((e) => (MorphNode.isStringLiteral(e)
695
- ? e.getLiteralValue()
696
- : e.getText()));
659
+ for (const a of arg.getElements()) {
660
+ cruds.add((MorphNode.isStringLiteral(a)
661
+ ? a.getLiteralValue()
662
+ : a.getText()));
663
+ }
697
664
  }
698
- return [];
699
665
  }
700
666
  function findPropertyByName(cls, name) {
701
667
  const exactMatch = cls.getProperties().find((p) => p.getName() === name);
Binary file
package/dist/orm.wasm CHANGED
Binary file
@@ -24,7 +24,7 @@ export class CrudContext {
24
24
  */
25
25
  interceptCrud(methodName) {
26
26
  const map = {
27
- post: this.upsert.bind(this),
27
+ save: this.upsert.bind(this),
28
28
  get: this.get.bind(this),
29
29
  list: this.list.bind(this),
30
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,MAAM,EACN,WAAW,EAIX,UAAU,EAEV,KAAK,EAGL,UAAU,EACV,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAwB,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;GAKG;AACH,KAAK,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,CAAC;AAE9D;;;GAGG;AACH,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C;;GAEG;AACH,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,gBAAgB;aAGT,GAAG,EAAE,UAAU;aACf,mBAAmB,EAAE,wBAAwB;aAC7C,IA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ACjB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,MAAM,GACf,MAAM,CACP,UAAU,EACV;IACE,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB,CACF,CAyCA;AAED;;;;GAIG;AACH,iBAAe,eAAe,CAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,MAAM,GAAG,IAAI,GAChB,OAAO,CACR,MAAM,CAAC,UAAU,EAAE;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAC3E,CA4DA;AA2DD;;;GAGG;AACH,iBAAe,cAAc,CAC3B,OAAO,EAAE,WAAW,EACpB,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAkD9B;AAkID;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;CAK5B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { left, right, isNullableType, getNavigationPropertyCidlType, NO_DATA_SOURCE, } from "../common.js";
2
- import { fromSql, loadOrmWasm } from "./wasm.js";
2
+ import { mapSql, loadOrmWasm } from "./wasm.js";
3
3
  import { CrudContext } from "./crud.js";
4
4
  /**
5
5
  * Singleton instance containing the cidl, constructor registry, and wasm binary.
@@ -200,7 +200,7 @@ async function hydrateModel(constructorRegistry, d1, model, id, dataSource) {
200
200
  const missingRecord = left(errorState(404, "Record not found"));
201
201
  const pk = model.primary_key.name;
202
202
  const query = dataSource !== NO_DATA_SOURCE
203
- ? `SELECT * FROM "${model.name}.${dataSource}" WHERE "${model.name}.${pk}" = ?`
203
+ ? `SELECT * FROM "${model.name}.${dataSource}" WHERE "${pk}" = ?`
204
204
  : `SELECT * FROM "${model.name}" WHERE "${pk}" = ?`;
205
205
  // Query DB
206
206
  let records;
@@ -217,7 +217,7 @@ async function hydrateModel(constructorRegistry, d1, model, id, dataSource) {
217
217
  return malformedQuery(e);
218
218
  }
219
219
  // Hydrate
220
- const models = fromSql(constructorRegistry[model.name], records.results, model.data_sources[dataSource]?.tree ?? {}).value;
220
+ const models = mapSql(constructorRegistry[model.name], records.results, model.data_sources[dataSource]?.tree ?? {}).value;
221
221
  return right(models[0]);
222
222
  }
223
223
  /**
@@ -33,5 +33,5 @@ export declare function invokeOrmWasm<T>(fn: (...args: number[]) => boolean, arg
33
33
  * Calls `object_relational_mapping` to turn a row of SQL records into
34
34
  * an instantiated object.
35
35
  */
36
- export declare function fromSql<T extends object>(ctor: new () => T, records: Record<string, any>[], includeTree: IncludeTree<T> | CidlIncludeTree | null): Either<string, T[]>;
36
+ export declare function mapSql<T extends object>(ctor: new () => T, records: Record<string, any>[], includeTree: IncludeTree<T> | CidlIncludeTree | null): Either<string, T[]>;
37
37
  //# sourceMappingURL=wasm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../../src/router/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,UAAU,EACV,MAAM,EAIP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAM/C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAC3B,cAAc,IAAI,MAAM,CAAC;IACzB,cAAc,IAAI,MAAM,CAAC;IACzB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,GA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EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,YAAY;CAQnE;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,UAAU,EACf,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,GAC1B,OAAO,CAAC,cAAc,CAAC,CAmBzB;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC7B,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,EAClC,IAAI,EAAE,YAAY,EAAE,EACpB,IAAI,EAAE,cAAc,GACnB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAkBnB;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EACrC,IAAI,EAAE,UAAU,CAAC,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAC9B,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,eAAe,GAAG,IAAI,GACnD,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CA0DrB"}
@@ -61,7 +61,7 @@ export function invokeOrmWasm(fn, args, wasm) {
61
61
  * Calls `object_relational_mapping` to turn a row of SQL records into
62
62
  * an instantiated object.
63
63
  */
64
- export function fromSql(ctor, records, includeTree) {
64
+ export function mapSql(ctor, records, includeTree) {
65
65
  const { ast, constructorRegistry, wasm } = RuntimeContainer.get();
66
66
  const args = [
67
67
  WasmResource.fromString(ctor.name, wasm),