@lunora/codegen 1.0.0-alpha.79 → 1.0.0-alpha.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-CQDN7BKc.mjs → FLAGS_FILENAME-UPE377GV.mjs} +1 -1
- package/dist/packem_shared/GENERATED_HEADER-BSvZOCvj.mjs +1 -0
- package/dist/packem_shared/{MUTATORS_FILENAME-3Akvs4aT.mjs → MUTATORS_FILENAME-CsAoG-d2.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-B2lXWa7r.mjs → NOTIFY_FILENAME-zA5OFFbv.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-BPT6vyLU.mjs → OPENRPC_VERSION-Dco0Fvm4.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-fCPRec_w.mjs +12 -0
- package/dist/packem_shared/{SHAPES_FILENAME-maut3z1K.mjs → SHAPES_FILENAME-DyVUZzIk.mjs} +1 -1
- package/dist/packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs +1 -0
- package/dist/packem_shared/{buildOpenApiDocument-D6xm3JqM.mjs → buildOpenApiDocument-CfLCgKoc.mjs} +1 -1
- package/dist/packem_shared/discover-queries-Ctpk9SA-.mjs +1 -0
- package/dist/packem_shared/{discoverAuthApiCalls-CEk3J0kc.mjs → discoverAuthApiCalls-CYdI8pkP.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-kIgM9ZJC.mjs → discoverCrons-CwtPaymU.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-CVYkUBTm.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-CLn3VDRI.mjs → discoverHttpRoutes-DmTedJlp.mjs} +1 -1
- package/dist/packem_shared/{discoverInserts-Cn-CLKET.mjs → discoverInserts-CssZuKb6.mjs} +1 -1
- package/dist/packem_shared/{discoverMaskProcedures-fZtvsy8v.mjs → discoverMaskProcedures-DQ-4yUUK.mjs} +1 -1
- package/dist/packem_shared/{discoverMigrations-BH_IKdFk.mjs → discoverMigrations-qyXaVjw1.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-Cl7qNL0J.mjs → discoverNondeterministicCalls-GNP4oKrf.mjs} +1 -1
- package/dist/packem_shared/discoverQueries-2A0lbpxV.mjs +1 -0
- package/dist/packem_shared/{discoverR2sqlCalls-CMNfDWlq.mjs → discoverR2sqlCalls-B7uqLnVS.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-Bf4_2S0t.mjs → discoverRlsMetadata-Bt0QK8VM.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-Bn1X9COt.mjs → discoverSandboxUsage-Bb2JzaIW.mjs} +1 -1
- package/dist/packem_shared/discoverSchema-DUl8rbP3.mjs +1 -0
- package/dist/packem_shared/{discoverStorageRulesMetadata-CL8J41rX.mjs → discoverStorageRulesMetadata-VJ_uXOFe.mjs} +1 -1
- package/dist/packem_shared/{emit-BtiV37rG.mjs → emit-B6-LPmOS.mjs} +187 -179
- package/dist/packem_shared/{emitApp-Bc3G4eki.mjs → emitApp-DGiGQ1P4.mjs} +17 -12
- package/dist/packem_shared/parse-validator-_jDrFxwt.mjs +1 -0
- package/dist/packem_shared/redact-6jD4lAhq.mjs +1 -0
- package/package.json +4 -4
- package/dist/packem_shared/GENERATED_HEADER-bdSyaxCS.mjs +0 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-FjKlVIV5.mjs +0 -5
- package/dist/packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs +0 -1
- package/dist/packem_shared/discover-queries-LfER8HbK.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-DnqHgv0t.mjs +0 -1
- package/dist/packem_shared/discoverQueries-B_2Ciq7P.mjs +0 -1
- package/dist/packem_shared/discoverSchema-Cy4OQ0Cu.mjs +0 -1
- package/dist/packem_shared/parse-validator-CSDlMEvE.mjs +0 -1
- package/dist/packem_shared/redact-CQ8-to6l.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as S,w as D}from"./emit-B6-LPmOS.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,m=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),v=e=>m.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],R=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],x=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],O=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,C=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],L=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],j=e=>{const{hasAccess:t,hasAuth:r,hasFramework:a,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:l,hasQueue:s,hasScheduler:u,hasStorage:d,hasWorkflow:h,useUmbrella:c,wantsOpenApi:p,wantsOpenRpc:b}=e,i=c?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","HttpRouterLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector"),a&&g.push("FrameworkHostHandler");const f=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...a?["withFrameworkWorker"]:[]].join(", ");return[...r?['import type { LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...R(t,r),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { createD1CtxDb, facetGlobalColumn, listGlobalTables, readGlobalTablePage } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...x(l),...u?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...d?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...h?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...C(e),`import type { ${[...g].toSorted((w,y)=>w.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${f} } from "${i}";`,"",...A(e.identity),...L(e),...n||o?['import schema from "../schema.js";']:[],...O(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},T=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
|
|
2
2
|
interface StorageDeclaration<Env> {
|
|
3
3
|
/** The default R2 bucket binding (the bare \`ctx.storage\`). */
|
|
4
4
|
bucket: Selector<Env, R2BucketLike>;
|
|
@@ -8,7 +8,7 @@ interface StorageDeclaration<Env> {
|
|
|
8
8
|
publicBaseUrl?: Selector<Env, string>;
|
|
9
9
|
/** HMAC secret for signed URLs. */
|
|
10
10
|
signingSecret?: Selector<Env, string>;
|
|
11
|
-
}`]:[],...e.hasScheduler?["/** `.scheduler(...)` declaration — the `SchedulerDO` namespace plus the worker origin its callbacks dispatch back to. Backs `ctx.scheduler` AND the studio's scheduled-jobs view. */\ninterface SchedulerDeclaration<Env> {\n /** The `SchedulerDO` namespace binding (typically `env.SCHEDULER`). */\n namespace: Selector<Env, DurableObjectNamespaceLike & ShardNamespaceLike>;\n /** The worker origin the `SchedulerDO` dispatches HTTP job callbacks back to. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasGlobal?["/** `.global(...)` declaration — the D1 binding backing `.global()` tables. Backs cross-tenant `ctx.db` reads/writes AND the studio's global data browser. */\ninterface GlobalDeclaration<Env> {\n /** The D1 binding (typically `env.DB`). */\n d1: Selector<Env, D1DatabaseLike>;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasHyperdriveGlobal?['/** `.hyperdriveGlobal(...)` declaration — backs `.global({ backend: "hyperdrive" })` tables on a Postgres/MySQL database via Hyperdrive. Stays reactive: the writer is injected as `globalDb` and the broadcast hook drives live queries. */\ninterface HyperdriveGlobalDeclaration<Env> {\n /** The Hyperdrive engine — selects the Postgres or MySQL dialect. */\n engine: HyperdriveEngine;\n /** Build the `SqlExec` from `env` — e.g. `buildPgExec(fromPostgresJs(postgres(env.HYPERDRIVE.connectionString)))`. Cache the driver on the DO instance; rebuild lazily after hibernation. */\n exec: (env: Env) => SqlExec;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}']:[],...e.hasAuth?['/** `.auth(...)` declaration — better-auth options plus the storage the adapter reads. Give it `d1` (the default) or `namespace` (a Durable Object that hosts the auth tables), never both. The builder owns the lazy build + `ensureMigrated` dance and wires `authHandler` / `resolveIdentity` / `authAdmin`. */\ninterface AuthDeclaration<Env> {\n /** The D1 binding the auth SQL adapter is wired over (via `lunoraD1Adapter`). Omit only when using `namespace`. */\n d1?: Selector<Env, unknown>;\n /** Shared secret the worker presents on the object\'s internal session route. REQUIRED with `namespace`: the binding is reachable from any worker bound to it, so the secret — not the binding — is the authorization boundary. Without it identity resolution fails closed. */\n internalSecret?: Selector<Env, string>;\n /** Name of the Durable Object instance holding the auth tables. Defaults to `"auth"`. Set it to run separate auth objects (per deployment, per tenant) off one namespace. */\n objectName?: Selector<Env, string>;\n /** The auth Durable Object namespace — the DO-backed mode. Needed for `@better-auth/scim`, which requires native transactions that D1 has none of. The object owns the auth tables, so `/api/auth/*` and identity resolution both go through it. */\n namespace?: Selector<Env, ShardNamespaceLike>;\n /** Build the better-auth options from `env` (secret, plugins, email/password, …). */\n options: (env: Env) => LunoraAuthOptions;\n}']:[]],
|
|
11
|
+
}`]:[],...e.hasScheduler?["/** `.scheduler(...)` declaration — the `SchedulerDO` namespace plus the worker origin its callbacks dispatch back to. Backs `ctx.scheduler` AND the studio's scheduled-jobs view. */\ninterface SchedulerDeclaration<Env> {\n /** The `SchedulerDO` namespace binding (typically `env.SCHEDULER`). */\n namespace: Selector<Env, DurableObjectNamespaceLike & ShardNamespaceLike>;\n /** The worker origin the `SchedulerDO` dispatches HTTP job callbacks back to. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasGlobal?["/** `.global(...)` declaration — the D1 binding backing `.global()` tables. Backs cross-tenant `ctx.db` reads/writes AND the studio's global data browser. */\ninterface GlobalDeclaration<Env> {\n /** The D1 binding (typically `env.DB`). */\n d1: Selector<Env, D1DatabaseLike>;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasHyperdriveGlobal?['/** `.hyperdriveGlobal(...)` declaration — backs `.global({ backend: "hyperdrive" })` tables on a Postgres/MySQL database via Hyperdrive. Stays reactive: the writer is injected as `globalDb` and the broadcast hook drives live queries. */\ninterface HyperdriveGlobalDeclaration<Env> {\n /** The Hyperdrive engine — selects the Postgres or MySQL dialect. */\n engine: HyperdriveEngine;\n /** Build the `SqlExec` from `env` — e.g. `buildPgExec(fromPostgresJs(postgres(env.HYPERDRIVE.connectionString)))`. Cache the driver on the DO instance; rebuild lazily after hibernation. */\n exec: (env: Env) => SqlExec;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}']:[],...e.hasAuth?['/** `.auth(...)` declaration — better-auth options plus the storage the adapter reads. Give it `d1` (the default) or `namespace` (a Durable Object that hosts the auth tables), never both. The builder owns the lazy build + `ensureMigrated` dance and wires `authHandler` / `resolveIdentity` / `authAdmin`. */\ninterface AuthDeclaration<Env> {\n /** The D1 binding the auth SQL adapter is wired over (via `lunoraD1Adapter`). Omit only when using `namespace`. */\n d1?: Selector<Env, unknown>;\n /** Shared secret the worker presents on the object\'s internal session route. REQUIRED with `namespace`: the binding is reachable from any worker bound to it, so the secret — not the binding — is the authorization boundary. Without it identity resolution fails closed. */\n internalSecret?: Selector<Env, string>;\n /** Name of the Durable Object instance holding the auth tables. Defaults to `"auth"`. Set it to run separate auth objects (per deployment, per tenant) off one namespace. */\n objectName?: Selector<Env, string>;\n /** The auth Durable Object namespace — the DO-backed mode. Needed for `@better-auth/scim`, which requires native transactions that D1 has none of. The object owns the auth tables, so `/api/auth/*` and identity resolution both go through it. */\n namespace?: Selector<Env, ShardNamespaceLike>;\n /** Build the better-auth options from `env` (secret, plugins, email/password, …). */\n options: (env: Env) => LunoraAuthOptions;\n}']:[]],q=e=>[...e.hasAccess?[" private accessSelector?: Selector<Env, CreateAccessResolverOptions>;"]:[]," private adminToken?: Selector<Env, string>;",...e.hasAuth?[" private authDeclaration?: AuthDeclaration<Env>;"]:[]," private readonly extendFns: ((env: Env, derived: Readonly<WorkerOptions>) => Partial<WorkerOptions>)[] = [];",...e.hasGlobal?[" private globalDeclaration?: GlobalDeclaration<Env>;"]:[],...e.hasHyperdriveGlobal?[" private hyperdriveGlobalDeclaration?: HyperdriveGlobalDeclaration<Env>;"]:[]," private httpRouterApp?: HttpRouterLike;"," private readonly routeMap: Record<string, Route> = {};",...e.hasScheduler?[" private schedulerDeclaration?: SchedulerDeclaration<Env>;"]:[],...v(e)?[" private readonly shardExtras: Partial<ShardConfig> = {};"]:[]," private shardSelector?: Selector<Env, ShardNamespaceLike>;",...e.hasStorage?[" private storageDeclaration?: StorageDeclaration<Env>;"]:[]],N=e=>m.filter(([t])=>e[t]).map(([,t,r,a])=>` /** ${a} */
|
|
12
12
|
public ${t}(factory: NonNullable<ShardConfig["${r}"]>): this {
|
|
13
13
|
this.shardExtras.${r} = factory;
|
|
14
14
|
|
|
@@ -33,7 +33,7 @@ interface StorageDeclaration<Env> {
|
|
|
33
33
|
this.emailHandler = handler;
|
|
34
34
|
|
|
35
35
|
return this;
|
|
36
|
-
}
|
|
36
|
+
}`," /** Mount a whole HTTP app (`httpRouter()` from `@lunora/server`, or anything with a `fetch`) ahead of Lunora's own routes. Use this for a multi-endpoint hono app with its own CORS + error handling; `.route()` is for one-off endpoints. */\n public httpRouter(app: HttpRouterLike): this {\n this.httpRouterApp = app;\n\n return this;\n }",` /** Mount a custom HTTP route (e.g. an asset-serving or test endpoint). Key is \`"METHOD path"\`, \`"path"\`, or a path prefix matched by the runtime. */
|
|
37
37
|
public route(key: string, handler: Route): this {
|
|
38
38
|
this.routeMap[key] = handler;
|
|
39
39
|
|
|
@@ -53,7 +53,7 @@ interface StorageDeclaration<Env> {
|
|
|
53
53
|
this.storageDeclaration = declaration;
|
|
54
54
|
|
|
55
55
|
return this;
|
|
56
|
-
}`]:[],...N(e)]
|
|
56
|
+
}`]:[],...N(e)],I=e=>{const t=[...e.hasGlobal?[` ...(this.globalDeclaration
|
|
57
57
|
? {
|
|
58
58
|
d1: (rawEnv: Record<string, unknown>, request?: { identity?: Record<string, unknown>; userId?: string | null }) => {
|
|
59
59
|
const env = rawEnv as Env;
|
|
@@ -113,7 +113,7 @@ interface StorageDeclaration<Env> {
|
|
|
113
113
|
: {}),`]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...v(e)?[" ...this.shardExtras,"]:[]];return t.length>0?`
|
|
114
114
|
${t.join(`
|
|
115
115
|
`)}
|
|
116
|
-
`:""}
|
|
116
|
+
`:""},$=e=>[...e.hasScheduler?[` if (this.schedulerDeclaration) {
|
|
117
117
|
options.schedulerDO = this.schedulerDeclaration.namespace(env);
|
|
118
118
|
}`]:[],...e.hasWorkflow?[` options.workflowsClient = (workflowEnv) => {
|
|
119
119
|
const source = workflowEnv as Record<string, unknown>;
|
|
@@ -190,7 +190,7 @@ ${t.join(`
|
|
|
190
190
|
}`]:[],...e.voiceAgents&&e.voiceAgents.length>0?[` options.voiceAgents = {
|
|
191
191
|
${e.voiceAgents.map(t=>` ${JSON.stringify(t.exportName)}: (env as Record<string, unknown>)[${JSON.stringify(t.bindingName)}] as ShardNamespaceLike,`).join(`
|
|
192
192
|
`)}
|
|
193
|
-
};`]:[]],G=e=>[" cronJobs: LUNORA_CRONS,"," functions: LUNORA_FUNCTIONS,",...e.identity?[` identity: lunoraIdentityContract.${e.identity.exportName},`]:[],...e.jurisdiction?[` jurisdiction: ${JSON.stringify(e.jurisdiction)},`]:[],...e.wantsOpenApi?[" openApiSpec,"]:[],...e.wantsOpenRpc?[" openRpcSpec,"]:[],...e.hasQueue?[" queue: (batch: unknown, queueEnv: unknown, _context: ExecutionContextLike): Promise<void> =>"," dispatchQueueBatch(batch as Parameters<typeof dispatchQueueBatch>[0], LUNORA_QUEUE_REGISTRY, {"," capture: shouldCaptureQueue(queueEnv as Record<string, unknown>)",` ? createQueueCaptureSink(queueEnv as Record<string, unknown>${e.jurisdiction?`, { jurisdiction: ${JSON.stringify(e.jurisdiction)} }`:""})`," : undefined,"," env: queueEnv as Record<string, unknown>,"," }),"]:[]," routes: this.routeMap,"," shardDO: this.shardSelector?.(env) ?? (undefined as unknown as ShardNamespaceLike),"],B=e=>e?`
|
|
193
|
+
};`]:[]],G=e=>[" cronJobs: LUNORA_CRONS,"," functions: LUNORA_FUNCTIONS,",...e.identity?[` identity: lunoraIdentityContract.${e.identity.exportName},`]:[],...e.jurisdiction?[` jurisdiction: ${JSON.stringify(e.jurisdiction)},`]:[],...e.wantsOpenApi?[" openApiSpec,"]:[],...e.wantsOpenRpc?[" openRpcSpec,"]:[],...e.hasQueue?[" queue: (batch: unknown, queueEnv: unknown, _context: ExecutionContextLike): Promise<void> =>"," dispatchQueueBatch(batch as Parameters<typeof dispatchQueueBatch>[0], LUNORA_QUEUE_REGISTRY, {"," capture: shouldCaptureQueue(queueEnv as Record<string, unknown>)",` ? createQueueCaptureSink(queueEnv as Record<string, unknown>${e.jurisdiction?`, { jurisdiction: ${JSON.stringify(e.jurisdiction)} }`:""})`," : undefined,"," env: queueEnv as Record<string, unknown>,"," }),"]:[]," ...(this.httpRouterApp ? { httpRouter: this.httpRouterApp } : {}),"," routes: this.routeMap,"," shardDO: this.shardSelector?.(env) ?? (undefined as unknown as ShardNamespaceLike),"],B=e=>e?`
|
|
194
194
|
/** Resolve the storage capability (single or multi-bucket) for the DO side. */
|
|
195
195
|
private resolveStorage(env: Env): Storage | undefined {
|
|
196
196
|
const declaration = this.storageDeclaration;
|
|
@@ -240,7 +240,12 @@ ${e.voiceAgents.map(t=>` ${JSON.stringify(t.exportName)}: (env as Rec
|
|
|
240
240
|
|
|
241
241
|
const make = (bucket: R2BucketLike): Storage =>
|
|
242
242
|
createStorage({ bucket, publicBaseUrl: declaration.publicBaseUrl?.(env), signingSecret: declaration.signingSecret?.(env) });
|
|
243
|
-
|
|
243
|
+
// Held separately from the map so \`pick\`'s fallback is a plain binding:
|
|
244
|
+
// under \`noUncheckedIndexedAccess\` a \`Record<string, Storage>\` lookup —
|
|
245
|
+
// including \`buckets.default\` — widens to \`Storage | undefined\`, which
|
|
246
|
+
// would not satisfy \`pick\`'s declared \`Storage\` return.
|
|
247
|
+
const fallbackStorage = make(defaultBucket);
|
|
248
|
+
const buckets: Record<string, Storage> = { default: fallbackStorage };
|
|
244
249
|
|
|
245
250
|
for (const [name, selector] of Object.entries(declaration.buckets ?? {})) {
|
|
246
251
|
const bucket = selector(env);
|
|
@@ -250,7 +255,7 @@ ${e.voiceAgents.map(t=>` ${JSON.stringify(t.exportName)}: (env as Rec
|
|
|
250
255
|
}
|
|
251
256
|
}
|
|
252
257
|
|
|
253
|
-
const pick = (name?: string): Storage => buckets[name !== undefined && name !== "" ? name : "default"] ??
|
|
258
|
+
const pick = (name?: string): Storage => buckets[name !== undefined && name !== "" ? name : "default"] ?? fallbackStorage;
|
|
254
259
|
const hasSigning = Boolean(declaration.publicBaseUrl?.(env) && declaration.signingSecret?.(env));
|
|
255
260
|
|
|
256
261
|
return {
|
|
@@ -292,7 +297,7 @@ const buildGlobalIntrospector = (database: D1DatabaseLike): GlobalIntrospector =
|
|
|
292
297
|
readTablePage: (options) => readGlobalTablePage(exec, schema as never, options),
|
|
293
298
|
};
|
|
294
299
|
};
|
|
295
|
-
`:"",U=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,r)=>t.localeCompare(r)).join(", "),F=e=>{const{hasAuth:t}=e,r=
|
|
300
|
+
`:"",U=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,r)=>t.localeCompare(r)).join(", "),F=e=>{const{hasAuth:t}=e,r=T(e),a=$(e),n=t?` let auth: LunoraAuth | null = null;
|
|
296
301
|
`:"",o=t?`
|
|
297
302
|
const ensureAuth = async (env: Env): Promise<void> => {
|
|
298
303
|
if (!this.authDeclaration || auth) {
|
|
@@ -323,7 +328,7 @@ ${c.map(i=>` { agent: lunoraAgentDefinitions.${i.exportName}, binding
|
|
|
323
328
|
`:"",b=` /** Materialise the standalone Cloudflare worker + \`ShardDO\` class. */
|
|
324
329
|
public build(): ComposedApp {
|
|
325
330
|
return this.assemble();
|
|
326
|
-
}${e.hasFramework?"\n\n /** Compose Lunora's realtime plane INTO a meta-framework's Cloudflare handler (SvelteKit/Astro/Nuxt). The framework `host` serves everything except the reserved `/_lunora/*` endpoints; pass the adapter-emitted worker (e.g. SvelteKit's `_worker.js`, Astro's `handle`). */\n public buildFrameworkWorker(host: FrameworkHostHandler): ComposedApp {\n return this.assemble(host);\n }":""}`;return`${D}${
|
|
331
|
+
}${e.hasFramework?"\n\n /** Compose Lunora's realtime plane INTO a meta-framework's Cloudflare handler (SvelteKit/Astro/Nuxt). The framework `host` serves everything except the reserved `/_lunora/*` endpoints; pass the adapter-emitted worker (e.g. SvelteKit's `_worker.js`, Astro's `handle`). */\n public buildFrameworkWorker(host: FrameworkHostHandler): ComposedApp {\n return this.assemble(host);\n }":""}`;return`${D}${j(e).join(`
|
|
327
332
|
`)}
|
|
328
333
|
|
|
329
334
|
/** Read a value off the per-request \`env\`. Returns \`undefined\` to leave the capability unconfigured (its \`ctx.*\`/admin surface stays a clear-error stub). */
|
|
@@ -348,7 +353,7 @@ interface ComposedApp extends LunoraWorker {
|
|
|
348
353
|
* first request so per-isolate singletons are built once.
|
|
349
354
|
*/
|
|
350
355
|
class AppBuilder<Env extends object> {
|
|
351
|
-
${
|
|
356
|
+
${q(e).join(`
|
|
352
357
|
`)}
|
|
353
358
|
|
|
354
359
|
private emailHandler?: (env: Env) => (message: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
@@ -361,7 +366,7 @@ ${b}
|
|
|
361
366
|
|
|
362
367
|
/** Build the shard DO + compose the worker (standalone or framework-hosted), wrapping the lazy per-isolate singletons + auth init. */
|
|
363
368
|
private assemble(${h}): ComposedApp {
|
|
364
|
-
const ShardDO = createShardDO({${
|
|
369
|
+
const ShardDO = createShardDO({${I(e)}});
|
|
365
370
|
|
|
366
371
|
// Per-isolate singletons: the worker (and auth instance) are expensive to
|
|
367
372
|
// build, so the first request constructs them and every later request on
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as c}from"@lunora/errors";import{Node as r}from"ts-morph";let l;const w=e=>{l=e},d=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","unique"]),k=(e,n)=>{const t={notNull:!0,...e.column};switch(n){case"$defaultFn":case"default":case"defaultNow":{t.hasDefault=!0;break}case"$onUpdateFn":{t.hasOnUpdate=!0;break}case"$type":break;case"nullable":{t.notNull=!1;break}case"unique":{t.unique=!0;break}}return{...e,column:t}},f=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),g=new Set(["check","meta"]),o=e=>r.isCallExpression(e)?N(e):{kind:"any",sourceText:e.getText()},m=e=>{const n={};for(const t of e.getProperties()){if(!r.isPropertyAssignment(t))continue;const s=t.getNameNode();if(r.isComputedPropertyName(s))continue;const i=t.getInitializer();if(!i)continue;const a=t.getName();if(!d.test(a))throw new c("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(a)}`);n[a]=o(i)}return n},u=(e,n)=>e&&r.isExpression(e)?o(e):n,y=e=>e===void 0?"undefined":r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),b=e=>{const n=e&&l?l(e):void 0;return n===void 0?{kind:"from"}:{kind:"from",tsType:n}},x=(e,n)=>{if(f.has(e))return{kind:e};const[t,s]=n;switch(e){case"array":return{inner:u(t,{kind:"any"}),kind:"array"};case"from":return b(t);case"id":return{kind:"id",tableName:t&&r.isStringLiteral(t)?t.getLiteralText():"_unknown_"};case"literal":return{kind:"literal",literalValue:y(t)};case"object":return t&&r.isObjectLiteralExpression(t)?{kind:"object",shape:m(t)}:{kind:"object",shape:{}};case"optional":return{inner:u(t,{kind:"any"}),kind:"optional"};case"record":return{keyType:u(t,{kind:"string"}),kind:"record",valueType:u(s,{kind:"any"})};case"storage":return t&&r.isStringLiteral(t)?{bucket:t.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:n.filter(i=>r.isExpression(i)).map(i=>o(i))};default:throw new c("INTERNAL",`Unsupported validator kind: ${e}`)}},N=e=>{const n=e.getExpression();if(!r.isPropertyAccessExpression(n))return{kind:"any",sourceText:e.getText()};const t=n.getName(),s=e.getArguments();if(p.has(t)){const i=n.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return k(a,t)}if(g.has(t)){const i=n.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return t==="check"?{...a,hasRefinement:!0}:a}return x(t,s)};export{m as c,w as p,o as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const s=/[\w+/=-]{40,}/u,a=/[a-z]/u,i=/[A-Z]/u,r=/\d/u,n=/\b(?:[\da-f]{32,}|[\dA-F]{32,})\b/u,d=e=>{const t=s.exec(e)?.[0];return t===void 0?!1:a.test(t)&&i.test(t)&&r.test(t)},k=e=>n.test(e),c=/\b(?:sk|rk)_live_[\dA-Za-z]{20,}/u,o=/\bAKIA[\dA-Z]{16}\b/u,u=/\bgh[posru]_[\dA-Za-z]{36,}/u,h=/\bsk-[\dA-Za-z]{32,}/u,_=/\bxox[abprs]-[\dA-Za-z-]{10,}/u,p=/-----BEGIN(?: [A-Z]+)? PRIVATE KEY-----/u,l=[{kind:"stripe_live_key",test:e=>c.test(e)},{kind:"aws_access_key",test:e=>o.test(e)},{kind:"github_token",test:e=>u.test(e)},{kind:"openai_key",test:e=>h.test(e)},{kind:"slack_token",test:e=>_.test(e)},{kind:"private_key",test:e=>p.test(e)},{kind:"high_entropy",test:d},{kind:"hex_secret",test:k}],A=new Set(["hex_secret","high_entropy"]),b=new Set(["auth","bearer","credential","credentials","hmac","key","keys","passphrase","password","private","secret","secrets","signature","signing","token"]),g=/([a-z\d])([A-Z])/gu,y=/[^A-Za-z\d]+/u,Z=e=>e.replaceAll(g,"$1 $2").split(y).filter(Boolean).map(t=>t.toLowerCase()),S=e=>e!==void 0&&Z(e).some(t=>b.has(t)),z=e=>l.find(t=>t.test(e))?.kind,E=e=>A.has(e),v=e=>`${e.slice(0,4)}…(${String(e.length)} chars)`;export{l as SECRET_RULES,E as isHeuristicSecretKind,S as isSecretishName,v as redact,z as secretKindOf};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.80",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.58",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.33",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.17",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.9",
|
|
53
53
|
"@lunora/platform": "1.0.0-alpha.1",
|
|
54
54
|
"@lunora/queue": "1.0.0-alpha.12",
|
|
55
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
55
|
+
"@lunora/scheduler": "1.0.0-alpha.15",
|
|
56
56
|
"@lunora/values": "1.0.0-alpha.12",
|
|
57
57
|
"@lunora/workflow": "1.0.0-alpha.14",
|
|
58
58
|
"jsonc-parser": "^3.3.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"@lunora/agent/component";import"@lunora/errors";import"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{w as r,n as o,H as n,h as l,b as p,Q as u,c,t as d,l as g,$ as C,G as E,f as S,v as A,r as D,d as f,K as h,u as b}from"./emit-BtiV37rG.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as buildStorageColumns,n as emitAgents,l as emitApi,p as emitCollections,u as emitContainers,c as emitCrons,d as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,E as emitQueues,S as emitSeed,A as emitServer,D as emitShard,f as emitVectors,h as emitWorkflows,b as emitWranglerCronTriggers};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as $e,mkdirSync as Bt,writeFileSync as Vt,rmSync as Ut}from"node:fs";import{join as g,dirname as pe}from"node:path";import{performance as me}from"node:perf_hooks";import{runAdvisor as Wt}from"@lunora/advisor";import{LunoraError as B}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Ze}from"ts-morph";import{serializeSchemaSnapshot as Gt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{toAdvisorContext as Ht}from"./formatAdvisories-BCEfzLT0.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as _t,procedureHandler as pt,chainUsesWrappedCall as mt,isDatabaseAccessor as C,chainHasStep as Qt,discoverFunctions as Jt}from"./discoverFunctions-DnqHgv0t.mjs";import{discoverAgents as Xt}from"./AGENTS_FILENAME-BesaDYkL.mjs";import{i as w,a as F,e as h,c as S,r as Zt,s as H,b as Yt,d as es,E as ts}from"./discover-queries-LfER8HbK.mjs";import ss from"./discoverAuthApiCalls-CEk3J0kc.mjs";import{discoverContainers as rs}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import ns from"./discoverCrons-kIgM9ZJC.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as Q}from"./module-specifiers-8FEEiUcv.mjs";import{a as xe,n as is,t as os,h as as,v as cs,$ as us,r as ls,b as ds,Q as gs,K as fs,H as ps,G as ms,c as xs,d as hs,l as Es,f as ys,u as $s}from"./emit-BtiV37rG.mjs";import{discoverFlagKeys as As}from"./FLAGS_FILENAME-CQDN7BKc.mjs";import Ss from"./discoverHttpRoutes-CLn3VDRI.mjs";import Ns from"./discoverInserts-Cn-CLKET.mjs";import vs,{discoverMaskStrategies as bs,discoverMaskMetadata as Ps}from"./discoverMaskProcedures-fZtvsy8v.mjs";import ws from"./discoverMigrations-BH_IKdFk.mjs";import{MUTATORS_FILENAME as Is,isDefineMutatorCallee as Ls,discoverMutators as Os}from"./MUTATORS_FILENAME-3Akvs4aT.mjs";import Fs from"./discoverNondeterministicCalls-Cl7qNL0J.mjs";import{discoverNotifyConfig as Ts,discoverNotifyCalls as Ds}from"./NOTIFY_FILENAME-B2lXWa7r.mjs";import{discoverQueues as Cs}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Ks from"./discoverR2sqlCalls-CMNfDWlq.mjs";import ks,{discoverRlsMetadata as Rs}from"./discoverRlsMetadata-Bf4_2S0t.mjs";import{discoverSandboxUsage as js}from"./discoverSandboxUsage-Bn1X9COt.mjs";import Ms from"./discoverSchema-Cy4OQ0Cu.mjs";import{secretKindOf as zs,redact as qs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as Bs}from"./SHAPES_FILENAME-maut3z1K.mjs";import Vs from"./discoverStorageRulesMetadata-CL8J41rX.mjs";import{e as Us}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ws}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as Gs}from"./emitApp-Bc3G4eki.mjs";import{buildOpenApiDocument as Hs,emitOpenApiModule as _s}from"./buildOpenApiDocument-D6xm3JqM.mjs";import{buildOpenRpcDocument as Qs,emitOpenRpcModule as Js}from"./OPENRPC_VERSION-BPT6vyLU.mjs";import{gatePlatformFeatures as Xs,resolveCodegenTarget as Zs}from"./DEFAULT_TARGET-BYPEwgZu.mjs";import{buildSchemaSnapshot as Ys}from"./SchemaSnapshotParseError-0KRzSjo4.mjs";const xt=new Set(["delete","get","head","options","patch","post","put"]),er=new Set(["handler","stream"]),tr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ye=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),sr=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!xt.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},rr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||xt.has(r.getName()))break;s=r.getExpression()}return sr(s)},nr=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ye.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ye.has(s.getText()))return!0}return!1},ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!er.has(r.getName()))return;const n=rr(s);if(!n||!tr.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&nr(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},or=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=ir(n,t);o&&s.push(o)}return s},ar=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...or(n,f(t,r)))}return s},cr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",ur=(e,t)=>{if(!cr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||F(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},lr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ur(r,t);n&&s.push(n)}return s},dr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...lr(n,f(t,r)))}return s},gr=new Set(["generateText","streamText"]),fr=new Set(["messages","prompt","system"]),pr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],mr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of pr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},xr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=mr(t);if(s!==void 0)return s}},hr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Er=e=>{if(Zt(e))return!0;const t=hr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},yr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!fr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Er(s))return!0}return!1},$r=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!gr.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(S(c.getExpression())==="tool"&&(a=xr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:yr(o)})}return s},Ar=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...$r(n,f(t,r)))}return s},Sr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Nr=(e,t)=>{if(!Sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},vr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Nr(r,t);n&&s.push(n)}return s},br=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...vr(n,f(t,r)))}return s},ht=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Pr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:ht(r)}},wr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=ht(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},Et=(e,t)=>t?wr(t):Pr(e),Ir=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Lr=/\.check\(|\.meta\(|length|max/iu,Or=/\bv\.any\s*\(/u,Fr=/\bv\.string\s*\(/u,Tr=e=>Or.test(e),Dr=e=>Fr.test(e)&&!Lr.test(e),Cr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Tr(a)?t.push(c):Dr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Kr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const{objects:n}=Et(s,r.receiver),{anyArgs:o,unboundedStringArgs:a}=Cr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},kr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Kr(n,t);o&&s.push(o)}return s},Rr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kr(n,f(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},he=e=>e?.getKind()===u.TrueKeyword,jr=e=>e?.getKind()===u.FalseKeyword,Mr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,zr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),qr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Br=e=>e!==void 0&&i.isCallExpression(e)&&zr.has(S(e.getExpression())??""),Vr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Ur=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:qr(N(e,"plugins"))&&Br(N(e,"database")),secureCookiesDisabled:jr(N(t,"useSecureCookies")),sessionFreshAgeZero:Mr(N(r,"freshAge")),trustedOriginsWildcard:Vr(N(e,"trustedOrigins"))}},Wr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Gr=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?Ur(s):Wr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Hr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Gr(r,t);n&&s.push(n)}return s},_r=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Hr(n,f(t,r)))}return s},Qr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Jr=(e,t,s)=>{const r=Qr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||F(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},Xr=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Jr(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Xr(o,f(t,n),s))}return r},Zr=new Set(["content","pdf","scrape","screenshot"]),Yr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Zr}),en=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),tn=new Set(["RateLimiter"]),sn=new Set(["extend"]),yt=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},et=e=>e&&i.isObjectLiteralExpression(e)?yt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},rn=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},nn=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?rn(e):void 0},on=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&nn(t.getBody());return s?yt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},an=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(en.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...et(r.getArguments()[0])}):sn.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...on(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!tn.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...et(r.getArguments()[0])})}return s},cn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...an(n,f(t,r)))}return s},tt="ctx.containers.",un=e=>{if(!e.startsWith(tt))return!1;const t=e.slice(tt.length);return t.length>0&&!t.includes(".")},ln=(e,t)=>J(e,t,{argIndex:0,matchReceiver:un,methods:new Set(["get"])}),dn=new Set(["allow","deny","setAllowed"]),gn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},fn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!gn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},pn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!dn.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},mn=(e,t)=>fn(e,t)??pn(e,t),xn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=mn(r,t);n&&s.push(n)}return s},hn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xn(n,f(t,r)))}return s},En="env.ts",yn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},$n=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&Q(r.getModuleSpecifierValue())}return!1},An=e=>{if(i.isIdentifier(e))return yn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&$n(t)}return!1},Sn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!An(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Nn=(e,t)=>{const s=g(t,En);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Sn(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},vn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),bn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return vn.has(s)?s:void 0},Pn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=bn(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?Pn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},In=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Ln=new Set(["dbRateLimit","rateLimit"]),On=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},Fn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Tn=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=In.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:On(e.getArguments()[r]),file:t,limitName:Ln.has(s)?Fn(e):"",line:e.getStartLineNumber()}},Dn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Tn(r,t);n&&s.push(n)}return s},Cn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Dn(n,f(t,r)))}return s},Kn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},kn=(e,t)=>{const s=Object.fromEntries(xe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Kn(n);for(const c of xe)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(xe.every(c=>s[c.key]))break}return s},Rn=["providerSubscriptionId","state"],jn=["providerEventId","processedAt"],st=(e,t)=>t.every(s=>s in e.shape),Mn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&st(t,Rn)&&st(s,jn)},zn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),qn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Bn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&qn(t.getExpression())},Vn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Un=(e,t)=>{if(!Bn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=Vn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},Wn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Un(r,t);n&&s.push(n)}return s},Gn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Wn(n,f(t,r)))}return s},Hn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},_n=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Qn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Hn(a)&&s.push({file:o,indexName:_n(a),line:a.getStartLineNumber()})}return s},Jn=new Set(["delete","get","head","options","patch","post","put"]),Xn=new Set(["handler","stream"]),Zn=new Set(["runAction","runMutation"]),Yn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,rt=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,nt=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},it=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Zn.has(a)&&U(c,t))return a;if(Yn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ot=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},ei=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Xn.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Jn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},ti=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=rt(e.getArguments()[0]),l=c&&nt(c,!0);if(!c||l===void 0)return;const p=it(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ot(c,l),sideEffect:p}}const r=ei(e);if(r===void 0)return;const n=rt(e.getArguments()[0]),o=n&&nt(n,!1);if(!n||o===void 0)return;const a=it(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ot(n,o),sideEffect:a}},si=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ti(r,t);n&&s.push(n)}return s},ri=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...si(n,f(t,r)))}return s},ni=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ii=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",$t=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",at=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>ni.has(Ae(s.getExpression()))&&es(s,t)),oi=(e,t)=>{if(at(e,t))return!0;const s=H(e);return s!==void 0&&at(s,t)},ye=(e,t)=>Yt(e,t)&&!oi(e,t),ai=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=H(e);return t!==void 0&&i.isNewExpression(t)&&Ae(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=H(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Se=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:$t(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&Se(n,t,s)}},At=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&Se(n,"response-init",t)},ci=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")At(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},ui=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){At(e.getArguments()[1],t);return}if(ii.has(r)&&ai(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:$t(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},li=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ci(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))ui(s,t)},di=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=_t(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return li(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},gi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...di(r,t));return s},fi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...gi(n,f(t,r)))}return s},St="identity.ts",pi=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},mi=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&Q(r.getModuleSpecifierValue())}return!1},xi=e=>{if(i.isIdentifier(e))return pi(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&mi(t)}return!1},hi=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!xi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Ei=(e,t)=>{const s=g(t,St);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=hi(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},yi=new Set(["auth","context.auth","ctx.auth"]),$i="userId",Ai=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Si=(e,t)=>{const s=g(t,St);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?Ai(o):void 0}},ct=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return yi.has(e.getExpression().getText())?e:void 0},Ni=e=>{if(i.isPropertyAccessExpression(e)&&ct(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&ct(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},vi=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=Ni(n);o!==void 0&&r.push({declared:o===$i||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},bi=(e,t)=>{const s=Si(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...vi(o,f(t,n),s))}return r},Pi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},wi=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Pi(s);if(!(!r||!w(r)||F(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ii=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=wi(r,t);n&&s.push(n)}return s},Li=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ii(n,f(t,r)))}return s},Oi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Fi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Oi}),Ti=new Set(["queue","send"]),ut=new Set(["bcc","cc","to"]),Di=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ti.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Ci=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return ut.has(t.getName())&&w(r)&&!F(r)}if(!i.isPropertyAssignment(t)||!ut.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!F(s)}):!1,Ki=(e,t)=>{const s=Di(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Ci(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},ki=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ki(r,t);n&&s.push(n)}return s},Ri=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ki(n,f(t,r)))}return s},ji=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Mi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},zi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return Ls(s.getExpression())?s:void 0},qi=e=>{const t=zi(e),s=t===void 0?void 0:Mi(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>ji(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Bi=e=>e.getVariableDeclarations().flatMap(t=>qi(t)),Vi=(e,t)=>{const s=g(t,Is);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Bi(r)},Ui=new Set(["delete","get","patch"]),Wi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Gi=new Set(["auth","identity","session","user"]),Hi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),_i=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!C(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Qi=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Ji=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Xi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Zi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Ji(s.getExpression(),t)&&Xi(s.getThenStatement())),Yi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Ui.has(n))continue;const o=r.getExpression();if(!(C(o)||i.isPropertyAccessExpression(o)&&C(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},eo=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},to=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>eo(s)==="ctx")),so=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Hi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),ro=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Wi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Gi.has(t.getName()))return!0}return to(e)||so(e)},no=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=pt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&mt(r.receiver,"use","rls"),a=ro(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=_i(p);if(y===void 0)continue;const I=Qi(p);if(I===void 0||c.has(I)||!Zi(n,I))continue;const k=Yi(n,I);k!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:k,table:y,usesRls:o,visibility:r.visibility}))}return l},io=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...no(c,o))}return s},oo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),ao=new Set(["insert","insertManyUnsafe","patch","replace"]),co=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ao.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},uo=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},lo=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!oo.has(a))&&w(c)&&!F(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},go=(e,t)=>{const s=co(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?uo(r,s).flatMap(n=>lo(n,s,e,t)):[]},fo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...go(r,t));return s},po=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...fo(n,f(t,r)))}return s},mo=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse($e(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},xo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),ho=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Eo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?ho(t.getInitializer()):void 0},yo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!xo.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?Eo(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},$o=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...yo(n,f(t,r)))}return s},Ao=new Set(["defineQueue","defineWorkflow"]),So=new Set(["run","runAction","runMutation","runQuery"]),No=new Set(["api","internal"]),vo=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},bo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},Nt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},vt=(e,t)=>e===t||e.startsWith(`${t}.`),bt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},lt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},Pt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>lt(s));return i.isIdentifier(e)&<(e)&&t.push(e),t},Po=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},wo=e=>{const t=Nt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Io=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:wo(e),n=new Set,o=a=>bt(a).some(c=>r.some(l=>vt(c.getText(),l)))?!0:Pt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Po(a))n.add(l)}return{names:n,prefixes:r}},Lo=(e,t)=>bt(e).some(s=>t.prefixes.some(r=>vt(s.getText(),r)))?!0:Pt(e).some(s=>t.names.has(s.getText())),Oo=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!No.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Fo=(e,t,s)=>{const r=Nt(e,0);if(r===void 0)return[];const n=Io(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!So.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!Lo(l,n))continue;const p=Oo(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},To=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=vo(r);if(n===void 0||!Ao.has(n))continue;const o=bo(r);o!==void 0&&s.push(...Fo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Do=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...To(n,f(t,r)))}return s},dt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Co=/account|credential|member|passkey|session|user/iu,Ko=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},ko=(e,t)=>{const{objects:s,opaque:r}=Et(e,t);return Ir(s).some(n=>Ko(n))?!0:r?void 0:!1},Ne=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Ro=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},jo=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Mo=e=>{const t=jo(e),s=t?Ne(t):void 0;if(t&&s==="protectPublic"){const r=Ro(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in dt?{...V,[dt[s]]:!0}:V},zo=e=>{const t={...V};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=Mo(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&Co.test(r.getLiteralText()))},Bo=new Set(["create","runAfter","runAt","send","sendBatch"]),Vo=new Set(["queues","scheduler","workflows"]),Uo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Bo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Vo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Wo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},wt=new Set(["generateObject","generateText","streamObject","streamText"]),Go=e=>{const t=Ne(e);return t!==void 0&&wt.has(t)},Ho=e=>{const t=Ne(e);if(t===void 0||!wt.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},_o=new Set(["log","span","trace"]),Qo=new Set(["ai"]),Jo=new Set(["email","mail"]),Xo=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),q=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Zo=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="Error"}),gt="lunora-advisor-exempt",Yo=/^[\s*/]+/u,ea=/[\w-]/u,ta=e=>{const t=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
|
|
2
|
-
`);for(const s of t.split(`
|
|
3
|
-
`)){const r=s.replace(Yo,"");if(!r.startsWith(gt))continue;const n=r.slice(gt.length);if(ea.test(n.charAt(0)))continue;const o=n.indexOf("--");return{exempt:!0,exemptReason:(o===-1?"":n.slice(o+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},sa=e=>{let t=!1,s=!1,r=!1,n=!1,o=!1;for(const a of e.getDescendantsOfKind(u.CallExpression))if(qo(a)&&(o=!0),Uo(a)&&(t=!0),Wo(a)&&(n=!0),Go(a)&&(s=!0),Ho(a)&&(r=!0),o&&t&&n&&r)break;return{callsMail:q(e,Jo),emitsEvent:q(e,_o),fanOut:t,handlesErrors:e.getDescendantsOfKind(u.TryStatement).length>0,reachesOutbound:q(e,Xo),runsAiGeneration:s||q(e,Qo),throwsBareError:Zo(e),unboundedAiGeneration:r,usesInsertManyUnsafe:n,writesUserTable:o}},ra=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?zo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1};return{...sa(e),...ta(e),...n,exportName:e.getName(),file:t,hasEmailArg:ko(s,r.receiver),kind:r.kind,visibility:r.visibility}},na=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=ra(n,t);o&&s.push(o)}return s},ia=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...na(n,f(t,r)))}return s},oa=new Set(["dbRateLimit","rateLimit"]),aa=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ca=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},ua=e=>i.isArrowFunction(e)?e.getBody():e,la=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!oa.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=aa(r);if(!n)return;const o=ua(n);if(!(!w(o)||F(o)))return{callee:s,exportName:h(e),file:t,limitName:ca(e),line:e.getStartLineNumber()}},da=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=la(r,t);n&&s.push(n)}return s},ga=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...da(n,f(t,r)))}return s},fa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),pa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!fa.has(t.getName()))return;const s=t.getExpression();if(C(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&C(s.getExpression()))return s.getName()},ma=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&C(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},xa=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},It=(e,t=!1)=>{const s=xa(e);if(i.isIdentifier(s)){if(t)return;const r=H(s);return r===void 0?void 0:It(r,!0)}if(i.isCallExpression(s))return pa(s)??ma(s)},ha=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},Ea=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=pt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Qt(r.receiver,"output"),a=r.receiver!==void 0&&mt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of ha(n)){const y=It(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ya=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ea(c,o))}return s},$a=new Set(["findFirst","findFirstOrThrow","findMany"]),Aa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!$a.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Sa=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},Na=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},va=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=Aa(o);if(a===void 0)continue;const c=Sa(Na(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...va(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Pa=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},wa=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(Pa(o))continue;const a=G(o);if(a===void 0)continue;const c=zs(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:qs(a)}))}return s},Ia=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...wa(n,f(t,r)))}return s},La=new Set(["findFirst","findFirstOrThrow","findMany"]),Oa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!La.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Fa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},Ta=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=Oa(o);if(a===void 0)continue;const c=Fa(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Da=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ta(c,o))}return s},Ca=new Set(["query","unsafe"]),Ka=e=>{if(!i.isPropertyAccessExpression(e)||!Ca.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},ka=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ra=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ja=(e,t)=>{if(!Ka(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ka(s)))return{exportName:Ra(e),file:t,line:s.getStartLineNumber()}},Ma=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ja(r,t);n&&s.push(n)}return s},za=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ma(n,f(t,r)))}return s},qa=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Ba=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:qa}),Va=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ua=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Wa=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Ua(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},Ga=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Va.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Ha=(e,t)=>{const s=Ga(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Wa(e.getArguments()[s.optionsIndex])}},_a=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ha(r,t);n&&s.push(n)}return s},Qa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(..._a(n,f(t,r)))}return s},Ja=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),Xa=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return Ee.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return Ee.has(n)?n:void 0}const s=t.getText();return Ee.has(s)?s:void 0},Za=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Lt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Za(e))return"empty-object";if(i.isParenthesizedExpression(e))return Lt(e.getExpression())}},Ot=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Ft=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ot(t)===e),Tt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ot(t)===e),Ya=e=>{const t=Ft(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Tt(e).length>0},ec=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Ft(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Tt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},tc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},sc=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!Ja.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ya(a))for(const c of ec(a)){const l=Lt(c);l!==void 0&&n.push({exportName:tc(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},rc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Xa(r);n!==void 0&&s.push(...sc(r,n,t))}return s},nc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...rc(n,f(t,r)))}return s},ic=new Set(["query","upsert","upsertMany"]),oc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(ic.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},ac=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},cc=(e,t)=>{const s=oc(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=ac(r);if(!(!n||!w(n)||F(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},uc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=cc(r,t);n&&s.push(n)}return s},lc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...uc(n,f(t,r)))}return s},dc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},gc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},fc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!dc(a))continue;const c=Us(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:gc(a)})}}return s},pc=".lunora-schema.json",A=(e,t)=>{E(e)&&$e(e,"utf8")===t||Vt(e,t,"utf8")},P=(e,t)=>{if(t===""){Ut(e,{force:!0});return}A(e,t)},mc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse($e(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},xc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},hc=e=>{let t=E(e)?e:pe(e);for(;t&&t!==pe(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=pe(t)}},ft=e=>e.replaceAll("\\","/"),Ec=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new B("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new B("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new B("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},yc=e=>{const t=hc(e);return t?new Ze({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ze({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},ou=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>ft(c))),o=ft(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},au=e=>{const t=xc(),s=t?me.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new B("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??yc(r),a=Ms(o,n,e.projectRoot),c=Jt(o,r),l=Ss(o,r),p=ws(o,r),y=Bs(o,r),I=Os(o,r),k=Ei(o,r),ve=Nn(o,r),v=Ws(o,r),T=Cs(o,r),b=Xt(o,r);Ec(v,b);const X=ns(o,r,v,b),D=rs(o,r),R=e.lint===!1?void 0:Ht({adminRoutes:ar(o,r),aiRawRuns:dr(o,r),aiToolSideEffects:Ar(o,r),argumentDerivedFetches:br(o,r),argumentValidators:Rr(o,r),authApiCalls:ss(o,r),authConfigs:_r(o,r),browserUrlAccesses:Yr(o,r),configCalls:cn(o,r),containerKeyAccesses:ln(o,r),containerOverrides:hn(o,r),containers:D,exportSinks:wn(o,r),failOpenGuards:Cn(o,r),flagSecurityDefaults:Gn(o,r),geoIndexUsages:Qn(o,r),httpActionGuards:ri(o,r),httpHeaderWrites:fi(o,r),identityClaimReads:bi(o,r),imageDeliveryUrlAccesses:Li(o,r),inserts:Ns(o,r),kvKeyAccesses:Fi(o,r),mailRecipientAccesses:Ri(o,r),maskProcedures:vs(o,r),maskStrategies:bs(o,r),mutatorWrites:Vi(o,r),nondeterministicCalls:Fs(o,r),normalizeIdAuthorizations:io(o,r),notifyCalls:Ds(o,r),notifyConfig:Ts(o,r),ownerFieldWrites:po(o,r),unrestrictedWhereBranches:nc(o,r),paymentWebhooks:$o(o,r),privilegedDispatches:Do(o,r),procedureProtections:ia(o,r),queries:ts(o,r),queues:T,r2sqlCalls:Ks(o,r),ratelimitKeySelectors:ga(o,r),rawRowReturns:ya(o,r),relationLoads:ba(o,r),rlsProcedures:ks(o,r),schema:a,secretLiterals:Ia(o,r),shapes:y,softDeleteReads:Da(o,r),sqlInterpolations:za(o,r),storageKeyAccesses:Ba(o,r),storageUploads:Qa(o,r),vectorNamespaceAccesses:lc(o,r),workflowCalls:fc(o,r),workflows:v,wranglerVariables:e.wranglerVariables}),be=R===void 0?[]:Wt(R,{source:"static"}),Dt=Rs(o,r),Ct=Ps(o,r),Z=Vs(o,r),Kt=kn(o,r),Pe=Xs(Kt,Zs(e.projectRoot,e.target)),$=Pe.usage,Y=$.ai,ee=$.payments,we=$.kv,Ie=$.access,te=E(g(r,"flags.ts")),kt=te?As(o,r):[],se=E(g(r,"notify.ts")),re=$.hyperdrive,ne=js(o,r),Rt=ne.usesSandboxBrowser||ne.usesSandboxContainer,ie=$.browser||ne.usesSandboxBrowser,oe=$.images,ae=$.analytics,Le=$.pipelines,ce=$.r2sql,ue=$.x402,L=mo(e.projectRoot),j=zn($,{containerCount:D.length,cronCount:X.length,dependencies:L,hasPaymentTables:Mn(a.tables),queueCount:T.length,storageColumnCount:Object.keys(is(a)).length,storageRuleCount:Z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:v.length}),O=L.has("lunorash"),Oe=t?me.now():0,Fe=os(a,O),Te=as({agents:b,functions:c,httpRoutes:l,mutators:I,useUmbrella:O,workflows:v}),De=cs({agents:b,containers:D,env:ve,hasAccessFacade:Ie,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:we,hasNotify:se,hasPayments:ee,hasPipelines:Le,hasR2sql:ce,hasX402:ue,identity:k,queues:T,schema:a,storageRuleBuckets:Z.rules.map(m=>m.bucket),useUmbrella:O,workflows:v}),Ce=us({agents:b,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:O,usesSandbox:Rt}),le=Ys(a,p.map(m=>m.id)),Ke=ls({advisories:be,advisorProcedures:R?.procedureProtections??[],agents:b,containers:D,env:ve,flagKeys:kt,hasAccessFacade:Ie,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:we,hasNotify:se,hasPayments:ee,hasPipelines:Le,hasR2sql:ce,hasX402:ue,maskMetadata:Ct,mutators:I,queues:T,rlsMetadata:Dt,schema:a,schemaSnapshot:le,shapes:y,storageRules:Z,studioFeatures:j,useUmbrella:O,workflows:v}),ke=ds(y,L.has("@lunora/db"),O),Re=gs(D,a.jurisdiction),je=fs(v),Me=ps(b),ze=ms(T),qe=xs(X),Be=hs(a.vectorIndexes),M=Es(a,O),Ve=ys(L.has("@lunora/seed")),z=e.apiSpec??"openapi",de=z==="openapi"||z==="both",ge=z==="openrpc"||z==="both",Ue=Gs({emailAgents:b.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:L.has("@lunora/cloudflare-access"),hasAi:Y,hasAnalytics:ae,hasAuth:L.has("@lunora/auth"),hasBrowser:ie,hasFramework:L.has("@lunora/astro")||L.has("@lunora/svelte")||L.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:re,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:oe,hasKv:j.kv,hasNotify:se,hasPayments:ee,hasR2sql:ce,hasQueue:T.some(m=>m.mode==="push"),hasScheduler:j.scheduler,hasStorage:j.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:v.length>0,hasX402:ue,identity:k,jurisdiction:a.jurisdiction,useUmbrella:O,voiceAgents:b.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:de,wantsOpenRpc:ge}),We=mc(e.projectRoot),Ge=Hs({functions:c,httpRoutes:l,version:We}),He=Qs({functions:c,version:We}),_e=`${JSON.stringify(Ge,void 0,2)}
|
|
4
|
-
`,Qe=`${JSON.stringify(He,void 0,2)}
|
|
5
|
-
`,Je=_s(Ge),Xe=Js(He),fe=g(r,pc),jt=E(fe),x=g(r,"_generated");if(e.dryRun||(E(x)||Bt(x,{recursive:!0}),A(g(x,"app.ts"),Ue),A(g(x,"dataModel.ts"),Fe),A(g(x,"api.ts"),Te),A(g(x,"server.ts"),De),A(g(x,"functions.ts"),Ce),A(g(x,"shard.ts"),Ke),A(g(x,"crons.ts"),qe),A(g(x,"vectors.ts"),Be),A(g(x,"drizzle.global.ts"),M.global),A(g(x,"drizzle.shard.ts"),M.shard),P(g(x,"containers.ts"),Re),P(g(x,"workflows.ts"),je),P(g(x,"agents.ts"),Me),P(g(x,"queues.ts"),ze),P(g(x,"seed.ts"),Ve),P(g(x,"collections.ts"),ke),P(g(x,"openapi.json"),de?_e:""),P(g(x,"openapi.ts"),de?Je:""),P(g(x,"openrpc.json"),ge?Qe:""),P(g(x,"openrpc.ts"),ge?Xe:""),(!jt||e.updateSchemaBaseline===!0)&&A(fe,Gt(le))),t){const m=me.now(),Mt=Math.round(m-s),zt=Math.round(Oe-s),qt=Math.round(m-Oe);console.error(`@lunora/codegen: codegen took ${Mt.toString()}ms (discovery ${zt.toString()}ms, emit ${qt.toString()}ms)`)}return{advisories:be,advisorContext:R,agents:b,containers:D,cronTriggers:$s(X),generated:{agents:Me,api:Te,app:Ue,collections:ke,containers:Re,crons:qe,dataModel:Fe,drizzleGlobal:M.global,drizzleShard:M.shard,functions:Ce,openApi:_e,openApiModule:Je,openRpc:Qe,openRpcModule:Xe,queues:ze,seed:Ve,server:De,shard:Ke,vectors:Be,workflows:je},outputDirectory:x,platformDiagnostics:Pe.diagnostics,queues:T,schemaSnapshot:le,schemaSnapshotPath:fe,workflows:v}};export{pc as SCHEMA_SNAPSHOT_FILENAME,yc as createCodegenProject,ou as refreshCodegenProject,au as runCodegen};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as m}from"node:fs";import{join as p}from"node:path";import{LunoraError as l}from"@lunora/errors";import{workflowDefaultName as c,workflowClassName as u,workflowBindingName as g}from"@lunora/workflow";import{Node as i,SyntaxKind as d}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-DPezpZTz.mjs";const w="workflows.ts",x=new Set(["do","sleep","sleepUntil","waitForEvent"]),N=o=>{const e=o.getSymbol();if(!e)return o.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},b=(o,e,t)=>{if(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue();throw a(o,`workflow "${e}": \`${t}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},E=o=>{const e=o.getExpression();if(!i.isPropertyAccessExpression(e)||!x.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},h=o=>{const e=o.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const r=[];for(const n of t.getDescendantsOfKind(d.CallExpression)){if(!E(n))continue;const s=n.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||r.push({line:n.getStartLineNumber(),method:n.getExpression().getName(),name:s.getLiteralValue()})}return r},k=(o,e)=>{const t=o.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))throw a(o,`workflow "${e}": defineWorkflow must be passed an inline object literal`);const r={bindingName:g(e),className:u(e),exportName:e,name:c(e),steps:h(t)},n=t.getProperty("name");return n&&i.isPropertyAssignment(n)&&(r.name=b(n.getInitializerOrThrow(),e,"name")),r},S=o=>{let e=o;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e&&i.isCallExpression(e)?e:void 0},y=o=>{const e=[];for(const t of o.getVariableDeclarations()){if(!t.isExported())continue;const r=S(t.getInitializer());if(!r)continue;const n=r.getExpression();if(!i.isIdentifier(n)||!N(n))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw a(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(k(r,s.getText()))}return e},L=o=>{const e=new Map,t=new Map;for(const r of o){const n=e.get(r.name);if(n!==void 0)throw new l("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${r.name}": produced by both "${n}" and "${r.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(r.name,r.exportName);const s=t.get(r.bindingName);if(s!==void 0)throw new l("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${r.bindingName}": produced by both "${s}" and "${r.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(r.bindingName,r.exportName)}},T=(o,e)=>{const t=p(e,w);if(!m(t))return[];const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),n=y(r);return n.sort((s,f)=>s.exportName.localeCompare(f.exportName)),L(n),n};export{w as WORKFLOWS_FILENAME,T as discoverWorkflows};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as A}from"./discoverFunctions-DnqHgv0t.mjs";const p=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return s.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(s.isPropertyAssignment(t)&&t.getNameNode()===e)},m=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return s.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(s.isPropertyAssignment(t)&&t.getNameNode()===e)},g=e=>s.isIdentifier(e)?m(e):e.getDescendantsOfKind(a.Identifier).some(t=>m(t)),x=(e,t)=>{if(e.getText()!==t)return!1;const r=e.getParent();return s.isPropertyAccessExpression(r)&&r.getNameNode()===e?!1:!(s.isPropertyAssignment(r)&&r.getNameNode()===e)},I=e=>{let t=e;for(;s.isPropertyAccessExpression(t)||s.isElementAccessExpression(t)||s.isNonNullExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t:void 0},F=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e))return e.getName()},N=e=>s.isIdentifier(e)?p(e):e.getDescendantsOfKind(a.Identifier).some(t=>p(t)),u=e=>{if(!s.isIdentifier(e))return;const t=e.getText(),r=e.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(r===void 0)return;const n=e.getStart();let i,d=-1;for(const o of r.getDescendantsOfKind(a.VariableDeclaration)){if(o.getName()!==t)continue;const c=o.getInitializer(),f=o.getStart();c!==void 0&&f<n&&f>d&&(i=c,d=f)}return i},K=e=>{if(N(e))return!0;const t=u(e);return t!==void 0&&N(t)},T=e=>{if(g(e))return!0;const t=u(e);if(t!==void 0&&g(t))return!0;const r=t??e;return(s.isIdentifier(r)?[r]:r.getDescendantsOfKind(a.Identifier)).some(n=>{const i=u(n);return i!==void 0&&g(i)})},l=(e,t)=>s.isIdentifier(e)?x(e,t):e.getDescendantsOfKind(a.Identifier).some(r=>x(r,t)),O=(e,t)=>{if(l(e,t))return!0;const r=u(e);if(r!==void 0&&l(r,t))return!0;const n=I(e);if(n!==void 0){const i=u(n);return i!==void 0&&l(i,t)}return!1},P=e=>{for(const t of e.getAncestors())if(s.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},y=new Set(["withIndex","withSearchIndex"]),h=e=>{const t=e.getExpression();if(!s.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const r=t.getExpression();return s.isPropertyAccessExpression(r)?r.getName()==="db":s.isIdentifier(r)&&r.getText()==="db"},v=e=>{const t=[];let r=e;for(;;){const n=r.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;t.push(n.getName()),r=i}return t},S=e=>{const t=e.getArguments()[0];return t&&s.isStringLiteral(t)?t.getLiteralText():""},w=(e,t)=>{const r=[];for(const n of E(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),d=A(t,n);for(const o of i.getDescendantsOfKind(a.CallExpression)){if(!h(o))continue;const c=v(o);c.includes("filter")&&r.push({exportName:P(o),file:d,hasFilter:!0,hasIndex:c.some(f=>y.has(f)),line:o.getStartLineNumber(),table:S(o)})}}return r};export{w as E,T as a,O as b,F as c,l as d,P as e,K as i,N as r,u as s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readdirSync as w,lstatSync as D}from"node:fs";import{join as F,extname as C,relative as L,sep as O}from"node:path";import{Node as s,SyntaxKind as j}from"ts-morph";import{t as z}from"./module-specifiers-8FEEiUcv.mjs";import{d as A}from"./parse-validator-CSDlMEvE.mjs";import{n as U}from"./paths-BmX5O1sG.mjs";const y=new Set(["action","mutation","query","stream"]),V=/\bany\b(?!\s*(?:\?\s*)?:)/u,_=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,R=/^[A-Za-z_$][\w$]*$/u,M=e=>R.test(e)?e:JSON.stringify(e),H=/\.ts$/u,B=(e,t)=>L(e,t).split(O).join("/").replace(H,""),h={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},W={onConnect:"connect",onDisconnect:"disconnect"},q=z,P=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return q(n)?r.getNameNode().getText():void 0}},N=(e,t=!1)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!s.isIdentifier(i))return;const r=P(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?N(o,!0):void 0}return}return y.has(r)?"public":h[r]?"internal":void 0},d=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},J=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=d(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=d(i,"tag"),c=d(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},K=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=J(e),i=e.getProperty("rest");return i!==void 0&&s.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},Q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return K(t.getArguments()[0]);t=i.getExpression()}},G=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!s.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:A(r)},Z=(e,t)=>{for(const i of[e.getSymbol(),e.getAliasSymbol()])if(i)for(const r of i.getDeclarations()){const n=r.getSourceFile();if(!(n.isInNodeModules()||n.isDeclarationFile())&&n.getFilePath()===t&&(s.isInterfaceDeclaration(r)||s.isTypeAliasDeclaration(r))&&!r.isExported())return!0}return!1},X=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},S=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),Z(e,i)||X(e).some(n=>p(n,t,i,r))?!0:S(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),Y=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(s.isPropertySignature(i)||s.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},ee=8,te=(e,t,i,r,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},ie=(e,t,i,r,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},re=(e,t,i,r,n,o)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),m=Y(c,l),$=m&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],x=[];for(const f of $){const v=o(f,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${M(c.getName())}${m?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>ee||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?te(e,t,i,r,o,g):e.isUnion()?ie(e,t,i,r,o,g):re(e,t,i,r,o,g)},T=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const r=(i.getSymbol()??i.getAliasSymbol())?.getName();if(r==="Promise"||r==="AsyncIterable"||r==="AsyncIterableIterator"||r==="AsyncGenerator"){const a=i.getTypeArguments()[0];a&&(i=a)}const n=i.getText(e);if(!n||n==="any"||n==="never"||V.test(n.replaceAll(_,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},ne=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":T(r)},se=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":T(t)},oe=e=>{let t={},i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...A(n),...t})}i=r.getExpression()}return t},ae=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!y.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=N(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=P(t);if(!i)return;if(y.has(i))return{kind:i,visibility:"public"};const r=h[i];if(r)return{kind:r,visibility:"internal"};const n=W[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},b=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,Ae=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",he=e=>{const t=e.getArguments()[0],i=b(t);if(i!==void 0)return i;if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&s.isPropertyAssignment(r)?b(r.getInitializer()):void 0},ce=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Pe=(e,t)=>{let i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},Ne=(e,t,i)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=r.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&ce(o.getExpression())===i)return!0;r=n.getExpression()}return!1},I=(e,t=[],i=e)=>{let r;try{r=w(e)}catch{return t}for(const n of r){const o=F(e,n),a=D(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;I(o,t,i)}else if(a.isFile()&&C(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},le=e=>{const t=ae(e);if(t){if(t.receiver){const i=Q(t.receiver);return{args:oe(t.receiver),...i?{expose:i}:{},kind:t.kind,returnType:se(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:G(e),kind:t.kind,returnType:ne(e),visibility:t.visibility}}},ue=8,u=(e,t=0)=>{if(t>ue)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?k(i,t+1):void 0},k=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(j.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?k(r,t+1):void 0}},ge=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const i=e.getInitializer(),r=i&&(s.isCallExpression(i)?i:u(i));return r?[[e.getName(),r]]:[]},pe=(e,t,i)=>{const r=le(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},fe=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ge(n)){const c=pe(a,o,t);c&&i.push(c)}return i},de=e=>{const t=new Map;for(const i of e){const r=U(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},Se=(e,t)=>{const i=I(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=B(t,n);r.push(...fe(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),de(r),r};export{Pe as chainHasStep,Ne as chainUsesWrappedCall,ae as classifyProcedureCall,Se as discoverFunctions,b as inlineHandler,Ae as isDatabaseAccessor,I as listLunoraSourceFiles,B as lunoraRelativePath,he as procedureHandler,T as unwrapHandlerReturn};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"ts-morph";import{E as p}from"./discover-queries-LfER8HbK.mjs";import"./discoverFunctions-DnqHgv0t.mjs";export{p as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as j}from"@lunora/errors";import{Node as s,SyntaxKind as w}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{d as T}from"./parse-validator-CSDlMEvE.mjs";import{createRequire as N}from"node:module";import{join as O}from"node:path";const _=e=>{switch(typeof e){case"bigint":return e.toString();case"boolean":case"number":return String(e);case"string":return JSON.stringify(e);default:return e===null?"null":void 0}},$=e=>({...e?.defaultValue!==void 0||e?.defaultFn!==void 0||e?.serverDefault!==void 0?{hasDefault:!0}:{},...e?.onUpdateFn===void 0?{}:{hasOnUpdate:!0},notNull:e?.notNull??!0,...e?.unique===!0?{unique:!0}:{}}),g=e=>{const r=e?._meta??{},t=e?.kind??"unknown",n={column:$(r.column),kind:t};switch(t){case"array":case"optional":{n.inner=g(r.inner);break}case"id":{n.tableName=r.tableName;break}case"literal":{n.literalValue=_(r.value);break}case"object":{const i=r.shape??{};n.shape=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,g(a)]));break}case"record":{n.valueType=g(r.valueValidator),r.keyValidator!==void 0&&(n.keyType=g(r.keyValidator));break}case"storage":{typeof r.bucket=="string"&&(n.bucket=r.bucket);break}case"union":{const i=r.members??[];n.members=i.map(o=>g(o));break}}return n},M=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",z=(e,r)=>{const t=[];e.relationMap&&Object.keys(e.relationMap).length>0&&t.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&t.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&t.push("vector indexes"),t.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${r}" declares ${t.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},D=(e,r)=>{const t=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return z(e,r),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:n,name:r,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(i=>({field:i.field,...i.filterFields?{filterFields:i.filterFields}:{},...i.language===void 0?{}:{language:i.language},...i.staged===void 0?{}:{staged:i.staged},...i.strategy===void 0?{}:{strategy:i.strategy},name:i.name})),shape:Object.fromEntries(Object.entries(t).map(([i,o])=>[i,g(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},B=e=>{const{key:r,tables:t}=e;if(typeof r!="string"||typeof t!="object"||t===null)return;const n=Object.entries(t).map(([a,l])=>D(l,a)),i=e.vectorIndexes??{},o=Object.entries(i??{}).map(([a,l])=>({...l.dimensions===void 0?{}:{dimensions:l.dimensions},...l.field===void 0?{}:{field:l.field},...l.metadata===void 0?{}:{metadata:l.metadata},...l.metric===void 0?{}:{metric:l.metric},name:a,table:l.table??""}));return{bareTables:n,bareVectorIndexes:o,key:r}},q=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r.getText():void 0}},F=e=>{const r=q(e);if(r===void 0)return;const t=s.isPropertyAccessExpression(e)?e.getName():void 0,n=t===void 0?[]:[t];for(const i of e.getSourceFile().getImportDeclarations()){const o=i.getModuleSpecifierValue();for(const a of i.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===r)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:n};if(i.getDefaultImport()?.getText()===r)return{importedName:"default",moduleSpecifier:o,propertyPath:n};if(i.getNamespaceImport()?.getText()===r&&t!==void 0)return{importedName:t,moduleSpecifier:o,propertyPath:[]}}},C=(e,r)=>{let t=e[r.importedName];for(const n of r.propertyPath){if(typeof t!="object"||t===null)return;t=t[n]}return t},V=(e,r)=>{const t=F(e);if(t)try{const n=N(O(r,"noop.cjs")),i=n.resolve(t.moduleSpecifier),o=n(i),a=C(o,t);return typeof a!="object"||a===null?void 0:B(a)}catch{return}},R=new Set(["cosine","dot-product","euclidean"]),J=new Set(["cascade","restrict","set null"]),E=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),K=(e,r)=>{if(E.has(e))throw f(r,`table name "${e}" is reserved — it collides with a \`ctx.db\` member (one of ${[...E].map(t=>`"${t}"`).join(", ")}). Rename the table.`)},c=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},m=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isNumericLiteral(n))return Number(n.getLiteralText())}},U=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&(s.isTrueLiteral(n)||s.isFalseLiteral(n)))return n.getLiteralValue()}},h=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isArrayLiteralExpression(n))return n.getElements().filter(i=>s.isStringLiteral(i)).map(i=>i.getLiteralText())}},v=e=>e&&R.has(e)?e:void 0,G=e=>e&&J.has(e)?e:void 0,H=e=>{if(!s.isArrowFunction(e))return;let r=e.getBody();if(s.isParenthesizedExpression(r))r=r.getExpression();else if(s.isBlock(r)){const t=r.getStatements().find(n=>s.isReturnStatement(n));r=t&&s.isReturnStatement(t)?t.getExpression()??r:r}return s.isObjectLiteralExpression(r)?r:void 0},Q=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return;const n=t.getName();if(n!=="one"&&n!=="many")return;const[i,o]=r.getArguments(),a=i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_";let l="_unknown_",d="_id",u;return o&&s.isObjectLiteralExpression(o)&&(l=c(o,"field")??l,d=c(o,"references")??d,u=n==="one"?G(c(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:u,references:d,table:a}},W=e=>{const r=H(e);if(!r)return[];const t=[];for(const n of r.getProperties()){const i=Q(n);i&&t.push(i)}return t},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",X=e=>{const[r,t,n]=e;let i=!1;if(n&&s.isObjectLiteralExpression(n)){const o=n.getProperty("unique");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();if(a&&!s.isTrueLiteral(a)&&!s.isFalseLiteral(a))throw f(a,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(a.getText())}`);i=a?s.isTrueLiteral(a):!1}}return{fields:t&&s.isArrayLiteralExpression(t)?t.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText()):[],name:x(r),unique:i}},Y=e=>{const[r,t]=e;let n="_unknown_",i,o,a,l;return t&&s.isObjectLiteralExpression(t)&&(n=c(t,"field")??n,i=h(t,"filterFields"),o=c(t,"language"),a=U(t,"staged"),l=c(t,"strategy")),{field:n,filterFields:i,language:o,name:x(r),staged:a,strategy:l}},Z=e=>{const[r,t]=e;let n="_unknown_",i;return t&&s.isObjectLiteralExpression(t)&&(n=c(t,"field")??n,i=m(t,"precision")),{field:n,name:x(r),precision:i}},ee=e=>{const[r,t]=e,n=r&&s.isStringLiteral(r)?r.getLiteralText():"_unknown_";let i;return t&&s.isObjectLiteralExpression(t)&&(i=m(t,"after")),{after:i,field:n}},te=e=>{if(!s.isObjectLiteralExpression(e))return;const r=c(e,"field");return r===void 0?void 0:{direction:c(e,"direction")==="desc"?"desc":"asc",field:r}},re=e=>{const[r,t]=e;let n=[],i;if(t&&s.isObjectLiteralExpression(t)){const o=t.getProperty("sortBy");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();a&&s.isArrayLiteralExpression(a)&&(n=a.getElements().map(l=>te(l)).filter(l=>l!==void 0))}i=h(t,"partitionBy")}return{name:x(r),partitionBy:i,sortBy:n}},ne=(e,r)=>{const[t,n]=e,i=t&&s.isStringLiteral(t)?t.getLiteralText():"_unknown_";if(!(!n||!s.isObjectLiteralExpression(n)))return{dimensions:m(n,"dimensions"),field:i,metadata:h(n,"metadata"),metric:v(c(n,"metric")),name:c(n,"index")??"_unnamed_",table:r}},ie=e=>{const r=e[0];return r&&s.isObjectLiteralExpression(r)&&c(r,"backend")==="hyperdrive"?"hyperdrive":"d1"},se=e=>{if(e&&s.isObjectLiteralExpression(e)){const r=e.getProperty("field");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},p=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},oe=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isArrayLiteralExpression(n)){const i=n.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText());return i.length>0?i:void 0}}},ae=e=>{const r=e[0];return!r||!s.isObjectLiteralExpression(r)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(r,"binding")??"",columns:oe(r,"columns"),hasReconcile:r.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:r.getProperty("softDeleteColumn")!==void 0,hasTenantBy:r.getProperty("tenantBy")!==void 0,idColumn:p(r,"idColumn"),mode:p(r,"mode"),query:p(r,"query")}},le=(e,r,t,n)=>{switch(r){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(Z(t));break}case"global":{e.shardMode="global",e.globalBackend=ie(t);break}case"index":{e.indexes.push(X(t));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(re(t));break}case"relations":{const i=t[0];i&&e.relations.push(...W(i));break}case"searchIndex":{e.searchIndexes.push(Y(t));break}case"shardBy":{const i=t[0];e.shardMode={field:i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:se(t[0])};break}case"source":{e.externalSource=ae(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=ee(t);break}case"vectorize":{const i=ne(t,n);i&&e.vectorIndexes.push(i);break}}},L=(e,r)=>{const t={externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let n={},i=e;for(;s.isCallExpression(i);){const o=i.getExpression(),a=i.getArguments();if(s.isPropertyAccessExpression(o))le(t,o.getName(),a,r),i=o.getExpression();else if(s.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];l&&s.isObjectLiteralExpression(l)&&(n=T(l));break}else break}return t.softDelete&&!(t.softDelete.field in n)&&(n={...n,[t.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),{externallyManaged:t.externallyManaged,externalSource:t.externalSource,geoIndexes:t.geoIndexes,globalBackend:t.shardMode==="global"?t.globalBackend??"d1":void 0,indexes:t.indexes,isPublic:t.isPublic,name:r,rankIndexes:t.rankIndexes,relations:t.relations,searchIndexes:t.searchIndexes,shape:n,shardMode:t.shardMode,softDelete:t.softDelete,ttl:t.ttl,vectorIndexes:t.vectorIndexes}},ce=e=>{const r=e.getProperty("source");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isObjectLiteralExpression(t))return c(t,"table")??"_unknown_"}return"_unknown_"},de=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isIdentifier(t)||t.getText()!=="defineVectorIndex")return;const n=r.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))return;const i=e.getNameNode(),o=s.isStringLiteral(i)?i.getLiteralText():i.getText();return{dimensions:m(n,"dimensions"),metric:v(c(n,"metric")),name:o,table:ce(n)}},P=e=>{const r=[];for(const t of e.getProperties()){const n=de(t);n&&r.push(n)}return r},k=(e,r)=>`${e}_${r}`,y=(e,r,t)=>t.has(e)?k(r,e):e,ue=(e,r,t)=>{const n=k(r,e.name);return{...e,extensionKey:r,name:n,relations:e.relations.map(i=>({...i,table:y(i.table,r,t)})),vectorIndexes:e.vectorIndexes.map(i=>({...i,table:y(i.table,r,t)}))}},ge=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},fe=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t))return t.getInitializer()},pe=e=>{if(!s.isCallExpression(e))return!1;const r=e.getExpression();return s.isIdentifier(r)&&r.getText()==="defineSchemaExtension"},me=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r:void 0}},xe=e=>{if(s.isObjectLiteralExpression(e))return e;if(s.isCallExpression(e)){const r=e.getExpression();let t;if(s.isIdentifier(r)?t=r.getText():s.isPropertyAccessExpression(r)&&(t=r.getName()),t==="definePlugin"){const n=e.getArguments()[1];return n&&s.isObjectLiteralExpression(n)?n:void 0}}},be=(e,r)=>{const t=ge(e);if(t){if(s.isPropertyAccessExpression(r)){const n=xe(t);return n?fe(n,r.getName()):void 0}return t}},ye=e=>{let r=e,t=0;for(;r&&t<32;){if(t+=1,pe(r))return r;const n=me(r),i=n&&s.isIdentifier(n)?n.getSymbol():void 0,o=(i?.getAliasedSymbol()?.getDeclarations()??i?.getDeclarations()??[])[0];if(!o)return;const a=o.getSourceFile();if(a.isInNodeModules()||a.isDeclarationFile())return;r=be(o,r)}},he=e=>{const[r,t]=e.getArguments();if(!(!r||!s.isStringLiteral(r))&&!(!t||!s.isObjectLiteralExpression(t)))return{key:r.getLiteralText(),options:t}},ke=e=>{const r=e.getProperty("tables");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();if(!t||!s.isObjectLiteralExpression(t))return[];const n=[];for(const i of t.getProperties()){if(!s.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.push(L(o,i.getName()))}return n},Ie=e=>{const r=e.getProperty("vectorIndexes");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();return!t||!s.isObjectLiteralExpression(t)?[]:P(t)},S=(e,r,t)=>{const n=new Set(r.map(a=>a.name)),i=r.map(a=>ue(a,e,n)),o=t.map(a=>({...a,name:k(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Ee=(e,r)=>S(e,ke(r),Ie(r)),ve=(e,r)=>{const t=e.getArguments()[0];if(!t)return;const n=ye(t);if(!n){if(r!==void 0){const o=V(t,r);if(o)return S(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${t.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${r===void 0?"no project root was available to resolve the package":"the package could not be imported/introspected"}. Extension tables will be absent from the generated types.`);return}const i=he(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Ee(i.key,i.options)},Le=e=>{const r=[];let t=e;for(;;){const n=t.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;n.getName()==="extend"&&r.push(i),t=i}return r},A=(e,r,t,n,i)=>{let o=e;for(;;){const a=o.getParent();if(!a||!s.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!s.isCallExpression(l))break;if(a.getName()===r){const d=l.getArguments()[0];if(!d||!s.isStringLiteral(d))throw f(l,`\`.${r}(...)\` expects a string literal (${i})`);const u=d.getLiteralText();if(!n.has(u))throw f(d,`unknown ${t} ${JSON.stringify(u)} — expected ${i}`);return u}o=l}},Pe=new Set(["eu","fedramp","us"]),Se=e=>A(e,"jurisdiction","jurisdiction",Pe,'"eu", "us", or "fedramp"'),Ae=new Set(["required"]),je=e=>A(e,"rls","rls mode",Ae,'"required"'),we=e=>{const r=[];for(const t of e.getProperties()){if(!s.isPropertyAssignment(t))continue;const n=t.getInitializer();if(n){const i=t.getName();K(i,t.getNameNode()),r.push(L(n,i))}}return r},Te=(e,r,t)=>{const n=new Set(r.map(o=>o.name)),i=[];for(const o of Le(e)){const a=ve(o,t);if(a){for(const l of a.tables){if(n.has(l.name))throw f(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);n.add(l.name),r.push(l)}i.push(...a.vectorIndexes)}}return i},De=(e,r,t)=>{const n=e.addSourceFileAtPath(r).getDescendantsOfKind(w.CallExpression).find(b=>{const I=b.getExpression();return s.isIdentifier(I)&&I.getText()==="defineSchema"});if(!n)throw new j("INTERNAL",`defineSchema() not found in ${r}`);const i=n.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw f(n,"defineSchema() expects an object literal");const o=we(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?P(a):[],d=Te(n,o,t),u=[...o.flatMap(b=>b.vectorIndexes),...l,...d];return{jurisdiction:Se(n),rlsMode:je(n),tables:o,vectorIndexes:u}};export{De as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{Node as r}from"ts-morph";const c=/^[A-Za-z_$][\w$]*$/u,d=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","unique"]),p=(n,t)=>{const e={notNull:!0,...n.column};switch(t){case"$defaultFn":case"default":case"defaultNow":{e.hasDefault=!0;break}case"$onUpdateFn":{e.hasOnUpdate=!0;break}case"$type":break;case"nullable":{e.notNull=!1;break}case"unique":{e.unique=!0;break}}return{...n,column:e}},k=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),f=new Set(["check","meta"]),o=n=>r.isCallExpression(n)?b(n):{kind:"any",sourceText:n.getText()},g=n=>{const t={};for(const e of n.getProperties()){if(!r.isPropertyAssignment(e))continue;const s=e.getNameNode();if(r.isComputedPropertyName(s))continue;const i=e.getInitializer();if(!i)continue;const a=e.getName();if(!c.test(a))throw new l("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(a)}`);t[a]=o(i)}return t},u=(n,t)=>n&&r.isExpression(n)?o(n):t,m=n=>n===void 0?"undefined":r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)?JSON.stringify(n.getLiteralValue()):n.getText(),y=(n,t)=>{if(k.has(n))return{kind:n};const[e,s]=t;switch(n){case"array":return{inner:u(e,{kind:"any"}),kind:"array"};case"from":return{kind:"from"};case"id":return{kind:"id",tableName:e&&r.isStringLiteral(e)?e.getLiteralText():"_unknown_"};case"literal":return{kind:"literal",literalValue:m(e)};case"object":return e&&r.isObjectLiteralExpression(e)?{kind:"object",shape:g(e)}:{kind:"object",shape:{}};case"optional":return{inner:u(e,{kind:"any"}),kind:"optional"};case"record":return{keyType:u(e,{kind:"string"}),kind:"record",valueType:u(s,{kind:"any"})};case"storage":return e&&r.isStringLiteral(e)?{bucket:e.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(i=>r.isExpression(i)).map(i=>o(i))};default:throw new l("INTERNAL",`Unsupported validator kind: ${n}`)}},b=n=>{const t=n.getExpression();if(!r.isPropertyAccessExpression(t))return{kind:"any",sourceText:n.getText()};const e=t.getName(),s=n.getArguments();if(d.has(e)){const i=t.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return p(a,e)}if(f.has(e)){const i=t.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return e==="check"?{...a,hasRefinement:!0}:a}return y(e,s)};export{g as d,o as s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const s=/[\w+/=-]{40,}/u,d=/[a-z]/u,i=/[A-Z]/u,n=/\d/u,k=/\b(?:[\da-f]{32,}|[\dA-F]{32,})\b/u,a=t=>{const e=s.exec(t)?.[0];return e===void 0?!1:d.test(e)&&i.test(e)&&n.test(e)},r=t=>k.test(t),u=/\b(?:sk|rk)_live_[\dA-Za-z]{20,}/u,_=/\bAKIA[\dA-Z]{16}\b/u,c=/\bgh[posru]_[\dA-Za-z]{36,}/u,A=/\bsk-[\dA-Za-z]{32,}/u,b=/\bxox[abprs]-[\dA-Za-z-]{10,}/u,o=/-----BEGIN(?: [A-Z]+)? PRIVATE KEY-----/u,h=[{kind:"stripe_live_key",test:t=>u.test(t)},{kind:"aws_access_key",test:t=>_.test(t)},{kind:"github_token",test:t=>c.test(t)},{kind:"openai_key",test:t=>A.test(t)},{kind:"slack_token",test:t=>b.test(t)},{kind:"private_key",test:t=>o.test(t)},{kind:"high_entropy",test:a},{kind:"hex_secret",test:r}],p=t=>h.find(e=>e.test(t))?.kind,E=t=>`${t.slice(0,4)}…(${String(t.length)} chars)`;export{h as SECRET_RULES,E as redact,p as secretKindOf};
|