@lunora/codegen 1.0.0-alpha.35 → 1.0.0-alpha.37

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/index.mjs CHANGED
@@ -2,7 +2,7 @@ export { formatAdvisories, lintSchema } from './packem_shared/formatAdvisories-D
2
2
  export { CodegenDiagnosticError, diagnosticAt } from './packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs';
3
3
  export { default as discoverAuthApiCalls } from './packem_shared/discoverAuthApiCalls-URDoTADN.mjs';
4
4
  export { CONTAINERS_FILENAME, discoverContainers } from './packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs';
5
- export { default as discoverCrons } from './packem_shared/discoverCrons-DdZOeroL.mjs';
5
+ export { default as discoverCrons } from './packem_shared/discoverCrons-BNL5hAPv.mjs';
6
6
  export { FLAGS_FILENAME, discoverFlags } from './packem_shared/FLAGS_FILENAME-BjpS5w08.mjs';
7
7
  export { discoverFunctions } from './packem_shared/discoverFunctions-BJdF7lRs.mjs';
8
8
  export { default as discoverHttpRoutes } from './packem_shared/discoverHttpRoutes-CcwP-Rkr.mjs';
@@ -19,11 +19,11 @@ export { default as discoverSchema } from './packem_shared/discoverSchema-CeXJWV
19
19
  export { SHAPES_FILENAME, discoverShapes } from './packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs';
20
20
  export { default as discoverStorageRulesMetadata } from './packem_shared/discoverStorageRulesMetadata-CFHByjIl.mjs';
21
21
  export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/WORKFLOWS_FILENAME-CCC_42o3.mjs';
22
- export { G as GENERATED_HEADER, e as emitApi, a as emitCollections, b as emitContainers, c as emitCrons, d as emitDataModel, f as emitDrizzleSchema, g as emitFunctions, h as emitServer, i as emitShard, j as emitVectors, k as emitWorkflows, l as emitWranglerCronTriggers } from './packem_shared/emit-CBwEvCXQ.mjs';
23
- export { emitApp } from './packem_shared/emitApp-nQ2oC-8G.mjs';
24
- export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-bp1pYSV6.mjs';
25
- export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-4YIeMkOI.mjs';
26
- export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-C6Q0h0O5.mjs';
22
+ export { G as GENERATED_HEADER, e as emitApi, a as emitCollections, b as emitContainers, c as emitCrons, d as emitDataModel, f as emitDrizzleSchema, g as emitFunctions, h as emitServer, i as emitShard, j as emitVectors, k as emitWorkflows, l as emitWranglerCronTriggers } from './packem_shared/emit-Bl3STBW9.mjs';
23
+ export { emitApp } from './packem_shared/emitApp-CPfFyx9U.mjs';
24
+ export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-CYHG8Yuq.mjs';
25
+ export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-BUv-bV3M.mjs';
26
+ export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-CCiIKql3.mjs';
27
27
  export { SCHEMA_SNAPSHOT_VERSION, SchemaSnapshotParseError, buildSchemaSnapshot, diffSchemaSnapshots, evaluateSchemaDrift, parseSchemaSnapshot, serializeSchemaSnapshot } from './packem_shared/SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs';
28
28
  export { schemaFromIr } from './packem_shared/schemaFromIr-DTYsLBaA.mjs';
29
29
  export { LUNORA_ERROR_CODES, validatorIrToJsonSchema } from './packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs';
@@ -1,3 +1,3 @@
1
1
  import '@lunora/errors';
2
- export { G as GENERATED_HEADER, m as buildStorageColumns, e as emitApi, a as emitCollections, b as emitContainers, c as emitCrons, d as emitDataModel, f as emitDrizzleSchema, g as emitFunctions, n as emitQueues, o as emitSeed, h as emitServer, i as emitShard, j as emitVectors, k as emitWorkflows, l as emitWranglerCronTriggers } from './emit-CBwEvCXQ.mjs';
2
+ export { G as GENERATED_HEADER, m as buildStorageColumns, e as emitApi, a as emitCollections, b as emitContainers, c as emitCrons, d as emitDataModel, f as emitDrizzleSchema, g as emitFunctions, n as emitQueues, o as emitSeed, h as emitServer, i as emitShard, j as emitVectors, k as emitWorkflows, l as emitWranglerCronTriggers } from './emit-Bl3STBW9.mjs';
3
3
  import './paths-BRd6JHuF.mjs';
