cloesce 0.1.0 → 0.1.1

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/cli.js CHANGED
@@ -6,7 +6,7 @@ import path from "node:path";
6
6
  import { command, run, subcommands, flag, string, positional, option, optional, } from "cmd-ts";
7
7
  import { Project } from "ts-morph";
8
8
  import { CidlExtractor } from "./extractor/extract.js";
9
- import { ExtractorError, ExtractorErrorCode, getErrorInfo, } from "./extractor/err.js";
9
+ import { ExtractorErrorCode, getErrorInfo, } from "./extractor/err.js";
10
10
  let debugPhase = "npm cloesce";
11
11
  function debug(...args) {
12
12
  console.log(`[${debugPhase}]: `, ...args);
@@ -177,7 +177,8 @@ async function extract(config, args = {}) {
177
177
  }));
178
178
  const fileCount = project.getSourceFiles().length;
179
179
  if (fileCount === 0) {
180
- new ExtractorError(ExtractorErrorCode.MissingFile);
180
+ console.warn("No .cloesce.ts files found in the specified paths.");
181
+ process.exit(1);
181
182
  }
182
183
  debug(`Found ${fileCount} .cloesce.ts files`);
183
184
  try {
@@ -7,15 +7,12 @@ export declare enum ExtractorErrorCode {
7
7
  InvalidPropertyModifier = 5,
8
8
  InvalidApiMethodModifier = 6,
9
9
  InvalidSelectorSyntax = 7,
10
- InvalidOneToOneSelector = 8,
11
- InvalidNavigationProperty = 9,
12
- TooManyWranglerEnvs = 10,
13
- MissingFile = 11,
14
- InvalidServiceProperty = 12,
15
- InvalidTypescriptSyntax = 13,
16
- MissingKValue = 14,
17
- MissingR2ObjectBody = 15,
18
- InvalidServiceInitializer = 16
10
+ InvalidNavigationProperty = 8,
11
+ TooManyWranglerEnvs = 9,
12
+ InvalidTypescriptSyntax = 10,
13
+ MissingKValue = 11,
14
+ MissingR2ObjectBody = 12,
15
+ InvalidServiceInitializer = 13
19
16
  }
20
17
  export declare function getErrorInfo(code: ExtractorErrorCode): {
21
18
  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,WAAW,IAAA;IACX,WAAW,IAAA;IACX,mBAAmB,IAAA;IACnB,2BAA2B,IAAA;IAC3B,uBAAuB,IAAA;IACvB,wBAAwB,IAAA;IACxB,qBAAqB,IAAA;IACrB,uBAAuB,IAAA;IACvB,yBAAyB,IAAA;IACzB,mBAAmB,KAAA;IACnB,WAAW,KAAA;IACX,sBAAsB,KAAA;IACtB,uBAAuB,KAAA;IACvB,aAAa,KAAA;IACb,mBAAmB,KAAA;IACnB,yBAAyB,KAAA;CAC1B;AAwFD,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB;iBApFpC,MAAM;gBAAc,MAAM;EAsF1C;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,uBAAuB,IAAA;IACvB,wBAAwB,IAAA;IACxB,qBAAqB,IAAA;IACrB,yBAAyB,IAAA;IACzB,mBAAmB,IAAA;IACnB,uBAAuB,KAAA;IACvB,aAAa,KAAA;IACb,mBAAmB,KAAA;IACnB,yBAAyB,KAAA;CAC1B;AAyED,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB;iBArEpC,MAAM;gBAAc,MAAM;EAuE1C;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"}
@@ -8,15 +8,12 @@ export var ExtractorErrorCode;
8
8
  ExtractorErrorCode[ExtractorErrorCode["InvalidPropertyModifier"] = 5] = "InvalidPropertyModifier";
9
9
  ExtractorErrorCode[ExtractorErrorCode["InvalidApiMethodModifier"] = 6] = "InvalidApiMethodModifier";
10
10
  ExtractorErrorCode[ExtractorErrorCode["InvalidSelectorSyntax"] = 7] = "InvalidSelectorSyntax";
11
- ExtractorErrorCode[ExtractorErrorCode["InvalidOneToOneSelector"] = 8] = "InvalidOneToOneSelector";
12
- ExtractorErrorCode[ExtractorErrorCode["InvalidNavigationProperty"] = 9] = "InvalidNavigationProperty";
13
- ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 10] = "TooManyWranglerEnvs";
14
- ExtractorErrorCode[ExtractorErrorCode["MissingFile"] = 11] = "MissingFile";
15
- ExtractorErrorCode[ExtractorErrorCode["InvalidServiceProperty"] = 12] = "InvalidServiceProperty";
16
- ExtractorErrorCode[ExtractorErrorCode["InvalidTypescriptSyntax"] = 13] = "InvalidTypescriptSyntax";
17
- ExtractorErrorCode[ExtractorErrorCode["MissingKValue"] = 14] = "MissingKValue";
18
- ExtractorErrorCode[ExtractorErrorCode["MissingR2ObjectBody"] = 15] = "MissingR2ObjectBody";
19
- ExtractorErrorCode[ExtractorErrorCode["InvalidServiceInitializer"] = 16] = "InvalidServiceInitializer";
11
+ ExtractorErrorCode[ExtractorErrorCode["InvalidNavigationProperty"] = 8] = "InvalidNavigationProperty";
12
+ ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 9] = "TooManyWranglerEnvs";
13
+ ExtractorErrorCode[ExtractorErrorCode["InvalidTypescriptSyntax"] = 10] = "InvalidTypescriptSyntax";
14
+ ExtractorErrorCode[ExtractorErrorCode["MissingKValue"] = 11] = "MissingKValue";
15
+ ExtractorErrorCode[ExtractorErrorCode["MissingR2ObjectBody"] = 12] = "MissingR2ObjectBody";
16
+ ExtractorErrorCode[ExtractorErrorCode["InvalidServiceInitializer"] = 13] = "InvalidServiceInitializer";
20
17
  })(ExtractorErrorCode || (ExtractorErrorCode = {}));
