@lunora/codegen 1.0.0-alpha.143 → 1.0.0-alpha.145

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.d.mts CHANGED
@@ -75,15 +75,38 @@ interface SchemaSnapshot {
75
75
  * UI-disagrees-with-the-deploy-gate divergence this module exists to prevent.
76
76
  */
77
77
  type DriftScope = "schema" | "table";
78
+ /**
79
+ * What actually fixes a change, so a consumer can name the right tool.
80
+ *
81
+ * - `"backfill"` — a `defineMigration` transform rewrites the affected rows.
82
+ * The ONLY value for which a data migration is the answer.
83
+ * - `"rehome"` — the rows' physical storage moves (a different Durable Object,
84
+ * or a different region). The per-shard runner only ever replaces a row inside
85
+ * the shard it was handed, so no transform reaches these; the fix is an
86
+ * export/import round trip, or a revert.
87
+ * - `"code"` — nothing happens to stored data; a query or a call site has to
88
+ * change (a dropped index, a dropped relation).
89
+ * - `"none"` — additive, nothing to do.
90
+ *
91
+ * This lives HERE, next to the change union, for the same reason {@link DriftScope}
92
+ * does: a hand-maintained set of type names in the consumer gives zero
93
+ * compile-time pressure, so a new variant would silently default to whatever the
94
+ * set omits. The deploy gate uses this to decide both what a data migration may
95
+ * excuse and which tables it offers to scaffold one for — a wrong default there
96
+ * sends the operator to a tool that cannot work.
97
+ */
98
+ type DriftRemediation = "backfill" | "code" | "none" | "rehome";
78
99
  /** One classified structural change between two snapshots. */
79
100
  interface DriftChange {
101
+ /** What fixes this change — see {@link DriftRemediation}. `"none"` for every `safe` change. */
102
+ remediation: DriftRemediation;
80
103
  /**
81
104
  * `"table"` means this table's own DDL moved (fields, indexes, shard mode) —
82
105
  * a relation whose foreign key lives on the OTHER table stays `"schema"`, so
83
106
  * the "changed" signal keeps meaning "this table's shape moved".
84
107
  */
85
108
  scope: DriftScope;
86
- /** `"breaking"` changes need a data migration; `"safe"` changes are additive. */
109
+ /** `"breaking"` changes need attention before deploy; `"safe"` changes are additive. */
87
110
  severity: "breaking" | "safe";
88
111
  /** Human-readable, actionable description (used in the gate message). */
89
112
  summary: string;
@@ -436,8 +459,10 @@ interface FunctionIR {
436
459
  /**
437
460
  * A `defineMigration({...})` declaration discovered in the user's lunora
438
461
  * sources. The emitted `LUNORA_MIGRATIONS` registry keys on {@link MigrationIR.id}; the
439
- * import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. {@link MigrationIR.table} is
440
- * informational (the runtime object carries the authoritative value).
462
+ * import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. The runtime object
463
+ * carries the authoritative {@link MigrationIR.table}, but the lifted value is
464
+ * load-bearing at build time: the schema-drift gate matches it against the
465
+ * tables with breaking drift, so a migration left at `""` covers nothing.
441
466
  */
442
467
  interface MigrationIR {
443
468
  /** Export binding name, used to reference the module member in generated imports. */
@@ -905,15 +930,18 @@ interface NondeterministicCallIR {
905
930
  line: number;
906
931
  }
907
932
  /**
908
- * One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
909
- * `r2sql_outside_action` advisor lint input. Structurally identical to the
910
- * advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
911
- * `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
912
- * Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
913
- * home for `ctx.r2sql` and is skipped.
933
+ * One `ctx.<property>` access lexically inside a `query`/`mutation` handler —
934
+ * the feeder shape behind every "action-only surface used outside an action"
935
+ * advisor lint (`hyperdrive_outside_action` for `ctx.sql`,
936
+ * `r2sql_outside_action` for `ctx.r2sql`). Structurally identical to the
937
+ * advisor's `AdvisorHyperdriveCall` / `AdvisorR2sqlCall` (same field set) so
938
+ * values pass straight through `lintSchema` without conversion, exactly as
939
+ * {@link NondeterministicCallIR} does. Only `query`/`mutation` handlers are
940
+ * recorded; `action(...)` is the only context where these surfaces are even
941
+ * typed, so it is the intended home and is skipped.
914
942
  */
915
- interface R2sqlCallIR {
916
- /** The accessed `ctx.r2sql` surface, e.g. `ctx.r2sql.query` / `ctx.r2sql.from`. */
943
+ interface ContextPropertyCallIR {
944
+ /** The accessed surface, e.g. `ctx.sql.query` / `ctx.r2sql.from` — the property, suffixed with the method when one is called on it. */
917
945
  callee: string;
918
946
  /** Export binding name of the function performing the access. */
919
947
  exportName: string;
@@ -921,7 +949,7 @@ interface R2sqlCallIR {
921
949
  file: string;
922
950
  /** Which procedure kind the access lives in — only `query`/`mutation` handlers are recorded. */
923
951
  kind: "mutation" | "query";
924
- /** 1-based line of the access, or `0` when unknown. */
952
+ /** 1-based line of the access. */
925
953
  line: number;
926
954
  }
927
955
  /**
@@ -1773,9 +1801,9 @@ interface FlagSecurityDefaultIR {
1773
1801
  * `__cdc_log`, so a subscribed query is never re-run when a flag flips and keeps
1774
1802
  * serving the branch it last picked; `useFlag` is the reactive path. Structurally
1775
1803
  * identical to the advisor's `AdvisorFlagRead` (same field set) so values pass
1776
- * straight through `lintSchema` without conversion, exactly as `R2sqlCallIR` does.
1804
+ * straight through `lintSchema` without conversion, exactly as `ContextPropertyCallIR` does.
1777
1805
  *
1778
- * Only `query` handlers are recorded — unlike `R2sqlCallIR` / `NondeterministicCallIR`
1806
+ * Only `query` handlers are recorded — unlike `ContextPropertyCallIR` / `NondeterministicCallIR`
1779
1807
  * there is no `kind` field, because `mutation`/`action` handlers run once and have
1780
1808
  * no subscription staleness to warn about, so the feeder drops them rather than
1781
1809
  * handing the lint rows it would discard.
@@ -2026,6 +2054,7 @@ interface LintSchemaOptions {
2026
2054
  geoIndexUsages?: ReadonlyArray<AdvisorGeoIndexUsage>;
2027
2055
  httpActionGuards?: ReadonlyArray<HttpActionGuardIR>;
2028
2056
  httpHeaderWrites?: ReadonlyArray<HttpHeaderWriteIR>;
2057
+ hyperdriveCalls?: ReadonlyArray<ContextPropertyCallIR>;
2029
2058
  identityClaimReads?: ReadonlyArray<IdentityClaimReadIR>;
2030
2059
  imageDeliveryUrlAccesses?: ReadonlyArray<ImageDeliveryUrlAccessIR>;
2031
2060
  inserts?: ReadonlyArray<InsertWriteIR>;
@@ -2044,7 +2073,7 @@ interface LintSchemaOptions {
2044
2073
  procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>;
2045
2074
  queries?: ReadonlyArray<QueryReadIR>;
2046
2075
  queues?: ReadonlyArray<QueueIR>;
2047
- r2sqlCalls?: ReadonlyArray<R2sqlCallIR>;
2076
+ r2sqlCalls?: ReadonlyArray<ContextPropertyCallIR>;
2048
2077
  ratelimitKeySelectors?: ReadonlyArray<RatelimitKeySelectorIR>;
2049
2078
  rawRowReturns?: ReadonlyArray<RawRowReturnIR>;
2050
2079
  relationLoads?: ReadonlyArray<RelationLoadIR>;
@@ -2306,12 +2335,13 @@ declare const resolveCodegenTarget: (projectRoot: string, explicit?: string) =>
2306
2335
  * `@lunora/config`'s driver registry (`deployTargetIds`) used to assert
2307
2336
  * equality against this — "two id spaces for one concept" — on the theory that
2308
2337
  * a target with a matrix but no driver "gates a surface nothing can deploy."
2309
- * Plan 234 found that reasoning incomplete by registering `node` here: a
2310
- * codegen-gateable target and a deployable target are genuinely different
2311
- * questions, and a spike/dev-only host answers the first "yes" and the second
2312
- * "not yet" without that being a bug in either registry. See
2313
- * `plans/234-node-host-findings.md` for the finding and `@lunora/config`'s
2314
- * `project-config.test.ts` for where the now-relaxed invariant lives.
2338
+ * Both registries list `cloudflare` and `node` today, so they happen to agree;
2339
+ * the assertion stays relaxed because agreement is a coincidence of timing, not
2340
+ * an invariant. "Codegen can gate capabilities for this target" and "the CLI can
2341
+ * deploy to it" are different questions, and a new host answers the first the
2342
+ * moment its capability matrix lands — before its deploy driver exists. See
2343
+ * `@lunora/config`'s `project-config.test.ts` for where that relaxed invariant
2344
+ * lives.
2315
2345
  * @returns the registered matrix ids, sorted.
2316
2346
  */
2317
2347
  declare const platformMatrixIds: () => ReadonlyArray<string>;
@@ -2541,6 +2571,13 @@ interface CodegenResult {
2541
2571
  /** WorkflowEntrypoint classes (`_generated/workflows.ts`); `""` (and not written) when no workflows are declared. */
2542
2572
  workflows: string;
2543
2573
  };
2574
+ /**
2575
+ * Data migrations discovered from `defineMigration` exports under `lunora/`,
2576
+ * each with the table it iterates. The drift gate matches a NEW id against
2577
+ * its table so a backfill only excuses breaking drift on the table it
2578
+ * actually visits. Empty when the project declares none.
2579
+ */
2580
+ migrations: ReadonlyArray<MigrationIR>;
2544
2581
  outputDirectory: string;
2545
2582
  /**
2546
2583
  * Portability diagnostics for the requested {@link CodegenOptions.target}:
@@ -2681,6 +2718,17 @@ declare const discoverFunctions: (project: Project, lunoraDirectory: string) =>
2681
2718
  * These are the headline OpenAPI target: each becomes a real `paths` entry.
2682
2719
  */
2683
2720
  declare const discoverHttpRoutes: (project: Project, lunoraDirectory: string) => HttpRouteIR[];
2721
+ /**
2722
+ * Discover Hyperdrive `ctx.sql` accesses inside exported `query(...)` /
2723
+ * `mutation(...)` handlers — the `hyperdrive_outside_action` lint input.
2724
+ *
2725
+ * The lint shipped with no feeder at all: it returns `[]` unless
2726
+ * `context.hyperdriveCalls` is set, and nothing set it, so the one guardrail
2727
+ * against non-deterministic external SQL in a reactive handler never fired.
2728
+ * `ctx.sql` is typed on `ActionCtx` only, so `action(...)` bodies are skipped by
2729
+ * the shared walker — an access there is correct usage, not a finding.
2730
+ */
2731
+ declare const discoverHyperdriveCalls: (project: Project, lunoraDirectory: string) => ContextPropertyCallIR[];
2684
2732
  /**
2685
2733
  * Discover `ctx.db.insert("table", …)` writes under the lunora source directory
2686
2734
  * and attribute each to the exported function (and file) performing it. Calls
@@ -2786,18 +2834,11 @@ declare const QUEUES_FILENAME = "queues.ts";
2786
2834
  */
2787
2835
  declare const discoverQueues: (project: Project, lunoraDirectory: string) => QueueIR[];
2788
2836
  /**
2789
- * Discover `ctx.r2sql` accesses lexically inside the handler body of every
2790
- * exported `query(...)` / `mutation(...)` registration under the lunora source
2791
- * directory — the `r2sql_outside_action` lint input. `action(...)` (and
2792
- * `stream(...)`) registrations are intentionally skipped: R2 SQL is the
2793
- * external, non-reactive surface that belongs in actions.
2794
- *
2795
- * Traversal is scoped to the handler node (not the whole declaration), mirroring
2796
- * `discoverNondeterministicCalls` — so a `ctx.r2sql` touch in a sibling helper
2797
- * outside the handler is not attributed to the query/mutation. One
2798
- * {@link R2sqlCallIR} is produced per access site.
2837
+ * Discover `ctx.r2sql` accesses inside exported `query(...)` / `mutation(...)`
2838
+ * handlers — the `r2sql_outside_action` lint input. `action(...)` is the
2839
+ * intended home for R2 SQL and is skipped by the shared walker.
2799
2840
  */
2800
- declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => R2sqlCallIR[];
2841
+ declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => ContextPropertyCallIR[];
2801
2842
  declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string) => RlsProcedureIR[];
2802
2843
  /**
2803
2844
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
@@ -3160,8 +3201,19 @@ interface EmitAppOptions {
3160
3201
  hasHyperdriveGlobal: boolean;
3161
3202
  /** App uses `@lunora/bindings/images` / `ctx.images` → emit `.images()`. */
3162
3203
  hasImages: boolean;
3163
- /** App uses `@lunora/bindings/kv` / `ctx.kv` → emit `.kv()`. */
3204
+ /** App uses `@lunora/bindings/kv` / `ctx.kv` → emit `.kv()`. Usage-only, because the method's parameter type reads `ShardConfig["kv"]`, and that config field is emitted on the same usage signal. */
3164
3205
  hasKv: boolean;
3206
+ /**
3207
+ * Wire the studio's zero-config KV introspector. Gated on `studioFeatures.kv`
3208
+ * (usage OR a declared `@lunora/bindings` dependency), NOT on {@link EmitAppOptions.hasKv},
3209
+ * so a visible KV tab always has a working backend — never the reverse.
3210
+ *
3211
+ * Kept separate from `hasKv` deliberately: the two were accidentally equal
3212
+ * while the dependency arm in `discover/studio-features.ts` matched a subpath
3213
+ * and could never fire. Fixing that arm made them diverge, and the shared flag
3214
+ * emitted a `.kv()` builder whose `ShardConfig["kv"]` type did not exist.
3215
+ */
3216
+ hasKvIntrospector: boolean;
3165
3217
  /** App declares `lunora/notify.ts` (`@lunora/notify`) → wire `options.notifySubscriptionStore` so the studio Notifications page can read registered devices. */
3166
3218
  hasNotify: boolean;
3167
3219
  /** App uses `@lunora/payment` / `ctx.payments` → emit `.payment()`. */
@@ -3345,11 +3397,15 @@ declare class SchemaSnapshotParseError extends LunoraError {
3345
3397
  declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
3346
3398
  /** The decision the pre-deploy gate returns. */
3347
3399
  interface SchemaDriftDecision {
3348
- /** True when the deploy must be blocked (breaking drift with no new migration, and no override). */
3400
+ /** True when the deploy must be blocked (breaking drift no new migration covers, and no override). */
3349
3401
  blocked: boolean;
3350
3402
  /** Every classified change (both severities), for reporting. */
3351
3403
  changes: ReadonlyArray<DriftChange>;
3352
- /** Migration ids declared now but absent from the baseline — proof a migration was added. */
3404
+ /**
3405
+ * Migration ids declared now but absent from the baseline. Reported for
3406
+ * context; the gate acts on which of them cover an affected TABLE, not on how
3407
+ * many there are.
3408
+ */
3353
3409
  newMigrationIds: ReadonlyArray<string>;
3354
3410
  /**
3355
3411
  * A multi-line, actionable explanation. Always present; empty string when
@@ -3361,9 +3417,22 @@ interface SchemaDriftDecision {
3361
3417
  * Decide whether breaking schema drift should block a deploy.
3362
3418
  *
3363
3419
  * Blocks only when the baseline exists (a first-ever capture is never blocking),
3364
- * there is at least one `breaking` change, no NEW migration id was added since
3365
- * the baseline, and the `allowDrift` override is not set. Safe-only drift (or
3366
- * breaking drift accompanied by a new migration id) passes.
3420
+ * there is at least one `breaking` change, no new migration COVERS it, and the
3421
+ * `allowDrift` override is not set. Safe-only drift passes.
3422
+ *
3423
+ * "Covers" is per-table, not per-run: a new migration excuses breaking drift on
3424
+ * the table it iterates, and nothing else. Counting new ids alone let a backfill
3425
+ * on `messages` unblock a required field added to `users` — the gate reported
3426
+ * "accompanied by a migration" for a change that migration would never visit.
3427
+ * The shard-mode diff cites this block to justify the studio not shipping a
3428
+ * stranded-rows detector (see `shared/schema-snapshot.ts`), and that claim only
3429
+ * holds if an unrelated migration cannot wave it through.
3430
+ *
3431
+ * Only a `"backfill"` change is coverable at all. A `"rehome"` change moves rows
3432
+ * to another Durable Object or region and a `"code"` change breaks a call site;
3433
+ * rewriting rows fixes neither, so a migration must not excuse them however well
3434
+ * its table matches. Those are cleared by fixing the code or accepting the new
3435
+ * shape (`--allow-schema-drift` / `--update-schema-baseline`).
3367
3436
  */
3368
3437
  declare const evaluateSchemaDrift: (options: {
3369
3438
  allowDrift?: boolean;
@@ -3371,6 +3440,8 @@ declare const evaluateSchemaDrift: (options: {
3371
3440
  /** The command printing the remediation, so it names only flags that command accepts. */
3372
3441
  command?: string;
3373
3442
  current: SchemaSnapshot;
3443
+ /** This run's declared migrations, so a new one is matched to the table it iterates. */
3444
+ migrations: ReadonlyArray<Pick<MigrationIR, "id" | "table">>;
3374
3445
  }) => SchemaDriftDecision;
3375
3446
  /**
3376
3447
  * Convert a {@link SchemaIR} into a synthetic runtime {@link Schema} carrying just
@@ -3687,4 +3758,4 @@ declare const secretKindOf: (value: string) => string | undefined;
3687
3758
  /** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
3688
3759
  declare const redact: (value: string) => string;
3689
3760
  declare const VERSION = "0.0.0";
3690
- export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
3761
+ export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -75,15 +75,38 @@ interface SchemaSnapshot {
75
75
  * UI-disagrees-with-the-deploy-gate divergence this module exists to prevent.
76
76
  */
77
77
  type DriftScope = "schema" | "table";
78
+ /**
79
+ * What actually fixes a change, so a consumer can name the right tool.
80
+ *
81
+ * - `"backfill"` — a `defineMigration` transform rewrites the affected rows.
82
+ * The ONLY value for which a data migration is the answer.
83
+ * - `"rehome"` — the rows' physical storage moves (a different Durable Object,
84
+ * or a different region). The per-shard runner only ever replaces a row inside
85
+ * the shard it was handed, so no transform reaches these; the fix is an
86
+ * export/import round trip, or a revert.
87
+ * - `"code"` — nothing happens to stored data; a query or a call site has to
88
+ * change (a dropped index, a dropped relation).
89
+ * - `"none"` — additive, nothing to do.
90
+ *
91
+ * This lives HERE, next to the change union, for the same reason {@link DriftScope}
92
+ * does: a hand-maintained set of type names in the consumer gives zero
93
+ * compile-time pressure, so a new variant would silently default to whatever the
94
+ * set omits. The deploy gate uses this to decide both what a data migration may
95
+ * excuse and which tables it offers to scaffold one for — a wrong default there
96
+ * sends the operator to a tool that cannot work.
97
+ */
98
+ type DriftRemediation = "backfill" | "code" | "none" | "rehome";
78
99
  /** One classified structural change between two snapshots. */
79
100
  interface DriftChange {
101
+ /** What fixes this change — see {@link DriftRemediation}. `"none"` for every `safe` change. */
102
+ remediation: DriftRemediation;
80
103
  /**
81
104
  * `"table"` means this table's own DDL moved (fields, indexes, shard mode) —
82
105
  * a relation whose foreign key lives on the OTHER table stays `"schema"`, so
83
106
  * the "changed" signal keeps meaning "this table's shape moved".
84
107
  */
85
108
  scope: DriftScope;
86
- /** `"breaking"` changes need a data migration; `"safe"` changes are additive. */
109
+ /** `"breaking"` changes need attention before deploy; `"safe"` changes are additive. */
87
110
  severity: "breaking" | "safe";
88
111
  /** Human-readable, actionable description (used in the gate message). */
89
112
  summary: string;
@@ -436,8 +459,10 @@ interface FunctionIR {
436
459
  /**
437
460
  * A `defineMigration({...})` declaration discovered in the user's lunora
438
461
  * sources. The emitted `LUNORA_MIGRATIONS` registry keys on {@link MigrationIR.id}; the
439
- * import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. {@link MigrationIR.table} is
440
- * informational (the runtime object carries the authoritative value).
462
+ * import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. The runtime object
463
+ * carries the authoritative {@link MigrationIR.table}, but the lifted value is
464
+ * load-bearing at build time: the schema-drift gate matches it against the
465
+ * tables with breaking drift, so a migration left at `""` covers nothing.
441
466
  */
442
467
  interface MigrationIR {
443
468
  /** Export binding name, used to reference the module member in generated imports. */
@@ -905,15 +930,18 @@ interface NondeterministicCallIR {
905
930
  line: number;
906
931
  }
907
932
  /**
908
- * One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
909
- * `r2sql_outside_action` advisor lint input. Structurally identical to the
910
- * advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
911
- * `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
912
- * Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
913
- * home for `ctx.r2sql` and is skipped.
933
+ * One `ctx.<property>` access lexically inside a `query`/`mutation` handler —
934
+ * the feeder shape behind every "action-only surface used outside an action"
935
+ * advisor lint (`hyperdrive_outside_action` for `ctx.sql`,
936
+ * `r2sql_outside_action` for `ctx.r2sql`). Structurally identical to the
937
+ * advisor's `AdvisorHyperdriveCall` / `AdvisorR2sqlCall` (same field set) so
938
+ * values pass straight through `lintSchema` without conversion, exactly as
939
+ * {@link NondeterministicCallIR} does. Only `query`/`mutation` handlers are
940
+ * recorded; `action(...)` is the only context where these surfaces are even
941
+ * typed, so it is the intended home and is skipped.
914
942
  */
915
- interface R2sqlCallIR {
916
- /** The accessed `ctx.r2sql` surface, e.g. `ctx.r2sql.query` / `ctx.r2sql.from`. */
943
+ interface ContextPropertyCallIR {
944
+ /** The accessed surface, e.g. `ctx.sql.query` / `ctx.r2sql.from` — the property, suffixed with the method when one is called on it. */
917
945
  callee: string;
918
946
  /** Export binding name of the function performing the access. */
919
947
  exportName: string;
@@ -921,7 +949,7 @@ interface R2sqlCallIR {
921
949
  file: string;
922
950
  /** Which procedure kind the access lives in — only `query`/`mutation` handlers are recorded. */
923
951
  kind: "mutation" | "query";
924
- /** 1-based line of the access, or `0` when unknown. */
952
+ /** 1-based line of the access. */
925
953
  line: number;
926
954
  }
927
955
  /**
@@ -1773,9 +1801,9 @@ interface FlagSecurityDefaultIR {
1773
1801
  * `__cdc_log`, so a subscribed query is never re-run when a flag flips and keeps
1774
1802
  * serving the branch it last picked; `useFlag` is the reactive path. Structurally
1775
1803
  * identical to the advisor's `AdvisorFlagRead` (same field set) so values pass
1776
- * straight through `lintSchema` without conversion, exactly as `R2sqlCallIR` does.
1804
+ * straight through `lintSchema` without conversion, exactly as `ContextPropertyCallIR` does.
1777
1805
  *
1778
- * Only `query` handlers are recorded — unlike `R2sqlCallIR` / `NondeterministicCallIR`
1806
+ * Only `query` handlers are recorded — unlike `ContextPropertyCallIR` / `NondeterministicCallIR`
1779
1807
  * there is no `kind` field, because `mutation`/`action` handlers run once and have
1780
1808
  * no subscription staleness to warn about, so the feeder drops them rather than
1781
1809
  * handing the lint rows it would discard.
@@ -2026,6 +2054,7 @@ interface LintSchemaOptions {
2026
2054
  geoIndexUsages?: ReadonlyArray<AdvisorGeoIndexUsage>;
2027
2055
  httpActionGuards?: ReadonlyArray<HttpActionGuardIR>;
2028
2056
  httpHeaderWrites?: ReadonlyArray<HttpHeaderWriteIR>;
2057
+ hyperdriveCalls?: ReadonlyArray<ContextPropertyCallIR>;
2029
2058
  identityClaimReads?: ReadonlyArray<IdentityClaimReadIR>;
2030
2059
  imageDeliveryUrlAccesses?: ReadonlyArray<ImageDeliveryUrlAccessIR>;
2031
2060
  inserts?: ReadonlyArray<InsertWriteIR>;
@@ -2044,7 +2073,7 @@ interface LintSchemaOptions {
2044
2073
  procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>;
2045
2074
  queries?: ReadonlyArray<QueryReadIR>;
2046
2075
  queues?: ReadonlyArray<QueueIR>;
2047
- r2sqlCalls?: ReadonlyArray<R2sqlCallIR>;
2076
+ r2sqlCalls?: ReadonlyArray<ContextPropertyCallIR>;
2048
2077
  ratelimitKeySelectors?: ReadonlyArray<RatelimitKeySelectorIR>;
2049
2078
  rawRowReturns?: ReadonlyArray<RawRowReturnIR>;
2050
2079
  relationLoads?: ReadonlyArray<RelationLoadIR>;
@@ -2306,12 +2335,13 @@ declare const resolveCodegenTarget: (projectRoot: string, explicit?: string) =>
2306
2335
  * `@lunora/config`'s driver registry (`deployTargetIds`) used to assert
2307
2336
  * equality against this — "two id spaces for one concept" — on the theory that
2308
2337
  * a target with a matrix but no driver "gates a surface nothing can deploy."
2309
- * Plan 234 found that reasoning incomplete by registering `node` here: a
2310
- * codegen-gateable target and a deployable target are genuinely different
2311
- * questions, and a spike/dev-only host answers the first "yes" and the second
2312
- * "not yet" without that being a bug in either registry. See
2313
- * `plans/234-node-host-findings.md` for the finding and `@lunora/config`'s
2314
- * `project-config.test.ts` for where the now-relaxed invariant lives.
2338
+ * Both registries list `cloudflare` and `node` today, so they happen to agree;
2339
+ * the assertion stays relaxed because agreement is a coincidence of timing, not
2340
+ * an invariant. "Codegen can gate capabilities for this target" and "the CLI can
2341
+ * deploy to it" are different questions, and a new host answers the first the
2342
+ * moment its capability matrix lands — before its deploy driver exists. See
2343
+ * `@lunora/config`'s `project-config.test.ts` for where that relaxed invariant
2344
+ * lives.
2315
2345
  * @returns the registered matrix ids, sorted.
2316
2346
  */
2317
2347
  declare const platformMatrixIds: () => ReadonlyArray<string>;
@@ -2541,6 +2571,13 @@ interface CodegenResult {
2541
2571
  /** WorkflowEntrypoint classes (`_generated/workflows.ts`); `""` (and not written) when no workflows are declared. */
2542
2572
  workflows: string;
2543
2573
  };
2574
+ /**
2575
+ * Data migrations discovered from `defineMigration` exports under `lunora/`,
2576
+ * each with the table it iterates. The drift gate matches a NEW id against
2577
+ * its table so a backfill only excuses breaking drift on the table it
2578
+ * actually visits. Empty when the project declares none.
2579
+ */
2580
+ migrations: ReadonlyArray<MigrationIR>;
2544
2581
  outputDirectory: string;
2545
2582
  /**
2546
2583
  * Portability diagnostics for the requested {@link CodegenOptions.target}:
@@ -2681,6 +2718,17 @@ declare const discoverFunctions: (project: Project, lunoraDirectory: string) =>
2681
2718
  * These are the headline OpenAPI target: each becomes a real `paths` entry.
2682
2719
  */
2683
2720
  declare const discoverHttpRoutes: (project: Project, lunoraDirectory: string) => HttpRouteIR[];
2721
+ /**
2722
+ * Discover Hyperdrive `ctx.sql` accesses inside exported `query(...)` /
2723
+ * `mutation(...)` handlers — the `hyperdrive_outside_action` lint input.
2724
+ *
2725
+ * The lint shipped with no feeder at all: it returns `[]` unless
2726
+ * `context.hyperdriveCalls` is set, and nothing set it, so the one guardrail
2727
+ * against non-deterministic external SQL in a reactive handler never fired.
2728
+ * `ctx.sql` is typed on `ActionCtx` only, so `action(...)` bodies are skipped by
2729
+ * the shared walker — an access there is correct usage, not a finding.
2730
+ */
2731
+ declare const discoverHyperdriveCalls: (project: Project, lunoraDirectory: string) => ContextPropertyCallIR[];
2684
2732
  /**
2685
2733
  * Discover `ctx.db.insert("table", …)` writes under the lunora source directory
2686
2734
  * and attribute each to the exported function (and file) performing it. Calls
@@ -2786,18 +2834,11 @@ declare const QUEUES_FILENAME = "queues.ts";
2786
2834
  */
2787
2835
  declare const discoverQueues: (project: Project, lunoraDirectory: string) => QueueIR[];
2788
2836
  /**
2789
- * Discover `ctx.r2sql` accesses lexically inside the handler body of every
2790
- * exported `query(...)` / `mutation(...)` registration under the lunora source
2791
- * directory — the `r2sql_outside_action` lint input. `action(...)` (and
2792
- * `stream(...)`) registrations are intentionally skipped: R2 SQL is the
2793
- * external, non-reactive surface that belongs in actions.
2794
- *
2795
- * Traversal is scoped to the handler node (not the whole declaration), mirroring
2796
- * `discoverNondeterministicCalls` — so a `ctx.r2sql` touch in a sibling helper
2797
- * outside the handler is not attributed to the query/mutation. One
2798
- * {@link R2sqlCallIR} is produced per access site.
2837
+ * Discover `ctx.r2sql` accesses inside exported `query(...)` / `mutation(...)`
2838
+ * handlers — the `r2sql_outside_action` lint input. `action(...)` is the
2839
+ * intended home for R2 SQL and is skipped by the shared walker.
2799
2840
  */
2800
- declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => R2sqlCallIR[];
2841
+ declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => ContextPropertyCallIR[];
2801
2842
  declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string) => RlsProcedureIR[];
2802
2843
  /**
2803
2844
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
@@ -3160,8 +3201,19 @@ interface EmitAppOptions {
3160
3201
  hasHyperdriveGlobal: boolean;
3161
3202
  /** App uses `@lunora/bindings/images` / `ctx.images` → emit `.images()`. */
3162
3203
  hasImages: boolean;
3163
- /** App uses `@lunora/bindings/kv` / `ctx.kv` → emit `.kv()`. */
3204
+ /** App uses `@lunora/bindings/kv` / `ctx.kv` → emit `.kv()`. Usage-only, because the method's parameter type reads `ShardConfig["kv"]`, and that config field is emitted on the same usage signal. */
3164
3205
  hasKv: boolean;
3206
+ /**
3207
+ * Wire the studio's zero-config KV introspector. Gated on `studioFeatures.kv`
3208
+ * (usage OR a declared `@lunora/bindings` dependency), NOT on {@link EmitAppOptions.hasKv},
3209
+ * so a visible KV tab always has a working backend — never the reverse.
3210
+ *
3211
+ * Kept separate from `hasKv` deliberately: the two were accidentally equal
3212
+ * while the dependency arm in `discover/studio-features.ts` matched a subpath
3213
+ * and could never fire. Fixing that arm made them diverge, and the shared flag
3214
+ * emitted a `.kv()` builder whose `ShardConfig["kv"]` type did not exist.
3215
+ */
3216
+ hasKvIntrospector: boolean;
3165
3217
  /** App declares `lunora/notify.ts` (`@lunora/notify`) → wire `options.notifySubscriptionStore` so the studio Notifications page can read registered devices. */
3166
3218
  hasNotify: boolean;
3167
3219
  /** App uses `@lunora/payment` / `ctx.payments` → emit `.payment()`. */
@@ -3345,11 +3397,15 @@ declare class SchemaSnapshotParseError extends LunoraError {
3345
3397
  declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
3346
3398
  /** The decision the pre-deploy gate returns. */
3347
3399
  interface SchemaDriftDecision {
3348
- /** True when the deploy must be blocked (breaking drift with no new migration, and no override). */
3400
+ /** True when the deploy must be blocked (breaking drift no new migration covers, and no override). */
3349
3401
  blocked: boolean;
3350
3402
  /** Every classified change (both severities), for reporting. */
3351
3403
  changes: ReadonlyArray<DriftChange>;
3352
- /** Migration ids declared now but absent from the baseline — proof a migration was added. */
3404
+ /**
3405
+ * Migration ids declared now but absent from the baseline. Reported for
3406
+ * context; the gate acts on which of them cover an affected TABLE, not on how
3407
+ * many there are.
3408
+ */
3353
3409
  newMigrationIds: ReadonlyArray<string>;
3354
3410
  /**
3355
3411
  * A multi-line, actionable explanation. Always present; empty string when
@@ -3361,9 +3417,22 @@ interface SchemaDriftDecision {
3361
3417
  * Decide whether breaking schema drift should block a deploy.
3362
3418
  *
3363
3419
  * Blocks only when the baseline exists (a first-ever capture is never blocking),
3364
- * there is at least one `breaking` change, no NEW migration id was added since
3365
- * the baseline, and the `allowDrift` override is not set. Safe-only drift (or
3366
- * breaking drift accompanied by a new migration id) passes.
3420
+ * there is at least one `breaking` change, no new migration COVERS it, and the
3421
+ * `allowDrift` override is not set. Safe-only drift passes.
3422
+ *
3423
+ * "Covers" is per-table, not per-run: a new migration excuses breaking drift on
3424
+ * the table it iterates, and nothing else. Counting new ids alone let a backfill
3425
+ * on `messages` unblock a required field added to `users` — the gate reported
3426
+ * "accompanied by a migration" for a change that migration would never visit.
3427
+ * The shard-mode diff cites this block to justify the studio not shipping a
3428
+ * stranded-rows detector (see `shared/schema-snapshot.ts`), and that claim only
3429
+ * holds if an unrelated migration cannot wave it through.
3430
+ *
3431
+ * Only a `"backfill"` change is coverable at all. A `"rehome"` change moves rows
3432
+ * to another Durable Object or region and a `"code"` change breaks a call site;
3433
+ * rewriting rows fixes neither, so a migration must not excuse them however well
3434
+ * its table matches. Those are cleared by fixing the code or accepting the new
3435
+ * shape (`--allow-schema-drift` / `--update-schema-baseline`).
3367
3436
  */
3368
3437
  declare const evaluateSchemaDrift: (options: {
3369
3438
  allowDrift?: boolean;
@@ -3371,6 +3440,8 @@ declare const evaluateSchemaDrift: (options: {
3371
3440
  /** The command printing the remediation, so it names only flags that command accepts. */
3372
3441
  command?: string;
3373
3442
  current: SchemaSnapshot;
3443
+ /** This run's declared migrations, so a new one is matched to the table it iterates. */
3444
+ migrations: ReadonlyArray<Pick<MigrationIR, "id" | "table">>;
3374
3445
  }) => SchemaDriftDecision;
3375
3446
  /**
3376
3447
  * Convert a {@link SchemaIR} into a synthetic runtime {@link Schema} carrying just
@@ -3687,4 +3758,4 @@ declare const secretKindOf: (value: string) => string | undefined;
3687
3758
  /** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
3688
3759
  declare const redact: (value: string) => string;
3689
3760
  declare const VERSION = "0.0.0";
3690
- export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
3761
+ export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DLXXalg2.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as C}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-DglkHRlt.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-B60GWv_I.mjs";import{default as G}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as b}from"./packem_shared/index-CCDlo9L7.mjs";import{default as y}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-BKSzaCkq.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs";import{default as ae}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as me}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as fe}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as ce}from"./packem_shared/discoverSchema-CubSTjtY.mjs";import{SHAPES_FILENAME as Se,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-D3N7xcEk.mjs";import{default as xe}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as ue,discoverWorkflows as ve}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as ge,e as Oe,a as Re,b as Me,c as he,d as Ce,f as _e,g as Te,h as Ie,i as Le,j as Fe,k as De,l as Pe,m as Ue}from"./packem_shared/emit-s6mHBmXu.mjs";import{emitApp as He}from"./packem_shared/emitApp-D1qxNeh1.mjs";import{buildOpenApiDocument as ke,emitOpenApi as ye,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-DLEWgA5Y.mjs";import{OPENRPC_VERSION as Ke,buildOpenRpcDocument as Ve,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-B9ZC0SrC.mjs";import{DEFAULT_TARGET as qe,platformMatrixIds as Be,readProjectTarget as Je,resolveCodegenTarget as Ye}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Ze,createCodegenProject as $e,findTsconfig as er,refreshCodegenProject as rr,runCodegen as or}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-lbo63hy2.mjs";import{SchemaSnapshotParseError as sr,buildSchemaSnapshot as ar,evaluateSchemaDrift as ir,parseSchemaSnapshot as mr}from"./packem_shared/SchemaSnapshotParseError-CvPTjDrT.mjs";import{schemaFromIr as fr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as cr,validatorIrToJsonSchema as nr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as lr,SDK_TARGETS as Er,generateSdk as xr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as ur,secretKindOf as vr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as gr,findSolutionByMessage as Or}from"@lunora/errors";import{isTypedSchema as Mr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,qe as DEFAULT_TARGET,T as FLAGS_FILENAME,ge as GENERATED_HEADER,cr as LUNORA_ERROR_CODES,gr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ke as OPENRPC_VERSION,ee as QUEUES_FILENAME,Ze as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,lr as SDK_LANGUAGES,Er as SDK_TARGETS,Se as SHAPES_FILENAME,sr as SchemaSnapshotParseError,e as VERSION,ue as WORKFLOWS_FILENAME,ke as buildOpenApiDocument,Ve as buildOpenRpcDocument,ar as buildSchemaSnapshot,$e as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,me as discoverRlsMetadata,ae as discoverRlsProcedures,fe as discoverSandboxUsage,ce as discoverSchema,le as discoverShapes,xe as discoverStorageRulesMetadata,ve as discoverWorkflows,Oe as emitAgents,Re as emitApi,He as emitApp,Me as emitCollections,he as emitContainers,Ce as emitCrons,_e as emitDataModel,Te as emitDrizzleSchema,Ie as emitFunctions,ye as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,De as emitVectors,Pe as emitWorkflows,Ue as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ir as evaluateSchemaDrift,Or as findLunoraSolution,er as findTsconfig,m as formatAdvisories,xr as generateSdk,Mr as isTypedSchema,d as lintSchema,mr as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Je as readProjectTarget,ur as redact,rr as refreshCodegenProject,Ye as resolveCodegenTarget,or as runCodegen,fr as schemaFromIr,vr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,nr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as h}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-DglkHRlt.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-B60GWv_I.mjs";import{default as G}from"./packem_shared/discoverHyperdriveCalls-De_QiFIl.mjs";import{default as b}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as y}from"./packem_shared/index-CCDlo9L7.mjs";import{default as j}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as V,discoverMutators as z}from"./packem_shared/MUTATORS_FILENAME-BKSzaCkq.mjs";import{default as w}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as B,discoverNotifyCalls as J,discoverNotifyConfig as Y}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Z}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as ee}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as oe,discoverQueues as te}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as ae}from"./packem_shared/discoverR2sqlCalls-BdkZw-D2.mjs";import{default as me}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as fe}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as ce}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as le}from"./packem_shared/discoverSchema-CubSTjtY.mjs";import{SHAPES_FILENAME as xe,discoverShapes as Ee}from"./packem_shared/SHAPES_FILENAME-D3N7xcEk.mjs";import{default as ue}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as Ne,discoverWorkflows as ge}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as Re,e as Ce,a as Me,b as he,c as _e,d as Te,f as Ie,g as Le,h as Fe,i as De,j as Pe,k as Ue,l as Ge,m as He}from"./packem_shared/emit-Bo3kao_A.mjs";import{emitApp as ke}from"./packem_shared/emitApp-CPXPVz9b.mjs";import{buildOpenApiDocument as We,emitOpenApi as je,emitOpenApiModule as Ke}from"./packem_shared/buildOpenApiDocument-CU1yw_t3.mjs";import{OPENRPC_VERSION as ze,buildOpenRpcDocument as Qe,emitOpenRpc as we,emitOpenRpcModule as qe}from"./packem_shared/OPENRPC_VERSION-CJwwFY8T.mjs";import{DEFAULT_TARGET as Je,platformMatrixIds as Ye,readProjectTarget as Xe,resolveCodegenTarget as Ze}from"./packem_shared/DEFAULT_TARGET-CwB3hjFH.mjs";import{SCHEMA_SNAPSHOT_FILENAME as er,createCodegenProject as rr,findTsconfig as or,refreshCodegenProject as tr,runCodegen as sr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BtWckBME.mjs";import{SchemaSnapshotParseError as ir,buildSchemaSnapshot as mr,evaluateSchemaDrift as dr,parseSchemaSnapshot as fr}from"./packem_shared/SchemaSnapshotParseError-qXCOA7dD.mjs";import{schemaFromIr as cr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as lr,validatorIrToJsonSchema as Sr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Er,SDK_TARGETS as Ar,generateSdk as ur}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Nr,secretKindOf as gr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Rr,findSolutionByMessage as Cr}from"@lunora/errors";import{isTypedSchema as hr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Je as DEFAULT_TARGET,T as FLAGS_FILENAME,Re as GENERATED_HEADER,lr as LUNORA_ERROR_CODES,Rr as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,B as NOTIFY_FILENAME,ze as OPENRPC_VERSION,oe as QUEUES_FILENAME,er as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Er as SDK_LANGUAGES,Ar as SDK_TARGETS,xe as SHAPES_FILENAME,ir as SchemaSnapshotParseError,e as VERSION,Ne as WORKFLOWS_FILENAME,We as buildOpenApiDocument,Qe as buildOpenRpcDocument,mr as buildSchemaSnapshot,rr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverHyperdriveCalls,b as discoverInserts,y as discoverMaskProcedures,j as discoverMigrations,z as discoverMutators,w as discoverNondeterministicCalls,J as discoverNotifyCalls,Y as discoverNotifyConfig,ee as discoverQueries,te as discoverQueues,ae as discoverR2sqlCalls,fe as discoverRlsMetadata,me as discoverRlsProcedures,ce as discoverSandboxUsage,le as discoverSchema,Ee as discoverShapes,ue as discoverStorageRulesMetadata,ge as discoverWorkflows,Ce as emitAgents,Me as emitApi,ke as emitApp,he as emitCollections,_e as emitContainers,Te as emitCrons,Ie as emitDataModel,Le as emitDrizzleSchema,Fe as emitFunctions,je as emitOpenApi,Ke as emitOpenApiModule,we as emitOpenRpc,qe as emitOpenRpcModule,De as emitServer,Pe as emitShard,Ue as emitVectors,Ge as emitWorkflows,He as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,dr as evaluateSchemaDrift,Cr as findLunoraSolution,or as findTsconfig,m as formatAdvisories,ur as generateSdk,hr as isTypedSchema,d as lintSchema,fr as parseSchemaSnapshot,Ye as platformMatrixIds,Z as readPackageDependencies,Xe as readProjectTarget,Nr as redact,tr as refreshCodegenProject,Ze as resolveCodegenTarget,sr as runCodegen,cr as schemaFromIr,gr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Sr as validatorIrToJsonSchema};
@@ -0,0 +1 @@
1
+ import{existsSync as d,readFileSync as p}from"node:fs";import{join as m}from"node:path";import{NODE_CAPABILITIES as f,CLOUDFLARE_CAPABILITIES as h}from"@lunora/platform";import{parse as g}from"jsonc-parser";const v="cloudflare",y="lunora.json",b=a=>{const e=m(a,y);if(!d(e))return;let r;try{r=p(e,"utf8")}catch{return}const s=[],n=g(r,s,{allowTrailingComma:!0});if(s.length>0||n===null||typeof n!="object")return;const{target:o}=n;return typeof o=="string"&&o.length>0?o:void 0},E=(a,e)=>e??b(a)??v,i={cloudflare:h,node:f},L=()=>Object.keys(i).toSorted((a,e)=>a.localeCompare(e)),_={access:null,ai:"ai",analytics:"analytics",browser:"browser",container:"containers",flags:null,hyperdrive:"hyperdrive",images:"images",kv:"keyValueStore",mail:"mail",notify:null,payments:null,pipelines:"pipelines",r2sql:null,scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows",x402:null},T=["crossShardFanout","durableStreams","globalTables","queues","secrets"],c={crossShardFanout:"cross-shard fan-out queries (a `.shardBy(...)` schema)",durableStreams:"durable streams (`.stream(handler, { durable: true })`)",globalTables:"global tables (`.global()`)",queues:"queues (`defineQueue`)",secrets:"the secrets store (`ctx.secrets`)"},$=(a,e,r,s={})=>{const n={...a},o=[];for(const[t,l]of Object.entries(_)){if(l===null||!a[t])continue;const u=e.features[l]?.level;u==="unsupported"?(n[t]=!1,o.push({feature:t,level:"error",message:`${e.name} does not support "${t}" (ctx.${t}). Its surface was omitted from the generated types.`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${t} usage, or deploy to a target whose capability matrix marks "${l}" as native or emulated.`,target:r})):u===void 0&&(n[t]=!1,o.push({feature:t,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${t}" (ctx.${t}). Treated as unsupported and its surface was omitted from the generated types.`,name:"platform_undeclared_feature",remediation:`Rate "${l}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than shipping a surface the host may not provide.`,target:r}))}for(const t of T){if(s[t]!==!0)continue;const l=e.features[t]?.level;l==="unsupported"?o.push({level:"error",message:`${e.name} does not support ${c[t]}, which this app declares.`,name:"platform_unsupported_feature",remediation:`Remove the declaration, or deploy to a target whose capability matrix marks "${t}" as native or emulated.`,target:r}):l===void 0&&o.push({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${c[t]}, which this app declares. Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${t}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than letting the app deploy onto a primitive the host may not provide.`,target:r})}return{diagnostics:o,usage:n}},k=(a,e,r={})=>{const s=i[e];return s===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(i).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],usage:{...a}}:$(a,s,e,r)};export{_ as CAPABILITY_TO_FEATURE,v as DEFAULT_TARGET,y as PROJECT_CONFIG_FILE,$ as gateAgainstMatrix,k as gatePlatformFeatures,L as platformMatrixIds,b as readProjectTarget,E as resolveCodegenTarget};
@@ -1 +1 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-DLXXalg2.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-s6mHBmXu.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
1
+ import"./SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-Bo3kao_A.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};