@@ -1,4 +1,4 @@
1
- import { G as GENERATED_HEADER } from './emit-CBwEvCXQ.mjs';
1
+ import { G as GENERATED_HEADER } from './emit-Bl3STBW9.mjs';
2
2
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
3
  import { argsObjectSchema, LUNORA_ERROR_CODES } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
4
 
@@ -7,9 +7,9 @@ import { lintSchema } from './formatAdvisories-DLIqHq5l.mjs';
7
7
  import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall, inlineHandler as inlineHandler$1, procedureHandler, chainUsesWrappedCall, isDatabaseAccessor, chainHasStep, discoverFunctions } from './discoverFunctions-BJdF7lRs.mjs';
8
8
  import discoverAuthApiCalls from './discoverAuthApiCalls-URDoTADN.mjs';
9
9
  import { discoverContainers } from './CONTAINERS_FILENAME-DjpXMqhp.mjs';
10
- import discoverCrons from './discoverCrons-DdZOeroL.mjs';
10
+ import discoverCrons from './discoverCrons-BNL5hAPv.mjs';
11
11
  import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
12
- import { C as CAPABILITIES, m as buildStorageColumns, d as emitDataModel, e as emitApi, h as emitServer, g as emitFunctions, i as emitShard, a as emitCollections, b as emitContainers, k as emitWorkflows, n as emitQueues, c as emitCrons, j as emitVectors, f as emitDrizzleSchema, o as emitSeed, l as emitWranglerCronTriggers } from './emit-CBwEvCXQ.mjs';
12
+ import { C as CAPABILITIES, m as buildStorageColumns, d as emitDataModel, e as emitApi, h as emitServer, g as emitFunctions, i as emitShard, a as emitCollections, b as emitContainers, k as emitWorkflows, n as emitQueues, c as emitCrons, j as emitVectors, f as emitDrizzleSchema, o as emitSeed, l as emitWranglerCronTriggers } from './emit-Bl3STBW9.mjs';
13
13
  import { discoverFlagKeys } from './FLAGS_FILENAME-BjpS5w08.mjs';
14
14
  import discoverHttpRoutes from './discoverHttpRoutes-CcwP-Rkr.mjs';
15
15
  import discoverInserts from './discoverInserts-BpFhM32L.mjs';
@@ -27,9 +27,9 @@ import { discoverShapes } from './SHAPES_FILENAME-DOhPGi-6.mjs';
27
27
  import discoverStorageRulesMetadata from './discoverStorageRulesMetadata-CFHByjIl.mjs';
28
28
  import { e as enclosingExportName$2 } from './discover-ast-CT6BgBr4.mjs';
29
29
  import { discoverWorkflows } from './WORKFLOWS_FILENAME-CCC_42o3.mjs';
30
- import { emitApp } from './emitApp-nQ2oC-8G.mjs';
31
- import { buildOpenApiDocument, emitOpenApiModule } from './buildOpenApiDocument-bp1pYSV6.mjs';
32
- import { buildOpenRpcDocument, emitOpenRpcModule } from './OPENRPC_VERSION-4YIeMkOI.mjs';
30
+ import { emitApp } from './emitApp-CPfFyx9U.mjs';
31
+ import { buildOpenApiDocument, emitOpenApiModule } from './buildOpenApiDocument-CYHG8Yuq.mjs';
32
+ import { buildOpenRpcDocument, emitOpenRpcModule } from './OPENRPC_VERSION-BUv-bV3M.mjs';
33
33
  import { buildSchemaSnapshot, serializeSchemaSnapshot } from './SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs';
34
34
 
35
35
  const HTTP_VERBS$1 = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put"]);