21
18
  const errorInfoMap = {
22
19
  [ExtractorErrorCode.MissingExport]: {
@@ -51,14 +48,6 @@ const errorInfoMap = {
51
48
  description: "Too many wrangler environments defined in the project",
52
49
  suggestion: "Consolidate or remove unused @WranglerEnv's",
53
50
  },
54
- [ExtractorErrorCode.MissingFile]: {
55
- description: "A specified input file could not be found",
56
- suggestion: "Verify the input file path is correct",
57
- },
58
- [ExtractorErrorCode.InvalidServiceProperty]: {
59
- description: "Services must contain only dependency injected instances as attributes.",
60
- suggestion: "Remove the attribute.",
61
- },
62
51
  [ExtractorErrorCode.InvalidTypescriptSyntax]: {
63
52
  description: "The TypeScript syntax is invalid.",
64
53
  suggestion: "Fix the TypeScript syntax errors.",
@@ -75,10 +64,6 @@ const errorInfoMap = {
75
64
  description: "The selector syntax is invalid.",
76
65
  suggestion: "Selectors should be of the form `N<T>(m => m.property)` where T is a model type and N is OneToOne or OneToMany.",
77
66
  },
78
- [ExtractorErrorCode.InvalidOneToOneSelector]: {
79
- description: "OneToOne selectors must select a model constructor or name string.",
80
- suggestion: "Ensure the selector is of the form `OneToOne<T>(...)` where T is a model type or a string representing the model name.",
81
- },
82
67
  [ExtractorErrorCode.InvalidNavigationProperty]: {
83
68
  description: "A navigation property must be of type T, T | undefined, or T[] where T is a model type.",
84
69
  suggestion: "Change the property type to be of the correct form.",
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"orm.d.ts","sourceRoot":"","sources":["../../src/router/orm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,QAAQ,EACT,MAAM,2BAA2B,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orm {
126
126
  recurse(instance, model, args.includeTree ?? {});
127
127
  await Promise.all(promises);
128
128
  return instance;
129
- async function hydrateKVList(namespace, key, kv, current) {
130
- const res = await namespace.list({ prefix: key });
131
- if (kv.value.cidl_type === "Stream") {
132
- current[kv.value.name] = await Promise.all(res.keys.map(async (k) => {
133
- const stream = await namespace.get(k.name, { type: "stream" });
134
- return Object.assign(new KValue(), {
135
- key: k.name,
136
- raw: stream,
137
- metadata: null,
138
- });
139
- }));
140
- }
141
- else {
142
- current[kv.value.name] = await Promise.all(res.keys.map(async (k) => {
143
- const kvRes = await namespace.getWithMetadata(k.name, {
144
- type: "json",
145
- });
146
- return Object.assign(new KValue(), {
147
- key: k.name,
148
- raw: kvRes.value,
149
- metadata: kvRes.metadata,
150
- });
151
- }));
152
- }
153
- }
154
- async function hydrateKVSingle(namespace, key, kv, current) {
155
- if (kv.value.cidl_type === "Stream") {
156
- const res = await namespace.get(key, { type: "stream" });
157
- current[kv.value.name] = Object.assign(new KValue(), {
158
- key,
159
- raw: res,
160
- metadata: null,
161
- });
162
- }
163
- else {
164
- const res = await namespace.getWithMetadata(key, { type: "json" });
165
- current[kv.value.name] = Object.assign(new KValue(), {
166
- key,
167
- raw: res.value,
168
- metadata: res.metadata,
169
- });
170
- }
171
- }
172
129
  function recurse(current, meta, includeTree) {
173
130
  // Hydrate navigation properties
174
131
  for (const navProp of meta.navigation_properties) {
@@ -276,6 +233,49 @@ export class Orm {
276
233
  }
277
234
  }
278
235
  }
236
+ async function hydrateKVList(namespace, key, kv, current) {
237
+ const res = await namespace.list({ prefix: key });
238
+ if (kv.value.cidl_type === "Stream") {
239
+ current[kv.value.name] = await Promise.all(res.keys.map(async (k) => {
240
+ const stream = await namespace.get(k.name, { type: "stream" });
241
+ return Object.assign(new KValue(), {
242
+ key: k.name,
243
+ raw: stream,
244
+ metadata: null,
245
+ });
246
+ }));
247
+ }
248
+ else {
249
+ current[kv.value.name] = await Promise.all(res.keys.map(async (k) => {
250
+ const kvRes = await namespace.getWithMetadata(k.name, {
251
+ type: "json",
252
+ });
253
+ return Object.assign(new KValue(), {
254
+ key: k.name,
255
+ raw: kvRes.value,
256
+ metadata: kvRes.metadata,
257
+ });
258
+ }));
259
+ }
260
+ }
261
+ async function hydrateKVSingle(namespace, key, kv, current) {
262
+ if (kv.value.cidl_type === "Stream") {
263
+ const res = await namespace.get(key, { type: "stream" });
264
+ current[kv.value.name] = Object.assign(new KValue(), {
265
+ key,
266
+ raw: res,
267
+ metadata: null,
268
+ });
269
+ }
270
+ else {
271
+ const res = await namespace.getWithMetadata(key, { type: "json" });
272
+ current[kv.value.name] = Object.assign(new KValue(), {
273
+ key,
274
+ raw: res.value,
275
+ metadata: res.metadata,
276
+ });
277
+ }
278
+ }
279
279
  }
280
280
  /**
281
281
  * Given a new Model object, performs an upsert operation for D1 and KV.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloesce",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Compile simple TypeScript classes into a full stack Cloudflare project.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",