cloesce 0.0.5-unstable.4 → 0.0.5-unstable.6

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/ast.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type CrudKind = "SAVE" | "GET" | "LIST";
2
- export type CidlType = "Void" | "Integer" | "Real" | "Text" | "Blob" | "DateIso" | "Boolean" | "Stream" | {
2
+ export type CidlType = "Void" | "Integer" | "Real" | "Text" | "Blob" | "DateIso" | "Boolean" | "Stream" | "JsonValue" | {
3
3
  DataSource: string;
4
4
  } | {
5
5
  Inject: string;
@@ -26,7 +26,7 @@ export interface NamedTypedValue {
26
26
  name: string;
27
27
  cidl_type: CidlType;
28
28
  }
29
- export interface ModelAttribute {
29
+ export interface D1Column {
30
30
  value: NamedTypedValue;
31
31
  foreign_key_reference: string | null;
32
32
  }
@@ -51,28 +51,39 @@ export interface ApiMethod {
51
51
  }
52
52
  export type NavigationPropertyKind = {
53
53
  OneToOne: {
54
- reference: string;
54
+ column_reference: string;
55
55
  };
56
56
  } | {
57
57
  OneToMany: {
58
- reference: string;
58
+ column_reference: string;
59
59
  };
60
- } | {
61
- ManyToMany: {
62
- unique_id: string;
63
- };
64
- };
60
+ } | "ManyToMany";
65
61
  export interface NavigationProperty {
66
62
  var_name: string;
67
- model_name: string;
63
+ model_reference: string;
68
64
  kind: NavigationPropertyKind;
69
65
  }
70
66
  export declare function getNavigationPropertyCidlType(nav: NavigationProperty): CidlType;
67
+ export interface KeyValue {
68
+ format: string;
69
+ namespace_binding: string;
70
+ value: NamedTypedValue;
71
+ list_prefix: boolean;
72
+ }
73
+ export interface AstR2Object {
74
+ format: string;
75
+ bucket_binding: string;
76
+ var_name: string;
77
+ list_prefix: boolean;
78
+ }
71
79
  export interface Model {
72
80
  name: string;
73
- primary_key: NamedTypedValue;
74
- attributes: ModelAttribute[];
81
+ primary_key: NamedTypedValue | null;
82
+ columns: D1Column[];
75
83
  navigation_properties: NavigationProperty[];
84
+ key_params: string[];
85
+ kv_objects: KeyValue[];
86
+ r2_objects: AstR2Object[];
76
87
  methods: Record<string, ApiMethod>;
77
88
  data_sources: Record<string, DataSource>;
78
89
  cruds: CrudKind[];
@@ -85,7 +96,7 @@ export interface PlainOldObject {
85
96
  }
86
97
  export interface ServiceAttribute {
87
98
  var_name: string;
88
- injected: string;
99
+ inject_reference: string;
89
100
  }
90
101
  export interface Service {
91
102
  name: string;
@@ -104,18 +115,17 @@ export interface DataSource {
104
115
  export interface WranglerEnv {
105
116
  name: string;
106
117
  source_path: string;
107
- db_binding: string;
118
+ d1_binding?: string;
119
+ kv_bindings: string[];
120
+ r2_bindings: string[];
108
121
  vars: Record<string, CidlType>;
109
122
  }
110
123
  export interface CloesceAst {
111
- [x: string]: any;
112
- version: string;
113
124
  project_name: string;
114
- language: string;
115
125
  wrangler_env?: WranglerEnv;
116
126
  models: Record<string, Model>;
117
127
  poos: Record<string, PlainOldObject>;
118
128
  services: Record<string, Service>;
119
- app_source: string | null;
129
+ main_source: string | null;
120
130
  }
121
131
  //# sourceMappingURL=ast.d.ts.map
package/dist/ast.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/C,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,SAAS,GACT,SAAS,GACT,QAAQ,GACR;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GACtB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GACnB;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,GACtB;IAAE,KAAK,EAAE,QAAQ,CAAA;C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Q,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B"}
package/dist/ast.js CHANGED
@@ -23,8 +23,8 @@ export function defaultMediaType() {
23
23
  return MediaType.Json;
24
24
  }
25
25
  export function getNavigationPropertyCidlType(nav) {
26
- return "OneToOne" in nav.kind
27
- ? { Object: nav.model_name }
28
- : { Array: { Object: nav.model_name } };
26
+ return typeof nav.kind !== "string" && "OneToOne" in nav.kind
27
+ ? { Object: nav.model_reference }
28
+ : { Array: { Object: nav.model_reference } };
29
29
  }
30
30
  export const NO_DATA_SOURCE = "none";
package/dist/cli.js CHANGED
@@ -190,20 +190,19 @@ async function extract(config, args = {}) {
190
190
  try {
191
191
  const extractorStart = Date.now();
192
192
  debug("Extracting CIDL...");
193
- const extractor = new CidlExtractor(cloesceProjectName, "v0.0.4");
194
- const result = extractor.extract(project);
193
+ const result = CidlExtractor.extract(cloesceProjectName, project);
195
194
  if (result.isLeft()) {
196
195
  console.error(formatErr(result.value));
197
196
  process.exit(1);
198
197
  }
199
- let ast = result.unwrap();
198
+ const ast = result.unwrap();
200
199
  if (truncate) {
201
200
  if (ast.wrangler_env) {
202
201
  ast.wrangler_env.source_path =
203
202
  "./" + path.basename(ast.wrangler_env.source_path);
204
203
  }
205
- if (ast.app_source) {
206
- ast.app_source = "./" + path.basename(ast.app_source);
204
+ if (ast.main_source) {
205
+ ast.main_source = "./" + path.basename(ast.main_source);
207
206
  }
208
207
  for (const model of Object.values(ast.models)) {
209
208
  model.source_path = "./" + path.basename(model.source_path);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Denotes that some error occured internally in Cloesce that should not happen.
3
+ */
4
+ export declare class InternalError extends Error {
5
+ constructor(description: string);
6
+ }
7
+ export declare class Either<L, R> {
8
+ private readonly inner;
9
+ private constructor();
10
+ get value(): L | R;
11
+ static left<R>(): Either<void, R>;
12
+ static left<L, R = never>(value: L): Either<L, R>;
13
+ static right<R, L = never>(value: R): Either<L, R>;
14
+ isLeft(): this is Either<L, never>;
15
+ isRight(): this is Either<never, R>;
16
+ unwrap(): R;
17
+ unwrapLeft(): L;
18
+ map<B>(fn: (val: R) => B): Either<L, B>;
19
+ mapLeft<B>(fn: (val: L) => B): Either<B, R>;
20
+ }
21
+ export declare function b64ToU8(b64: string): Uint8Array;
22
+ export declare function u8ToB64(u8: Uint8Array): string;
23
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,WAAW,EAAE,MAAM;CAIhC;AAED,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC;IAEpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IADxB,OAAO;IAIP,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,CAEjB;IAED,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAMjD,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAIlD,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;IAIlC,OAAO,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAInC,MAAM,IAAI,CAAC;IAOX,UAAU,IAAI,CAAC;IAOf,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAMvC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;CAK5C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAc/C;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAY9C"}
package/dist/common.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Denotes that some error occured internally in Cloesce that should not happen.
3
+ */
4
+ export class InternalError extends Error {
5
+ constructor(description) {
6
+ super(`An internal Cloesce error occurred: ${description}`);
7
+ Object.setPrototypeOf(this, InternalError.prototype);
8
+ }
9
+ }
10
+ export class Either {
11
+ inner;
12
+ constructor(inner) {
13
+ this.inner = inner;
14
+ }
15
+ get value() {
16
+ return this.inner.ok ? this.inner.right : this.inner.left;
17
+ }
18
+ static left(value) {
19
+ return new Either({ ok: false, left: value });
20
+ }
21
+ static right(value) {
22
+ return new Either({ ok: true, right: value });
23
+ }
24
+ isLeft() {
25
+ return !this.inner.ok;
26
+ }
27
+ isRight() {
28
+ return this.inner.ok;
29
+ }
30
+ unwrap() {
31
+ if (!this.inner.ok) {
32
+ throw new Error("Tried to unwrap a Left value");
33
+ }
34
+ return this.inner.right;
35
+ }
36
+ unwrapLeft() {
37
+ if (this.inner.ok) {
38
+ throw new Error("Tried to unwrapLeft a Right value");
39
+ }
40
+ return this.inner.left;
41
+ }
42
+ map(fn) {
43
+ return this.inner.ok
44
+ ? Either.right(fn(this.inner.right))
45
+ : Either.left(this.inner.left);
46
+ }
47
+ mapLeft(fn) {
48
+ return this.inner.ok
49
+ ? Either.right(this.inner.right)
50
+ : Either.left(fn(this.inner.left));
51
+ }
52
+ }
53
+ export function b64ToU8(b64) {
54
+ // Prefer Buffer in Node.js environments
55
+ if (typeof Buffer !== "undefined") {
56
+ const buffer = Buffer.from(b64, "base64");
57
+ return new Uint8Array(buffer);
58
+ }
59
+ // Use atob only in browser environments
60
+ const s = atob(b64);
61
+ const u8 = new Uint8Array(s.length);
62
+ for (let i = 0; i < s.length; i++) {
63
+ u8[i] = s.charCodeAt(i);
64
+ }
65
+ return u8;
66
+ }
67
+ export function u8ToB64(u8) {
68
+ // Prefer Buffer in Node.js environments
69
+ if (typeof Buffer !== "undefined") {
70
+ return Buffer.from(u8).toString("base64");
71
+ }
72
+ // Use btoa only in browser environments
73
+ let s = "";
74
+ for (let i = 0; i < u8.length; i++) {
75
+ s += String.fromCharCode(u8[i]);
76
+ }
77
+ return btoa(s);
78
+ }
@@ -1,22 +1,21 @@
1
1
  export declare enum ExtractorErrorCode {
2
2
  MissingExport = 0,
3
- AppMissingDefaultExport = 1,
3
+ InvalidMain = 1,
4
4
  UnknownType = 2,
5
5
  MultipleGenericType = 3,
6
6
  InvalidDataSourceDefinition = 4,
7
7
  InvalidPartialType = 5,
8
- InvalidIncludeTree = 6,
9
- InvalidAttributeModifier = 7,
10
- InvalidApiMethodModifier = 8,
11
- UnknownNavigationPropertyReference = 9,
12
- InvalidNavigationPropertyReference = 10,
13
- MissingNavigationPropertyReference = 11,
14
- MissingManyToManyUniqueId = 12,
15
- MissingPrimaryKey = 13,
16
- MissingDatabaseBinding = 14,
17
- TooManyWranglerEnvs = 15,
18
- MissingFile = 16,
19
- InvalidServiceAttribute = 17
8
+ InvalidPropertyModifier = 6,
9
+ InvalidApiMethodModifier = 7,
10
+ InvalidSelectorSyntax = 8,
11
+ InvalidOneToOneSelector = 9,
12
+ InvalidNavigationProperty = 10,
13
+ TooManyWranglerEnvs = 11,
14
+ MissingFile = 12,
15
+ InvalidServiceProperty = 13,
16
+ InvalidTypescriptSyntax = 14,
17
+ MissingKValue = 15,
18
+ MissingR2ObjectBody = 16
20
19
  }
21
20
  export declare function getErrorInfo(code: ExtractorErrorCode): {
22
21
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../src/extractor/err.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC5B,aAAa,IAAA;IACb,uBAAuB,IAAA;IACvB,WAAW,IAAA;IACX,mBAAmB,IAAA;IACnB,2BAA2B,IAAA;IAC3B,kBAAkB,IAAA;IAClB,kBAAkB,IAAA;IAClB,wBAAwB,IAAA;IACxB,wBAAwB,IAAA;IACxB,kCAAkC,IAAA;IAClC,kCAAkC,KAAA;IAClC,kCAAkC,KAAA;IAClC,yBAAyB,KAAA;IACzB,iBAAiB,KAAA;IACjB,sBAAsB,KAAA;IACtB,mBAAmB,KAAA;IACnB,WAAW,KAAA;IACX,uBAAuB,KAAA;CACxB;AA0FD,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB;iBAtFpC,MAAM;gBAAc,MAAM;EAwF1C;AAED,qBAAa,cAAc;IAIN,IAAI,EAAE,kBAAkB;IAH3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAEE,IAAI,EAAE,kBAAkB;IAE3C,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS;CAG/D"}
1
+ {"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../src/extractor/err.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC5B,aAAa,IAAA;IACb,WAAW,IAAA;IACX,WAAW,IAAA;IACX,mBAAmB,IAAA;IACnB,2BAA2B,IAAA;IAC3B,kBAAkB,IAAA;IAClB,uBAAuB,IAAA;IACvB,wBAAwB,IAAA;IACxB,qBAAqB,IAAA;IACrB,uBAAuB,IAAA;IACvB,yBAAyB,KAAA;IACzB,mBAAmB,KAAA;IACnB,WAAW,KAAA;IACX,sBAAsB,KAAA;IACtB,uBAAuB,KAAA;IACvB,aAAa,KAAA;IACb,mBAAmB,KAAA;CACpB;AAuFD,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB;iBAnFpC,MAAM;gBAAc,MAAM;EAqF1C;AAED,qBAAa,cAAc;IAIN,IAAI,EAAE,kBAAkB;IAH3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAEE,IAAI,EAAE,kBAAkB;IAE3C,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS;CAG/D"}
@@ -1,32 +1,31 @@
1
1
  export var ExtractorErrorCode;
2
2
  (function (ExtractorErrorCode) {
3
3
  ExtractorErrorCode[ExtractorErrorCode["MissingExport"] = 0] = "MissingExport";
4
- ExtractorErrorCode[ExtractorErrorCode["AppMissingDefaultExport"] = 1] = "AppMissingDefaultExport";
4
+ ExtractorErrorCode[ExtractorErrorCode["InvalidMain"] = 1] = "InvalidMain";
5
5
  ExtractorErrorCode[ExtractorErrorCode["UnknownType"] = 2] = "UnknownType";
6
6
  ExtractorErrorCode[ExtractorErrorCode["MultipleGenericType"] = 3] = "MultipleGenericType";
7
7
  ExtractorErrorCode[ExtractorErrorCode["InvalidDataSourceDefinition"] = 4] = "InvalidDataSourceDefinition";
8
8
  ExtractorErrorCode[ExtractorErrorCode["InvalidPartialType"] = 5] = "InvalidPartialType";
9
- ExtractorErrorCode[ExtractorErrorCode["InvalidIncludeTree"] = 6] = "InvalidIncludeTree";
10
- ExtractorErrorCode[ExtractorErrorCode["InvalidAttributeModifier"] = 7] = "InvalidAttributeModifier";
11
- ExtractorErrorCode[ExtractorErrorCode["InvalidApiMethodModifier"] = 8] = "InvalidApiMethodModifier";
12
- ExtractorErrorCode[ExtractorErrorCode["UnknownNavigationPropertyReference"] = 9] = "UnknownNavigationPropertyReference";
13
- ExtractorErrorCode[ExtractorErrorCode["InvalidNavigationPropertyReference"] = 10] = "InvalidNavigationPropertyReference";
14
- ExtractorErrorCode[ExtractorErrorCode["MissingNavigationPropertyReference"] = 11] = "MissingNavigationPropertyReference";
15
- ExtractorErrorCode[ExtractorErrorCode["MissingManyToManyUniqueId"] = 12] = "MissingManyToManyUniqueId";
16
- ExtractorErrorCode[ExtractorErrorCode["MissingPrimaryKey"] = 13] = "MissingPrimaryKey";
17
- ExtractorErrorCode[ExtractorErrorCode["MissingDatabaseBinding"] = 14] = "MissingDatabaseBinding";
18
- ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 15] = "TooManyWranglerEnvs";
19
- ExtractorErrorCode[ExtractorErrorCode["MissingFile"] = 16] = "MissingFile";
20
- ExtractorErrorCode[ExtractorErrorCode["InvalidServiceAttribute"] = 17] = "InvalidServiceAttribute";
9
+ ExtractorErrorCode[ExtractorErrorCode["InvalidPropertyModifier"] = 6] = "InvalidPropertyModifier";
10
+ ExtractorErrorCode[ExtractorErrorCode["InvalidApiMethodModifier"] = 7] = "InvalidApiMethodModifier";
11
+ ExtractorErrorCode[ExtractorErrorCode["InvalidSelectorSyntax"] = 8] = "InvalidSelectorSyntax";
12
+ ExtractorErrorCode[ExtractorErrorCode["InvalidOneToOneSelector"] = 9] = "InvalidOneToOneSelector";
13
+ ExtractorErrorCode[ExtractorErrorCode["InvalidNavigationProperty"] = 10] = "InvalidNavigationProperty";
14
+ ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 11] = "TooManyWranglerEnvs";
15
+ ExtractorErrorCode[ExtractorErrorCode["MissingFile"] = 12] = "MissingFile";
16
+ ExtractorErrorCode[ExtractorErrorCode["InvalidServiceProperty"] = 13] = "InvalidServiceProperty";
17
+ ExtractorErrorCode[ExtractorErrorCode["InvalidTypescriptSyntax"] = 14] = "InvalidTypescriptSyntax";
18
+ ExtractorErrorCode[ExtractorErrorCode["MissingKValue"] = 15] = "MissingKValue";
19
+ ExtractorErrorCode[ExtractorErrorCode["MissingR2ObjectBody"] = 16] = "MissingR2ObjectBody";
21
20
  })(ExtractorErrorCode || (ExtractorErrorCode = {}));
22
21
  const errorInfoMap = {
23
22
  [ExtractorErrorCode.MissingExport]: {
24
23
  description: "All Cloesce types must be exported.",
25
24
  suggestion: "Add `export` to the class definition.",
26
25
  },
27
- [ExtractorErrorCode.AppMissingDefaultExport]: {
28
- description: "app.cloesce.ts does not export a CloesceApp by default",
29
- suggestion: "Export an instantiated CloesceApp in app.cloesce.ts",
26
+ [ExtractorErrorCode.InvalidMain]: {
27
+ description: "The main function must follow the expected signature.",
28
+ suggestion: "Change to: export default async function main(request: Request, env: WranglerEnv, app: CloesceApp, ctx: ExecutionContext): Promise<Response> {...}",
30
29
  },
31
30
  [ExtractorErrorCode.UnknownType]: {
32
31
  description: "Encountered an unknown or unsupported type",
@@ -44,11 +43,7 @@ const errorInfoMap = {
44
43
  description: "Data Sources must be explicitly typed as a static Include Tree",
45
44
  suggestion: "Declare your data source as `static readonly _: IncludeTree<Model>`",
46
45
  },
47
- [ExtractorErrorCode.InvalidIncludeTree]: {
48
- description: "Invalid Include Tree",
49
- suggestion: "Include trees must only contain references to a model's navigation properties.",
50
- },
51
- [ExtractorErrorCode.InvalidAttributeModifier]: {
46
+ [ExtractorErrorCode.InvalidPropertyModifier]: {
52
47
  description: "Attributes can only be public on a Model, Plain Old Object or Wrangler Environment",
53
48
  suggestion: "Change the attribute modifier to just `public`",
54
49
  },
@@ -56,30 +51,6 @@ const errorInfoMap = {
56
51
  description: "Model methods must be public if they are decorated as GET, POST, PUT, PATCH",
57
52
  suggestion: "Change the method modifier to just `public`",
58
53
  },
59
- [ExtractorErrorCode.UnknownNavigationPropertyReference]: {
60
- description: "Unknown Navigation Property Reference",
61
- suggestion: "Verify that the navigation property reference model exists, or create a model.",
62
- },
63
- [ExtractorErrorCode.InvalidNavigationPropertyReference]: {
64
- description: "Invalid Navigation Property Reference",
65
- suggestion: "Ensure the navigation property points to a valid model field",
66
- },
67
- [ExtractorErrorCode.MissingNavigationPropertyReference]: {
68
- description: "Missing Navigation Property Reference",
69
- suggestion: "Navigation properties require a foreign key model attribute reference",
70
- },
71
- [ExtractorErrorCode.MissingManyToManyUniqueId]: {
72
- description: "Missing unique id on Many to Many navigation property",
73
- suggestion: "Define a unique identifier field for the Many-to-Many relationship",
74
- },
75
- [ExtractorErrorCode.MissingPrimaryKey]: {
76
- description: "Missing primary key on a model",
77
- suggestion: "Add a primary key field to your model (e.g., `id: number`)",
78
- },
79
- [ExtractorErrorCode.MissingDatabaseBinding]: {
80
- description: "Missing a database binding in the WranglerEnv definition",
81
- suggestion: "Add a `D1Database` to your WranglerEnv",
82
- },
83
54
  [ExtractorErrorCode.TooManyWranglerEnvs]: {
84
55
  description: "Too many wrangler environments defined in the project",
85
56
  suggestion: "Consolidate or remove unused @WranglerEnv's",
@@ -88,10 +59,34 @@ const errorInfoMap = {
88
59
  description: "A specified input file could not be found",
89
60
  suggestion: "Verify the input file path is correct",
90
61
  },
91
- [ExtractorErrorCode.InvalidServiceAttribute]: {
62
+ [ExtractorErrorCode.InvalidServiceProperty]: {
92
63
  description: "Services must contain only dependency injected instances as attributes.",
93
64
  suggestion: "Remove the attribute.",
94
65
  },
66
+ [ExtractorErrorCode.InvalidTypescriptSyntax]: {
67
+ description: "The TypeScript syntax is invalid.",
68
+ suggestion: "Fix the TypeScript syntax errors.",
69
+ },
70
+ [ExtractorErrorCode.MissingKValue]: {
71
+ description: "All KV decorated fields must be of type KValue<T>",
72
+ suggestion: "Change the field type to KValue<T>.",
73
+ },
74
+ [ExtractorErrorCode.MissingR2ObjectBody]: {
75
+ description: "All R2 decorated fields must be of type R2ObjectBody.",
76
+ suggestion: "Change the field type to R2ObjectBody.",
77
+ },
78
+ [ExtractorErrorCode.InvalidSelectorSyntax]: {
79
+ description: "The selector syntax is invalid.",
80
+ suggestion: "Selectors should be of the form `N<T>(m => m.property)` where T is a model type and N is OneToOne or OneToMany.",
81
+ },
82
+ [ExtractorErrorCode.InvalidOneToOneSelector]: {
83
+ description: "OneToOne selectors must select a model constructor or name string.",
84
+ suggestion: "Ensure the selector is of the form `OneToOne<T>(...)` where T is a model type or a string representing the model name.",
85
+ },
86
+ [ExtractorErrorCode.InvalidNavigationProperty]: {
87
+ description: "A navigation property must be of type T, T | undefined, or T[] where T is a model type.",
88
+ suggestion: "Change the property type to be of the correct form.",
89
+ },
95
90
  };
96
91
  export function getErrorInfo(code) {
97
92
  return errorInfoMap[code];
@@ -1,21 +1,28 @@
1
- import { Project, Type, SourceFile, MethodDeclaration, ClassDeclaration, Expression } from "ts-morph";
2
- import { CidlIncludeTree, CloesceAst, CidlType, HttpVerb, Model, ApiMethod, WranglerEnv, PlainOldObject, Service } from "../ast.js";
1
+ import { Project, Type, SourceFile, ClassDeclaration, Decorator } from "ts-morph";
2
+ import { CloesceAst, CidlType, WranglerEnv } from "../ast.js";
3
3
  import { ExtractorError } from "./err.js";
4
- import { Either } from "../ui/common.js";
4
+ import { Either } from "../common.js";
5
5
  export declare class CidlExtractor {
6
- projectName: string;
7
- version: string;
8
- constructor(projectName: string, version: string);
9
- extract(project: Project): Either<ExtractorError, CloesceAst>;
10
- static app(sourceFile: SourceFile): Either<ExtractorError, string>;
11
- static model(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, Model>;
12
- static modelMethod(modelName: string, method: MethodDeclaration, verb: HttpVerb): Either<ExtractorError, ApiMethod>;
13
- static service(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, Service>;
14
- static serviceMethod(method: MethodDeclaration, verb: HttpVerb): Either<ExtractorError, ApiMethod>;
15
- static poo(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, PlainOldObject>;
6
+ private modelDecls;
7
+ private extractedPoos;
8
+ private constructor();
9
+ static extract(projectName: string, project: Project): Either<ExtractorError, CloesceAst>;
10
+ /**
11
+ * @returns An error if the main function is invalid, or the source code of the app function if valid.
12
+ * Undefined if no main function is defined.
13
+ */
14
+ private static main;
15
+ private model;
16
+ private service;
17
+ private method;
18
+ private poo;
16
19
  static env(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, WranglerEnv>;
17
20
  private static readonly primTypeMap;
18
21
  static cidlType(type: Type, inject?: boolean): Either<ExtractorError, CidlType>;
19
- static includeTree(expr: Expression | undefined, currentClass: ClassDeclaration, sf: SourceFile): Either<ExtractorError, CidlIncludeTree>;
22
+ /**
23
+ * Mutates the property declaration to add inferred decorators based on naming conventions.
24
+ */
25
+ private inferModelDecorator;
20
26
  }
27
+ export declare function getSelectorPropertyName(decorator: Decorator): Either<ExtractorError, string>;
21
28
  //# 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,EACP,IAAI,EACJ,UAAU,EAEV,iBAAiB,EAEjB,gBAAgB,EAEhB,UAAU,EAEX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,eAAe,EACf,UAAU,EACV,QAAQ,EAER,QAAQ,EACR,KAAK,EAEL,SAAS,EAGT,WAAW,EACX,cAAc,EAEd,OAAO,EAER,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAsB,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAuBzC,qBAAa,aAAa;IAEf,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,MAAM;gBADf,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM;IAGxB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC;IA4G7D,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,cAAc,EAAE,MAAM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