@lunora/codegen 1.0.0-alpha.26 → 1.0.0-alpha.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- package/README.md +1 -1
- package/dist/index.d.mts +3851 -1254
- package/dist/index.d.ts +3851 -1254
- package/dist/index.mjs +1 -34
- package/dist/packem_shared/AGENTS_FILENAME-UhIaG4BZ.mjs +1 -0
- package/dist/packem_shared/CAPABILITY_PROBES-DFsutD7g.mjs +25 -0
- package/dist/packem_shared/CONTAINERS_FILENAME-DhUL5rDc.mjs +1 -0
- package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
- package/dist/packem_shared/DEFAULT_TARGET-7sHexLjO.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-BINQ51Zq.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-dFyrHgQ0.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-D1Q6EUII.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-bbHHFQ_t.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-CGu1_YK7.mjs +3 -0
- package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs +1 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSLmXUQA.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BVhRHIbS.mjs +11 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs +2 -0
- package/dist/packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs +372 -0
- package/dist/packem_shared/SHAPES_FILENAME-DuR5hLW1.mjs +1 -0
- package/dist/packem_shared/SchemaSnapshotParseError-CPOXlFhI.mjs +18 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-IqUyMQgM.mjs +1 -0
- package/dist/packem_shared/attribution-sW_DHmLO.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-DOsv1HEF.mjs +3 -0
- package/dist/packem_shared/capabilitiesUsedBy-CzqyN9dX.mjs +1 -0
- package/dist/packem_shared/chain-BTbLDrrU.mjs +1 -0
- package/dist/packem_shared/classify-procedure-call-OnJoKgqu.mjs +1 -0
- package/dist/packem_shared/context-property-calls-BEBjylgc.mjs +1 -0
- package/dist/packem_shared/context-root-KWXRWlv6.mjs +1 -0
- package/dist/packem_shared/database-calls-rLPCL3-U.mjs +1 -0
- package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
- package/dist/packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-CNj9-Jch.mjs +1 -0
- package/dist/packem_shared/discoverCrons-BqTY53L5.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-DPH4drkg.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-MRFziTCb.mjs +1 -0
- package/dist/packem_shared/discoverHyperdriveCalls-BcVkR6nw.mjs +1 -0
- package/dist/packem_shared/discoverInserts-Duz40u-s.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-DYJhbHF3.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-D2P2n7JE.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-Cxf6T2Oi.mjs +1 -0
- package/dist/packem_shared/discoverQueries-CWmNPVHm.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-DnKwop5c.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-BXXEFXjf.mjs +1 -0
- package/dist/packem_shared/discoverRlsProcedures-Des596JU.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-Bjl8A_hj.mjs +1 -0
- package/dist/packem_shared/discoverSchema-Cd3iH6q5.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-DGFonj0I.mjs +1 -0
- package/dist/packem_shared/emitAgents-Dotqck8w.mjs +1 -0
- package/dist/packem_shared/emitApi-xDIHPRPH.mjs +154 -0
- package/dist/packem_shared/emitApp-RNU41dtm.mjs +860 -0
- package/dist/packem_shared/emitCrons-DsXsg1uG.mjs +83 -0
- package/dist/packem_shared/emitDataModel-DSk9AkJe.mjs +113 -0
- package/dist/packem_shared/emitDrizzleSchema-DohtnI8c.mjs +15 -0
- package/dist/packem_shared/emitFunctions-evl8Mx1a.mjs +249 -0
- package/dist/packem_shared/emitServer-DymRagL2.mjs +368 -0
- package/dist/packem_shared/emitShard-DHMYSP4m.mjs +1 -0
- package/dist/packem_shared/exported-procedure-chains-58yS9zc8.mjs +1 -0
- package/dist/packem_shared/fingerprintSchemaSources-BzFVnBfa.mjs +1 -0
- package/dist/packem_shared/formatAdvisories-DwmUKYuc.mjs +2 -0
- package/dist/packem_shared/handler-reference-C1oBljnl.mjs +1 -0
- package/dist/packem_shared/index-BusOvbeQ.mjs +1 -0
- package/dist/packem_shared/ir-DBSvhNa-.mjs +1 -0
- package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
- package/dist/packem_shared/isTypedSchema-CKzc3ioR.mjs +4 -0
- package/dist/packem_shared/json-data-Chfs2Cz5.mjs +1 -0
- package/dist/packem_shared/listLunoraSourceFiles-DRes9d5p.mjs +1 -0
- package/dist/packem_shared/loadProjectConfig-CuGQsqYS.mjs +1 -0
- package/dist/packem_shared/module-specifiers-WF8iAydP.mjs +1 -0
- package/dist/packem_shared/modules-CsA-QVJ6.mjs +1 -0
- package/dist/packem_shared/parse-validator-B4mFs19C.mjs +1 -0
- package/dist/packem_shared/paths-C-9fwEgQ.mjs +1 -0
- package/dist/packem_shared/qualifiers-Cw8dEDbh.mjs +1 -0
- package/dist/packem_shared/readPackageDependencies-C6h6FZuP.mjs +1 -0
- package/dist/packem_shared/readServiceBindings-CnvEGOir.mjs +1 -0
- package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
- package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-BWFnvCVg.mjs +1 -0
- package/dist/packem_shared/shard-WXSIZRpD.mjs +1438 -0
- package/dist/packem_shared/shard-runtime-B1nU9CRa.mjs +321 -0
- package/dist/packem_shared/shared-BXUKWh7t.mjs +9 -0
- package/dist/packem_shared/unwrap-handler-return-D7E2TKkS.mjs +1 -0
- package/package.json +16 -7
- package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
- package/dist/packem_shared/FLAGS_FILENAME-B1vE0LIo.mjs +0 -139
- package/dist/packem_shared/GENERATED_HEADER-CYaSI_qY.mjs +0 -3268
- package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
- package/dist/packem_shared/LUNORA_SOLUTION_RULES-BTejmZp-.mjs +0 -131
- package/dist/packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs +0 -81
- package/dist/packem_shared/OPENRPC_VERSION-CRe5l79E.mjs +0 -60
- package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +0 -119
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-cgOjZTVY.mjs +0 -1137
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs +0 -245
- package/dist/packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs +0 -94
- package/dist/packem_shared/WORKFLOWS_FILENAME-CCisG0Vy.mjs +0 -124
- package/dist/packem_shared/buildOpenApiDocument-BlpXQe2K.mjs +0 -183
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-CoirYbg6.mjs +0 -62
- package/dist/packem_shared/discoverCrons-Cev7RRAf.mjs +0 -257
- package/dist/packem_shared/discoverFunctions-BWMczzBx.mjs +0 -465
- package/dist/packem_shared/discoverHttpRoutes-CfP6cMzt.mjs +0 -131
- package/dist/packem_shared/discoverInserts-C7zxXkUf.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-Cm81kwrb.mjs +0 -217
- package/dist/packem_shared/discoverMigrations-Bi5nJ0mJ.mjs +0 -97
- package/dist/packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs +0 -122
- package/dist/packem_shared/discoverQueries-B0wGT-xe.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-BS9GOGC5.mjs +0 -280
- package/dist/packem_shared/discoverSchema-KYq55qu3.mjs +0 -864
- package/dist/packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs +0 -97
- package/dist/packem_shared/emitApp-C38fHt_1.mjs +0 -675
- package/dist/packem_shared/formatAdvisories-DdjK7sgh.mjs +0 -81
- package/dist/packem_shared/parse-validator-Cabb60UV.mjs +0 -133
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-KWXRWlv6.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||p(e),l=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),u=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!l.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},m=(e,t,s)=>{const o=new Set,i=new Set;for(const a of e.getDescendantsOfKind(g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,u as r,m as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const u=t=>t.output!==void 0&&t.output.kind!=="any"&&t.kind!=="stream";export{u as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=r=>[...new Set(r)].toSorted((e,a)=>e.localeCompare(a)),s=r=>o(r.filter(e=>e.level==="ERROR").map(e=>e.name)),t=r=>o(r.filter(e=>e.level==="error").map(e=>e.name)),i=r=>({advisoryNames:s(r.advisories),platformDiagnosticNames:t(r.platformDiagnostics)});export{i as describeErrorLevelFindings,s as errorAdvisoryNames,t as errorPlatformDiagnosticNames,o as sortedUniqueNames};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as t}from"ts-morph";import{collectCallRows as n,propertyKeyName as p}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{c as a}from"./attribution-sW_DHmLO.mjs";const c=s=>{const r=s.getExpression();if(!t.isPropertyAccessExpression(r))return!1;const e=r.getExpression();return t.isPropertyAccessExpression(e)?e.getName()==="authApi":t.isIdentifier(e)&&e.getText()==="authApi"},u=s=>{const r=s.getArguments()[0];if(r===void 0)return!1;if(!t.isObjectLiteralExpression(r))return!0;for(const e of r.getProperties())if((t.isPropertyAssignment(e)||t.isShorthandPropertyAssignment(e))&&p(e)==="headers"||t.isSpreadAssignment(e))return!0;return!1},A=(s,r)=>n(s,r,(e,o)=>{if(!c(e))return;const i=e.getExpression();return{file:o,hasHeaders:u(e),line:e.getStartLineNumber(),method:t.isPropertyAccessExpression(i)?i.getName():"",scope:a(e)}});export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as I}from"@lunora/scheduler";import{SyntaxKind as m,Node as n}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as b}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y,propertyKeyName as P}from"./listLunoraSourceFiles-DRes9d5p.mjs";const D=new Set([...A,"cron"]),v=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(n.isImportSpecifier(r))return b(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},F=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const s=r.getInitializer();if(s?.getKind()!==m.CallExpression)continue;const i=s.getExpression();n.isIdentifier(i)&&v(i)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;n.isCallExpression(t)||n.isPropertyAccessExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue();if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1;if(n.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(n.isNumericLiteral(r))return-r.getLiteralValue()}if(n.isObjectLiteralExpression(e))return p(e,t);if(n.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},p=(e,t)=>{const r={};for(const s of e.getProperties()){if(!n.isPropertyAssignment(s))throw f(s,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const i=s.getInitializer();i&&(r[P(s)]=_(i,t))}return r},C=(e,t,r)=>{const s=e.getArguments()[t];if(!s||!n.isPropertyAccessExpression(s))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const i=s.getName(),o=s.getExpression();if(!n.isPropertyAccessExpression(o))throw f(s,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=o.getName();return`${$(a)}:${i}`},h=e=>({workflow:{className:e.className,exportName:e.exportName}}),w=e=>({workflow:{className:e.className,exportName:e.exportName}}),T=(e,t,r,s,i,o)=>{const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${s}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},j=(e,t,r,s,i)=>{const o=e.getArguments()[t];if(o&&n.isPropertyAccessExpression(o)){const a=T(o,"workflows",s,r,"workflow",h);if(a)return a;const c=T(o,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&n.isIdentifier(o)){const a=s.get(o.getText()),c=i.get(o.getText());if(a&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(c)return w(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},k=/^@lunora\/scheduler:\s*/u,U=(e,t)=>{const r=x(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!O(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return S(r,`cron expression for job "${t}"`),r},M=(e,t,r)=>{const s=e.getArguments()[1];if(!s||!n.isObjectLiteralExpression(s))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return I(t,p(s,r),r)}catch(i){if(i instanceof R)throw i;const o=i instanceof Error?i.message.replace(k,""):String(i);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},z=(e,t,r,s,i)=>{const o=t.getName();if(!D.has(o)||!r.has(V(t.getExpression())??""))return;const a=x(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=o==="cron"?U(e,a):M(e,o,a),u=j(e,2,a,s,i),l=e.getArguments()[3];return{args:l&&n.isObjectLiteralExpression(l)?p(l,a):{},cron:c,name:a,...u}},H=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},W=(e,t,r=[],s=[])=>{const i=y(t),o=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(s.map(u=>[u.exportName,u]));for(const u of i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=F(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!n.isPropertyAccessExpression(N))continue;const E=z(d,N,g,a,c);E&&o.push(E)}}return o.sort((u,l)=>u.name.localeCompare(l.name)),H(o),o};export{W as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as P}from"./declared-output-Iaar469J.mjs";import{s as b}from"./paths-C-9fwEgQ.mjs";import{findObjectProperty as c,bindingKeyName as N,listLunoraSourceFiles as A,lunoraRelativePath as F}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{e as O,i as z}from"./attribution-sW_DHmLO.mjs";import{u as y,p as C,c as g,r as S}from"./unwrap-handler-return-D7E2TKkS.mjs";import{b as d,c as L}from"./classify-procedure-call-OnJoKgqu.mjs";import{Node as n,SyntaxKind as k}from"ts-morph";import{r as h,p as x,a as I}from"./parse-validator-B4mFs19C.mjs";const T=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=c(e,"handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},w=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":y(e)},V=i=>{let e={};for(const t of d(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(e={...x(s),...e})}return e},D=i=>{const e=d(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?C(e.call,()=>I(t)):void 0},p=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},j=i=>{const e=c(i,"cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=p(t,"scope"),s=v(t,"maxAge"),o=v(t,"staleWhileRevalidate"),a=p(t,"tag"),l=p(t,"vary"),m={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(m).length===0?void 0:m},B=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=j(i),t=c(i,"rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},R=i=>{const e=d(i).find(t=>t.name==="expose");return e?B(e.call.getArguments()[0]):void 0},M=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=c(e,"args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},$=8,u=(i,e=0)=>{if(e>$)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0},f=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?u(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0}if(n.isBindingElement(i)){const t=N(i),o=i.getFirstAncestorByKind(k.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?f(o,e+1):void 0}},W=(i,e=()=>!0)=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const o=[];for(const a of t.getElements().filter(l=>e(l.getName()))){const l=u(a.getNameNode());l&&o.push([a.getName(),l])}return o}if(!e(i.getName()))return[];const r=i.getInitializer(),s=r&&(n.isCallExpression(r)?r:u(r));return s?[[i.getName(),s]]:[]},_=i=>{const e=L(i);if(!e)return;const{receiver:t}=e;if(t){const r=R(t),s=g(()=>D(t)),o=g(()=>w(i)),a=P({kind:e.kind,output:s.value});return S(a?s.erased:o.erased),{args:V(t),...r?{expose:r}:{},kind:e.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:M(i),kind:e.kind,returnType:T(i),visibility:e.visibility}},E=(i,e,t)=>{const r=_(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},H=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",e):void 0;o&&t.push(o)}return t},K=(i,e)=>{const t=O(i),r=i.getVariableStatements().flatMap(o=>o.getDeclarations()).flatMap(o=>W(o,a=>t.has(a))).flatMap(([o,a])=>(t.get(o)??[]).filter(l=>z(l)).flatMap(l=>E(a,l,e)??[])),s=new Set(r.map(o=>o.exportName));return r.push(...H(i,e).filter(o=>!s.has(o.exportName))),r},q=i=>{const e=new Map;for(const t of i){const r=b(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},te=(i,e)=>{const t=A(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=F(e,s);r.push(...K(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),q(r),r};export{te as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-B4mFs19C.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{b as f,d as g}from"./attribution-sW_DHmLO.mjs";import{u as x}from"./unwrap-handler-return-D7E2TKkS.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},b=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},T=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=b(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:T(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./context-property-calls-BEBjylgc.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{c as a}from"./attribution-sW_DHmLO.mjs";import{i as c}from"./database-calls-rLPCL3-U.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./listLunoraSourceFiles-DRes9d5p.mjs";import"./attribution-sW_DHmLO.mjs";import"./database-calls-rLPCL3-U.mjs";import"./classify-procedure-call-OnJoKgqu.mjs";import{d as a}from"./index-BusOvbeQ.mjs";export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as f,Node as s}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as u}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as m,lunoraRelativePath as p,findObjectProperty as h}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{b as I,a as b}from"./attribution-sW_DHmLO.mjs";const P=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return u(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=h(r,i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},v=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!P(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=d(o,"id"),a=b(r,"member");if(a!==void 0){if(n===void 0||n.trim()==="")throw g(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:d(o,"table")??""}}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},E=(r,i)=>{const t=m(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=p(i,o);for(const l of I(n)){const c=v(l,a);c&&e.push(c)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as s,SyntaxKind as r}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as l,handlerOf as c}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{b as d,d as f}from"./attribution-sW_DHmLO.mjs";import{c as u}from"./classify-procedure-call-OnJoKgqu.mjs";const m={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},p=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),h=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},x=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const i=t.getText();return i==="fetch"||i==="Date"?i:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),o=h(t.getExpression());if(o!==void 0)return n==="fetch"&&p.has(o)?"fetch":m[`${o}.${n}`]},N=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),o=n.every(i=>s.isNumericLiteral(i)||s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i));return n.length>0&&o?void 0:"new Date"},E=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=u(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const o=c(t,n.receiver);return o?{exportName:f(e)??e.getName(),handler:o,kind:n.kind}:void 0},S=(e,t)=>{const n=[];for(const o of e.handler.getDescendantsOfKind(r.CallExpression)){const i=x(o);i!==void 0&&n.push({callee:i,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}for(const o of e.handler.getDescendantsOfKind(r.NewExpression)){const i=N(o);i!==void 0&&n.push({callee:i,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}return n},v=(e,t)=>{const n=[];for(const o of d(e)){const i=E(o);i&&n.push(...S(i,t))}return n},T=(e,t)=>{const n=[];for(const o of a(t)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...v(i,l(t,o)))}return n};export{T as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as c}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{c as l}from"./attribution-sW_DHmLO.mjs";import{i as f}from"./database-calls-rLPCL3-U.mjs";const u=new Set(["withGeoIndex","withIndex","withSearchIndex"]),p=new Set(["collect","collectWithScores","first","paginate","take","unique"]),m=n=>{const t=n.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const e=t.getExpression();return f(e)},g=n=>{const t=[];let e=n;for(;;){const r=e.getParent();if(!r||!i.isPropertyAccessExpression(r))break;const s=r.getParent();if(!s||!i.isCallExpression(s))break;t.push(r.getName()),e=s}return t},d=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,E=n=>{let t=n;for(;;){const e=t.getParent();if(!e||!i.isPropertyAccessExpression(e))return!1;const r=e.getParent();if(!r||!i.isCallExpression(r))return!1;if(e.getName()==="filter"){const s=r.getArguments()[0];if(s&&d.test(s.getText()))return!0}t=r}},h=n=>{const t=n.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},y=(n,t)=>c(n,t,(e,r)=>{if(!m(e))return;const s=g(e),a=s.includes("filter");return{file:r,filtersPrimaryKey:a&&E(e),hasFilter:a,hasIndex:s.some(o=>u.has(o)),line:e.getStartLineNumber(),scope:l(e),table:h(e),terminal:s.findLast(o=>p.has(o))}});export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as r}from"./context-property-calls-BEBjylgc.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as x,lunoraRelativePath as h,findObjectProperty as m,stringPropertyOf as c}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{e as A}from"./exported-procedure-chains-58yS9zc8.mjs";import{r as L}from"./chain-BTbLDrrU.mjs";const E=new Set(["delete","insert","read","update"]),P=(e,t,i)=>{const r=e.getArguments()[0];if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){if(!o.isObjectLiteralExpression(n))continue;const a=c(n,"on");a===void 0||!E.has(a)||s.push({file:t,on:a,procedure:i,table:c(n,"table")??""})}return s},u=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=m(e,"permissions");if(!t||!o.isPropertyAssignment(t))return[];const i=t.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const s of i.getElements()){if(o.isStringLiteral(s)){r.push(s.getLiteralText());continue}if(o.isCallExpression(s)){const n=s.getArguments()[0];n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}}return r},f=(e,t)=>t===void 0?e:{...e,description:t},v=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const i=e.getArguments()[1],r=i?c(i,"description"):void 0,s=i?u(i):[];return f({name:t.getLiteralText(),permissions:s},r)}if(o.isObjectLiteralExpression(e)){const t=c(e,"name");return t===void 0?void 0:f({name:t,permissions:u(e)},c(e,"description"))}},y=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const i=m(t,"roles");if(!i||!o.isPropertyAssignment(i))return[];const r=i.getInitializer();if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){const a=v(n);a&&s.push(a)}return s},O=(e,t,i)=>{const r=L(e);return{policies:r.flatMap(s=>P(s,t,i)),roles:r.flatMap(s=>y(s))}},I=(e,t)=>{const i=[],r=new Map;for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=h(t,s);for(const{name:g,receiver:d}of A(n)){const p=O(d,a,g);i.push(...p.policies);for(const l of p.roles)r.has(l.name)||r.set(l.name,l)}}return{policies:i,roles:[...r.values()]}};export{I as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,findObjectProperty as u}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{b as p,d}from"./attribution-sW_DHmLO.mjs";import{t as m}from"./database-calls-rLPCL3-U.mjs";import{c as b}from"./classify-procedure-call-OnJoKgqu.mjs";import{r as g}from"./chain-BTbLDrrU.mjs";const h=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const r=[];for(const s of t.getElements()){if(!o.isObjectLiteralExpression(s))continue;const i=u(s,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}return r},y=e=>{const t=g(e);return{rlsTables:t.flatMap(r=>h(r)),usesRls:t.length>0}},v=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),P=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),T=(e,t)=>{if(!o.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!o.isCallExpression(r))return;const s=b(r);if(!s)return;const i=s.receiver?y(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:a}=m(e,v,P);return{exportName:d(e)??e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},O=(e,t)=>{const r=[];for(const s of c(t)){const i=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=f(t,s);for(const a of p(i)){const l=T(a,n);l&&r.push(l)}}return r};export{O as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{listLunoraSourceFiles as d}from"./listLunoraSourceFiles-DRes9d5p.mjs";const f=new Set(["@lunora/agent","@lunora/agent/sandbox"]),t={browserTool:"usesSandboxBrowser",containerFsTool:"usesSandboxContainer",containerTool:"usesSandboxContainer",fsTool:"usesSandboxFs",jsCodeTool:"usesSandboxLoader"},u=()=>({usesSandboxBrowser:!1,usesSandboxContainer:!1,usesSandboxFs:!1,usesSandboxLoader:!1}),i=o=>{const s=u();if(!f.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=t[e.getNameNode().getText()];n!==void 0&&(s[n]=!0)}return s},b=(o,s)=>{const e=u();for(const n of d(s)){const c=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const a of c.getImportDeclarations()){const l=i(a);for(const r of Object.values(t))e[r]||=l[r]}if(Object.values(t).every(a=>e[a]))break}return e};export{b as discoverSandboxUsage,u as noSandboxUsage,i as scanImportDeclaration};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as M}from"@lunora/errors";import{Node as i,SyntaxKind as R}from"ts-morph";import{diagnosticAt as d}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{createRequire as F}from"node:module";import{join as C}from"node:path";import{findObjectProperty as u,propertyKeyName as I}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{r as B,p as V}from"./parse-validator-B4mFs19C.mjs";import{R as q}from"./reserved-words-CW1QFbTd.mjs";const J=(e,t)=>`table "${e}" is .global() and declares vector index "${t}". Vector sync runs on the shard write path, which a global (D1/Hyperdrive) table's writes never take — the index would stay empty. Drop .global(), or keep the index yourself with ctx.vectors.upsert/deleteByIds.`,U=e=>{switch(typeof e){case"bigint":return e.toString();case"boolean":case"number":return String(e);case"string":return JSON.stringify(e);default:return e===null?"null":void 0}},K=e=>({...e?.defaultValue!==void 0||e?.defaultFn!==void 0||e?.serverDefault!==void 0?{hasDefault:!0}:{},...e?.onUpdateFn===void 0?{}:{hasOnUpdate:!0},notNull:e?.notNull??!0,...e?.unique===!0?{unique:!0}:{}}),m=e=>{const t=e?._meta??{},n=e?.kind??"unknown",s={column:K(t.column),kind:n};switch(n){case"array":case"optional":{s.inner=m(t.inner);break}case"from":break;case"id":{s.tableName=t.tableName;break}case"literal":{s.literalValue=U(t.value);break}case"object":{const r=t.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([o,a])=>[o,m(a)]));break}case"record":{s.valueType=m(t.valueValidator),t.keyValidator!==void 0&&(s.keyType=m(t.keyValidator));break}case"storage":{typeof t.bucket=="string"&&(s.bucket=t.bucket);break}case"union":{const r=t.members??[];s.members=r.map(o=>m(o));break}}return s},Z=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",G=(e,t)=>{const n=[];e.relationMap&&Object.keys(e.relationMap).length>0&&n.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&n.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&n.push("vector indexes"),n.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${t}" declares ${n.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},W=(e,t)=>{const n=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return G(e,t),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:s,name:t,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(r=>({field:r.field,...r.filterFields?{filterFields:r.filterFields}:{},...r.language===void 0?{}:{language:r.language},...r.staged===void 0?{}:{staged:r.staged},...r.strategy===void 0?{}:{strategy:r.strategy},name:r.name})),shape:Object.fromEntries(Object.entries(n).map(([r,o])=>[r,m(o)])),shardMode:Z(e.shardMode),vectorIndexes:[]}},X=e=>{const{key:t,tables:n}=e;if(typeof t!="string"||typeof n!="object"||n===null)return;const s=Object.entries(n).map(([a,l])=>W(l,a)),r=e.vectorIndexes??{},o=Object.entries(r??{}).map(([a,l])=>({...l.dimensions===void 0?{}:{dimensions:l.dimensions},...l.field===void 0?{}:{field:l.field},...l.metadata===void 0?{}:{metadata:l.metadata},...l.metric===void 0?{}:{metric:l.metric},name:a,table:l.table??""}));return{bareTables:s,bareVectorIndexes:o,key:t}},H=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0}},Q=e=>{const t=H(e);if(t===void 0)return;const n=i.isPropertyAccessExpression(e)?e.getName():void 0,s=n===void 0?[]:[n];for(const r of e.getSourceFile().getImportDeclarations()){const o=r.getModuleSpecifierValue();for(const a of r.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===t)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:s};if(r.getDefaultImport()?.getText()===t)return{importedName:"default",moduleSpecifier:o,propertyPath:s};if(r.getNamespaceImport()?.getText()===t&&n!==void 0)return{importedName:n,moduleSpecifier:o,propertyPath:[]}}},Y=(e,t)=>{let n=e[t.importedName];for(const s of t.propertyPath){if(typeof n!="object"||n===null)return;n=n[s]}return n},ee=(e,t)=>{const n=Q(e);if(n)try{const s=F(C(t,"noop.cjs")),r=s.resolve(n.moduleSpecifier),o=s(r),a=Y(o,n);return typeof a!="object"||a===null?void 0:X(a)}catch{return}},te=new Set(["cosine","dot-product","euclidean"]),b=(e,t)=>{const n=u(e,t);if(n&&i.isPropertyAssignment(n))return n.getInitializer()},f=(e,t)=>{const n=b(e,t);if(n&&i.isStringLiteral(n))return n.getLiteralText()},x=(e,t)=>{const n=b(e,t);if(n&&i.isNumericLiteral(n))return Number(n.getLiteralText())},L=(e,t)=>{const n=b(e,t);if(n&&(i.isTrueLiteral(n)||i.isFalseLiteral(n)))return n.getLiteralValue()},h=(e,t)=>{const n=b(e,t);if(n&&i.isArrayLiteralExpression(n))return n.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},O=e=>e&&te.has(e)?e:void 0,y=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",ne=(e,t)=>{const n=h(e,t);return n!==void 0&&n.length>0?n:void 0},A=(e,t,n,s,r)=>{let o=e;for(;;){const a=o.getParent();if(!a||!i.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!i.isCallExpression(l))break;if(a.getName()===t){const c=l.getArguments()[0];if(!c||!i.isStringLiteral(c))throw d(l,`\`.${t}(...)\` expects a string literal (${r})`);const g=c.getLiteralText();if(!s.has(g))throw d(c,`unknown ${n} ${JSON.stringify(g)} — expected ${r}`);return g}o=l}},re=e=>`table "${e}" is both .global() and .ttl(). The TTL sweep is a shard's alarm deleting from that shard's own SQLite, and a global (D1/Hyperdrive) table's rows live outside every shard — so expired rows would never be deleted. Drop .ttl() and expire the rows from a cron, or keep the table shard-local.`,se=/^(?:sqlite_|_cf_|__)/u,ie=/__(?:agg|rank|geo|fts)_/u,oe=e=>se.test(e)||ie.test(e),ae=new Set(["cascade","restrict","set null"]),le=new Set(["aggregate","asId","cdcChangedTables","count","delete","deleteAll","deleteMany","deleteWhere","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","insertMany","insertManyUnsafe","lookupById","normalizeId","patch","patchMany","patchWhere","query","rank","rankBefore","rankPage","rankPageRows","related","relationEdges","replace","restore","system","wipeShard"]),N=/^[A-Za-z_$][\w$]*$/u,S=(e,t)=>{if(le.has(e))throw d(t,`table name "${e}" is reserved — the generated shard binds each table's facade onto the same object that carries \`ctx.db\`'s own members, so this table would overwrite \`ctx.db.${e}\` and every use of it would break. Rename the table.`);if(q.has(e))throw d(t,`table name "${e}" is a reserved JavaScript word — codegen interpolates table names into a bare \`const ${e} = sqliteTable(...)\` binding in the generated Drizzle module, which is a syntax error for a keyword. Rename the table.`);if(!N.test(e))throw d(t,`table name ${JSON.stringify(e)} is not a valid JS identifier — table names are used in generated type names (Doc_<name>) and must match [A-Za-z_$][A-Za-z0-9_$]*. Rename the table.`);if(oe(e))throw d(t,`table name ${JSON.stringify(e)} is reserved for framework tables — a leading \`__\` and the \`__agg_\`/\`__rank_\`/\`__geo_\`/\`__fts_\` infixes name Lunora's own bookkeeping and index companions, so the Studio and the admin API hide and refuse such a table. Rename the table.`)},ce=e=>e&&ae.has(e)?e:void 0,de=e=>{if(!i.isArrowFunction(e))return;let t=e.getBody();if(i.isParenthesizedExpression(t))t=t.getExpression();else if(i.isBlock(t)){const n=t.getStatements().find(s=>i.isReturnStatement(s));t=n&&i.isReturnStatement(n)?n.getExpression()??t:t}return i.isObjectLiteralExpression(t)?t:void 0},fe=e=>{if(!i.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const n=t.getExpression();if(!i.isPropertyAccessExpression(n))return;const s=n.getName();if(s!=="one"&&s!=="many")return;const[r,o]=t.getArguments();if(!r||!i.isStringLiteral(r))throw d(r??t,`relation target table must be a string literal — codegen resolves relation targets statically. Got ${r?r.getText():"no argument"}.`);const a=r.getLiteralText();let l="_unknown_",c="_id",g;return o&&i.isObjectLiteralExpression(o)&&(l=f(o,"field")??l,c=f(o,"references")??c,g=s==="one"?ce(f(o,"onDelete")):void 0),{field:l,kind:s,name:I(e),onDelete:g,references:c,table:a}},ue=e=>{const t=de(e);if(!t)return[];const n=[];for(const s of t.getProperties()){const r=fe(s);r&&n.push(r)}return n},pe=(e,t,n)=>{if(!t.includes("."))return;const[s="",...r]=t.split("."),o=`${s}${r.map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("")}`;throw d(e,`index "${n}" indexes the nested path ${JSON.stringify(t)} — Lunora indexes only top-level columns. Denormalise the value into its own column (e.g. \`${o}\`), index that instead, and keep it in sync with a table \`.triggers()\` beforeInsert/beforeUpdate.`)},ge=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=u(e,"unique");if(!t||!i.isPropertyAssignment(t))return!1;const n=t.getInitializer();if(n===void 0)return!1;if(!i.isTrueLiteral(n)&&!i.isFalseLiteral(n))throw d(n,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(n.getText())}`);return i.isTrueLiteral(n)},me=e=>{const[t,n,s]=e,r=ge(s),o=y(t),a=n&&i.isArrayLiteralExpression(n)?n.getElements():[];for(const c of a)if(!i.isStringLiteral(c))throw d(c,`index "${o}" lists a non-literal field (${JSON.stringify(c.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=a.filter(c=>i.isStringLiteral(c));for(const c of l)pe(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:r}},be=e=>{const[t,n]=e;let s="_unknown_",r,o,a,l;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=h(n,"filterFields"),o=f(n,"language"),a=L(n,"staged"),l=f(n,"strategy")),{field:s,filterFields:r,language:o,name:y(t),staged:a,strategy:l}},xe=e=>{const[t,n]=e;let s="_unknown_",r;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=x(n,"precision")),{field:s,name:y(t),precision:r}},he=e=>{const[t,n]=e,s=t&&i.isStringLiteral(t)?t.getLiteralText():"_unknown_";let r;return n&&i.isObjectLiteralExpression(n)&&(r=x(n,"after")),{after:r,field:s}},ye=e=>{if(!i.isObjectLiteralExpression(e))return;const t=f(e,"field");return t===void 0?void 0:{direction:f(e,"direction")==="desc"?"desc":"asc",field:t}},ve=e=>{const[t,n]=e;let s=[],r;if(n&&i.isObjectLiteralExpression(n)){const o=u(n,"sortBy");if(o&&i.isPropertyAssignment(o)){const a=o.getInitializer();a&&i.isArrayLiteralExpression(a)&&(s=a.getElements().map(l=>ye(l)).filter(l=>l!==void 0))}r=h(n,"partitionBy")}return{name:y(t),partitionBy:r,sortBy:s}},Ee=(e,t)=>{const[n,s]=e,r=n&&i.isStringLiteral(n)?n.getLiteralText():"_unknown_";if(!(!s||!i.isObjectLiteralExpression(s)))return{dimensions:x(s,"dimensions"),field:r,metadata:h(s,"metadata"),metric:O(f(s,"metric")),name:f(s,"index")??"_unnamed_",table:t}},Ie=e=>{const t=e[0];return t&&i.isObjectLiteralExpression(t)&&f(t,"backend")==="hyperdrive"?"hyperdrive":"d1"},Se=e=>{if(e&&i.isObjectLiteralExpression(e)){const t=u(e,"field");if(t&&i.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}}return"deletedAt"},ke=e=>{const t=e[0];return!t||!i.isObjectLiteralExpression(t)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:f(t,"binding")??"",columns:ne(t,"columns"),hasReconcile:u(t,"reconcileEveryMs")!==void 0,hasSoftDelete:u(t,"softDeleteColumn")!==void 0,hasTenantBy:u(t,"tenantBy")!==void 0,idColumn:f(t,"idColumn"),mode:f(t,"mode"),query:f(t,"query")}},we=(e,t,n,s)=>{switch(t){case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(xe(n));break}case"global":{e.shardMode="global",e.globalBackend=Ie(n);break}case"index":{e.indexes.push(me(n));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(ve(n));break}case"relations":{const r=n[0];r&&e.relations.push(...ue(r));break}case"searchIndex":{e.searchIndexes.push(be(n));break}case"shardBy":{const r=n[0];e.shardMode={field:r&&i.isStringLiteral(r)?r.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:Se(n[0])};break}case"source":{e.externalSource=ke(n),e.externallyManaged=!0;break}case"ttl":{e.ttl=he(n);break}case"vectorize":{const r=Ee(n,s);r&&e.vectorIndexes.push(r);break}}},_=["__vocab","_config","_content","_data","_docsize","_idx"],Te=(e,t,n)=>{const s=new Set(n.map(r=>r.name));for(const r of n)for(const o of _){const a=`${r.name}${o}`;if(!s.has(a))continue;const l=o==="__vocab"?`the \`fts5vocab\` companion for "${a}" is created \`IF NOT EXISTS\`, so it silently resolves to "${r.name}"'s — the second index then reads the wrong vocabulary and returns wrong results, with no error`:`creating "${a}" is rejected (\`object name reserved for internal use: SQLITE_ERROR\`), which aborts the shard migration and leaves every sharded table unreadable`;throw d(e,`table "${t}" declares search indexes "${r.name}" and "${a}", whose generated FTS5 tables collide: "${r.name}" already owns "${t}__fts_${a}" as its "${o}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${_.join(", ")}.`)}},_e=(e,t,n)=>{if(n.ttl!==void 0&&n.shardMode==="global")throw d(e,re(t))},P=(e,t)=>{const n={commitOrdered:!1,externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,memory:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let s={},r=e;for(;i.isCallExpression(r);){const o=r.getExpression(),a=r.getArguments();if(i.isPropertyAccessExpression(o))we(n,o.getName(),a,t),r=o.getExpression();else if(i.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];if(l&&i.isObjectLiteralExpression(l))s=V(l);else if(l)throw d(l,`table "${t}" calls defineTable(${JSON.stringify(l.getText())}), but codegen reads the field map syntactically and can only read an object literal. Inline the fields into the defineTable(...) call. To reuse them in an \`.input()\`, derive from the generated \`Doc_${t}\` / \`Insert_${t}\` type instead of sharing the runtime value.`);break}else break}return n.softDelete&&!(n.softDelete.field in s)&&(s={...s,[n.softDelete.field]:{inner:{column:{notNull:!1},kind:"number"},kind:"optional"}}),Te(e,t,n.searchIndexes),_e(e,t,n),{commitOrdered:n.commitOrdered,externallyManaged:n.externallyManaged,externalSource:n.externalSource,geoIndexes:n.geoIndexes,globalBackend:n.shardMode==="global"?n.globalBackend??"d1":void 0,indexes:n.indexes,isPublic:n.isPublic,memory:n.memory,name:t,rankIndexes:n.rankIndexes,relations:n.relations,searchIndexes:n.searchIndexes,shape:s,shardMode:n.shardMode,softDelete:n.softDelete,ttl:n.ttl,vectorIndexes:n.vectorIndexes}},j=(e,t=[],n=new Set,s=new Set)=>{s.add(e);for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){const a=B(r.getExpression());a!==void 0&&!s.has(a)&&j(a,t,n,s);continue}if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(o){const a=I(r);if(S(a,r.getNameNode()),n.has(a))throw d(r.getNameNode(),`defineSchema({...}): table "${a}" is declared more than once — the earlier declaration would be silently discarded. Remove the duplicate.`);n.add(a),t.push(P(o,a))}}return t},Le=e=>{const t=u(e,"source");if(t&&i.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&i.isObjectLiteralExpression(n))return f(n,"table")??"_unknown_"}return"_unknown_"},Oe=e=>{if(!i.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const n=t.getExpression();if(!i.isIdentifier(n)||n.getText()!=="defineVectorIndex")return;const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const r=e.getNameNode(),o=i.isStringLiteral(r)?r.getLiteralText():r.getText();return{dimensions:x(s,"dimensions"),metric:O(f(s,"metric")),name:o,table:Le(s)}},$=e=>{const t=[];for(const n of e.getProperties()){const s=Oe(n);s&&t.push(s)}return t},k=(e,t)=>`${e}_${t}`,Ae=(e,t)=>{if(!N.test(e))throw d(t,`defineSchemaExtension key ${JSON.stringify(e)} is not a valid JS identifier — it is prefixed onto every table the extension contributes (\`${e}_<table>\`), and table names are used in generated type names (Doc_<name>) and must match [A-Za-z_$][A-Za-z0-9_$]*. Rename the extension key.`)},E=(e,t,n)=>n.has(e)?k(t,e):e,Ne=(e,t,n,s)=>{const r=k(t,e.name);return{...e,extensionKey:t,...s?{extensionFromPackage:!0}:{},name:r,relations:e.relations.map(o=>({...o,table:E(o.table,t,n)})),vectorIndexes:e.vectorIndexes.map(o=>({...o,table:E(o.table,t,n)}))}},Pe=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},je=e=>{if(!i.isCallExpression(e))return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="defineSchemaExtension"},$e=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t:void 0}},De=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isCallExpression(e)){const t=e.getExpression();let n;if(i.isIdentifier(t)?n=t.getText():i.isPropertyAccessExpression(t)&&(n=t.getName()),n==="definePlugin"){const s=e.getArguments()[1];return s&&i.isObjectLiteralExpression(s)?s:void 0}}},ze=(e,t)=>{const n=Pe(e);if(n){if(i.isPropertyAccessExpression(t)){const s=De(n);return s?b(s,t.getName()):void 0}return n}},Me=e=>{let t=e,n=0;for(;t&&n<32;){if(n+=1,je(t))return t;const s=$e(t),r=s&&i.isIdentifier(s)?s.getSymbol():void 0,a=(r?.getAliasedSymbol()?.getDeclarations()??r?.getDeclarations()??[])[0];if(!a)return;const l=a.getSourceFile();if(l.isInNodeModules()||l.isDeclarationFile())return;t=ze(a,t)}},Re=e=>{const[t,n]=e.getArguments();if(!(!t||!i.isStringLiteral(t))&&!(!n||!i.isObjectLiteralExpression(n)))return{key:t.getLiteralText(),keyNode:t,options:n}},Fe=e=>{const t=u(e,"tables");if(!t||!i.isPropertyAssignment(t))return[];const n=t.getInitializer();if(!n||!i.isObjectLiteralExpression(n))return[];const s=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=I(r);S(a,r.getNameNode()),s.push(P(o,a))}return s},Ce=e=>{const t=u(e,"vectorIndexes");if(!t||!i.isPropertyAssignment(t))return[];const n=t.getInitializer();return!n||!i.isObjectLiteralExpression(n)?[]:$(n)},D=(e,t,n,s,r)=>{Ae(e,s);const o=new Set(t.map(c=>c.name)),a=t.map(c=>Ne(c,e,o,r)),l=n.map(c=>({...c,name:k(e,c.name),table:E(c.table,e,o)}));return{tables:a,vectorIndexes:l}},Be=(e,t,n)=>D(e,Fe(n),Ce(n),t,t.getSourceFile().getFilePath().includes("/node_modules/")),Ve=(e,t)=>{const n=e.getArguments()[0];if(!n)return;const s=Me(n);if(!s){if(t!==void 0){const o=ee(n,t);if(o){for(const a of o.bareTables)S(a.name,n);return D(o.key,o.bareTables,o.bareVectorIndexes,n,!0)}}console.warn(`@lunora/codegen: skipping \`.extend(${n.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${t===void 0?"no project root was available to resolve the package":"the package could not be imported/introspected"}. Extension tables will be absent from the generated types.`);return}const r=Re(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Be(r.key,r.keyNode,r.options)},qe=e=>{const t=[];let n=e;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;s.getName()==="extend"&&t.push(r),n=r}return t},Je=(e,t,n)=>{const s=new Set(t.map(o=>o.name)),r=[];for(const o of qe(e)){const a=Ve(o,n);if(a){for(const l of a.tables){if(s.has(l.name))throw d(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);s.add(l.name),t.push(l)}r.push(...a.vectorIndexes)}}return r},Ue=new Set(["eu","fedramp","us"]),Ke=e=>A(e,"jurisdiction","jurisdiction",Ue,'"eu", "us", or "fedramp"'),Ze=e=>{let t=e;for(;;){const n=t.getParent(),s=n?.getParent();if(!n||!i.isPropertyAccessExpression(n)||!s||!i.isCallExpression(s))return!1;if(n.getName()==="jurisdiction"){const r=s.getArguments()[1];return r!==void 0&&i.isObjectLiteralExpression(r)&&L(r,"pinAuth")===!0}t=s}},Ge=new Set(["required"]),We=e=>A(e,"rls","rls mode",Ge,'"required"'),st=(e,t,n)=>{const r=e.addSourceFileAtPath(t).getDescendantsOfKind(R.CallExpression).find(p=>{const T=p.getExpression();return i.isIdentifier(T)&&T.getText()==="defineSchema"});if(!r)throw new M("INTERNAL",`defineSchema() not found in ${t}`);const o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))throw d(r,"defineSchema() expects an object literal");const a=j(o),l=r.getArguments()[1],c=l&&i.isObjectLiteralExpression(l)?$(l):[],g=Je(r,a,n),w=[...a.flatMap(p=>p.vectorIndexes),...c,...g],z=new Set(a.filter(p=>p.shardMode==="global").map(p=>p.name)),v=w.find(p=>z.has(p.table));if(v)throw d(r,J(v.table,v.name));return{jurisdiction:Ke(r),...Ze(r)?{jurisdictionPinsAuth:!0}:{},rlsMode:We(r),tables:a,vectorIndexes:w}};export{st as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{w as d}from"./classify-procedure-call-OnJoKgqu.mjs";import{e as m}from"./exported-procedure-chains-58yS9zc8.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{o as i,j as r,s as o,h as n,t as g,k as F,d as u,v as p,m as f,g as l,f as d,i as k,u as w,l as Q}from"./shard-runtime-B1nU9CRa.mjs";import"./shared-BXUKWh7t.mjs";export{i as buildDoTypeImports,r as emitAgentFragments,o as emitAgents,n as emitContainerFragments,g as emitContainers,F as emitPaymentFragments,u as emitQueueFragments,p as emitQueues,f as emitQueuesMetadataFragments,l as emitServiceFragments,d as emitTopicFragments,k as emitWorkflowFragments,w as emitWorkflows,Q as emitWorkflowsMetadataFragments};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import{agentComponent as T}from"@lunora/agent/component";import{LunoraError as P}from"@lunora/errors";import{s as u}from"./paths-C-9fwEgQ.mjs";import{r as j,a as K,b as h,c as E}from"./qualifiers-Cw8dEDbh.mjs";import{G as w,a as B,r as g,p as $,b as x,c as y,d as v}from"./shared-BXUKWh7t.mjs";const A=t=>{const r=new Map;for(const o of t){const e=r.get(o.filePath)??[];e.push(o),r.set(o.filePath,e)}return[...r.entries()].toSorted(([o],[e])=>o.localeCompare(e))},C=t=>{const r=([o,e])=>{const c=e.toSorted((a,i)=>a.exportName.localeCompare(i.exportName)).map(a=>{const i=h(g(a.args),a.filePath),n=h(E(a),a.filePath);return` ${a.exportName}: FunctionReference<"${a.kind}", ${i}, ${n}>;`}).join(`
|
|
2
|
+
`);return` ${x(u(o))}: {
|
|
3
|
+
${c}
|
|
4
|
+
};`};return A(t).map(o=>r(o)).join(`
|
|
5
|
+
`)},W=(t,r)=>{if(t.length===0&&r.length===0)return{block:"",importLine:""};const o=[];let e="";if(t.length>0&&(e+="\n/** Params type carried by a `defineWorkflow` definition (its phantom `__params`). */\ntype WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params } ? (unknown extends Params ? Record<string, unknown> : Params) : Record<string, unknown>;\n"),e+=`
|
|
6
|
+
/** A typed reference to a durable workflow, addressable for \`cronJobs()\` targets. Mirrors \`@lunora/scheduler\`'s \`WorkflowReference\` structurally. */
|
|
7
|
+
export interface WorkflowReference<Params = Record<string, unknown>> {
|
|
8
|
+
readonly isLunoraWorkflow: true;
|
|
9
|
+
readonly __params?: Params;
|
|
10
|
+
readonly className: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}
|
|
13
|
+
`,t.length>0){const c=[...t].toSorted((n,s)=>n.exportName.localeCompare(s.exportName)),a=c.map(n=>` ${n.exportName}: WorkflowReference<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${n.exportName}>>;`).join(`
|
|
14
|
+
`),i=c.map(n=>` ${y(n.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(n.className)}, name: ${JSON.stringify(n.exportName)} },`).join(`
|
|
15
|
+
`);e+=`
|
|
16
|
+
/** This project's durable workflows, addressable as typed references (e.g. \`crons.daily("digest", …, workflows.digestPipeline, params)\`). */
|
|
17
|
+
export interface WorkflowsRef {
|
|
18
|
+
${a}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const workflows: WorkflowsRef = {
|
|
22
|
+
${i}
|
|
23
|
+
};
|
|
24
|
+
`,o.push(`import type * as lunoraWorkflowDefinitions from "../workflows.js";
|
|
25
|
+
`)}if(r.length>0){const c=[...r].toSorted((n,s)=>n.exportName.localeCompare(s.exportName)),a=c.map(n=>` ${n.exportName}: WorkflowReference<AgentRunInput>;`).join(`
|
|
26
|
+
`),i=c.map(n=>` ${y(n.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(n.className)}, name: ${JSON.stringify(n.name)} },`).join(`
|
|
27
|
+
`);e+=`
|
|
28
|
+
/** This project's durable agents, addressable as typed references for \`cronJobs()\` — each fire starts a fresh agent run (e.g. \`crons.daily("sweep", …, agents.support, { input, threadKey })\`). */
|
|
29
|
+
export interface AgentsRef {
|
|
30
|
+
${a}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const agents: AgentsRef = {
|
|
34
|
+
${i}
|
|
35
|
+
};
|
|
36
|
+
`,o.push(`import type { AgentRunInput } from "@lunora/agent";
|
|
37
|
+
`)}return{block:e,importLine:o.join("")}},D=()=>Object.keys(T().functions).toSorted((t,r)=>t.localeCompare(r)),O=t=>new Set(t.filter(r=>u(r.filePath)==="agents").map(r=>r.exportName)),J=()=>new Set(Object.entries(T().functions).filter(([,t])=>t.visibility==="internal").map(([t])=>t)),X=(t,r)=>{const o={importLine:"",lines:"",prelude:""};if(t.length===0)return o;const e=O(r),c=J(),a=r.find(n=>u(n.filePath)==="agents"&&c.has(n.exportName));if(a)throw new P("INTERNAL",`@lunora/codegen: "agents:${a.exportName}" is reserved for the durable agent loop's internal dispatch — rename the "${a.exportName}" export in ${a.filePath}`);const i=D().filter(n=>!e.has(n));return i.length===0?o:{importLine:`import { agentComponent } from "@lunora/agent/component";
|
|
38
|
+
`,lines:i.map(n=>` "agents:${n}": lunoraAgentRuntimeFunctions.${n} as unknown as RegisteredLunoraFunction,`).join(`
|
|
39
|
+
`),prelude:`
|
|
40
|
+
/**
|
|
41
|
+
* The \`@lunora/agent\` runtime component — auto-registered because \`lunora/agents.ts\`
|
|
42
|
+
* declares agents. The durable loop dispatches the internal mutations; clients
|
|
43
|
+
* subscribe to the public queries (\`agents:agentMessages\` is the live thread view).
|
|
44
|
+
*/
|
|
45
|
+
const lunoraAgentRuntimeFunctions = agentComponent().functions;
|
|
46
|
+
`}},Y=(t,r)=>{if(!t)return{importLine:"",lines:"",prelude:""};const o=r.find(e=>u(e.filePath)==="sandbox"&&e.exportName==="invoke");if(o)throw new P("INTERNAL",`@lunora/codegen: "sandbox:invoke" is reserved for the batteries-included sandbox tool dispatcher (browserTool/containerTool) — rename the "invoke" export in ${o.filePath}`);return{importLine:`import { sandboxComponent } from "@lunora/agent/component";
|
|
47
|
+
`,lines:' "sandbox:invoke": lunoraSandbox.invoke as unknown as RegisteredLunoraFunction,',prelude:"\n/**\n * The `@lunora/agent` sandbox dispatcher — auto-registered because `lunora/`\n * imports a sandbox tool (`browserTool`/`containerTool`). The batteries-included\n * tools dispatch to this internal action, which runs on an action ctx carrying\n * `ctx.browser` + `ctx.containers` (the durable tool step itself has neither).\n */\nconst lunoraSandbox = sandboxComponent();\n"}},H=(t,r)=>{if(t.length===0)return[];const o=O(r),e=[{args:{key:{kind:"string"},limit:{inner:{kind:"number"},kind:"optional"}},exportName:"agentMessages",filePath:"agents",kind:"query",returnType:"Record<string, unknown>[]"},{args:{decision:{kind:"union",members:[{kind:"literal",literalValue:'"approve"'},{kind:"literal",literalValue:'"reject"'}]},instanceId:{kind:"string"},note:{inner:{kind:"string"},kind:"optional"},threadKey:{kind:"string"},toolCallId:{kind:"string"}},exportName:"agentResolveApproval",filePath:"agents",kind:"mutation",returnType:"{ resolved: boolean }"},{args:{agent:{kind:"string"},input:{kind:"string"},threadKey:{kind:"string"},title:{inner:{kind:"string"},kind:"optional"}},exportName:"agentRun",filePath:"agents",kind:"mutation",returnType:"{ id: string; threadKey: string }"},{args:{key:{kind:"string"}},exportName:"agentState",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"},{args:{key:{kind:"string"}},exportName:"agentThread",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"}];for(const c of t)c.voice&&e.push({args:{threadKey:{kind:"string"}},exportName:`${c.exportName}Voice`,filePath:"agents",kind:"stream",returnType:"Record<string, unknown>"});return e.filter(c=>!o.has(c.exportName))},_=(t,r)=>{if(t.length===0)return[];const o=new Set(r.filter(e=>u(e.filePath)==="mutators").map(e=>e.exportName));return t.filter(e=>!o.has(e.exportName)).map(e=>({args:e.args,exportName:e.exportName,filePath:e.filePath,kind:"mutation",returnType:e.returnType}))},q=t=>{const r=t.filter(i=>i.stream);if(r.length===0)return{block:"",body:""};const o=A(r),e=o.map(([i,n])=>{const s=n.map(l=>{const p=h(l.chunkType??"unknown",l.filePath),d=h(g(l.searchParams),l.filePath),m=h(g(l.params),l.filePath);return` ${x(l.exportName)}: HttpStreamRef<${p}, ${d}, ${m}>;`}).join(`
|
|
48
|
+
`);return` ${x(u(i))}: {
|
|
49
|
+
${s}
|
|
50
|
+
};`}).join(`
|
|
51
|
+
`),c=o.map(([i,n])=>{const s=n.map(l=>` ${y(l.exportName)}: { method: ${JSON.stringify(l.method)}, path: ${JSON.stringify(l.path)} },`).join(`
|
|
52
|
+
`);return` ${y(u(i))}: {
|
|
53
|
+
${s}
|
|
54
|
+
},`}).join(`
|
|
55
|
+
`);return{block:`
|
|
56
|
+
/** This project's HTTP-SSE stream routes (\`httpRoute.<verb>(path).stream()\`), addressable as typed references for \`client.httpStream\` / \`useHttpStream\`. */
|
|
57
|
+
export interface HttpStreamsRef {
|
|
58
|
+
${e}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const httpStreams: HttpStreamsRef = {
|
|
62
|
+
${c}
|
|
63
|
+
};
|
|
64
|
+
`,body:e}},Z=t=>{const{agents:r=[],functions:o,httpRoutes:e=[],mutators:c=[],useUmbrella:a=!1,workflows:i=[]}=t,n=v(a),s=[...o.filter(k=>k.visibility!=="internal"),...H(r,o),..._(c,o)],l=o.filter(k=>k.visibility==="internal"),p=C(s),d=C(l),m=q(e),b=`${p}
|
|
65
|
+
${d}
|
|
66
|
+
${m.body}`,f=j(b),L=f.length>0?`
|
|
67
|
+
import type { ${f.join(", ")} } from "./dataModel.js";
|
|
68
|
+
`:"",I=p?`
|
|
69
|
+
${p}
|
|
70
|
+
`:"",M=d?`
|
|
71
|
+
${d}
|
|
72
|
+
`:"",N=W(i,r),R=`export interface ApiTypes {${I}}
|
|
73
|
+
|
|
74
|
+
export const api = anyApi as unknown as ApiTypes;
|
|
75
|
+
|
|
76
|
+
/** Internal functions — callable only server-side via \`ctx.run*\`, never from a client. */
|
|
77
|
+
export interface InternalApiTypes {${M}}
|
|
78
|
+
|
|
79
|
+
export const internal = anyApi as unknown as InternalApiTypes;
|
|
80
|
+
${N.block}${m.block}`,S=[...R.includes("FunctionReference<")?["FunctionReference"]:[],...m.block===""?[]:["HttpStreamRef"]],F=S.length>0?`import type { ${S.join(", ")} } from "${n.client}";
|
|
81
|
+
`:"";return K(`${w}import { anyApi } from "${n.client}";
|
|
82
|
+
${F}${N.importLine}${L}
|
|
83
|
+
${R}`,a)},ee=t=>t?`${w}import { createSeedClient as createSeedClientBase } from "@lunora/seed";
|
|
84
|
+
import type { SeedClient, SeedClientOptions } from "@lunora/seed";
|
|
85
|
+
|
|
86
|
+
import schema from "../schema.js";
|
|
87
|
+
import type { InsertModel } from "./dataModel.js";
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Schema-aware seed client with this project's \`InsertModel\` and runtime schema
|
|
91
|
+
* pre-bound. Each table is a method; call it with a count, a range, explicit
|
|
92
|
+
* partial rows, or per-field overrides. Foreign keys connect to rows seeded
|
|
93
|
+
* earlier in the run, and FK-parent tables are seeded automatically.
|
|
94
|
+
* @example
|
|
95
|
+
* const seed = createSeedClient({ seed: 1 });
|
|
96
|
+
* const { users } = await seed.users(5);
|
|
97
|
+
* const { posts } = await seed.posts((x) => x([10, 20]));
|
|
98
|
+
*/
|
|
99
|
+
export const createSeedClient = (options?: SeedClientOptions): SeedClient<InsertModel> => createSeedClientBase<InsertModel>(schema, options);
|
|
100
|
+
`:"",te=(t,r,o=!1)=>{if(t.length===0||!r)return"";const e=v(o),c=s=>s.table===void 0?"Row":`Doc<${JSON.stringify(s.table)}> & Row`,a=t.map(s=>{B(s.exportName,"shape export name");const l=c(s),p=h(g(s.args),s.filePath),d=Object.keys(s.args).length>0,m=d?` args: ${p};`:` args?: ${p};`,b=d?`(args: ${p}) => void`:`(args?: ${p}) => void`,f=`${s.exportName}CollectionOptions`;return`/** Options for the \`${s.exportName}\` shape binding. */
|
|
101
|
+
export interface ${$(f)} {
|
|
102
|
+
${m}
|
|
103
|
+
/**
|
|
104
|
+
* Share the optimistic-overlay gate with other collections + mutators on this
|
|
105
|
+
* shard. Defaults to the shared per-shard registry, which is almost always what
|
|
106
|
+
* you want — pass one only to isolate this collection's gate.
|
|
107
|
+
*/
|
|
108
|
+
checkpoints?: CheckpointRegistry;
|
|
109
|
+
/** The Lunora client to subscribe through. */
|
|
110
|
+
client: LunoraClient;
|
|
111
|
+
/** Row key extractor — defaults to \`row._id\`. Override when the app keys rows by a natural column. */
|
|
112
|
+
getKey?: (row: ${l}) => string;
|
|
113
|
+
/** \`"eager"\` starts syncing at creation; \`"lazy"\` (default) on the first subscriber. */
|
|
114
|
+
load?: "eager" | "lazy";
|
|
115
|
+
/** Notified when the underlying subscription errors; the collection always leaves \`loading\`. */
|
|
116
|
+
onError?: (error: SubscriptionError) => void;
|
|
117
|
+
/** Routes the subscription to a shard's DO. **Required for a \`.shardBy()\` table** — without it the watermark lands in the default bucket. */
|
|
118
|
+
shardKey?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Collection options for the \`${s.exportName}\` replication shape: \`config\` for
|
|
123
|
+
* \`createCollection\`, plus the \`checkpoints\` registry to hand \`bindMutators\` and
|
|
124
|
+
* \`scope\` to re-point the subscription.
|
|
125
|
+
*/
|
|
126
|
+
export const ${s.exportName}CollectionOptions = (options: ${$(f)}): LunoraCollectionOptions<${l}> =>
|
|
127
|
+
lunoraCollectionOptions<${l}>({
|
|
128
|
+
client: options.client,
|
|
129
|
+
...(options.checkpoints === undefined ? {} : { checkpoints: options.checkpoints }),
|
|
130
|
+
...(options.getKey === undefined ? {} : { getKey: options.getKey }),
|
|
131
|
+
...(options.load === undefined ? {} : { load: options.load }),
|
|
132
|
+
...(options.onError === undefined ? {} : { onError: options.onError }),
|
|
133
|
+
...(options.shardKey === undefined ? {} : { shardKey: options.shardKey }),
|
|
134
|
+
shape: { args: options.args, name: ${JSON.stringify(s.exportName)}, ...(options.shardKey === undefined ? {} : { shardKey: options.shardKey }) },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/** Live collection for the \`${s.exportName}\` shape, with its sync controls. */
|
|
138
|
+
export const ${s.exportName}Collection = (
|
|
139
|
+
options: ${$(f)},
|
|
140
|
+
): { checkpoints: CheckpointRegistry; collection: Collection<${l}, string>; scope: ${b} } => {
|
|
141
|
+
const { checkpoints, config, scope } = ${s.exportName}CollectionOptions(options);
|
|
142
|
+
|
|
143
|
+
return { checkpoints, collection: createCollection(config), scope };
|
|
144
|
+
};`}).join(`
|
|
145
|
+
|
|
146
|
+
`),i=j(a),n=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
|
|
147
|
+
`:"";return`${w}import type { LunoraClient, SubscriptionError } from "${e.client}";
|
|
148
|
+
import { lunoraCollectionOptions } from "@lunora/db/collections";
|
|
149
|
+
import type { CheckpointRegistry, LunoraCollectionOptions, Row } from "@lunora/db";
|
|
150
|
+
import type { Collection } from "@tanstack/db";
|
|
151
|
+
import { createCollection } from "@tanstack/db";
|
|
152
|
+
${n}
|
|
153
|
+
${a}
|
|
154
|
+
`};export{Z as emitApi,te as emitCollections,ee as emitSeed,A as groupByFileSorted,X as renderAgentFunctionRegistry,Y as renderSandboxFunctionRegistry};
|