@lunora/codegen 1.0.0-alpha.20 → 1.0.0-alpha.200

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 (94) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/index.d.mts +3324 -1151
  4. package/dist/index.d.ts +3324 -1151
  5. package/dist/index.mjs +1 -34
  6. package/dist/packem_shared/AGENTS_FILENAME-B78F7DuQ.mjs +1 -0
  7. package/dist/packem_shared/CONTAINERS_FILENAME-CQoUu7n7.mjs +1 -0
  8. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  9. package/dist/packem_shared/DEFAULT_TARGET-DtzlGawL.mjs +1 -0
  10. package/dist/packem_shared/FLAGS_FILENAME-CoTJH0-7.mjs +1 -0
  11. package/dist/packem_shared/GENERATED_HEADER-CEgr9fSF.mjs +1 -0
  12. package/dist/packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs +1 -0
  13. package/dist/packem_shared/MUTATORS_FILENAME-B7EXNAFK.mjs +1 -0
  14. package/dist/packem_shared/NOTIFY_FILENAME-Bgq52CnU.mjs +1 -0
  15. package/dist/packem_shared/OPENRPC_VERSION-D6-0Hn3B.mjs +3 -0
  16. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-D29yBg5X.mjs +1 -0
  17. package/dist/packem_shared/QUEUES_FILENAME-Q3CF3uYr.mjs +1 -0
  18. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BpSBAMAb.mjs +9 -0
  19. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs +2 -0
  20. package/dist/packem_shared/SDK_LANGUAGES-CFyux-74.mjs +371 -0
  21. package/dist/packem_shared/SHAPES_FILENAME-Bvd5kgsF.mjs +1 -0
  22. package/dist/packem_shared/SchemaSnapshotParseError-lUWe6lPo.mjs +18 -0
  23. package/dist/packem_shared/WORKFLOWS_FILENAME-BaSbufF2.mjs +1 -0
  24. package/dist/packem_shared/buildOpenApiDocument-DCGde3iO.mjs +3 -0
  25. package/dist/packem_shared/chain-BWtZ1NER.mjs +1 -0
  26. package/dist/packem_shared/classify-procedure-call-BIlyTUBD.mjs +1 -0
  27. package/dist/packem_shared/context-property-calls-H37QsE0Q.mjs +1 -0
  28. package/dist/packem_shared/describeErrorLevelFindings-D23VSkFP.mjs +1 -0
  29. package/dist/packem_shared/discoverAuthApiCalls-DoblmzUW.mjs +1 -0
  30. package/dist/packem_shared/discoverCrons-CMu0sA8k.mjs +1 -0
  31. package/dist/packem_shared/discoverFunctions-DRf4ucil.mjs +1 -0
  32. package/dist/packem_shared/discoverHttpRoutes-_ME7hLcW.mjs +1 -0
  33. package/dist/packem_shared/discoverHyperdriveCalls-DP3Vb0HC.mjs +1 -0
  34. package/dist/packem_shared/discoverInserts-COk-Sm_n.mjs +1 -0
  35. package/dist/packem_shared/discoverMaskProcedures-CNkhbP5z.mjs +1 -0
  36. package/dist/packem_shared/discoverMigrations-B_sYrTyE.mjs +1 -0
  37. package/dist/packem_shared/discoverNondeterministicCalls-Dy6k2aPS.mjs +1 -0
  38. package/dist/packem_shared/discoverQueries-BQXP4BZ0.mjs +1 -0
  39. package/dist/packem_shared/discoverR2sqlCalls-FaK1-wbV.mjs +1 -0
  40. package/dist/packem_shared/discoverRlsMetadata-DwULXx5T.mjs +1 -0
  41. package/dist/packem_shared/discoverRlsProcedures-D_J8cH-m.mjs +1 -0
  42. package/dist/packem_shared/discoverSandboxUsage-DskdDbkM.mjs +1 -0
  43. package/dist/packem_shared/discoverSchema-DoZtXwLg.mjs +1 -0
  44. package/dist/packem_shared/discoverStorageRulesMetadata-C3ywuLJd.mjs +1 -0
  45. package/dist/packem_shared/emit-BuaY_1hY.mjs +2659 -0
  46. package/dist/packem_shared/emitApp-nInCbDo8.mjs +838 -0
  47. package/dist/packem_shared/exported-procedure-chains-Bqdp4ywr.mjs +1 -0
  48. package/dist/packem_shared/formatAdvisories-DwmUKYuc.mjs +2 -0
  49. package/dist/packem_shared/index-C4eKBBMk.mjs +1 -0
  50. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  51. package/dist/packem_shared/isTypedSchema-B_qlBbE-.mjs +2 -0
  52. package/dist/packem_shared/listLunoraSourceFiles-D4xthUf-.mjs +1 -0
  53. package/dist/packem_shared/module-specifiers-WF8iAydP.mjs +1 -0
  54. package/dist/packem_shared/parse-validator-tdRHHDzh.mjs +1 -0
  55. package/dist/packem_shared/paths-C-9fwEgQ.mjs +1 -0
  56. package/dist/packem_shared/queries-CPlxXagL.mjs +1 -0
  57. package/dist/packem_shared/readPackageDependencies-C6h6FZuP.mjs +1 -0
  58. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  59. package/dist/packem_shared/schemaFromIr-BWFnvCVg.mjs +1 -0
  60. package/dist/packem_shared/unwrap-handler-return-Da99uRXX.mjs +1 -0
  61. package/package.json +16 -7
  62. package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
  63. package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
  64. package/dist/packem_shared/FLAGS_FILENAME-B1vE0LIo.mjs +0 -139
  65. package/dist/packem_shared/GENERATED_HEADER-CI272wRm.mjs +0 -3245
  66. package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
  67. package/dist/packem_shared/LUNORA_SOLUTION_RULES-BTejmZp-.mjs +0 -131
  68. package/dist/packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs +0 -81
  69. package/dist/packem_shared/OPENRPC_VERSION-t5pV2NIN.mjs +0 -60
  70. package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +0 -119
  71. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BMez-jgr.mjs +0 -1039
  72. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs +0 -245
  73. package/dist/packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs +0 -94
  74. package/dist/packem_shared/WORKFLOWS_FILENAME-CCisG0Vy.mjs +0 -124
  75. package/dist/packem_shared/buildOpenApiDocument-Dx5QftUn.mjs +0 -183
  76. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  77. package/dist/packem_shared/discoverAuthApiCalls-CoirYbg6.mjs +0 -62
  78. package/dist/packem_shared/discoverCrons-Cev7RRAf.mjs +0 -257
  79. package/dist/packem_shared/discoverFunctions-BWMczzBx.mjs +0 -465
  80. package/dist/packem_shared/discoverHttpRoutes-CfP6cMzt.mjs +0 -131
  81. package/dist/packem_shared/discoverInserts-C7zxXkUf.mjs +0 -61
  82. package/dist/packem_shared/discoverMaskProcedures-Cm81kwrb.mjs +0 -217
  83. package/dist/packem_shared/discoverMigrations-Bi5nJ0mJ.mjs +0 -97
  84. package/dist/packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs +0 -122
  85. package/dist/packem_shared/discoverQueries-B0wGT-xe.mjs +0 -62
  86. package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +0 -80
  87. package/dist/packem_shared/discoverRlsMetadata-BS9GOGC5.mjs +0 -280
  88. package/dist/packem_shared/discoverSchema-KYq55qu3.mjs +0 -864
  89. package/dist/packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs +0 -97
  90. package/dist/packem_shared/emitApp-cOSypPuO.mjs +0 -659
  91. package/dist/packem_shared/formatAdvisories-DdjK7sgh.mjs +0 -81
  92. package/dist/packem_shared/parse-validator-Cabb60UV.mjs +0 -133
  93. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  94. package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
