@lunora/codegen 1.0.0-alpha.5 → 1.0.0-alpha.50
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/LICENSE.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +1950 -734
- package/dist/index.d.ts +1950 -734
- package/dist/index.mjs +32 -24
- package/dist/packem_shared/AGENTS_FILENAME-Cxx7wiSs.mjs +158 -0
- package/dist/packem_shared/{CONTAINERS_FILENAME-0K-pjNb8.mjs → CONTAINERS_FILENAME-DjpXMqhp.mjs} +1 -1
- package/dist/packem_shared/{CodegenDiagnosticError-54jWDxA9.mjs → CodegenDiagnosticError-DyQ5FwkM.mjs} +7 -5
- package/dist/packem_shared/FLAGS_FILENAME-Dg4mKUuz.mjs +139 -0
- package/dist/packem_shared/GENERATED_HEADER-C5paWNYO.mjs +4 -0
- package/dist/packem_shared/{LUNORA_ERROR_CODES-CySpQPD3.mjs → LUNORA_ERROR_CODES-DvTLozCu.mjs} +8 -1
- package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +81 -0
- package/dist/packem_shared/{OPENRPC_VERSION-C7zKVeKi.mjs → OPENRPC_VERSION-7A2weq2u.mjs} +2 -2
- package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +145 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-G5dkcxPR.mjs +3502 -0
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs → SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs} +18 -2
- package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +94 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-Dtuzvluc.mjs +158 -0
- package/dist/packem_shared/{buildOpenApiDocument-Cns1EkCQ.mjs → buildOpenApiDocument-B7mEdzA2.mjs} +2 -2
- package/dist/packem_shared/{discoverAuthApiCalls-C35R6z0T.mjs → discoverAuthApiCalls-Dx3K42rk.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-BL6iGuJ3.mjs → discoverCrons-DvqkEWdx.mjs} +68 -36
- package/dist/packem_shared/{discoverFunctions-DEgAcRuD.mjs → discoverFunctions-BJ-qR7Rg.mjs} +72 -14
- package/dist/packem_shared/{discoverHttpRoutes-C978pBiG.mjs → discoverHttpRoutes-daCzuTe8.mjs} +10 -2
- package/dist/packem_shared/{discoverInserts-CRQdXvHO.mjs → discoverInserts-DI4q5NxE.mjs} +24 -2
- package/dist/packem_shared/{discoverMaskProcedures-B64zA740.mjs → discoverMaskProcedures-BcTOEKNU.mjs} +58 -2
- package/dist/packem_shared/{discoverMigrations-Doj_-BAA.mjs → discoverMigrations-VNUFvCwr.mjs} +10 -4
- package/dist/packem_shared/{discoverNondeterministicCalls-4KiPQxQU.mjs → discoverNondeterministicCalls-S0N2xLCq.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-BkIi0dBD.mjs → discoverQueries-CJnnnLpd.mjs} +1 -1
- package/dist/packem_shared/{discoverR2sqlCalls-BpDqvcUn.mjs → discoverR2sqlCalls-pnpicWfz.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-DpRB1HMe.mjs → discoverRlsMetadata-DppniPUH.mjs} +1 -1
- package/dist/packem_shared/discoverSandboxUsage-BUM2r90k.mjs +38 -0
- package/dist/packem_shared/{discoverSchema-DB_QrIQe.mjs → discoverSchema-BaSAvooG.mjs} +326 -14
- package/dist/packem_shared/{discoverStorageRulesMetadata-DAqJUxUv.mjs → discoverStorageRulesMetadata-CnHl2rXD.mjs} +1 -1
- package/dist/packem_shared/{GENERATED_HEADER-DF1hQcix.mjs → emit-ClTbCLy4.mjs} +1458 -154
- package/dist/packem_shared/{emitApp-Ci_hcJNO.mjs → emitApp-CzzrjVqH.mjs} +129 -31
- package/dist/packem_shared/formatAdvisories-BmF7Mplc.mjs +115 -0
- package/dist/packem_shared/{parse-validator-tuQtHrsr.mjs → parse-validator-BSJo1HGP.mjs} +18 -6
- package/dist/packem_shared/redact-oTmsol5A.mjs +33 -0
- package/package.json +10 -7
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BqOtU2lC.mjs +0 -922
- package/dist/packem_shared/WORKFLOWS_FILENAME-DRDQdhfq.mjs +0 -84
- package/dist/packem_shared/formatAdvisories-8NIv1k0I.mjs +0 -69
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Finding } from '@lunora/advisor';
|
|
2
2
|
export type { Finding } from '@lunora/advisor';
|
|
3
|
+
import { LunoraError } from '@lunora/errors';
|
|
4
|
+
export { MESSAGE_SOLUTIONS as LUNORA_SOLUTION_RULES, type Solution as LunoraSolution, type SolutionRule as LunoraSolutionRule, findSolutionByMessage as findLunoraSolution } from '@lunora/errors';
|
|
3
5
|
import { Node, Project } from 'ts-morph';
|
|
4
6
|
import { StudioFeaturesResult } from '@lunora/do';
|
|
5
7
|
import { Schema } from '@lunora/server';
|
|
6
8
|
import { JsonSchema } from '@lunora/values';
|
|
7
9
|
/**
|
|
8
|
-
* AST-observable subset of a column's modifier chain (`.unique()`, `.default()`,
|
|
9
|
-
* …). Function-valued modifiers (`.$defaultFn`/`.$onUpdateFn`) can't be
|
|
10
|
-
* serialized, so only their *presence* is recorded.
|
|
11
|
-
*/
|
|
10
|
+
* AST-observable subset of a column's modifier chain (`.unique()`, `.default()`,
|
|
11
|
+
* …). Function-valued modifiers (`.$defaultFn`/`.$onUpdateFn`) can't be
|
|
12
|
+
* serialized, so only their *presence* is recorded.
|
|
13
|
+
*/
|
|
12
14
|
interface ColumnMetaIR {
|
|
13
15
|
/** `.default(...)` or `.$defaultFn(...)` present — field is optional on insert. */
|
|
14
16
|
hasDefault?: boolean;
|
|
@@ -25,6 +27,15 @@ interface ValidatorIR {
|
|
|
25
27
|
bucket?: string;
|
|
26
28
|
/** Column modifiers (`.unique()`, `.default()`, `.nullable()`, …) when present. */
|
|
27
29
|
column?: ColumnMetaIR;
|
|
30
|
+
/**
|
|
31
|
+
* `true` when this validator carries a `.check(...)` refinement. The predicate
|
|
32
|
+
* is a runtime closure the AST→IR step can't represent, so the node keeps its
|
|
33
|
+
* base `kind` but records the refinement's presence here. The AOT args-validator
|
|
34
|
+
* compiler declines any node with this flag (compiling it would silently skip
|
|
35
|
+
* the predicate). `.meta(...)` is pure metadata with no parse effect and does
|
|
36
|
+
* NOT set this.
|
|
37
|
+
*/
|
|
38
|
+
hasRefinement?: boolean;
|
|
28
39
|
/** For `v.optional(inner)` / `v.array(inner)`. */
|
|
29
40
|
inner?: ValidatorIR;
|
|
30
41
|
/** For `v.record(key, value)`. */
|
|
@@ -67,19 +78,19 @@ interface VectorIndexIR {
|
|
|
67
78
|
table: string;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
|
-
* One ordering key on a rank index's `sortBy`: the column and direction.
|
|
71
|
-
* Mirrors the runtime `RankSortKey` (defaults `direction` to `"asc"`).
|
|
72
|
-
*/
|
|
81
|
+
* One ordering key on a rank index's `sortBy`: the column and direction.
|
|
82
|
+
* Mirrors the runtime `RankSortKey` (defaults `direction` to `"asc"`).
|
|
83
|
+
*/
|
|
73
84
|
interface RankSortKeyIR {
|
|
74
85
|
direction: "asc" | "desc";
|
|
75
86
|
field: string;
|
|
76
87
|
}
|
|
77
88
|
/**
|
|
78
|
-
* A `.rankIndex(name, { sortBy, partitionBy?, where? })` declaration. The owning
|
|
79
|
-
* table is always the table the index is declared on, so — unlike a vector index
|
|
80
|
-
* — there is no separate `on`/`table` reference to carry: it rides along on its
|
|
81
|
-
* {@link TableIR}. Only the fields needed for type emission are captured.
|
|
82
|
-
*/
|
|
89
|
+
* A `.rankIndex(name, { sortBy, partitionBy?, where? })` declaration. The owning
|
|
90
|
+
* table is always the table the index is declared on, so — unlike a vector index
|
|
91
|
+
* — there is no separate `on`/`table` reference to carry: it rides along on its
|
|
92
|
+
* {@link TableIR}. Only the fields needed for type emission are captured.
|
|
93
|
+
*/
|
|
83
94
|
interface RankIndexIR {
|
|
84
95
|
name: string;
|
|
85
96
|
/** Columns scoping each ranking; omitted ⇒ one global rank over the table. */
|
|
@@ -100,21 +111,67 @@ interface RelationIR {
|
|
|
100
111
|
/** Target table name. */
|
|
101
112
|
table: string;
|
|
102
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Statically-discovered `.source(...)` config (plan 077). Only the bits the
|
|
116
|
+
* advisor lints + DO wiring need are captured; `map`/`tenantBy` are functions and
|
|
117
|
+
* cannot be serialized, so their presence is recorded as `hasTenantBy` rather than
|
|
118
|
+
* the function itself.
|
|
119
|
+
*/
|
|
120
|
+
interface ExternalSourceIR {
|
|
121
|
+
/** The wrangler Hyperdrive binding name. */
|
|
122
|
+
binding: string;
|
|
123
|
+
/** Whether a `columns` projection allow-list was given. */
|
|
124
|
+
columns?: ReadonlyArray<string>;
|
|
125
|
+
/** `true` when a `reconcileEveryMs` was given — one of the two incremental delete-visibility paths the `external_source_incremental_no_delete_path` lint checks. */
|
|
126
|
+
hasReconcile?: boolean;
|
|
127
|
+
/** `true` when a `softDeleteColumn` was given — the other incremental delete-visibility path. */
|
|
128
|
+
hasSoftDelete?: boolean;
|
|
129
|
+
/** `true` when a `tenantBy` mapper was given — the tenant-isolation boundary the `external_source_unscoped` lint checks. */
|
|
130
|
+
hasTenantBy: boolean;
|
|
131
|
+
/** The `idColumn` literal, when given (defaults to `"id"` at runtime). */
|
|
132
|
+
idColumn?: string;
|
|
133
|
+
/** Delete-detection mode literal, when given (`"full-pull"` today). */
|
|
134
|
+
mode?: string;
|
|
135
|
+
/** The membership query literal, when statically knowable. */
|
|
136
|
+
query?: string;
|
|
137
|
+
/**
|
|
138
|
+
* `true` when `.source(...)` was present but its argument was **not** a static
|
|
139
|
+
* object literal (e.g. `.source(buildConfig())`), so none of the fields above
|
|
140
|
+
* could be read. The source still exists — this flag lets `hasSourcedTables`
|
|
141
|
+
* (codegen) and the `external_source_*` lints treat it as a source that can't be
|
|
142
|
+
* verified, instead of mistaking it for no `.source()` at all.
|
|
143
|
+
*/
|
|
144
|
+
unanalyzable?: boolean;
|
|
145
|
+
}
|
|
103
146
|
interface TableIR {
|
|
104
147
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
148
|
+
* `true` when the table chain carried `.externallyManaged()` — its rows are
|
|
149
|
+
* written outside Lunora's discoverable insert path (adapter/migration/
|
|
150
|
+
* middleware), so advisor insert-path lints skip it. Optional: hand-built
|
|
151
|
+
* IR and the runtime `fromServerSchema` path default it to `false`.
|
|
152
|
+
*/
|
|
110
153
|
externallyManaged?: boolean;
|
|
111
154
|
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
155
|
+
* Set when the chain carried `.source(...)` — the table is materialized from an
|
|
156
|
+
* external Hyperdrive-backed database by a system poll loop (plan 077). Carries
|
|
157
|
+
* the statically-knowable bits the advisor lints read; the functions (`map`,
|
|
158
|
+
* `tenantBy`) are not serialized, only their presence (`hasTenantBy`).
|
|
159
|
+
*/
|
|
160
|
+
externalSource?: ExternalSourceIR;
|
|
161
|
+
/**
|
|
162
|
+
* Storage backend for a `.global()` table: `"d1"` (default) or
|
|
163
|
+
* `"hyperdrive"` (a Postgres/MySQL database via Cloudflare Hyperdrive). Only
|
|
164
|
+
* meaningful when `shardMode === "global"`; absent for sharded/root tables.
|
|
165
|
+
*/
|
|
116
166
|
globalBackend?: "d1" | "hyperdrive";
|
|
117
167
|
indexes: ReadonlyArray<IndexIR>;
|
|
168
|
+
/**
|
|
169
|
+
* `true` when the table chain carried `.public()` — an explicit opt-OUT of
|
|
170
|
+
* the schema's `.rls("required")` enforcement for this one table. Optional:
|
|
171
|
+
* hand-built IR and tables that never called `.public()` default it to
|
|
172
|
+
* `false`.
|
|
173
|
+
*/
|
|
174
|
+
isPublic?: boolean;
|
|
118
175
|
name: string;
|
|
119
176
|
/** Rank indexes declared inline via `.rankIndex(name, …)`. */
|
|
120
177
|
rankIndexes: ReadonlyArray<RankIndexIR>;
|
|
@@ -126,10 +183,30 @@ interface TableIR {
|
|
|
126
183
|
field: string;
|
|
127
184
|
kind: "shardBy";
|
|
128
185
|
};
|
|
186
|
+
/** Set when the chain carried `.softDelete()` — the marker column's name (default `deletedAt`). The column is injected into `shape` so `Doc_*` carries it. */
|
|
187
|
+
softDelete?: {
|
|
188
|
+
field: string;
|
|
189
|
+
};
|
|
129
190
|
/** Vector indexes declared inline via `.vectorize()` (DSL Shape A). */
|
|
130
191
|
vectorIndexes: ReadonlyArray<VectorIndexIR>;
|
|
131
192
|
}
|
|
193
|
+
/** The Cloudflare DO data-residency jurisdictions the schema may declare. Canonical literal set for the codegen package. */
|
|
194
|
+
type JurisdictionIR = "eu" | "fedramp" | "us";
|
|
132
195
|
interface SchemaIR {
|
|
196
|
+
/**
|
|
197
|
+
* Cloudflare data-residency jurisdiction declared via
|
|
198
|
+
* `defineSchema(...).jurisdiction("…")`. Emitted into the generated worker's
|
|
199
|
+
* `createWorker({ jurisdiction })` (and `ctx.scheduler` / `ctx.containers`).
|
|
200
|
+
* Absent ⇒ un-pinned.
|
|
201
|
+
*/
|
|
202
|
+
jurisdiction?: JurisdictionIR;
|
|
203
|
+
/**
|
|
204
|
+
* Set when `defineSchema(...).rls("required")` was chained onto the schema —
|
|
205
|
+
* every table's `ctx.db` write path is denied without an RLS-covering
|
|
206
|
+
* procedure unless the table itself is `.public()` (see {@link TableIR.isPublic}).
|
|
207
|
+
* Absent when the schema never called `.rls("required")`.
|
|
208
|
+
*/
|
|
209
|
+
rlsMode?: "required";
|
|
133
210
|
tables: ReadonlyArray<TableIR>;
|
|
134
211
|
/** All vector indexes (inline Shape A hoisted + standalone Shape B), flattened. */
|
|
135
212
|
vectorIndexes: ReadonlyArray<VectorIndexIR>;
|
|
@@ -141,33 +218,33 @@ interface FunctionIR {
|
|
|
141
218
|
filePath: string;
|
|
142
219
|
kind: "action" | "mutation" | "query" | "stream";
|
|
143
220
|
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
221
|
+
* Set on connection-lifecycle hooks (`onConnect`/`onDisconnect`): the socket
|
|
222
|
+
* side the hook fires on. Such a function is also an internal mutation (so it
|
|
223
|
+
* lands in `LUNORA_FUNCTIONS` for path dispatch); emit additionally collects
|
|
224
|
+
* it into the `LUNORA_LIFECYCLE_HOOKS` manifest keyed by this side. Absent on
|
|
225
|
+
* ordinary functions.
|
|
226
|
+
*/
|
|
150
227
|
lifecycle?: "connect" | "disconnect";
|
|
151
228
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
229
|
+
* Serialized TS source for the handler's return type, with `Promise<T>`
|
|
230
|
+
* unwrapped so callers see `T` directly. Defaults to `"unknown"` when
|
|
231
|
+
* ts-morph cannot resolve the type (typically because the consuming
|
|
232
|
+
* project lacks a tsconfig that can reach `@lunora/server`).
|
|
233
|
+
*/
|
|
157
234
|
returnType: string;
|
|
158
235
|
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
236
|
+
* Call surface the function is exposed on. Absent (or `"public"`) means it
|
|
237
|
+
* lands in the generated `api`; `"internal"` routes it to the separate
|
|
238
|
+
* `internal` object and is rejected by the DO's external RPC path.
|
|
239
|
+
*/
|
|
163
240
|
visibility?: "internal" | "public";
|
|
164
241
|
}
|
|
165
242
|
/**
|
|
166
|
-
* A `defineMigration({...})` declaration discovered in the user's lunora
|
|
167
|
-
* sources. The emitted `LUNORA_MIGRATIONS` registry keys on {@link MigrationIR.id}; the
|
|
168
|
-
* import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. {@link MigrationIR.table} is
|
|
169
|
-
* informational (the runtime object carries the authoritative value).
|
|
170
|
-
*/
|
|
243
|
+
* A `defineMigration({...})` declaration discovered in the user's lunora
|
|
244
|
+
* sources. The emitted `LUNORA_MIGRATIONS` registry keys on {@link MigrationIR.id}; the
|
|
245
|
+
* import wiring needs {@link MigrationIR.exportName}/{@link MigrationIR.filePath}. {@link MigrationIR.table} is
|
|
246
|
+
* informational (the runtime object carries the authoritative value).
|
|
247
|
+
*/
|
|
171
248
|
interface MigrationIR {
|
|
172
249
|
/** Export binding name, used to reference the module member in generated imports. */
|
|
173
250
|
exportName: string;
|
|
@@ -179,12 +256,90 @@ interface MigrationIR {
|
|
|
179
256
|
table: string;
|
|
180
257
|
}
|
|
181
258
|
/**
|
|
182
|
-
* A
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
|
|
259
|
+
* A `defineShape({...})` declaration discovered in `lunora/shapes.ts`
|
|
260
|
+
* (local-first sync engine, Phase 7). The emitted `LUNORA_SHAPES` registry keys
|
|
261
|
+
* on {@link ShapeIR.exportName}; the generated DO's `resolveShape` override
|
|
262
|
+
* dispatches a `shape_subscribe` to the matching registered shape. Discovery is
|
|
263
|
+
* marker-driven (the `__lunoraShape` brand) — no field metadata is lifted here
|
|
264
|
+
* because the runtime object (`columns`/`compileWhere`) carries the authority.
|
|
265
|
+
*/
|
|
266
|
+
interface ShapeIR {
|
|
267
|
+
/** Export binding name — the shape's registry key and import member. */
|
|
268
|
+
exportName: string;
|
|
269
|
+
/** Path relative to `<projectRoot>/lunora/` without extension — always `"shapes"`. */
|
|
270
|
+
filePath: string;
|
|
271
|
+
/**
|
|
272
|
+
* The `table` string literal from the `defineShape({ table })` call, lifted
|
|
273
|
+
* only for static advisor lints (the runtime object stays authoritative).
|
|
274
|
+
* `undefined` when `table` is not a plain string literal — lints skip those.
|
|
275
|
+
*/
|
|
276
|
+
table?: string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The single `defineIdentity({...})` claim contract discovered in
|
|
280
|
+
* `lunora/identity.ts`. Discovery is **marker-driven** (the `__lunoraIdentity`
|
|
281
|
+
* brand, exactly like {@link ShapeIR}) — no claim metadata is lifted here
|
|
282
|
+
* because the emitted `_generated/server.ts` recovers the claim *type* from the
|
|
283
|
+
* declaration itself (`InferIdentity` over the contract's `typeof`), and the
|
|
284
|
+
* runtime object (`validate`/`onInvalid`) carries the authority at the boundary.
|
|
285
|
+
* Exactly one per app; absent ⇒ generated output is byte-identical to today.
|
|
286
|
+
*/
|
|
287
|
+
interface IdentityIR {
|
|
288
|
+
/** Export binding name — the namespace member `_generated/server.ts` reads via `typeof`. */
|
|
289
|
+
exportName: string;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The single `defineEnv({...})` contract discovered in `lunora/env.ts`. Like
|
|
293
|
+
* {@link IdentityIR}, only the export binding is lifted — the emitted
|
|
294
|
+
* `_generated/server.ts` recovers the validated shape from the declaration
|
|
295
|
+
* itself (`ReturnType` over the accessor's `typeof`), and the generated ShardDO
|
|
296
|
+
* applies the same accessor to the worker `env` at ctx-build time to populate
|
|
297
|
+
* `ctx.env`. Exactly one per app; absent ⇒ generated output is byte-identical.
|
|
298
|
+
*/
|
|
299
|
+
interface EnvIR {
|
|
300
|
+
/** Export binding name — the namespace member `_generated/server.ts` reads via `typeof`. */
|
|
301
|
+
exportName: string;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* A `defineMutator({...})` declaration discovered in `lunora/mutators.ts`
|
|
305
|
+
* (local-first sync engine, Phase 7). The emitted registry registers the
|
|
306
|
+
* authoritative `server` impl into the DO's `LUNORA_FUNCTIONS` table (so
|
|
307
|
+
* `handleRpc` transaction-wraps it) and records its path in
|
|
308
|
+
* `LUNORA_MUTATOR_PATHS` so the DO's `isCustomMutator` override routes the
|
|
309
|
+
* client-watermark push protocol. The client `client` impl is split into the
|
|
310
|
+
* browser bundle separately — only the path crosses to the server side.
|
|
311
|
+
*/
|
|
312
|
+
interface MutatorIR {
|
|
313
|
+
/** Export binding name — the mutator's registry key and import member. */
|
|
314
|
+
exportName: string;
|
|
315
|
+
/** Path relative to `<projectRoot>/lunora/` without extension — always `"mutators"`. */
|
|
316
|
+
filePath: string;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* A whole-row `ctx.db.replace(id, document)` write discovered inside a custom
|
|
320
|
+
* mutator's inline `server` impl (`lunora/mutators.ts`) — the input the
|
|
321
|
+
* `mutator_full_row_replace` advisor lint consumes. A `replace` overwrites the
|
|
322
|
+
* entire row, so a concurrent edit to a different column on a synced table is
|
|
323
|
+
* clobbered; `ctx.db.patch(id, { field })` merges at the column level instead.
|
|
324
|
+
* Structurally identical to `AdvisorMutatorWrite` so it passes straight through
|
|
325
|
+
* to the advisor without conversion, exactly as `InsertWriteIR` does for
|
|
326
|
+
* `AdvisorInsertWrite`.
|
|
327
|
+
*/
|
|
328
|
+
interface MutatorWriteIR {
|
|
329
|
+
/** The mutator export whose `server` impl performs the replace, e.g. `renameChannel`. */
|
|
330
|
+
exportName: string;
|
|
331
|
+
/** Openable source path the replace appears in — always `lunora/mutators.ts`. */
|
|
332
|
+
file: string;
|
|
333
|
+
/** 1-based line of the `replace(...)` call. */
|
|
334
|
+
line: number;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* A single cron job lifted from a `cronJobs()` builder in `lunora/crons.ts`.
|
|
338
|
+
* Mirrors `@lunora/scheduler`'s `CronJob`: {@link CronJobIR.cron} is the compiled
|
|
339
|
+
* standard cron expression, {@link CronJobIR.functionPath} is the target
|
|
340
|
+
* `__lunoraRef` (`namespace:fn`), and {@link CronJobIR.args} is the static
|
|
341
|
+
* argument object passed at registration.
|
|
342
|
+
*/
|
|
188
343
|
interface CronJobIR {
|
|
189
344
|
/** Static args object (source-text JSON), defaults to `{}`. */
|
|
190
345
|
args: Record<string, unknown>;
|
|
@@ -195,25 +350,25 @@ interface CronJobIR {
|
|
|
195
350
|
/** Unique, human-readable job name. */
|
|
196
351
|
name: string;
|
|
197
352
|
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
353
|
+
* Set when the job targets a durable workflow (a `lunora/workflows.ts`
|
|
354
|
+
* export) instead of a function: the workflow's `WORKFLOW_*` binding name
|
|
355
|
+
* plus its export name. On each fire the worker starts a new workflow
|
|
356
|
+
* INSTANCE (the {@link CronJobIR.args} become its `params`) rather than
|
|
357
|
+
* dispatching a one-shot function.
|
|
358
|
+
*/
|
|
204
359
|
workflow?: {
|
|
205
360
|
binding: string;
|
|
206
361
|
exportName: string;
|
|
207
362
|
};
|
|
208
363
|
}
|
|
209
364
|
/**
|
|
210
|
-
* A container lifted from a `defineContainer()` export in
|
|
211
|
-
* `lunora/containers.ts`. Carries everything the emitters and the config layer
|
|
212
|
-
* need to wire wrangler (`containers[]` + the Durable Object binding +
|
|
213
|
-
* migration class) and the generated `_generated/containers.ts` DO class.
|
|
214
|
-
* Names are derived via `@lunora/container`'s shared helpers so codegen and
|
|
215
|
-
* the config layer can never disagree.
|
|
216
|
-
*/
|
|
365
|
+
* A container lifted from a `defineContainer()` export in
|
|
366
|
+
* `lunora/containers.ts`. Carries everything the emitters and the config layer
|
|
367
|
+
* need to wire wrangler (`containers[]` + the Durable Object binding +
|
|
368
|
+
* migration class) and the generated `_generated/containers.ts` DO class.
|
|
369
|
+
* Names are derived via `@lunora/container`'s shared helpers so codegen and
|
|
370
|
+
* the config layer can never disagree.
|
|
371
|
+
*/
|
|
217
372
|
interface ContainerIR {
|
|
218
373
|
/** Durable Object binding name, e.g. `CONTAINER_TRANSCODER`. */
|
|
219
374
|
bindingName: string;
|
|
@@ -222,18 +377,18 @@ interface ContainerIR {
|
|
|
222
377
|
/** Generated DO class name, e.g. `TranscoderContainer`. */
|
|
223
378
|
className: string;
|
|
224
379
|
/**
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
380
|
+
* Whether the container may open outbound internet connections, when the
|
|
381
|
+
* value was a static literal. `undefined` means the field was omitted (the
|
|
382
|
+
* platform default is `true`) or wasn't a literal. Lifted for the advisor.
|
|
383
|
+
*/
|
|
229
384
|
enableInternet?: boolean;
|
|
230
385
|
/** The `lunora/containers.ts` export name, e.g. `transcoder`. */
|
|
231
386
|
exportName: string;
|
|
232
387
|
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
388
|
+
* Normalized image source: a local Dockerfile (`dockerfile`), a pre-built
|
|
389
|
+
* registry reference (`registry`), or a Railpack source directory (`build`)
|
|
390
|
+
* that the deploy step builds and pushes before wrangler runs.
|
|
391
|
+
*/
|
|
237
392
|
image: {
|
|
238
393
|
buildContext: string;
|
|
239
394
|
dockerfilePath: string;
|
|
@@ -261,20 +416,20 @@ interface ContainerIR {
|
|
|
261
416
|
stepPercentage?: number;
|
|
262
417
|
};
|
|
263
418
|
/**
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
419
|
+
* The static `sleepAfter` value, when it was a literal. `undefined` means
|
|
420
|
+
* omitted (platform default `"10m"`) or non-literal. Lifted for the advisor.
|
|
421
|
+
*/
|
|
267
422
|
sleepAfter?: number | string;
|
|
268
423
|
}
|
|
269
424
|
/**
|
|
270
|
-
* A workflow lifted from a `defineWorkflow()` export in `lunora/workflows.ts`.
|
|
271
|
-
* Carries what the emitters and the config layer need to wire the wrangler
|
|
272
|
-
* `workflows[]` entry and the generated `_generated/workflows.ts`
|
|
273
|
-
* `WorkflowEntrypoint` class. Unlike containers, workflows are NOT Durable
|
|
274
|
-
* Objects — wrangler gets only a `workflows[]` entry, never a `durable_objects`
|
|
275
|
-
* binding or a migration class. Names are derived via `@lunora/workflow`'s
|
|
276
|
-
* shared helpers so codegen and the config layer can never disagree.
|
|
277
|
-
*/
|
|
425
|
+
* A workflow lifted from a `defineWorkflow()` export in `lunora/workflows.ts`.
|
|
426
|
+
* Carries what the emitters and the config layer need to wire the wrangler
|
|
427
|
+
* `workflows[]` entry and the generated `_generated/workflows.ts`
|
|
428
|
+
* `WorkflowEntrypoint` class. Unlike containers, workflows are NOT Durable
|
|
429
|
+
* Objects — wrangler gets only a `workflows[]` entry, never a `durable_objects`
|
|
430
|
+
* binding or a migration class. Names are derived via `@lunora/workflow`'s
|
|
431
|
+
* shared helpers so codegen and the config layer can never disagree.
|
|
432
|
+
*/
|
|
278
433
|
interface WorkflowIR {
|
|
279
434
|
/** The Cloudflare `Workflow` binding name, e.g. `WORKFLOW_ORDER_PIPELINE`. */
|
|
280
435
|
bindingName: string;
|
|
@@ -283,21 +438,152 @@ interface WorkflowIR {
|
|
|
283
438
|
/** The `lunora/workflows.ts` export name, e.g. `orderPipeline`. */
|
|
284
439
|
exportName: string;
|
|
285
440
|
/**
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
441
|
+
* The stable wrangler `workflows[].name`. Defaults to the kebab-cased export
|
|
442
|
+
* name (`orderPipeline` → `order-pipeline`); a static `name:` literal in the
|
|
443
|
+
* definition overrides it.
|
|
444
|
+
*/
|
|
445
|
+
name: string;
|
|
446
|
+
/**
|
|
447
|
+
* Durable step labels lifted from the handler body — the first string-literal
|
|
448
|
+
* argument of every `ctx.step.do` / `.sleep` / `.sleepUntil` / `.waitForEvent`
|
|
449
|
+
* call. Feeds the duplicate-step-name lint, which flags a name used twice
|
|
450
|
+
* (Cloudflare memoizes by name, so the second call silently returns the
|
|
451
|
+
* first's cached result). Calls with a non-literal name are omitted (not
|
|
452
|
+
* statically comparable).
|
|
453
|
+
*/
|
|
454
|
+
steps: ReadonlyArray<WorkflowStepIR>;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* An agent lifted from a `defineAgent()` export in `lunora/agents.ts`. A
|
|
458
|
+
* `defineAgent` compiles its durable tool-loop onto a Cloudflare Workflow, so —
|
|
459
|
+
* like {@link WorkflowIR} — an agent is NOT a Durable Object: wrangler gets only
|
|
460
|
+
* a `workflows[]` entry, never a `durable_objects` binding or a migration class.
|
|
461
|
+
* Carries what the emitters and the config layer need to wire the generated
|
|
462
|
+
* agent `WorkflowEntrypoint` class (e.g. `SupportAgentWorkflow`), the typed
|
|
463
|
+
* per-agent `ctx.agents` producer, and the reconciled wrangler `workflows[]`
|
|
464
|
+
* entry. Names are derived via `@lunora/agent`'s shared helpers so codegen and
|
|
465
|
+
* the config layer can never disagree.
|
|
466
|
+
*/
|
|
467
|
+
interface AgentIR {
|
|
468
|
+
/** The Cloudflare `Workflow` binding name, e.g. `AGENT_SUPPORT`. */
|
|
469
|
+
bindingName: string;
|
|
470
|
+
/** Generated `WorkflowEntrypoint` class name, e.g. `SupportAgentWorkflow`. */
|
|
471
|
+
className: string;
|
|
472
|
+
/** The `lunora/agents.ts` export name, e.g. `support`. */
|
|
473
|
+
exportName: string;
|
|
474
|
+
/**
|
|
475
|
+
* The stable wrangler `workflows[].name`. Defaults to the kebab-cased export
|
|
476
|
+
* name (`support` → `agent-support`); a static `name:` literal in the
|
|
477
|
+
* definition overrides it.
|
|
478
|
+
*/
|
|
479
|
+
name: string;
|
|
480
|
+
/**
|
|
481
|
+
* Whether the definition declares an `onEmail` mapper on
|
|
482
|
+
* `defineAgent({ onEmail: … })`. When `true` the emitter wires this agent
|
|
483
|
+
* onto the worker's top-level `email()` handler (via `@lunora/agent/inbound`)
|
|
484
|
+
* so inbound mail starts a durable run. Detected by AST PRESENCE — the
|
|
485
|
+
* closure is never evaluated — and written to IR only when present, so
|
|
486
|
+
* email-free agents (and agent-free projects) stay byte-identical.
|
|
487
|
+
*/
|
|
488
|
+
onEmail?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Whether the definition opted into public run-starts via
|
|
491
|
+
* `defineAgent({ publicRun: true })` — emitted into the `ctx.agents` wiring
|
|
492
|
+
* spec so the public `agents:agentRun` mutation can gate on it fail-closed.
|
|
493
|
+
* Absent (falsy) means server-side starts only; the field is written to IR
|
|
494
|
+
* only when the literal is `true`, so agent-free and non-opted-in output is
|
|
495
|
+
* byte-identical.
|
|
496
|
+
*/
|
|
497
|
+
publicRun?: boolean;
|
|
498
|
+
/**
|
|
499
|
+
* Whether the definition opted into a real-time voice session via a `voice`
|
|
500
|
+
* block on `defineAgent({ voice: … })`. Unlike the durable loop (a Workflow),
|
|
501
|
+
* the voice path IS a Durable Object — so when this is `true` the emitter
|
|
502
|
+
* generates the `voiceClassName` `VoiceSessionDO` subclass and the
|
|
503
|
+
* `api.agents.{name}Voice` client reference, and the config layer reconciles
|
|
504
|
+
* a `durable_objects` binding (`voiceBindingName`) + `new_sqlite_classes`
|
|
505
|
+
* migration. Written to IR only when the literal is present, so voice-free
|
|
506
|
+
* agents (and agent-free projects) stay byte-identical.
|
|
507
|
+
*/
|
|
508
|
+
voice?: boolean;
|
|
509
|
+
/** The voice DO's Cloudflare `DurableObjectNamespace` binding name, e.g. `VOICE_SUPPORT`. Present only when `voice`. */
|
|
510
|
+
voiceBindingName?: string;
|
|
511
|
+
/** Generated `VoiceSessionDO` subclass name, e.g. `SupportVoiceDO`. Present only when `voice`. */
|
|
512
|
+
voiceClassName?: string;
|
|
513
|
+
}
|
|
514
|
+
/** One durable step call lifted from a workflow handler body (the use side of {@link WorkflowIR.steps}). */
|
|
515
|
+
interface WorkflowStepIR {
|
|
516
|
+
/** 1-based line of the durable step call. */
|
|
517
|
+
line: number;
|
|
518
|
+
/** The native step method invoked: `do` / `sleep` / `sleepUntil` / `waitForEvent`. */
|
|
519
|
+
method: string;
|
|
520
|
+
/** The step's static label (the first string-literal argument). */
|
|
521
|
+
name: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* A queue lifted from a `defineQueue()` export in `lunora/queues.ts`. Carries
|
|
525
|
+
* what the emitters and the config layer need to wire the typed `ctx.queues`
|
|
526
|
+
* producer, the generated worker `queue()` dispatch, and the wrangler
|
|
527
|
+
* `queues.producers[]` / `queues.consumers[]` entries. Like workflows, a queue
|
|
528
|
+
* is NOT a Durable Object — wrangler gets only `queues.*` entries. Names are
|
|
529
|
+
* derived via `@lunora/queue`'s shared helpers so codegen and the config layer
|
|
530
|
+
* can never disagree.
|
|
531
|
+
*/
|
|
532
|
+
interface QueueIR {
|
|
533
|
+
/** The Cloudflare `Queue` producer binding name, e.g. `QUEUE_EMAIL`. */
|
|
534
|
+
bindingName: string;
|
|
535
|
+
/** The `lunora/queues.ts` export name, e.g. `emailQueue`. */
|
|
536
|
+
exportName: string;
|
|
537
|
+
/** How the queue is consumed: `"push"` (a worker `queue()` handler) or `"pull"` (external HTTP). */
|
|
538
|
+
mode: "pull" | "push";
|
|
539
|
+
/**
|
|
540
|
+
* The stable wrangler queue name (`queues.producers[].queue`). Defaults to
|
|
541
|
+
* the kebab-cased export name (`emailQueue` → `email-queue`); a static
|
|
542
|
+
* `name:` literal in the definition overrides it.
|
|
543
|
+
*/
|
|
290
544
|
name: string;
|
|
545
|
+
/** Push-consumer batch/retry tuning, mirrored onto the wrangler `queues.consumers[]` entry. */
|
|
546
|
+
tuning: {
|
|
547
|
+
deadLetterQueue?: string;
|
|
548
|
+
maxBatchSize?: number;
|
|
549
|
+
maxBatchTimeout?: number;
|
|
550
|
+
maxRetries?: number;
|
|
551
|
+
retryDelay?: number;
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* The feature-flag provider declared by the default export of `lunora/flags.ts`
|
|
556
|
+
* (`defineFlags({ provider, … })`). Discovery is **metadata-only** — codegen
|
|
557
|
+
* imports the real module at runtime for the provider value; this IR exists so
|
|
558
|
+
* the config layer can reconcile/validate the wrangler `flagship` binding when
|
|
559
|
+
* the app uses Flagship in binding mode. A `custom` provider (any other
|
|
560
|
+
* OpenFeature factory) carries no binding to reconcile.
|
|
561
|
+
*/
|
|
562
|
+
interface FlagsIR {
|
|
563
|
+
/**
|
|
564
|
+
* The wrangler `flagship[].binding` name — set **only** for a flagship
|
|
565
|
+
* `provider` in binding mode (`flagshipProvider({ binding: "FLAGS" })`). The
|
|
566
|
+
* config layer hints/validates a matching `flagship` binding from this.
|
|
567
|
+
*/
|
|
568
|
+
bindingName?: string;
|
|
569
|
+
/**
|
|
570
|
+
* Flagship operating mode — `"binding"` (wrangler binding, needs a
|
|
571
|
+
* `flagship` entry) or `"http"` (no binding); `undefined` for a `custom`
|
|
572
|
+
* provider or when the mode can't be read statically.
|
|
573
|
+
*/
|
|
574
|
+
mode?: "binding" | "http";
|
|
575
|
+
/** `"flagship"` when the provider is `flagshipProvider(...)`, else `"custom"` (any other OpenFeature provider factory). */
|
|
576
|
+
provider: "custom" | "flagship";
|
|
291
577
|
}
|
|
292
578
|
/**
|
|
293
|
-
* A `ctx.workflows.get("name")…` call discovered in a function body — the
|
|
294
|
-
* use-site analog of {@link WorkflowIR} (which is the declaration side). Feeds
|
|
295
|
-
* the `workflow_unused` lint (a declared workflow with zero call sites) and the
|
|
296
|
-
* `workflow_unknown_target` lint (a `.get("x")` whose `x` isn't declared — a
|
|
297
|
-
* typo catcher). {@link WorkflowCallIR.workflow} is `""` when the `get(...)`
|
|
298
|
-
* argument is not a string literal (a dynamic name — which suppresses the
|
|
299
|
-
* unused-workflow heuristic rather than producing a false positive).
|
|
300
|
-
*/
|
|
579
|
+
* A `ctx.workflows.get("name")…` call discovered in a function body — the
|
|
580
|
+
* use-site analog of {@link WorkflowIR} (which is the declaration side). Feeds
|
|
581
|
+
* the `workflow_unused` lint (a declared workflow with zero call sites) and the
|
|
582
|
+
* `workflow_unknown_target` lint (a `.get("x")` whose `x` isn't declared — a
|
|
583
|
+
* typo catcher). {@link WorkflowCallIR.workflow} is `""` when the `get(...)`
|
|
584
|
+
* argument is not a string literal (a dynamic name — which suppresses the
|
|
585
|
+
* unused-workflow heuristic rather than producing a false positive).
|
|
586
|
+
*/
|
|
301
587
|
interface WorkflowCallIR {
|
|
302
588
|
/** Export binding name of the function performing the call, e.g. `create`. */
|
|
303
589
|
exportName: string;
|
|
@@ -309,11 +595,11 @@ interface WorkflowCallIR {
|
|
|
309
595
|
workflow: string;
|
|
310
596
|
}
|
|
311
597
|
/**
|
|
312
|
-
* A `ctx.db.query("table")…` read discovered in a function body, reduced to what
|
|
313
|
-
* the `filter_without_index` advisor lint needs: which table, whether the chain
|
|
314
|
-
* narrows with an index, and whether it filters. `table` is `""` when the
|
|
315
|
-
* `query(...)` argument is not a string literal (a dynamic table — not lintable).
|
|
316
|
-
*/
|
|
598
|
+
* A `ctx.db.query("table")…` read discovered in a function body, reduced to what
|
|
599
|
+
* the `filter_without_index` advisor lint needs: which table, whether the chain
|
|
600
|
+
* narrows with an index, and whether it filters. `table` is `""` when the
|
|
601
|
+
* `query(...)` argument is not a string literal (a dynamic table — not lintable).
|
|
602
|
+
*/
|
|
317
603
|
interface QueryReadIR {
|
|
318
604
|
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
319
605
|
file: string;
|
|
@@ -327,12 +613,12 @@ interface QueryReadIR {
|
|
|
327
613
|
table: string;
|
|
328
614
|
}
|
|
329
615
|
/**
|
|
330
|
-
* A `ctx.authApi.<method>(...)` call discovered in a function body, attributed
|
|
331
|
-
* to the exported function (and its file = api namespace) that performs it.
|
|
332
|
-
* Structurally identical to `AdvisorAuthApiCall` so it passes straight through
|
|
333
|
-
* to the advisor lint without conversion, exactly as `InsertWriteIR` does for
|
|
334
|
-
* `AdvisorInsertWrite`.
|
|
335
|
-
*/
|
|
616
|
+
* A `ctx.authApi.<method>(...)` call discovered in a function body, attributed
|
|
617
|
+
* to the exported function (and its file = api namespace) that performs it.
|
|
618
|
+
* Structurally identical to `AdvisorAuthApiCall` so it passes straight through
|
|
619
|
+
* to the advisor lint without conversion, exactly as `InsertWriteIR` does for
|
|
620
|
+
* `AdvisorInsertWrite`.
|
|
621
|
+
*/
|
|
336
622
|
interface AuthApiCallIR {
|
|
337
623
|
/** Export binding name of the function performing the call, e.g. "createOrg". */
|
|
338
624
|
exportName: string;
|
|
@@ -346,12 +632,12 @@ interface AuthApiCallIR {
|
|
|
346
632
|
method: string;
|
|
347
633
|
}
|
|
348
634
|
/**
|
|
349
|
-
* A `ctx.db.insert("table", …)` write discovered in a function body, attributed
|
|
350
|
-
* to the exported function (and its file = api namespace) that performs it — the
|
|
351
|
-
* write-side analog of {@link QueryReadIR}. Lets tooling wire a table's write
|
|
352
|
-
* action by behavior (which function inserts into it) rather than by naming.
|
|
353
|
-
* {@link InsertWriteIR.table} is `""` when the argument is not a string literal.
|
|
354
|
-
*/
|
|
635
|
+
* A `ctx.db.insert("table", …)` write discovered in a function body, attributed
|
|
636
|
+
* to the exported function (and its file = api namespace) that performs it — the
|
|
637
|
+
* write-side analog of {@link QueryReadIR}. Lets tooling wire a table's write
|
|
638
|
+
* action by behavior (which function inserts into it) rather than by naming.
|
|
639
|
+
* {@link InsertWriteIR.table} is `""` when the argument is not a string literal.
|
|
640
|
+
*/
|
|
355
641
|
interface InsertWriteIR {
|
|
356
642
|
/** Export binding name of the function performing the insert, e.g. "send". */
|
|
357
643
|
exportName: string;
|
|
@@ -363,14 +649,14 @@ interface InsertWriteIR {
|
|
|
363
649
|
table: string;
|
|
364
650
|
}
|
|
365
651
|
/**
|
|
366
|
-
* A non-deterministic API call (`Date.now`, `Math.random`, `crypto.randomUUID`,
|
|
367
|
-
* `crypto.getRandomValues`, `fetch`) discovered lexically inside a `query(...)`
|
|
368
|
-
* or `mutation(...)` handler body — the `nondeterministic_query_mutation` lint
|
|
369
|
-
* input. Structurally identical to `AdvisorNondeterministicCall` so values pass
|
|
370
|
-
* straight through to the advisor without conversion, exactly as `AuthApiCallIR`
|
|
371
|
-
* does for `AdvisorAuthApiCall`. `action(...)` handlers are never recorded —
|
|
372
|
-
* actions are the determinism escape hatch.
|
|
373
|
-
*/
|
|
652
|
+
* A non-deterministic API call (`Date.now`, `Math.random`, `crypto.randomUUID`,
|
|
653
|
+
* `crypto.getRandomValues`, `fetch`) discovered lexically inside a `query(...)`
|
|
654
|
+
* or `mutation(...)` handler body — the `nondeterministic_query_mutation` lint
|
|
655
|
+
* input. Structurally identical to `AdvisorNondeterministicCall` so values pass
|
|
656
|
+
* straight through to the advisor without conversion, exactly as `AuthApiCallIR`
|
|
657
|
+
* does for `AdvisorAuthApiCall`. `action(...)` handlers are never recorded —
|
|
658
|
+
* actions are the determinism escape hatch.
|
|
659
|
+
*/
|
|
374
660
|
interface NondeterministicCallIR {
|
|
375
661
|
/** The non-deterministic API invoked, e.g. `Date.now` / `Math.random` / `crypto.randomUUID` / `fetch`. */
|
|
376
662
|
callee: string;
|
|
@@ -384,13 +670,13 @@ interface NondeterministicCallIR {
|
|
|
384
670
|
line: number;
|
|
385
671
|
}
|
|
386
672
|
/**
|
|
387
|
-
* One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
|
|
388
|
-
* `r2sql_outside_action` advisor lint input. Structurally identical to the
|
|
389
|
-
* advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
|
|
390
|
-
* `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
|
|
391
|
-
* Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
|
|
392
|
-
* home for `ctx.r2sql` and is skipped.
|
|
393
|
-
*/
|
|
673
|
+
* One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
|
|
674
|
+
* `r2sql_outside_action` advisor lint input. Structurally identical to the
|
|
675
|
+
* advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
|
|
676
|
+
* `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
|
|
677
|
+
* Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
|
|
678
|
+
* home for `ctx.r2sql` and is skipped.
|
|
679
|
+
*/
|
|
394
680
|
interface R2sqlCallIR {
|
|
395
681
|
/** The accessed `ctx.r2sql` surface, e.g. `ctx.r2sql.query` / `ctx.r2sql.from`. */
|
|
396
682
|
callee: string;
|
|
@@ -404,21 +690,21 @@ interface R2sqlCallIR {
|
|
|
404
690
|
line: number;
|
|
405
691
|
}
|
|
406
692
|
/**
|
|
407
|
-
* Per-procedure RLS usage snapshot, produced by `discoverRlsProcedures` for the
|
|
408
|
-
* `rls_uncovered_table` advisor lint. Structurally identical to
|
|
409
|
-
* `AdvisorRlsProcedure` (they share the same field set) so values pass straight
|
|
410
|
-
* through to the advisor without conversion, exactly as `AuthApiCallIR` does for
|
|
411
|
-
* `AdvisorAuthApiCall`.
|
|
412
|
-
*/
|
|
693
|
+
* Per-procedure RLS usage snapshot, produced by `discoverRlsProcedures` for the
|
|
694
|
+
* `rls_uncovered_table` advisor lint. Structurally identical to
|
|
695
|
+
* `AdvisorRlsProcedure` (they share the same field set) so values pass straight
|
|
696
|
+
* through to the advisor without conversion, exactly as `AuthApiCallIR` does for
|
|
697
|
+
* `AdvisorAuthApiCall`.
|
|
698
|
+
*/
|
|
413
699
|
interface RlsProcedureIR {
|
|
414
700
|
/** Export binding name of the procedure (e.g. `listDocuments`). */
|
|
415
701
|
exportName: string;
|
|
416
702
|
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
417
703
|
file: string;
|
|
418
704
|
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
705
|
+
* Table names extracted from the `rls(policies)` array literal. Empty when the
|
|
706
|
+
* policies argument is not a statically-readable array literal.
|
|
707
|
+
*/
|
|
422
708
|
rlsTables: string[];
|
|
423
709
|
/** Tables read by the procedure via `ctx.db.query/findMany/findFirst/…`. */
|
|
424
710
|
tablesRead: string[];
|
|
@@ -430,22 +716,22 @@ interface RlsProcedureIR {
|
|
|
430
716
|
visibility: "internal" | "public";
|
|
431
717
|
}
|
|
432
718
|
/**
|
|
433
|
-
* One procedure reduced to the facts the `mask_uncovered_pii_column` lint needs:
|
|
434
|
-
* whether its builder chain includes `.use(mask(...))`, which `(table, column)`
|
|
435
|
-
* pairs that mask declares, and which tables the procedure reads/writes. The
|
|
436
|
-
* column-level analogue of {@link RlsProcedureIR}. Structurally identical to
|
|
437
|
-
* `AdvisorMaskProcedure` so values pass straight through without conversion.
|
|
438
|
-
*/
|
|
719
|
+
* One procedure reduced to the facts the `mask_uncovered_pii_column` lint needs:
|
|
720
|
+
* whether its builder chain includes `.use(mask(...))`, which `(table, column)`
|
|
721
|
+
* pairs that mask declares, and which tables the procedure reads/writes. The
|
|
722
|
+
* column-level analogue of {@link RlsProcedureIR}. Structurally identical to
|
|
723
|
+
* `AdvisorMaskProcedure` so values pass straight through without conversion.
|
|
724
|
+
*/
|
|
439
725
|
interface MaskProcedureIR {
|
|
440
726
|
/** Export binding name of the procedure (e.g. `listUsers`). */
|
|
441
727
|
exportName: string;
|
|
442
728
|
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
443
729
|
file: string;
|
|
444
730
|
/**
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
731
|
+
* `(table, column)` pairs this procedure's `mask(policies)` object literal
|
|
732
|
+
* declares. Empty when the policies argument is not a statically-readable
|
|
733
|
+
* object literal (conservative: `usesMask` is still `true`).
|
|
734
|
+
*/
|
|
449
735
|
maskColumns: {
|
|
450
736
|
column: string;
|
|
451
737
|
table: string;
|
|
@@ -460,14 +746,14 @@ interface MaskProcedureIR {
|
|
|
460
746
|
visibility: "internal" | "public";
|
|
461
747
|
}
|
|
462
748
|
/**
|
|
463
|
-
* One masked column surfaced to the studio's data-browser mask preview: a
|
|
464
|
-
* `(table, column)` pair plus the declared {@link MaskProcedureIR} strategy so
|
|
465
|
-
* the preview can pick redact-vs-hash-vs-custom rendering. Aggregated across the
|
|
466
|
-
* project's `.use(mask(...))` chains by `discoverMaskMetadata`; the descriptive
|
|
467
|
-
* twin of {@link RlsPolicyIR}. `"custom"` covers any non-string strategy (a
|
|
468
|
-
* `(value, ctx) => …` function) — its logic is an opaque closure, never read by
|
|
469
|
-
* the UI; the preview renders a fixed sentinel for it.
|
|
470
|
-
*/
|
|
749
|
+
* One masked column surfaced to the studio's data-browser mask preview: a
|
|
750
|
+
* `(table, column)` pair plus the declared {@link MaskProcedureIR} strategy so
|
|
751
|
+
* the preview can pick redact-vs-hash-vs-custom rendering. Aggregated across the
|
|
752
|
+
* project's `.use(mask(...))` chains by `discoverMaskMetadata`; the descriptive
|
|
753
|
+
* twin of {@link RlsPolicyIR}. `"custom"` covers any non-string strategy (a
|
|
754
|
+
* `(value, ctx) => …` function) — its logic is an opaque closure, never read by
|
|
755
|
+
* the UI; the preview renders a fixed sentinel for it.
|
|
756
|
+
*/
|
|
471
757
|
interface MaskColumnMetadataIR {
|
|
472
758
|
/** Column the mask policy redacts. */
|
|
473
759
|
column: string;
|
|
@@ -477,24 +763,48 @@ interface MaskColumnMetadataIR {
|
|
|
477
763
|
table: string;
|
|
478
764
|
}
|
|
479
765
|
/**
|
|
480
|
-
* Schema-wide masking metadata the codegen emits into the generated ShardDO so
|
|
481
|
-
* the studio's data-browser mask toggle can preview what a non-privileged caller
|
|
482
|
-
* would see. Aggregated across every `.use(mask(...))` chain in the project —
|
|
483
|
-
* purely descriptive (table + column + strategy), never the masking closure. The
|
|
484
|
-
* column-level analogue of {@link RlsMetadataIR}.
|
|
485
|
-
*/
|
|
766
|
+
* Schema-wide masking metadata the codegen emits into the generated ShardDO so
|
|
767
|
+
* the studio's data-browser mask toggle can preview what a non-privileged caller
|
|
768
|
+
* would see. Aggregated across every `.use(mask(...))` chain in the project —
|
|
769
|
+
* purely descriptive (table + column + strategy), never the masking closure. The
|
|
770
|
+
* column-level analogue of {@link RlsMetadataIR}.
|
|
771
|
+
*/
|
|
486
772
|
interface MaskMetadataIR {
|
|
487
773
|
/** Every statically-discovered masked column, deduped by `(table, column)` (first declaration wins). */
|
|
488
774
|
columns: MaskColumnMetadataIR[];
|
|
489
775
|
}
|
|
490
776
|
/**
|
|
491
|
-
* One
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
* `
|
|
497
|
-
|
|
777
|
+
* One masked column whose `mask(policies)` strategy is a statically-known
|
|
778
|
+
* literal (`"hash"` or `"redact"`) — the `mask_weak_hash_strategy_on_pii` lint
|
|
779
|
+
* input. Unlike {@link MaskColumnMetadataIR} (app-wide, deduped by `(table,
|
|
780
|
+
* column)`, studio-preview evidence), this is per declaration site (file + line
|
|
781
|
+
* + enclosing export), undeduped, so the lint can point at the exact
|
|
782
|
+
* `mask(...)` call that applies a weak strategy. A `MaskFn` (custom, non-literal)
|
|
783
|
+
* strategy carries no lint-relevant signal and is never recorded here.
|
|
784
|
+
* Structurally identical to `AdvisorMaskStrategy`.
|
|
785
|
+
*/
|
|
786
|
+
interface MaskStrategyIR {
|
|
787
|
+
/** Masked column name. */
|
|
788
|
+
column: string;
|
|
789
|
+
/** Export binding name of the procedure whose `.use(mask(...))` chain declared this column, or `"<module>"` when declared at file scope. */
|
|
790
|
+
exportName: string;
|
|
791
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
792
|
+
file: string;
|
|
793
|
+
/** 1-based line of the masked column's strategy property. */
|
|
794
|
+
line: number;
|
|
795
|
+
/** The statically-known strategy literal: `"hash"` or `"redact"`. */
|
|
796
|
+
strategy: string;
|
|
797
|
+
/** Logical table the masked column belongs to. */
|
|
798
|
+
table: string;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* One statically-readable policy entry from an `rls([...])` array literal,
|
|
802
|
+
* surfaced to the studio's read-only RLS inspector via the generated
|
|
803
|
+
* `rlsPolicies()` hook. Captures the policy's `table` + `on` operation and the
|
|
804
|
+
* procedure it guards — never the `when` predicate, which is an opaque JS
|
|
805
|
+
* closure (its logic stays in code, not the UI). Produced by
|
|
806
|
+
* `discoverRlsProcedures` alongside the lint IR.
|
|
807
|
+
*/
|
|
498
808
|
interface RlsPolicyIR {
|
|
499
809
|
/** Source file (relative to `lunora/`, without extension) the policy is declared in. */
|
|
500
810
|
file: string;
|
|
@@ -506,12 +816,12 @@ interface RlsPolicyIR {
|
|
|
506
816
|
table: string;
|
|
507
817
|
}
|
|
508
818
|
/**
|
|
509
|
-
* One statically-readable role entry from an `rls(policies, { roles: [...] })`
|
|
510
|
-
* call, surfaced to the studio's RLS inspector. Captures the role's `name`,
|
|
511
|
-
* optional `description`, and the names of the permissions it grants (string
|
|
512
|
-
* literals or `definePermission("name")` calls). Produced by
|
|
513
|
-
* `discoverRlsProcedures`.
|
|
514
|
-
*/
|
|
819
|
+
* One statically-readable role entry from an `rls(policies, { roles: [...] })`
|
|
820
|
+
* call, surfaced to the studio's RLS inspector. Captures the role's `name`,
|
|
821
|
+
* optional `description`, and the names of the permissions it grants (string
|
|
822
|
+
* literals or `definePermission("name")` calls). Produced by
|
|
823
|
+
* `discoverRlsProcedures`.
|
|
824
|
+
*/
|
|
515
825
|
interface RlsRoleIR {
|
|
516
826
|
/** Optional human-readable description from `defineRole(name, { description })`. */
|
|
517
827
|
description?: string;
|
|
@@ -521,11 +831,11 @@ interface RlsRoleIR {
|
|
|
521
831
|
permissions: string[];
|
|
522
832
|
}
|
|
523
833
|
/**
|
|
524
|
-
* Schema-wide RLS metadata the codegen emits into the generated ShardDO so the
|
|
525
|
-
* studio's read-only inspector can list, per table, which policies guard it and
|
|
526
|
-
* what roles are defined. Aggregated across every `.use(rls(...))` chain in the
|
|
527
|
-
* project — purely descriptive, never the predicate logic.
|
|
528
|
-
*/
|
|
834
|
+
* Schema-wide RLS metadata the codegen emits into the generated ShardDO so the
|
|
835
|
+
* studio's read-only inspector can list, per table, which policies guard it and
|
|
836
|
+
* what roles are defined. Aggregated across every `.use(rls(...))` chain in the
|
|
837
|
+
* project — purely descriptive, never the predicate logic.
|
|
838
|
+
*/
|
|
529
839
|
interface RlsMetadataIR {
|
|
530
840
|
/** Every statically-discovered policy `(table, on, procedure)` entry. */
|
|
531
841
|
policies: RlsPolicyIR[];
|
|
@@ -544,24 +854,33 @@ interface StorageRuleIR {
|
|
|
544
854
|
procedure: string;
|
|
545
855
|
}
|
|
546
856
|
/**
|
|
547
|
-
* Schema-wide storage-access-rule metadata emitted into the generated ShardDO so
|
|
548
|
-
* the studio's read-only inspector can list, per bucket, which operations are
|
|
549
|
-
* gated and under what key prefix. Aggregated across every
|
|
550
|
-
* `.use(storageRules(...))` chain — descriptive only, never the predicate logic.
|
|
551
|
-
*/
|
|
857
|
+
* Schema-wide storage-access-rule metadata emitted into the generated ShardDO so
|
|
858
|
+
* the studio's read-only inspector can list, per bucket, which operations are
|
|
859
|
+
* gated and under what key prefix. Aggregated across every
|
|
860
|
+
* `.use(storageRules(...))` chain — descriptive only, never the predicate logic.
|
|
861
|
+
*/
|
|
552
862
|
interface StorageRulesMetadataIR {
|
|
553
863
|
rules: StorageRuleIR[];
|
|
554
864
|
}
|
|
555
865
|
/**
|
|
556
|
-
* A typed REST route declared with the `httpRoute.<verb>("/path")…` builder in
|
|
557
|
-
* `@lunora/server` and mounted on `httpRouter()`. Captured statically from the
|
|
558
|
-
* builder chain so the OpenAPI emitter can render a real `paths` entry: the verb
|
|
559
|
-
* + path become the operation's method + URL, and the accumulated validator maps
|
|
560
|
-
* become its query parameters, path parameters, and request body.
|
|
561
|
-
*/
|
|
866
|
+
* A typed REST route declared with the `httpRoute.<verb>("/path")…` builder in
|
|
867
|
+
* `@lunora/server` and mounted on `httpRouter()`. Captured statically from the
|
|
868
|
+
* builder chain so the OpenAPI emitter can render a real `paths` entry: the verb
|
|
869
|
+
* + path become the operation's method + URL, and the accumulated validator maps
|
|
870
|
+
* become its query parameters, path parameters, and request body.
|
|
871
|
+
*/
|
|
562
872
|
interface HttpRouteIR {
|
|
563
873
|
/** `v.*` validators decoding the JSON request body (`.body({...})`), keyed by field. */
|
|
564
874
|
body: Record<string, ValidatorIR>;
|
|
875
|
+
/**
|
|
876
|
+
* Rendered TS type of one SSE chunk — the `R` the `.stream(handler)`
|
|
877
|
+
* handler yields — inferred from the handler via the type checker. Present
|
|
878
|
+
* only when {@link HttpRouteIR.stream} is `true`; `"unknown"` when the
|
|
879
|
+
* checker can't resolve enough context. Feeds the emitted
|
|
880
|
+
* `HttpStreamRef<Chunk, …>` so the chunk type flows to the client.
|
|
881
|
+
* @experimental Part of the HTTP-SSE stream surface (the `httpStreams.*` emission).
|
|
882
|
+
*/
|
|
883
|
+
chunkType?: string;
|
|
565
884
|
/** Export binding name of the route handler (used only for diagnostics / dedupe). */
|
|
566
885
|
exportName: string;
|
|
567
886
|
/** Path relative to `<projectRoot>/lunora/` without extension, e.g. "http". */
|
|
@@ -580,28 +899,34 @@ interface HttpRouteIR {
|
|
|
580
899
|
stream: boolean;
|
|
581
900
|
}
|
|
582
901
|
/**
|
|
583
|
-
* Per-procedure protective-middleware snapshot, produced by
|
|
584
|
-
* `discoverProcedureMiddleware` for the security lints
|
|
585
|
-
* (`public_mutation_without_ratelimit`, `user_creating_mutation_without_captcha`).
|
|
586
|
-
* Records which `.use(...)` guards a procedure's builder chain carries plus the
|
|
587
|
-
* behavioural facts that decide whether a guard is *expected* (does it write a
|
|
588
|
-
* user/session table, does it send mail). `protectPublic({ rateLimit, captcha })`
|
|
589
|
-
* is unwrapped: the bundle's object-literal keys set `usesRateLimit`/`usesCaptcha`
|
|
590
|
-
* exactly as the individual `.use(rateLimit(...))` / `.use(verifyTurnstile(...))`
|
|
591
|
-
* steps would. Structurally identical to `AdvisorProcedureProtection` so values
|
|
592
|
-
* pass straight through to the advisor without conversion.
|
|
593
|
-
*/
|
|
902
|
+
* Per-procedure protective-middleware snapshot, produced by
|
|
903
|
+
* `discoverProcedureMiddleware` for the security lints
|
|
904
|
+
* (`public_mutation_without_ratelimit`, `user_creating_mutation_without_captcha`).
|
|
905
|
+
* Records which `.use(...)` guards a procedure's builder chain carries plus the
|
|
906
|
+
* behavioural facts that decide whether a guard is *expected* (does it write a
|
|
907
|
+
* user/session table, does it send mail). `protectPublic({ rateLimit, captcha })`
|
|
908
|
+
* is unwrapped: the bundle's object-literal keys set `usesRateLimit`/`usesCaptcha`
|
|
909
|
+
* exactly as the individual `.use(rateLimit(...))` / `.use(verifyTurnstile(...))`
|
|
910
|
+
* steps would. Structurally identical to `AdvisorProcedureProtection` so values
|
|
911
|
+
* pass straight through to the advisor without conversion.
|
|
912
|
+
*/
|
|
594
913
|
interface ProcedureMiddlewareIR {
|
|
595
914
|
/** `true` when the handler (or a helper inside it) references `ctx.mail` / `ctx.email`. */
|
|
596
915
|
callsMail: boolean;
|
|
597
916
|
/** Export binding name of the procedure (e.g. `signUp`). */
|
|
598
917
|
exportName: string;
|
|
918
|
+
/** `true` when the handler fans work out to a privileged, cost-bearing dispatch surface (scheduler `runAfter`/`runAt`, a queue producer send, or a workflow create). Feeds the privileged-fanout lint. */
|
|
919
|
+
fanOut: boolean;
|
|
599
920
|
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
600
921
|
file: string;
|
|
601
922
|
/** Registration kind — only `mutation`/`action` are write-shaped; `query` is read-only. */
|
|
602
923
|
kind: "action" | "mutation" | "query";
|
|
924
|
+
/** `true` when the handler runs an AI generation (`generateText`/`streamText`/`generateObject`/`streamObject`) with no `maxOutputTokens` bound in its config literal. Feeds the `ai_unbounded_generation_public` lint. */
|
|
925
|
+
unboundedAiGeneration: boolean;
|
|
603
926
|
/** `true` when the chain carries `.use(verifyTurnstile(...))` or a `protectPublic({ captcha })` bundle. */
|
|
604
927
|
usesCaptcha: boolean;
|
|
928
|
+
/** `true` when the handler calls `ctx.db.insertManyUnsafe(...)`, bypassing validators and triggers. Feeds the `insert_many_unsafe_user_data` lint. */
|
|
929
|
+
usesInsertManyUnsafe: boolean;
|
|
605
930
|
/** `true` when the chain carries `.use(mask(...))`. */
|
|
606
931
|
usesMask: boolean;
|
|
607
932
|
/** `true` when the chain carries `.use(rateLimit(...))` or a `protectPublic({ rateLimit })` bundle. */
|
|
@@ -614,13 +939,13 @@ interface ProcedureMiddlewareIR {
|
|
|
614
939
|
writesUserTable: boolean;
|
|
615
940
|
}
|
|
616
941
|
/**
|
|
617
|
-
* Per-procedure argument-validator snapshot, produced by the
|
|
618
|
-
* argument-validator discoverer for the input-hardening lints
|
|
619
|
-
* (`public_arg_uses_any`, `unbounded_string_arg`). Only public procedures are
|
|
620
|
-
* recorded — internal functions take server-trusted input. Structurally identical
|
|
621
|
-
* to `AdvisorArgumentValidator` so it passes straight through to the advisor
|
|
622
|
-
* without conversion.
|
|
623
|
-
*/
|
|
942
|
+
* Per-procedure argument-validator snapshot, produced by the
|
|
943
|
+
* argument-validator discoverer for the input-hardening lints
|
|
944
|
+
* (`public_arg_uses_any`, `unbounded_string_arg`). Only public procedures are
|
|
945
|
+
* recorded — internal functions take server-trusted input. Structurally identical
|
|
946
|
+
* to `AdvisorArgumentValidator` so it passes straight through to the advisor
|
|
947
|
+
* without conversion.
|
|
948
|
+
*/
|
|
624
949
|
interface ArgumentValidatorIR {
|
|
625
950
|
/** Arg names declared as `v.any()` (unvalidated, untyped input). */
|
|
626
951
|
anyArgs: string[];
|
|
@@ -634,11 +959,32 @@ interface ArgumentValidatorIR {
|
|
|
634
959
|
unboundedStringArgs: string[];
|
|
635
960
|
}
|
|
636
961
|
/**
|
|
637
|
-
* One
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* Structurally identical to `
|
|
641
|
-
|
|
962
|
+
* One factory/constructor call in `lunora/` whose config object literal a
|
|
963
|
+
* security lint inspects for a present-or-absent key — the shared input for the
|
|
964
|
+
* config-call security lints (payment authorize, inbound-mail verify, rate-limit
|
|
965
|
+
* store, browser private-targets). Structurally identical to `AdvisorConfigCall`
|
|
966
|
+
* so it passes straight through to the advisor without conversion.
|
|
967
|
+
*/
|
|
968
|
+
interface ConfigCallIR {
|
|
969
|
+
/** `true` when the config argument was a static object literal the feeder could read. */
|
|
970
|
+
analyzable: boolean;
|
|
971
|
+
/** The factory function or constructor name at the call site, e.g. `createPayment` / `RateLimiter`. */
|
|
972
|
+
callee: string;
|
|
973
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
974
|
+
file: string;
|
|
975
|
+
/** 1-based line of the call site, or `0` when unknown. */
|
|
976
|
+
line: number;
|
|
977
|
+
/** Keys present in the config object literal (empty when not `analyzable`). */
|
|
978
|
+
presentKeys: string[];
|
|
979
|
+
/** Keys in the config object literal explicitly assigned the literal `true`. */
|
|
980
|
+
trueKeys: string[];
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* One secret-shaped string literal discovered in `lunora/` source — the
|
|
984
|
+
* `hardcoded_secret` lint input. Complements the pre-commit `vis secrets` scan by
|
|
985
|
+
* surfacing the same class of finding in-IDE via the studio Advisors table.
|
|
986
|
+
* Structurally identical to `AdvisorSecretLiteral`.
|
|
987
|
+
*/
|
|
642
988
|
interface SecretLiteralIR {
|
|
643
989
|
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
644
990
|
file: string;
|
|
@@ -650,14 +996,14 @@ interface SecretLiteralIR {
|
|
|
650
996
|
preview: string;
|
|
651
997
|
}
|
|
652
998
|
/**
|
|
653
|
-
* One `ctx.sql.query(text, …)` / `ctx.sql.unsafe(text, …)` call whose `text`
|
|
654
|
-
* argument is built in place rather than passed as a fixed statement — the
|
|
655
|
-
* `sql_injection_risk` lint input. The Hyperdrive driver binds ONLY the `params`
|
|
656
|
-
* array; the `text` string is spliced verbatim into the SQL, so a `text` assembled
|
|
657
|
-
* from a string concatenation or a substitution template literal is an injection
|
|
658
|
-
* vector. A fixed string literal / no-substitution template is safe. Structurally
|
|
659
|
-
* identical to `AdvisorSqlInterpolation`.
|
|
660
|
-
*/
|
|
999
|
+
* One `ctx.sql.query(text, …)` / `ctx.sql.unsafe(text, …)` call whose `text`
|
|
1000
|
+
* argument is built in place rather than passed as a fixed statement — the
|
|
1001
|
+
* `sql_injection_risk` lint input. The Hyperdrive driver binds ONLY the `params`
|
|
1002
|
+
* array; the `text` string is spliced verbatim into the SQL, so a `text` assembled
|
|
1003
|
+
* from a string concatenation or a substitution template literal is an injection
|
|
1004
|
+
* vector. A fixed string literal / no-substitution template is safe. Structurally
|
|
1005
|
+
* identical to `AdvisorSqlInterpolation`.
|
|
1006
|
+
*/
|
|
661
1007
|
interface SqlInterpolationIR {
|
|
662
1008
|
/** Export binding name of the procedure performing the `ctx.sql` call. */
|
|
663
1009
|
exportName: string;
|
|
@@ -667,11 +1013,313 @@ interface SqlInterpolationIR {
|
|
|
667
1013
|
line: number;
|
|
668
1014
|
}
|
|
669
1015
|
/**
|
|
670
|
-
* One
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
|
|
1016
|
+
* One `ctx.fetch(url, …)` call inside an action whose URL argument is derived
|
|
1017
|
+
* from the handler's `args` — the `action_fetch_ssrf` lint input. `ctx.fetch` is
|
|
1018
|
+
* the action-only outbound-request escape hatch with no host allowlist, so a URL
|
|
1019
|
+
* assembled from request input is a server-side request forgery vector (cloud
|
|
1020
|
+
* metadata endpoints, internal services). Only arg-derived URLs reach here; a
|
|
1021
|
+
* fixed literal or a URL built from config/`ctx.*` is not recorded. Structurally
|
|
1022
|
+
* identical to `AdvisorArgumentDerivedFetch`.
|
|
1023
|
+
*/
|
|
1024
|
+
interface ArgumentDerivedFetchIR {
|
|
1025
|
+
/** Export binding name of the action performing the `ctx.fetch` call. */
|
|
1026
|
+
exportName: string;
|
|
1027
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1028
|
+
file: string;
|
|
1029
|
+
/** 1-based line of the `ctx.fetch` call, or `0` when unknown. */
|
|
1030
|
+
line: number;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* One `ctx.kv.<method>(key, …)` call whose namespace key is derived from the
|
|
1034
|
+
* handler's `args` with no server-side scoping — the `kv_unscoped_user_key_idor`
|
|
1035
|
+
* lint input. Workers KV is a single flat namespace, so a key taken straight from
|
|
1036
|
+
* request input lets any caller read, overwrite, or delete another user's entry
|
|
1037
|
+
* (IDOR). Only arg-derived, unscoped keys reach here; a fixed literal, or a key
|
|
1038
|
+
* prefixed with a server-trusted identity (`${ctx.auth.userId}:…` — references
|
|
1039
|
+
* `ctx`, so treated as scoped), is not recorded. `list` is excluded (it takes a
|
|
1040
|
+
* prefix, not a per-entry key). Structurally identical to `AdvisorKvKeyAccess`.
|
|
1041
|
+
*/
|
|
1042
|
+
interface KvKeyAccessIR {
|
|
1043
|
+
/** Export binding name of the procedure performing the `ctx.kv` access. */
|
|
1044
|
+
exportName: string;
|
|
1045
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1046
|
+
file: string;
|
|
1047
|
+
/** 1-based line of the `ctx.kv` call, or `0` when unknown. */
|
|
1048
|
+
line: number;
|
|
1049
|
+
/** The `ctx.kv` method invoked: `get` / `getRaw` / `getWithMetadata` / `put` / `delete`. */
|
|
1050
|
+
method: string;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* One `ctx.db` write (`insert` / `replace` / `patch` / `insertManyUnsafe`) that sets
|
|
1054
|
+
* an ownership / identity column — `userId`, `ownerId`, `tenantId`, and the like —
|
|
1055
|
+
* from the handler's `args` instead of the server-trusted identity. The
|
|
1056
|
+
* `owner_field_from_args_not_auth` lint input: the ownership column decides who a
|
|
1057
|
+
* row belongs to, so a value taken from request input lets any caller write rows
|
|
1058
|
+
* owned by another user or tenant (the act-as-any-user / cross-tenant IDOR vector).
|
|
1059
|
+
* A column stamped from `ctx.*`, or set to a fixed literal, is not recorded; only an
|
|
1060
|
+
* arg-derived identity write reaches here. Structurally identical to
|
|
1061
|
+
* `AdvisorOwnerFieldWrite`.
|
|
1062
|
+
*/
|
|
1063
|
+
interface OwnerFieldWriteIR {
|
|
1064
|
+
/** Export binding name of the procedure performing the write. */
|
|
1065
|
+
exportName: string;
|
|
1066
|
+
/** The identity column being written from `args` (e.g. `userId`). */
|
|
1067
|
+
field: string;
|
|
1068
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1069
|
+
file: string;
|
|
1070
|
+
/** 1-based line of the `ctx.db` write call, or `0` when unknown. */
|
|
1071
|
+
line: number;
|
|
1072
|
+
/** The `ctx.db` write method (`insert` / `replace` / `patch` / `insertManyUnsafe`). */
|
|
1073
|
+
method: string;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* One `ctx.storage.<bucket>.<method>(key, …)` call whose R2 object key is derived
|
|
1077
|
+
* from the handler's `args` with no server-side scoping — the
|
|
1078
|
+
* `storage_key_from_user_args` lint input. The bucket read/write/URL/delete methods
|
|
1079
|
+
* key by their first argument, so an object key taken straight from request input is
|
|
1080
|
+
* object-level IDOR (read/overwrite/delete anyone's object). A key referencing a
|
|
1081
|
+
* server-trusted `ctx.*` value (e.g. `${ctx.auth.userId}/…`) is treated as scoped
|
|
1082
|
+
* and is not recorded; only an arg-derived, `ctx`-free key reaches here.
|
|
1083
|
+
* Structurally identical to `AdvisorStorageKeyAccess`.
|
|
1084
|
+
*/
|
|
1085
|
+
interface StorageKeyAccessIR {
|
|
1086
|
+
/** Export binding name of the procedure performing the storage call. */
|
|
1087
|
+
exportName: string;
|
|
1088
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1089
|
+
file: string;
|
|
1090
|
+
/** 1-based line of the storage call, or `0` when unknown. */
|
|
1091
|
+
line: number;
|
|
1092
|
+
/** The bucket method invoked with the arg-derived key, e.g. `get` / `put` / `delete` / `download`. */
|
|
1093
|
+
method: string;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* One `ctx.containers.<exportName>.get(name, …)` call whose instance key is derived
|
|
1097
|
+
* from the handler's `args` with no server-side scoping — the
|
|
1098
|
+
* `container_instance_key_from_user_input` lint input. Each container definition's
|
|
1099
|
+
* `.get(name)` accessor routes to one instance per `name`, so a key taken straight from
|
|
1100
|
+
* request input lets any caller reach another tenant's container (a cross-tenant IDOR). A
|
|
1101
|
+
* fixed literal key, or one derived from a server-trusted identity (`${ctx.auth.userId}` —
|
|
1102
|
+
* references `ctx`, so treated as scoped), is not recorded; only an arg-derived, unscoped
|
|
1103
|
+
* key reaches here. `.any()`/`.pool()` take no key and are not sinks. Structurally
|
|
1104
|
+
* identical to `AdvisorContainerKeyAccess`.
|
|
1105
|
+
*/
|
|
1106
|
+
interface ContainerKeyAccessIR {
|
|
1107
|
+
/** Export binding name of the procedure performing the `ctx.containers` access. */
|
|
1108
|
+
exportName: string;
|
|
1109
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1110
|
+
file: string;
|
|
1111
|
+
/** 1-based line of the `ctx.containers.*.get` call, or `0` when unknown. */
|
|
1112
|
+
line: number;
|
|
1113
|
+
/** The container accessor method invoked — always `get`. */
|
|
1114
|
+
method: string;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* One `ctx.ai.run(model, …)` call whose model-id argument is derived from the handler's
|
|
1118
|
+
* `args` with no server-side scoping — the `ai_raw_run_escape_hatch` lint input.
|
|
1119
|
+
* `ctx.ai.run` is the raw Workers AI binding passthrough, bypassing the typed
|
|
1120
|
+
* `ctx.ai.model(...)` + AI-SDK layer (`generateText`/`streamText`/…) that caps output and
|
|
1121
|
+
* enforces a schema, so an arg-derived model id lets any caller select an arbitrary model.
|
|
1122
|
+
* A fixed literal model, or one scoped by a server-trusted `ctx.*` value, is not recorded;
|
|
1123
|
+
* only an arg-derived, unscoped model id reaches here (an arg-derived `inputs` argument is
|
|
1124
|
+
* normal usage and is never inspected). Structurally identical to `AdvisorAiRawRun`.
|
|
1125
|
+
*/
|
|
1126
|
+
interface AiRawRunIR {
|
|
1127
|
+
/** Export binding name of the procedure performing the `ctx.ai.run` call. */
|
|
1128
|
+
exportName: string;
|
|
1129
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1130
|
+
file: string;
|
|
1131
|
+
/** 1-based line of the `ctx.ai.run` call, or `0` when unknown. */
|
|
1132
|
+
line: number;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* One `ctx.vectors.<method>(indexName, input)` call whose `input.namespace` is derived
|
|
1136
|
+
* from the handler's `args` with no server-side scoping — the
|
|
1137
|
+
* `vectors_namespace_from_user_input` lint input. A Vectorize namespace partitions one
|
|
1138
|
+
* index into isolated sub-collections, so a namespace taken straight from request input
|
|
1139
|
+
* lets any caller read or poison another tenant's vectors. A fixed literal namespace, or
|
|
1140
|
+
* one prefixed with a server-trusted identity (`${ctx.auth.orgId}` — references `ctx`, so
|
|
1141
|
+
* treated as scoped), is not recorded; only an arg-derived, unscoped namespace reaches
|
|
1142
|
+
* here. Structurally identical to `AdvisorVectorNamespaceAccess`.
|
|
1143
|
+
*/
|
|
1144
|
+
interface VectorNamespaceAccessIR {
|
|
1145
|
+
/** Export binding name of the procedure performing the `ctx.vectors` access. */
|
|
1146
|
+
exportName: string;
|
|
1147
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1148
|
+
file: string;
|
|
1149
|
+
/** 1-based line of the `ctx.vectors` call, or `0` when unknown. */
|
|
1150
|
+
line: number;
|
|
1151
|
+
/** The `ctx.vectors` method invoked: `query` / `upsert` / `upsertMany`. */
|
|
1152
|
+
method: string;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* One `ctx.mail`/`ctx.email` `send`/`queue` call whose recipient field (`to`/`cc`/`bcc`)
|
|
1156
|
+
* is derived from the handler's `args` with no server-side scoping — the
|
|
1157
|
+
* `mail_recipient_from_request_input` lint input. A recipient taken straight from request
|
|
1158
|
+
* input turns the deployment into an open relay / spam amplifier (any caller can direct
|
|
1159
|
+
* mail to an arbitrary address). A fixed literal recipient, or one scoped by a
|
|
1160
|
+
* server-trusted `ctx.*` value (e.g. `ctx.auth.user.email`), is not recorded; only an
|
|
1161
|
+
* arg-derived, unscoped recipient reaches here. Structurally identical to
|
|
1162
|
+
* `AdvisorMailRecipientAccess`.
|
|
1163
|
+
*/
|
|
1164
|
+
interface MailRecipientAccessIR {
|
|
1165
|
+
/** Export binding name of the procedure performing the `ctx.mail`/`ctx.email` call. */
|
|
1166
|
+
exportName: string;
|
|
1167
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1168
|
+
file: string;
|
|
1169
|
+
/** 1-based line of the `ctx.mail`/`ctx.email` call, or `0` when unknown. */
|
|
1170
|
+
line: number;
|
|
1171
|
+
/** The mailer method invoked: `send` / `queue`. */
|
|
1172
|
+
method: string;
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* One `ctx.browser.<method>(url, …)` call whose navigation URL (`arguments[0]`)
|
|
1176
|
+
* is derived from the handler's `args` with no server-side scoping — the
|
|
1177
|
+
* `browser_user_url_without_allowlist` lint input. The lint additionally
|
|
1178
|
+
* cross-references `createBrowser` config-call evidence to suppress findings
|
|
1179
|
+
* when the browser is hardened with an `allowedHosts` allowlist or
|
|
1180
|
+
* `resolveDns`. Structurally identical to `AdvisorBrowserUrlAccess`.
|
|
1181
|
+
*/
|
|
1182
|
+
interface BrowserUrlAccessIR {
|
|
1183
|
+
/** Export binding name of the procedure performing the `ctx.browser` call. */
|
|
1184
|
+
exportName: string;
|
|
1185
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1186
|
+
file: string;
|
|
1187
|
+
/** 1-based line of the `ctx.browser` call, or `0` when unknown. */
|
|
1188
|
+
line: number;
|
|
1189
|
+
/** The browser method invoked: `content` / `pdf` / `scrape` / `screenshot`. */
|
|
1190
|
+
method: string;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* One runtime container-override call: a `<handle>.start({ enableInternet: true, … })`
|
|
1194
|
+
* launch override, or a `<handle>.egress.<method>(...)` runtime firewall mutation
|
|
1195
|
+
* (`allow` / `deny` / `setAllowed`) — the `container_start_enable_internet_override`
|
|
1196
|
+
* and `container_runtime_egress_relaxation` lint input. Both shapes re-open network
|
|
1197
|
+
* access the static `defineContainer` declaration (and its `container_public_internet`
|
|
1198
|
+
* lint) assumes is locked down. Matched structurally by call shape, independent of the
|
|
1199
|
+
* receiver's resolved type. Structurally identical to `AdvisorContainerOverride`.
|
|
1200
|
+
*/
|
|
1201
|
+
interface ContainerOverrideIR {
|
|
1202
|
+
/** e.g. the egress method name, or `"enableInternet: true"`. */
|
|
1203
|
+
detail: string;
|
|
1204
|
+
/** Export binding name of the procedure performing the call. */
|
|
1205
|
+
exportName: string;
|
|
1206
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1207
|
+
file: string;
|
|
1208
|
+
/** Which override shape matched. */
|
|
1209
|
+
kind: "egress_relaxation" | "enable_internet";
|
|
1210
|
+
/** 1-based line of the call, or `0` when unknown. */
|
|
1211
|
+
line: number;
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* One `buildImageDeliveryUrl({ key, … })` call (`@lunora/bindings/images`) whose
|
|
1215
|
+
* `key` — the CDN transform's source image, an absolute URL or an
|
|
1216
|
+
* origin-relative key — is derived from the handler's `args` with no
|
|
1217
|
+
* server-side scoping — the `images_url_source_from_user_input` lint input.
|
|
1218
|
+
* `ctx.images.transform`/`info` take image *bytes*, never a URL, so they are not
|
|
1219
|
+
* sinks; only the `key` of `buildImageDeliveryUrl` accepts a URL-or-key source
|
|
1220
|
+
* and is inspected. An arg-derived `key` lets any caller point the CDN's
|
|
1221
|
+
* `/cdn-cgi/image/` transform at an attacker-chosen origin (SSRF / open proxy)
|
|
1222
|
+
* or at an arbitrary key under the account's own store. A fixed literal, or a
|
|
1223
|
+
* key scoped by a server-trusted `ctx.*` value, is not recorded. Structurally
|
|
1224
|
+
* identical to `AdvisorImageDeliveryUrlAccess`.
|
|
1225
|
+
*/
|
|
1226
|
+
interface ImageDeliveryUrlAccessIR {
|
|
1227
|
+
/** Export binding name of the procedure performing the `buildImageDeliveryUrl` call. */
|
|
1228
|
+
exportName: string;
|
|
1229
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1230
|
+
file: string;
|
|
1231
|
+
/** 1-based line of the `buildImageDeliveryUrl` call, or `0` when unknown. */
|
|
1232
|
+
line: number;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* One `createAuth({...})` call's configuration snapshot — the shared input for
|
|
1236
|
+
* the five `auth_*` security lints (trusted-origins wildcard, CSRF check
|
|
1237
|
+
* disabled, secure cookies disabled, email verification disabled, session
|
|
1238
|
+
* freshAge zero). Matched by callee NAME (an `import`-agnostic, fail-closed
|
|
1239
|
+
* convention the other feeders share), so a re-export or alias still resolves.
|
|
1240
|
+
* When the config argument isn't a statically-analyzable object literal (a
|
|
1241
|
+
* top-level spread, or not an object literal at all), `analyzable` is `false`
|
|
1242
|
+
* and every boolean fact defaults to its SAFE (not-flagged) value — an opaque
|
|
1243
|
+
* config can't be relied on either way. Structurally identical to
|
|
1244
|
+
* `AdvisorAuthConfig`.
|
|
1245
|
+
*/
|
|
1246
|
+
interface AuthConfigIR {
|
|
1247
|
+
/** `true` when the call's config argument was a static object literal the feeder could read. */
|
|
1248
|
+
analyzable: boolean;
|
|
1249
|
+
/** `advanced.disableCSRFCheck === true`. */
|
|
1250
|
+
disableCsrfCheck: boolean;
|
|
1251
|
+
/** `emailAndPassword.enabled === true`. */
|
|
1252
|
+
emailPasswordEnabled: boolean;
|
|
1253
|
+
/** Export binding name enclosing the `createAuth(...)` call. */
|
|
1254
|
+
exportName: string;
|
|
1255
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1256
|
+
file: string;
|
|
1257
|
+
/** 1-based line of the `createAuth(...)` call, or `0` when unknown. */
|
|
1258
|
+
line: number;
|
|
1259
|
+
/** `emailAndPassword.requireEmailVerification === true` present. */
|
|
1260
|
+
requireEmailVerification: boolean;
|
|
1261
|
+
/** `advanced.useSecureCookies === false`. */
|
|
1262
|
+
secureCookiesDisabled: boolean;
|
|
1263
|
+
/** `session.freshAge === 0` (explicit literal). */
|
|
1264
|
+
sessionFreshAgeZero: boolean;
|
|
1265
|
+
/** `trustedOrigins` array literal contains a `"*"` element. */
|
|
1266
|
+
trustedOriginsWildcard: boolean;
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* One `rateLimit`/`dbRateLimit` middleware call (`@lunora/ratelimit`) whose
|
|
1270
|
+
* `key` selector — the per-caller rate-limit sub-key, `(ctx) => string |
|
|
1271
|
+
* undefined` — is derived from the handler's `args` with no server-side
|
|
1272
|
+
* scoping (no reference to the trusted `ctx` binding anywhere in the selector)
|
|
1273
|
+
* — the `ratelimit_key_spoofable_or_global` lint input. A key an attacker
|
|
1274
|
+
* controls lets them rotate it per request and bypass the limit entirely,
|
|
1275
|
+
* defeating its purpose. A selector scoped by `ctx` (e.g. `ctx.auth.userId`,
|
|
1276
|
+
* `ctx.ip`), or one with no `args` reference at all (a fixed/global bucket —
|
|
1277
|
+
* the "no key" case this lint deliberately does not flag, to keep it low-FP),
|
|
1278
|
+
* is not recorded. Structurally identical to `AdvisorRatelimitKeySelector`.
|
|
1279
|
+
*/
|
|
1280
|
+
interface RatelimitKeySelectorIR {
|
|
1281
|
+
/** The `rateLimit`/`dbRateLimit` callee invoked. */
|
|
1282
|
+
callee: string;
|
|
1283
|
+
/** Export binding name of the procedure whose `.use(...)` chain carries the call. */
|
|
1284
|
+
exportName: string;
|
|
1285
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1286
|
+
file: string;
|
|
1287
|
+
/** The rate limit's `name` argument (the second positional argument), or `""` when not a string literal. */
|
|
1288
|
+
limitName: string;
|
|
1289
|
+
/** 1-based line of the `rateLimit`/`dbRateLimit` call, or `0` when unknown. */
|
|
1290
|
+
line: number;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* One payload-derived privileged dispatch — a `ctx.run`/`context.run` back into a
|
|
1294
|
+
* Lunora function from inside a `defineQueue` push handler or a `defineWorkflow`
|
|
1295
|
+
* handler, whose args reference the handler's untrusted payload (`context.params`
|
|
1296
|
+
* for a workflow, a `for (… of batch.messages)` body for a queue) — the
|
|
1297
|
+
* `privileged_dispatch_unvalidated_payload` lint input. Both handler kinds run
|
|
1298
|
+
* under the **system identity** (RLS disabled), so forwarding attacker-influenced
|
|
1299
|
+
* payload into the dispatch bypasses the target's row policy. The resolved
|
|
1300
|
+
* `targetFile`/`targetExport` let the lint join RLS-procedure evidence and fire
|
|
1301
|
+
* only for RLS-gated targets. Structurally identical to `AdvisorPrivilegedDispatch`.
|
|
1302
|
+
*/
|
|
1303
|
+
interface PrivilegedDispatchIR {
|
|
1304
|
+
/** `"queue"` for a `defineQueue` handler, `"workflow"` for a `defineWorkflow` handler. */
|
|
1305
|
+
dispatchKind: "queue" | "workflow";
|
|
1306
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1307
|
+
file: string;
|
|
1308
|
+
/** Export binding name of the handler performing the dispatch. */
|
|
1309
|
+
handlerExport: string;
|
|
1310
|
+
/** 1-based line of the dispatch call, or `0` when unknown. */
|
|
1311
|
+
line: number;
|
|
1312
|
+
/** Export name of the dispatched target (`send` in `api.messages.send`). */
|
|
1313
|
+
targetExport: string;
|
|
1314
|
+
/** File path of the dispatched target relative to `lunora/` (`messages` in `api.messages.send`). */
|
|
1315
|
+
targetFile: string;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* One discovered `httpRoute.<verb>("/admin/…")` route on an admin/privileged-looking
|
|
1319
|
+
* path, with whether its builder chain references an auth/admin guard — the
|
|
1320
|
+
* `admin_route_without_guard` lint input. Structurally identical to
|
|
1321
|
+
* `AdvisorAdminRoute`.
|
|
1322
|
+
*/
|
|
675
1323
|
interface AdminRouteIR {
|
|
676
1324
|
/** Export binding name of the route handler. */
|
|
677
1325
|
exportName: string;
|
|
@@ -684,6 +1332,317 @@ interface AdminRouteIR {
|
|
|
684
1332
|
/** `true` when the handler body references an auth/session/admin guard (`ctx.auth`, `getSession`, `requireAdmin`, …). */
|
|
685
1333
|
usesGuard: boolean;
|
|
686
1334
|
}
|
|
1335
|
+
/**
|
|
1336
|
+
* One tracked `ctx.storage.<bucket>.<method>(...)` upload/signing call — the
|
|
1337
|
+
* shared input for the storage config-hygiene security lints
|
|
1338
|
+
* (`storage_upload_without_content_type_allowlist`, `storage_upload_without_max_size`,
|
|
1339
|
+
* `storage_generate_upload_url_no_content_type_pin`, `storage_presigned_url_for_private_content`).
|
|
1340
|
+
* `upload`/`store` carry the `UploadOptions` guards (`allowedContentTypes` /
|
|
1341
|
+
* `maxSize`); `generateUploadUrl` carries the signed-PUT `contentType` pin;
|
|
1342
|
+
* `getPresignedUrl`/`getSignedUrl` carry a statically-known `expiresInSeconds`
|
|
1343
|
+
* literal. `presentKeys` is empty (and `expiresInSeconds` unset) when the
|
|
1344
|
+
* options argument was absent, a non-literal, or a spread — see `analyzable`.
|
|
1345
|
+
* Structurally identical to `AdvisorStorageUpload`.
|
|
1346
|
+
*/
|
|
1347
|
+
interface StorageUploadIR {
|
|
1348
|
+
/** `true` when the call's options-object argument (or its deliberate absence) was statically resolvable. */
|
|
1349
|
+
analyzable: boolean;
|
|
1350
|
+
/** Numeric literal value of an `expiresInSeconds` option, when statically known (`getSignedUrl` / `getPresignedUrl` only). */
|
|
1351
|
+
expiresInSeconds?: number;
|
|
1352
|
+
/** Export binding name of the procedure performing the call. */
|
|
1353
|
+
exportName: string;
|
|
1354
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1355
|
+
file: string;
|
|
1356
|
+
/** 1-based line of the call, or `0` when unknown. */
|
|
1357
|
+
line: number;
|
|
1358
|
+
/** The `ctx.storage` method invoked. */
|
|
1359
|
+
method: "generateUploadUrl" | "getPresignedUrl" | "getSignedUrl" | "store" | "upload";
|
|
1360
|
+
/** Options-object keys present at the call site (empty when not `analyzable`, or when no options argument was passed). */
|
|
1361
|
+
presentKeys: string[];
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* One discovered `httpAction`/`httpRoute` handler in `lunora/` that performs a
|
|
1365
|
+
* side effect (`ctx.runMutation` / `ctx.runAction` / a `ctx.db.{insert,patch,
|
|
1366
|
+
* replace,delete,insertManyUnsafe}` write) from the HTTP edge, with whether it
|
|
1367
|
+
* reads `ctx.auth` — the `http_action_missing_auth_guard` lint input. A handler
|
|
1368
|
+
* that mutates state or dispatches an action without ever consulting the request
|
|
1369
|
+
* identity is an unauthenticated write bypassing identity/RLS. Only handlers with
|
|
1370
|
+
* a statically-resolvable inline body and `ctx` binding are recorded (fail-safe
|
|
1371
|
+
* under-report); read-only handlers are never recorded. Structurally identical to
|
|
1372
|
+
* `AdvisorHttpActionGuard`.
|
|
1373
|
+
*/
|
|
1374
|
+
interface HttpActionGuardIR {
|
|
1375
|
+
/** Export binding name of the handler (or `"<module>"` when mounted inline / not a named binding). */
|
|
1376
|
+
exportName: string;
|
|
1377
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1378
|
+
file: string;
|
|
1379
|
+
/** Which HTTP surface the handler is: a raw `httpAction` or a typed `httpRoute` route. */
|
|
1380
|
+
kind: "httpAction" | "httpRoute";
|
|
1381
|
+
/** 1-based line of the handler call, or `0` when unknown. */
|
|
1382
|
+
line: number;
|
|
1383
|
+
/** For an `httpRoute`, the uppercased verb (`"POST"`); absent for a raw `httpAction`. */
|
|
1384
|
+
method?: string;
|
|
1385
|
+
/** `true` when the handler reads `ctx.auth` (a direct member access or a `const { auth } = ctx` destructure). */
|
|
1386
|
+
readsAuth: boolean;
|
|
1387
|
+
/** The first side effect found, as a stable label: `runMutation`, `runAction`, or `db.<method>`. */
|
|
1388
|
+
sideEffect: string;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* One response-header write, inside an `httpAction` handler, whose value is derived
|
|
1392
|
+
* from raw request input (`request.headers`, `request.url`/query, `await
|
|
1393
|
+
* request.json()`) with no CR/LF sanitizer — the
|
|
1394
|
+
* `http_action_response_header_injection` lint input. A `Request`-derived string
|
|
1395
|
+
* placed verbatim into a response header lets a caller smuggle `\r\n` and inject
|
|
1396
|
+
* extra headers or split the response (header injection / response splitting). Only
|
|
1397
|
+
* sites whose value is request-tainted AND unguarded are recorded: a value routed
|
|
1398
|
+
* through a CR/LF guard (`isSafeHeaderValue`), a URL/URI encoder
|
|
1399
|
+
* (`encodeURIComponent`/`encodeURI`), a numeric coercion (`Number`/`parseInt`/
|
|
1400
|
+
* `parseFloat`), or `btoa` is treated as safe and never recorded (`String(...)` /
|
|
1401
|
+
* `.toString()` are NOT sanitizers — they don't strip CR/LF). Structurally
|
|
1402
|
+
* identical to `AdvisorHttpHeaderWrite`.
|
|
1403
|
+
*/
|
|
1404
|
+
interface HttpHeaderWriteIR {
|
|
1405
|
+
/** Export binding name of the enclosing handler, or `"<module>"` when mounted inline. */
|
|
1406
|
+
exportName: string;
|
|
1407
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1408
|
+
file: string;
|
|
1409
|
+
/** The header name being written (`"location"`), or `""` when the key is not a string literal. */
|
|
1410
|
+
headerName: string;
|
|
1411
|
+
/** 1-based line of the request-tainted header value. */
|
|
1412
|
+
line: number;
|
|
1413
|
+
/** How the header was written. */
|
|
1414
|
+
via: "headers-append" | "headers-ctor" | "headers-set" | "response-init";
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* One rate-limit / Turnstile middleware call in `lunora/` — the
|
|
1418
|
+
* `ratelimit_middleware_fail_open` lint input. `rateLimit`/`dbRateLimit`
|
|
1419
|
+
* (`@lunora/ratelimit`) and `verifyTurnstileMiddleware` (`@lunora/auth`) each
|
|
1420
|
+
* accept a `failOpen` escape hatch that admits every request when the
|
|
1421
|
+
* limiter/siteverify is unavailable; `failOpen` is `true` only when the options
|
|
1422
|
+
* literal set it to the boolean literal `true` (anything else is fail-closed).
|
|
1423
|
+
* The lint escalates a fail-open guard to a finding when the guarded procedure
|
|
1424
|
+
* (`exportName`/`limitName`) looks auth/payment-sensitive. Structurally
|
|
1425
|
+
* identical to `AdvisorFailOpenGuard`.
|
|
1426
|
+
*/
|
|
1427
|
+
interface FailOpenGuardIR {
|
|
1428
|
+
/** The middleware factory at the call site: `rateLimit` / `dbRateLimit` / `verifyTurnstileMiddleware`. */
|
|
1429
|
+
callee: string;
|
|
1430
|
+
/** Export binding name of the procedure the guard is attached to, or `"<module>"` at file scope. */
|
|
1431
|
+
exportName: string;
|
|
1432
|
+
/** `true` only when the options literal set `failOpen: true` as a boolean literal; a non-literal or absent option is treated as fail-closed. */
|
|
1433
|
+
failOpen: boolean;
|
|
1434
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1435
|
+
file: string;
|
|
1436
|
+
/** The rate-limit `name` (second string argument) for `rateLimit`/`dbRateLimit`; `""` for `verifyTurnstileMiddleware`. */
|
|
1437
|
+
limitName: string;
|
|
1438
|
+
/** 1-based line of the middleware call, or `0` when unknown. */
|
|
1439
|
+
line: number;
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* One `ctx.flags.boolean("key", <boolean-literal>)` read in `lunora/` — the
|
|
1443
|
+
* `flag_gates_security_with_unsafe_default` lint input. OpenFeature returns the
|
|
1444
|
+
* `defaultValue` when the provider errors, so a fail-open default on a
|
|
1445
|
+
* security-shaped key silently opens access during an outage. Only reads with a
|
|
1446
|
+
* statically-known string key and boolean-literal default are recorded; the lint
|
|
1447
|
+
* owns the security-shape + polarity judgment. Structurally identical to
|
|
1448
|
+
* `AdvisorFlagSecurityDefault`.
|
|
1449
|
+
*/
|
|
1450
|
+
interface FlagSecurityDefaultIR {
|
|
1451
|
+
/** The boolean-literal default returned on a provider outage (fail-open value). */
|
|
1452
|
+
defaultValue: boolean;
|
|
1453
|
+
/** Export binding name of the procedure performing the flag read, or `"<module>"` at file scope. */
|
|
1454
|
+
exportName: string;
|
|
1455
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1456
|
+
file: string;
|
|
1457
|
+
/** The flag key — the first string-literal argument of `ctx.flags.boolean`. */
|
|
1458
|
+
key: string;
|
|
1459
|
+
/** 1-based line of the `ctx.flags.boolean` call, or `0` when unknown. */
|
|
1460
|
+
line: number;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* One `generateText` / `streamText` call in `lunora/` whose `tools` reach a
|
|
1464
|
+
* privileged side effect (a DB write, function dispatch, or outbound
|
|
1465
|
+
* fetch/mail/queue send). `userInputDerived` records whether the model input
|
|
1466
|
+
* (`prompt`/`messages`/`system`) flows from the handler's `args`; the
|
|
1467
|
+
* `ai_tool_side_effect_prompt_injection` lint fires only when it does.
|
|
1468
|
+
* Structurally identical to `AdvisorAiToolSideEffect`.
|
|
1469
|
+
*/
|
|
1470
|
+
interface AiToolSideEffectIR {
|
|
1471
|
+
/** Export binding name of the procedure performing the call. */
|
|
1472
|
+
exportName: string;
|
|
1473
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1474
|
+
file: string;
|
|
1475
|
+
/** 1-based line of the generation call, or `0` when unknown. */
|
|
1476
|
+
line: number;
|
|
1477
|
+
/** The generation entrypoint invoked. */
|
|
1478
|
+
method: "generateText" | "streamText";
|
|
1479
|
+
/** The privileged side-effect sink a model-callable tool reaches (`ctx.db.insert`, `ctx.run`, `ctx.fetch`, …). */
|
|
1480
|
+
sideEffect: string;
|
|
1481
|
+
/** `true` when a model-input option is derived from the handler's `args` (a bare `args.x`, or a name destructured from `args`). */
|
|
1482
|
+
userInputDerived: boolean;
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* One `<receiver>.identity.<key>` claim read in `lunora/`, where `<receiver>` is
|
|
1486
|
+
* an RLS/mask policy `auth` (or `ctx.auth`/`context.auth`). `declared` records
|
|
1487
|
+
* whether `<key>` is in the app's `defineIdentity({ ... })` contract (or the
|
|
1488
|
+
* always-present `userId`); the `identity_undeclared_claim_trusted` lint fires on
|
|
1489
|
+
* the undeclared reads. Emitted only when a resolvable identity contract exists.
|
|
1490
|
+
* Structurally identical to `AdvisorIdentityClaimRead`.
|
|
1491
|
+
*/
|
|
1492
|
+
interface IdentityClaimReadIR {
|
|
1493
|
+
/** `true` when `key` is a declared claim (in the `defineIdentity` contract, or the always-present `userId`). */
|
|
1494
|
+
declared: boolean;
|
|
1495
|
+
/** Export binding name of the enclosing declaration (`<module>` at file scope). */
|
|
1496
|
+
exportName: string;
|
|
1497
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1498
|
+
file: string;
|
|
1499
|
+
/** The claim key read off the identity bag. */
|
|
1500
|
+
key: string;
|
|
1501
|
+
/** 1-based line of the read, or `0` when unknown. */
|
|
1502
|
+
line: number;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* One payment webhook-adapter construction in `lunora/` (`createStripeAdapter` /
|
|
1506
|
+
* `createPolarAdapter` / `createAutumnAdapter` / `createDodoPaymentsAdapter`).
|
|
1507
|
+
* `toleranceSeconds` carries the statically-known `webhookToleranceSeconds`
|
|
1508
|
+
* replay window when it is a plain numeric literal; the payment-webhook
|
|
1509
|
+
* wide-tolerance lint fires when it exceeds a conservative ceiling. Structurally
|
|
1510
|
+
* identical to `AdvisorPaymentWebhook`.
|
|
1511
|
+
*/
|
|
1512
|
+
interface PaymentWebhookIR {
|
|
1513
|
+
/** The adapter factory invoked. */
|
|
1514
|
+
callee: "createAutumnAdapter" | "createDodoPaymentsAdapter" | "createPolarAdapter" | "createStripeAdapter";
|
|
1515
|
+
/** Export binding name of the enclosing declaration (`<module>` at file scope). */
|
|
1516
|
+
exportName: string;
|
|
1517
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1518
|
+
file: string;
|
|
1519
|
+
/** 1-based line of the construction, or `0` when unknown. */
|
|
1520
|
+
line: number;
|
|
1521
|
+
/** Statically-known `webhookToleranceSeconds` literal, when present and a plain numeric literal. */
|
|
1522
|
+
toleranceSeconds?: number;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* One `ctx.db.<table>.findMany({ includeDeleted })` list read whose
|
|
1526
|
+
* `includeDeleted` is either a hardcoded `true` or derived from the handler's
|
|
1527
|
+
* `args` — the `soft_delete_include_deleted_from_args` lint input. The lint joins
|
|
1528
|
+
* `table` against the schema's soft-delete tables and `visibility` against
|
|
1529
|
+
* `.public()` before flagging. Structurally identical to `AdvisorSoftDeleteRead`
|
|
1530
|
+
* so values pass straight through without conversion.
|
|
1531
|
+
*/
|
|
1532
|
+
interface SoftDeleteReadIR {
|
|
1533
|
+
/** Export binding name of the procedure performing the read. */
|
|
1534
|
+
exportName: string;
|
|
1535
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1536
|
+
file: string;
|
|
1537
|
+
/** `true` when `includeDeleted` was derived from the handler's `args` (any caller can flip it). */
|
|
1538
|
+
fromArgs: boolean;
|
|
1539
|
+
/** `true` when `includeDeleted` was a hardcoded `true` literal (always resurfaces soft-deleted rows). */
|
|
1540
|
+
hardcodedTrue: boolean;
|
|
1541
|
+
/** 1-based line of the read call. */
|
|
1542
|
+
line: number;
|
|
1543
|
+
/** Table read, or `""` when the table-arg form's first argument wasn't a string literal. */
|
|
1544
|
+
table: string;
|
|
1545
|
+
/** `"internal"` for `internalQuery` / `internalMutation` / `internalAction`. */
|
|
1546
|
+
visibility: "internal" | "public";
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* One `ctx.db.<table>.findMany({ with: { <rel> } })` relation-hydrating list read
|
|
1550
|
+
* — the `masked_relation_leak_via_with` lint input. Column masking does not
|
|
1551
|
+
* descend into `with`-hydrated relations, so a masked table surfaced only through
|
|
1552
|
+
* a `with` on an unprotected parent read is returned in the clear. The lint
|
|
1553
|
+
* resolves each relation accessor to its target table and joins it against the
|
|
1554
|
+
* discovered mask evidence before flagging. Structurally identical to
|
|
1555
|
+
* `AdvisorRelationLoad` so values pass straight through without conversion.
|
|
1556
|
+
*/
|
|
1557
|
+
interface RelationLoadIR {
|
|
1558
|
+
/** Export binding name of the procedure performing the read. */
|
|
1559
|
+
exportName: string;
|
|
1560
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1561
|
+
file: string;
|
|
1562
|
+
/** 1-based line of the read call. */
|
|
1563
|
+
line: number;
|
|
1564
|
+
/** Parent table the read targets, or `""` when the table-arg form's first argument wasn't a string literal. */
|
|
1565
|
+
parentTable: string;
|
|
1566
|
+
/** Relation accessor names named in the read's `with: { … }` map — matched against the parent table's declared relations. */
|
|
1567
|
+
relations: string[];
|
|
1568
|
+
/** `"internal"` for `internalQuery` / `internalMutation` / `internalAction`. */
|
|
1569
|
+
visibility: "internal" | "public";
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* One `query` handler whose `return` hands back the raw rows of a table — the
|
|
1573
|
+
* result of a `ctx.db.<table>.findMany()` / `.findFirst()` / `.get()` read, or a
|
|
1574
|
+
* `ctx.db.query("<table>")…collect()` fluent chain — returned directly (or through
|
|
1575
|
+
* one local `const` hop) with no hand-built projection. The
|
|
1576
|
+
* `output_projection_missing_on_public_read` lint keeps only `visibility ===
|
|
1577
|
+
* "public"` rows with no `.output(...)` / `.use(mask(...))` on the chain, then
|
|
1578
|
+
* joins `table` against the schema and flags one whose columns are PII-named.
|
|
1579
|
+
* Structurally identical to `AdvisorRawRowReturn` so values pass straight through
|
|
1580
|
+
* without conversion.
|
|
1581
|
+
*/
|
|
1582
|
+
interface RawRowReturnIR {
|
|
1583
|
+
/** Export binding name of the query returning the raw rows. */
|
|
1584
|
+
exportName: string;
|
|
1585
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1586
|
+
file: string;
|
|
1587
|
+
/** 1-based line of the `return` (or concise-body) expression. */
|
|
1588
|
+
line: number;
|
|
1589
|
+
/** Table whose raw rows are returned, or `""` when the read's table wasn't a string literal. */
|
|
1590
|
+
table: string;
|
|
1591
|
+
/** `true` when the procedure's builder chain carries a `.use(mask(...))` step. */
|
|
1592
|
+
usesMask: boolean;
|
|
1593
|
+
/** `true` when the procedure's builder chain carries an `.output(...)` return-shape projection. */
|
|
1594
|
+
usesOutput: boolean;
|
|
1595
|
+
/** `"internal"` for `internalQuery`; `"public"` for `query`. */
|
|
1596
|
+
visibility: "internal" | "public";
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* One `query`/`mutation` handler that gates a `ctx.db.get`/`patch`/`delete` on a
|
|
1600
|
+
* null-checked `ctx.db.normalizeId(table, id)` result — the
|
|
1601
|
+
* `normalize_id_used_as_authorization` lint input. `normalizeId` validates an id's
|
|
1602
|
+
* structural shape only (it never reads the database), so a non-null result proves
|
|
1603
|
+
* the id is well-formed, never that the caller owns the row; gating access on it is
|
|
1604
|
+
* an IDOR. The lint owns the negative proof — it keeps only `visibility === "public"`
|
|
1605
|
+
* rows with no `.use(rls(...))` and no ownership/identity mention (`mentionsOwnership`),
|
|
1606
|
+
* then joins `table` against the schema's RLS mode before flagging. Structurally
|
|
1607
|
+
* identical to `AdvisorNormalizeIdAuthorization` so values pass straight through.
|
|
1608
|
+
*/
|
|
1609
|
+
interface NormalizeIdAuthorizationIR {
|
|
1610
|
+
/** Export binding name of the procedure performing the normalize-then-access. */
|
|
1611
|
+
exportName: string;
|
|
1612
|
+
/** Source file relative to `<projectRoot>/lunora/`, without extension. */
|
|
1613
|
+
file: string;
|
|
1614
|
+
/** 1-based line of the `ctx.db.normalizeId(...)` call the access is gated on. */
|
|
1615
|
+
line: number;
|
|
1616
|
+
/** `true` when the handler anywhere reads an ownership-named identifier or `ctx.auth`/`ctx.identity`/… — an intervening ownership signal. */
|
|
1617
|
+
mentionsOwnership: boolean;
|
|
1618
|
+
/** The id-first `ctx.db` sink the normalized id reaches. */
|
|
1619
|
+
sinkMethod: "delete" | "get" | "patch";
|
|
1620
|
+
/** Table named in the `normalizeId` call, or `""` when its table argument wasn't a string literal. */
|
|
1621
|
+
table: string;
|
|
1622
|
+
/** `true` when the procedure's builder chain carries a `.use(rls(...))` step. */
|
|
1623
|
+
usesRls: boolean;
|
|
1624
|
+
/** `"internal"` for `internalQuery`/`internalMutation`; `"public"` for `query`/`mutation`. */
|
|
1625
|
+
visibility: "internal" | "public";
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* One committed `wrangler.jsonc` `vars` entry whose value is a plaintext secret —
|
|
1629
|
+
* the `plaintext_secret_in_wrangler_vars` lint input. `vars` are baked into the
|
|
1630
|
+
* deployed Worker in cleartext and checked into source control, so a real API key
|
|
1631
|
+
* / token / private key there ships the secret to every reader of the repo and the
|
|
1632
|
+
* bundle; it belongs in a Secrets Store binding or `wrangler secret put`. Produced
|
|
1633
|
+
* by `@lunora/config` (which reads `wrangler.jsonc`), not a ts-morph feeder —
|
|
1634
|
+
* codegen only passes it through. Structurally identical to `AdvisorWranglerVariable`.
|
|
1635
|
+
*/
|
|
1636
|
+
interface WranglerVariableIR {
|
|
1637
|
+
/** The `wrangler.jsonc` file the var was read from, relative to the project root. */
|
|
1638
|
+
file: string;
|
|
1639
|
+
/** The offending `vars` key (e.g. `STRIPE_SECRET_KEY`). */
|
|
1640
|
+
key: string;
|
|
1641
|
+
/** Heuristic that matched, e.g. `stripe_live_key` / `private_key` / `secret_named_var`. */
|
|
1642
|
+
kind: string;
|
|
1643
|
+
/** Redacted preview of the value (first few chars + length) for the finding detail — never the full secret. */
|
|
1644
|
+
preview: string;
|
|
1645
|
+
}
|
|
687
1646
|
interface ProjectIR {
|
|
688
1647
|
crons: ReadonlyArray<CronJobIR>;
|
|
689
1648
|
functions: ReadonlyArray<FunctionIR>;
|
|
@@ -693,283 +1652,466 @@ interface ProjectIR {
|
|
|
693
1652
|
schema: SchemaIR;
|
|
694
1653
|
}
|
|
695
1654
|
/**
|
|
696
|
-
* Run the static lints against a discovered {@link SchemaIR} and the reads/writes/calls
|
|
697
|
-
* found in function bodies: query reads feed `filter_without_index`, insert writes
|
|
698
|
-
* feed `table_without_insert`, authApi calls feed `auth_api_call_without_headers`,
|
|
699
|
-
* rls procedure snapshots feed `rls_uncovered_table`,
|
|
700
|
-
* snapshots feed `mask_uncovered_pii_column
|
|
701
|
-
* feed
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
|
|
1655
|
+
* Run the static lints against a discovered {@link SchemaIR} and the reads/writes/calls
|
|
1656
|
+
* found in function bodies: query reads feed `filter_without_index`, insert writes
|
|
1657
|
+
* feed `table_without_insert`, authApi calls feed `auth_api_call_without_headers`,
|
|
1658
|
+
* rls procedure snapshots feed `rls_uncovered_table`, mask procedure
|
|
1659
|
+
* snapshots feed `mask_uncovered_pii_column`, and per-column mask strategies
|
|
1660
|
+
* feed `mask_weak_hash_strategy_on_pii`; declared containers
|
|
1661
|
+
* feed the `container_*` lints; declared workflows (with their durable step labels)
|
|
1662
|
+
* + `ctx.workflows.get(...)` call sites feed the `workflow_unused` /
|
|
1663
|
+
* `workflow_unknown_target` / duplicate-step-name lints; non-deterministic
|
|
1664
|
+
* calls inside query/mutation handlers feed the `nondeterministic_query_mutation` lint
|
|
1665
|
+
* (all default empty for callers that don't analyze functions/containers/workflows).
|
|
1666
|
+
* The IR types are structurally identical to the advisor's evidence types so they
|
|
1667
|
+
* pass straight through without conversion. Returns the findings; surfacing them
|
|
1668
|
+
* (console, error overlay, studio Advisors table) is the caller's choice.
|
|
1669
|
+
*/
|
|
1670
|
+
/**
|
|
1671
|
+
* Named inputs for {@link lintSchema}. Every feeder is a discrete key rather than
|
|
1672
|
+
* a positional argument: the feeder list grows every few releases and many IR
|
|
1673
|
+
* types are structurally similar (`{file, exportName, line}`-shaped evidence),
|
|
1674
|
+
* so a positional call was a silent-transposition hazard — swapping two adjacent
|
|
1675
|
+
* arguments could typecheck yet feed the wrong evidence to the wrong lint and
|
|
1676
|
+
* corrupt a security advisory. `schema` is the only required field; every other
|
|
1677
|
+
* feeder defaults to "not analyzed" when omitted.
|
|
1678
|
+
*/
|
|
1679
|
+
interface LintSchemaOptions {
|
|
1680
|
+
adminRoutes?: ReadonlyArray<AdminRouteIR>;
|
|
1681
|
+
aiRawRuns?: ReadonlyArray<AiRawRunIR>;
|
|
1682
|
+
aiToolSideEffects?: ReadonlyArray<AiToolSideEffectIR>;
|
|
1683
|
+
argumentDerivedFetches?: ReadonlyArray<ArgumentDerivedFetchIR>;
|
|
1684
|
+
argumentValidators?: ReadonlyArray<ArgumentValidatorIR>;
|
|
1685
|
+
authApiCalls?: ReadonlyArray<AuthApiCallIR>;
|
|
1686
|
+
authConfigs?: ReadonlyArray<AuthConfigIR>;
|
|
1687
|
+
browserUrlAccesses?: ReadonlyArray<BrowserUrlAccessIR>;
|
|
1688
|
+
configCalls?: ReadonlyArray<ConfigCallIR>;
|
|
1689
|
+
containerKeyAccesses?: ReadonlyArray<ContainerKeyAccessIR>;
|
|
1690
|
+
containerOverrides?: ReadonlyArray<ContainerOverrideIR>;
|
|
1691
|
+
containers?: ReadonlyArray<ContainerIR>;
|
|
1692
|
+
failOpenGuards?: ReadonlyArray<FailOpenGuardIR>;
|
|
1693
|
+
flagSecurityDefaults?: ReadonlyArray<FlagSecurityDefaultIR>;
|
|
1694
|
+
httpActionGuards?: ReadonlyArray<HttpActionGuardIR>;
|
|
1695
|
+
httpHeaderWrites?: ReadonlyArray<HttpHeaderWriteIR>;
|
|
1696
|
+
identityClaimReads?: ReadonlyArray<IdentityClaimReadIR>;
|
|
1697
|
+
imageDeliveryUrlAccesses?: ReadonlyArray<ImageDeliveryUrlAccessIR>;
|
|
1698
|
+
inserts?: ReadonlyArray<InsertWriteIR>;
|
|
1699
|
+
kvKeyAccesses?: ReadonlyArray<KvKeyAccessIR>;
|
|
1700
|
+
mailRecipientAccesses?: ReadonlyArray<MailRecipientAccessIR>;
|
|
1701
|
+
maskProcedures?: ReadonlyArray<MaskProcedureIR>;
|
|
1702
|
+
maskStrategies?: ReadonlyArray<MaskStrategyIR>;
|
|
1703
|
+
mutatorWrites?: ReadonlyArray<MutatorWriteIR>;
|
|
1704
|
+
nondeterministicCalls?: ReadonlyArray<NondeterministicCallIR>;
|
|
1705
|
+
normalizeIdAuthorizations?: ReadonlyArray<NormalizeIdAuthorizationIR>;
|
|
1706
|
+
ownerFieldWrites?: ReadonlyArray<OwnerFieldWriteIR>;
|
|
1707
|
+
paymentWebhooks?: ReadonlyArray<PaymentWebhookIR>;
|
|
1708
|
+
privilegedDispatches?: ReadonlyArray<PrivilegedDispatchIR>;
|
|
1709
|
+
procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>;
|
|
1710
|
+
queries?: ReadonlyArray<QueryReadIR>;
|
|
1711
|
+
queues?: ReadonlyArray<QueueIR>;
|
|
1712
|
+
r2sqlCalls?: ReadonlyArray<R2sqlCallIR>;
|
|
1713
|
+
ratelimitKeySelectors?: ReadonlyArray<RatelimitKeySelectorIR>;
|
|
1714
|
+
rawRowReturns?: ReadonlyArray<RawRowReturnIR>;
|
|
1715
|
+
relationLoads?: ReadonlyArray<RelationLoadIR>;
|
|
1716
|
+
rlsProcedures?: ReadonlyArray<RlsProcedureIR>;
|
|
1717
|
+
schema: SchemaIR;
|
|
1718
|
+
secretLiterals?: ReadonlyArray<SecretLiteralIR>;
|
|
1719
|
+
shapes?: ReadonlyArray<ShapeIR>;
|
|
1720
|
+
softDeleteReads?: ReadonlyArray<SoftDeleteReadIR>;
|
|
1721
|
+
sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>;
|
|
1722
|
+
storageKeyAccesses?: ReadonlyArray<StorageKeyAccessIR>;
|
|
1723
|
+
storageUploads?: ReadonlyArray<StorageUploadIR>;
|
|
1724
|
+
vectorNamespaceAccesses?: ReadonlyArray<VectorNamespaceAccessIR>;
|
|
1725
|
+
workflowCalls?: ReadonlyArray<WorkflowCallIR>;
|
|
1726
|
+
workflows?: ReadonlyArray<WorkflowIR>;
|
|
1727
|
+
wranglerVariables?: ReadonlyArray<WranglerVariableIR>;
|
|
1728
|
+
}
|
|
1729
|
+
declare const lintSchema: (options: LintSchemaOptions) => Finding[];
|
|
1730
|
+
/**
|
|
1731
|
+
* Render advisor findings as a single multi-line string for console surfacing:
|
|
1732
|
+
* a one-line summary header followed by one `[LEVEL] name: detail` line per
|
|
1733
|
+
* finding. Returns `""` when there are no findings.
|
|
1734
|
+
*/
|
|
715
1735
|
declare const formatAdvisories: (findings: ReadonlyArray<Finding>) => string;
|
|
716
1736
|
/**
|
|
717
|
-
* An error thrown by codegen discovery when the user's schema or function
|
|
718
|
-
* source has a structural problem that can be pinpointed to a specific source
|
|
719
|
-
* location.
|
|
720
|
-
*
|
|
721
|
-
|
|
722
|
-
|
|
1737
|
+
* An error thrown by codegen discovery when the user's schema or function
|
|
1738
|
+
* source has a structural problem that can be pinpointed to a specific source
|
|
1739
|
+
* location. A `LunoraError` subclass (`code: "CODEGEN_DIAGNOSTIC"`); the `file`,
|
|
1740
|
+
* `line`, and `column` properties (also passed through as the base `loc`) mirror
|
|
1741
|
+
* what Vite's error-overlay `loc` field expects so the browser can display the
|
|
1742
|
+
* exact spot.
|
|
1743
|
+
*/
|
|
1744
|
+
declare class CodegenDiagnosticError extends LunoraError {
|
|
723
1745
|
readonly column: number;
|
|
724
1746
|
readonly file: string;
|
|
725
1747
|
readonly line: number;
|
|
726
1748
|
constructor(message: string, file: string, line: number, column: number);
|
|
727
1749
|
}
|
|
728
1750
|
/**
|
|
729
|
-
* Build a {@link CodegenDiagnosticError} whose message includes the source
|
|
730
|
-
* location and whose `file`/`line`/`column` properties are set from the
|
|
731
|
-
* ts-morph `Node`'s position in its source file.
|
|
732
|
-
*
|
|
733
|
-
* Message format: `@lunora/codegen: <detail> (<file>:<line>:<column>)`
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*/
|
|
1751
|
+
* Build a {@link CodegenDiagnosticError} whose message includes the source
|
|
1752
|
+
* location and whose `file`/`line`/`column` properties are set from the
|
|
1753
|
+
* ts-morph `Node`'s position in its source file.
|
|
1754
|
+
*
|
|
1755
|
+
* Message format: `@lunora/codegen: <detail> (<file>:<line>:<column>)`
|
|
1756
|
+
*
|
|
1757
|
+
* `meta` is merged onto the returned error for callers that also carry the
|
|
1758
|
+
* project-wide `LunoraError` envelope (`code`/`name`/`status`) — it never
|
|
1759
|
+
* touches `file`/`line`/`column`, and the error stays an instance of
|
|
1760
|
+
* {@link CodegenDiagnosticError} so the Vite overlay's `instanceof` location
|
|
1761
|
+
* lookup is unaffected.
|
|
1762
|
+
*/
|
|
1763
|
+
declare const diagnosticAt: (node: Node, detail: string, meta?: Record<string, unknown>) => CodegenDiagnosticError;
|
|
1764
|
+
/** The only file agents may be declared in — mirrors `lunora/workflows.ts`. */
|
|
1765
|
+
declare const AGENTS_FILENAME = "agents.ts";
|
|
1766
|
+
/**
|
|
1767
|
+
* Discover every agent the project declares: exported `defineAgent()` calls in
|
|
1768
|
+
* `lunora/agents.ts`. Returns `[]` when the file doesn't exist. Only four things
|
|
1769
|
+
* are read statically — the optional `name` override (wrangler `workflows[].name`),
|
|
1770
|
+
* the optional `publicRun` opt-in (the `agents:agentRun` capability gate), the
|
|
1771
|
+
* presence of a `voice` block (which turns on the voice-session Durable Object),
|
|
1772
|
+
* and the presence of an `onEmail` mapper (which wires the worker `email()`
|
|
1773
|
+
* handler); the rest of the agent config (model / tools / memory / voice models /
|
|
1774
|
+
* the `onEmail` closure body) is runtime-only, so codegen never evaluates it.
|
|
1775
|
+
*/
|
|
1776
|
+
declare const discoverAgents: (project: Project, lunoraDirectory: string) => AgentIR[];
|
|
1777
|
+
/**
|
|
1778
|
+
* Discover `ctx.authApi.<method>(...)` (and bare `authApi.<method>(...)`) calls
|
|
1779
|
+
* under the lunora source directory and attribute each to the exported function
|
|
1780
|
+
* (and file) performing it. Calls outside an exported declaration are dropped.
|
|
1781
|
+
*/
|
|
741
1782
|
declare const discoverAuthApiCalls: (project: Project, lunoraDirectory: string) => AuthApiCallIR[];
|
|
742
1783
|
/** The only file containers may be declared in — mirrors `lunora/crons.ts`. */
|
|
743
1784
|
declare const CONTAINERS_FILENAME = "containers.ts";
|
|
744
1785
|
/**
|
|
745
|
-
* Discover every container the project declares: exported `defineContainer()`
|
|
746
|
-
* calls in `lunora/containers.ts`. Returns `[]` when the file doesn't exist.
|
|
747
|
-
* Wrangler-relevant fields (`image`, `instanceType`, `maxInstances`, `name`)
|
|
748
|
-
* must be static literals; runtime-only fields (`env`, `sleepAfter`, …) may be
|
|
749
|
-
* any expression since the generated class imports the definition object.
|
|
750
|
-
*/
|
|
1786
|
+
* Discover every container the project declares: exported `defineContainer()`
|
|
1787
|
+
* calls in `lunora/containers.ts`. Returns `[]` when the file doesn't exist.
|
|
1788
|
+
* Wrangler-relevant fields (`image`, `instanceType`, `maxInstances`, `name`)
|
|
1789
|
+
* must be static literals; runtime-only fields (`env`, `sleepAfter`, …) may be
|
|
1790
|
+
* any expression since the generated class imports the definition object.
|
|
1791
|
+
*/
|
|
751
1792
|
declare const discoverContainers: (project: Project, lunoraDirectory: string) => ContainerIR[];
|
|
752
1793
|
/**
|
|
753
|
-
* Scan every `.ts` file under `lunoraDir` for `cronJobs()` builder registrations
|
|
754
|
-
* (`crons.interval(...)`, `crons.daily(...)`, `crons.cron(...)`, …) and lift them
|
|
755
|
-
* into {@link CronJobIR}. Schedules are compiled to standard cron expressions;
|
|
756
|
-
* function references are resolved to their `namespace:fn` dispatch path, while a
|
|
757
|
-
*
|
|
758
|
-
* workflow start. Names must be unique
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1794
|
+
* Scan every `.ts` file under `lunoraDir` for `cronJobs()` builder registrations
|
|
1795
|
+
* (`crons.interval(...)`, `crons.daily(...)`, `crons.cron(...)`, …) and lift them
|
|
1796
|
+
* into {@link CronJobIR}. Schedules are compiled to standard cron expressions;
|
|
1797
|
+
* function references are resolved to their `namespace:fn` dispatch path, while a
|
|
1798
|
+
* `workflows.NAME` / `agents.NAME` reference (or a bare identifier naming a
|
|
1799
|
+
* declared workflow) resolves to a durable workflow start. Names must be unique
|
|
1800
|
+
* across the project.
|
|
1801
|
+
*/
|
|
1802
|
+
declare const discoverCrons: (project: Project, lunoraDirectory: string, workflows?: ReadonlyArray<WorkflowIR>, agents?: ReadonlyArray<AgentIR>) => CronJobIR[];
|
|
1803
|
+
/** The only file a feature-flag provider may be declared in — mirrors `lunora/queues.ts`. */
|
|
1804
|
+
declare const FLAGS_FILENAME = "flags.ts";
|
|
1805
|
+
/**
|
|
1806
|
+
* Discover the feature-flag provider a project declares in `lunora/flags.ts`.
|
|
1807
|
+
* Returns `undefined` when the file doesn't exist (the app has no flags). The
|
|
1808
|
+
* read is metadata-only and lenient: codegen wires `ctx.flags` purely from the
|
|
1809
|
+
* file's *existence* (`run-codegen.ts`) and imports the real module for the
|
|
1810
|
+
* provider value — this IR exists solely so the config layer can reconcile the
|
|
1811
|
+
* wrangler `flagship` binding for the Flagship binding-mode provider. Anything
|
|
1812
|
+
* it can't read statically degrades to a `custom` provider (no binding), never
|
|
1813
|
+
* a thrown error.
|
|
1814
|
+
*/
|
|
1815
|
+
declare const discoverFlags: (project: Project, lunoraDirectory: string) => FlagsIR | undefined;
|
|
1816
|
+
/**
|
|
1817
|
+
* Scan all .ts files under `lunoraDir` (skipping `_generated/` and `schema.ts`)
|
|
1818
|
+
* for top-level `export const x = query/mutation/action({...})` registrations.
|
|
1819
|
+
*/
|
|
765
1820
|
declare const discoverFunctions: (project: Project, lunoraDirectory: string) => FunctionIR[];
|
|
766
1821
|
/**
|
|
767
|
-
* Scan all `.ts` files under `lunoraDir` (skipping `_generated/` and `schema.ts`)
|
|
768
|
-
* for `export const x = httpRoute.<verb>(...)…handler(...)` typed REST routes.
|
|
769
|
-
* These are the headline OpenAPI target: each becomes a real `paths` entry.
|
|
770
|
-
*/
|
|
1822
|
+
* Scan all `.ts` files under `lunoraDir` (skipping `_generated/` and `schema.ts`)
|
|
1823
|
+
* for `export const x = httpRoute.<verb>(...)…handler(...)` typed REST routes.
|
|
1824
|
+
* These are the headline OpenAPI target: each becomes a real `paths` entry.
|
|
1825
|
+
*/
|
|
771
1826
|
declare const discoverHttpRoutes: (project: Project, lunoraDirectory: string) => HttpRouteIR[];
|
|
772
1827
|
/**
|
|
773
|
-
* Discover `ctx.db.insert("table", …)` writes under the lunora source directory
|
|
774
|
-
* and attribute each to the exported function (and file) performing it. Calls
|
|
775
|
-
* with a non-literal table argument, or outside an exported declaration, are
|
|
776
|
-
* dropped (`table === ""` / no enclosing export).
|
|
777
|
-
*/
|
|
1828
|
+
* Discover `ctx.db.insert("table", …)` writes under the lunora source directory
|
|
1829
|
+
* and attribute each to the exported function (and file) performing it. Calls
|
|
1830
|
+
* with a non-literal table argument, or outside an exported declaration, are
|
|
1831
|
+
* dropped (`table === ""` / no enclosing export).
|
|
1832
|
+
*/
|
|
778
1833
|
declare const discoverInserts: (project: Project, lunoraDirectory: string) => InsertWriteIR[];
|
|
779
1834
|
/**
|
|
780
|
-
* Discover masking usage for every exported Lunora procedure under the lunora
|
|
781
|
-
* source directory — the column-level twin of `discoverRlsProcedures`. For each
|
|
782
|
-
* procedure, records whether its builder chain includes `.use(mask(...))`, which
|
|
783
|
-
* `(table, column)` pairs that mask declares, and which tables it reads/writes
|
|
784
|
-
* through `ctx.db`. Feeds the `mask_uncovered_pii_column` advisor lint.
|
|
785
|
-
*/
|
|
1835
|
+
* Discover masking usage for every exported Lunora procedure under the lunora
|
|
1836
|
+
* source directory — the column-level twin of `discoverRlsProcedures`. For each
|
|
1837
|
+
* procedure, records whether its builder chain includes `.use(mask(...))`, which
|
|
1838
|
+
* `(table, column)` pairs that mask declares, and which tables it reads/writes
|
|
1839
|
+
* through `ctx.db`. Feeds the `mask_uncovered_pii_column` advisor lint.
|
|
1840
|
+
*/
|
|
786
1841
|
declare const discoverMaskProcedures: (project: Project, lunoraDirectory: string) => MaskProcedureIR[];
|
|
787
1842
|
/**
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
|
|
793
|
-
* column)` with the first declaration winning, so a column masked by several
|
|
794
|
-
* procedures lists once — the same evidence the advisor lint uses.
|
|
795
|
-
*/
|
|
796
|
-
/**
|
|
797
|
-
* Scan all `.ts` files under `lunoraDir` for top-level
|
|
798
|
-
* `export const x = defineMigration({...})` declarations and lift them into
|
|
799
|
-
* {@link MigrationIR}. `id` must be a static string literal (it's the registry
|
|
800
|
-
* key); `table` is best-effort and left `""` when not a literal.
|
|
801
|
-
*/
|
|
1843
|
+
* Scan all `.ts` files under `lunoraDir` for top-level
|
|
1844
|
+
* `export const x = defineMigration({...})` declarations and lift them into
|
|
1845
|
+
* {@link MigrationIR}. `id` must be a static string literal (it's the registry
|
|
1846
|
+
* key); `table` is best-effort and left `""` when not a literal.
|
|
1847
|
+
*/
|
|
802
1848
|
declare const discoverMigrations: (project: Project, lunoraDirectory: string) => MigrationIR[];
|
|
803
|
-
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
|
|
1849
|
+
/** The only file custom mutators may be declared in — mirrors `lunora/queues.ts`. */
|
|
1850
|
+
declare const MUTATORS_FILENAME = "mutators.ts";
|
|
1851
|
+
/**
|
|
1852
|
+
* Discover every custom mutator the project declares: exported
|
|
1853
|
+
* `defineMutator()` calls in `lunora/mutators.ts`. Returns `[]` when the file
|
|
1854
|
+
* doesn't exist. Only the export binding is lifted — the runtime object carries
|
|
1855
|
+
* the authoritative `server` impl + `handler`, so codegen never evaluates the
|
|
1856
|
+
* body. The client `client` impl is split into the browser bundle separately.
|
|
1857
|
+
*/
|
|
1858
|
+
declare const discoverMutators: (project: Project, lunoraDirectory: string) => MutatorIR[];
|
|
1859
|
+
/**
|
|
1860
|
+
* Discover non-deterministic API calls (`Date.now`, `new Date()`, `Date()`,
|
|
1861
|
+
* `Math.random`, `crypto.randomUUID`, `crypto.getRandomValues` — including
|
|
1862
|
+
* `globalThis`/`self`/`window`-prefixed receivers — and `fetch`) lexically inside
|
|
1863
|
+
* the handler body of every exported `query(...)` / `mutation(...)` registration
|
|
1864
|
+
* under the lunora source directory — the `nondeterministic_query_mutation` lint
|
|
1865
|
+
* input. `action(...)` (and `stream(...)`) registrations are intentionally
|
|
1866
|
+
* skipped: actions run exactly once and may use ambient APIs freely.
|
|
1867
|
+
*
|
|
1868
|
+
* Traversal is scoped to the handler node (not the whole declaration), mirroring
|
|
1869
|
+
* how the auth-api / insert feeders attribute calls — so a call in a sibling
|
|
1870
|
+
* helper outside the handler, or in a nested `action(...)` passed elsewhere, is
|
|
1871
|
+
* not attributed to the query/mutation. One {@link NondeterministicCallIR} is
|
|
1872
|
+
* produced per call site.
|
|
1873
|
+
*/
|
|
818
1874
|
declare const discoverNondeterministicCalls: (project: Project, lunoraDirectory: string) => NondeterministicCallIR[];
|
|
819
1875
|
/**
|
|
820
|
-
* Discover `ctx.db.query("table")…` reads under the lunora source directory and
|
|
821
|
-
* reduce each to a {@link QueryReadIR}. Only reads that call `.filter()` are
|
|
822
|
-
* returned — an unfiltered read is never a `filter_without_index` candidate, so
|
|
823
|
-
* dropping the rest keeps the lint input small.
|
|
824
|
-
*/
|
|
1876
|
+
* Discover `ctx.db.query("table")…` reads under the lunora source directory and
|
|
1877
|
+
* reduce each to a {@link QueryReadIR}. Only reads that call `.filter()` are
|
|
1878
|
+
* returned — an unfiltered read is never a `filter_without_index` candidate, so
|
|
1879
|
+
* dropping the rest keeps the lint input small.
|
|
1880
|
+
*/
|
|
825
1881
|
declare const discoverQueries: (project: Project, lunoraDirectory: string) => QueryReadIR[];
|
|
826
|
-
/**
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
*
|
|
830
|
-
* `
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
*
|
|
837
|
-
|
|
1882
|
+
/** The only file queues may be declared in — mirrors `lunora/workflows.ts`. */
|
|
1883
|
+
declare const QUEUES_FILENAME = "queues.ts";
|
|
1884
|
+
/**
|
|
1885
|
+
* Discover every queue the project declares: exported `defineQueue()` calls in
|
|
1886
|
+
* `lunora/queues.ts`. Returns `[]` when the file doesn't exist. Only the
|
|
1887
|
+
* wrangler-relevant literals (`name`/`mode`/batch tuning) are read; the handler
|
|
1888
|
+
* body is runtime-only, so codegen never evaluates it.
|
|
1889
|
+
*/
|
|
1890
|
+
declare const discoverQueues: (project: Project, lunoraDirectory: string) => QueueIR[];
|
|
1891
|
+
/**
|
|
1892
|
+
* Discover `ctx.r2sql` accesses lexically inside the handler body of every
|
|
1893
|
+
* exported `query(...)` / `mutation(...)` registration under the lunora source
|
|
1894
|
+
* directory — the `r2sql_outside_action` lint input. `action(...)` (and
|
|
1895
|
+
* `stream(...)`) registrations are intentionally skipped: R2 SQL is the
|
|
1896
|
+
* external, non-reactive surface that belongs in actions.
|
|
1897
|
+
*
|
|
1898
|
+
* Traversal is scoped to the handler node (not the whole declaration), mirroring
|
|
1899
|
+
* `discoverNondeterministicCalls` — so a `ctx.r2sql` touch in a sibling helper
|
|
1900
|
+
* outside the handler is not attributed to the query/mutation. One
|
|
1901
|
+
* {@link R2sqlCallIR} is produced per access site.
|
|
1902
|
+
*/
|
|
838
1903
|
declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => R2sqlCallIR[];
|
|
839
1904
|
declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string) => RlsProcedureIR[];
|
|
840
1905
|
/**
|
|
841
|
-
* Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
|
|
842
|
-
* every statically-discovered `(table, on, procedure)` policy entry plus every
|
|
843
|
-
* role declared via `rls(policies, { roles })`. Walks the same builder chains as
|
|
844
|
-
* {@link discoverRlsProcedures} but extracts the richer `{ on }` operation +
|
|
845
|
-
* role/permission shape rather than the lint's table-name set.
|
|
846
|
-
*
|
|
847
|
-
* Only the **builder** form (`c.use(rls(...)).query(...)`) can declare policies,
|
|
848
|
-
* so bare-factory procedures contribute nothing. The `when` predicate is never
|
|
849
|
-
* read — it's an opaque JS closure whose logic belongs in code, not the UI.
|
|
850
|
-
* Roles are deduped by name (first declaration wins) so a role registered on
|
|
851
|
-
* several procedures lists once.
|
|
852
|
-
*/
|
|
1906
|
+
* Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
|
|
1907
|
+
* every statically-discovered `(table, on, procedure)` policy entry plus every
|
|
1908
|
+
* role declared via `rls(policies, { roles })`. Walks the same builder chains as
|
|
1909
|
+
* {@link discoverRlsProcedures} but extracts the richer `{ on }` operation +
|
|
1910
|
+
* role/permission shape rather than the lint's table-name set.
|
|
1911
|
+
*
|
|
1912
|
+
* Only the **builder** form (`c.use(rls(...)).query(...)`) can declare policies,
|
|
1913
|
+
* so bare-factory procedures contribute nothing. The `when` predicate is never
|
|
1914
|
+
* read — it's an opaque JS closure whose logic belongs in code, not the UI.
|
|
1915
|
+
* Roles are deduped by name (first declaration wins) so a role registered on
|
|
1916
|
+
* several procedures lists once.
|
|
1917
|
+
*/
|
|
853
1918
|
declare const discoverRlsMetadata: (project: Project, lunoraDirectory: string) => RlsMetadataIR;
|
|
854
1919
|
/**
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
*/
|
|
1920
|
+
* Which sandbox tools a project imports from `@lunora/agent` (main entry or the
|
|
1921
|
+
* `/sandbox` subpath), detected by NAMED value import. Drives two things:
|
|
1922
|
+
* registering the `sandbox:invoke` dispatcher (either tool) and provisioning the
|
|
1923
|
+
* `BROWSER` wrangler binding (`browserTool` — the browser op runs on
|
|
1924
|
+
* `ctx.browser` inside the dispatcher).
|
|
1925
|
+
*/
|
|
1926
|
+
interface SandboxUsage {
|
|
1927
|
+
/** `import { browserTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
|
|
1928
|
+
usesSandboxBrowser: boolean;
|
|
1929
|
+
/** `import { containerTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
|
|
1930
|
+
usesSandboxContainer: boolean;
|
|
1931
|
+
}
|
|
1932
|
+
declare const discoverSandboxUsage: (project: Project, lunoraDirectory: string) => SandboxUsage;
|
|
1933
|
+
/**
|
|
1934
|
+
* Load `<projectRoot>/lunora/schema.ts`, find `defineSchema({...})`, and
|
|
1935
|
+
* return a structural IR. Throws if the file or call cannot be found.
|
|
1936
|
+
*/
|
|
1937
|
+
declare const discoverSchema: (project: Project, schemaPath: string, projectRoot?: string) => SchemaIR;
|
|
1938
|
+
/** The only file shapes may be declared in — mirrors `lunora/queues.ts`. */
|
|
1939
|
+
declare const SHAPES_FILENAME = "shapes.ts";
|
|
1940
|
+
/**
|
|
1941
|
+
* Discover every replication shape the project declares: exported
|
|
1942
|
+
* `defineShape()` calls in `lunora/shapes.ts`. Returns `[]` when the file
|
|
1943
|
+
* doesn't exist. Only the export binding is lifted — the runtime object carries
|
|
1944
|
+
* the authoritative `table`/`columns`/`compileWhere`, so codegen never
|
|
1945
|
+
* evaluates the predicate.
|
|
1946
|
+
*/
|
|
1947
|
+
declare const discoverShapes: (project: Project, lunoraDirectory: string) => ShapeIR[];
|
|
1948
|
+
/**
|
|
1949
|
+
* Aggregate the schema-wide storage-rule metadata the studio's inspector reads:
|
|
1950
|
+
* every statically-discovered `(bucket, on, prefix, procedure)` entry across all
|
|
1951
|
+
* `.use(storageRules(...))` chains. Only the builder form can declare rules, so
|
|
1952
|
+
* bare-factory procedures contribute nothing.
|
|
1953
|
+
*/
|
|
865
1954
|
declare const discoverStorageRulesMetadata: (project: Project, lunoraDirectory: string) => StorageRulesMetadataIR;
|
|
866
1955
|
/** The only file workflows may be declared in — mirrors `lunora/containers.ts`. */
|
|
867
1956
|
declare const WORKFLOWS_FILENAME = "workflows.ts";
|
|
868
1957
|
/**
|
|
869
|
-
* Discover every workflow the project declares: exported `defineWorkflow()`
|
|
870
|
-
* calls in `lunora/workflows.ts`. Returns `[]` when the file doesn't exist. The
|
|
871
|
-
* only wrangler-relevant literal is the optional `name` override; the workflow
|
|
872
|
-
* body is runtime-only, so codegen never evaluates it.
|
|
873
|
-
*/
|
|
1958
|
+
* Discover every workflow the project declares: exported `defineWorkflow()`
|
|
1959
|
+
* calls in `lunora/workflows.ts`. Returns `[]` when the file doesn't exist. The
|
|
1960
|
+
* only wrangler-relevant literal is the optional `name` override; the workflow
|
|
1961
|
+
* body is runtime-only, so codegen never evaluates it.
|
|
1962
|
+
*/
|
|
874
1963
|
declare const discoverWorkflows: (project: Project, lunoraDirectory: string) => WorkflowIR[];
|
|
875
1964
|
declare const GENERATED_HEADER = "// GENERATED by @lunora/codegen — do not edit.\n// Run `lunora codegen` to regenerate.\n\n";
|
|
876
1965
|
/** Emit `_generated/dataModel.ts` — `Doc<"name">` + `Id<"name">` for every table. */
|
|
877
1966
|
declare const emitDataModel: (schema: SchemaIR, useUmbrella?: boolean) => string;
|
|
878
1967
|
/**
|
|
879
|
-
* Emit `_generated/api.ts` — the typed `api.*` registry (public functions), the
|
|
880
|
-
* `internal.*` registry, and (when the project declares
|
|
881
|
-
* `workflows.*` reference
|
|
882
|
-
* at runtime (the `__lunoraRef` is identical); visibility is enforced
|
|
883
|
-
* server-side at dispatch, not in the reference. Splitting the *types* keeps
|
|
884
|
-
* internal functions off the client-facing `api` surface.
|
|
885
|
-
*/
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1968
|
+
* Emit `_generated/api.ts` — the typed `api.*` registry (public functions), the
|
|
1969
|
+
* `internal.*` registry, and (when the project declares them) the typed
|
|
1970
|
+
* `workflows.*` / `agents.*` scheduler-target reference objects. `api`/`internal` are the same `anyApi` proxy
|
|
1971
|
+
* at runtime (the `__lunoraRef` is identical); visibility is enforced
|
|
1972
|
+
* server-side at dispatch, not in the reference. Splitting the *types* keeps
|
|
1973
|
+
* internal functions off the client-facing `api` surface.
|
|
1974
|
+
*/
|
|
1975
|
+
interface EmitApiOptions {
|
|
1976
|
+
agents?: ReadonlyArray<AgentIR>;
|
|
1977
|
+
functions: ReadonlyArray<FunctionIR>;
|
|
1978
|
+
/** Typed REST routes; only `.stream()` (SSE) routes emit a `httpStreams.*` reference. */
|
|
1979
|
+
httpRoutes?: ReadonlyArray<HttpRouteIR>;
|
|
1980
|
+
useUmbrella?: boolean;
|
|
1981
|
+
workflows?: ReadonlyArray<WorkflowIR>;
|
|
1982
|
+
}
|
|
1983
|
+
declare const emitApi: (options: EmitApiOptions) => string;
|
|
1984
|
+
/**
|
|
1985
|
+
* Emit `_generated/collections.ts` — one TanStack DB collection factory per
|
|
1986
|
+
* `defineShape` in `lunora/shapes.ts` (the local-first partial-replication
|
|
1987
|
+
* surface). Each factory builds a live collection that syncs its shape's rowset
|
|
1988
|
+
* through the client's poke protocol (`subscribeShape`), so an app feeds the
|
|
1989
|
+
* result straight to `useLiveQuery`.
|
|
1990
|
+
*
|
|
1991
|
+
* Returns `""` (so `writeIfPresent` skips the file) unless the project both
|
|
1992
|
+
* declares shapes AND installs `@lunora/db` — the add-on that ships
|
|
1993
|
+
* `lunoraCollectionOptions`. `@lunora/db` stays a scoped install even under the
|
|
1994
|
+
* `lunorash` umbrella (an opt-in add-on, like `@lunora/auth`), so its import is
|
|
1995
|
+
* always `@lunora/db/collections`; only the in-umbrella `@lunora/client` import
|
|
1996
|
+
* is remapped to `lunorash/client`.
|
|
1997
|
+
*/
|
|
1998
|
+
declare const emitCollections: (shapes: ReadonlyArray<ShapeIR>, hasDatabase: boolean, useUmbrella?: boolean) => string;
|
|
897
1999
|
interface EmitServerOptions {
|
|
2000
|
+
/** Agents declared via `defineAgent` exports — wires the typed `ctx.agents` producers onto Mutation/Action contexts. */
|
|
2001
|
+
agents?: ReadonlyArray<AgentIR>;
|
|
898
2002
|
containers?: ReadonlyArray<ContainerIR>;
|
|
2003
|
+
/**
|
|
2004
|
+
* The single `defineEnv(...)` contract declared in `lunora/env.ts`. When
|
|
2005
|
+
* present, `ctx.env` is typed as the validated `InferEnv` shape (recovered
|
|
2006
|
+
* via `ReturnType` over the accessor's `typeof`). `undefined` leaves `ctx.env`
|
|
2007
|
+
* the base optional binding record — byte-identical to today.
|
|
2008
|
+
*/
|
|
2009
|
+
env?: EnvIR;
|
|
2010
|
+
/**
|
|
2011
|
+
* A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access
|
|
2012
|
+
* facade (`@lunora/cloudflare-access/context`) onto every ctx. Distinct from
|
|
2013
|
+
* `emitApp`'s `hasAccess` (which gates the worker's `.access()` resolveIdentity
|
|
2014
|
+
* method); this one gates the per-request `ctx.access` read surface.
|
|
2015
|
+
*/
|
|
2016
|
+
hasAccessFacade?: boolean;
|
|
899
2017
|
hasAi?: boolean;
|
|
900
|
-
/** A `lunora/` source uses `@lunora/analytics` / `ctx.analytics` — wires the write helper onto every ctx. */
|
|
2018
|
+
/** A `lunora/` source uses `@lunora/bindings/analytics` / `ctx.analytics` — wires the write helper onto every ctx. */
|
|
901
2019
|
hasAnalytics?: boolean;
|
|
902
2020
|
/** A `lunora/` source uses `@lunora/browser` / `ctx.browser` — wires `ctx.browser` onto ActionCtx only. */
|
|
903
2021
|
hasBrowser?: boolean;
|
|
2022
|
+
/** The project declares `lunora/flags.ts` — wires `ctx.flags` (OpenFeature) onto every ctx. */
|
|
2023
|
+
hasFlags?: boolean;
|
|
904
2024
|
/** A `lunora/` source uses `@lunora/hyperdrive` / `ctx.sql` — wires `ctx.sql` onto ActionCtx only. */
|
|
905
2025
|
hasHyperdrive?: boolean;
|
|
906
|
-
/** A `lunora/` source uses `@lunora/images` / `ctx.images` — wires `ctx.images` onto ActionCtx only. */
|
|
2026
|
+
/** A `lunora/` source uses `@lunora/bindings/images` / `ctx.images` — wires `ctx.images` onto ActionCtx only. */
|
|
907
2027
|
hasImages?: boolean;
|
|
908
|
-
/** A `lunora/` source uses `@lunora/kv` / `ctx.kv` — wires `ctx.kv` onto every ctx. */
|
|
2028
|
+
/** A `lunora/` source uses `@lunora/bindings/kv` / `ctx.kv` — wires `ctx.kv` onto every ctx. */
|
|
909
2029
|
hasKv?: boolean;
|
|
910
2030
|
hasPayments?: boolean;
|
|
911
|
-
/** A `lunora/` source uses `@lunora/pipelines` / `ctx.pipelines` — wires `ctx.pipelines` onto ActionCtx only. */
|
|
2031
|
+
/** A `lunora/` source uses `@lunora/bindings/pipelines` / `ctx.pipelines` — wires `ctx.pipelines` onto ActionCtx only. */
|
|
912
2032
|
hasPipelines?: boolean;
|
|
913
|
-
/** A `lunora/` source uses `@lunora/r2sql` / `ctx.r2sql` — wires `ctx.r2sql` onto ActionCtx only. */
|
|
2033
|
+
/** A `lunora/` source uses `@lunora/bindings/r2sql` / `ctx.r2sql` — wires `ctx.r2sql` onto ActionCtx only. */
|
|
914
2034
|
hasR2sql?: boolean;
|
|
2035
|
+
/** A `lunora/` source uses `@lunora/x402/pay` / `ctx.x402` — wires the agent-wallet pay rail onto ActionCtx only. */
|
|
2036
|
+
hasX402?: boolean;
|
|
2037
|
+
/**
|
|
2038
|
+
* The single `defineIdentity(...)` claim contract declared in
|
|
2039
|
+
* `lunora/identity.ts` (Plan 080). When present, `ctx.auth.getIdentity()`,
|
|
2040
|
+
* the RLS policy `ctx.auth.identity`, and the shard-authorization hooks
|
|
2041
|
+
* narrow to the declared shape (recovered via `InferIdentity` over the
|
|
2042
|
+
* contract's `typeof`). `undefined` keeps the identity an untyped bag —
|
|
2043
|
+
* byte-identical to today.
|
|
2044
|
+
*/
|
|
2045
|
+
identity?: IdentityIR;
|
|
2046
|
+
/** Queues declared via `defineQueue` exports — wires the typed `ctx.queues` producers onto Mutation/Action contexts. */
|
|
2047
|
+
queues?: ReadonlyArray<QueueIR>;
|
|
915
2048
|
schema?: SchemaIR;
|
|
916
2049
|
storageRuleBuckets?: ReadonlyArray<string>;
|
|
917
2050
|
/** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
|
|
918
2051
|
useUmbrella?: boolean;
|
|
919
2052
|
workflows?: ReadonlyArray<WorkflowIR>;
|
|
920
2053
|
}
|
|
921
|
-
declare const emitServer: ({
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
*
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
*
|
|
949
|
-
|
|
950
|
-
* (`@lunora/container/do`) constructed with the user's definition object. The
|
|
951
|
-
* worker entry must re-export these classes: wrangler requires every
|
|
952
|
-
* `containers[].class_name` to be exported by the deployed worker. Returns ""
|
|
953
|
-
* when the project declares no containers (the file is not written then).
|
|
954
|
-
*/
|
|
955
|
-
declare const emitContainers: (containers: ReadonlyArray<ContainerIR>) => string;
|
|
956
|
-
/**
|
|
957
|
-
* Emit `_generated/workflows.ts` — one `WorkflowEntrypoint` class per
|
|
958
|
-
* `defineWorkflow` export, each a thin subclass of `LunoraWorkflow`
|
|
959
|
-
* (`@lunora/workflow/do`) constructed with the user's definition object. The
|
|
960
|
-
* worker entry must re-export these classes: wrangler requires every
|
|
961
|
-
* `workflows[].class_name` to be exported by the deployed worker. Returns ""
|
|
962
|
-
* when the project declares no workflows (the file is not written then).
|
|
963
|
-
*/
|
|
2054
|
+
declare const emitServer: ({ agents, containers, env, hasAccessFacade, hasAi, hasAnalytics, hasBrowser, hasFlags, hasHyperdrive, hasImages, hasKv, hasPayments, hasPipelines, hasR2sql, hasX402, identity, queues, schema, storageRuleBuckets, useUmbrella, workflows }?: EmitServerOptions) => string;
|
|
2055
|
+
interface EmitFunctionsOptions {
|
|
2056
|
+
agents?: ReadonlyArray<AgentIR>;
|
|
2057
|
+
functions: ReadonlyArray<FunctionIR>;
|
|
2058
|
+
migrations?: ReadonlyArray<MigrationIR>;
|
|
2059
|
+
mutators?: ReadonlyArray<MutatorIR>;
|
|
2060
|
+
shapes?: ReadonlyArray<ShapeIR>;
|
|
2061
|
+
/** Import of a sandbox tool (`browserTool`/`containerTool`) auto-registers the `sandbox:invoke` action. */
|
|
2062
|
+
usesSandbox?: boolean;
|
|
2063
|
+
useUmbrella?: boolean;
|
|
2064
|
+
}
|
|
2065
|
+
declare const emitFunctions: (options: EmitFunctionsOptions) => string;
|
|
2066
|
+
/**
|
|
2067
|
+
* Emit `_generated/containers.ts` — one container-enabled Durable Object class
|
|
2068
|
+
* per `defineContainer` export, each a thin subclass of `LunoraContainer`
|
|
2069
|
+
* (`@lunora/container/do`) constructed with the user's definition object. The
|
|
2070
|
+
* worker entry must re-export these classes: wrangler requires every
|
|
2071
|
+
* `containers[].class_name` to be exported by the deployed worker. Returns ""
|
|
2072
|
+
* when the project declares no containers (the file is not written then).
|
|
2073
|
+
*/
|
|
2074
|
+
declare const emitContainers: (containers: ReadonlyArray<ContainerIR>, jurisdiction?: JurisdictionIR) => string;
|
|
2075
|
+
/**
|
|
2076
|
+
* Emit `_generated/workflows.ts` — one `WorkflowEntrypoint` class per
|
|
2077
|
+
* `defineWorkflow` export, each a thin subclass of `LunoraWorkflow`
|
|
2078
|
+
* (`@lunora/workflow/do`) constructed with the user's definition object. The
|
|
2079
|
+
* worker entry must re-export these classes: wrangler requires every
|
|
2080
|
+
* `workflows[].class_name` to be exported by the deployed worker. Returns ""
|
|
2081
|
+
* when the project declares no workflows (the file is not written then).
|
|
2082
|
+
*/
|
|
964
2083
|
declare const emitWorkflows: (workflows: ReadonlyArray<WorkflowIR>) => string;
|
|
2084
|
+
/**
|
|
2085
|
+
* Emit `_generated/agents.ts` — one `WorkflowEntrypoint` class per `defineAgent`
|
|
2086
|
+
* export, each a thin subclass of `LunoraWorkflow` (`@lunora/workflow/do`)
|
|
2087
|
+
* constructed with the compiled agent tool-loop (`compileAgentWorkflow`). Like
|
|
2088
|
+
* `_generated/workflows.ts`, the worker entry must re-export these classes:
|
|
2089
|
+
* wrangler requires every `workflows[].class_name` to be exported by the
|
|
2090
|
+
* deployed worker. Returns "" when the project declares no agents (the file is
|
|
2091
|
+
* not written then).
|
|
2092
|
+
*/
|
|
2093
|
+
declare const emitAgents: (agents: ReadonlyArray<AgentIR>) => string;
|
|
965
2094
|
interface EmitShardOptions {
|
|
966
2095
|
advisories?: ReadonlyArray<Finding>;
|
|
2096
|
+
/** Agents declared via `defineAgent` exports in `lunora/agents.ts` — wires the typed `ctx.agents` producers. */
|
|
2097
|
+
agents?: ReadonlyArray<AgentIR>;
|
|
967
2098
|
containers?: ReadonlyArray<ContainerIR>;
|
|
2099
|
+
/** The single `defineEnv(...)` contract declared in `lunora/env.ts` — applies the accessor to the worker `env` to populate `ctx.env`. */
|
|
2100
|
+
env?: EnvIR;
|
|
2101
|
+
/** Statically-discovered `ctx.flags.<type>("key")` reads — the studio Flags page + reactive evaluation iterate these. */
|
|
2102
|
+
flagKeys?: ReadonlyArray<{
|
|
2103
|
+
key: string;
|
|
2104
|
+
type: "boolean" | "number" | "object" | "string";
|
|
2105
|
+
}>;
|
|
2106
|
+
/** A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access facade onto every ctx. */
|
|
2107
|
+
hasAccessFacade?: boolean;
|
|
968
2108
|
hasAi?: boolean;
|
|
969
2109
|
/** A `lunora/` source reads `ctx.analytics` — wires the Analytics Engine write helper onto every ctx. */
|
|
970
2110
|
hasAnalytics?: boolean;
|
|
971
2111
|
/** A `lunora/` source reads `ctx.browser` — wires `ctx.browser` onto the ActionCtx only. */
|
|
972
2112
|
hasBrowser?: boolean;
|
|
2113
|
+
/** The project declares `lunora/flags.ts` — wires `ctx.flags` (OpenFeature) onto every ctx. */
|
|
2114
|
+
hasFlags?: boolean;
|
|
973
2115
|
/** A `lunora/` source reads `ctx.sql` (Hyperdrive) — wires `ctx.sql` onto the ActionCtx only. */
|
|
974
2116
|
hasHyperdrive?: boolean;
|
|
975
2117
|
/** A `lunora/` source reads `ctx.images` — wires `ctx.images` onto the ActionCtx only. */
|
|
@@ -977,98 +2119,102 @@ interface EmitShardOptions {
|
|
|
977
2119
|
/** A `lunora/` source reads `ctx.kv` — wires `ctx.kv` onto every ctx. */
|
|
978
2120
|
hasKv?: boolean;
|
|
979
2121
|
hasPayments?: boolean;
|
|
2122
|
+
/** A `lunora/` source reads `ctx.pipelines` — wires `ctx.pipelines` onto the ActionCtx only. */
|
|
2123
|
+
hasPipelines?: boolean;
|
|
980
2124
|
/** A `lunora/` source reads `ctx.r2sql` (R2 SQL) — wires `ctx.r2sql` onto the ActionCtx only. */
|
|
981
2125
|
hasR2sql?: boolean;
|
|
2126
|
+
/** A `lunora/` source reads `ctx.x402` — wires the agent-wallet pay rail onto the ActionCtx only. */
|
|
2127
|
+
hasX402?: boolean;
|
|
982
2128
|
maskMetadata?: MaskMetadataIR;
|
|
2129
|
+
/** Custom mutators declared via `defineMutator` in `lunora/mutators.ts` — wires the `isCustomMutator` push-protocol override. */
|
|
2130
|
+
mutators?: ReadonlyArray<MutatorIR>;
|
|
2131
|
+
/** Queues declared via `defineQueue` exports in `lunora/queues.ts` — wires the typed `ctx.queues` producers. */
|
|
2132
|
+
queues?: ReadonlyArray<QueueIR>;
|
|
983
2133
|
rlsMetadata?: RlsMetadataIR;
|
|
984
2134
|
schema: SchemaIR;
|
|
2135
|
+
/** Replication shapes declared via `defineShape` in `lunora/shapes.ts` — wires the `resolveShape` subscription override. */
|
|
2136
|
+
shapes?: ReadonlyArray<ShapeIR>;
|
|
985
2137
|
storageRules?: StorageRulesMetadataIR;
|
|
986
2138
|
studioFeatures?: StudioFeaturesResult;
|
|
987
2139
|
/** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
|
|
988
2140
|
useUmbrella?: boolean;
|
|
989
2141
|
workflows?: ReadonlyArray<WorkflowIR>;
|
|
990
2142
|
}
|
|
991
|
-
declare const emitShard: ({
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
maskMetadata,
|
|
1003
|
-
rlsMetadata,
|
|
1004
|
-
schema,
|
|
1005
|
-
storageRules,
|
|
1006
|
-
studioFeatures,
|
|
1007
|
-
useUmbrella,
|
|
1008
|
-
workflows
|
|
1009
|
-
}: EmitShardOptions) => string;
|
|
1010
|
-
/**
|
|
1011
|
-
* Emit drizzle `sqliteTable` definitions for the project schema, split into
|
|
1012
|
-
* `global` (D1-backed) and `shard` (DO-SQLite-backed) buckets. Tables marked
|
|
1013
|
-
* `.global()` go in the global file; everything else (default root + `.shardBy()`)
|
|
1014
|
-
* goes in the shard file.
|
|
1015
|
-
*
|
|
1016
|
-
* `searchIndexes` are intentionally not emitted — drizzle has no `sqliteTable`
|
|
1017
|
-
* abstraction for FTS5 virtual tables. FTS plumbing is handled by the runtime
|
|
1018
|
-
* outside of drizzle.
|
|
1019
|
-
*/
|
|
2143
|
+
declare const emitShard: ({ advisories, agents, containers, env, flagKeys, hasAccessFacade, hasAi, hasAnalytics, hasBrowser, hasFlags, hasHyperdrive, hasImages, hasKv, hasPayments, hasPipelines, hasR2sql, hasX402, maskMetadata, mutators, queues, rlsMetadata, schema, shapes, storageRules, studioFeatures, useUmbrella, workflows }: EmitShardOptions) => string;
|
|
2144
|
+
/**
|
|
2145
|
+
* Emit drizzle `sqliteTable` definitions for the project schema, split into
|
|
2146
|
+
* `global` (D1-backed) and `shard` (DO-SQLite-backed) buckets. Tables marked
|
|
2147
|
+
* `.global()` go in the global file; everything else (default root + `.shardBy()`)
|
|
2148
|
+
* goes in the shard file.
|
|
2149
|
+
*
|
|
2150
|
+
* `searchIndexes` are intentionally not emitted — drizzle has no `sqliteTable`
|
|
2151
|
+
* abstraction for FTS5 virtual tables. FTS plumbing is handled by the runtime
|
|
2152
|
+
* outside of drizzle.
|
|
2153
|
+
*/
|
|
1020
2154
|
declare const emitDrizzleSchema: (schema: SchemaIR, useUmbrella?: boolean) => {
|
|
1021
2155
|
global: string;
|
|
1022
2156
|
shard: string;
|
|
1023
2157
|
};
|
|
1024
2158
|
/**
|
|
1025
|
-
* Emit `_generated/crons.ts` from the discovered cron jobs.
|
|
1026
|
-
*
|
|
1027
|
-
* `LUNORA_CRON_TRIGGERS` is the deduplicated schedule array — what lands in
|
|
1028
|
-
* wrangler's `triggers.crons` (the vite plugin reconciles it into
|
|
1029
|
-
* `wrangler.jsonc`, and {@link emitWranglerCronTriggers} renders the same list
|
|
1030
|
-
* for the CLI / docs).
|
|
1031
|
-
*
|
|
1032
|
-
* `LUNORA_CRONS` is the dispatcher map keyed by cron expression, each value a
|
|
1033
|
-
* list of `{ name, functionPath, args }`. Cloudflare's `scheduled()` handler
|
|
1034
|
-
* receives only the cron string, so multiple jobs sharing one expression must
|
|
1035
|
-
* all fire — hence a list per key rather than a single entry.
|
|
1036
|
-
*
|
|
1037
|
-
* Jobs arrive pre-sorted by name (deterministic output); the trigger array
|
|
1038
|
-
* preserves first-seen order of distinct expressions.
|
|
1039
|
-
*
|
|
1040
|
-
* Cloudflare caps a Worker at **3 Cron Triggers** (i.e. 3 distinct cron
|
|
1041
|
-
* expressions). Because the dispatcher fires every job sharing an expression,
|
|
1042
|
-
* many jobs can ride a single trigger — only the count of *distinct* schedules
|
|
1043
|
-
* matters. `lunora codegen` warns when that count exceeds the limit; for
|
|
1044
|
-
* finer-grained scheduling use Durable Object alarms (`@lunora/scheduler`),
|
|
1045
|
-
* which have no such cap.
|
|
1046
|
-
*/
|
|
2159
|
+
* Emit `_generated/crons.ts` from the discovered cron jobs.
|
|
2160
|
+
*
|
|
2161
|
+
* `LUNORA_CRON_TRIGGERS` is the deduplicated schedule array — what lands in
|
|
2162
|
+
* wrangler's `triggers.crons` (the vite plugin reconciles it into
|
|
2163
|
+
* `wrangler.jsonc`, and {@link emitWranglerCronTriggers} renders the same list
|
|
2164
|
+
* for the CLI / docs).
|
|
2165
|
+
*
|
|
2166
|
+
* `LUNORA_CRONS` is the dispatcher map keyed by cron expression, each value a
|
|
2167
|
+
* list of `{ name, functionPath, args }`. Cloudflare's `scheduled()` handler
|
|
2168
|
+
* receives only the cron string, so multiple jobs sharing one expression must
|
|
2169
|
+
* all fire — hence a list per key rather than a single entry.
|
|
2170
|
+
*
|
|
2171
|
+
* Jobs arrive pre-sorted by name (deterministic output); the trigger array
|
|
2172
|
+
* preserves first-seen order of distinct expressions.
|
|
2173
|
+
*
|
|
2174
|
+
* Cloudflare caps a Worker at **3 Cron Triggers** (i.e. 3 distinct cron
|
|
2175
|
+
* expressions). Because the dispatcher fires every job sharing an expression,
|
|
2176
|
+
* many jobs can ride a single trigger — only the count of *distinct* schedules
|
|
2177
|
+
* matters. `lunora codegen` warns when that count exceeds the limit; for
|
|
2178
|
+
* finer-grained scheduling use Durable Object alarms (`@lunora/scheduler`),
|
|
2179
|
+
* which have no such cap.
|
|
2180
|
+
*/
|
|
1047
2181
|
declare const emitCrons: (crons: ReadonlyArray<CronJobIR>) => string;
|
|
1048
2182
|
/**
|
|
1049
|
-
* Render `_generated/vectors.ts` — the static registry of every vector index
|
|
1050
|
-
* declared in `schema.ts` (inline `.vectorize()` columns + standalone
|
|
1051
|
-
* `defineVectorIndex()` definitions).
|
|
1052
|
-
*
|
|
1053
|
-
* Cloudflare Vectorize exposes no way to enumerate an account's indexes at
|
|
1054
|
-
* runtime — a binding can `describe()` itself but the worker can't ask "which
|
|
1055
|
-
* indexes exist". So this generated array is the source of truth the studio's
|
|
1056
|
-
* vector browser lists, and the worker's admin route pairs each entry with its
|
|
1057
|
-
* live `describe()` stats. Entries are sorted by name for deterministic output.
|
|
1058
|
-
*/
|
|
2183
|
+
* Render `_generated/vectors.ts` — the static registry of every vector index
|
|
2184
|
+
* declared in `schema.ts` (inline `.vectorize()` columns + standalone
|
|
2185
|
+
* `defineVectorIndex()` definitions).
|
|
2186
|
+
*
|
|
2187
|
+
* Cloudflare Vectorize exposes no way to enumerate an account's indexes at
|
|
2188
|
+
* runtime — a binding can `describe()` itself but the worker can't ask "which
|
|
2189
|
+
* indexes exist". So this generated array is the source of truth the studio's
|
|
2190
|
+
* vector browser lists, and the worker's admin route pairs each entry with its
|
|
2191
|
+
* live `describe()` stats. Entries are sorted by name for deterministic output.
|
|
2192
|
+
*/
|
|
1059
2193
|
declare const emitVectors: (vectorIndexes: ReadonlyArray<VectorIndexIR>) => string;
|
|
1060
2194
|
/**
|
|
1061
|
-
* Render the deduplicated cron schedules as a JSON fragment suitable for
|
|
1062
|
-
* splicing into `wrangler.jsonc`'s `triggers.crons`. The vite plugin uses this
|
|
1063
|
-
* (plus the parsed wrangler config) to reconcile generated triggers without the
|
|
1064
|
-
* user hand-editing the file.
|
|
1065
|
-
*/
|
|
2195
|
+
* Render the deduplicated cron schedules as a JSON fragment suitable for
|
|
2196
|
+
* splicing into `wrangler.jsonc`'s `triggers.crons`. The vite plugin uses this
|
|
2197
|
+
* (plus the parsed wrangler config) to reconcile generated triggers without the
|
|
2198
|
+
* user hand-editing the file.
|
|
2199
|
+
*/
|
|
1066
2200
|
declare const emitWranglerCronTriggers: (crons: ReadonlyArray<CronJobIR>) => string[];
|
|
1067
2201
|
/** Which capability methods the generated `defineApp` builder exposes — one flag per package-backed feature the app actually uses. */
|
|
1068
2202
|
interface EmitAppOptions {
|
|
2203
|
+
/**
|
|
2204
|
+
* Inbound-email agents (`defineAgent({ onEmail })`) → wire the worker's
|
|
2205
|
+
* top-level `email()` handler to `dispatchAgentEmail(...)` (from
|
|
2206
|
+
* `@lunora/agent/inbound`), so received mail starts a durable run. Empty/absent
|
|
2207
|
+
* ⇒ no wiring, byte-identical output for email-free (and agent-free) projects.
|
|
2208
|
+
*/
|
|
2209
|
+
emailAgents?: ReadonlyArray<{
|
|
2210
|
+
bindingName: string;
|
|
2211
|
+
exportName: string;
|
|
2212
|
+
}>;
|
|
2213
|
+
/** App depends on `@lunora/cloudflare-access` → emit `.access()` (wire the Cloudflare Access `resolveIdentity`, composed ahead of `@lunora/auth` when both are present). */
|
|
2214
|
+
hasAccess: boolean;
|
|
1069
2215
|
/** App uses `@lunora/ai` / `ctx.ai` → emit `.ai()` (override the Workers AI binding backing `ctx.ai`). */
|
|
1070
2216
|
hasAi: boolean;
|
|
1071
|
-
/** App uses `@lunora/analytics` / `ctx.analytics` → emit `.analytics()` (override the dataset backing `ctx.analytics`). */
|
|
2217
|
+
/** App uses `@lunora/bindings/analytics` / `ctx.analytics` → emit `.analytics()` (override the dataset backing `ctx.analytics`). */
|
|
1072
2218
|
hasAnalytics: boolean;
|
|
1073
2219
|
/** App depends on `@lunora/auth` → emit `.auth()` + the lazy build/migrate dance. */
|
|
1074
2220
|
hasAuth: boolean;
|
|
@@ -1082,13 +2228,15 @@ interface EmitAppOptions {
|
|
|
1082
2228
|
hasHyperdrive: boolean;
|
|
1083
2229
|
/** Schema declares **Hyperdrive-backed** `.global({ backend: "hyperdrive" })` tables → emit `.hyperdriveGlobal()` (reactive Postgres/MySQL ctx-db over Hyperdrive). */
|
|
1084
2230
|
hasHyperdriveGlobal: boolean;
|
|
1085
|
-
/** App uses `@lunora/images` / `ctx.images` → emit `.images()`. */
|
|
2231
|
+
/** App uses `@lunora/bindings/images` / `ctx.images` → emit `.images()`. */
|
|
1086
2232
|
hasImages: boolean;
|
|
1087
|
-
/** App uses `@lunora/kv` / `ctx.kv` → emit `.kv()`. */
|
|
2233
|
+
/** App uses `@lunora/bindings/kv` / `ctx.kv` → emit `.kv()`. */
|
|
1088
2234
|
hasKv: boolean;
|
|
1089
2235
|
/** App uses `@lunora/payment` / `ctx.payments` → emit `.payment()`. */
|
|
1090
2236
|
hasPayments: boolean;
|
|
1091
|
-
/** App
|
|
2237
|
+
/** App declares push queues (`defineQueue`) → wire `LUNORA_QUEUE_REGISTRY` into the worker's `queue()` consumer entry. */
|
|
2238
|
+
hasQueue: boolean;
|
|
2239
|
+
/** App uses `@lunora/bindings/r2sql` / `ctx.r2sql` → emit `.r2sql()`. */
|
|
1092
2240
|
hasR2sql: boolean;
|
|
1093
2241
|
/** App imports `@lunora/scheduler` / declares crons → emit `.scheduler()`. */
|
|
1094
2242
|
hasScheduler: boolean;
|
|
@@ -1098,28 +2246,45 @@ interface EmitAppOptions {
|
|
|
1098
2246
|
hasVectors: boolean;
|
|
1099
2247
|
/** App declares Cloudflare Workflows (`defineWorkflow`) → wire `options.workflowsClient` so the studio's workflow-instance proxy can reach the CF REST API. */
|
|
1100
2248
|
hasWorkflow: boolean;
|
|
2249
|
+
/** App uses `@lunora/x402/pay` / `ctx.x402` → emit `.x402()` (wire the agent-wallet pay rail). */
|
|
2250
|
+
hasX402: boolean;
|
|
2251
|
+
/** The single `defineIdentity(...)` contract in `lunora/identity.ts` (Plan 080) → import it as a VALUE and wire `options.identity`, so the runtime trust boundary validates every resolved identity before it becomes `ctx.auth`. `undefined` ⇒ no wiring, byte-identical output. */
|
|
2252
|
+
identity?: IdentityIR;
|
|
2253
|
+
/** Schema declares `.jurisdiction("…")` → pin every DO the worker reaches (shards, fan-out, scheduler, containers) to the Cloudflare data-residency jurisdiction. */
|
|
2254
|
+
jurisdiction?: JurisdictionIR;
|
|
1101
2255
|
/** Project depends on the unscoped `lunorash` umbrella → import the runtime via `lunorash/runtime` instead of `@lunora/runtime`. */
|
|
1102
2256
|
useUmbrella: boolean;
|
|
2257
|
+
/**
|
|
2258
|
+
* Voice-enabled agents (`defineAgent({ voice: … })`) → wire
|
|
2259
|
+
* `options.voiceAgents`, mapping each agent's export name to its `VOICE_*`
|
|
2260
|
+
* Durable Object namespace binding so the runtime exposes
|
|
2261
|
+
* `/_lunora/voice/<exportName>`. Empty/absent ⇒ no wiring, byte-identical
|
|
2262
|
+
* output for voice-free (and agent-free) projects.
|
|
2263
|
+
*/
|
|
2264
|
+
voiceAgents?: ReadonlyArray<{
|
|
2265
|
+
bindingName: string;
|
|
2266
|
+
exportName: string;
|
|
2267
|
+
}>;
|
|
1103
2268
|
/** An OpenAPI spec is emitted (`openapi.ts`) → wire `openApiSpec` into the worker. */
|
|
1104
2269
|
wantsOpenApi: boolean;
|
|
1105
2270
|
/** An OpenRPC spec is emitted (`openrpc.ts`) → wire `openRpcSpec` into the worker. */
|
|
1106
2271
|
wantsOpenRpc: boolean;
|
|
1107
2272
|
}
|
|
1108
2273
|
/**
|
|
1109
|
-
* Emit `_generated/app.ts` — a fluent, feature-specialized worker-composition
|
|
1110
|
-
* builder. Only the methods for capabilities THIS app uses are emitted, so the
|
|
1111
|
-
* builder's type surface (IntelliSense) lists exactly what can be configured.
|
|
1112
|
-
*
|
|
1113
|
-
* Each capability declaration is fanned into BOTH runtime surfaces: the DO-side
|
|
1114
|
-
* `createShardDO(...)` factory that backs `ctx.*`, and the worker-side
|
|
1115
|
-
* `createWorker(...)` options that back the studio/admin endpoints — so storage
|
|
1116
|
-
* / scheduler / global are declared once instead of twice. The builder is pure
|
|
1117
|
-
* sugar over the public `createWorker` / `createShardDO`; both stay usable.
|
|
1118
|
-
*
|
|
1119
|
-
* Lives in generated code (not `@lunora/runtime`, which is dependency-free) so
|
|
1120
|
-
* it can import the add-on packages the app installed (`@lunora/auth`,
|
|
1121
|
-
* `@lunora/storage`, …) directly.
|
|
1122
|
-
*/
|
|
2274
|
+
* Emit `_generated/app.ts` — a fluent, feature-specialized worker-composition
|
|
2275
|
+
* builder. Only the methods for capabilities THIS app uses are emitted, so the
|
|
2276
|
+
* builder's type surface (IntelliSense) lists exactly what can be configured.
|
|
2277
|
+
*
|
|
2278
|
+
* Each capability declaration is fanned into BOTH runtime surfaces: the DO-side
|
|
2279
|
+
* `createShardDO(...)` factory that backs `ctx.*`, and the worker-side
|
|
2280
|
+
* `createWorker(...)` options that back the studio/admin endpoints — so storage
|
|
2281
|
+
* / scheduler / global are declared once instead of twice. The builder is pure
|
|
2282
|
+
* sugar over the public `createWorker` / `createShardDO`; both stay usable.
|
|
2283
|
+
*
|
|
2284
|
+
* Lives in generated code (not `@lunora/runtime`, which is dependency-free) so
|
|
2285
|
+
* it can import the add-on packages the app installed (`@lunora/auth`,
|
|
2286
|
+
* `@lunora/storage`, …) directly.
|
|
2287
|
+
*/
|
|
1123
2288
|
declare const emitApp: (options: EmitAppOptions) => string;
|
|
1124
2289
|
/** Inputs the OpenAPI emitter needs from a codegen run. */
|
|
1125
2290
|
interface OpenApiEmitInput {
|
|
@@ -1129,40 +2294,40 @@ interface OpenApiEmitInput {
|
|
|
1129
2294
|
version?: string;
|
|
1130
2295
|
}
|
|
1131
2296
|
/**
|
|
1132
|
-
* Emit an OpenAPI 3.1.0 document covering both Lunora function surfaces.
|
|
1133
|
-
*
|
|
1134
|
-
* `httpRouter()` typed REST routes become real `paths` keyed by their method +
|
|
1135
|
-
* URL, with query/path parameters and JSON request bodies derived from their
|
|
1136
|
-
* `v.*` validators, and a response schema from `.output()` when declared.
|
|
1137
|
-
*
|
|
1138
|
-
* RPC `query`/`mutation`/`action` functions become one operation each on
|
|
1139
|
-
* `POST /_lunora/rpc` (disambiguated by a `#functionPath` path fragment), with a
|
|
1140
|
-
* requestBody pinning `functionPath` + typed `args`. `internal`/`stream`
|
|
1141
|
-
* functions are excluded (unreachable / not invocable on the external RPC path).
|
|
1142
|
-
*
|
|
1143
|
-
* Operations are grouped into `tags` by file namespace, and every operation
|
|
1144
|
-
* references a reusable `LunoraError` error-response component enumerating the
|
|
1145
|
-
* standard error codes. Borrows oRPC's per-procedure-operation + tag-grouping +
|
|
1146
|
-
* internal-filtering structure; the JSON Schema dialect matches `@lunora/values`
|
|
1147
|
-
* (Draft 2020-12). Returns the document as a plain object (the single source of
|
|
1148
|
-
* truth `emitOpenApi` stringifies and `emitOpenApiModule` inlines, so the
|
|
1149
|
-
* `.json` and `.ts` artifacts can never drift).
|
|
1150
|
-
*/
|
|
2297
|
+
* Emit an OpenAPI 3.1.0 document covering both Lunora function surfaces.
|
|
2298
|
+
*
|
|
2299
|
+
* `httpRouter()` typed REST routes become real `paths` keyed by their method +
|
|
2300
|
+
* URL, with query/path parameters and JSON request bodies derived from their
|
|
2301
|
+
* `v.*` validators, and a response schema from `.output()` when declared.
|
|
2302
|
+
*
|
|
2303
|
+
* RPC `query`/`mutation`/`action` functions become one operation each on
|
|
2304
|
+
* `POST /_lunora/rpc` (disambiguated by a `#functionPath` path fragment), with a
|
|
2305
|
+
* requestBody pinning `functionPath` + typed `args`. `internal`/`stream`
|
|
2306
|
+
* functions are excluded (unreachable / not invocable on the external RPC path).
|
|
2307
|
+
*
|
|
2308
|
+
* Operations are grouped into `tags` by file namespace, and every operation
|
|
2309
|
+
* references a reusable `LunoraError` error-response component enumerating the
|
|
2310
|
+
* standard error codes. Borrows oRPC's per-procedure-operation + tag-grouping +
|
|
2311
|
+
* internal-filtering structure; the JSON Schema dialect matches `@lunora/values`
|
|
2312
|
+
* (Draft 2020-12). Returns the document as a plain object (the single source of
|
|
2313
|
+
* truth `emitOpenApi` stringifies and `emitOpenApiModule` inlines, so the
|
|
2314
|
+
* `.json` and `.ts` artifacts can never drift).
|
|
2315
|
+
*/
|
|
1151
2316
|
declare const buildOpenApiDocument: (input: OpenApiEmitInput) => Record<string, unknown>;
|
|
1152
2317
|
/**
|
|
1153
|
-
* Emit the OpenAPI 3.1 document as a pretty-printed JSON string
|
|
1154
|
-
* (`_generated/openapi.json`) — the portable artifact for external tooling.
|
|
1155
|
-
*/
|
|
2318
|
+
* Emit the OpenAPI 3.1 document as a pretty-printed JSON string
|
|
2319
|
+
* (`_generated/openapi.json`) — the portable artifact for external tooling.
|
|
2320
|
+
*/
|
|
1156
2321
|
declare const emitOpenApi: (input: OpenApiEmitInput) => string;
|
|
1157
2322
|
/**
|
|
1158
|
-
* Emit the OpenAPI document as an importable TS module
|
|
1159
|
-
* (`_generated/openapi.ts`) the worker entry imports and passes to
|
|
1160
|
-
* `createWorker({ openApiSpec })`. The document object literal is inlined
|
|
1161
|
-
* verbatim (same `JSON.stringify` form the `.json` uses), so the `.ts` and
|
|
1162
|
-
* `.json` are byte-identical content and regenerate together — closing the gap
|
|
1163
|
-
* where a Worker cannot read the JSON file at runtime. `document_` is the object
|
|
1164
|
-
* returned by {@link buildOpenApiDocument} (reused, never recomputed).
|
|
1165
|
-
*/
|
|
2323
|
+
* Emit the OpenAPI document as an importable TS module
|
|
2324
|
+
* (`_generated/openapi.ts`) the worker entry imports and passes to
|
|
2325
|
+
* `createWorker({ openApiSpec })`. The document object literal is inlined
|
|
2326
|
+
* verbatim (same `JSON.stringify` form the `.json` uses), so the `.ts` and
|
|
2327
|
+
* `.json` are byte-identical content and regenerate together — closing the gap
|
|
2328
|
+
* where a Worker cannot read the JSON file at runtime. `document_` is the object
|
|
2329
|
+
* returned by {@link buildOpenApiDocument} (reused, never recomputed).
|
|
2330
|
+
*/
|
|
1166
2331
|
declare const emitOpenApiModule: (document_: Record<string, unknown>) => string;
|
|
1167
2332
|
/** The OpenRPC dialect version this emitter targets. */
|
|
1168
2333
|
declare const OPENRPC_VERSION = "1.3.2";
|
|
@@ -1173,37 +2338,37 @@ interface OpenRpcEmitInput {
|
|
|
1173
2338
|
version?: string;
|
|
1174
2339
|
}
|
|
1175
2340
|
/**
|
|
1176
|
-
* Emit an OpenRPC 1.x document describing Lunora's JSON-RPC surface.
|
|
1177
|
-
*
|
|
1178
|
-
* Only the RPC `query`/`mutation`/`action` functions become `methods` — one per
|
|
1179
|
-
* function, `name` = `file:fn`. `internal` (off the external RPC path) and
|
|
1180
|
-
* `stream` (not invocable over the RPC envelope) are excluded, the same filter
|
|
1181
|
-
* the OpenAPI emitter applies. Each method's single `args` param is typed from
|
|
1182
|
-
* the function's `v.*` validators (`argsObjectSchema`); `result` is the
|
|
1183
|
-
* `.output()` schema when declared, else a best-effort inferred schema. The
|
|
1184
|
-
* standard `LunoraError` codes ride along under each method's `errors`.
|
|
1185
|
-
*
|
|
1186
|
-
* `httpRouter()` typed REST routes are deliberately omitted — OpenRPC is
|
|
1187
|
-
* RPC-only and cannot represent REST paths; the OpenAPI document is the spec
|
|
1188
|
-
* that covers the REST surface. Methods are sorted by name for stable output.
|
|
1189
|
-
* Returns the document as a plain object (the single source of truth
|
|
1190
|
-
* `emitOpenRpc` stringifies and `emitOpenRpcModule` inlines, so the `.json` and
|
|
1191
|
-
* `.ts` artifacts can never drift).
|
|
1192
|
-
*/
|
|
2341
|
+
* Emit an OpenRPC 1.x document describing Lunora's JSON-RPC surface.
|
|
2342
|
+
*
|
|
2343
|
+
* Only the RPC `query`/`mutation`/`action` functions become `methods` — one per
|
|
2344
|
+
* function, `name` = `file:fn`. `internal` (off the external RPC path) and
|
|
2345
|
+
* `stream` (not invocable over the RPC envelope) are excluded, the same filter
|
|
2346
|
+
* the OpenAPI emitter applies. Each method's single `args` param is typed from
|
|
2347
|
+
* the function's `v.*` validators (`argsObjectSchema`); `result` is the
|
|
2348
|
+
* `.output()` schema when declared, else a best-effort inferred schema. The
|
|
2349
|
+
* standard `LunoraError` codes ride along under each method's `errors`.
|
|
2350
|
+
*
|
|
2351
|
+
* `httpRouter()` typed REST routes are deliberately omitted — OpenRPC is
|
|
2352
|
+
* RPC-only and cannot represent REST paths; the OpenAPI document is the spec
|
|
2353
|
+
* that covers the REST surface. Methods are sorted by name for stable output.
|
|
2354
|
+
* Returns the document as a plain object (the single source of truth
|
|
2355
|
+
* `emitOpenRpc` stringifies and `emitOpenRpcModule` inlines, so the `.json` and
|
|
2356
|
+
* `.ts` artifacts can never drift).
|
|
2357
|
+
*/
|
|
1193
2358
|
declare const buildOpenRpcDocument: (input: OpenRpcEmitInput) => Record<string, unknown>;
|
|
1194
2359
|
/**
|
|
1195
|
-
* Emit the OpenRPC 1.x document as a pretty-printed JSON string
|
|
1196
|
-
* (`_generated/openrpc.json`) — the portable artifact for external tooling.
|
|
1197
|
-
*/
|
|
2360
|
+
* Emit the OpenRPC 1.x document as a pretty-printed JSON string
|
|
2361
|
+
* (`_generated/openrpc.json`) — the portable artifact for external tooling.
|
|
2362
|
+
*/
|
|
1198
2363
|
declare const emitOpenRpc: (input: OpenRpcEmitInput) => string;
|
|
1199
2364
|
/**
|
|
1200
|
-
* Emit the OpenRPC document as an importable TS module
|
|
1201
|
-
* (`_generated/openrpc.ts`) the worker entry imports and passes to
|
|
1202
|
-
* `createWorker({ openRpcSpec })`. The document object literal is inlined
|
|
1203
|
-
* verbatim (same `JSON.stringify` form the `.json` uses), so the `.ts` and
|
|
1204
|
-
* `.json` are byte-identical content and regenerate together. `document_` is
|
|
1205
|
-
* the object returned by {@link buildOpenRpcDocument} (reused, never recomputed).
|
|
1206
|
-
*/
|
|
2365
|
+
* Emit the OpenRPC document as an importable TS module
|
|
2366
|
+
* (`_generated/openrpc.ts`) the worker entry imports and passes to
|
|
2367
|
+
* `createWorker({ openRpcSpec })`. The document object literal is inlined
|
|
2368
|
+
* verbatim (same `JSON.stringify` form the `.json` uses), so the `.ts` and
|
|
2369
|
+
* `.json` are byte-identical content and regenerate together. `document_` is
|
|
2370
|
+
* the object returned by {@link buildOpenRpcDocument} (reused, never recomputed).
|
|
2371
|
+
*/
|
|
1207
2372
|
declare const emitOpenRpcModule: (document_: Record<string, unknown>) => string;
|
|
1208
2373
|
/** Current snapshot format version. Bumped if the structural shape below changes. */
|
|
1209
2374
|
declare const SCHEMA_SNAPSHOT_VERSION: 1;
|
|
@@ -1234,14 +2399,27 @@ interface TableSnapshot {
|
|
|
1234
2399
|
/** Relation accessor name → {@link RelationSnapshot}. */
|
|
1235
2400
|
relations: Record<string, RelationSnapshot>;
|
|
1236
2401
|
/**
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
2402
|
+
* `"root"` (default single-DO), `"global"` (D1-replicated), or
|
|
2403
|
+
* `"shardBy:<field>"` (partitioned). Encoded as a string so the snapshot
|
|
2404
|
+
* stays a plain JSON-stable value.
|
|
2405
|
+
*/
|
|
1241
2406
|
shardMode: string;
|
|
1242
2407
|
}
|
|
1243
2408
|
/** The committed baseline — a deterministic structural view of the whole schema. */
|
|
1244
2409
|
interface SchemaSnapshot {
|
|
2410
|
+
/**
|
|
2411
|
+
* Cloudflare DO data-residency jurisdiction declared via `.jurisdiction("…")`,
|
|
2412
|
+
* or absent. Tracked because changing it strands all existing Durable Object
|
|
2413
|
+
* data (a DO name maps to a different ID per jurisdiction). Optional, so old
|
|
2414
|
+
* baselines written before this field parse cleanly (absent ⇒ undefined).
|
|
2415
|
+
*
|
|
2416
|
+
* Typed as a plain `string` (not the authoring union) on purpose: this is
|
|
2417
|
+
* STORED data that a newer Lunora may have written with a jurisdiction this
|
|
2418
|
+
* version doesn't yet know. Preserving the raw value keeps the breaking
|
|
2419
|
+
* `changedJurisdiction` diff correct under a downgrade — coercing an unknown
|
|
2420
|
+
* value to `undefined` would fail OPEN and hide the most destructive change.
|
|
2421
|
+
*/
|
|
2422
|
+
jurisdiction?: string;
|
|
1245
2423
|
/** Sorted list of every declared `defineMigration` id at capture time. */
|
|
1246
2424
|
migrationIds: ReadonlyArray<string>;
|
|
1247
2425
|
/** Table name → {@link TableSnapshot}, keys sorted for stable serialization. */
|
|
@@ -1255,7 +2433,7 @@ interface DriftChange {
|
|
|
1255
2433
|
/** Human-readable, actionable description (used in the gate message). */
|
|
1256
2434
|
summary: string;
|
|
1257
2435
|
/** A machine-readable change discriminator. */
|
|
1258
|
-
type: "addedIndex" | "addedOptionalField" | "addedRelation" | "addedRequiredField" | "addedTable" | "changedFieldKind" | "changedIndex" | "changedShardMode" | "fieldOptionalToRequired" | "fieldRequiredToOptional" | "removedField" | "removedIndex" | "removedRelation" | "removedTable";
|
|
2436
|
+
type: "addedIndex" | "addedOptionalField" | "addedRelation" | "addedRequiredField" | "addedTable" | "changedJurisdiction" | "changedFieldKind" | "changedIndex" | "changedShardMode" | "fieldOptionalToRequired" | "fieldRequiredToOptional" | "removedField" | "removedIndex" | "removedRelation" | "removedTable";
|
|
1259
2437
|
}
|
|
1260
2438
|
/** The result of diffing two snapshots: every classified change. */
|
|
1261
2439
|
interface SchemaDrift {
|
|
@@ -1263,36 +2441,36 @@ interface SchemaDrift {
|
|
|
1263
2441
|
changes: ReadonlyArray<DriftChange>;
|
|
1264
2442
|
}
|
|
1265
2443
|
/**
|
|
1266
|
-
* Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
|
|
1267
|
-
* declared migration ids. Tables and migration ids are sorted so the emitted
|
|
1268
|
-
* JSON is byte-stable across runs (no spurious diffs / churn).
|
|
1269
|
-
*/
|
|
2444
|
+
* Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
|
|
2445
|
+
* declared migration ids. Tables and migration ids are sorted so the emitted
|
|
2446
|
+
* JSON is byte-stable across runs (no spurious diffs / churn).
|
|
2447
|
+
*/
|
|
1270
2448
|
declare const buildSchemaSnapshot: (schema: SchemaIR, migrationIds: ReadonlyArray<string>) => SchemaSnapshot;
|
|
1271
2449
|
/** Serialize a snapshot to the exact bytes written to `lunora/.lunora-schema.json` (trailing newline). */
|
|
1272
2450
|
declare const serializeSchemaSnapshot: (snapshot: SchemaSnapshot) => string;
|
|
1273
2451
|
/**
|
|
1274
|
-
* Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
|
|
1275
|
-
* malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
|
|
1276
|
-
* treat a corrupt baseline as a hard error rather than silently degrading to a
|
|
1277
|
-
* "first capture" that would mask drift and then overwrite the bad file.
|
|
1278
|
-
*/
|
|
1279
|
-
declare class SchemaSnapshotParseError extends
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1282
|
-
/**
|
|
1283
|
-
* Parse a committed snapshot file. Returns `undefined` ONLY when the content is
|
|
1284
|
-
* absent/empty; throws {@link SchemaSnapshotParseError} when content is present
|
|
1285
|
-
* but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
|
|
1286
|
-
* caller can distinguish "no baseline yet" (a legitimate first capture) from "a
|
|
1287
|
-
* corrupt baseline" (which must not be silently treated as a first capture).
|
|
1288
|
-
*/
|
|
2452
|
+
* Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
|
|
2453
|
+
* malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
|
|
2454
|
+
* treat a corrupt baseline as a hard error rather than silently degrading to a
|
|
2455
|
+
* "first capture" that would mask drift and then overwrite the bad file.
|
|
2456
|
+
*/
|
|
2457
|
+
declare class SchemaSnapshotParseError extends LunoraError {
|
|
2458
|
+
constructor(message: string);
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Parse a committed snapshot file. Returns `undefined` ONLY when the content is
|
|
2462
|
+
* absent/empty; throws {@link SchemaSnapshotParseError} when content is present
|
|
2463
|
+
* but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
|
|
2464
|
+
* caller can distinguish "no baseline yet" (a legitimate first capture) from "a
|
|
2465
|
+
* corrupt baseline" (which must not be silently treated as a first capture).
|
|
2466
|
+
*/
|
|
1289
2467
|
declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
|
|
1290
2468
|
/**
|
|
1291
|
-
* Diff the current snapshot against a committed baseline and classify every
|
|
1292
|
-
* structural change. Pure — no I/O. When `baseline` is `undefined` (no committed
|
|
1293
|
-
* snapshot yet) there is no drift to report: every table is treated as a fresh
|
|
1294
|
-
* additive `addedTable`, so a first deploy is never blocked.
|
|
1295
|
-
*/
|
|
2469
|
+
* Diff the current snapshot against a committed baseline and classify every
|
|
2470
|
+
* structural change. Pure — no I/O. When `baseline` is `undefined` (no committed
|
|
2471
|
+
* snapshot yet) there is no drift to report: every table is treated as a fresh
|
|
2472
|
+
* additive `addedTable`, so a first deploy is never blocked.
|
|
2473
|
+
*/
|
|
1296
2474
|
declare const diffSchemaSnapshots: (baseline: SchemaSnapshot | undefined, current: SchemaSnapshot) => SchemaDrift;
|
|
1297
2475
|
/** The decision the pre-deploy gate returns. */
|
|
1298
2476
|
interface SchemaDriftDecision {
|
|
@@ -1303,212 +2481,250 @@ interface SchemaDriftDecision {
|
|
|
1303
2481
|
/** Migration ids declared now but absent from the baseline — proof a migration was added. */
|
|
1304
2482
|
newMigrationIds: ReadonlyArray<string>;
|
|
1305
2483
|
/**
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
2484
|
+
* A multi-line, actionable explanation. Always present; empty string when
|
|
2485
|
+
* there is no drift at all. Mirrors the D1-placeholder guard's message style.
|
|
2486
|
+
*/
|
|
1309
2487
|
reason: string;
|
|
1310
2488
|
}
|
|
1311
2489
|
/**
|
|
1312
|
-
* Decide whether breaking schema drift should block a deploy.
|
|
1313
|
-
*
|
|
1314
|
-
* Blocks only when the baseline exists (a first-ever capture is never blocking),
|
|
1315
|
-
* there is at least one `breaking` change, no NEW migration id was added since
|
|
1316
|
-
* the baseline, and the `allowDrift` override is not set. Safe-only drift (or
|
|
1317
|
-
* breaking drift accompanied by a new migration id) passes.
|
|
1318
|
-
*/
|
|
2490
|
+
* Decide whether breaking schema drift should block a deploy.
|
|
2491
|
+
*
|
|
2492
|
+
* Blocks only when the baseline exists (a first-ever capture is never blocking),
|
|
2493
|
+
* there is at least one `breaking` change, no NEW migration id was added since
|
|
2494
|
+
* the baseline, and the `allowDrift` override is not set. Safe-only drift (or
|
|
2495
|
+
* breaking drift accompanied by a new migration id) passes.
|
|
2496
|
+
*/
|
|
1319
2497
|
declare const evaluateSchemaDrift: (options: {
|
|
1320
2498
|
allowDrift?: boolean;
|
|
1321
2499
|
baseline: SchemaSnapshot | undefined;
|
|
1322
2500
|
current: SchemaSnapshot;
|
|
1323
2501
|
}) => SchemaDriftDecision;
|
|
1324
2502
|
/**
|
|
1325
|
-
* Committed, tracked baseline file holding the blessed structural schema
|
|
1326
|
-
* snapshot the pre-deploy drift gate diffs against. Lives in `lunora/` (NOT the
|
|
1327
|
-
* gitignored `_generated/`) so it is committed alongside `schema.ts`. Leading
|
|
1328
|
-
* dot keeps it tucked away next to the schema it describes.
|
|
1329
|
-
*/
|
|
2503
|
+
* Committed, tracked baseline file holding the blessed structural schema
|
|
2504
|
+
* snapshot the pre-deploy drift gate diffs against. Lives in `lunora/` (NOT the
|
|
2505
|
+
* gitignored `_generated/`) so it is committed alongside `schema.ts`. Leading
|
|
2506
|
+
* dot keeps it tucked away next to the schema it describes.
|
|
2507
|
+
*/
|
|
1330
2508
|
declare const SCHEMA_SNAPSHOT_FILENAME = ".lunora-schema.json";
|
|
1331
2509
|
/**
|
|
1332
|
-
* Construct the ts-morph `Project` codegen discovers over. Prefers the user's
|
|
1333
|
-
* `tsconfig.json` (when one is found walking up from `lunoraDirectory`) so
|
|
1334
|
-
* cross-file type resolution and path aliases work; falls back to an isolated
|
|
1335
|
-
* project otherwise. This is the exact construction {@link runCodegen} uses
|
|
1336
|
-
* when no `project` is injected — exported so a long-lived caller (the Vite
|
|
1337
|
-
* dev-loop) can build one once and reuse it across runs via
|
|
1338
|
-
* {@link refreshCodegenProject} instead of re-parsing the user's whole TS
|
|
1339
|
-
* program on every save.
|
|
1340
|
-
*/
|
|
2510
|
+
* Construct the ts-morph `Project` codegen discovers over. Prefers the user's
|
|
2511
|
+
* `tsconfig.json` (when one is found walking up from `lunoraDirectory`) so
|
|
2512
|
+
* cross-file type resolution and path aliases work; falls back to an isolated
|
|
2513
|
+
* project otherwise. This is the exact construction {@link runCodegen} uses
|
|
2514
|
+
* when no `project` is injected — exported so a long-lived caller (the Vite
|
|
2515
|
+
* dev-loop) can build one once and reuse it across runs via
|
|
2516
|
+
* {@link refreshCodegenProject} instead of re-parsing the user's whole TS
|
|
2517
|
+
* program on every save.
|
|
2518
|
+
*/
|
|
1341
2519
|
declare const createCodegenProject: (lunoraDirectory: string) => Project;
|
|
1342
2520
|
/**
|
|
1343
|
-
* Synchronise a reused {@link createCodegenProject} Project with the current
|
|
1344
|
-
* on-disk state of `lunoraDirectory`, so the next {@link runCodegen} sees the
|
|
1345
|
-
* same files a freshly-constructed Project would — without re-parsing the whole
|
|
1346
|
-
* TS program. Adds any on-disk source file the Project doesn't yet have, and
|
|
1347
|
-
* `refreshFromFileSystemSync()`es the ones it does (picking up edits); then
|
|
1348
|
-
* removes Project source files under `lunoraDirectory` that no longer exist on
|
|
1349
|
-
* disk (the classic stale-deleted-file cache bug).
|
|
1350
|
-
*
|
|
1351
|
-
* Files outside `lunoraDirectory` (e.g. those pulled in by the user's tsconfig)
|
|
1352
|
-
* are left untouched — they back type resolution and rarely change in the
|
|
1353
|
-
* dev-loop; a tsconfig change invalidates the whole cached Project upstream.
|
|
1354
|
-
*/
|
|
2521
|
+
* Synchronise a reused {@link createCodegenProject} Project with the current
|
|
2522
|
+
* on-disk state of `lunoraDirectory`, so the next {@link runCodegen} sees the
|
|
2523
|
+
* same files a freshly-constructed Project would — without re-parsing the whole
|
|
2524
|
+
* TS program. Adds any on-disk source file the Project doesn't yet have, and
|
|
2525
|
+
* `refreshFromFileSystemSync()`es the ones it does (picking up edits); then
|
|
2526
|
+
* removes Project source files under `lunoraDirectory` that no longer exist on
|
|
2527
|
+
* disk (the classic stale-deleted-file cache bug).
|
|
2528
|
+
*
|
|
2529
|
+
* Files outside `lunoraDirectory` (e.g. those pulled in by the user's tsconfig)
|
|
2530
|
+
* are left untouched — they back type resolution and rarely change in the
|
|
2531
|
+
* dev-loop; a tsconfig change invalidates the whole cached Project upstream.
|
|
2532
|
+
*/
|
|
1355
2533
|
declare const refreshCodegenProject: (project: Project, lunoraDirectory: string) => void;
|
|
1356
2534
|
/**
|
|
1357
|
-
* Top-level codegen entry. Parses `<projectRoot>/lunora/schema.ts` and every
|
|
1358
|
-
* function file under `<projectRoot>/lunora/`, then writes
|
|
1359
|
-
* `_generated/{api,server,dataModel}.ts` next to them.
|
|
1360
|
-
|
|
2535
|
+
* Top-level codegen entry. Parses `<projectRoot>/lunora/schema.ts` and every
|
|
2536
|
+
* function file under `<projectRoot>/lunora/`, then writes
|
|
2537
|
+
* `_generated/{api,server,dataModel}.ts` next to them.
|
|
2538
|
+
*
|
|
2539
|
+
* When `LUNORA_CODEGEN_TIMING` is set (truthy), a single diagnostic summary
|
|
2540
|
+
* line is written to stderr with the total wall time and the discovery-vs-emit
|
|
2541
|
+
* split — opt-in instrumentation that is otherwise zero-cost and side-effect-free
|
|
2542
|
+
* on the returned {@link CodegenResult}.
|
|
2543
|
+
*/
|
|
1361
2544
|
declare const runCodegen: (options: CodegenOptions) => CodegenResult;
|
|
1362
2545
|
interface CodegenOptions {
|
|
1363
2546
|
/**
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
2547
|
+
* Which machine-readable API spec(s) to emit into `_generated/`.
|
|
2548
|
+
*
|
|
2549
|
+
* `"openapi"` (the default) writes only `openapi.json` (OpenAPI 3.1; covers
|
|
2550
|
+
* both the RPC functions and `httpRouter()` REST routes). `"openrpc"` writes
|
|
2551
|
+
* only `openrpc.json` (OpenRPC 1.x; the RPC functions only — OpenRPC cannot
|
|
2552
|
+
* represent REST routes). `"both"` writes both files; `"none"` writes neither.
|
|
2553
|
+
*
|
|
2554
|
+
* Regardless of the choice, `CodegenResult.generated.openApi` and `.openRpc`
|
|
2555
|
+
* always carry the rendered string (computation is cheap and pure); only the
|
|
2556
|
+
* on-disk write is gated by this option.
|
|
2557
|
+
*/
|
|
1375
2558
|
apiSpec?: "both" | "none" | "openapi" | "openrpc";
|
|
1376
2559
|
/**
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
2560
|
+
* When true, run discovery + emit (so any schema/function parse error
|
|
2561
|
+
* surfaces) but skip writing files to `_generated/`. The returned
|
|
2562
|
+
* `outputDirectory` is still the path that *would* have been written.
|
|
2563
|
+
*/
|
|
1381
2564
|
dryRun?: boolean;
|
|
1382
2565
|
/**
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
2566
|
+
* Run the static schema advisor (unindexed FKs, …) during codegen.
|
|
2567
|
+
* Defaults to `true`. When `false`, `CodegenResult.advisories` is empty.
|
|
2568
|
+
* Computed regardless of `dryRun`; codegen never prints them — see
|
|
2569
|
+
* {@link CodegenResult.advisories}.
|
|
2570
|
+
*/
|
|
1388
2571
|
lint?: boolean;
|
|
1389
2572
|
/** Override the lunora subdirectory name. Defaults to `"lunora"`. */
|
|
1390
2573
|
lunoraDirectory?: string;
|
|
1391
2574
|
/**
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
2575
|
+
* Reuse a previously-constructed ts-morph {@link Project} instead of building
|
|
2576
|
+
* a fresh one each run. The caller owns refreshing its source files from disk
|
|
2577
|
+
* (see {@link refreshCodegenProject}) — codegen does not re-read changed files
|
|
2578
|
+
* off an injected Project. Built via {@link createCodegenProject} when absent.
|
|
2579
|
+
* Used by the Vite dev-loop to avoid re-parsing the whole TS program on every
|
|
2580
|
+
* save; omit it (CLI one-shot path) to get the default fresh-Project behaviour.
|
|
2581
|
+
*/
|
|
1399
2582
|
project?: Project;
|
|
1400
2583
|
/** Project root containing the `lunora/` directory. */
|
|
1401
2584
|
projectRoot: string;
|
|
1402
2585
|
/**
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
2586
|
+
* Re-bless the committed schema-drift baseline (`lunora/.lunora-schema.json`)
|
|
2587
|
+
* with the current structural snapshot. The baseline is ALWAYS written on
|
|
2588
|
+
* first capture (when the file is absent); set this to overwrite an existing
|
|
2589
|
+
* one — e.g. after the developer has added the data migration that justifies
|
|
2590
|
+
* a breaking change. Ignored when `dryRun` is true.
|
|
2591
|
+
*/
|
|
1409
2592
|
updateSchemaBaseline?: boolean;
|
|
2593
|
+
/**
|
|
2594
|
+
* Committed `wrangler.jsonc` `vars` entries that hold plaintext secrets — the
|
|
2595
|
+
* `plaintext_secret_in_wrangler_vars` lint input. Produced by `@lunora/config`
|
|
2596
|
+
* (which reads `wrangler.jsonc`) and threaded through by the CLI / Vite plugin;
|
|
2597
|
+
* codegen only forwards it to the advisor. Absent when no wrangler config is
|
|
2598
|
+
* present or the caller doesn't scan it.
|
|
2599
|
+
*/
|
|
2600
|
+
wranglerVariables?: ReadonlyArray<WranglerVariableIR>;
|
|
1410
2601
|
}
|
|
1411
2602
|
interface CodegenResult {
|
|
1412
2603
|
/**
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
2604
|
+
* Static schema advisor findings (e.g. unindexed foreign keys) produced
|
|
2605
|
+
* this run. Empty when `lint` is `false` or the schema is clean. Codegen
|
|
2606
|
+
* does not print these itself — each caller presents them through its own
|
|
2607
|
+
* channel (the CLI logger, the vite overlay, the studio Advisors table).
|
|
2608
|
+
* `formatAdvisories` is exported for a plain multi-line rendering.
|
|
2609
|
+
*/
|
|
1419
2610
|
advisories: ReadonlyArray<Finding>;
|
|
1420
2611
|
/**
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
2612
|
+
* Agents discovered from `defineAgent` exports in `lunora/agents.ts` — the
|
|
2613
|
+
* list the config layer reconciles into wrangler's `workflows[]` array (an
|
|
2614
|
+
* agent compiles onto a Cloudflare Workflow). Agents are NOT Durable Objects,
|
|
2615
|
+
* so this adds no binding or migration. Empty when the project declares none.
|
|
2616
|
+
*/
|
|
2617
|
+
agents: ReadonlyArray<AgentIR>;
|
|
2618
|
+
/**
|
|
2619
|
+
* Containers discovered from `defineContainer` exports in
|
|
2620
|
+
* `lunora/containers.ts` — the list the config layer reconciles into
|
|
2621
|
+
* wrangler's `containers[]`, `CONTAINER_*` Durable Object bindings, and
|
|
2622
|
+
* migration classes. Empty when the project declares no containers.
|
|
2623
|
+
*/
|
|
1426
2624
|
containers: ReadonlyArray<ContainerIR>;
|
|
1427
2625
|
/**
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
2626
|
+
* Deduplicated cron schedules discovered from `cronJobs()` definitions —
|
|
2627
|
+
* the array the vite plugin reconciles into `wrangler.jsonc`'s
|
|
2628
|
+
* `triggers.crons`. Empty when the project declares no crons.
|
|
2629
|
+
*/
|
|
1432
2630
|
cronTriggers: ReadonlyArray<string>;
|
|
1433
2631
|
generated: {
|
|
1434
|
-
|
|
2632
|
+
/** WorkflowEntrypoint classes for declared agents (`_generated/agents.ts`); `""` (and not written) when no agents are declared. */
|
|
2633
|
+
agents: string;
|
|
2634
|
+
api: string;
|
|
2635
|
+
/** Fluent worker-composition builder (`_generated/app.ts`) — `defineApp()`. Always written. */
|
|
1435
2636
|
app: string;
|
|
2637
|
+
/** Partial-replication collection factories (`_generated/collections.ts`); `""` (and not written) unless the project declares shapes and installs `@lunora/db`. */
|
|
2638
|
+
collections: string;
|
|
1436
2639
|
/** Container DO classes (`_generated/containers.ts`); `""` (and not written) when no containers are declared. */
|
|
1437
2640
|
containers: string;
|
|
1438
2641
|
crons: string;
|
|
1439
2642
|
dataModel: string;
|
|
1440
2643
|
drizzleGlobal: string;
|
|
1441
2644
|
drizzleShard: string;
|
|
1442
|
-
functions: string;
|
|
2645
|
+
functions: string;
|
|
2646
|
+
/** OpenAPI 3.1.0 document (`_generated/openapi.json`), pretty-printed JSON. */
|
|
1443
2647
|
openApi: string;
|
|
1444
2648
|
/**
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
2649
|
+
* OpenAPI document as an importable TS module (`_generated/openapi.ts`) —
|
|
2650
|
+
* `export const openApiSpec`, the worker imports it for
|
|
2651
|
+
* `createWorker({ openApiSpec })`. Same document as `openApi`. Written
|
|
2652
|
+
* alongside `openapi.json` whenever `apiSpec` includes `openapi`.
|
|
2653
|
+
*/
|
|
1450
2654
|
openApiModule: string;
|
|
1451
2655
|
/** OpenRPC 1.x document (`_generated/openrpc.json`), pretty-printed JSON. Always computed; written only when `apiSpec` includes `openrpc`. */
|
|
1452
2656
|
openRpc: string;
|
|
1453
2657
|
/**
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
2658
|
+
* OpenRPC document as an importable TS module (`_generated/openrpc.ts`) —
|
|
2659
|
+
* `export const openRpcSpec`, for `createWorker({ openRpcSpec })`. Same
|
|
2660
|
+
* document as `openRpc`. Written alongside `openrpc.json` whenever
|
|
2661
|
+
* `apiSpec` includes `openrpc`.
|
|
2662
|
+
*/
|
|
1459
2663
|
openRpcModule: string;
|
|
2664
|
+
/** Push-consumer queue registry (`_generated/queues.ts`); `""` (and not written) when no push queues are declared. */
|
|
2665
|
+
queues: string;
|
|
1460
2666
|
/** Project-bound seed client (`_generated/seed.ts`); `""` (and not written) when `@lunora/seed` is not a declared dependency. */
|
|
1461
2667
|
seed: string;
|
|
1462
2668
|
server: string;
|
|
1463
|
-
shard: string;
|
|
2669
|
+
shard: string;
|
|
2670
|
+
/** Static vector-index registry (`_generated/vectors.ts`) — `LUNORA_VECTOR_INDEXES`. Empty array body when the schema declares none. */
|
|
1464
2671
|
vectors: string;
|
|
1465
2672
|
/** WorkflowEntrypoint classes (`_generated/workflows.ts`); `""` (and not written) when no workflows are declared. */
|
|
1466
2673
|
workflows: string;
|
|
1467
2674
|
};
|
|
1468
2675
|
outputDirectory: string;
|
|
1469
2676
|
/**
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
2677
|
+
* Queues discovered from `defineQueue` exports in `lunora/queues.ts` — the
|
|
2678
|
+
* list the config layer reconciles into wrangler's `queues.producers[]` /
|
|
2679
|
+
* `queues.consumers[]`. Queues are NOT Durable Objects, so this adds no
|
|
2680
|
+
* binding or migration. Empty when the project declares no queues.
|
|
2681
|
+
*/
|
|
2682
|
+
queues: ReadonlyArray<QueueIR>;
|
|
2683
|
+
/**
|
|
2684
|
+
* The CURRENT structural schema snapshot computed this run (tables + field
|
|
2685
|
+
* kinds/optionality + indexes/relations/shard mode + declared migration ids).
|
|
2686
|
+
* The pre-deploy drift gate diffs this against the committed baseline read
|
|
2687
|
+
* from {@link CodegenResult.schemaSnapshotPath}. Always present, even on a
|
|
2688
|
+
* `dryRun`.
|
|
2689
|
+
*/
|
|
1476
2690
|
schemaSnapshot: SchemaSnapshot;
|
|
1477
2691
|
/** Absolute path of the committed baseline file (`lunora/.lunora-schema.json`). */
|
|
1478
2692
|
schemaSnapshotPath: string;
|
|
1479
2693
|
/**
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
2694
|
+
* Workflows discovered from `defineWorkflow` exports in
|
|
2695
|
+
* `lunora/workflows.ts` — the list the config layer reconciles into
|
|
2696
|
+
* wrangler's `workflows[]` array. Workflows are NOT Durable Objects, so this
|
|
2697
|
+
* adds no binding or migration. Empty when the project declares no workflows.
|
|
2698
|
+
*/
|
|
1485
2699
|
workflows: ReadonlyArray<WorkflowIR>;
|
|
1486
2700
|
}
|
|
1487
2701
|
/**
|
|
1488
|
-
* Convert a {@link SchemaIR} into a synthetic runtime {@link Schema} carrying just
|
|
1489
|
-
* the `tables[name].shape` surface `@lunora/seed` introspects. System columns
|
|
1490
|
-
* (`_id`, `_creationTime`) are absent from the IR shape, exactly as the seed
|
|
1491
|
-
* engine expects (it assigns `_id` itself).
|
|
1492
|
-
*/
|
|
2702
|
+
* Convert a {@link SchemaIR} into a synthetic runtime {@link Schema} carrying just
|
|
2703
|
+
* the `tables[name].shape` surface `@lunora/seed` introspects. System columns
|
|
2704
|
+
* (`_id`, `_creationTime`) are absent from the IR shape, exactly as the seed
|
|
2705
|
+
* engine expects (it assigns `_id` itself).
|
|
2706
|
+
*/
|
|
1493
2707
|
declare const schemaFromIr: (ir: SchemaIR) => Schema;
|
|
1494
2708
|
/**
|
|
1495
|
-
* Convert a codegen {@link ValidatorIR} into a JSON Schema node. A thin wrapper
|
|
1496
|
-
* over the shared {@link jsonSchemaFromNode} core (from `@lunora/values`) with the
|
|
1497
|
-
* IR-backed {@link irReader}, so the kind→schema mapping is the *same* algorithm
|
|
1498
|
-
* `@lunora/values`' `toJsonSchema` runs — codegen never instantiates the runtime
|
|
1499
|
-
* `v.*` objects, it only holds the reflected IR. Shared by the OpenAPI and
|
|
1500
|
-
* OpenRPC emitters so both surfaces speak one JSON Schema dialect.
|
|
1501
|
-
*/
|
|
2709
|
+
* Convert a codegen {@link ValidatorIR} into a JSON Schema node. A thin wrapper
|
|
2710
|
+
* over the shared {@link jsonSchemaFromNode} core (from `@lunora/values`) with the
|
|
2711
|
+
* IR-backed {@link irReader}, so the kind→schema mapping is the *same* algorithm
|
|
2712
|
+
* `@lunora/values`' `toJsonSchema` runs — codegen never instantiates the runtime
|
|
2713
|
+
* `v.*` objects, it only holds the reflected IR. Shared by the OpenAPI and
|
|
2714
|
+
* OpenRPC emitters so both surfaces speak one JSON Schema dialect.
|
|
2715
|
+
*/
|
|
1502
2716
|
declare const validatorIrToJsonSchema: (validator: ValidatorIR) => JsonSchema;
|
|
1503
|
-
/**
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1509
|
-
|
|
1510
|
-
* the contract; clients switch on `error.code`. Kept sorted for stable output.
|
|
1511
|
-
*/
|
|
2717
|
+
/**
|
|
2718
|
+
* The machine-readable `LunoraError` codes Lunora emits on the RPC + REST
|
|
2719
|
+
* surfaces, enumerated from `@lunora/server`'s `CODE_STATUS` map plus the
|
|
2720
|
+
* runtime/DO dispatch codes (`FUNCTION_NOT_FOUND`, `PAYLOAD_TOO_LARGE`,
|
|
2721
|
+
* `METHOD_NOT_ALLOWED`, the `*_NOT_CONFIGURED` admin gates, …). The list documents
|
|
2722
|
+
* the contract; clients switch on `error.code`. Kept sorted for stable output.
|
|
2723
|
+
*/
|
|
1512
2724
|
declare const LUNORA_ERROR_CODES: ReadonlyArray<string>;
|
|
2725
|
+
/** The matching secret rule's `kind` for a string value, or `undefined` when none matches. */
|
|
2726
|
+
declare const secretKindOf: (value: string) => string | undefined;
|
|
2727
|
+
/** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
|
|
2728
|
+
declare const redact: (value: string) => string;
|
|
1513
2729
|
declare const VERSION = "0.0.0";
|
|
1514
|
-
export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, type FieldSnapshot, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, type QueryReadIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
|
|
2730
|
+
export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, 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, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, 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, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, 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, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, redact, refreshCodegenProject, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, validatorIrToJsonSchema };
|