@lunora/codegen 1.0.0-alpha.266 → 1.0.0-alpha.267

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.
Files changed (58) hide show
  1. package/dist/index.d.mts +11 -0
  2. package/dist/index.d.ts +11 -0
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-DwlmRvXo.mjs → AGENTS_FILENAME-Z3MMfNoG.mjs} +1 -1
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-D8YLxYhQ.mjs → CONTAINERS_FILENAME-IJ5ME0fR.mjs} +1 -1
  6. package/dist/packem_shared/{DEFAULT_TARGET-CaXPORLo.mjs → DEFAULT_TARGET-CadzOvvN.mjs} +1 -1
  7. package/dist/packem_shared/{FLAGS_FILENAME-BGFPEEjc.mjs → FLAGS_FILENAME-BaRnAlw6.mjs} +1 -1
  8. package/dist/packem_shared/{MUTATORS_FILENAME-DwAZEI6d.mjs → MUTATORS_FILENAME-BpaUVHB6.mjs} +1 -1
  9. package/dist/packem_shared/{NOTIFY_FILENAME-DrBbzi0l.mjs → NOTIFY_FILENAME-CX_Gz1si.mjs} +1 -1
  10. package/dist/packem_shared/{OPENRPC_VERSION-BqeEI2Dn.mjs → OPENRPC_VERSION-B73FvmDP.mjs} +1 -1
  11. package/dist/packem_shared/{QUEUES_FILENAME-D0AeAQz-.mjs → QUEUES_FILENAME-B8RkoxY5.mjs} +1 -1
  12. package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-YwnhjnM-.mjs → SCHEMA_SNAPSHOT_FILENAME-QrTRRuEd.mjs} +6 -6
  13. package/dist/packem_shared/{SHAPES_FILENAME-C-CUVhR6.mjs → SHAPES_FILENAME-D9dnZ1x2.mjs} +1 -1
  14. package/dist/packem_shared/{WORKFLOWS_FILENAME-d1r1GnQd.mjs → WORKFLOWS_FILENAME-DryVyDtJ.mjs} +1 -1
  15. package/dist/packem_shared/{attribution-B7i322L0.mjs → attribution-DmwAff2x.mjs} +1 -1
  16. package/dist/packem_shared/{buildOpenApiDocument-BYtXD9iB.mjs → buildOpenApiDocument-CcjqWh8u.mjs} +1 -1
  17. package/dist/packem_shared/{capabilitiesUsedBy-_kfPZ5wC.mjs → capabilitiesUsedBy-CodLXY4q.mjs} +1 -1
  18. package/dist/packem_shared/chain-2WjN7Idh.mjs +1 -0
  19. package/dist/packem_shared/{classify-procedure-call-DC_O3oNQ.mjs → classify-procedure-call-B8KernCD.mjs} +1 -1
  20. package/dist/packem_shared/{context-property-calls-BvE4YxG6.mjs → context-property-calls-BxYJwsij.mjs} +1 -1
  21. package/dist/packem_shared/{context-root-C4hjiCTo.mjs → context-root-Z4sUTfYv.mjs} +1 -1
  22. package/dist/packem_shared/{database-calls-B6ylmcGA.mjs → database-calls-Bd3kT6B1.mjs} +1 -1
  23. package/dist/packem_shared/{discoverAuthApiCalls-CUM8XgDc.mjs → discoverAuthApiCalls-CJtGjrRa.mjs} +1 -1
  24. package/dist/packem_shared/{discoverCrons-DI1xHRei.mjs → discoverCrons-7FZyY_8h.mjs} +1 -1
  25. package/dist/packem_shared/{discoverFunctions-B-7117i2.mjs → discoverFunctions-BiAdFs_o.mjs} +1 -1
  26. package/dist/packem_shared/{discoverHttpRoutes-BT2HmWD_.mjs → discoverHttpRoutes-BkfwRTKx.mjs} +1 -1
  27. package/dist/packem_shared/discoverHyperdriveCalls-CWXYIz5_.mjs +1 -0
  28. package/dist/packem_shared/{discoverInserts-BHxWlrW0.mjs → discoverInserts-C52minJD.mjs} +1 -1
  29. package/dist/packem_shared/discoverMaskProcedures-jARUptd8.mjs +1 -0
  30. package/dist/packem_shared/{discoverMigrations-DdeNFu0j.mjs → discoverMigrations-BQbzkdoU.mjs} +1 -1
  31. package/dist/packem_shared/{discoverNondeterministicCalls-Deg23AAc.mjs → discoverNondeterministicCalls-DZkD5QFA.mjs} +1 -1
  32. package/dist/packem_shared/{discoverQueries-yKWWoX-Z.mjs → discoverQueries-HhyYb-hV.mjs} +1 -1
  33. package/dist/packem_shared/discoverR2sqlCalls-D-GN7Agb.mjs +1 -0
  34. package/dist/packem_shared/{discoverRlsMetadata-DwG8EMHQ.mjs → discoverRlsMetadata-CG8Rv9n8.mjs} +1 -1
  35. package/dist/packem_shared/{discoverRlsProcedures-D3UFRjOI.mjs → discoverRlsProcedures-qwXpyg2N.mjs} +1 -1
  36. package/dist/packem_shared/{discoverSandboxUsage-C-ntjbjl.mjs → discoverSandboxUsage-Z3ZV6dlv.mjs} +1 -1
  37. package/dist/packem_shared/{discoverSchema-DFN2L811.mjs → discoverSchema-Dja7ta2_.mjs} +1 -1
  38. package/dist/packem_shared/{discoverStorageRulesMetadata-B-f9lVjJ.mjs → discoverStorageRulesMetadata-Bgm8JPFh.mjs} +1 -1
  39. package/dist/packem_shared/{emitApp-Dec8sEI0.mjs → emitApp-CT3NRUF_.mjs} +2 -0
  40. package/dist/packem_shared/{emitCrons-DsXsg1uG.mjs → emitCrons-DKeoaeqU.mjs} +28 -15
  41. package/dist/packem_shared/{exported-procedure-chains-CmwqreGv.mjs → exported-procedure-chains-DOQLEINN.mjs} +1 -1
  42. package/dist/packem_shared/{fingerprintSchemaSources-4S1x40Bs.mjs → fingerprintSchemaSources-BDXTtGpN.mjs} +1 -1
  43. package/dist/packem_shared/{handler-reference-DaXlBYJx.mjs → handler-reference-C_f896vO.mjs} +1 -1
  44. package/dist/packem_shared/{index-B5G7NWDW.mjs → index-ndyk9srq.mjs} +1 -1
  45. package/dist/packem_shared/{isTestPath-5ruOnRVA.mjs → isTestPath-Djd59sWZ.mjs} +1 -1
  46. package/dist/packem_shared/loadProjectConfig-ifN6C_Dn.mjs +1 -0
  47. package/dist/packem_shared/{modules-DQv8-RtF.mjs → modules-CyqMHMWS.mjs} +1 -1
  48. package/dist/packem_shared/{parse-validator-C2Osg6gv.mjs → parse-validator-DLAJeWE4.mjs} +1 -1
  49. package/dist/packem_shared/project-config-file-CD247zmH.mjs +1 -0
  50. package/dist/packem_shared/{readServiceBindings-BcN87FPt.mjs → readServiceBindings-BNe3IN3v.mjs} +1 -1
  51. package/dist/packem_shared/{unwrap-handler-return-CM6v2E3A.mjs → unwrap-handler-return-BlGA5K9G.mjs} +1 -1
  52. package/package.json +6 -6
  53. package/dist/packem_shared/chain-C17a7v59.mjs +0 -1
  54. package/dist/packem_shared/discoverHyperdriveCalls-Bir4M-bD.mjs +0 -1
  55. package/dist/packem_shared/discoverMaskProcedures-DHqunTJ7.mjs +0 -1
  56. package/dist/packem_shared/discoverR2sqlCalls-C48f9S0b.mjs +0 -1
  57. package/dist/packem_shared/loadProjectConfig-D-yD5eRd.mjs +0 -1
  58. package/dist/packem_shared/project-config-file-Cb5ouVEK.mjs +0 -1
@@ -1,4 +1,4 @@
1
- import{i as f}from"./ir-DBSvhNa-.mjs";import{G as c,d as m}from"./shared-BXUKWh7t.mjs";const u=n=>n?`${c}/**
1
+ import{i as m}from"./ir-DBSvhNa-.mjs";import{G as i,d as c}from"./shared-BXUKWh7t.mjs";const u=r=>r?`${i}/**
2
2
  * The \`SchedulerDO\` Durable Object class, re-exported so a worker entry can
3
3
  * forward it — wrangler binds only what the entry exports:
4
4
  *
@@ -8,7 +8,7 @@ import{i as f}from"./ir-DBSvhNa-.mjs";import{G as c,d as m}from"./shared-BXUKWh7
8
8
  * forwards this module for you whenever it exists.
9
9
  */
10
10
  export { SchedulerDO } from "@lunora/scheduler";
11
- `:"",y=(n,r)=>n.some(o=>f(o))?`${c}/**
11
+ `:"",y=(r,t)=>r.some(o=>m(o))?`${i}/**
12
12
  * The \`ShardRegistryDO\` Durable Object class — the live set of shard keys per
13
13
  * \`.shardBy()\` table, which cross-shard export, CDC sync and migrations fan out
14
14
  * to. Re-exported so a worker entry can forward it (wrangler binds only what the
@@ -21,17 +21,30 @@ export { SchedulerDO } from "@lunora/scheduler";
21
21
  * \`export *\`. A Vite-first (class-A) app needs neither line — its generated
22
22
  * worker entry does both whenever this module exists.
23
23
  */