@@ -1,4 +1,4 @@
1
- import { G as GENERATED_HEADER } from './emit-CBwEvCXQ.mjs';
1
+ import { G as GENERATED_HEADER } from './emit-Bl3STBW9.mjs';
2
2
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
3
  import { LUNORA_ERROR_CODES, objectSchema, argsObjectSchema, validatorIrToJsonSchema } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
4
 
@@ -1,3 +1,4 @@
1
+ import { LunoraError } from '@lunora/errors';
1
2
  import { isValidCronExpression, compileCronSchedule, CRON_SCHEDULE_KINDS } from '@lunora/scheduler';
2
3
  import { SyntaxKind, Node } from 'ts-morph';
3
4
  import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
@@ -219,9 +220,7 @@ const assertUniqueNames = (crons) => {
219
220
  const seen = /* @__PURE__ */ new Set();
220
221
  for (const cron of crons) {
221
222
  if (seen.has(cron.name)) {
222
- throw Object.assign(new Error(`Duplicate cron job name "${cron.name}": cron names must be unique across the project.`), {
223
- code: "DUPLICATE_CRON_NAME",
224
- name: "LunoraError",
223
+ throw new LunoraError("DUPLICATE_CRON_NAME", `Duplicate cron job name "${cron.name}": cron names must be unique across the project.`, {
225
224
  status: 500
226
225
  });
227
226
  }
@@ -795,11 +795,7 @@ const CALL_REGISTERED_HELPER = `const callRegistered = async <R>(context: Caller
795
795
  const registered = LUNORA_FUNCTIONS[functionPath];
796
796
 
797
797
  if (!registered) {
798
- throw Object.assign(new Error(\`function not registered: \${functionPath}\`), {
799
- name: "LunoraError",
800
- code: "FUNCTION_NOT_FOUND",
801
- status: 404,
802
- });
798
+ throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
803
799
  }
804
800
 
805
801
  return (await registered.handler(context, args ?? {})) as R;
@@ -1252,7 +1248,8 @@ ${caller.implementation}
1252
1248
  const callRegisteredHelper = hasFunctions ? `${CALL_REGISTERED_HELPER}
1253
1249
 
1254
1250
  ` : "";
1255
- return `${GENERATED_HEADER}${importBlock}${compiledArgsImport}${shapeTypeImport}import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
1251
+ return `${GENERATED_HEADER}${importBlock}${compiledArgsImport}${shapeTypeImport}import { LunoraError } from "${base.server}";
1252
+ import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
1256
1253
  ${dataModelImport}
1257
1254
  /**
1258
1255
  * Single registered function, narrowed to the shape \`handleRpc\` needs.
@@ -1300,11 +1297,7 @@ export const dispatchLunoraFunction = async (functionPath: string, context: unkn
1300
1297
  const registered = LUNORA_FUNCTIONS[functionPath];
1301
1298
 
1302
1299
  if (!registered || registered.visibility === "internal") {
1303
- throw Object.assign(new Error(\`function not registered: \${functionPath}\`), {
1304
- name: "LunoraError",
1305
- code: "FUNCTION_NOT_FOUND",
1306
- status: 404,
1307
- });
1300
+ throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
1308
1301
  }
1309
1302
 
1310
1303
  return registered.handler(context, args);
@@ -2339,7 +2332,7 @@ const LUNORA_RLS_READ_REGISTRY = buildRlsReadRegistry(Object.values(LUNORA_FUNCT
2339
2332
  // inline into every generated shard. With shapes, also pull the RLS
2340
2333
  // read-registry builder + `composeShapeReadWhere` so `resolveShape` can
2341
2334
  // AND-merge a shape's predicate with the table's read base-where.
2342
- hasShapes ? `import { asBucketStorage, buildRlsReadRegistry, composeShapeReadWhere, createSecrets } from "${base.server}";` : `import { asBucketStorage, createSecrets } from "${base.server}";`
2335
+ hasShapes ? `import { asBucketStorage, buildRlsReadRegistry, composeShapeReadWhere, createSecrets, LunoraError } from "${base.server}";` : `import { asBucketStorage, createSecrets, LunoraError } from "${base.server}";`
2343
2336
  ];
2344
2337
  if (hasTables) {
2345
2338
  importLines.push(`import { bindOrm, bindTableFacade } from "${base.server}";`);
@@ -2771,11 +2764,7 @@ const dispatchRun = async (expected: FunctionKind, functionPath: string, args: R
2771
2764
  }
2772
2765
 
2773
2766
  if (runDepth >= MAX_RUN_DEPTH) {
2774
- throw Object.assign(new Error(\`ctx.run*: composition depth limit (\${MAX_RUN_DEPTH}) exceeded — likely a cyclic runQuery/runMutation\`), {
2775
- name: "LunoraError",
2776
- code: "RUN_DEPTH_EXCEEDED",
2777
- status: 500,
2778
- });
2767
+ throw new LunoraError("RUN_DEPTH_EXCEEDED", \`ctx.run*: composition depth limit (\${MAX_RUN_DEPTH}) exceeded — likely a cyclic runQuery/runMutation\`);
2779
2768
  }
2780
2769
 
2781
2770
  runDepth += 1;
@@ -2803,11 +2792,7 @@ export const createShardDO = (config: ShardDOConfig = {}): new (state: ShardDOSt
2803
2792
  // \`isSystemDispatch()\`). A client RPC never carries that flag, so its
2804
2793
  // internals stay not-found and never leak across the external boundary.
2805
2794
  if (!registered || (registered.visibility === "internal" && !this.isSystemDispatch())) {
2806
- throw Object.assign(new Error(\`function not registered: \${functionPath}\`), {
2807
- name: "LunoraError",
2808
- code: "FUNCTION_NOT_FOUND",
2809
- status: 404,
2810
- });
2795
+ throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
2811
2796
  }
2812
2797
 
2813
2798
  this.ensureMigrated();
@@ -2917,11 +2902,7 @@ ${flagsOverrides.evaluateOverride}${flagsOverrides.subscriptionOverride}${workfl
2917
2902
  const migration = LUNORA_MIGRATIONS[args.id];
2918
2903
 
2919
2904
  if (!migration) {
2920
- throw Object.assign(new Error(\`data migration "\${args.id}" is not registered\`), {
2921
- name: "LunoraError",
2922
- code: "MIGRATION_NOT_FOUND",
2923
- status: 404,
2924
- });
2905
+ throw new LunoraError("MIGRATION_NOT_FOUND", \`data migration "\${args.id}" is not registered\`, { status: 404 });
2925
2906
  }
2926
2907
 
2927
2908
  this.ensureMigrated();
@@ -2957,18 +2938,14 @@ ${flagsOverrides.evaluateOverride}${flagsOverrides.subscriptionOverride}${workfl
2957
2938
  const definition = (schema as unknown as SchemaLike).tables[args.table];
2958
2939
 
2959
2940
  if (!definition) {
2960
- throw Object.assign(new Error(\`unknown table: \${args.table}\`), { name: "LunoraError", code: "UNKNOWN_TABLE", status: 404 });
2941
+ throw new LunoraError("UNKNOWN_TABLE", \`unknown table: \${args.table}\`, { status: 404 });
2961
2942
  }
2962
2943
 
2963
2944
  // \`.global()\` tables live in D1, not this DO's SQLite — editing them
2964
2945
  // here would corrupt nothing but would fail confusingly, so reject up
2965
2946
  // front with a clear code the studio can surface.
2966
2947
  if (definition.shardMode?.kind === "global") {
2967
- throw Object.assign(new Error(\`table "\${args.table}" is global; edit it through D1, not the shard\`), {
2968
- name: "LunoraError",
2969
- code: "GLOBAL_TABLE_NOT_EDITABLE",
2970
- status: 400,
2971
- });
2948
+ throw new LunoraError("GLOBAL_TABLE_NOT_EDITABLE", \`table "\${args.table}" is global; edit it through D1, not the shard\`, { status: 400 });
2972
2949
  }
2973
2950
 
2974
2951
  this.ensureMigrated();
@@ -3012,17 +2989,13 @@ ${flagsOverrides.evaluateOverride}${flagsOverrides.subscriptionOverride}${workfl
3012
2989
  const definition = (schema as unknown as SchemaLike).tables[table];
3013
2990
 
3014
2991
  if (!definition) {
3015
- throw Object.assign(new Error(\`unknown table: \${table}\`), { name: "LunoraError", code: "UNKNOWN_TABLE", status: 404 });
2992
+ throw new LunoraError("UNKNOWN_TABLE", \`unknown table: \${table}\`, { status: 404 });
3016
2993
  }
3017
2994
 
3018
2995
  // \`.global()\` tables live in D1, not this DO's SQLite — the same
3019
2996
  // guard \`runShardWrite\` applies to single-row edits.
3020
2997
  if (definition.shardMode?.kind === "global") {
3021
- throw Object.assign(new Error(\`table "\${table}" is global; edit it through D1, not the shard\`), {
3022
- name: "LunoraError",
3023
- code: "GLOBAL_TABLE_NOT_EDITABLE",
3024
- status: 400,
3025
- });
2998
+ throw new LunoraError("GLOBAL_TABLE_NOT_EDITABLE", \`table "\${table}" is global; edit it through D1, not the shard\`, { status: 400 });
3026
2999
  }
3027
3000
 
3028
3001
  this.ensureMigrated();
@@ -3063,7 +3036,7 @@ ${flagsOverrides.evaluateOverride}${flagsOverrides.subscriptionOverride}${workfl
3063
3036
  // \`rankBefore\` is optional on \`DatabaseWriterLike\` (the D1 twin omits it),
3064
3037
  // but the shard writer from \`createShardCtxDb\` always defines it.
3065
3038
  if (!writer.rankBefore) {
3066
- throw Object.assign(new Error("rankBefore is unavailable on the shard writer"), { name: "LunoraError", code: "NOT_IMPLEMENTED", status: 500 });
3039
+ throw new LunoraError("NOT_IMPLEMENTED", "rankBefore is unavailable on the shard writer", { status: 500 });
3067
3040
  }
3068
3041
 
3069
3042
  return writer.rankBefore(args.table, args.index, {
@@ -3093,7 +3066,7 @@ ${flagsOverrides.evaluateOverride}${flagsOverrides.subscriptionOverride}${workfl
3093
3066
  // directions live in the schema's rankIndex, so the shard reads them itself;
3094
3067
  // \`args.directions\` is only the coordinator's comparator hint and isn't forwarded.
3095
3068
  if (!writer.rankPageRows) {
3096
- throw Object.assign(new Error("rankPage is unavailable on the shard writer"), { name: "LunoraError", code: "NOT_IMPLEMENTED", status: 500 });
3069
+ throw new LunoraError("NOT_IMPLEMENTED", "rankPage is unavailable on the shard writer", { status: 500 });
3097
3070
  }
3098
3071
 
3099
3072
  return writer.rankPageRows(args.table, args.index, {
@@ -1,4 +1,4 @@
1
- import { A as APP_METHOD_CAPABILITIES, G as GENERATED_HEADER } from './emit-CBwEvCXQ.mjs';
1
+ import { A as APP_METHOD_CAPABILITIES, G as GENERATED_HEADER } from './emit-Bl3STBW9.mjs';
2
2
 
3
3
  const hasFlagKey = (key) => `has${key.charAt(0).toUpperCase()}${key.slice(1)}`;
4
4
  const LONG_TAIL = APP_METHOD_CAPABILITIES.map(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.35",
3
+ "version": "1.0.0-alpha.37",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,7 +46,7 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.21",
49
+ "@lunora/advisor": "1.0.0-alpha.23",
50
50
  "@lunora/container": "1.0.0-alpha.7",
51
51
  "@lunora/errors": "1.0.0-alpha.2",
52
52
  "@lunora/queue": "1.0.0-alpha.5",