@@ -0,0 +1 @@
1
+ import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-BIlyTUBD.mjs";const f=s=>{const i=[];for(const r of s.getVariableStatements())if(r.isExported())for(const t of r.getDeclarations()){const e=t.getInitializer(),o=e&&a.isCallExpression(e)?n(e):void 0;o?.receiver&&i.push({name:t.getName(),receiver:o.receiver})}return i};export{f as e};
@@ -0,0 +1,2 @@
1
+ import{runAdvisor as i}from"@lunora/advisor";const d=n=>[...n.indexes.map(e=>({fields:e.fields,kind:"index",name:e.name,unique:e.unique})),...n.searchIndexes.map(e=>({fields:[e.field,...e.filterFields??[]],kind:"search",name:e.name})),...n.rankIndexes.map(e=>({fields:[...e.sortBy.map(r=>r.field),...e.partitionBy??[]],kind:"rank",name:e.name})),...n.vectorIndexes.filter(e=>e.field!==void 0).map(e=>({fields:[e.field],kind:"vector",name:e.name})),...(n.geoIndexes??[]).map(e=>({fields:[e.field],kind:"geo",name:e.name}))],l=n=>{const e={};for(const[r,s]of Object.entries(n.shape))e[r]=s.kind==="optional"?s.inner?.kind??"optional":s.kind;return e},m=n=>({rlsMode:n.rlsMode,tables:n.tables.map(e=>({externallyManaged:e.externallyManaged??!1,externalSource:e.externalSource?{hasReconcile:e.externalSource.hasReconcile??!1,hasSoftDelete:e.externalSource.hasSoftDelete??!1,hasTenantBy:e.externalSource.hasTenantBy,mode:e.externalSource.mode,unanalyzable:e.externalSource.unanalyzable}:void 0,columnKinds:l(e),fields:Object.keys(e.shape),indexes:d(e),isPublic:e.isPublic??!1,name:e.name,relations:e.relations.map(r=>({field:r.field,kind:r.kind,name:r.name,onDelete:r.onDelete,references:r.references,table:r.table})),commitOrdered:e.commitOrdered,shardKind:typeof e.shardMode=="string"?e.shardMode:"shardBy",softDelete:e.softDelete,ttl:e.ttl}))}),c=n=>n.map(e=>({exportName:e.exportName,file:`lunora/${e.filePath}.ts`,table:e.table})),u=n=>n.map(e=>({exportName:e.exportName,file:`lunora/${e.filePath}.ts`,line:e.line,owner:e.owner})),f=n=>{const{argumentValidators:e,mutators:r,queries:s,schema:t,shapes:o,...a}=n;return{...a,argValidators:e,mutators:r===void 0?void 0:u(r),queries:s??[],schema:m(t),shapes:o===void 0?void 0:c(o)}},p=n=>i(f(n),{source:"static"}),v=n=>{if(n.length===0)return"";const e=`@lunora/codegen: ${String(n.length)} schema advisor finding${n.length===1?"":"s"}`,r=n.map(s=>` [${s.level}] ${s.name}: ${s.detail}`);return[e,...r].join(`
2
+ `)};export{v as formatAdvisories,p as lintSchema,f as toAdvisorContext};
@@ -0,0 +1 @@
1
+ import{Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as m,tablesAccessedIn as d}from"./listLunoraSourceFiles-D4xthUf-.mjs";import{w as g,c as p}from"./classify-procedure-call-BIlyTUBD.mjs";const u=e=>{if(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e))return;const t=e.getNameNode();return r.isStringLiteral(t)?t.getLiteralValue():e.getName()},h=e=>g(e,"use","mask"),x=e=>{if(r.isPropertyAssignment(e)){const t=e.getInitializer();if(t&&r.isStringLiteral(t)){const s=t.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},k=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const i of t.getProperties()){const n=u(i);if(n===void 0||!r.isPropertyAssignment(i))continue;const o=i.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=u(a);c!==void 0&&s.push({column:c,table:n})}}return s},v=e=>{const t=h(e);return{maskColumns:t.flatMap(s=>k(s)),usesMask:t.length>0}},P=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),C=new Set(["delete","insert","patch","replace"]),M=(e,t)=>{if(!r.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const i=p(s);if(!i)return;const n=i.receiver?v(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:o,tablesWritten:a}=d(e,P,C);return{exportName:e.getName(),file:t,maskColumns:n.maskColumns,tablesRead:o,tablesWritten:a,usesMask:n.usesMask,visibility:i.visibility}},E=(e,t)=>{const s=[];for(const i of f(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=m(t,i);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,o);l&&s.push(l)}}return s};export{u as a,E as d,h as m,x as s};
@@ -0,0 +1 @@
1
+ const e=l=>l.shardMode==="global"&&l.globalBackend!=="hyperdrive",o=l=>l.shardMode==="global"&&l.globalBackend==="hyperdrive";export{e as isD1GlobalTable,o as isHyperdriveGlobalTable};
@@ -0,0 +1,2 @@
1
+ const b=/[^a-zA-Z0-9]+/gu,M=/([a-z0-9])([A-Z])/gu,p=t=>t.split(b).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),L=t=>t.replaceAll(M,"$1_$2").replaceAll(b,"_").toLowerCase(),d=t=>t===void 0?!1:["$ref","allOf","anyOf","enum","items","oneOf","properties","type"].some(e=>e in t),O=t=>t==="query"?"query":t==="action"?"action":"mutation",i=(t,e=0)=>{if(e>32||t===null||typeof t!="object")return!1;if(Array.isArray(t))return t.some(o=>i(o,e+1));const r=t;if(r.type==="integer"&&r.format==="int64"||r.type==="string"&&r.contentEncoding==="base64")return!0;const{properties:n}=r;return n!==null&&typeof n=="object"&&Object.values(n).some(o=>i(o,e+1))?!0:["additionalProperties","allOf","anyOf","items","oneOf"].some(o=>i(r[o],e+1))},R=t=>t.replaceAll(/[\n\r\u2028\u2029]+/gu," ").replaceAll("*/","* /").replaceAll('"""','" ""'),T=t=>t.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(`
2
+ `,"\\n").replaceAll("\r","\\r"),j=["$","{","'","$","'","}"].join(""),D=t=>T(t).split("$").join(j),_=(t,e)=>t.argsType!==void 0?e.typed(t.argsType):t.takesArgs?e.untyped:e.none,f=32,h=(t,e=0)=>{if(e>f||t===null||typeof t!="object")return!1;const r=t;return r.type==="null"||Array.isArray(r.type)&&r.type.includes("null")?!0:["anyOf","oneOf"].some(n=>{const o=r[n];return Array.isArray(o)&&o.some(s=>h(s,e+1))})},E=(t,e,r)=>e.length===0?r===0?[]:[t]:e.map(n=>({properties:{...t.properties,...n.properties},required:new Set([...t.required,...n.required])})),C=t=>{const{properties:e}=t;if(e===null||typeof e!="object")return[];const r=t.required;return[{properties:e,required:new Set(Array.isArray(r)?r.filter(n=>typeof n=="string"):[])}]},m=(t,e,r)=>{const n=t[e];return Array.isArray(n)?n.flatMap(o=>A(o,r+1)):[]},A=(t,e=0)=>{if(e>f||t===null||typeof t!="object")return[];const r=t,n=[...C(r),...m(r,"allOf",e)],o={properties:Object.assign({},...n.map(a=>a.properties)),required:new Set(n.flatMap(a=>[...a.required]))},s=[...m(r,"anyOf",e),...m(r,"oneOf",e)];return E(o,s,n.length)},S=(t,e=0)=>{if(e>f||t===null||typeof t!="object")return[];const r=t,n=[r];for(const o of["anyOf","oneOf","allOf"]){const s=r[o];if(Array.isArray(s))for(const a of s)n.push(...S(a,e+1))}return n},y=(t,e,r,n=0)=>{if(n>f||t===null||typeof t!="object")return;const o=A(t),s=[...new Set(o.flatMap(a=>Object.keys(a.properties)))].toSorted((a,l)=>a.localeCompare(l));for(const a of s){const l=[...e,a],u=o.every(c=>c.required.has(a)),g=o.map(c=>c.properties[a]).filter(c=>c!==void 0);u?g.some(c=>h(c))&&r.nullable.push(l):r.optional.push(l);for(const c of g)y(c,l,r,n+1)}for(const a of S(t))for(const l of["additionalProperties","items"]){const u=a[l];u!==null&&typeof u=="object"&&y(u,[...e,"*"],r,n+1)}},N=(t,e)=>t.join("\0").localeCompare(e.join("\0")),k=t=>{const e={nullable:[],optional:[]};y(t,[],e);const r=n=>[...new Map(n.map(o=>[o.join("\0"),o])).values()].toSorted(N);return{nullable:r(e.nullable),optional:r(e.optional)}},w=t=>{const[e="",r=""]=t.name.split(":"),n=`${p(e)}${p(r)}`,o=t.params?.[0]?.schema,s=t.result?.schema;return{argsNullPaths:k(o),argsType:d(o)&&!i(o)?`${n}Args`:void 0,takesArgs:d(o),functionName:r,functionPath:t.name,namespace:e,resultType:d(s)&&!i(s)?`${n}Result`:void 0,summary:t.summary??t.name,verb:O(t["x-lunora-function-kind"])}},x=t=>{const e=new Map;for(const r of t.methods){const n=w(r),o=e.get(n.namespace);o===void 0?e.set(n.namespace,[n]):o.push(n)}return[...e.entries()].toSorted(([r],[n])=>r.localeCompare(n)).map(([r,n])=>({methods:n.toSorted((o,s)=>o.functionName.localeCompare(s.functionName)),name:r}))},I=t=>t.methods.flatMap(e=>{const r=w(e);return[{name:r.argsType,schema:e.params?.[0]?.schema},{name:r.resultType,schema:e.result?.schema}]}).filter(e=>e.name!==void 0&&e.schema!==void 0).toSorted((e,r)=>e.name.localeCompare(r.name)),P=/^[A-Za-z][A-Za-z0-9]*$/u,$=t=>P.test(t),q=t=>{const e=new Map;for(const r of t.methods){const n=p(r.functionName);if(!$(n))throw new Error(`sdk: function "${r.functionPath}" produces the invalid identifier "${n}" — rename the export so it starts with a letter.`);const o=r.verb==="query"?[n,`Subscribe${n}`,`Watch${n}`]:[n];for(const s of o){const a=e.get(s);if(a!==void 0){const l=s.startsWith("Watch")?' (the Dart target emits a "watch" Stream member for every query)':"";throw new Error(`sdk: functions "${a}" and "${r.functionPath}" both generate "${s}"${l} — rename one so the generated methods stay distinct.`)}e.set(s,r.functionPath)}}},z=t=>{const e=new Map;for(const r of t){const n=p(r.name);if(!$(n))throw new Error(`sdk: namespace "${r.name}" produces the invalid identifier "${n}" — rename the file so it starts with a letter.`);const o=e.get(n);if(o!==void 0)throw new Error(`sdk: namespaces "${o}" and "${r.name}" both generate "${n}" — rename one so the generated types stay distinct.`);e.set(n,r.name),q(r)}},v=t=>t.flatMap(e=>e.methods),H=t=>[`GENERATED by \`lunora sdk generate --lang ${t}\` — do not edit.`,"Run the command again to regenerate."],U=(t,e)=>{const r=n=>n!==void 0&&new RegExp(String.raw`\b${n}\b`,"u").test(e)?n:void 0;return t.map(n=>({methods:n.methods.map(o=>({...o,argsType:r(o.argsType),resultType:r(o.resultType)})),name:n.name}))},W=t=>t.methods.filter(e=>i(e.params?.[0]?.schema)||i(e.result?.schema)).map(e=>e.name).toSorted((e,r)=>e.localeCompare(r)),Z=(t,e)=>[...new Set(v(t).flatMap(r=>[r.argsType,r.resultType]).filter(r=>r!==void 0&&!new RegExp(String.raw`\b${r}\b`,"u").test(e)))].toSorted((r,n)=>r.localeCompare(n)),F=t=>[...new Set(v(t).flatMap(e=>[e.argsType,e.resultType]).filter(e=>e!==void 0))].toSorted((e,r)=>e.localeCompare(r));export{v as allMethods,_ as argsChoice,z as assertGeneratable,R as commentText,H as generatedHeaderLines,i as hasUnrepresentableWireType,d as isTypedSchema,D as kotlinLiteral,I as modelSources,k as nullPathsOf,w as parseMethod,x as parseSpec,F as referencedModels,T as stringLiteral,p as toPascalCase,L as toSnakeCase,Z as undeclaredModels,W as unrepresentableFunctions,O as verbForKind,U as withDeclaredModels};
@@ -0,0 +1 @@
1
+ import{readdirSync as E,realpathSync as A,lstatSync as P,statSync as b}from"node:fs";import{dirname as v,join as u,relative as O,sep as L,extname as x}from"node:path";import{Node as r,SyntaxKind as m}from"ts-morph";import{diagnosticAt as F}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const R=/\.ts$/u,f=(t,e)=>O(t,e).split(L).join("/").replace(R,""),N=new Set(["_generated","node_modules"]),T=(t,e,s)=>t==="schema.ts"&&e===s,I=t=>{try{return b(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},S=(t,e,s,n)=>{let i,o;try{i=E(t),o=A(t)}catch{return e}if(n.has(o))return e;n.add(o);for(const a of i){const l=u(t,a),c=I(l);c!==void 0&&(c.isDirectory()?N.has(a)||S(l,e,s,n):c.isFile()&&x(a)===".ts"&&!T(a,t,s)&&e.push(l))}return e},h=t=>S(t,[],t,new Set),D=["src/server","src/index.ts","src/worker.ts"],_=new Set([".ts",".tsx"]),y=(t,e=[])=>{let s;try{s=P(t)}catch{return e}if(s.isFile())return _.has(x(t))&&e.push(t),e;if(!s.isDirectory())return e;for(const n of E(t))n==="_generated"||n==="node_modules"||y(u(t,n),e);return e},C=t=>{const e=v(t),s=h(t).map(i=>({displayPath:f(t,i),filePath:i})),n=new Set(s.map(i=>i.filePath));for(const i of D)for(const o of y(u(e,i)))n.has(o)||(n.add(o),s.push({displayPath:f(e,o),filePath:o}));return s},w=(t,e,s)=>{const n=[];for(const{displayPath:i,filePath:o}of e){const a=t.getSourceFile(o)??t.addSourceFileAtPath(o);for(const l of a.getDescendantsOfKind(m.CallExpression)){const c=s(l,i);c!==void 0&&n.push(c)}}return n},W=(t,e,s)=>w(t,h(e).map(n=>({displayPath:f(e,n),filePath:n})),s),q=(t,e,s)=>w(t,C(e),s),M=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},X=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:void 0}const s=t.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return;const n=s.getProperty("handler");if(!n||!r.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(r.isArrowFunction(i)||r.isFunctionExpression(i))?i:void 0},Y=(t,e)=>{if(!t||!r.isObjectLiteralExpression(t))return;const s=t.getProperty(e);return s&&r.isPropertyAssignment(s)?s.getInitializer():void 0},p=t=>r.isPropertyAccessExpression(t)&&t.getName()==="db"||r.isIdentifier(t)&&t.getText()==="db",z=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),H=t=>{const e=t.getExpression();if(!r.isPropertyAccessExpression(e)||!z.has(e.getName()))return;const s=e.getExpression();if(p(s)){const n=t.getArguments()[0];return{options:t.getArguments()[1],table:n&&r.isStringLiteral(n)?n.getLiteralText():""}}if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(p(n))return{options:t.getArguments()[0],table:s.getName()}}},g=(t,e)=>{const s=t.getExpression();return!r.isPropertyAccessExpression(s)||!e.has(s.getName())?!1:p(s.getExpression())},d=t=>{const e=t.getArguments()[0];return e&&r.isStringLiteral(e)?e.getLiteralText():""},U=(t,e,s)=>{const n=new Set,i=new Set;for(const o of t.getDescendantsOfKind(m.CallExpression))if(g(o,e)){const a=d(o);a!==""&&n.add(a)}else if(g(o,s)){const a=d(o);a!==""&&i.add(a)}return{tablesRead:[...n],tablesWritten:[...i]}},j=t=>{let e=t;for(;e&&(r.isAsExpression(e)||r.isSatisfiesExpression(e)||r.isParenthesizedExpression(e)||r.isNonNullExpression(e));)e=e.getExpression();return e},G=t=>{const e=j(t);return e&&r.isCallExpression(e)?e:void 0},J=t=>{const e=t.getExportAssignment(i=>!i.isExportEquals());if(!e)return;const s=e.getExpression();if(!r.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&r.isVariableDeclaration(n)?n.getInitializer():s},Q=t=>{const e=t.getArguments()[1];return e&&r.isStringLiteral(e)?e.getLiteralValue():""},Z=(t,e)=>{if(!r.isObjectLiteralExpression(t))return;const s=t.getProperty(e);if(!s||!r.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&r.isStringLiteral(n)?n.getLiteralText():void 0},k=t=>{const e=t.getStatements(),[s]=e;if(e.length!==1||s===void 0||!r.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&r.isObjectLiteralExpression(n)?n:void 0},tt=t=>{if(r.isObjectLiteralExpression(t))return t;if(r.isParenthesizedExpression(t)){const e=t.getExpression();return r.isObjectLiteralExpression(e)?e:void 0}return r.isBlock(t)?k(t):void 0},et=t=>r.isIdentifier(t)&&t.getText()==="ctx",st=t=>(e,s,n)=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw F(e,`${t} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{R as TS_EXTENSION_RE,W as collectCallRows,q as collectSecurityCallRows,J as defaultExportExpression,M as enclosingExportName,X as handlerOf,et as isContextIdentifier,p as isDatabaseAccessor,Q as limitNameOf,h as listLunoraSourceFiles,C as listSecurityScanFiles,f as lunoraRelativePath,tt as objectLiteralFromCallbackBody,Y as propertyInitializer,H as readTargetOf,st as stringPropertyFor,Z as stringPropertyOf,d as tableArgumentOf,U as tablesAccessedIn,j as unwrapExpression,G as unwrapToCallExpression};
@@ -0,0 +1 @@
1
+ const r=/(?:^|\/)_generated\/server(?:\.js)?$/u,s=new Set(["@lunora/server","lunorash/server"]),o=e=>s.has(e),n=e=>r.test(e),t=e=>o(e)||n(e),a=new Set(["@lunora/scheduler",...s]),E=e=>a.has(e);export{t as a,o as b,E as i};
@@ -0,0 +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";let f;const _=e=>{f=e},E=/^[A-Za-z_$][\w$]*$/u,m=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),A=(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}},k=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),p=new Set(["check","email","int","length","max","min","pattern","positive","url"]),N=new Set(["meta"]),I=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()},L=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||!L(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},T="v",w=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()===T},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&w(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?M(e):{kind:"any",sourceText:e.getText()}},D=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,D(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=r.getName();if(!E.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,R=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),V=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},O=(e,t,r)=>{if(k.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return V(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:R(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}`)}},x=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},M=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(m.has(r)||p.has(r)||N.has(r)||I.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(m.has(r))return A(a,r);if(!p.has(r))return a;const s=r==="max"&&a.kind==="string"?x(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return O(r,i,e)};export{b as a,c as p,u as r,_ as s};
@@ -0,0 +1 @@
1
+ const a=/\/index$/u,s=/[^\dA-Za-z]/gu,c=e=>e.replace(a,"").replaceAll(s,"_");export{c as s};
@@ -0,0 +1 @@
1
+ import{Node as r,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as h,isDatabaseAccessor as A}from"./listLunoraSourceFiles-D4xthUf-.mjs";const m=(t,e)=>{if(t.getText()!==e)return!1;const s=t.getParent();return r.isPropertyAccessExpression(s)&&s.getNameNode()===t?!1:!(r.isPropertyAssignment(s)&&s.getNameNode()===t)},x=(t,e)=>r.isIdentifier(t)?m(t,e):t.getDescendantsOfKind(f.Identifier).some(s=>m(s,e)),g=t=>x(t,"ctx"),I=t=>{let e=t;for(;r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isNonNullExpression(e);)e=e.getExpression();return r.isIdentifier(e)?e:void 0},E=t=>x(t,"args"),u=t=>{if(!r.isIdentifier(t))return;const e=t.getText(),s=t.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o));if(s===void 0)return;const i=t.getStart();let n,a=-1;for(const o of s.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==e)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<i&&l>a&&(n=c,a=l)}return n},C=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},K=t=>{if(r.isCallExpression(t)||r.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(r.isCallExpression(e)||r.isNewExpression(e))},O=t=>{if(g(t))return!0;const e=u(t);if(e!==void 0&&g(e))return!0;const s=e??t;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(f.Identifier)).some(n=>{const a=u(n);return a!==void 0&&g(a)})},p=(t,e)=>x(t,e),T=(t,e)=>{if(p(t,e))return!0;const s=u(t);if(s!==void 0&&p(s,e))return!0;const i=I(t);if(i!==void 0){const n=u(i);return n!==void 0&&p(n,e)}return!1},v=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return"<module>"},N=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),b=t=>{const e=t.getExpression();if(!r.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const s=e.getExpression();return A(s)},y=t=>{const e=[];let s=t;for(;;){const i=s.getParent();if(!i||!r.isPropertyAccessExpression(i))break;const n=i.getParent();if(!n||!r.isCallExpression(n))break;e.push(i.getName()),s=n}return e},D=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,w=t=>{let e=t;for(;;){const s=e.getParent();if(!s||!r.isPropertyAccessExpression(s))return!1;const i=s.getParent();if(!i||!r.isCallExpression(i))return!1;if(s.getName()==="filter"){const n=i.getArguments()[0];if(n&&D.test(n.getText()))return!0}e=i}},R=t=>{const e=t.getArguments()[0];return e&&r.isStringLiteral(e)?e.getLiteralText():""},_=(t,e)=>{const s=[];for(const i of P(e)){const n=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=h(e,i);for(const o of n.getDescendantsOfKind(f.CallExpression)){if(!b(o))continue;const c=y(o),l=c.includes("filter");s.push({exportName:v(o),file:a,filtersPrimaryKey:l&&w(o),hasFilter:l,hasIndex:c.some(d=>N.has(d)),line:o.getStartLineNumber(),table:R(o),terminal:c.findLast(d=>S.has(d))})}}return s};export{O as a,K as b,T as c,_ as d,v as e,p as f,C as i,E as r,u as s};
@@ -0,0 +1 @@
1
+ import{existsSync as r,readFileSync as a}from"node:fs";import{join as d}from"node:path";const m=o=>{const n=d(o,"package.json");if(r(n))try{const s=JSON.parse(a(n,"utf8")),t=new Set;for(const c of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const e=s[c];if(e!==null&&typeof e=="object")for(const i of Object.keys(e))t.add(i)}return t}catch{return}};export{m as default};
@@ -0,0 +1 @@
1
+ const s=/[\w+/=-]{40,}/u,n=/[a-z]/u,E=/[A-Z]/u,_=/\d/u,c=/\b(?:[\da-f]{32,}|[\dA-F]{32,})\b/u,o=t=>{const e=s.exec(t)?.[0];return e===void 0?!1:n.test(e)&&E.test(e)&&_.test(e)},i=t=>c.test(t),r=/\b(?:sk|rk)_live_[\dA-Za-z]{20,}/u,a=/\bAKIA[\dA-Z]{16}\b/u,R=/\bgh[posru]_[\dA-Za-z]{36,}/u,d=/\bsk-[\dA-Za-z]{32,}/u,A=/\bxox[abprs]-[\dA-Za-z-]{10,}/u,k=/-----BEGIN(?: [A-Z]+)? PRIVATE KEY-----/u,S=[{kind:"stripe_live_key",test:t=>r.test(t)},{kind:"aws_access_key",test:t=>a.test(t)},{kind:"github_token",test:t=>R.test(t)},{kind:"openai_key",test:t=>d.test(t)},{kind:"slack_token",test:t=>A.test(t)},{kind:"private_key",test:t=>k.test(t)},{kind:"high_entropy",test:o},{kind:"hex_secret",test:i}],u=new Set(["hex_secret","high_entropy"]),h=new Set(["auth","bearer","credential","credentials","hmac","key","keys","passphrase","password","private","secret","secrets","signature","signing","token"]),p=/([a-z\d])([A-Z])/gu,T=/[^A-Za-z\d]+/u,I=t=>t.replaceAll(p,"$1 $2").split(T).filter(Boolean).map(e=>e.toLowerCase()),l=t=>t!==void 0&&I(t).some(e=>h.has(e)),K=t=>S.find(e=>e.test(t))?.kind,b=t=>u.has(t),g=t=>`${t.slice(0,4)}…(${String(t.length)} chars)`;export{S as SECRET_RULES,b as isHeuristicSecretKind,l as isSecretishName,g as redact,K as secretKindOf};
@@ -0,0 +1 @@
1
+ const s=e=>{try{return JSON.parse(e)}catch{const t=e.trim();return t.length>=2&&(t.startsWith("'")||t.startsWith('"'))&&t.at(-1)===t[0]?t.slice(1,-1):t}},n=e=>{const t={};return e.column!==void 0&&(t.column={defaultValue:e.column.hasDefault===!0?null:void 0,notNull:e.column.notNull,unique:e.column.unique}),e.inner!==void 0&&(t.inner=n(e.inner)),e.members!==void 0&&(t.members=e.members.map(a=>n(a))),e.shape!==void 0&&(t.shape=Object.fromEntries(Object.entries(e.shape).map(([a,l])=>[a,n(l)]))),e.tableName!==void 0&&(t.tableName=e.tableName),e.literalValue!==void 0&&(t.value=s(e.literalValue)),e.keyType!==void 0&&(t.keyValidator=n(e.keyType)),e.valueType!==void 0&&(t.valueValidator=n(e.valueType)),{_meta:t,kind:e.kind}},m=e=>({tables:Object.fromEntries(e.tables.map(a=>[a.name,{shape:Object.fromEntries(Object.entries(a.shape).map(([l,o])=>[l,n(o)]))}]))});export{m as schemaFromIr};
@@ -0,0 +1 @@
1
+ import{Node as u,SyntaxKind as f}from"ts-morph";import{posix as y}from"node:path";const j=/\bany\b(?!\s*(?:\?\s*)?:)/u,R=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,k=e=>j.test(e.replaceAll(R,"")),w="/_generated/",U=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},C=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,E=e=>{for(const t of e.getAncestors())if(u.isModuleDeclaration(t)){const n=C.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},D=new WeakMap,L=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=D.get(n.compilerSymbol);return r===void 0&&(r=new Map,D.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},x=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),O=(e,t,n)=>e.getModuleSpecifierValue()===t&&x(e,n)?n:void 0,$=(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},P=(e,t,n)=>{if(!x(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:L(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},h=/^\.\.?(?:$|\/)/u,q=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),B=(e,t)=>{const n=t.getModuleSpecifierValue();if(!h.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:q.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${y.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=y.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},F=(e,t,n)=>{const r=E(t);for(const s of e.getImportDeclarations()){const i=r===void 0?$(s,t)??P(s,t,n):O(s,r,n);if(i!==void 0)return{exportName:i,specifier:B(e,s)??s.getModuleSpecifierValue()}}},K=(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))}),g={kind:"verbatim"},m={kind:"expand"},V=new Set([f.ClassDeclaration,f.EnumDeclaration,f.EnumMember,f.InterfaceDeclaration,f.TypeAliasDeclaration]),W=e=>E(e)!==void 0||u.isExportable(e)&&e.isExported(),I=(e,t,n)=>{const r=e.getSourceFile();if(r.getSymbol()===void 0&&E(e)===void 0||!V.has(e.getKind()))return g;const s=r.getFilePath();if(s.includes(w))return g;if(s===n)return m;const i=u.isEnumMember(e)?e.getParent():e;if(!u.hasName(i))return m;const o=F(t.getSourceFile(),i,i.getName());return o===void 0?W(i)?g:m:K(o.specifier,t)?m:{kind:"qualify",qualified:o}},N=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1;for(const a of[s,r].flatMap(c=>c?.getDeclarations()??[])){const c=I(a,t,n);if(c.kind==="qualify"&&i.has(a))return c;o||=c.kind!=="verbatim"}return o?m:g},G=(e,t,n)=>{const r=u.isPropertySignature(e)||u.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return g;let s=!1;for(const i of[r,...r.getDescendantsOfKind(f.TypeReference)].filter(o=>u.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=I(a,t,n);if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?m:g},X=/^[A-Za-z_$][\w$]*$/u,H=e=>X.test(e)?e:JSON.stringify(e),M=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},p=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,b=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),N(e,t,n).kind!=="verbatim"||M(e).some(s=>b(s,t,n,r))?!0:p(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>G(i,t,n).kind!=="verbatim")?!0:b(s.getTypeAtLocation(t),t,n,r)):!1),Y=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(u.isPropertySignature(n)||u.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},J=32,z=8,Q=(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 o?.isUnion()?`(${a})[]`:`${a}[]`},Z=(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(" | ")},ee=(e,t,n,r,s,i)=>{if(!p(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),l=Y(a,c),_=l&&c.isUnion()?c.getUnionTypes().filter(v=>!v.isUndefined()):[c],T=[];for(const v of _){const A=i(v,t,n,r+1,s);if(A===void 0)return;T.push(A)}o.push(`${H(a.getName())}${l?"?":""}: ${T.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},te=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},ne=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>u.isClassDeclaration(t)||u.isClassExpression(t)),S=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>J)return!0;const i=new Set(r).add(e);if(M(e).some(l=>S(l,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return S(o,t,n+1,i,s);if(U(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(l=>l?.getDeclarations()??[]).some(l=>u.isClassDeclaration(l)||u.isClassExpression(l)))return!0;const c=p(e)&&e.getProperties().some(l=>S(l.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},re=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const l=o(c,n,r,s+1,i);if(l===void 0)return;a.push(l)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},se=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>u.isEnumDeclaration(t)||u.isEnumMember(t)),d=(e,t,n,r,s)=>{if(r>z||s.has(e))return;const i=N(e,t,n);if(i.kind==="verbatim"&&!b(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!ne(e)){if(e.isEnumLiteral())return te(e);if(i.kind==="qualify"&&!se(e)){const a=re(i.qualified,e,t,n,r,o,d);if(a!==void 0)return a}return e.isArray()?Q(e,t,n,r,o,d):e.isUnion()?Z(e,t,n,r,o,d):ee(e,t,n,r,o,d)}},ae=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"||k(i)||S(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();return b(n,e,o)?d(n,e,o,0,new Set)??"unknown":i};export{d as e,k as i,b as r,ae as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.20",
3
+ "version": "1.0.0-alpha.200",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,14 +46,23 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.10",
50
- "@lunora/container": "1.0.0-alpha.5",
51
- "@lunora/queue": "1.0.0-alpha.1",
52
- "@lunora/scheduler": "1.0.0-alpha.3",
53
- "@lunora/values": "1.0.0-alpha.3",
54
- "@lunora/workflow": "1.0.0-alpha.4",
49
+ "@lunora/advisor": "1.0.0-alpha.145",
50
+ "@lunora/agent": "1.0.0-alpha.124",
51
+ "@lunora/container": "1.0.0-alpha.52",
52
+ "@lunora/errors": "1.0.0-alpha.39",
53
+ "@lunora/platform": "1.0.0-alpha.32",
54
+ "@lunora/queue": "1.0.0-alpha.59",
55
+ "@lunora/scheduler": "1.0.0-alpha.76",
56
+ "@lunora/values": "1.0.0-alpha.49",
57
+ "@lunora/workflow": "1.0.0-alpha.57",
58
+ "jiti": "^2.7.0",
59
+ "quicktype-core": "^26.0.0",
55
60
  "ts-morph": "^28.0.0"
56
61
  },
62
+ "peerDependencies": {
63
+ "@lunora/server": ">=1.0.0-alpha.91 <2.0.0-0",
64
+ "@lunora/shard-engine": ">=1.0.0-alpha.45 <2.0.0-0"
65
+ },
57
66
  "engines": {
58
67
  "node": "^22.15.0 || >=24.11.0"
59
68
  }
@@ -1,224 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { containerClassName, containerBindingName, normalizeContainerImage } from '@lunora/container';
4
- import { SyntaxKind, Node } from 'ts-morph';
5
- import { diagnosticAt } from './CodegenDiagnosticError-DeblMkzO.mjs';
6
-
7
- const CONTAINERS_FILENAME = "containers.ts";
8
- const isDefineContainer = (identifier) => {
9
- const symbol = identifier.getSymbol();
10
- if (!symbol) {
11
- return identifier.getText() === "defineContainer";
12
- }
13
- for (const declaration of symbol.getDeclarations()) {
14
- if (!Node.isImportSpecifier(declaration)) {
15
- continue;
16
- }
17
- if (declaration.getImportDeclaration().getModuleSpecifierValue() !== "@lunora/container") {
18
- return false;
19
- }
20
- return declaration.getNameNode().getText() === "defineContainer";
21
- }
22
- return false;
23
- };
24
- const stringProperty = (expression, exportName, property) => {
25
- if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
26
- return expression.getLiteralValue();
27
- }
28
- throw diagnosticAt(
29
- expression,
30
- `container "${exportName}": \`${property}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`
31
- );
32
- };
33
- const numberProperty = (expression, exportName, property) => {
34
- if (Node.isNumericLiteral(expression)) {
35
- return expression.getLiteralValue();
36
- }
37
- throw diagnosticAt(
38
- expression,
39
- `container "${exportName}": \`${property}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`
40
- );
41
- };
42
- const imageFromExpression = (expression, exportName) => {
43
- if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
44
- return normalizeContainerImage(expression.getLiteralValue());
45
- }
46
- if (Node.isObjectLiteralExpression(expression)) {
47
- const registry = expression.getProperty("registry");
48
- if (registry && Node.isPropertyAssignment(registry)) {
49
- const initializer = registry.getInitializerOrThrow();
50
- return normalizeContainerImage({ registry: stringProperty(initializer, exportName, "image.registry") });
51
- }
52
- const build = expression.getProperty("build");
53
- if (build && Node.isPropertyAssignment(build)) {
54
- const initializer = build.getInitializerOrThrow();
55
- return normalizeContainerImage({ build: stringProperty(initializer, exportName, "image.build") });
56
- }
57
- }
58
- throw diagnosticAt(expression, `container "${exportName}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`);
59
- };
60
- const stringRecordLiteral = (expression) => {
61
- if (!Node.isObjectLiteralExpression(expression)) {
62
- return void 0;
63
- }
64
- const record = {};
65
- for (const property of expression.getProperties()) {
66
- if (!Node.isPropertyAssignment(property)) {
67
- continue;
68
- }
69
- const value = property.getInitializerOrThrow();
70
- if (Node.isStringLiteral(value) || Node.isNoSubstitutionTemplateLiteral(value)) {
71
- record[property.getName()] = value.getLiteralValue();
72
- }
73
- }
74
- return Object.keys(record).length > 0 ? record : void 0;
75
- };
76
- const rolloutLiteral = (expression) => {
77
- if (!Node.isObjectLiteralExpression(expression)) {
78
- return void 0;
79
- }
80
- const rollout = {};
81
- for (const property of expression.getProperties()) {
82
- if (!Node.isPropertyAssignment(property)) {
83
- continue;
84
- }
85
- const key = property.getName();
86
- const value = property.getInitializerOrThrow();
87
- if (Node.isNumericLiteral(value) && (key === "gracePeriodSeconds" || key === "stepPercentage")) {
88
- rollout[key] = value.getLiteralValue();
89
- }
90
- }
91
- return rollout.gracePeriodSeconds === void 0 && rollout.stepPercentage === void 0 ? void 0 : rollout;
92
- };
93
- const booleanLiteral = (expression) => {
94
- if (Node.isTrueLiteral(expression)) {
95
- return true;
96
- }
97
- if (Node.isFalseLiteral(expression)) {
98
- return false;
99
- }
100
- return void 0;
101
- };
102
- const stringOrNumberLiteral = (expression) => {
103
- if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
104
- return expression.getLiteralValue();
105
- }
106
- if (Node.isNumericLiteral(expression)) {
107
- return expression.getLiteralValue();
108
- }
109
- return void 0;
110
- };
111
- const instanceTypeFromExpression = (expression, exportName) => {
112
- if (Node.isStringLiteral(expression)) {
113
- return expression.getLiteralValue();
114
- }
115
- if (Node.isObjectLiteralExpression(expression)) {
116
- const custom = {};
117
- for (const property of expression.getProperties()) {
118
- if (!Node.isPropertyAssignment(property)) {
119
- throw diagnosticAt(property, `container "${exportName}": \`instanceType\` must be an object of static number literals`);
120
- }
121
- const key = property.getName();
122
- if (key !== "diskMb" && key !== "memoryMib" && key !== "vcpu") {
123
- throw diagnosticAt(property, `container "${exportName}": unknown \`instanceType\` field "${key}" — expected vcpu, memoryMib, or diskMb`);
124
- }
125
- custom[key] = numberProperty(property.getInitializerOrThrow(), exportName, `instanceType.${key}`);
126
- }
127
- return custom;
128
- }
129
- throw diagnosticAt(expression, `container "${exportName}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`);
130
- };
131
- const containerFromCall = (call, exportName) => {
132
- const argument = call.getArguments()[0];
133
- if (!argument || !Node.isObjectLiteralExpression(argument)) {
134
- throw diagnosticAt(call, `container "${exportName}": defineContainer must be passed an inline object literal`);
135
- }
136
- const ir = {
137
- bindingName: containerBindingName(exportName),
138
- className: containerClassName(exportName),
139
- exportName,
140
- image: { buildContext: ".", dockerfilePath: "./Dockerfile", kind: "dockerfile" }
141
- };
142
- let sawImage = false;
143
- for (const property of argument.getProperties()) {
144
- if (!Node.isPropertyAssignment(property)) {
145
- continue;
146
- }
147
- const key = property.getName();
148
- const initializer = property.getInitializerOrThrow();
149
- switch (key) {
150
- case "buildArgs": {
151
- ir.buildArgs = stringRecordLiteral(initializer);
152
- break;
153
- }
154
- case "enableInternet": {
155
- ir.enableInternet = booleanLiteral(initializer);
156
- break;
157
- }
158
- case "image": {
159
- ir.image = imageFromExpression(initializer, exportName);
160
- sawImage = true;
161
- break;
162
- }
163
- case "instanceType": {
164
- ir.instanceType = instanceTypeFromExpression(initializer, exportName);
165
- break;
166
- }
167
- case "maxInstances": {
168
- ir.maxInstances = numberProperty(initializer, exportName, "maxInstances");
169
- break;
170
- }
171
- case "name": {
172
- ir.name = stringProperty(initializer, exportName, "name");
173
- break;
174
- }
175
- case "rollout": {
176
- ir.rollout = rolloutLiteral(initializer);
177
- break;
178
- }
179
- case "sleepAfter": {
180
- ir.sleepAfter = stringOrNumberLiteral(initializer);
181
- break;
182
- }
183
- }
184
- }
185
- if (!sawImage) {
186
- throw diagnosticAt(argument, `container "${exportName}": defineContainer requires a static \`image\` property`);
187
- }
188
- return ir;
189
- };
190
- const containersFromSource = (source) => {
191
- const containers = [];
192
- for (const declaration of source.getVariableDeclarations()) {
193
- if (!declaration.isExported()) {
194
- continue;
195
- }
196
- const initializer = declaration.getInitializer();
197
- if (initializer?.getKind() !== SyntaxKind.CallExpression) {
198
- continue;
199
- }
200
- const call = initializer;
201
- const callee = call.getExpression();
202
- if (!Node.isIdentifier(callee) || !isDefineContainer(callee)) {
203
- continue;
204
- }
205
- const nameNode = declaration.getNameNode();
206
- if (!Node.isIdentifier(nameNode)) {
207
- throw diagnosticAt(nameNode, "defineContainer exports must be plain named exports (no destructuring)");
208
- }
209
- containers.push(containerFromCall(call, nameNode.getText()));
210
- }
211
- return containers;
212
- };
213
- const discoverContainers = (project, lunoraDirectory) => {
214
- const containersPath = join(lunoraDirectory, CONTAINERS_FILENAME);
215
- if (!existsSync(containersPath)) {
216
- return [];
217
- }
218
- const source = project.getSourceFile(containersPath) ?? project.addSourceFileAtPath(containersPath);
219
- const containers = containersFromSource(source);
220
- containers.sort((a, b) => a.exportName.localeCompare(b.exportName));
221
- return containers;
222
- };
223
-
224
- export { CONTAINERS_FILENAME, discoverContainers };
@@ -1,23 +0,0 @@
1
- class CodegenDiagnosticError extends Error {
2
- column;
3
- file;
4
- line;
5
- constructor(message, file, line, column) {
6
- super(message);
7
- this.name = "CodegenDiagnosticError";
8
- this.file = file;
9
- this.line = line;
10
- this.column = column;
11
- }
12
- }
13
- const diagnosticAt = (node, detail, meta) => {
14
- const sourceFile = node.getSourceFile();
15
- const file = sourceFile.getFilePath();
16
- const line = node.getStartLineNumber();
17
- const { column } = sourceFile.getLineAndColumnAtPos(node.getStart());
18
- const message = `@lunora/codegen: ${detail} (${file}:${line.toString()}:${column.toString()})`;
19
- const error = new CodegenDiagnosticError(message, file, line, column);
20
- return meta ? Object.assign(error, meta) : error;
21
- };
22
-
23
- export { CodegenDiagnosticError, diagnosticAt };
@@ -1,139 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { SyntaxKind, Node } from 'ts-morph';
4
- import { listLunoraSourceFiles } from './discoverFunctions-BWMczzBx.mjs';
5
-
6
- const FLAGS_FILENAME = "flags.ts";
7
- const FLAG_TYPES = /* @__PURE__ */ new Set(["boolean", "number", "object", "string"]);
8
- const FLAGSHIP_PROVIDER_MODULE = "@lunora/flags/providers/flagship";
9
- const isFlagshipProvider = (identifier) => {
10
- const symbol = identifier.getSymbol();
11
- if (!symbol) {
12
- return identifier.getText() === "flagshipProvider";
13
- }
14
- for (const declaration of symbol.getDeclarations()) {
15
- if (!Node.isImportSpecifier(declaration)) {
16
- continue;
17
- }
18
- if (declaration.getImportDeclaration().getModuleSpecifierValue() !== FLAGSHIP_PROVIDER_MODULE) {
19
- return false;
20
- }
21
- return declaration.getNameNode().getText() === "flagshipProvider";
22
- }
23
- return false;
24
- };
25
- const stringPropertyOrUndefined = (argument, property) => {
26
- const node = argument.getProperty(property);
27
- if (!node || !Node.isPropertyAssignment(node)) {
28
- return void 0;
29
- }
30
- const initializer = node.getInitializerOrThrow();
31
- if (Node.isStringLiteral(initializer) || Node.isNoSubstitutionTemplateLiteral(initializer)) {
32
- return initializer.getLiteralValue();
33
- }
34
- return void 0;
35
- };
36
- const flagshipIrFromCall = (call) => {
37
- const argument = call.getArguments()[0];
38
- if (argument && Node.isObjectLiteralExpression(argument)) {
39
- const bindingName = stringPropertyOrUndefined(argument, "binding");
40
- if (bindingName !== void 0 && bindingName.length > 0) {
41
- return { bindingName, mode: "binding", provider: "flagship" };
42
- }
43
- }
44
- return { mode: "http", provider: "flagship" };
45
- };
46
- const defaultExportExpression = (source) => {
47
- const assignment = source.getExportAssignment((declaration2) => !declaration2.isExportEquals());
48
- if (!assignment) {
49
- return void 0;
50
- }
51
- const expression = assignment.getExpression();
52
- if (!Node.isIdentifier(expression)) {
53
- return expression;
54
- }
55
- const declaration = expression.getSymbol()?.getValueDeclaration();
56
- if (declaration && Node.isVariableDeclaration(declaration)) {
57
- return declaration.getInitializer();
58
- }
59
- return expression;
60
- };
61
- const providerInitializer = (defineFlagsCall) => {
62
- const argument = defineFlagsCall.getArguments()[0];
63
- if (!argument || !Node.isObjectLiteralExpression(argument)) {
64
- return void 0;
65
- }
66
- const property = argument.getProperty("provider");
67
- return property && Node.isPropertyAssignment(property) ? property.getInitializer() : void 0;
68
- };
69
- const discoverFlags = (project, lunoraDirectory) => {
70
- const flagsPath = join(lunoraDirectory, FLAGS_FILENAME);
71
- if (!existsSync(flagsPath)) {
72
- return void 0;
73
- }
74
- const source = project.getSourceFile(flagsPath) ?? project.addSourceFileAtPath(flagsPath);
75
- const exported = defaultExportExpression(source);
76
- if (!exported || !Node.isCallExpression(exported)) {
77
- return { provider: "custom" };
78
- }
79
- const provider = providerInitializer(exported);
80
- if (provider && Node.isCallExpression(provider)) {
81
- const callee = provider.getExpression();
82
- if (Node.isIdentifier(callee) && isFlagshipProvider(callee)) {
83
- return flagshipIrFromCall(provider);
84
- }
85
- }
86
- return { provider: "custom" };
87
- };
88
- const isContextIdentifier = (node) => Node.isIdentifier(node) && node.getText() === "ctx";
89
- const flagTypeFromAccess = (access) => {
90
- const name = access.getName();
91
- if (!FLAG_TYPES.has(name)) {
92
- return void 0;
93
- }
94
- const receiver = access.getExpression();
95
- if (!Node.isPropertyAccessExpression(receiver)) {
96
- return void 0;
97
- }
98
- if (receiver.getName() === "flags" && isContextIdentifier(receiver.getExpression())) {
99
- return name;
100
- }
101
- const inner = receiver.getExpression();
102
- if (receiver.getName() === "details" && Node.isPropertyAccessExpression(inner) && inner.getName() === "flags" && isContextIdentifier(inner.getExpression())) {
103
- return name;
104
- }
105
- return void 0;
106
- };
107
- const flagKeyFromCall = (call) => {
108
- const callee = call.getExpression();
109
- if (!Node.isPropertyAccessExpression(callee)) {
110
- return void 0;
111
- }
112
- const type = flagTypeFromAccess(callee);
113
- if (type === void 0) {
114
- return void 0;
115
- }
116
- const argument = call.getArguments()[0];
117
- if (!argument || !(Node.isStringLiteral(argument) || Node.isNoSubstitutionTemplateLiteral(argument))) {
118
- return void 0;
119
- }
120
- const key = argument.getLiteralValue();
121
- return key.length > 0 ? { key, type } : void 0;
122
- };
123
- const discoverFlagKeys = (project, lunoraDirectory) => {
124
- const found = /* @__PURE__ */ new Map();
125
- for (const filePath of listLunoraSourceFiles(lunoraDirectory)) {
126
- const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
127
- for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
128
- const candidate = flagKeyFromCall(call);
129
- if (candidate && !found.has(candidate.key)) {
130
- found.set(candidate.key, candidate.type);
131
- }
132
- }
133
- }
134
- return [...found.entries()].map(([key, type]) => {
135
- return { key, type };
136
- }).toSorted((a, b) => a.key.localeCompare(b.key));
137
- };
138
-
139
- export { FLAGS_FILENAME, discoverFlagKeys, discoverFlags };