24
- export { ShardRegistryDO } from "${m(r).do}";
25
- `:"",w=n=>{const r=new Map;for(const s of n){const a=r.get(s.cron);a?a.push(s):r.set(s.cron,[s])}const o=[...r.keys()].map(s=>` ${JSON.stringify(s)},`).join(`
24
+ export { ShardRegistryDO } from "${c(t).do}";
25
+ `:"",w=r=>`${i}/**
26
+ * Host the shard, the scheduler and the shard registry in ONE Durable Object
27
+ * class, so the app spends one of the account's classes instead of three. A
28
+ * Vite-first (class-A) app needs nothing more: its generated worker entry builds
29
+ * \`LunoraDO\` from these. A hand-written entry does the same by hand:
30
+ *
31
+ * \`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO, scheduler: SchedulerDO, shardRegistry: ShardRegistryDO });\`
32
+ *
33
+ * and passes \`roleNamespace(env.SHARD, "scheduler")\` / \`roleNamespace(env.SHARD, "shardRegistry")\`
34
+ * to \`.scheduler()\` / \`.shardRegistry()\`. Merge before the first deploy only:
35
+ * data already in \`ShardDO\` does not move, and a deployed merge cannot be undone.
36
+ */
37
+ export { mergeDurableObjects, roleNamespace } from "${c(r).do}";
38
+ `,O=r=>{const t=new Map;for(const n of r){const d=t.get(n.cron);d?d.push(n):t.set(n.cron,[n])}const o=[...t.keys()].map(n=>` ${JSON.stringify(n)},`).join(`
26
39
  `),e=o.length>0?`
27
40
  ${o}
28
- `:"",t=[...r.entries()].map(([s,a])=>{const l=a.map(i=>{const h=i.workflow?`workflow: ${JSON.stringify(i.workflow.className)}`:`functionPath: ${JSON.stringify(i.functionPath)}`;return` { name: ${JSON.stringify(i.name)}, ${h}, args: ${JSON.stringify(i.args)} },`}).join(`
29
- `);return` ${JSON.stringify(s)}: [
41
+ `:"",s=[...t.entries()].map(([n,d])=>{const l=d.map(a=>{const f=a.workflow?`workflow: ${JSON.stringify(a.workflow.className)}`:`functionPath: ${JSON.stringify(a.functionPath)}`;return` { name: ${JSON.stringify(a.name)}, ${f}, args: ${JSON.stringify(a.args)} },`}).join(`
42
+ `);return` ${JSON.stringify(n)}: [
30
43
  ${l}
31
44
  ],`}).join(`
32
- `),d=t.length>0?`
33
- ${t}
34
- `:"";return`${c}/**
45
+ `),h=s.length>0?`
46
+ ${s}
47
+ `:"";return`${i}/**
35
48
  * One scheduled cron invocation. Exactly one target is set: \`functionPath\` is
36
49
  * the \`namespace:fn\` dispatch ref (matches \`__lunoraRef\`), invoked on the
37
50
  * shard; \`workflow\` is a workflow class name (its \`ctx.exports\` key) whose durable workflow is
@@ -55,11 +68,11 @@ export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${e}];
55
68
  * Dispatcher map keyed by cron expression. The Worker's \`scheduled()\` handler
56
69
  * looks up \`event.cron\` here and dispatches every job in the list.
57
70
  */
58
- export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${d}};
59
- `},S=n=>{const r=[...n].toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>{const t=[`name: ${JSON.stringify(e.name)}`,`table: ${JSON.stringify(e.table)}`];return e.field!==void 0&&t.push(`field: ${JSON.stringify(e.field)}`),e.dimensions!==void 0&&t.push(`dimensions: ${JSON.stringify(e.dimensions)}`),e.metric!==void 0&&t.push(`metric: ${JSON.stringify(e.metric)}`),e.metadata!==void 0&&t.push(`metadata: ${JSON.stringify(e.metadata)}`),` { ${t.join(", ")} },`}).join(`
60
- `),o=r.length>0?`
61
- ${r}
62
- `:"";return`${c}/**
71
+ export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${h}};
72
+ `},S=r=>{const t=[...r].toSorted((e,s)=>e.name.localeCompare(s.name)).map(e=>{const s=[`name: ${JSON.stringify(e.name)}`,`table: ${JSON.stringify(e.table)}`];return e.field!==void 0&&s.push(`field: ${JSON.stringify(e.field)}`),e.dimensions!==void 0&&s.push(`dimensions: ${JSON.stringify(e.dimensions)}`),e.metric!==void 0&&s.push(`metric: ${JSON.stringify(e.metric)}`),e.metadata!==void 0&&s.push(`metadata: ${JSON.stringify(e.metadata)}`),` { ${s.join(", ")} },`}).join(`
73
+ `),o=t.length>0?`
74
+ ${t}
75
+ `:"";return`${i}/**
63
76
  * One vector index declared in \`schema.ts\` — an inline \`.vectorize()\` column
64
77
  * or a standalone \`defineVectorIndex()\`. \`field\` is the source column (absent
65
78
  * for a \`select\`-derived Shape B index); \`metadata\` lists the row fields
@@ -80,4 +93,4 @@ export interface LunoraVectorIndex {
80
93
  * \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
81
94
  */
82
95
  export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${o}];
83
- `},R=n=>[...new Set(n.map(r=>r.cron))];export{w as emitCrons,u as emitScheduler,y as emitShardRegistry,S as emitVectors,R as emitWranglerCronTriggers};
96
+ `},b=r=>[...new Set(r.map(t=>t.cron))];export{O as emitCrons,w as emitDurableObjects,u as emitScheduler,y as emitShardRegistry,S as emitVectors,b as emitWranglerCronTriggers};
@@ -1 +1 @@
1
- import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-B7i322L0.mjs";import{c as n}from"./classify-procedure-call-DC_O3oNQ.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
1
+ import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-DmwAff2x.mjs";import{c as n}from"./classify-procedure-call-B8KernCD.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
@@ -1 +1 @@
1
- import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-5ruOnRVA.mjs";const S=t=>{if(!s(t))return"unreadable";const e=h(t,{includeSkipped:!0}),o=u(t,"schema.ts");s(o)&&e.push(o);const r=i("sha256");for(const a of e.toSorted((n,p)=>n.localeCompare(p)))try{r.update(a).update("\0").update(c(a))}catch{}return r.digest("hex")};export{S as default};
1
+ import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-Djd59sWZ.mjs";const S=t=>{if(!s(t))return"unreadable";const e=h(t,{includeSkipped:!0}),o=u(t,"schema.ts");s(o)&&e.push(o);const r=i("sha256");for(const a of e.toSorted((n,p)=>n.localeCompare(p)))try{r.update(a).update("\0").update(c(a))}catch{}return r.digest("hex")};export{S as default};
@@ -1 +1 @@
1
- import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-5ruOnRVA.mjs";import{r as v,d as b}from"./attribution-B7i322L0.mjs";const h=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:h(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=b(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
1
+ import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-Djd59sWZ.mjs";import{r as v,d as b}from"./attribution-DmwAff2x.mjs";const h=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:h(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=b(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
@@ -1 +1 @@
1
- import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-5ruOnRVA.mjs";import{b as m,d as p}from"./attribution-B7i322L0.mjs";import{t as d}from"./database-calls-B6ylmcGA.mjs";import{w as g,c as h}from"./classify-procedure-call-DC_O3oNQ.mjs";import{a as k}from"./project-config-file-Cb5ouVEK.mjs";const l=e=>{if(!(!i.isPropertyAssignment(e)&&!i.isShorthandPropertyAssignment(e)&&!i.isMethodDeclaration(e)&&!i.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=l(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=h(t);if(!r)return;const o=r.receiver?y(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},E=(e,s)=>{const t=[];for(const r of u(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=f(s,r);for(const a of m(o)){const c=b(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
1
+ import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-Djd59sWZ.mjs";import{b as m,d as p}from"./attribution-DmwAff2x.mjs";import{t as d}from"./database-calls-Bd3kT6B1.mjs";import{w as g,c as h}from"./classify-procedure-call-B8KernCD.mjs";import{a as k}from"./project-config-file-CD247zmH.mjs";const l=e=>{if(!(!i.isPropertyAssignment(e)&&!i.isShorthandPropertyAssignment(e)&&!i.isMethodDeclaration(e)&&!i.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=l(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=h(t);if(!r)return;const o=r.receiver?y(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},E=(e,s)=>{const t=[];for(const r of u(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=f(s,r);for(const a of m(o)){const c=b(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
@@ -1 +1 @@
1
- import{existsSync as h,statSync as P,readdirSync as A,realpathSync as C,lstatSync as k}from"node:fs";import{dirname as d,join as g,relative as w,sep as F,resolve as D,extname as N,basename as j}from"node:path";import{findUpSync as z,FIND_UP_STOP as V,matcher as K}from"@visulima/fs";import{SyntaxKind as p,Node as i,VariableDeclarationKind as $}from"ts-morph";import{diagnosticAt as M}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{p as U,a as B,r as W}from"./project-config-file-Cb5ouVEK.mjs";import{findProjectConfigFile as O}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const X=/\.ts$/u,f=(e,t)=>w(e,t).split(F).join("/").replace(X,""),H=new Set(["_generated","node_modules"]),_=new Set(["__fixtures__","__mocks__","__snapshots__","__tests__"]),L=/\.(?:bench|e2e|e2e-spec|spec|spec-d|test|test-d)(?:\.tsx?)?$/u,xe=e=>{const t=e.split("/");return L.test(t.at(-1)??"")||t.slice(0,-1).some(s=>_.has(s))},E=(e,t,s)=>t?H.has(e)||!s&&_.has(e):!s&&L.test(e),v=new Map,m=()=>!1,Y=e=>{const t=z(c=>O(c)??(h(g(c,"package.json"))||h(g(c,".git"))?V:void 0),{cwd:d(D(e))}),s=t===void 0?void 0:P(t,{throwIfNoEntry:!1});if(t===void 0||s===void 0)return m;const n=`${String(s.mtimeMs)}:${String(s.size)}`,r=v.get(t);if(r?.key===n)return r.isExcluded;const{codegen:o}=W(d(t));o?.unreadable&&console.warn("@lunora/codegen: `codegen.exclude` in lunora.config is not an array of string literals without `!` negations — ignoring it.");const a=o?.exclude?.length?K(o.exclude):m;return v.set(t,{isExcluded:a,key:n}),a},q=(e,t,s)=>e==="schema.ts"&&t===s,G=e=>{try{return P(e)}catch{console.warn(`@lunora/codegen: skipping ${e} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},R=(e,t,s,n,r)=>{let o,a;try{o=A(e),a=C(e)}catch{return t}if(n.has(a))return t;n.add(a);for(const c of o){const u=g(e,c),l=G(u);l===void 0||r(c,w(s,u).split(F).join("/"),l.isDirectory())||(l.isDirectory()?R(u,t,s,n,r):l.isFile()&&N(c)===".ts"&&!q(c,e,s)&&t.push(u))}return t},T=(e,t={})=>{const s=t.includeSkipped??!1,n=s?m:Y(e);return R(e,[],e,new Set,(r,o,a)=>E(r,a,s)||n(o))},Q=["src/server","src/index.ts","src/worker.ts"],J=new Set([".ts",".tsx"]),b=(e,t=[])=>{let s;try{s=k(e)}catch{return t}if(s.isFile())return J.has(N(e))&&!E(j(e),!1,!1)&&t.push(e),t;if(!s.isDirectory())return t;for(const n of A(e))E(n,!0,!1)||b(g(e,n),t);return t},Z=e=>{const t=d(e),s=T(e).map(o=>({displayPath:f(e,o),filePath:o})),n=new Set(s.map(o=>o.filePath)),r=O(t);for(const o of[...Q.flatMap(a=>b(g(t,a))),...r===void 0?[]:[r]])n.has(o)||(n.add(o),s.push({displayPath:f(t,o),filePath:o}));return s},ee=e=>Array.isArray(e),I=(e,t,s,n)=>{const r=[];for(const{displayPath:o,filePath:a}of t){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a);for(const u of c.getDescendantsOfKind(s)){const l=n(u,o);ee(l)?r.push(...l):l!==void 0&&r.push(l)}}return r},te=e=>T(e).map(t=>({displayPath:f(e,t),filePath:t})),se=(e,t,s,n)=>I(e,te(t),s,n),Se=(e,t,s)=>se(e,t,p.CallExpression,s),he=(e,t,s)=>I(e,Z(t),p.CallExpression,s),ve=e=>U(e.getPropertyNameNode()??e.getNameNode()),S=(e,t)=>e?.getProperties().find(s=>!i.isSpreadAssignment(s)&&B(s)===t),ye=(e,t)=>{if(t){const o=e.getArguments()[0];return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:void 0}const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const n=S(s,"handler");if(!n||!i.isPropertyAssignment(n))return;const r=n.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:void 0},Pe=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=S(e,t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ie=e=>{const t=e?.getParent();return i.isVariableDeclaration(e)&&i.isVariableDeclarationList(t)&&t.getDeclarationKind()===$.Const},ne=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isParenthesizedExpression(s)||i.isAsExpression(s)||i.isSatisfiesExpression(s)||i.isTypeAssertion(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();return t},y=e=>{const t=ne(e),s=t.getParent();if(s===void 0)return!1;if(i.isBinaryExpression(s)){const r=s.getOperatorToken().getKind();return s.getLeft()===t&&r>=p.FirstAssignment&&r<=p.LastAssignment}if(i.isPrefixUnaryExpression(s)||i.isPostfixUnaryExpression(s)){const r=s.getOperatorToken();return r===p.PlusPlusToken||r===p.MinusMinusToken}return i.isDeleteExpression(s)?!0:i.isForOfStatement(s)||i.isForInStatement(s)?s.getInitializer()===t:i.isPropertyAssignment(s)?s.getInitializer()===t&&y(s):(i.isShorthandPropertyAssignment(s)||i.isSpreadAssignment(s)||i.isSpreadElement(s)||i.isObjectLiteralExpression(s)||i.isArrayLiteralExpression(s))&&y(s)},re=e=>{const t=e?.getDeclarations().find(n=>i.isVariableDeclaration(n));if(!ie(t))return;const s=t.getParent().getParent();return i.isVariableStatement(s)&&i.isSourceFile(s.getParent())?t.getInitializer():void 0},oe=e=>re(e.getSymbol()),Ae=e=>{if(!e)return;if(i.isObjectLiteralExpression(e))return e;if(!i.isIdentifier(e))return;const t=oe(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},x=e=>{let t=e;for(;t&&(i.isAsExpression(t)||i.isSatisfiesExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t));)t=t.getExpression();return t},ae=(e,t)=>{let s=x(e);for(;i.isAwaitExpression(s)||i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s)||i.isCallExpression(s);){const n=i.isCallExpression(s)?t?.(s):void 0;if(n!==void 0)return{verdict:n};s=x(s.getExpression())}return{root:s}},we=e=>ae(e).root,Fe=(e,t)=>e?.compilerNode===t.compilerNode,Ne=e=>{if(i.isPropertyAccessExpression(e))return{member:e.getName(),object:e.getExpression()};const t=i.isElementAccessExpression(e)?e.getArgumentExpression():void 0;return i.isElementAccessExpression(e)&&i.isStringLiteral(t)?{member:t.getLiteralValue(),object:e.getExpression()}:void 0},Oe=e=>{const t=e.getParent();return i.isReturnStatement(t)||i.isArrowFunction(t)&&t.getBody()===e?e.getFirstAncestor(n=>i.isFunctionLikeDeclaration(n)||i.isArrowFunction(n)):void 0},_e=e=>{const t=x(e);return t&&i.isCallExpression(t)?t:void 0},Le=e=>{const t=e.getExportAssignment(r=>!r.isExportEquals());if(!t)return;const s=t.getExpression();if(!i.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&i.isVariableDeclaration(n)?n.getInitializer():s},Re=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Te=(e,t)=>{if(!i.isObjectLiteralExpression(e))return;const s=S(e,t);if(!s||!i.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&i.isStringLiteral(n)?n.getLiteralText():void 0},ce=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},be=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)?ce(e):void 0},Ie=e=>(t,s,n)=>{if(i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue();throw M(t,`${e} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},le=new Set(["api","internal"]),Ce=new Set(["run","runAction","runMutation","runQuery"]),ke=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();return i.isIdentifier(s)&&le.has(s.getText())&&t.length>=2?t:void 0};export{Ce as RUN_METHODS,X as TS_EXTENSION_RE,ve as bindingKeyName,we as chainRootOf,Se as collectCallRows,se as collectNodeRows,he as collectSecurityCallRows,Le as defaultExportExpression,S as findObjectProperty,ke as functionReferenceSegments,ye as handlerOf,ie as isConstDeclaration,Fe as isSameNode,xe as isTestPath,y as isWriteTarget,Re as limitNameOf,T as listLunoraSourceFiles,Z as listSecurityScanFiles,f as lunoraRelativePath,Ne as memberAccessOf,be as objectLiteralFromCallbackBody,Ae as optionsObjectLiteral,ne as outermostValueWrapper,Pe as propertyInitializer,B as propertyKeyName,U as propertyNameText,Oe as returningFunctionOf,Ie as stringPropertyFor,Te as stringPropertyOf,re as symbolConstInitializer,x as unwrapExpression,_e as unwrapToCallExpression,ae as walkChain};
1
+ import{existsSync as h,statSync as P,readdirSync as A,realpathSync as C,lstatSync as k}from"node:fs";import{dirname as d,join as g,relative as w,sep as F,resolve as D,extname as N,basename as j}from"node:path";import{findUpSync as z,FIND_UP_STOP as V,matcher as K}from"@visulima/fs";import{SyntaxKind as p,Node as i,VariableDeclarationKind as $}from"ts-morph";import{diagnosticAt as M}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{p as U,a as B,r as W}from"./project-config-file-CD247zmH.mjs";import{findProjectConfigFile as O}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const X=/\.ts$/u,f=(e,t)=>w(e,t).split(F).join("/").replace(X,""),H=new Set(["_generated","node_modules"]),_=new Set(["__fixtures__","__mocks__","__snapshots__","__tests__"]),L=/\.(?:bench|e2e|e2e-spec|spec|spec-d|test|test-d)(?:\.tsx?)?$/u,xe=e=>{const t=e.split("/");return L.test(t.at(-1)??"")||t.slice(0,-1).some(s=>_.has(s))},E=(e,t,s)=>t?H.has(e)||!s&&_.has(e):!s&&L.test(e),v=new Map,m=()=>!1,Y=e=>{const t=z(c=>O(c)??(h(g(c,"package.json"))||h(g(c,".git"))?V:void 0),{cwd:d(D(e))}),s=t===void 0?void 0:P(t,{throwIfNoEntry:!1});if(t===void 0||s===void 0)return m;const n=`${String(s.mtimeMs)}:${String(s.size)}`,r=v.get(t);if(r?.key===n)return r.isExcluded;const{codegen:o}=W(d(t));o?.unreadable&&console.warn("@lunora/codegen: `codegen.exclude` in lunora.config is not an array of string literals without `!` negations — ignoring it.");const a=o?.exclude?.length?K(o.exclude):m;return v.set(t,{isExcluded:a,key:n}),a},q=(e,t,s)=>e==="schema.ts"&&t===s,G=e=>{try{return P(e)}catch{console.warn(`@lunora/codegen: skipping ${e} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},R=(e,t,s,n,r)=>{let o,a;try{o=A(e),a=C(e)}catch{return t}if(n.has(a))return t;n.add(a);for(const c of o){const u=g(e,c),l=G(u);l===void 0||r(c,w(s,u).split(F).join("/"),l.isDirectory())||(l.isDirectory()?R(u,t,s,n,r):l.isFile()&&N(c)===".ts"&&!q(c,e,s)&&t.push(u))}return t},T=(e,t={})=>{const s=t.includeSkipped??!1,n=s?m:Y(e);return R(e,[],e,new Set,(r,o,a)=>E(r,a,s)||n(o))},Q=["src/server","src/index.ts","src/worker.ts"],J=new Set([".ts",".tsx"]),b=(e,t=[])=>{let s;try{s=k(e)}catch{return t}if(s.isFile())return J.has(N(e))&&!E(j(e),!1,!1)&&t.push(e),t;if(!s.isDirectory())return t;for(const n of A(e))E(n,!0,!1)||b(g(e,n),t);return t},Z=e=>{const t=d(e),s=T(e).map(o=>({displayPath:f(e,o),filePath:o})),n=new Set(s.map(o=>o.filePath)),r=O(t);for(const o of[...Q.flatMap(a=>b(g(t,a))),...r===void 0?[]:[r]])n.has(o)||(n.add(o),s.push({displayPath:f(t,o),filePath:o}));return s},ee=e=>Array.isArray(e),I=(e,t,s,n)=>{const r=[];for(const{displayPath:o,filePath:a}of t){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a);for(const u of c.getDescendantsOfKind(s)){const l=n(u,o);ee(l)?r.push(...l):l!==void 0&&r.push(l)}}return r},te=e=>T(e).map(t=>({displayPath:f(e,t),filePath:t})),se=(e,t,s,n)=>I(e,te(t),s,n),Se=(e,t,s)=>se(e,t,p.CallExpression,s),he=(e,t,s)=>I(e,Z(t),p.CallExpression,s),ve=e=>U(e.getPropertyNameNode()??e.getNameNode()),S=(e,t)=>e?.getProperties().find(s=>!i.isSpreadAssignment(s)&&B(s)===t),ye=(e,t)=>{if(t){const o=e.getArguments()[0];return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:void 0}const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const n=S(s,"handler");if(!n||!i.isPropertyAssignment(n))return;const r=n.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:void 0},Pe=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=S(e,t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ie=e=>{const t=e?.getParent();return i.isVariableDeclaration(e)&&i.isVariableDeclarationList(t)&&t.getDeclarationKind()===$.Const},ne=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isParenthesizedExpression(s)||i.isAsExpression(s)||i.isSatisfiesExpression(s)||i.isTypeAssertion(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();return t},y=e=>{const t=ne(e),s=t.getParent();if(s===void 0)return!1;if(i.isBinaryExpression(s)){const r=s.getOperatorToken().getKind();return s.getLeft()===t&&r>=p.FirstAssignment&&r<=p.LastAssignment}if(i.isPrefixUnaryExpression(s)||i.isPostfixUnaryExpression(s)){const r=s.getOperatorToken();return r===p.PlusPlusToken||r===p.MinusMinusToken}return i.isDeleteExpression(s)?!0:i.isForOfStatement(s)||i.isForInStatement(s)?s.getInitializer()===t:i.isPropertyAssignment(s)?s.getInitializer()===t&&y(s):(i.isShorthandPropertyAssignment(s)||i.isSpreadAssignment(s)||i.isSpreadElement(s)||i.isObjectLiteralExpression(s)||i.isArrayLiteralExpression(s))&&y(s)},re=e=>{const t=e?.getDeclarations().find(n=>i.isVariableDeclaration(n));if(!ie(t))return;const s=t.getParent().getParent();return i.isVariableStatement(s)&&i.isSourceFile(s.getParent())?t.getInitializer():void 0},oe=e=>re(e.getSymbol()),Ae=e=>{if(!e)return;if(i.isObjectLiteralExpression(e))return e;if(!i.isIdentifier(e))return;const t=oe(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},x=e=>{let t=e;for(;t&&(i.isAsExpression(t)||i.isSatisfiesExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t));)t=t.getExpression();return t},ae=(e,t)=>{let s=x(e);for(;i.isAwaitExpression(s)||i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s)||i.isCallExpression(s);){const n=i.isCallExpression(s)?t?.(s):void 0;if(n!==void 0)return{verdict:n};s=x(s.getExpression())}return{root:s}},we=e=>ae(e).root,Fe=(e,t)=>e?.compilerNode===t.compilerNode,Ne=e=>{if(i.isPropertyAccessExpression(e))return{member:e.getName(),object:e.getExpression()};const t=i.isElementAccessExpression(e)?e.getArgumentExpression():void 0;return i.isElementAccessExpression(e)&&i.isStringLiteral(t)?{member:t.getLiteralValue(),object:e.getExpression()}:void 0},Oe=e=>{const t=e.getParent();return i.isReturnStatement(t)||i.isArrowFunction(t)&&t.getBody()===e?e.getFirstAncestor(n=>i.isFunctionLikeDeclaration(n)||i.isArrowFunction(n)):void 0},_e=e=>{const t=x(e);return t&&i.isCallExpression(t)?t:void 0},Le=e=>{const t=e.getExportAssignment(r=>!r.isExportEquals());if(!t)return;const s=t.getExpression();if(!i.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&i.isVariableDeclaration(n)?n.getInitializer():s},Re=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Te=(e,t)=>{if(!i.isObjectLiteralExpression(e))return;const s=S(e,t);if(!s||!i.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&i.isStringLiteral(n)?n.getLiteralText():void 0},ce=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},be=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)?ce(e):void 0},Ie=e=>(t,s,n)=>{if(i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue();throw M(t,`${e} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},le=new Set(["api","internal"]),Ce=new Set(["run","runAction","runMutation","runQuery"]),ke=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();return i.isIdentifier(s)&&le.has(s.getText())&&t.length>=2?t:void 0};export{Ce as RUN_METHODS,X as TS_EXTENSION_RE,ve as bindingKeyName,we as chainRootOf,Se as collectCallRows,se as collectNodeRows,he as collectSecurityCallRows,Le as defaultExportExpression,S as findObjectProperty,ke as functionReferenceSegments,ye as handlerOf,ie as isConstDeclaration,Fe as isSameNode,xe as isTestPath,y as isWriteTarget,Re as limitNameOf,T as listLunoraSourceFiles,Z as listSecurityScanFiles,f as lunoraRelativePath,Ne as memberAccessOf,be as objectLiteralFromCallbackBody,Ae as optionsObjectLiteral,ne as outermostValueWrapper,Pe as propertyInitializer,B as propertyKeyName,U as propertyNameText,Oe as returningFunctionOf,Ie as stringPropertyFor,Te as stringPropertyOf,re as symbolConstInitializer,x as unwrapExpression,_e as unwrapToCallExpression,ae as walkChain};
@@ -0,0 +1 @@
1
+ import{l as o,b as a,r as t}from"./project-config-file-CD247zmH.mjs";import{PROJECT_CONFIG_FILENAMES as i,findProjectConfigFile as l}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";export{i as PROJECT_CONFIG_FILENAMES,l as findProjectConfigFile,o as loadProjectConfig,a as readMergeDurableObjects,t as readProjectConfigLiterals};
@@ -1 +1 @@
1
- import{basename as b}from"node:path";import{Node as d}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as g}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as $,lunoraRelativePath as v,unwrapToCallExpression as E,defaultExportExpression as S,findObjectProperty as M}from"./isTestPath-5ruOnRVA.mjs";const h=(e,o)=>e.find(t=>t.ownsFolder!==!1&&o.startsWith(`${t.name}/`))?.name,F="module.ts",w=(e,o,t)=>{if(d.isStringLiteral(e)||d.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw c(e,`module "${o}": \`${t}\` must be a static string literal — codegen reads it without running the file`)},L=(e,o,t)=>{if(!d.isArrayLiteralExpression(e))throw c(e,`module "${o}": \`${t}\` must be an inline array of table names`);return e.getElements().map(n=>w(n,o,t))},p=(e,o,t)=>{const n=M(e,o);if(n!==void 0){if(!d.isPropertyAssignment(n))throw c(n,`module "${t}": write \`${o}\` inline as \`${o}: …\` — codegen reads it without running the file`);return n.getInitializerOrThrow()}},A=(e,o,t)=>{const n=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=E(S(n)),a=s?.getExpression();if(!s||!a||!d.isIdentifier(a)||a.getText()!=="defineModule")return;if(t==="")throw c(s,"defineModule: lunora/module.ts would make the whole app one module — move it into the folder it describes (lunora/<module>/module.ts)");const i=s.getArguments()[0],m={name:t,tables:[]};if(i===void 0)return m;if(!d.isObjectLiteralExpression(i))throw c(i,`module "${t}": defineModule must be passed an inline object literal`);const r=p(i,"description",t);r!==void 0&&(m.description=w(r,t,"description"));const l=p(i,"tables",t);return l!==void 0&&(m.tables=L(l,t,"tables")),m},k=(e,o)=>{const t=[];for(const n of $(o)){if(b(n)!==F)continue;const s=v(o,n),a=A(e,n,s==="module"?"":s.slice(0,-7));a&&t.push(a)}return t.toSorted((n,s)=>n.name.localeCompare(s.name))},T=(e,o)=>{const t=new Set(e.map(r=>r.name)),n=new Set(e.flatMap(r=>r.tables)),s=o.tables.filter(r=>r.extensionKey!==void 0&&!n.has(r.name)),a=Map.groupBy(s,r=>String(r.extensionKey)),i=e.map(r=>{const l=a.get(r.name);return l===void 0?r:{...r,tables:[...r.tables,...l.map(u=>u.name)]}}),m=[...a].filter(([r])=>!t.has(r)).map(([r,l])=>{const u=l.every(f=>f.extensionFromPackage===!0);return{installed:!0,name:r,...u?{ownsFolder:!1}:{},tables:l.map(f=>f.name)}});return[...i,...m].toSorted((r,l)=>r.name.localeCompare(l.name))},x=e=>{for(const o of e){const t=e.find(n=>n.name.startsWith(`${o.name}/`));if(t)throw new Error(`@lunora/codegen: module "${t.name}" is nested inside ${o.installed===!0?"installed component":"module"} "${o.name}" — a file can belong to one module only, so move one of the two`)}},y=(e,o)=>{const t=new Set(o.tables.map(s=>s.name)),n=new Map;for(const s of e)for(const a of s.tables){if(!t.has(a))throw new Error(`@lunora/codegen: module "${s.name}" declares table "${a}", which lunora/schema.ts does not define`);const i=n.get(a);if(i!==void 0)throw new Error(`@lunora/codegen: table "${a}" is claimed by both module "${i}" and module "${s.name}" — a table has one owner`);n.set(a,s.name)}},C=(e,o,t)=>{if(e.length===0)return;const n=new Set(o.map(s=>s.name));for(const s of t){const a=g(s);if(h(o,s)===void 0&&n.has(a))throw new Error(`@lunora/codegen: lunora/${s}.ts sits beside module "${a}" and shares its name — move it into lunora/${a}/ or rename one of them`)}},z=(e,o,t)=>{const n=T(e,o);return x(n),y(n,o),C(e,n,t),n},K=(e,o)=>h(e,o)??g(o);export{h as a,k as d,K as m,z as r};
1
+ import{basename as b}from"node:path";import{Node as d}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as g}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as $,lunoraRelativePath as v,unwrapToCallExpression as E,defaultExportExpression as S,findObjectProperty as M}from"./isTestPath-Djd59sWZ.mjs";const h=(e,o)=>e.find(t=>t.ownsFolder!==!1&&o.startsWith(`${t.name}/`))?.name,F="module.ts",w=(e,o,t)=>{if(d.isStringLiteral(e)||d.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw c(e,`module "${o}": \`${t}\` must be a static string literal — codegen reads it without running the file`)},L=(e,o,t)=>{if(!d.isArrayLiteralExpression(e))throw c(e,`module "${o}": \`${t}\` must be an inline array of table names`);return e.getElements().map(n=>w(n,o,t))},p=(e,o,t)=>{const n=M(e,o);if(n!==void 0){if(!d.isPropertyAssignment(n))throw c(n,`module "${t}": write \`${o}\` inline as \`${o}: …\` — codegen reads it without running the file`);return n.getInitializerOrThrow()}},A=(e,o,t)=>{const n=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=E(S(n)),a=s?.getExpression();if(!s||!a||!d.isIdentifier(a)||a.getText()!=="defineModule")return;if(t==="")throw c(s,"defineModule: lunora/module.ts would make the whole app one module — move it into the folder it describes (lunora/<module>/module.ts)");const i=s.getArguments()[0],m={name:t,tables:[]};if(i===void 0)return m;if(!d.isObjectLiteralExpression(i))throw c(i,`module "${t}": defineModule must be passed an inline object literal`);const r=p(i,"description",t);r!==void 0&&(m.description=w(r,t,"description"));const l=p(i,"tables",t);return l!==void 0&&(m.tables=L(l,t,"tables")),m},k=(e,o)=>{const t=[];for(const n of $(o)){if(b(n)!==F)continue;const s=v(o,n),a=A(e,n,s==="module"?"":s.slice(0,-7));a&&t.push(a)}return t.toSorted((n,s)=>n.name.localeCompare(s.name))},T=(e,o)=>{const t=new Set(e.map(r=>r.name)),n=new Set(e.flatMap(r=>r.tables)),s=o.tables.filter(r=>r.extensionKey!==void 0&&!n.has(r.name)),a=Map.groupBy(s,r=>String(r.extensionKey)),i=e.map(r=>{const l=a.get(r.name);return l===void 0?r:{...r,tables:[...r.tables,...l.map(u=>u.name)]}}),m=[...a].filter(([r])=>!t.has(r)).map(([r,l])=>{const u=l.every(f=>f.extensionFromPackage===!0);return{installed:!0,name:r,...u?{ownsFolder:!1}:{},tables:l.map(f=>f.name)}});return[...i,...m].toSorted((r,l)=>r.name.localeCompare(l.name))},x=e=>{for(const o of e){const t=e.find(n=>n.name.startsWith(`${o.name}/`));if(t)throw new Error(`@lunora/codegen: module "${t.name}" is nested inside ${o.installed===!0?"installed component":"module"} "${o.name}" — a file can belong to one module only, so move one of the two`)}},y=(e,o)=>{const t=new Set(o.tables.map(s=>s.name)),n=new Map;for(const s of e)for(const a of s.tables){if(!t.has(a))throw new Error(`@lunora/codegen: module "${s.name}" declares table "${a}", which lunora/schema.ts does not define`);const i=n.get(a);if(i!==void 0)throw new Error(`@lunora/codegen: table "${a}" is claimed by both module "${i}" and module "${s.name}" — a table has one owner`);n.set(a,s.name)}},C=(e,o,t)=>{if(e.length===0)return;const n=new Set(o.map(s=>s.name));for(const s of t){const a=g(s);if(h(o,s)===void 0&&n.has(a))throw new Error(`@lunora/codegen: lunora/${s}.ts sits beside module "${a}" and shares its name — move it into lunora/${a}/ or rename one of them`)}},z=(e,o,t)=>{const n=T(e,o);return x(n),y(n,o),C(e,n,t),n},K=(e,o)=>h(e,o)??g(o);export{h as a,k as d,K as m,z as r};
@@ -1 +1 @@
1
- import{LunoraError as y}from"@lunora/errors";import{Node as n,VariableDeclarationKind as h}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as E}from"./project-config-file-Cb5ouVEK.mjs";let f;const j=e=>{f=e},A=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),k=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},N=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),m=new Set(["check","email","int","length","max","min","pattern","positive","url"]),I=new Set(["meta"]),L=new Set(["strip"]),l=new Set,g=new Set,S=e=>{const t=e.getSymbol();let r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(r!==void 0&&n.isShorthandPropertyAssignment(r)){const i=r.getValueSymbol();r=(i?.getAliasedSymbol()??i)?.getValueDeclaration()}if(!(r===void 0||!n.isVariableDeclaration(r)))return r.getInitializer()},T=e=>{const t=e.getParent();return!n.isVariableDeclaration(t)||t.getVariableStatement()?.getDeclarationKind()===h.Const},u=e=>{if(n.isParenthesizedExpression(e)||n.isAsExpression(e)||n.isSatisfiesExpression(e))return u(e.getExpression());if(n.isObjectLiteralExpression(e))return e;if(n.isPropertyAccessExpression(e)){const r=e.getSymbol()?.getValueDeclaration(),i=r!==void 0&&n.isPropertyAssignment(r)?r.getInitializer():void 0;return i===void 0?void 0:u(i)}if(!n.isIdentifier(e)||l.has(e))return;const t=S(e);if(!(t===void 0||!T(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},w="v",D=e=>{if(n.isIdentifier(e))return!0;let t=e;for(;n.isCallExpression(t);){const r=t.getExpression();if(!n.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return n.isIdentifier(t)&&t.getText()===w},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&D(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?P(e):{kind:"any",sourceText:e.getText()}},R=e=>{const t=u(e.getExpression());if(t===void 0||g.has(t))return{};g.add(t);try{return b(t)}finally{g.delete(t)}},b=e=>{const t={};for(const r of e.getProperties()){if(n.isSpreadAssignment(r)){Object.assign(t,R(r));continue}const i=n.isShorthandPropertyAssignment(r);if(!i&&!n.isPropertyAssignment(r))continue;const o=r.getNameNode();if(n.isComputedPropertyName(o))continue;const a=i?r.getNameNode():r.getInitializer();if(!a)continue;const s=E(r);if(!A.test(s))throw new y("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(s)}`);t[s]=c(a)}return t},d=(e,t)=>e&&n.isExpression(e)?c(e):t,V=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),O=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},x=(e,t,r)=>{if(N.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return O(i);case"id":{if(!i||!n.isStringLiteral(i))throw v(i??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${i?i.getText():"no argument"}.`);return{kind:"id",tableName:i.getLiteralText()}}case"literal":return{kind:"literal",literalValue:V(i)};case"object":return i&&n.isObjectLiteralExpression(i)?{kind:"object",shape:b(i)}:{kind:"object",shape:{}};case"optional":return{inner:d(i,{kind:"any"}),kind:"optional"};case"record":return{keyType:d(i,{kind:"string"}),kind:"record",valueType:d(o,{kind:"any"})};case"storage":return i&&n.isStringLiteral(i)?{bucket:i.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(a=>n.isExpression(a)).map(a=>c(a))};default:throw new y("INTERNAL",`Unsupported validator kind: ${e}`)}},M=e=>{const[t]=e;if(e.length!==1||t===void 0||!n.isNumericLiteral(t))return;const r=Number(t.getText().replaceAll("_",""));return Number.isSafeInteger(r)&&r>=0?r:void 0},P=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(p.has(r)||m.has(r)||I.has(r)||L.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(p.has(r))return k(a,r);if(!m.has(r))return a;const s=r==="max"&&a.kind==="string"?M(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return x(r,i,e)};export{c as a,b as p,u as r,j as s};
1
+ import{LunoraError as y}from"@lunora/errors";import{Node as n,VariableDeclarationKind as h}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as E}from"./project-config-file-CD247zmH.mjs";let f;const j=e=>{f=e},A=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),k=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},N=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),m=new Set(["check","email","int","length","max","min","pattern","positive","url"]),I=new Set(["meta"]),L=new Set(["strip"]),l=new Set,g=new Set,S=e=>{const t=e.getSymbol();let r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(r!==void 0&&n.isShorthandPropertyAssignment(r)){const i=r.getValueSymbol();r=(i?.getAliasedSymbol()??i)?.getValueDeclaration()}if(!(r===void 0||!n.isVariableDeclaration(r)))return r.getInitializer()},T=e=>{const t=e.getParent();return!n.isVariableDeclaration(t)||t.getVariableStatement()?.getDeclarationKind()===h.Const},u=e=>{if(n.isParenthesizedExpression(e)||n.isAsExpression(e)||n.isSatisfiesExpression(e))return u(e.getExpression());if(n.isObjectLiteralExpression(e))return e;if(n.isPropertyAccessExpression(e)){const r=e.getSymbol()?.getValueDeclaration(),i=r!==void 0&&n.isPropertyAssignment(r)?r.getInitializer():void 0;return i===void 0?void 0:u(i)}if(!n.isIdentifier(e)||l.has(e))return;const t=S(e);if(!(t===void 0||!T(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},w="v",D=e=>{if(n.isIdentifier(e))return!0;let t=e;for(;n.isCallExpression(t);){const r=t.getExpression();if(!n.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return n.isIdentifier(t)&&t.getText()===w},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&D(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?P(e):{kind:"any",sourceText:e.getText()}},R=e=>{const t=u(e.getExpression());if(t===void 0||g.has(t))return{};g.add(t);try{return b(t)}finally{g.delete(t)}},b=e=>{const t={};for(const r of e.getProperties()){if(n.isSpreadAssignment(r)){Object.assign(t,R(r));continue}const i=n.isShorthandPropertyAssignment(r);if(!i&&!n.isPropertyAssignment(r))continue;const o=r.getNameNode();if(n.isComputedPropertyName(o))continue;const a=i?r.getNameNode():r.getInitializer();if(!a)continue;const s=E(r);if(!A.test(s))throw new y("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(s)}`);t[s]=c(a)}return t},d=(e,t)=>e&&n.isExpression(e)?c(e):t,V=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),O=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},x=(e,t,r)=>{if(N.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return O(i);case"id":{if(!i||!n.isStringLiteral(i))throw v(i??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${i?i.getText():"no argument"}.`);return{kind:"id",tableName:i.getLiteralText()}}case"literal":return{kind:"literal",literalValue:V(i)};case"object":return i&&n.isObjectLiteralExpression(i)?{kind:"object",shape:b(i)}:{kind:"object",shape:{}};case"optional":return{inner:d(i,{kind:"any"}),kind:"optional"};case"record":return{keyType:d(i,{kind:"string"}),kind:"record",valueType:d(o,{kind:"any"})};case"storage":return i&&n.isStringLiteral(i)?{bucket:i.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(a=>n.isExpression(a)).map(a=>c(a))};default:throw new y("INTERNAL",`Unsupported validator kind: ${e}`)}},M=e=>{const[t]=e;if(e.length!==1||t===void 0||!n.isNumericLiteral(t))return;const r=Number(t.getText().replaceAll("_",""));return Number.isSafeInteger(r)&&r>=0?r:void 0},P=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(p.has(r)||m.has(r)||I.has(r)||L.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(p.has(r))return k(a,r);if(!m.has(r))return a;const s=r==="max"&&a.kind==="string"?M(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return x(r,i,e)};export{c as a,b as p,u as r,j as s};
@@ -0,0 +1 @@
1
+ import{statSync as x,readFileSync as y}from"node:fs";import{basename as S}from"node:path";import{createJiti as E}from"jiti";import{Node as i,Project as P}from"ts-morph";import{findProjectConfigFile as v}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const j=t=>{if(i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t)||i.isNumericLiteral(t))return t.getLiteralText();if(i.isComputedPropertyName(t)){const r=t.getExpression();if(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))return r.getLiteralText()}return t.getText()},d=t=>j(t.getNameNode()),m=new Map,F=async t=>{const r=v(t);if(r===void 0)return{};let e;try{const a=x(r);e=`${String(a.mtimeMs)}:${String(a.size)}`}catch{return{}}const n=m.get(r);if(n?.key===e)return n.value;const s=(async()=>{try{const l=(await E(r,{interopDefault:!1,moduleCache:!1}).import(r))?.default;return{config:l!==null&&typeof l=="object"?l:void 0}}catch(a){return{error:a instanceof Error?a.message:String(a)}}})();return m.set(r,{key:e,value:s}),s},h=t=>{let e=t.getExportAssignments().find(n=>!n.isExportEquals())?.getExpression();for(;e!==void 0&&(i.isSatisfiesExpression(e)||i.isAsExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();if(e!==void 0&&i.isIdentifier(e))for(e=t.getVariableDeclaration(e.getText())?.getInitializer();e!==void 0&&(i.isSatisfiesExpression(e)||i.isAsExpression(e));)e=e.getExpression();return e!==void 0&&i.isObjectLiteralExpression(e)?e:void 0},c=(t,r)=>i.isPropertyAssignment(t)?t.getInitializer():r.getVariableDeclaration(d(t))?.getInitializer(),g=t=>{let r=t;for(;r!==void 0&&(i.isSatisfiesExpression(r)||i.isAsExpression(r)||i.isParenthesizedExpression(r));)r=r.getExpression();return r},b=(t,r,e)=>{const n=g(t);if(n===void 0||!i.isObjectLiteralExpression(n))return{unreadable:!0};const s=n.getProperties(),a=s.filter(u=>i.isPropertyAssignment(u)&&!i.isComputedPropertyName(u.getNameNode())||i.isShorthandPropertyAssignment(u));if(a.length!==s.length)return{unreadable:!0};const l=a.find(u=>d(u)===e);if(l===void 0)return{absent:!0};const o=c(l,r);return o===void 0?{unreadable:!0}:{literal:o}},O=(t,r)=>{const e=b(t,r,"minSeverity");return"absent"in e?{advisor:{}}:"literal"in e&&i.isStringLiteral(e.literal)?{advisor:{minSeverity:e.literal.getLiteralValue()}}:{advisor:{unreadable:!0}}},A=(t,r)=>{const e=b(t,r,"exclude");if("absent"in e)return{codegen:{}};if(!("literal"in e)||!i.isArrayLiteralExpression(e.literal))return{codegen:{unreadable:!0}};const n=[];for(const s of e.literal.getElements()){if(!i.isStringLiteral(s)&&!i.isNoSubstitutionTemplateLiteral(s)||s.getLiteralValue().startsWith("!"))return{codegen:{unreadable:!0}};n.push(s.getLiteralValue())}return{codegen:{exclude:n}}},N=(t,r)=>{const e=b(t,r,"merge");return"absent"in e?{durableObjects:{}}:"literal"in e&&(i.isTrueLiteral(e.literal)||i.isFalseLiteral(e.literal))?{durableObjects:{merge:e.literal.getLiteralValue()}}:{durableObjects:{unreadable:!0}}},w=new Map([["advisor",{advisor:{unreadable:!0}}],["codegen",{codegen:{unreadable:!0}}],["durableObjects",{durableObjects:{unreadable:!0}}],["remote",{unreadable:!0}],["target",{unreadable:!0}]]),L=(t,r)=>{const e=t.getProperty(r);if(e!==void 0)return(i.isPropertyAssignment(e)?e.getInitializer():void 0)??"unreadable"},p=(t,r)=>{const e=L(t,r);if(e!==void 0)return e!=="unreadable"&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():!1},T=t=>{const r=L(t,"rpc");if(r!==void 0)return r!=="unreadable"&&i.isFalseLiteral(r)?!1:"unreadable"},z=t=>{const r=g(t);if(r===void 0||!i.isObjectLiteralExpression(r))return{services:{unreadable:!0}};const e={};for(const n of r.getProperties()){if(!i.isPropertyAssignment(n)||i.isComputedPropertyName(n.getNameNode()))return{services:{unreadable:!0}};const s=g(n.getInitializer());if(s===void 0||!i.isObjectLiteralExpression(s)||s.getProperties().some(u=>!i.isPropertyAssignment(u)))return{services:{unreadable:!0}};const a=p(s,"dir"),l=p(s,"entrypoint"),o=T(s);if(typeof a!="string"||l===!1||o==="unreadable")return{services:{unreadable:!0}};e[d(n)]={dir:a,...l===void 0?{}:{entrypoint:l},...o===void 0?{}:{rpc:o}}}return{services:{declared:e}}},C=(t,r)=>{if(i.isGetAccessorDeclaration(t)||i.isMethodDeclaration(t))return w.get(d(t))??{};if(!i.isPropertyAssignment(t)&&!i.isShorthandPropertyAssignment(t))return{};const e=d(t);if(e==="advisor")return O(c(t,r),r);if(e==="services")return z(c(t,r));if(e==="codegen")return A(c(t,r),r);if(e==="durableObjects")return N(c(t,r),r);if(e!=="target"&&e!=="remote")return{};const n=c(t,r);return n===void 0?{unreadable:!0}:e==="target"?i.isStringLiteral(n)?{target:n.getLiteralValue()}:{unreadable:!0}:i.isTrueLiteral(n)||i.isFalseLiteral(n)?{remote:n.getLiteralValue()}:i.isObjectLiteralExpression(n)?{remote:!0}:{unreadable:!0}},D=t=>{const r=v(t);if(r===void 0)return{};let e;try{e=y(r,"utf8")}catch{return{unreadable:!0}}const s=new P({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(S(r),e,{overwrite:!0}),a=h(s);if(a===void 0)return{unreadable:!0};if(a.getProperties().some(o=>i.isSpreadAssignment(o))){const o=u=>a.getProperties().some(f=>!i.isSpreadAssignment(f)&&d(f)===u);return{...o("advisor")?{advisor:{unreadable:!0}}:{},...o("codegen")?{codegen:{unreadable:!0}}:{},...o("durableObjects")?{durableObjects:{unreadable:!0}}:{},...o("services")?{services:{unreadable:!0}}:{},unreadable:!0}}let l={};for(const o of a.getProperties())l={...l,...C(o,s)};return l},J=t=>{const{durableObjects:r}=D(t);return r?.unreadable&&console.warn("@lunora/codegen: `durableObjects.merge` in lunora.config is not a boolean literal — the Durable Object classes stay separate."),r?.merge===!0};export{d as a,J as b,F as l,j as p,D as r};
@@ -1 +1 @@
1
- import{existsSync as g,readFileSync as p}from"node:fs";import{isAbsolute as w,resolve as m,join as u}from"node:path";import{ts as h}from"ts-morph";import{r as E}from"./project-config-file-Cb5ouVEK.mjs";const f=/^[A-Za-z_$][\w$]*$/u,$=["wrangler.jsonc","wrangler.json"],b=t=>`SERVICE_${t.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/gu,"_").toUpperCase()}`,y=(t,e)=>{const r=$.map(n=>u(e,n)).find(n=>g(n));if(r===void 0){const n=g(u(e,"wrangler.toml"))?" (its wrangler.toml is not read — Lunora reads a service's config as JSON(C) only)":"";throw new Error(`@lunora/codegen: service "${t}" points at ${e}, which has no wrangler.jsonc / wrangler.json${n}`)}const o=h.parseConfigFileTextToJson(r,p(r,"utf8"));if(o.error!==void 0||typeof o.config!="object"||o.config===null)throw new Error(`@lunora/codegen: service "${t}": ${r} is not valid JSON(C)`);return{config:o.config,path:r}},v=(t,e)=>{const r=t.route??e.route,o=t.routes??e.routes;return!(r!==void 0||Array.isArray(o)&&o.length>0)&&(t.workers_dev??e.workers_dev)!==!1},S=(t,e,r)=>{if(!f.test(e))throw new Error(`@lunora/codegen: service key "${e}" must be an identifier — it becomes ctx.services.${e}`);if(r.entrypoint!==void 0&&!f.test(r.entrypoint))throw new Error(`@lunora/codegen: service "${e}": entrypoint "${r.entrypoint}" must name an exported WorkerEntrypoint class`);const o=w(r.dir)?r.dir:m(t,r.dir),{config:n,path:s}=y(e,o),{main:c,name:l}=n;if(typeof l!="string"||l==="")throw new Error(`@lunora/codegen: service "${e}": ${s} declares no Worker "name"`);if(typeof c!="string"||c==="")throw new Error(`@lunora/codegen: service "${e}": ${s} declares no "main" entry module`);const d=Object.entries(n.env??{}).map(([i,a])=>[i,a??{}]);return{binding:b(e),...r.entrypoint===void 0?{}:{entrypoint:r.entrypoint},envWorkers:Object.fromEntries(d.flatMap(([i,a])=>typeof a.name=="string"&&a.name!==""?[[i,a.name]]:[])),main:m(o,c),name:e,publicScopes:[...v(n,n)?[""]:[],...d.filter(([,i])=>v(i,n)).map(([i])=>i)],...r.entrypoint===void 0||r.rpc===!1?{}:{rpcEntrypoint:r.entrypoint},worker:l,wranglerPath:s}},j=t=>{const{services:e}=E(t);if(e?.unreadable===!0)throw new Error('@lunora/codegen: lunora.config `services` must be an inline object of { dir: "…", entrypoint?: "…", rpc?: false } literals — codegen reads it without running the file');const r=Object.entries(e?.declared??{}).map(([o,n])=>S(t,o,n)).toSorted((o,n)=>o.name.localeCompare(n.name));for(const[o,n]of r.entries()){const s=r.slice(o+1).find(c=>c.binding===n.binding);if(s!==void 0)throw new Error(`@lunora/codegen: services "${n.name}" and "${s.name}" both map to the binding ${n.binding} — rename one`)}return r},A=t=>{try{return{services:j(t)}}catch(e){return{error:e instanceof Error?e.message:String(e),services:[]}}};export{A as readServiceBindings,j as resolveServiceBindings};
1
+ import{existsSync as g,readFileSync as p}from"node:fs";import{isAbsolute as w,resolve as m,join as u}from"node:path";import{ts as h}from"ts-morph";import{r as E}from"./project-config-file-CD247zmH.mjs";const f=/^[A-Za-z_$][\w$]*$/u,$=["wrangler.jsonc","wrangler.json"],b=t=>`SERVICE_${t.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/gu,"_").toUpperCase()}`,y=(t,e)=>{const r=$.map(n=>u(e,n)).find(n=>g(n));if(r===void 0){const n=g(u(e,"wrangler.toml"))?" (its wrangler.toml is not read — Lunora reads a service's config as JSON(C) only)":"";throw new Error(`@lunora/codegen: service "${t}" points at ${e}, which has no wrangler.jsonc / wrangler.json${n}`)}const o=h.parseConfigFileTextToJson(r,p(r,"utf8"));if(o.error!==void 0||typeof o.config!="object"||o.config===null)throw new Error(`@lunora/codegen: service "${t}": ${r} is not valid JSON(C)`);return{config:o.config,path:r}},v=(t,e)=>{const r=t.route??e.route,o=t.routes??e.routes;return!(r!==void 0||Array.isArray(o)&&o.length>0)&&(t.workers_dev??e.workers_dev)!==!1},S=(t,e,r)=>{if(!f.test(e))throw new Error(`@lunora/codegen: service key "${e}" must be an identifier — it becomes ctx.services.${e}`);if(r.entrypoint!==void 0&&!f.test(r.entrypoint))throw new Error(`@lunora/codegen: service "${e}": entrypoint "${r.entrypoint}" must name an exported WorkerEntrypoint class`);const o=w(r.dir)?r.dir:m(t,r.dir),{config:n,path:s}=y(e,o),{main:c,name:l}=n;if(typeof l!="string"||l==="")throw new Error(`@lunora/codegen: service "${e}": ${s} declares no Worker "name"`);if(typeof c!="string"||c==="")throw new Error(`@lunora/codegen: service "${e}": ${s} declares no "main" entry module`);const d=Object.entries(n.env??{}).map(([i,a])=>[i,a??{}]);return{binding:b(e),...r.entrypoint===void 0?{}:{entrypoint:r.entrypoint},envWorkers:Object.fromEntries(d.flatMap(([i,a])=>typeof a.name=="string"&&a.name!==""?[[i,a.name]]:[])),main:m(o,c),name:e,publicScopes:[...v(n,n)?[""]:[],...d.filter(([,i])=>v(i,n)).map(([i])=>i)],...r.entrypoint===void 0||r.rpc===!1?{}:{rpcEntrypoint:r.entrypoint},worker:l,wranglerPath:s}},j=t=>{const{services:e}=E(t);if(e?.unreadable===!0)throw new Error('@lunora/codegen: lunora.config `services` must be an inline object of { dir: "…", entrypoint?: "…", rpc?: false } literals — codegen reads it without running the file');const r=Object.entries(e?.declared??{}).map(([o,n])=>S(t,o,n)).toSorted((o,n)=>o.name.localeCompare(n.name));for(const[o,n]of r.entries()){const s=r.slice(o+1).find(c=>c.binding===n.binding);if(s!==void 0)throw new Error(`@lunora/codegen: services "${n.name}" and "${s.name}" both map to the binding ${n.binding} — rename one`)}return r},A=t=>{try{return{services:j(t)}}catch(e){return{error:e instanceof Error?e.message:String(e),services:[]}}};export{A as readServiceBindings,j as resolveServiceBindings};
@@ -1 +1 @@
1
- import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./isTestPath-5ruOnRVA.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
1
+ import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./isTestPath-Djd59sWZ.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.266",
3
+ "version": "1.0.0-alpha.267",
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.190",
50
- "@lunora/agent": "1.0.0-alpha.179",
49
+ "@lunora/advisor": "1.0.0-alpha.191",
50
+ "@lunora/agent": "1.0.0-alpha.180",
51
51
  "@lunora/container": "1.0.0-alpha.69",
52
52
  "@lunora/errors": "1.0.0-alpha.50",
53
- "@lunora/platform": "1.0.0-alpha.55",
54
- "@lunora/queue": "1.0.0-alpha.91",
55
- "@lunora/scheduler": "1.0.0-alpha.110",
53
+ "@lunora/platform": "1.0.0-alpha.56",
54
+ "@lunora/queue": "1.0.0-alpha.92",
55
+ "@lunora/scheduler": "1.0.0-alpha.111",
56
56
  "@lunora/values": "1.0.0-alpha.60",
57
57
  "@lunora/workflow": "1.0.0-alpha.71",
58
58
  "@visulima/fs": "6.0.28",
@@ -1 +0,0 @@
1
- import{w as a}from"./classify-procedure-call-DC_O3oNQ.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-BvE4YxG6.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import"./isTestPath-5ruOnRVA.mjs";import"./attribution-B7i322L0.mjs";import"./database-calls-B6ylmcGA.mjs";import"./classify-procedure-call-DC_O3oNQ.mjs";import{d as a}from"./index-B5G7NWDW.mjs";export{a as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-BvE4YxG6.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +0,0 @@
1
- import{l as e,r as f}from"./project-config-file-Cb5ouVEK.mjs";import{PROJECT_CONFIG_FILENAMES as t,findProjectConfigFile as a}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";export{t as PROJECT_CONFIG_FILENAMES,a as findProjectConfigFile,e as loadProjectConfig,f as readProjectConfigLiterals};
@@ -1 +0,0 @@
1
- import{statSync as x,readFileSync as y}from"node:fs";import{basename as S}from"node:path";import{createJiti as E}from"jiti";import{Node as i,Project as P}from"ts-morph";import{findProjectConfigFile as b}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const h=t=>{if(i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t)||i.isNumericLiteral(t))return t.getLiteralText();if(i.isComputedPropertyName(t)){const r=t.getExpression();if(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))return r.getLiteralText()}return t.getText()},c=t=>h(t.getNameNode()),f=new Map,k=async t=>{const r=b(t);if(r===void 0)return{};let e;try{const a=x(r);e=`${String(a.mtimeMs)}:${String(a.size)}`}catch{return{}}const n=f.get(r);if(n?.key===e)return n.value;const s=(async()=>{try{const o=(await E(r,{interopDefault:!1,moduleCache:!1}).import(r))?.default;return{config:o!==null&&typeof o=="object"?o:void 0}}catch(a){return{error:a instanceof Error?a.message:String(a)}}})();return f.set(r,{key:e,value:s}),s},A=t=>{let e=t.getExportAssignments().find(n=>!n.isExportEquals())?.getExpression();for(;e!==void 0&&(i.isSatisfiesExpression(e)||i.isAsExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();if(e!==void 0&&i.isIdentifier(e))for(e=t.getVariableDeclaration(e.getText())?.getInitializer();e!==void 0&&(i.isSatisfiesExpression(e)||i.isAsExpression(e));)e=e.getExpression();return e!==void 0&&i.isObjectLiteralExpression(e)?e:void 0},d=(t,r)=>i.isPropertyAssignment(t)?t.getInitializer():r.getVariableDeclaration(c(t))?.getInitializer(),g=t=>{let r=t;for(;r!==void 0&&(i.isSatisfiesExpression(r)||i.isAsExpression(r)||i.isParenthesizedExpression(r));)r=r.getExpression();return r},v=(t,r,e)=>{const n=g(t);if(n===void 0||!i.isObjectLiteralExpression(n))return{unreadable:!0};const s=n.getProperties(),a=s.filter(u=>i.isPropertyAssignment(u)&&!i.isComputedPropertyName(u.getNameNode())||i.isShorthandPropertyAssignment(u));if(a.length!==s.length)return{unreadable:!0};const o=a.find(u=>c(u)===e);if(o===void 0)return{absent:!0};const l=d(o,r);return l===void 0?{unreadable:!0}:{literal:l}},j=(t,r)=>{const e=v(t,r,"minSeverity");return"absent"in e?{advisor:{}}:"literal"in e&&i.isStringLiteral(e.literal)?{advisor:{minSeverity:e.literal.getLiteralValue()}}:{advisor:{unreadable:!0}}},N=(t,r)=>{const e=v(t,r,"exclude");if("absent"in e)return{codegen:{}};if(!("literal"in e)||!i.isArrayLiteralExpression(e.literal))return{codegen:{unreadable:!0}};const n=[];for(const s of e.literal.getElements()){if(!i.isStringLiteral(s)&&!i.isNoSubstitutionTemplateLiteral(s)||s.getLiteralValue().startsWith("!"))return{codegen:{unreadable:!0}};n.push(s.getLiteralValue())}return{codegen:{exclude:n}}},w=new Map([["advisor",{advisor:{unreadable:!0}}],["codegen",{codegen:{unreadable:!0}}],["remote",{unreadable:!0}],["target",{unreadable:!0}]]),L=(t,r)=>{const e=t.getProperty(r);if(e!==void 0)return(i.isPropertyAssignment(e)?e.getInitializer():void 0)??"unreadable"},m=(t,r)=>{const e=L(t,r);if(e!==void 0)return e!=="unreadable"&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():!1},z=t=>{const r=L(t,"rpc");if(r!==void 0)return r!=="unreadable"&&i.isFalseLiteral(r)?!1:"unreadable"},C=t=>{const r=g(t);if(r===void 0||!i.isObjectLiteralExpression(r))return{services:{unreadable:!0}};const e={};for(const n of r.getProperties()){if(!i.isPropertyAssignment(n)||i.isComputedPropertyName(n.getNameNode()))return{services:{unreadable:!0}};const s=g(n.getInitializer());if(s===void 0||!i.isObjectLiteralExpression(s)||s.getProperties().some(u=>!i.isPropertyAssignment(u)))return{services:{unreadable:!0}};const a=m(s,"dir"),o=m(s,"entrypoint"),l=z(s);if(typeof a!="string"||o===!1||l==="unreadable")return{services:{unreadable:!0}};e[c(n)]={dir:a,...o===void 0?{}:{entrypoint:o},...l===void 0?{}:{rpc:l}}}return{services:{declared:e}}},T=(t,r)=>{if(i.isGetAccessorDeclaration(t)||i.isMethodDeclaration(t))return w.get(c(t))??{};if(!i.isPropertyAssignment(t)&&!i.isShorthandPropertyAssignment(t))return{};const e=c(t);if(e==="advisor")return j(d(t,r),r);if(e==="services")return C(d(t,r));if(e==="codegen")return N(d(t,r),r);if(e!=="target"&&e!=="remote")return{};const n=d(t,r);return n===void 0?{unreadable:!0}:e==="target"?i.isStringLiteral(n)?{target:n.getLiteralValue()}:{unreadable:!0}:i.isTrueLiteral(n)||i.isFalseLiteral(n)?{remote:n.getLiteralValue()}:i.isObjectLiteralExpression(n)?{remote:!0}:{unreadable:!0}},F=t=>{const r=b(t);if(r===void 0)return{};let e;try{e=y(r,"utf8")}catch{return{unreadable:!0}}const s=new P({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(S(r),e,{overwrite:!0}),a=A(s);if(a===void 0)return{unreadable:!0};if(a.getProperties().some(l=>i.isSpreadAssignment(l))){const l=u=>a.getProperties().some(p=>!i.isSpreadAssignment(p)&&c(p)===u);return{...l("advisor")?{advisor:{unreadable:!0}}:{},...l("codegen")?{codegen:{unreadable:!0}}:{},...l("services")?{services:{unreadable:!0}}:{},unreadable:!0}}let o={};for(const l of a.getProperties())o={...o,...T(l,s)};return o};export{c as a,k as l,h as p,F as r};