@lunora/codegen 1.0.0-alpha.256 → 1.0.0-alpha.257

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/index.d.mts +118 -66
  2. package/dist/index.d.ts +118 -66
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-D8SgT3OR.mjs → AGENTS_FILENAME-D0fmyQlq.mjs} +1 -1
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-C13yKxas.mjs → CONTAINERS_FILENAME-C2wrJ9hF.mjs} +1 -1
  6. package/dist/packem_shared/{DEFAULT_TARGET-Co7ZXJ21.mjs → DEFAULT_TARGET-D5J5j3CW.mjs} +1 -1
  7. package/dist/packem_shared/{FLAGS_FILENAME-W5XQz_Po.mjs → FLAGS_FILENAME-C1tAv68t.mjs} +1 -1
  8. package/dist/packem_shared/{MUTATORS_FILENAME-DqWOgC5Z.mjs → MUTATORS_FILENAME-CDYDr1iG.mjs} +1 -1
  9. package/dist/packem_shared/{NOTIFY_FILENAME-C1J_47et.mjs → NOTIFY_FILENAME-Dmylk3YO.mjs} +1 -1
  10. package/dist/packem_shared/{OPENRPC_VERSION-Cr7Zzp6s.mjs → OPENRPC_VERSION-LZowDAOS.mjs} +1 -1
  11. package/dist/packem_shared/QUEUES_FILENAME-CQXsARur.mjs +1 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CYrLeST3.mjs +11 -0
  13. package/dist/packem_shared/{SHAPES_FILENAME-DRUFomCj.mjs → SHAPES_FILENAME-CNUAxXo3.mjs} +1 -1
  14. package/dist/packem_shared/WORKFLOWS_FILENAME-DrRu8060.mjs +1 -0
  15. package/dist/packem_shared/attribution-DpIyvmtn.mjs +1 -0
  16. package/dist/packem_shared/{buildOpenApiDocument-SxfElVzK.mjs → buildOpenApiDocument-DZMRzaEx.mjs} +1 -1
  17. package/dist/packem_shared/{capabilitiesUsedBy-DqrbgTKV.mjs → capabilitiesUsedBy-DLv5b8Ss.mjs} +1 -1
  18. package/dist/packem_shared/chain-Bah-gxpx.mjs +1 -0
  19. package/dist/packem_shared/{classify-procedure-call-CmcShAze.mjs → classify-procedure-call-DcsbRyEV.mjs} +1 -1
  20. package/dist/packem_shared/{context-property-calls-CWf9-6G5.mjs → context-property-calls-BClPebao.mjs} +1 -1
  21. package/dist/packem_shared/discoverAuthApiCalls-CEL1n0I0.mjs +1 -0
  22. package/dist/packem_shared/{discoverCrons-BEALHx1S.mjs → discoverCrons-BcrneOpi.mjs} +1 -1
  23. package/dist/packem_shared/{discoverFunctions-BcBzcG5x.mjs → discoverFunctions-TvTtRhvv.mjs} +1 -1
  24. package/dist/packem_shared/{discoverHttpRoutes-CJHS4llq.mjs → discoverHttpRoutes-BdaGy42T.mjs} +1 -1
  25. package/dist/packem_shared/discoverHyperdriveCalls-CDm53WpH.mjs +1 -0
  26. package/dist/packem_shared/discoverInserts-B2MLcH9M.mjs +1 -0
  27. package/dist/packem_shared/discoverMaskProcedures-Cj-dvv0H.mjs +1 -0
  28. package/dist/packem_shared/{discoverMigrations-Dt7ywfZv.mjs → discoverMigrations-jUmsOO70.mjs} +1 -1
  29. package/dist/packem_shared/{discoverNondeterministicCalls-CNJV2BiP.mjs → discoverNondeterministicCalls-BJzH9mEn.mjs} +1 -1
  30. package/dist/packem_shared/discoverQueries-B4enrT1h.mjs +1 -0
  31. package/dist/packem_shared/discoverR2sqlCalls-BgbXtbva.mjs +1 -0
  32. package/dist/packem_shared/{discoverRlsMetadata-mXBmPOGj.mjs → discoverRlsMetadata-DewerjgN.mjs} +1 -1
  33. package/dist/packem_shared/{discoverRlsProcedures-F4Cy-kSi.mjs → discoverRlsProcedures-DY5xYy7C.mjs} +1 -1
  34. package/dist/packem_shared/{discoverSandboxUsage-DC6q7rZy.mjs → discoverSandboxUsage-CJPFsjOS.mjs} +1 -1
  35. package/dist/packem_shared/{discoverSchema-D5R60b4F.mjs → discoverSchema-DPRQni-9.mjs} +1 -1
  36. package/dist/packem_shared/{discoverStorageRulesMetadata-D3Ot9g5f.mjs → discoverStorageRulesMetadata-DnVGPbZl.mjs} +1 -1
  37. package/dist/packem_shared/{exported-procedure-chains-D48EXUVQ.mjs → exported-procedure-chains-BVawk4h7.mjs} +1 -1
  38. package/dist/packem_shared/{fingerprintSchemaSources-Cl1CJFeh.mjs → fingerprintSchemaSources-D5z-pfpY.mjs} +1 -1
  39. package/dist/packem_shared/handler-reference-DLDPO906.mjs +1 -0
  40. package/dist/packem_shared/{index-D7dKfGPh.mjs → index-CpnWNNMK.mjs} +1 -1
  41. package/dist/packem_shared/listLunoraSourceFiles-jTik1QWu.mjs +1 -0
  42. package/dist/packem_shared/{loadProjectConfig-nNIDOrlR.mjs → loadProjectConfig-D_pUUrhQ.mjs} +1 -1
  43. package/dist/packem_shared/{modules-DyCocr1e.mjs → modules-B7lb5-dN.mjs} +1 -1
  44. package/dist/packem_shared/{parse-validator-C6fHL7OS.mjs → parse-validator-0q0Uz-Cx.mjs} +1 -1
  45. package/dist/packem_shared/{readServiceBindings-CeQvSswr.mjs → readServiceBindings-B_M_ZvhO.mjs} +1 -1
  46. package/dist/packem_shared/{unwrap-handler-return-DVY_kFF7.mjs → unwrap-handler-return-DFT18rnR.mjs} +1 -1
  47. package/package.json +3 -3
  48. package/dist/packem_shared/QUEUES_FILENAME-RGwht3Xu.mjs +0 -1
  49. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DsV2KbZm.mjs +0 -11
  50. package/dist/packem_shared/WORKFLOWS_FILENAME-4-ib4HH-.mjs +0 -1
  51. package/dist/packem_shared/chain-mte5djRJ.mjs +0 -1
  52. package/dist/packem_shared/discoverAuthApiCalls-DoSN_yc3.mjs +0 -1
  53. package/dist/packem_shared/discoverHyperdriveCalls-Bkbh4tG7.mjs +0 -1
  54. package/dist/packem_shared/discoverInserts-DpuLYPPd.mjs +0 -1
  55. package/dist/packem_shared/discoverMaskProcedures-B0w8gM0S.mjs +0 -1
  56. package/dist/packem_shared/discoverQueries-BcdqjYky.mjs +0 -1
  57. package/dist/packem_shared/discoverR2sqlCalls-30Wtbc0P.mjs +0 -1
  58. package/dist/packem_shared/listLunoraSourceFiles-CSlcBYlo.mjs +0 -1
@@ -1 +1 @@
1
- import{existsSync as L}from"node:fs";import{join as P}from"node:path";import{containerClassName as T,containerBindingName as A,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as j,isManagedImage as I,isCloudflareRegistryDigest as O,normalizeContainerImage as b}from"@lunora/container";import{SyntaxKind as d,Node as o}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as y,stringPropertyFor as k,findObjectProperty as p,symbolConstInitializer as C}from"./listLunoraSourceFiles-CSlcBYlo.mjs";const D="containers.ts",M=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const r of e.getDeclarations())if(o.isImportSpecifier(r))return r.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:r.getNameNode().getText()==="defineContainer";return!1},f=k("container"),h=(t,e,r)=>{if(o.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${r}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},E=(t,e)=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t))return b(t.getLiteralValue());if(o.isObjectLiteralExpression(t)){const r=p(t,"registry");if(r&&o.isPropertyAssignment(r)){const i=r.getInitializerOrThrow();return b({registry:f(i,e,"image.registry")})}const n=p(t,"build");if(n&&o.isPropertyAssignment(n)){const i=n.getInitializerOrThrow();return b({build:f(i,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},_=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),F=new Set(["gracePeriodSeconds","stepPercentage"]),v=t=>{let e=t;for(;o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isTypeAssertion(e)||o.isParenthesizedExpression(e);)e=e.getExpression();return e},B=(t,e)=>{const r=i=>{let s=i;for(;o.isPropertyAccessExpression(s)||o.isElementAccessExpression(s)||o.isParenthesizedExpression(s);)s=s.getExpression();return s===i?void 0:s},n=i=>i!==void 0&&o.isIdentifier(i)&&i.getSymbol()===t;return e.getDescendants().some(i=>{if(o.isBinaryExpression(i)){const s=i.getOperatorToken().getKind();return s>=d.FirstAssignment&&s<=d.LastAssignment&&n(r(i.getLeft()))}if(o.isPrefixUnaryExpression(i)||o.isPostfixUnaryExpression(i)){const s=i.getOperatorToken();return(s===d.PlusPlusToken||s===d.MinusMinusToken)&&n(r(i.getOperand()))}return o.isDeleteExpression(i)?n(r(i.getExpression())):o.isCallExpression(i)&&i.getExpression().getText()==="Object.assign"&&n(i.getArguments()[0])})},V=16,$=(t,e,r,n)=>{let i={name:r,symbol:t},s;for(let l=0;l<V;l+=1){const c=C(i.symbol);if(c===void 0||!o.isExpression(c))return s;if(s=v(c),o.isObjectLiteralExpression(s)&&i.symbol!==void 0&&B(i.symbol,e.getSourceFile()))throw a(e,`${n}: \`${i.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!o.isIdentifier(s))return s;i={name:s.getText(),symbol:s.getSymbol()}}return s},S=(t,e)=>{const r=v(t);return o.isIdentifier(r)?$(r.getSymbol(),r,r.getText(),e)??r:r},x=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(n=>n.getApparentType().getProperties().map(i=>i.getName()))},K=(t,e,r)=>{const n=t.getExpression().getType(),i=e==="every"||n.isAny()||n.isUnknown()?["its keys"]:[...new Set(x(n))].filter(s=>e.has(s)).map(s=>`\`${s}\``);if(i.length>0)throw a(t,`${r}: this spread can set ${i.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},R=(t,e,r)=>{const n=y(t),i=o.isShorthandPropertyAssignment(t)?$(t.getValueSymbol(),t,n,r):void 0;if(i!==void 0)return[n,i];if(e==="every"||e.has(n))throw a(t,`${r}: \`${n}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},m=(t,e,r,n=new Set)=>{const i=[],s=new Set(n).add(t);for(const l of t.getProperties())if(o.isPropertyAssignment(l))i.push([y(l),S(l.getInitializerOrThrow(),r)]);else if(o.isSpreadAssignment(l))i.push(...U(l,e,r,s));else{const c=R(l,e,r);c!==void 0&&i.push(c)}return i},U=(t,e,r,n)=>{const i=S(t.getExpression(),r);if(!o.isObjectLiteralExpression(i))return K(t,e,r),[];if(n.has(i))throw a(t,`${r}: this spread refers back to an object it is part of, so it has no static value.`);return m(i,e,r,n)},z=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" buildArgs`))r[n]=f(i,e,`buildArgs.${n}`);return Object.keys(r).length>0?r:void 0},Y=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,F,`container "${e}" rollout`))(n==="gracePeriodSeconds"||n==="stepPercentage")&&(r[n]=h(i,e,`rollout.${n}`));return r.gracePeriodSeconds===void 0&&r.stepPercentage===void 0?void 0:r},w=t=>{if(o.isTrueLiteral(t))return!0;if(o.isFalseLiteral(t))return!1},q=t=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)||o.isNumericLiteral(t))return t.getLiteralValue()},N=(t,e)=>{if(o.isStringLiteral(t))return t.getLiteralValue();if(o.isObjectLiteralExpression(t)){const r={};for(const n of t.getProperties()){if(!o.isPropertyAssignment(n))throw a(n,`container "${e}": \`instanceType\` must be an object of static number literals`);const i=y(n);if(i!=="diskMb"&&i!=="memoryMib"&&i!=="vcpu")throw a(n,`container "${e}": unknown \`instanceType\` field "${i}" — expected vcpu, memoryMib, or diskMb`);r[i]=h(n.getInitializerOrThrow(),e,`instanceType.${i}`)}return r}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},H=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" images`)){const s=E(i,e);if(s.kind==="build")throw a(i,`container "${e}": \`images["${n}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(s.kind==="registry"&&!O(s.reference))throw a(i,`container "${e}": \`images["${n}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);r[n]=s}return r},J=(t,e)=>{const r=t.findLast(([i])=>i==="schedulingPolicy");if(r===void 0)return;const n=f(r[1],e,"schedulingPolicy");if(n!=="default"&&n!=="durable_object")throw a(r[1],`container "${e}": unknown \`schedulingPolicy\` "${n}" — use "default" or "durable_object"`);return n==="durable_object"?n:void 0},W=(t,e,r,n)=>{if(r!==void 0&&j.includes(t))throw a(e,`container "${n}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(r===void 0&&t==="images")throw a(e,`container "${n}": \`images\` needs schedulingPolicy "durable_object"`)},X=(t,e,r,n)=>{const{base:i,policy:s}=r;switch(t){case"buildArgs":{i.buildArgs=z(e,n);break}case"enableInternet":{i.enableInternet=w(e);break}case"image":{r.scheduled||(s.image=E(e,n));break}case"images":{s.images=H(e,n);break}case"instanceType":{i.instanceType=N(e,n);break}case"maxInstances":{s.maxInstances=h(e,n,"maxInstances");break}case"name":{i.name=f(e,n,"name");break}case"rollout":{s.rollout=Y(e,n);break}case"sandbox":{const l=w(e);if(l===void 0)throw a(e,`container "${n}": \`sandbox\` must be a static true/false literal`);i.sandbox=l;break}case"sleepAfter":{i.sleepAfter=q(e);break}}},G=(t,e,r)=>{const n=t.findLast(([s])=>s==="image")?.[1];if(n===void 0||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();if(!Object.hasOwn(e??{},i)&&!I(i))throw a(n,`container "${r}": \`image\` "${i}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},Q=(t,e)=>{const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const n=m(r,_,`container "${e}"`),i=J(n,e),s={base:{bindingName:A(e),className:T(e),exportName:e},policy:{},scheduled:i!==void 0};for(const[u,g]of n)W(u,g,i,e),X(u,g,s,e);const{base:l,policy:c}=s;if(i==="durable_object")return G(n,c.images,e),{...l,...c.images===void 0?{}:{images:c.images},schedulingPolicy:i};if(c.image===void 0)throw a(r,`container "${e}": defineContainer requires a static \`image\` property`);return{...l,image:c.image,...c.maxInstances===void 0?{}:{maxInstances:c.maxInstances},...c.rollout===void 0?{}:{rollout:c.rollout}}},Z=t=>{const e=[],r=new Map;for(const n of t.getVariableDeclarations()){if(!n.isExported())continue;const i=n.getInitializer();if(i?.getKind()!==d.CallExpression)continue;const s=i,l=s.getExpression();if(!o.isIdentifier(l)||!M(l))continue;const c=n.getNameNode();if(!o.isIdentifier(c))throw a(c,"defineContainer exports must be plain named exports (no destructuring)");const u=Q(s,c.getText()),g=r.get(u.bindingName);if(g!==void 0)throw a(c,`containers "${g}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);r.set(u.bindingName,u.exportName),e.push(u)}return e},oe=(t,e)=>{const r=P(e,D);if(!L(r))return[];const n=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=Z(n);return i.sort((s,l)=>s.exportName.localeCompare(l.exportName)),i};export{D as CONTAINERS_FILENAME,oe as discoverContainers};
1
+ import{existsSync as L}from"node:fs";import{join as P}from"node:path";import{containerClassName as T,containerBindingName as A,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as j,isManagedImage as I,isCloudflareRegistryDigest as O,normalizeContainerImage as b}from"@lunora/container";import{SyntaxKind as d,Node as o}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as y,stringPropertyFor as k,findObjectProperty as p,symbolConstInitializer as C}from"./listLunoraSourceFiles-jTik1QWu.mjs";const D="containers.ts",M=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const r of e.getDeclarations())if(o.isImportSpecifier(r))return r.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:r.getNameNode().getText()==="defineContainer";return!1},f=k("container"),h=(t,e,r)=>{if(o.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${r}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},E=(t,e)=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t))return b(t.getLiteralValue());if(o.isObjectLiteralExpression(t)){const r=p(t,"registry");if(r&&o.isPropertyAssignment(r)){const i=r.getInitializerOrThrow();return b({registry:f(i,e,"image.registry")})}const n=p(t,"build");if(n&&o.isPropertyAssignment(n)){const i=n.getInitializerOrThrow();return b({build:f(i,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},_=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),F=new Set(["gracePeriodSeconds","stepPercentage"]),v=t=>{let e=t;for(;o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isTypeAssertion(e)||o.isParenthesizedExpression(e);)e=e.getExpression();return e},B=(t,e)=>{const r=i=>{let s=i;for(;o.isPropertyAccessExpression(s)||o.isElementAccessExpression(s)||o.isParenthesizedExpression(s);)s=s.getExpression();return s===i?void 0:s},n=i=>i!==void 0&&o.isIdentifier(i)&&i.getSymbol()===t;return e.getDescendants().some(i=>{if(o.isBinaryExpression(i)){const s=i.getOperatorToken().getKind();return s>=d.FirstAssignment&&s<=d.LastAssignment&&n(r(i.getLeft()))}if(o.isPrefixUnaryExpression(i)||o.isPostfixUnaryExpression(i)){const s=i.getOperatorToken();return(s===d.PlusPlusToken||s===d.MinusMinusToken)&&n(r(i.getOperand()))}return o.isDeleteExpression(i)?n(r(i.getExpression())):o.isCallExpression(i)&&i.getExpression().getText()==="Object.assign"&&n(i.getArguments()[0])})},V=16,$=(t,e,r,n)=>{let i={name:r,symbol:t},s;for(let l=0;l<V;l+=1){const c=C(i.symbol);if(c===void 0||!o.isExpression(c))return s;if(s=v(c),o.isObjectLiteralExpression(s)&&i.symbol!==void 0&&B(i.symbol,e.getSourceFile()))throw a(e,`${n}: \`${i.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!o.isIdentifier(s))return s;i={name:s.getText(),symbol:s.getSymbol()}}return s},S=(t,e)=>{const r=v(t);return o.isIdentifier(r)?$(r.getSymbol(),r,r.getText(),e)??r:r},x=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(n=>n.getApparentType().getProperties().map(i=>i.getName()))},K=(t,e,r)=>{const n=t.getExpression().getType(),i=e==="every"||n.isAny()||n.isUnknown()?["its keys"]:[...new Set(x(n))].filter(s=>e.has(s)).map(s=>`\`${s}\``);if(i.length>0)throw a(t,`${r}: this spread can set ${i.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},R=(t,e,r)=>{const n=y(t),i=o.isShorthandPropertyAssignment(t)?$(t.getValueSymbol(),t,n,r):void 0;if(i!==void 0)return[n,i];if(e==="every"||e.has(n))throw a(t,`${r}: \`${n}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},m=(t,e,r,n=new Set)=>{const i=[],s=new Set(n).add(t);for(const l of t.getProperties())if(o.isPropertyAssignment(l))i.push([y(l),S(l.getInitializerOrThrow(),r)]);else if(o.isSpreadAssignment(l))i.push(...U(l,e,r,s));else{const c=R(l,e,r);c!==void 0&&i.push(c)}return i},U=(t,e,r,n)=>{const i=S(t.getExpression(),r);if(!o.isObjectLiteralExpression(i))return K(t,e,r),[];if(n.has(i))throw a(t,`${r}: this spread refers back to an object it is part of, so it has no static value.`);return m(i,e,r,n)},z=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" buildArgs`))r[n]=f(i,e,`buildArgs.${n}`);return Object.keys(r).length>0?r:void 0},Y=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,F,`container "${e}" rollout`))(n==="gracePeriodSeconds"||n==="stepPercentage")&&(r[n]=h(i,e,`rollout.${n}`));return r.gracePeriodSeconds===void 0&&r.stepPercentage===void 0?void 0:r},w=t=>{if(o.isTrueLiteral(t))return!0;if(o.isFalseLiteral(t))return!1},q=t=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)||o.isNumericLiteral(t))return t.getLiteralValue()},N=(t,e)=>{if(o.isStringLiteral(t))return t.getLiteralValue();if(o.isObjectLiteralExpression(t)){const r={};for(const n of t.getProperties()){if(!o.isPropertyAssignment(n))throw a(n,`container "${e}": \`instanceType\` must be an object of static number literals`);const i=y(n);if(i!=="diskMb"&&i!=="memoryMib"&&i!=="vcpu")throw a(n,`container "${e}": unknown \`instanceType\` field "${i}" — expected vcpu, memoryMib, or diskMb`);r[i]=h(n.getInitializerOrThrow(),e,`instanceType.${i}`)}return r}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},H=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" images`)){const s=E(i,e);if(s.kind==="build")throw a(i,`container "${e}": \`images["${n}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(s.kind==="registry"&&!O(s.reference))throw a(i,`container "${e}": \`images["${n}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);r[n]=s}return r},J=(t,e)=>{const r=t.findLast(([i])=>i==="schedulingPolicy");if(r===void 0)return;const n=f(r[1],e,"schedulingPolicy");if(n!=="default"&&n!=="durable_object")throw a(r[1],`container "${e}": unknown \`schedulingPolicy\` "${n}" — use "default" or "durable_object"`);return n==="durable_object"?n:void 0},W=(t,e,r,n)=>{if(r!==void 0&&j.includes(t))throw a(e,`container "${n}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(r===void 0&&t==="images")throw a(e,`container "${n}": \`images\` needs schedulingPolicy "durable_object"`)},X=(t,e,r,n)=>{const{base:i,policy:s}=r;switch(t){case"buildArgs":{i.buildArgs=z(e,n);break}case"enableInternet":{i.enableInternet=w(e);break}case"image":{r.scheduled||(s.image=E(e,n));break}case"images":{s.images=H(e,n);break}case"instanceType":{i.instanceType=N(e,n);break}case"maxInstances":{s.maxInstances=h(e,n,"maxInstances");break}case"name":{i.name=f(e,n,"name");break}case"rollout":{s.rollout=Y(e,n);break}case"sandbox":{const l=w(e);if(l===void 0)throw a(e,`container "${n}": \`sandbox\` must be a static true/false literal`);i.sandbox=l;break}case"sleepAfter":{i.sleepAfter=q(e);break}}},G=(t,e,r)=>{const n=t.findLast(([s])=>s==="image")?.[1];if(n===void 0||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();if(!Object.hasOwn(e??{},i)&&!I(i))throw a(n,`container "${r}": \`image\` "${i}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},Q=(t,e)=>{const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const n=m(r,_,`container "${e}"`),i=J(n,e),s={base:{bindingName:A(e),className:T(e),exportName:e},policy:{},scheduled:i!==void 0};for(const[u,g]of n)W(u,g,i,e),X(u,g,s,e);const{base:l,policy:c}=s;if(i==="durable_object")return G(n,c.images,e),{...l,...c.images===void 0?{}:{images:c.images},schedulingPolicy:i};if(c.image===void 0)throw a(r,`container "${e}": defineContainer requires a static \`image\` property`);return{...l,image:c.image,...c.maxInstances===void 0?{}:{maxInstances:c.maxInstances},...c.rollout===void 0?{}:{rollout:c.rollout}}},Z=t=>{const e=[],r=new Map;for(const n of t.getVariableDeclarations()){if(!n.isExported())continue;const i=n.getInitializer();if(i?.getKind()!==d.CallExpression)continue;const s=i,l=s.getExpression();if(!o.isIdentifier(l)||!M(l))continue;const c=n.getNameNode();if(!o.isIdentifier(c))throw a(c,"defineContainer exports must be plain named exports (no destructuring)");const u=Q(s,c.getText()),g=r.get(u.bindingName);if(g!==void 0)throw a(c,`containers "${g}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);r.set(u.bindingName,u.exportName),e.push(u)}return e},oe=(t,e)=>{const r=P(e,D);if(!L(r))return[];const n=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=Z(n);return i.sort((s,l)=>s.exportName.localeCompare(l.exportName)),i};export{D as CONTAINERS_FILENAME,oe as discoverContainers};
@@ -1 +1 @@
1
- import{NODE_CAPABILITIES as f,CLOUDFLARE_CAPABILITIES as h,CELLD_CAPABILITIES as b}from"@lunora/platform";import{readProjectConfigLiterals as g}from"./loadProjectConfig-nNIDOrlR.mjs";const d="cloudflare",v=t=>{const{target:e}=g(t);return e!==void 0&&e.length>0?e:void 0},A=(t,e)=>e??v(t)??d,L=(t,e)=>{if(e!==void 0)return[];const{target:a,unreadable:r}=g(t);return r!==!0||a!==void 0?[]:[{level:"warn",message:`lunora.config declares a \`target\` that codegen cannot read without evaluating it, so the "${d}" surface was emitted. \`runCodegen\` resolves the target synchronously, which means it reads literals only.`,name:"platform_unreadable_target",remediation:`Write \`target\` as a string literal on the config's default export (\`export default { target: "${d}" }\`), or pass \`--target\`.`,target:d}]},u={celld:b,cloudflare:h,node:f},C=()=>Object.keys(u).toSorted((t,e)=>t.localeCompare(e)),S={access:null,ai:"ai",aiSearch:"aiSearch",analytics:"analytics",analyticsSql:"analyticsSql",artifacts:"artifacts",browser:"browser",container:"containers",flags:null,hyperdrive:"hyperdrive",images:"images",kv:"keyValueStore",mail:"mail",notify:null,payments:null,pipelines:"pipelines",r2sql:null,scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows",x402:null},w=["agents","commitOrderedTables","containerEgressPolicy","containerRuntimeScheduling","containerSandboxTools","cronTriggers","crossShardFanout","durableStreams","globalTables","queues","relationGraph","secrets","services","topics","vectorStore","workerLoaders","workflowRollback","workflowSchedules"],m={agents:"durable agents (`defineAgent`)",commitOrderedTables:"commit-ordered tables (`.commitOrdered()`)",containerEgressPolicy:"container egress policies (`defineContainer({ allowedHosts | deniedHosts | interceptHttps })`)",containerRuntimeScheduling:'per-instance container images and snapshots (`defineContainer({ schedulingPolicy: "durable_object" })`)',containerSandboxTools:"container sandbox helpers — files, directory backups, bucket mounts (`defineContainer({ sandbox: true })`)",cronTriggers:"declared cron triggers (`cronJobs()`)",crossShardFanout:"cross-shard fan-out queries (a `.shardBy(...)` schema)",durableStreams:"durable streams (`.stream(handler, { durable: true })`)",globalTables:"global tables (`.global()`)",queues:"queues (`defineQueue`)",relationGraph:"relation-graph traversal (`ctx.db.related`, derived from `v.id(...)` columns)",secrets:"the secrets store (`ctx.secrets`)",services:"service bindings to sibling Workers (`lunora.config` `services`)",topics:"pub/sub topics (`defineTopic` / `defineSubscription`)",vectorStore:"vector indexes (`.vectorize()`)",workerLoaders:"sandboxed agent scripts (`jsCodeTool`, on Worker Loaders)",workflowRollback:"workflow step rollback (`defineStep({ rollback })`)",workflowSchedules:"scheduled workflow instances (`defineWorkflow({ schedules })`)"},y=(t,e,a)=>({level:"error",message:`${e.name} does not support ${m[t]}, which this app declares.`,name:"platform_unsupported_feature",remediation:`Remove the declaration, or deploy to a target whose capability matrix marks "${t}" as native or emulated.`,target:a}),T=(t,e,a)=>({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${m[t]}, which this app declares. Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${t}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than letting the app deploy onto a primitive the host may not provide.`,target:a}),k=t=>{const{diagnostics:e,gatedSignals:a,matrix:r,reported:n,signals:c,target:i}=t;for(const s of w){if(c[s]!==!0)continue;const o=r.features[s]?.level;o!=="unsupported"&&o!==void 0||(a[s]=!1,!n.has(s)&&e.push(o==="unsupported"?y(s,r,i):T(s,r,i)))}},_=(t,e,a,r={})=>{const n={...t},c={...r},i=[],s=new Set;for(const[o,l]of Object.entries(S)){if(l===null||!t[o])continue;const p=e.features[l]?.level;p==="unsupported"?(n[o]=!1,s.add(l),i.push({feature:o,level:"error",message:`${e.name} does not support "${o}" (ctx.${o}).`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${o} usage, or deploy to a target whose capability matrix marks "${l}" as native or emulated.`,target:a})):p===void 0&&(n[o]=!1,s.add(l),i.push({feature:o,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${o}" (ctx.${o}). Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${l}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than shipping a surface the host may not provide.`,target:a}))}return k({diagnostics:i,gatedSignals:c,matrix:e,reported:s,signals:r,target:a}),{diagnostics:i,signals:c,usage:n}},E=(t,e,a={})=>{const r=u[e];return r===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(u).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],signals:{...a},usage:{...t}}:_(t,r,e,a)},I=t=>{const e=u[t];if(e===void 0)return;const a=Object.entries(e.features).filter(([,r])=>r.level==="unsupported").map(([r])=>r).toSorted((r,n)=>r.localeCompare(n));return{id:e.id,name:e.name,unsupported:a}};export{S as CAPABILITY_TO_FEATURE,d as DEFAULT_TARGET,_ as gateAgainstMatrix,E as gatePlatformFeatures,C as platformMatrixIds,v as readProjectTarget,L as readTargetDiagnostics,A as resolveCodegenTarget,I as studioPlatformFor};
1
+ import{NODE_CAPABILITIES as f,CLOUDFLARE_CAPABILITIES as h,CELLD_CAPABILITIES as b}from"@lunora/platform";import{readProjectConfigLiterals as g}from"./loadProjectConfig-D_pUUrhQ.mjs";const d="cloudflare",v=t=>{const{target:e}=g(t);return e!==void 0&&e.length>0?e:void 0},A=(t,e)=>e??v(t)??d,L=(t,e)=>{if(e!==void 0)return[];const{target:a,unreadable:r}=g(t);return r!==!0||a!==void 0?[]:[{level:"warn",message:`lunora.config declares a \`target\` that codegen cannot read without evaluating it, so the "${d}" surface was emitted. \`runCodegen\` resolves the target synchronously, which means it reads literals only.`,name:"platform_unreadable_target",remediation:`Write \`target\` as a string literal on the config's default export (\`export default { target: "${d}" }\`), or pass \`--target\`.`,target:d}]},u={celld:b,cloudflare:h,node:f},C=()=>Object.keys(u).toSorted((t,e)=>t.localeCompare(e)),S={access:null,ai:"ai",aiSearch:"aiSearch",analytics:"analytics",analyticsSql:"analyticsSql",artifacts:"artifacts",browser:"browser",container:"containers",flags:null,hyperdrive:"hyperdrive",images:"images",kv:"keyValueStore",mail:"mail",notify:null,payments:null,pipelines:"pipelines",r2sql:null,scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows",x402:null},w=["agents","commitOrderedTables","containerEgressPolicy","containerRuntimeScheduling","containerSandboxTools","cronTriggers","crossShardFanout","durableStreams","globalTables","queues","relationGraph","secrets","services","topics","vectorStore","workerLoaders","workflowRollback","workflowSchedules"],m={agents:"durable agents (`defineAgent`)",commitOrderedTables:"commit-ordered tables (`.commitOrdered()`)",containerEgressPolicy:"container egress policies (`defineContainer({ allowedHosts | deniedHosts | interceptHttps })`)",containerRuntimeScheduling:'per-instance container images and snapshots (`defineContainer({ schedulingPolicy: "durable_object" })`)',containerSandboxTools:"container sandbox helpers — files, directory backups, bucket mounts (`defineContainer({ sandbox: true })`)",cronTriggers:"declared cron triggers (`cronJobs()`)",crossShardFanout:"cross-shard fan-out queries (a `.shardBy(...)` schema)",durableStreams:"durable streams (`.stream(handler, { durable: true })`)",globalTables:"global tables (`.global()`)",queues:"queues (`defineQueue`)",relationGraph:"relation-graph traversal (`ctx.db.related`, derived from `v.id(...)` columns)",secrets:"the secrets store (`ctx.secrets`)",services:"service bindings to sibling Workers (`lunora.config` `services`)",topics:"pub/sub topics (`defineTopic` / `defineSubscription`)",vectorStore:"vector indexes (`.vectorize()`)",workerLoaders:"sandboxed agent scripts (`jsCodeTool`, on Worker Loaders)",workflowRollback:"workflow step rollback (`defineStep({ rollback })`)",workflowSchedules:"scheduled workflow instances (`defineWorkflow({ schedules })`)"},y=(t,e,a)=>({level:"error",message:`${e.name} does not support ${m[t]}, which this app declares.`,name:"platform_unsupported_feature",remediation:`Remove the declaration, or deploy to a target whose capability matrix marks "${t}" as native or emulated.`,target:a}),T=(t,e,a)=>({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${m[t]}, which this app declares. Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${t}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than letting the app deploy onto a primitive the host may not provide.`,target:a}),k=t=>{const{diagnostics:e,gatedSignals:a,matrix:r,reported:n,signals:c,target:i}=t;for(const s of w){if(c[s]!==!0)continue;const o=r.features[s]?.level;o!=="unsupported"&&o!==void 0||(a[s]=!1,!n.has(s)&&e.push(o==="unsupported"?y(s,r,i):T(s,r,i)))}},_=(t,e,a,r={})=>{const n={...t},c={...r},i=[],s=new Set;for(const[o,l]of Object.entries(S)){if(l===null||!t[o])continue;const p=e.features[l]?.level;p==="unsupported"?(n[o]=!1,s.add(l),i.push({feature:o,level:"error",message:`${e.name} does not support "${o}" (ctx.${o}).`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${o} usage, or deploy to a target whose capability matrix marks "${l}" as native or emulated.`,target:a})):p===void 0&&(n[o]=!1,s.add(l),i.push({feature:o,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${o}" (ctx.${o}). Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${l}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than shipping a surface the host may not provide.`,target:a}))}return k({diagnostics:i,gatedSignals:c,matrix:e,reported:s,signals:r,target:a}),{diagnostics:i,signals:c,usage:n}},E=(t,e,a={})=>{const r=u[e];return r===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(u).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],signals:{...a},usage:{...t}}:_(t,r,e,a)},I=t=>{const e=u[t];if(e===void 0)return;const a=Object.entries(e.features).filter(([,r])=>r.level==="unsupported").map(([r])=>r).toSorted((r,n)=>r.localeCompare(n));return{id:e.id,name:e.name,unsupported:a}};export{S as CAPABILITY_TO_FEATURE,d as DEFAULT_TARGET,_ as gateAgainstMatrix,E as gatePlatformFeatures,C as platformMatrixIds,v as readProjectTarget,L as readTargetDiagnostics,A as resolveCodegenTarget,I as studioPlatformFor};
@@ -1 +1 @@
1
- import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as t}from"ts-morph";import{defaultExportExpression as g,propertyInitializer as f,findObjectProperty as c}from"./listLunoraSourceFiles-CSlcBYlo.mjs";const d="flags.ts",u=new Set(["@lunora/flags/providers/flagship","lunorash/flags/flagship"]),m=e=>{const i=e.getSymbol();if(!i)return e.getText()==="flagshipProvider";for(const r of i.getDeclarations())if(t.isImportSpecifier(r))return u.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="flagshipProvider":!1;return!1},v=(e,i)=>{const r=c(e,i);if(!r||!t.isPropertyAssignment(r))return;const o=r.getInitializerOrThrow();if(t.isStringLiteral(o)||t.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue()},h=e=>{const i=e.getArguments()[0];if(i&&t.isObjectLiteralExpression(i)){const r=v(i,"binding");if(r!==void 0&&r.length>0)return{bindingName:r,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},S=e=>f(e.getArguments()[0],"provider"),b=(e,i)=>{const r=p(i,d);if(!l(r))return;const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=g(o);if(!n||!t.isCallExpression(n))return{provider:"custom"};const s=S(n);if(s&&t.isCallExpression(s)){const a=s.getExpression();if(t.isIdentifier(a)&&m(a))return h(s)}return{provider:"custom"}};export{d as FLAGS_FILENAME,b as discoverFlags};
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as t}from"ts-morph";import{defaultExportExpression as g,propertyInitializer as f,findObjectProperty as c}from"./listLunoraSourceFiles-jTik1QWu.mjs";const d="flags.ts",u=new Set(["@lunora/flags/providers/flagship","lunorash/flags/flagship"]),m=e=>{const i=e.getSymbol();if(!i)return e.getText()==="flagshipProvider";for(const r of i.getDeclarations())if(t.isImportSpecifier(r))return u.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="flagshipProvider":!1;return!1},v=(e,i)=>{const r=c(e,i);if(!r||!t.isPropertyAssignment(r))return;const o=r.getInitializerOrThrow();if(t.isStringLiteral(o)||t.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue()},h=e=>{const i=e.getArguments()[0];if(i&&t.isObjectLiteralExpression(i)){const r=v(i,"binding");if(r!==void 0&&r.length>0)return{bindingName:r,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},S=e=>f(e.getArguments()[0],"provider"),b=(e,i)=>{const r=p(i,d);if(!l(r))return;const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=g(o);if(!n||!t.isCallExpression(n))return{provider:"custom"};const s=S(n);if(s&&t.isCallExpression(s)){const a=s.getExpression();if(t.isIdentifier(a)&&m(a))return h(s)}return{provider:"custom"}};export{d as FLAGS_FILENAME,b as discoverFlags};
@@ -1 +1 @@
1
- import{existsSync as p}from"node:fs";import{join as l}from"node:path";import{Node as o,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{p as x}from"./parse-validator-C6fHL7OS.mjs";import{findObjectProperty as c}from"./listLunoraSourceFiles-CSlcBYlo.mjs";import{u as M}from"./unwrap-handler-return-DVY_kFF7.mjs";const y="mutators.ts",f=d,S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},N=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(m.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&N(t)}return!1},b=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},A=r=>{const t=c(r,"args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},E=r=>{const t=c(r,"server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":M(e)},F=r=>{const t=c(r,"owner");if(!t||!o.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&o.isStringLiteral(e)?e.getLiteralValue():void 0},P=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==m.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw g(s,"defineMutator exports must be plain named exports (no destructuring)");const u=b(n);t.push({args:A(u),exportName:s.getText(),filePath:"mutators",line:n.getStartLineNumber(),owner:F(u),returnType:E(u)})}return t},O=(r,t)=>{const e=l(t,y);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,O as discoverMutators,I as isDefineMutatorCallee};
1
+ import{existsSync as p}from"node:fs";import{join as l}from"node:path";import{Node as o,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{p as x}from"./parse-validator-0q0Uz-Cx.mjs";import{findObjectProperty as c}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{u as M}from"./unwrap-handler-return-DFT18rnR.mjs";const y="mutators.ts",f=d,S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},N=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(m.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&N(t)}return!1},b=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},A=r=>{const t=c(r,"args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},E=r=>{const t=c(r,"server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":M(e)},F=r=>{const t=c(r,"owner");if(!t||!o.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&o.isStringLiteral(e)?e.getLiteralValue():void 0},P=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==m.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw g(s,"defineMutator exports must be plain named exports (no destructuring)");const u=b(n);t.push({args:A(u),exportName:s.getText(),filePath:"mutators",line:n.getStartLineNumber(),owner:F(u),returnType:E(u)})}return t},O=(r,t)=>{const e=l(t,y);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,O as discoverMutators,I as isDefineMutatorCallee};
@@ -1 +1 @@
1
- import{existsSync as x}from"node:fs";import{join as P}from"node:path";import{SyntaxKind as l,Node as c}from"ts-morph";import{listLunoraSourceFiles as p,lunoraRelativePath as g,defaultExportExpression as E,findObjectProperty as d,handlerOf as S}from"./listLunoraSourceFiles-CSlcBYlo.mjs";import{c as v}from"./classify-procedure-call-CmcShAze.mjs";const y="notify.ts",N=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),F=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=v(t);if(!o)return;const s=S(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},m=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=F(s);r&&t.push(r)}return t},a=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&a(o)==="notify")return"push"},A=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=a(e.getExpression());if(o==="notify"&&N.has(t))return`ctx.notify.${t}`;if(o==="push"&&h.has(t))return`ctx.push.${t}`},O=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&h.has(e.getName()):!1,_=(e,t)=>{const o=[];for(const s of p(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),f=g(t,s);for(const n of m(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const u=A(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return o},b=(e,t)=>{for(const o of p(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of m(s))for(const f of r.handler.getDescendantsOfKind(l.PropertyAccessExpression))if(O(f))return!0}return!1},w=(e,t)=>{const o=P(t,y);if(!x(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=E(s);let f=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=d(i,"webPush")!==void 0,n=d(i,"fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:b(e,t)}};export{y as NOTIFY_FILENAME,_ as discoverNotifyCalls,w as discoverNotifyConfig};
1
+ import{existsSync as x}from"node:fs";import{join as P}from"node:path";import{SyntaxKind as l,Node as c}from"ts-morph";import{listLunoraSourceFiles as p,lunoraRelativePath as g,defaultExportExpression as E,findObjectProperty as d,handlerOf as S}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{c as v}from"./classify-procedure-call-DcsbRyEV.mjs";const y="notify.ts",N=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),F=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=v(t);if(!o)return;const s=S(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},m=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=F(s);r&&t.push(r)}return t},a=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&a(o)==="notify")return"push"},A=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=a(e.getExpression());if(o==="notify"&&N.has(t))return`ctx.notify.${t}`;if(o==="push"&&h.has(t))return`ctx.push.${t}`},O=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&h.has(e.getName()):!1,_=(e,t)=>{const o=[];for(const s of p(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),f=g(t,s);for(const n of m(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const u=A(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return o},b=(e,t)=>{for(const o of p(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of m(s))for(const f of r.handler.getDescendantsOfKind(l.PropertyAccessExpression))if(O(f))return!0}return!1},w=(e,t)=>{const o=P(t,y);if(!x(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=E(s);let f=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=d(i,"webPush")!==void 0,n=d(i,"fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:b(e,t)}};export{y as NOTIFY_FILENAME,_ as discoverNotifyCalls,w as discoverNotifyConfig};
@@ -1,3 +1,3 @@
1
- import{m}from"./modules-DyCocr1e.mjs";import{r as u}from"./json-data-Chfs2Cz5.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as l,objectSchema as d,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{G as R}from"./shared-DjUziztz.mjs";const h="1.3.2",g={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},f=(e,n)=>{const t=`${p(e.filePath)}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${t}", "args": { … } }\`).`,errors:i.map((r,a)=>({code:-32e3-a,data:{code:r},message:r})),name:t,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:d(e.args)}],result:{name:"result",schema:e.output?l(e.output):g},summary:`${e.kind}: ${t}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},O=e=>{const n=e.version??"0.0.0",s=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream"),t=e.modules??[],r=s.map(o=>f(o,m(t,o.filePath))).toSorted((o,c)=>o.name.localeCompare(c.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:h}},E=e=>`${JSON.stringify(O(e),void 0,2)}
1
+ import{m}from"./modules-B7lb5-dN.mjs";import{r as u}from"./json-data-Chfs2Cz5.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as l,objectSchema as d,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{G as R}from"./shared-DjUziztz.mjs";const h="1.3.2",g={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},f=(e,n)=>{const t=`${p(e.filePath)}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${t}", "args": { … } }\`).`,errors:i.map((r,a)=>({code:-32e3-a,data:{code:r},message:r})),name:t,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:d(e.args)}],result:{name:"result",schema:e.output?l(e.output):g},summary:`${e.kind}: ${t}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},O=e=>{const n=e.version??"0.0.0",s=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream"),t=e.modules??[],r=s.map(o=>f(o,m(t,o.filePath))).toSorted((o,c)=>o.name.localeCompare(c.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:h}},E=e=>`${JSON.stringify(O(e),void 0,2)}
2
2
  `,b=e=>`${R}export const openRpcSpec = ${u(e,"Record<string, unknown>")};
3
3
  `;export{h as OPENRPC_VERSION,O as buildOpenRpcDocument,E as emitOpenRpc,b as emitOpenRpcModule};
@@ -0,0 +1 @@
1
+ import{existsSync as b}from"node:fs";import{join as h}from"node:path";import{LunoraError as l}from"@lunora/errors";import{queueDefaultName as y,queueBindingName as q}from"@lunora/queue";import{SyntaxKind as w,Node as c}from"ts-morph";import{diagnosticAt as d}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findObjectProperty as m,stringPropertyFor as N}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{r as x}from"./handler-reference-DLDPO906.mjs";const v="queues.ts",E=o=>{const t=e=>e==="defineQueue"||e==="defineSubscription"||e==="defineTopic",i=o.getSymbol();if(!i){const e=o.getText();return t(e)?e:void 0}for(const e of i.getDeclarations()){if(!c.isImportSpecifier(e))continue;if(e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const r=e.getNameNode().getText();return t(r)?r:void 0}},f=N("queue"),S=(o,t,i)=>{if(c.isNumericLiteral(o))return o.getLiteralValue();throw d(o,`queue "${t}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},$=(o,t)=>{const i=m(o,"name");if(!i||!c.isPropertyAssignment(i))return;const e=f(i.getInitializerOrThrow(),t,"name");if(e.length===0)throw d(i,`queue "${t}": \`name\` must be a non-empty string when provided`);return e},g=(o,t,i,e)=>{const r=x(m(o,"handler"),e)?.site,s={bindingName:q(t),exportName:t,mode:"push",name:$(o,t)??y(t),...i===void 0?{}:{topic:i},...r===void 0?{}:{handlerSite:r},tuning:{}},n=m(o,"mode");if(n&&c.isPropertyAssignment(n)){if(i!==void 0)throw d(n,`subscription "${t}": \`mode\` is not allowed — a subscription is always a push consumer`);const u=f(n.getInitializerOrThrow(),t,"mode");if(u!=="push"&&u!=="pull")throw d(n,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(u)})`);s.mode=u}const a=m(o,"deadLetterQueue");a&&c.isPropertyAssignment(a)&&(s.tuning.deadLetterQueue=f(a.getInitializerOrThrow(),t,"deadLetterQueue"));for(const u of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const p=m(o,u);p&&c.isPropertyAssignment(p)&&(s.tuning[u]=S(p.getInitializerOrThrow(),t,u))}return s},I=(o,t,i)=>{const e=o.getArguments()[0];if(!e||!c.isObjectLiteralExpression(e))throw d(o,`queue "${t}": defineQueue must be passed an inline object literal`);return g(e,t,void 0,i)},P=(o,t,i,e)=>{const[r,s]=o.getArguments();if(!r||!c.isIdentifier(r)||!i.has(r.getText()))throw d(r??o,`subscription "${t}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts`);if(!s||!c.isObjectLiteralExpression(s))throw d(o,`subscription "${t}": defineSubscription must be passed an inline object literal`);return g(s,t,r.getText(),e)},T=o=>{const t=[];for(const i of o.getVariableDeclarations()){if(!i.isExported())continue;const e=i.getInitializer();if(e?.getKind()!==w.CallExpression)continue;const r=e,s=r.getExpression(),n=c.isIdentifier(s)?E(s):void 0;if(n===void 0)continue;const a=i.getNameNode();if(!c.isIdentifier(a))throw d(a,`${n} exports must be plain named exports (no destructuring)`);t.push({call:r,exportName:a.getText(),factory:n})}return t},A=(o,t)=>{const i=T(o),e=new Set(i.filter(n=>n.factory==="defineTopic").map(n=>n.exportName)),r=[];for(const n of i)n.factory==="defineQueue"?r.push(I(n.call,n.exportName,t)):n.factory==="defineSubscription"&&r.push(P(n.call,n.exportName,e,t));const s=[...e].map(n=>({exportName:n}));return{queues:r,topics:s}},Q=o=>{const t=new Map,i=new Map;for(const e of o){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=i.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(e.bindingName,e.exportName)}},L=(o,t)=>{const i=h(t,v);if(!b(i))return{queues:[],topics:[]};const e=o.getSourceFile(i)??o.addSourceFileAtPath(i),{queues:r,topics:s}=A(e,t),n=r.toSorted((a,u)=>a.exportName.localeCompare(u.exportName));return Q(n),{queues:n,topics:s.toSorted((a,u)=>a.exportName.localeCompare(u.exportName))}},M=(o,t)=>L(o,t).queues;export{v as QUEUES_FILENAME,L as discoverQueueDeclarations,M as discoverQueues};
@@ -0,0 +1,11 @@
1
+ import{existsSync as P,mkdirSync as ln,readFileSync as fs,writeFileSync as un,rmSync as dn}from"node:fs";import{join as h,dirname as me}from"node:path";import{performance as _e}from"node:perf_hooks";import{runAdvisor as fn}from"@lunora/advisor";import{LunoraError as U}from"@lunora/errors";import{SyntaxKind as u,Node as o,VariableDeclarationKind as pn,Project as Ft}from"ts-morph";import{serializeSchemaSnapshot as gn}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as mn}from"./formatAdvisories-DwmUKYuc.mjs";import{readProjectConfigLiterals as hn}from"./loadProjectConfig-D_pUUrhQ.mjs";import{a as kt,d as vn,r as En}from"./modules-B7lb5-dN.mjs";import{QUEUES_FILENAME as xn,discoverQueueDeclarations as Sn}from"./QUEUES_FILENAME-CQXsARur.mjs";import{WORKFLOWS_FILENAME as yn,discoverWorkflows as An}from"./WORKFLOWS_FILENAME-DrRu8060.mjs";import{r as bn}from"./json-data-Chfs2Cz5.mjs";import{s as Ae}from"./paths-C-9fwEgQ.mjs";import{G as Nn}from"./shared-DjUziztz.mjs";import{CAPABILITIES as wn,usedCapabilities as Pn}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{isD1GlobalTable as ps,isHyperdriveGlobalTable as gs}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as In}from"./AGENTS_FILENAME-D0fmyQlq.mjs";import{discoverContainers as Tn}from"./CONTAINERS_FILENAME-C2wrJ9hF.mjs";import Cn from"./discoverCrons-BcrneOpi.mjs";import{diagnosticAt as ie}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as be}from"./module-specifiers-WF8iAydP.mjs";import{contextPropertiesRead as On,discoverFeatureUsage as Rn}from"./capabilitiesUsedBy-DLv5b8Ss.mjs";import Fn from"./readPackageDependencies-C6h6FZuP.mjs";import{listLunoraSourceFiles as m,propertyKeyName as E,unwrapExpression as ne,listSecurityScanFiles as Ne,objectLiteralFromCallbackBody as ms,propertyInitializer as A,lunoraRelativePath as b,bindingKeyName as we,collectCallRows as N,findObjectProperty as O,collectSecurityCallRows as kn,collectNodeRows as We,RUN_METHODS as hs,functionReferenceSegments as vs,limitNameOf as Es,optionsObjectLiteral as xs,isContextIdentifier as Ve,handlerOf as Ln,isDatabaseAccessor as L,readTargetOf as Ss}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{discoverSandboxUsage as Dn}from"./discoverSandboxUsage-CJPFsjOS.mjs";import{resolveServiceBindings as Mn}from"./readServiceBindings-B_M_ZvhO.mjs";import _n from"./discoverStorageRulesMetadata-DnVGPbZl.mjs";import{a as x,c as j,d as ys,e as Kn}from"./classify-procedure-call-DcsbRyEV.mjs";import{i as $n}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as zn,resolveCodegenTarget as As,readTargetDiagnostics as Un,studioPlatformFor as jn}from"./DEFAULT_TARGET-D5J5j3CW.mjs";import{b as bs,e as Bn}from"./shard-B2AqdAuz.mjs";import qn from"./emitServer-mdlKhXYb.mjs";import{emitDataModel as Wn}from"./emitDataModel-D3WuEZ4b.mjs";import{c as g,w as Ze}from"./attribution-DpIyvmtn.mjs";import{r as Pe,s as Vn}from"./parse-validator-0q0Uz-Cx.mjs";import Hn from"./discoverAuthApiCalls-CEL1n0I0.mjs";import{i as Gn,a as Yn,e as Qn,b as Xn,d as Jn,c as Zn}from"./unwrap-handler-return-DFT18rnR.mjs";import er from"./discoverFunctions-TvTtRhvv.mjs";import tr from"./discoverHttpRoutes-BdaGy42T.mjs";import sr from"./discoverHyperdriveCalls-CDm53WpH.mjs";import nr from"./discoverInserts-B2MLcH9M.mjs";import{m as et,a as Ee,s as Ns,d as rr}from"./index-CpnWNNMK.mjs";import{e as ws}from"./exported-procedure-chains-BVawk4h7.mjs";import or from"./discoverMigrations-jUmsOO70.mjs";import{MUTATORS_FILENAME as ir,isDefineMutatorCallee as ar,discoverMutators as cr}from"./MUTATORS_FILENAME-CDYDr1iG.mjs";import lr from"./discoverNondeterministicCalls-BJzH9mEn.mjs";import{discoverNotifyConfig as ur,discoverNotifyCalls as dr}from"./NOTIFY_FILENAME-Dmylk3YO.mjs";import fr from"./discoverQueries-B4enrT1h.mjs";import pr from"./discoverR2sqlCalls-BgbXtbva.mjs";import gr from"./discoverRlsProcedures-DY5xYy7C.mjs";import mr from"./discoverRlsMetadata-DewerjgN.mjs";import hr from"./discoverSchema-DPRQni-9.mjs";import{secretKindOf as vr,redact as Er,isHeuristicSecretKind as xr,isSecretishName as Sr}from"./redact-Cy14LEnc.mjs";import{discoverShapes as yr}from"./SHAPES_FILENAME-CNUAxXo3.mjs";import{emitApp as Ar}from"./emitApp-0rC4g46B.mjs";import{buildOpenApiDocument as br,emitOpenApiModule as Nr}from"./buildOpenApiDocument-DZMRzaEx.mjs";import{buildOpenRpcDocument as wr,emitOpenRpcModule as Pr}from"./OPENRPC_VERSION-LZowDAOS.mjs";import{buildSchemaSnapshot as Ir}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{emitCollections as Tr,emitSeed as Cr,emitApi as Or}from"./emitApi-DdW9RyGG.mjs";import{t as Rr,u as Fr,s as kr,v as Lr}from"./shard-runtime-B8rucwkF.mjs";import{emitCrons as Dr,emitScheduler as Mr,emitShardRegistry as _r,emitVectors as Kr,emitWranglerCronTriggers as $r}from"./emitCrons-BRKXFGFu.mjs";import zr from"./emitDrizzleSchema-Cv0HtLR3.mjs";import Ur from"./emitFunctions-BgNeOZt_.mjs";const Lt={error:"ERROR",info:"INFO",warn:"WARN"},Dt={ERROR:2,INFO:0,WARN:1},jr=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),Br=(e,t)=>{const{advisor:s}=hn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn(Lt,n)?Lt[n]:void 0;return r===void 0?[...t,jr(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(i=>Dt[i.level]>=Dt[r])},qr={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},Ps=xn.replace(/\.ts$/u,""),Wr="crons",Vr=yn.replace(/\.ts$/u,""),J=(e,t)=>`${Ae(e)}:${t}`,Ke=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},Hr=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${qr[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...Ke("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...Ke("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...Ke("workflow",t.workflow,"workflow name")}))],Gr=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",Yr=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:Gr(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Qr=e=>Hr(e).flatMap(t=>Yr(t)),Xr=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:Ps,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,r=s??n;return{file:Wr,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],Jr=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),$e=(e,t)=>t===void 0?e:{...e,module:t},Zr=e=>{const t=new Map,s=new Map,n=Jr(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},i=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(J(c.file,c.exportName),l)};for(const c of e.functions){const l=J(c.filePath,c.exportName),d=`${Ae(c.filePath)}.${c.exportName}`;i($e({detail:c.kind,id:`function:${l}`,kind:"function",name:d},kt(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=J(c.filePath,c.exportName);i($e({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},kt(e.modules,c.filePath)),l)}for(const c of e.schema.tables)i($e({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};i({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},J(Ps,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)i({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName});for(const c of e.workflows)i({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},J(Vr,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)i({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";i({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},eo=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,to=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(J(e.file,e.exportName))??{reason:eo(e.exportName)},so=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=to(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(i=>({from:i,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},ze=e=>`${e.from}|${e.kind}|${e.to}`,no=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,ro=e=>{const{nodes:t,sites:s}=Zr(e),n=new Map,r=new Map;for(const i of[...Xr(e),...Qr(e)]){const a=so(i,s,t);if("drawn"in a)for(const c of a.drawn)n.set(ze(c),c);else{const c={file:i.file,kind:i.kind,line:i.line,reason:a.reason};r.set(no(c),c)}}return{edges:[...n.values()].toSorted((i,a)=>ze(i).localeCompare(ze(a))),nodes:[...t.values()].toSorted((i,a)=>i.id.localeCompare(a.id)),modules:e.modules.map(i=>({...i.description===void 0?{}:{description:i.description},...i.installed===!0?{installed:!0}:{},...i.ownsFolder===!1?{ownsFolder:!1}:{},name:i.name,tables:[...i.tables]})),unresolved:[...r.values()].toSorted((i,a)=>i.file.localeCompare(a.file)||i.line-a.line),version:1}},oo=e=>`${Nn}export const architecture = ${bn(e,"Record<string, unknown>")};
2
+ `,io=(e,t)=>{if(!(!t||e.jurisdiction!=="fedramp"))throw new U("CODEGEN_DIAGNOSTIC",'@lunora/codegen: the schema pins data to the "fedramp" jurisdiction, but this app uses Cloudflare Artifacts (`ctx.artifacts`), which supports only the "eu" and "us" jurisdictions. Repo data would be stored outside the declared residency. Remove the `ctx.artifacts` usage, or pin the schema to a jurisdiction Artifacts supports.')},Mt=(e,t="api")=>{const s=new Map;for(const n of e){const r=Ae(n),i=s.get(r);if(i===void 0){s.set(r,n);continue}if(i!==n){const a=t==="api"?`the generated api.ts would declare "${r}" twice and the dispatch key "${r}:<fn>" would be ambiguous`:`the generated api.ts would declare "${r}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new U("INTERNAL",`@lunora/codegen: "${i}" and "${n}" both map to the ${t} namespace "${r}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},ao=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:r=!1,usage:i}=t,a=[];e.tables.some(c=>ps(c))&&a.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),e.tables.some(c=>gs(c))&&a.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'},{name:"@lunora/sql-store",reason:'`.global({ backend: "hyperdrive" })` makes `_generated/app.ts` import the `SqlCtxDbOptions` / `SqlExec` types'}),n&&a.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),r&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of i===void 0?[]:wn)c.requiredPackage!==void 0&&i?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(d=>d.name===c.name)===l)},co=(e,t,s={})=>{if(t===void 0)return;const n=ao(e,s).filter(i=>!t.has(i.name));if(n.length===0)return;const r=n.map(i=>` - ${i.name} — ${i.reason}`).join(`
3
+ `);throw new U("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
4
+ ${r}
5
+
6
+ Install them with your package manager, then re-run codegen.`)},lo="env.ts",uo=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(u.ImportDeclaration);return n!==void 0&&be(n.getModuleSpecifierValue())}return!1},po=e=>{if(o.isIdentifier(e))return uo(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&fo(t)}return!1},go=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==u.CallExpression||!po(n.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw ie(i,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},mo=(e,t)=>{const s=h(t,lo);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=go(n);if(r.length!==0){if(r.length>1)throw ie(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(i=>i.exportName).join(", ")}); exactly one is allowed`);return r[0]}},Is="identity.ts",ho=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},vo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(u.ImportDeclaration);return n!==void 0&&be(n.getModuleSpecifierValue())}return!1},Eo=e=>{if(o.isIdentifier(e))return ho(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&vo(t)}return!1},xo=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==u.CallExpression||!Eo(n.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw ie(i,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},So=(e,t)=>{const s=h(t,Is);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=xo(n);if(r.length!==0){if(r.length>1)throw ie(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(i=>i.exportName).join(", ")}); exactly one is allowed`);return r[0]}},yo=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Ao=(e,t)=>{const s=ne(t);if(s===void 0||!o.isIdentifier(s))return s;const n=s.getText();return ne(e.getDescendantsOfKind(u.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},bo=(e,t)=>e!==void 0&&o.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(o.isShorthandPropertyAssignment(s))return t.has(E(s));if(!o.isPropertyAssignment(s)||!t.has(E(s)))return!1;const n=ne(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),No=new Set(["durable"]),wo=new Set(["rollback"]),Po=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)?t.getName():t.getText()},Io=new Map([["defineContainer",{keys:yo,signal:"containerEgressPolicy"}],["defineStep",{keys:wo,signal:"workflowRollback"}],["stream",{keys:No,signal:"durableStreams"}]]),To=(e,t)=>{const s=Io.get(Po(t));if(s!==void 0)return t.getArguments().some(n=>bo(Ao(e,n),s.keys))?s.signal:void 0},Co=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=On(r).has("secrets"));for(const i of r.getDescendantsOfKind(u.CallExpression)){const a=To(r,i);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Oo="createWorker",Ro="extend",_t=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,Kt=e=>{const t=[],s=_t(A(e,"backupCron"));s!==void 0&&t.push(s);const n=A(e,"crons");if(n===void 0||!o.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)&&!o.isMethodDeclaration(r))continue;const i=_t(r.getNameNode());i!==void 0&&t.push(i)}return t},Fo=e=>{const t=x(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Oo)return o.isObjectLiteralExpression(s)?Kt(s):[];if(t!==Ro||!(o.isArrowFunction(s)||o.isFunctionExpression(s)))return[];const n=ms(s.getBody());return n===void 0?[]:Kt(n)},ko=(e,t)=>{const s=[];for(const{filePath:n}of Ne(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getDescendantsOfKind(u.CallExpression))s.push(...Fo(i))}return[...new Set(s)]},Ts=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Ts(e.inner)},Lo=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=Ts(n);return r!==void 0&&t.has(r)}))},Do=(e,t)=>{const s=new Map,n=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const i=s.get(r.name);if(i!==void 0)throw new U("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${i} and agent "${r.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(r.className);if(a!==void 0)throw new U("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${a} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Mo=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,i=So(s,t),a=mo(s,t),c=An(s,t),{queues:l,topics:d}=Sn(s,t),p=Mn(n),v=In(s,t);Do(c,v);const S=Tn(s,t),k=_n(s,t),D=Cn(s,t,c,v),M=ko(s,t),y=Co(s,t),T=Dn(s,t),$=Rn(s,t);$.browser=$.browser||T.usesSandboxBrowser;const B=zn($,As(n,e.target),{agents:v.length>0,commitOrderedTables:r.tables.some(I=>I.commitOrdered===!0),cronTriggers:D.length>0,crossShardFanout:r.tables.some(I=>$n(I)),containerEgressPolicy:y.containerEgressPolicy,containerRuntimeScheduling:S.some(I=>I.schedulingPolicy==="durable_object"),containerSandboxTools:S.some(I=>I.sandbox===!0),durableStreams:y.durableStreams,globalTables:r.tables.some(I=>I.shardMode==="global"),queues:l.length>0,relationGraph:Lo(r),secrets:y.secrets,services:p.length>0,topics:d.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:T.usesSandboxLoader,workflowRollback:y.workflowRollback,workflowSchedules:c.some(I=>I.schedules!==void 0)}),C=B.usage,G=Pn(C),Z=B.signals.vectorStore!==!1,ee=B.signals.services===!1?[]:p,Y=Fn(n),ae=Y??new Set,z=ae.has("lunorash");co(r,Y,{hasVectors:Z,scheduler:C.scheduler||D.length>0,storage:C.storage||k.rules.length>0||Object.keys(bs(r)).length>0,usage:C});const R=P(h(t,"flags.ts")),F=P(h(t,"notify.ts"));return{agents:v,capabilities:G,containers:S,crons:D,dataModelContent:Wn(r),declaredDependencies:Y,dependencies:ae,entryCronTriggers:M,env:a,featureUsage:C,hasFlags:R,hasNotify:F,identity:i,platformGate:{...B,diagnostics:[...Un(n,e.target),...B.diagnostics]},queues:l,serverContent:qn({agents:v,capabilities:G,containers:S,env:a,hasVectors:Z,hasFlags:R,hasNotify:F,identity:i,queues:l,schema:r,generatedDirectory:h(t,"_generated"),services:ee,storageRuleBuckets:k.rules.map(I=>I.bucket),topics:d,useUmbrella:z,workflows:c}),services:ee,storageRulesMetadata:k,topics:d,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:z,workflows:c}},Cs=new Set(["delete","get","head","options","patch","post","put"]),_o=new Set(["handler","stream"]),Ko=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,$t=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),$o=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Cs.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},zo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Cs.has(n.getName()))break;s=n.getExpression()}return $o(s)},Uo=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if($t.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&$t.has(s.getText()))return!0}return!1},jo=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!_o.has(n.getName()))return;const r=zo(s);if(!r||!Ko.test(r.path))return;const i=s.getArguments()[0],a=i!==void 0&&(o.isArrowFunction(i)||o.isFunctionExpression(i))&&Uo(i);return{exportName:e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},Bo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=jo(r,t);i&&s.push(i)}return s},qo=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bo(r,b(t,n)))}return s},Wo=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return o.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!o.isArrowFunction(n)&&!o.isFunctionExpression(n)&&!o.isFunctionDeclaration(n)))for(const r of n.getParameters()){const i=r.getDescendantsOfKind(u.BindingElement).find(a=>s(a));if(i!==void 0)return i}},Vo=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isObjectBindingPattern(s))return;const n=s.getParent();if(o.isBindingElement(n)){t=n;continue}return o.isParameterDeclaration(n)?we(t):void 0}},zt=(e,t)=>{const s=e.getParent();if(o.isPropertyAccessExpression(s)&&s.getNameNode()===e||o.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=Wo(e);return n!==void 0&&Vo(n)===t},tt=(e,t)=>o.isIdentifier(e)?zt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>zt(s,t)),Ue=e=>tt(e,"ctx"),Ho=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t:void 0},He=e=>tt(e,"args"),_=e=>{if(!o.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let r,i=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>i&&(r=c,i=l)}return r},K=e=>{if(He(e))return!0;const t=_(e);return t!==void 0&&He(t)},Go=e=>{if(o.isCallExpression(e)||o.isNewExpression(e))return!1;const t=_(e);return t===void 0||!(o.isCallExpression(t)||o.isNewExpression(t))},W=e=>{if(Ue(e))return!0;const t=_(e);if(t!==void 0&&Ue(t))return!0;const s=t??e;return(o.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const i=_(r);return i!==void 0&&Ue(i)})},he=(e,t)=>tt(e,t),Yo=(e,t)=>{if(he(e,t))return!0;const s=_(e);if(s!==void 0&&he(s,t))return!0;const n=Ho(e);if(n!==void 0){const r=_(n);return r!==void 0&&he(r,t)}return!1},Qo=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Xo=(e,t)=>{if(!Qo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!K(s)||W(s)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},Jo=(e,t)=>N(e,t,Xo),Zo=new Set(["generateText","streamText"]),ei=new Set(["messages","prompt","system"]),ti=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],si=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const r of ti)if(r.methods.has(s)&&r.prefixes.some(i=>n===i||n.startsWith(`${i}.`)))return`${n}.${s}`},ni=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=si(t);if(s!==void 0)return s}},ri=e=>{const t=new Set,s=e.getFirstAncestor(i=>o.isArrowFunction(i)||o.isFunctionExpression(i)||o.isFunctionDeclaration(i)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!o.isObjectBindingPattern(r))return t;for(const i of r.getElements()){const a=we(i),c=i.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},oi=e=>{if(He(e))return!0;const t=ri(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},ii=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!ei.has(E(t)))continue;const s=t.getInitializer();if(s!==void 0&&oi(s))return!0}return!1},ai=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=x(n.getExpression());if(r===void 0||!Zo.has(r))continue;const[i]=n.getArguments();if(i===void 0||!o.isObjectLiteralExpression(i))continue;let a;for(const c of i.getDescendantsOfKind(u.CallExpression))if(x(c.getExpression())==="tool"&&(a=ni(c),a!==void 0))break;a!==void 0&&s.push({scope:g(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:ii(i)})}return s},ci=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ai(r,b(t,n)))}return s},li=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},ui=(e,t)=>{if(!li(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!K(s)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},di=(e,t)=>N(e,t,ui),st=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!o.isSpreadAssignment(s))return!1;const n=Pe(s.getExpression());return n===void 0||st(n,t)})}finally{t.delete(e)}},fi=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=O(t,"args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Pe(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:st(r)}},pi=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const r=n.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const i=n.getArguments()[0],a=i!==void 0&&o.isExpression(i)?Pe(i):void 0;a===void 0?s=!0:(t.push(a),s||=st(a))}n=r.getExpression()}return{objects:t,opaque:s}},nt=(e,t)=>t?pi(t):fi(e),Os=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(o.isSpreadAssignment(s)){const n=Pe(s.getExpression());return n===void 0?[]:Os(n,t)}return o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)?[E(s)]:[]})}finally{t.delete(e)}},gi=e=>e.flatMap(t=>Os(t,new Set)),mi=new Set(["check","length","max"]),Ge=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!(!o.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},hi=e=>[e,...e.getDescendants()].filter(t=>Ge(t)!==void 0),vi=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!o.isCallExpression(n)||n.getExpression()!==s)return!1;if(mi.has(s.getName()))return!0;t=n}},Ei=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!o.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!i)continue;const a=hi(i),c=E(r);a.some(l=>Ge(l)==="any")?t.push(c):a.some(l=>Ge(l)==="string"&&!vi(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},xi=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=j(s);if(n?.visibility!=="public")return;const{objects:r}=nt(s,n.receiver),{anyArgs:i,unboundedStringArgs:a}=Ei(r);if(!(i.length===0&&a.length===0))return{anyArgs:i,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Si=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=xi(r,t);i&&s.push(i)}return s},yi=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Si(r,b(t,n)))}return s},je=e=>e?.getKind()===u.TrueKeyword,Ai=e=>e?.getKind()===u.FalseKeyword,bi=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Ni=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),wi=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&x(t.getExpression())==="scim"),Pi=e=>e!==void 0&&o.isCallExpression(e)&&Ni.has(x(e.getExpression())??""),Ii=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),Ti=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:je(A(t,"disableCSRFCheck")),emailPasswordEnabled:je(A(s,"enabled")),requireEmailVerification:je(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:wi(A(e,"plugins"))&&Pi(A(e,"database")),secureCookiesDisabled:Ai(A(t,"useSecureCookies")),sessionFreshAgeZero:bi(A(n,"freshAge")),trustedOriginsWildcard:Ii(A(e,"trustedOrigins"))}},Ci=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Oi=(e,t)=>{if(x(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(i=>o.isSpreadAssignment(i)),r=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?Ti(s):Ci();return{scope:g(e),file:t,line:e.getStartLineNumber(),...r}},Ri=(e,t)=>kn(e,t,Oi),Fi=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},ki=(e,t,s)=>{const n=Fi(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!K(r)||W(r))&&!(s.requireUnmodifiedReach===!0&&!Go(r)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:n}},Ie=(e,t,s)=>N(e,t,(n,r)=>ki(n,r,s)),Li=new Set(["content","pdf","scrape","screenshot"]),Di=(e,t)=>Ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Li}),Rs=e=>{const t=vs(e);return t===void 0?void 0:`${Ae(t.slice(0,-1).join("/"))}:${String(t.at(-1))}`},Fs=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getExpression();return o.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},Mi=e=>{if(!o.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||o.isIdentifier(t)&&t.getText()==="scheduler"},_i=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),Ki=(e,t)=>{const s=Rs(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:"the function reference is not a static api.* / internal.* chain"}:void 0},$i=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(hs.has(s))return Ki(s,n);if((s==="runAfter"||s==="runAt")&&Mi(t)){const c=Rs(r);return c===void 0?{kind:"schedule",reason:"the scheduled function is not a static api.* / internal.* chain"}:{kind:"schedule",target:c}}const i=_i.get(s),a=i===void 0?void 0:Fs(t,i.surface);return i===void 0||a===void 0?void 0:{kind:i.kind,target:a}},Ut=(e,t,s)=>s===void 0?void 0:{...s,file:t,line:e.getStartLineNumber(),scope:g(e)},zi=(e,t)=>[...N(e,t,(s,n)=>Ut(s,n,$i(s))),...We(e,t,u.PropertyAccessExpression,(s,n)=>{const r=Fs(s,"services");return Ut(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],Ui=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ji=new Set(["RateLimiter"]),Bi=new Set(["extend"]),jt="lunora",qi=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ks=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(o.isSpreadAssignment(r)){n=!0;continue}if(o.isPropertyAssignment(r)){const i=E(r);t.push(i),r.getInitializer()?.getKind()===u.TrueKeyword&&s.push(i);continue}(o.isShorthandPropertyAssignment(r)||o.isMethodDeclaration(r))&&t.push(E(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Ye=e=>e&&o.isObjectLiteralExpression(e)?ks(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Wi=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&ms(t.getBody());return s?ks(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Vi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=x(n.getExpression());r!==void 0&&(Ui.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...Ye(n.getArguments()[0])}):Bi.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...Wi(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(u.NewExpression)){const r=x(n.getExpression());r===void 0||!ji.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...Ye(n.getArguments()[0])})}return s},Hi=(e,t)=>{for(const s of qi){const n=h(t,s);if(!P(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=[];for(const a of r.getDescendantsOfKind(u.CallExpression))x(a.getExpression())===jt&&i.push({callee:jt,file:s,line:a.getStartLineNumber(),...Ye(a.getArguments()[0])});return i}return[]},Gi=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ne(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vi(i,n))}return s.push(...Hi(e,me(t))),s},Bt="ctx.containers.",Yi=e=>{if(!e.startsWith(Bt))return!1;const t=e.slice(Bt.length);return t.length>0&&!t.includes(".")},Qi=(e,t)=>Ie(e,t,{argIndex:0,matchReceiver:Yi,methods:new Set(["get"])}),Xi=new Set(["allow","deny","setAllowed"]),Ji=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=O(t,"enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},Zi=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Ji(e)))return{detail:"enableInternet: true",scope:g(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ea=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Xi.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:g(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},ta=(e,t)=>Zi(e,t)??ea(e,t),sa=(e,t)=>N(e,t,ta),na=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ra=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return na.has(s)?s:void 0},oa=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const r=E(n);t.push(r);const i=n.getInitializer();i&&o.isStringLiteral(i)&&i.getLiteralText()===""&&s.push(r);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(E(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},ia=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ne(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of i.getDescendantsOfKind(u.CallExpression)){const c=ra(a);if(c===void 0)continue;const l=a.getArguments()[0],d=l&&o.isObjectLiteralExpression(l)?oa(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},aa=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ca=new Set(["dbRateLimit","rateLimit"]),la=e=>{const t=xs(e);if(!t)return!1;const s=O(t,"failOpen");return s!==void 0&&o.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===u.TrueKeyword},ua=(e,t)=>{const s=x(e.getExpression());if(s===void 0)return;const n=aa.get(s);if(n!==void 0)return{callee:s,scope:g(e),failOpen:la(e.getArguments()[n]),file:t,limitName:ca.has(s)?Es(e):"",line:e.getStartLineNumber()}},da=(e,t)=>N(e,t,ua),fa=new Set(["boolean","number","object","string"]),pa=e=>{const t=e.getName();if(!fa.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ve(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ve(n.getExpression()))return t},ga=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=pa(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},ma=(e,t)=>{const s=new Map;for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getDescendantsOfKind(u.CallExpression)){const a=ga(i);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,r])=>({key:n,type:r})).toSorted((n,r)=>n.key.localeCompare(r.key))},ha=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=j(t);if(s?.kind!=="query")return;const n=Ln(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},qt=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},va=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=qt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=qt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},Ea=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const r=va(n);r!==void 0&&s.push({callee:r,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},xa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=ha(r);i&&s.push(...Ea(i,t))}return s},Sa=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xa(r,b(t,n)))}return s},ya=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ve(t.getExpression())},Aa=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},ba=(e,t)=>{if(!ya(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),i=Aa(n);if(!(r.length===0||i===void 0))return{defaultValue:i,scope:g(e),file:t,key:r,line:e.getStartLineNumber()}},Na=(e,t)=>N(e,t,ba),wa=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const r=n.getTypeAtLocation(e),i=r.getText(e);if(!i||i==="any"||i==="never"||Gn(i))return;const a=e.getSourceFile().getFilePath();if(Yn(r,e,a)){const c=Qn(r,e,a,0,new Set);return c===void 0&&Xn(i),c}return i},Pa=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Ia=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ta=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getDescendantsOfKind(u.CallExpression))Pa(a)&&s.push({file:i,indexName:Ia(a),line:a.getStartLineNumber()})}return s},re=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Ls=e=>{const t=e.getArguments()[0],s=re(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=O(t,"handler");return n!==void 0&&o.isPropertyAssignment(n)?re(n.getInitializer()):void 0},Ca=new Set(["delete","get","head","options","patch","post","put"]),Oa=new Set(["handler","stream"]),Ra=new Set(["runAction","runMutation"]),Fa=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),oe=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,Ds=(e,t)=>{if(!(e===void 0||!o.isObjectBindingPattern(e))){for(const s of e.getElements())if(we(s)===t){const r=s.getNameNode();return o.isIdentifier(r)?r.getText():void 0}}},Wt=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?o.isIdentifier(s)?s.getText():void 0:Ds(s,"ctx")},Vt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&o.isIdentifier(s)?s.getText():void 0:Ds(s,"request")},Ht=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(u.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const r of n){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))continue;const a=i.getName(),c=i.getExpression();if(Ra.has(a)&&oe(c,t))return a;if(Fa.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&oe(c.getExpression(),t))return`db.${a}`}},Gt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(u.PropertyAccessExpression))if(n.getName()==="auth"&&oe(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(u.VariableDeclaration)){const r=n.getNameNode();if(!(!o.isObjectBindingPattern(r)||!oe(n.getInitializer(),t))){for(const i of r.getElements())if(we(i)==="auth")return!0}}return!1},ka=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,La=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return o.isPropertyAccessExpression(n)&&n.getName()==="headers"&&oe(n.getExpression(),t)},Da=e=>[...o.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(u.StringLiteral).map(t=>t.getLiteralText())],Ms=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Da(s)},Ma=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!o.isArrowFunction(n)&&!o.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!o.isCallExpression(r))return[];const i=r.getExpression();if(!o.isPropertyAccessExpression(i))return[];const a=i.getExpression();return o.isIdentifier(a)?Ms(t,a.getText()):[]}return[]},_a=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(o.isStringLiteral(t))return[t.getLiteralText()];if(!o.isIdentifier(t))return[];const s=e.getSourceFile(),n=Ms(s,t.getText());return n.length>0?n:Ma(t,s)},Yt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(u.CallExpression);return o.isCallExpression(s)&&n.unshift(s),n.some(r=>La(r,t)&&_a(r).some(i=>ka.test(i)))},Ka=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Oa.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const r=n.getName();if(Ca.has(r)){const i=n.getExpression();return o.isIdentifier(i)&&i.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},$a=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=re(e.getArguments()[0]),l=c&&Wt(c,!0);if(!c||l===void 0||Yt(c,Vt(c,!0)))return;const d=Ht(c,l);return d===void 0?void 0:{scope:g(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Gt(c,l),sideEffect:d}}const n=Ka(e);if(n===void 0)return;const r=re(e.getArguments()[0]),i=r&&Wt(r,!1);if(!r||i===void 0||Yt(r,Vt(r,!1)))return;const a=Ht(r,i);return a===void 0?void 0:{scope:g(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Gt(r,i),sideEffect:a}},za=(e,t)=>N(e,t,$a),Ua=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ja=new Set(["append","set"]),_s=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Qt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(n=>Ua.has(x(n.getExpression())??"")&&he(n,t)),Ba=(e,t)=>{if(Qt(e,t))return!0;const s=_(e);return s!==void 0&&Qt(s,t)},Qe=(e,t)=>Yo(e,t)&&!Ba(e,t),qa=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=_(e);return t!==void 0&&o.isNewExpression(t)&&x(t.getExpression())==="Headers"},xe=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=_(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},rt=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&Qe(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:_s(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const r=n.getNameNode();Qe(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:E(n),line:r.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const r=xe(n.getExpression());r!==void 0&&rt(r,t,s)}},Ks=(e,t)=>{const s=xe(e);if(s===void 0)return;const n=O(s,"headers");if(n===void 0||!o.isPropertyAssignment(n))return;const r=xe(n.getInitializer());r!==void 0&&rt(r,"response-init",t)},Wa=(e,t)=>{const s=x(e.getExpression());if(s==="Response")Ks(e.getArguments()[1],t);else if(s==="Headers"){const n=xe(e.getArguments()[0]);n!==void 0&&rt(n,"headers-ctor",t)}},Va=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&o.isIdentifier(r)&&r.getText()==="Response"){Ks(e.getArguments()[1],t);return}if(ja.has(n)&&qa(r)){const i=e.getArguments()[1];i!==void 0&&Qe(i,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:_s(e.getArguments()[0]),line:i.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ha=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))Wa(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Va(s,t)},Ga=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=re(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const i=r.getNameNode();if(!o.isIdentifier(i))return[];const a=[];return Ha(n,{scope:g(e),relativePath:t,requestName:i.getText(),rows:a}),a},Ya=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression))s.push(...Ga(n,t));return s},Qa=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(r,b(t,n)))}return s},Xa=new Set(["auth","context.auth","ctx.auth"]),Ja="userId",Za=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(E(s))}return t},ec=(e,t)=>{const s=h(t,Is);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(u.CallExpression)){if(x(r.getExpression())!=="defineIdentity")continue;const[i]=r.getArguments();return i&&o.isObjectLiteralExpression(i)?Za(i):void 0}},Xt=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Xa.has(e.getExpression().getText())?e:void 0},tc=e=>{if(o.isPropertyAccessExpression(e)&&Xt(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&Xt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Jt=(e,t,s)=>{const n=tc(e);return n===void 0?void 0:{declared:n===Ja||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:g(e)}},sc=(e,t)=>{const s=ec(e,t);return s===void 0?[]:[...We(e,t,u.PropertyAccessExpression,(n,r)=>Jt(n,r,s)),...We(e,t,u.ElementAccessExpression,(n,r)=>Jt(n,r,s))]},nc=(e,t)=>{if(x(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!K(n)||W(n)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},rc=(e,t)=>N(e,t,nc),oc=e=>{if(o.isComputedPropertyName(e)){const t=e.getExpression();return o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)?t.getLiteralValue():void 0}return o.isStringLiteral(e)?e.getLiteralValue():e.getText()},ic=e=>e.getProperties().some(t=>{if(o.isSpreadAssignment(t))return!0;const s=oc(t.getNameNode());return s===void 0||s==="namespace"}),ac=(e,t)=>{for(const{filePath:s}of Ne(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(u.CallExpression)){const i=r.getExpression(),[a]=r.getArguments();if(!(!o.isPropertyAccessExpression(i)||i.getName()!=="auth"||a===void 0)&&(!o.isObjectLiteralExpression(a)||ic(a)))return r}}},cc="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",lc=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw ie(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${cc}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},uc=new Set(["delete","get","getRaw","getWithMetadata","put"]),dc=(e,t,s=[])=>{const n=Ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:uc});return Ze(n,s)},fc=new Set(["queue","send"]),Zt=new Set(["bcc","cc","to"]),pc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!fc.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},gc=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Zt.has(E(t))&&K(n)&&!W(n)}if(!o.isPropertyAssignment(t)||!Zt.has(E(t)))return!1;const s=t.getInitializer();return s!==void 0&&K(s)&&!W(s)}):!1,mc=(e,t)=>{const s=pc(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!gc(n)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s}},hc=(e,t)=>N(e,t,mc),vc=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,Ec=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?vc(e):!0,$s=(e,t=!1)=>{for(const s of e.getProperties()){if(Ec(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||$s(n,!0))return!0}return!1},xc=(e,t)=>{for(const s of m(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of ws(n))for(const i of et(r)){const a=i.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||$s(a)))return!0}}return!1},Sc=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=Ee(n);if(r===void 0||!o.isPropertyAssignment(n))continue;const i=n.getInitializer();if(!(!i||!o.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=Ee(a);c!==void 0&&s.push({column:c,strategy:Ns(a),table:r})}}return s},yc=(e,t)=>{const s=new Map;for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:i}of ws(r))for(const a of et(i))for(const c of Sc(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},Ac=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const r=[];for(const i of n.getProperties()){const a=Ee(i);if(a===void 0||!o.isPropertyAssignment(i))continue;const c=i.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const d=Ee(l);if(d===void 0)continue;const p=Ns(l);p!=="custom"&&r.push({column:d,exportName:t,file:s,line:l.getStartLineNumber(),strategy:p,table:a})}}return r},bc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;return n?.receiver?et(n.receiver).flatMap(r=>Ac(r,e.getName(),t)):[]},Nc=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...bc(c,i))}return s},wc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},Pc=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=O(t,"server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},Ic=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return ar(s.getExpression())?s:void 0},Tc=e=>{const t=Ic(e),s=t===void 0?void 0:Pc(t);if(s===void 0)return[];const n=e.getNameNode(),r=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(i=>wc(i)).map(i=>({exportName:r,file:"lunora/mutators.ts",line:i.getStartLineNumber()}))},Cc=e=>e.getVariableDeclarations().flatMap(t=>Tc(t)),Oc=(e,t)=>{const s=h(t,ir);if(!P(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Cc(n)},Rc=new Set(["delete","get","patch"]),Fc=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),kc=new Set(["auth","identity","session","user"]),Lc=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Dc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Mc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},_c=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Kc=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,$c=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>_c(s.getExpression(),t)&&Kc(s.getThenStatement())),zc=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const r=n.getName();if(!Rc.has(r))continue;const i=n.getExpression();if(!(L(i)||o.isPropertyAccessExpression(i)&&L(i.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return r}},Uc=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},jc=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Uc(s)==="ctx")),Bc=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Lc.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),qc=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Fc.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&kc.has(t.getName()))return!0}return jc(e)||Bc(e)},Wc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=j(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=Ls(s);if(r===void 0)return[];const i=n.receiver!==void 0&&ys(n.receiver,"use","rls"),a=qc(r),c=new Set,l=[];for(const d of r.getDescendantsOfKind(u.CallExpression)){const p=Dc(d);if(p===void 0)continue;const v=Mc(d);if(v===void 0||c.has(v)||!$c(r,v))continue;const S=zc(r,v);S!==void 0&&(c.add(v),l.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:S,table:p,usesRls:i,visibility:n.visibility}))}return l},Vc=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Wc(c,i))}return s},Hc=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Gc=new Set(["insert","insertManyUnsafe","patch","replace"]),Yc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Gc.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Qc=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},es=(e,t)=>{if(o.isPropertyAccessExpression(e)){const s=e.getExpression();return o.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(o.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return o.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&o.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},Xc=e=>{if(!o.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a));if(s===void 0)return;for(const a of s.getDescendantsOfKind(u.BinaryExpression)){const c=a.getLeft();if(o.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let r,i=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!o.isVariableDeclarationList(c)||c.getDeclarationKind()!==pn.Const)continue;const l=a.getInitializer(),d=a.getStart();l!==void 0&&d<n&&d>i&&(r=l,i=d)}return r},Jc=(e,t)=>{if(es(e,t))return!0;const s=Xc(e);return s!==void 0&&es(s,t)},Zc=(e,t,s,n,r)=>{const i=[];for(const a of e.getProperties()){let c,l;if(o.isPropertyAssignment(a)?(c=E(a),l=a.getInitializer()):o.isShorthandPropertyAssignment(a)&&(c=E(a),l=a.getNameNode()),!(c===void 0||l===void 0||!Hc.has(c))&&K(l)&&!W(l)){const d=g(s),p=d.kind==="export"&&r(d.name)===c&&Jc(l,c);i.push({field:c,file:n,line:s.getStartLineNumber(),method:t,scope:d,...p&&{ownerScoped:!0}})}}return i},el=(e,t,s)=>{const n=Yc(e.getExpression());if(n===void 0)return[];const r=e.getArguments()[1];return r?Qc(r,n).flatMap(i=>Zc(i,n,e,t,s)):[]},tl=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),i=N(e,t,(a,c)=>el(a,c,l=>r.get(`${c}:${l}`)));return Ze(i,s)},sl=["providerSubscriptionId","state"],nl=["providerEventId","processedAt"],ts=(e,t)=>t.every(s=>s in e.shape),rl=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ts(t,sl)&&ts(s,nl)},ol=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),il=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,al=e=>{const t=O(e,"webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?il(t.getInitializer()):void 0},cl=(e,t)=>{const s=x(e.getExpression());if(s===void 0||!ol.has(s))return;const[n]=e.getArguments(),r=n&&o.isObjectLiteralExpression(n)?al(n):void 0;return{callee:s,scope:g(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},ll=(e,t)=>N(e,t,cl),ul=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),dl=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},fl=(e,t)=>{const s=e.getArguments()[t];if(!s||!o.isObjectLiteralExpression(s))return;const n=O(s,"handler");if(n===void 0||!o.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(o.isArrowFunction(r)||o.isFunctionExpression(r)))return r},zs=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Us=(e,t)=>e===t||e.startsWith(`${t}.`),js=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},ss=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},Bs=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>ss(s));return o.isIdentifier(e)&&ss(e)&&t.push(e),t},pl=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},gl=e=>{const t=zs(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(u.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),i=o.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;i&&o.isIdentifier(i)&&s.push(`${i.getText()}.body`)}return s},ml=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:gl(e),r=new Set,i=a=>js(a).some(c=>n.some(l=>Us(c.getText(),l)))?!0:Bs(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&i(c))for(const l of pl(a))r.add(l)}return{names:r,prefixes:n}},hl=(e,t)=>js(e).some(s=>t.prefixes.some(n=>Us(s.getText(),n)))?!0:Bs(e).some(s=>t.names.has(s.getText())),vl=e=>{const t=vs(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},El=(e,t,s)=>{const n=zs(e,0);if(n===void 0)return[];const r=ml(e,t,n),i=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(u.CallExpression)){const l=c.getExpression();if(!o.isPropertyAccessExpression(l)||!hs.has(l.getName())||!i.has(l.getExpression().getText()))continue;const d=c.getArguments()[1];if(!d||!hl(d,r))continue;const p=vl(c.getArguments()[0]);p!==void 0&&a.push({dispatchKind:t,file:s,scope:g(c),line:c.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return a},xl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=dl(n),i=r===void 0?void 0:ul.get(r);if(i===void 0)continue;const a=fl(n,i);a!==void 0&&s.push(...El(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},Sl=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xl(r,b(t,n)))}return s},ns={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},rs=new Set(["account","credential","member","passkey","session","user"]),yl=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Al=e=>{const s=yl(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return rs.has(s)||rs.has(n)},bl=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Nl=(e,t)=>{const{objects:s,opaque:n}=nt(e,t);return gi(s).some(r=>bl(r))?!0:n?void 0:!1},wl=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!O(t,"captcha"),usesRateLimit:!!O(t,"rateLimit")}},Pl=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},ve={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Il=e=>{const t=Pl(e),s=t?x(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=wl(t);return{...ve,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ns?{...ve,[ns[s]]:!0}:ve},Tl=e=>{const t={...ve};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const i=Il(r);t.usesCaptcha||=i.usesCaptcha,t.usesEmailGate||=i.usesEmailGate,t.usesMask||=i.usesMask,t.usesRateLimit||=i.usesRateLimit,t.usesRls||=i.usesRls}s=n.getExpression()}return t},Cl=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Ol=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Cl.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const r=e.getArguments()[0];return!r||!(o.isStringLiteral(r)||o.isNoSubstitutionTemplateLiteral(r))?!1:Al(r.getLiteralText())},Rl=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Fl=new Set(["queues","scheduler","topics","workflows"]),kl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Rl.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&Fl.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ll=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},qs=new Set(["generateObject","generateText","streamObject","streamText"]),Dl=e=>{const t=x(e.getExpression());return t!==void 0&&qs.has(t)},Ml=e=>{const t=x(e.getExpression());if(t===void 0||!qs.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!O(s,"maxOutputTokens")},_l=new Set(["log","span","trace"]),Kl=new Set(["ai"]),$l=new Set(["email","mail"]),zl=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),Be=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),Ul=new Set([u.ArrowFunction,u.FunctionDeclaration,u.FunctionExpression,u.GetAccessor,u.MethodDeclaration,u.SetAccessor]),jl=new Set(["every","filter","flatMap","forEach","map","some"]),Bl=new Set(["all","allSettled","race"]),ql=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(jl.has(n))return t;const r=s.getExpression();if(o.isIdentifier(r)&&r.getText()==="Promise"&&Bl.has(n))return t},Wl=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Ul.has(t.getKind())){const s=ql(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Vl=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Hl=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Gl=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(u.PropertyAccessExpression)){if(!zl.has(n.getName()))continue;const r=n.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")continue;const i=Hl(n);i&&(t=!0,!Wl(i)&&!Vl(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Yl=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),os="lunora-advisor-exempt",Ql=/^[\s*/]+/u,Xl=/[\w-]/u,Jl=e=>{const s=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
7
+ `);for(const n of s.split(`
8
+ `)){const r=n.replace(Ql,"");if(!r.startsWith(os))continue;const i=r.slice(os.length);if(Xl.test(i.charAt(0)))continue;const a=i.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":i.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Zl=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=O(t,"handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},eu=(e,t)=>{const s=Zl(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),i=n.getVariableDeclaration(r)?.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:n.getFunction(r)},tu=e=>{let t=!1,s=!1,n=!1,r=!1,i=!1;for(const l of e.getDescendantsOfKind(u.CallExpression))if(Ol(l)&&(i=!0),kl(l)&&(t=!0),Ll(l)&&(r=!0),Dl(l)&&(s=!0),Ml(l)&&(n=!0),i&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=Gl(e);return{callsMail:Be(e,$l),emitsEvent:Be(e,_l),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Be(e,Kl),throwsBareError:Yl(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:i}},su=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=j(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?Tl(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},i=eu(e,s);return{...i?tu(i):{},...Jl(e),...r,analyzableBody:i!==void 0,exportName:e.getName(),file:t,hasEmailArg:Nl(s,n.receiver),kind:n.kind,visibility:n.visibility}},nu=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=su(r,t);i&&s.push(i)}return s},ru=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...nu(r,b(t,n)))}return s},ou=new Set(["dbRateLimit","rateLimit"]),iu=e=>o.isArrowFunction(e)?e.getBody():e,au=e=>{if(!o.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&o.isIdentifier(t)?t:void 0},Ws=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Vs=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(u.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(o.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},cu=(e,t)=>K(e)||t!==void 0&&Vs(e,t).some(s=>Ws(s)),lu=(e,t)=>t===void 0?W(e):Vs(e,t).some(s=>!Ws(s)),uu=(e,t)=>{const s=x(e.getExpression());if(s===void 0||!ou.has(s))return;const n=A(xs(e.getArguments()[2]),"key");if(!n)return;const r=iu(n),i=au(n);if(!(!cu(r,i)||lu(r,i)))return{callee:s,scope:g(e),file:t,limitName:Es(e),line:e.getStartLineNumber()}},du=(e,t)=>N(e,t,uu),fu=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),pu=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!fu.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},gu=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},mu=e=>{let t=ne(e)??e;for(;o.isAwaitExpression(t);)t=ne(t.getExpression())??t.getExpression();return t},Hs=(e,t=!1)=>{const s=mu(e);if(o.isIdentifier(s)){if(t)return;const n=_(s);return n===void 0?void 0:Hs(n,!0)}if(o.isCallExpression(s))return pu(s)??gu(s)},hu=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(u.ReturnStatement)){const r=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),i=n.getExpression();r===e&&i!==void 0&&s.push(i)}return s},vu=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=j(s);if(n?.kind!=="query")return[];const r=Ls(s);if(r===void 0)return[];const i=n.receiver!==void 0&&Kn(n.receiver,"output"),a=n.receiver!==void 0&&ys(n.receiver,"use","mask"),c=new Set,l=[];for(const d of hu(r)){const p=Hs(d);p===void 0||c.has(p)||(c.add(p),l.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:p,usesMask:a,usesOutput:i,visibility:n.visibility}))}return l},Eu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...vu(c,i))}return s},xu=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(E(s));return t},Su=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;if(!n)return[];const r=[];for(const i of e.getDescendantsOfKind(u.CallExpression)){const a=Ss(i);if(a===void 0)continue;const c=xu(A(a.options,"with"));c.length!==0&&r.push({exportName:e.getName(),file:t,line:i.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},yu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Su(c,i))}return s},Se=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=Se(e.getLeft()),s=Se(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Au=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&Se(t)!==void 0},bu=/(?:^|\/)__tests__\//u,Nu=/\.(?:spec|test)$/u,wu=e=>bu.test(e)||Nu.test(e),Pu=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return E(t);if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===u.EqualsToken)return t.getLeft().getText()}},Iu=(e,t,s)=>xr(e)?!wu(s)&&Sr(Pu(t)):!0,Tu=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],r=new Set;for(const i of n){if(Au(i))continue;const a=Se(i);if(a===void 0)continue;const c=vr(a);if(c===void 0||!Iu(c,i,t))continue;const l=i.getStartLineNumber(),d=`${String(l)}:${c}`;r.has(d)||(r.add(d),s.push({file:t,kind:c,line:l,preview:Er(a)}))}return s},Cu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Tu(r,b(t,n)))}return s},Ou=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;if(!n)return[];const r=[];for(const i of e.getDescendantsOfKind(u.CallExpression)){const a=Ss(i);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const l=o.isTrueLiteral(c),d=!l&&K(c);!l&&!d||r.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:l,line:i.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},Ru=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ou(c,i))}return s},Fu=new Set(["query","unsafe"]),ku=e=>{if(!o.isPropertyAccessExpression(e)||!Fu.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},Lu=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),Du=(e,t)=>{if(!ku(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Lu(s)))return{file:t,line:s.getStartLineNumber(),scope:g(e)}},Mu=(e,t)=>N(e,t,Du),_u=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Ku=e=>{for(const[t,s]of _u)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},$u=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getImportDeclarations()){const a=i.getModuleSpecifierValue(),c=Ku(a);c!==void 0&&s.push({file:b(t,n),line:i.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},zu=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Uu=(e,t,s=[])=>{const n=Ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:zu,requireUnmodifiedReach:!0});return Ze(n,s)},ju=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Bu=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,qu=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(o.isSpreadAssignment(r)){n=!0;continue}if(o.isPropertyAssignment(r)){const i=E(r);t.push(i),i==="expiresInSeconds"&&(s=Bu(r.getInitializer()));continue}(o.isShorthandPropertyAssignment(r)||o.isMethodDeclaration(r))&&t.push(E(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Wu=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=ju.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Vu=(e,t)=>{const s=Wu(e.getExpression());if(s!==void 0)return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s.method,...qu(e.getArguments()[s.optionsIndex])}},Hu=(e,t)=>N(e,t,Vu),Gu=(e,t)=>{const s=jn(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},Yu=new Set(["delete","hardDelete","patch","replace","restore"]),Qu=new Set(["insertMany","insertManyUnsafe","patchWhere"]),Xu=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),is=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],r=n.map(i=>i.getLiteralValue()).filter(i=>typeof i=="string");return r.length===n.length?r:[]},Ju=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const r=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return r===void 0?[]:is(r,e)}return is(s,e)},as="",Zu=(e,t)=>{if(Qu.has(e))return{method:e,tables:[t!==void 0&&o.isStringLiteral(t)?t.getLiteralText():as]};if(Yu.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Ju(t,e);return{method:e,tables:s.length===0?[as]:s}}},ed=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if(L(n))return Zu(s,e.getArguments()[0]);if(Xu.has(s)&&o.isPropertyAccessExpression(n)&&L(n.getExpression()))return{method:s,tables:[n.getName()]}},td=(e,t)=>N(e,t,(s,n)=>{const r=ed(s);if(r===void 0)return;const i=g(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:i,table:c}))}),sd=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),nd=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!o.isObjectLiteralExpression(s)||O(s,"args")===void 0)return!1}return nt(e,t).opaque},rd=(e,t)=>{const s=[],n=(r,i)=>{const a=r.getInitializer();if(a===void 0||!o.isCallExpression(a))return;const c=j(a);c!==void 0&&nd(a,c.receiver)&&s.push(sd(t,i,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(i=>i.isExported()))for(const i of r.getDeclarations())n(i,i.getName());return s},od=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...rd(r,b(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},id=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Te=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),Gs=e=>!e.isAny(),ot=e=>{const t=e.getType();if(!Gs(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:id.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Ys=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},Qs={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},ad=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),cd={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},it=(e,t,s,n,r)=>{const{call:i,file:a,note:c,typeName:l}=s,d=a!==void 0&&e!==a?a:void 0,p=d===void 0?r:ad(d),v=c===void 0?p.remediation:`${c} ${p.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${p.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${i};\`. ${v}`:v,title:"Procedure exists at runtime but is missing from the generated API"}},ld=(e,t,s)=>{const n=[];for(const r of e.getVariableStatements().filter(i=>i.isExported()))for(const i of r.getDeclarations()){const a=i.getName();if(Te(s,t,a)||!Ys(i))continue;const c=ot(i);c!==void 0&&n.push(it(t,a,c,i.getStartLineNumber(),Qs))}return n},ud=(e,t,s)=>{if(Te(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(i=>!i.isExportEquals())){const i=ot(r.getExpression());i!==void 0&&n.push(it(t,"default",i,r.getStartLineNumber(),Qs))}return n},dd=(e,t,s)=>{const n=[];for(const r of e.getExportDeclarations().filter(i=>i.getModuleSpecifier()===void 0))for(const i of r.getNamedExports()){const a=i.getAliasNode()?.getText()??i.getName();if(Te(s,t,a))continue;const c=i.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!Ys(c))continue;const l=ot(c);l!==void 0&&n.push(it(t,a,l,i.getStartLineNumber(),cd))}return n},fd=(e,t,s)=>[...ld(e,t,s),...ud(e,t,s),...dd(e,t,s)],pd=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>Te(s,t,n.getName())).filter(n=>{const r=n.getInitializer();return r!==void 0&&o.isCallExpression(r)&&o.isPropertyAccessExpression(r.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),gd=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),md=(e,t,s)=>{const n=[],r=[];for(const a of m(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=b(t,a);n.push(...fd(c,l,s)),r.push(...pd(c,l,s))}const[i]=r;return i!==void 0&&r.every(({declaration:a})=>!Gs(a.getType()))&&n.push(gd(i)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},hd=new Set(["when","where"]),qe=new Set(["definePolicy","defineShape"]),vd=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return qe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const r=n.getNameNode().getText();return qe.has(r)?r:void 0}const s=t.getText();return qe.has(s)?s:void 0},Ed=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,Xs=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ed(e))return"empty-object";if(o.isParenthesizedExpression(e))return Xs(e.getExpression())}},at=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),xd=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>at(t)===e),Js=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>at(t)===e),Sd=e=>{const t=xd(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Js(e).length>0},yd=e=>e.getDescendantsOfKind(u.IfStatement).filter(t=>at(t)===e),Xe=e=>e.getKind()===u.NullKeyword||e.getKind()===u.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",Ad=(e,t)=>Xe(e)||Xe(t),bd=new Map([[u.EqualsEqualsEqualsToken,"positive"],[u.EqualsEqualsToken,"positive"],[u.ExclamationEqualsEqualsToken,"negative"],[u.ExclamationEqualsToken,"negative"]]),cs=e=>!Xe(e)&&(o.isLiteralExpression(e)||e.getKind()===u.TrueKeyword),Nd=(e,t,s)=>{const n=bd.get(e);if(n!==void 0)return Ad(t,s)?n==="positive"?"negative":"positive":cs(t)||cs(s)?void 0:n},se=e=>{if(o.isParenthesizedExpression(e))return se(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===u.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Nd(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===u.AmpersandAmpersandToken||t===u.BarBarToken){const n=se(e.getLeft()),r=se(e.getRight());return n===r?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},ls=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},wd=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(u.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Pd=e=>o.isReturnStatement(e)?e.getExpression()??e:e,Id=e=>{const t=[];for(const s of Js(e)){const n=se(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of yd(e)){const n=se(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?ls(s.getThenStatement()):ls(s.getElseStatement())??wd(s);r!==void 0&&t.push(Pd(r))}return t},Td=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Cd=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const r=[];for(const i of n.getProperties()){if(!o.isPropertyAssignment(i)||!hd.has(E(i)))continue;const a=i.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Sd(a))for(const c of Id(a)){const l=Xs(c);l!==void 0&&r.push({exportName:Td(e),file:s,form:l,key:E(i),line:c.getStartLineNumber(),owner:t})}}return r},Od=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=vd(n);r!==void 0&&s.push(...Cd(n,r,t))}return s},Rd=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Od(r,b(t,n)))}return s},Fd=new Set(["query","upsert","upsertNow"]),kd=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Fd.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Ld=(e,t)=>{const s=kd(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=A(n,"namespace");if(!(!r||!K(r)||W(r)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s}},Dd=(e,t)=>N(e,t,Ld),Md=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},_d=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Kd=(e,t)=>N(e,t,(s,n)=>Md(s)?{file:n,line:s.getStartLineNumber(),scope:g(s),workflow:_d(s)}:void 0),$d=".lunora-schema.json",Je=(e,t)=>{P(e)&&fs(e,"utf8")===t||un(e,t,"utf8")},zd=(e,t)=>{if(t===""){dn(e,{force:!0});return}Je(e,t)},Ud=e=>{const t=h(e,"package.json");if(P(t))try{const s=JSON.parse(fs(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},jd=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Bd=e=>{let t=P(e)?e:me(e);for(;t&&t!==me(t);){const s=h(t,"tsconfig.json");if(P(s))return s;t=me(t)}},us=e=>e.replaceAll("\\","/"),qd=(e,t,s)=>{if(s&&e.length>0){const i=e.map(a=>`"${a.exportName}"`).join(", ");throw new U("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${i}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const i of t.columns){const a=n.get(i.table)??[];a.push(i.column),n.set(i.table,a)}const r=t.columns.length>0;for(const i of e){if(i.table===void 0){if(r)throw new U("MASK_UNSUPPORTED",`defineShape "${i.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${i.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(i.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new U("MASK_UNSUPPORTED",`defineShape "${i.exportName}" replicates table "${i.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ye=(e,t,s)=>{const n=e.getSourceFile(t);if(n===void 0){e.createSourceFile(t,s,{overwrite:!0});return}n.getFullText()!==s&&n.replaceWithText(s)},ds=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Wd=8,Vd=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:r,migrations:i,project:a,shapes:c,usesSandbox:l,useUmbrella:d,workflows:p}=e,v=()=>Zn(()=>{const y=er(a,r),T=cr(a,r);return{functions:y,httpRoutes:tr(a,r),mutators:T}});let{erased:S,value:{functions:k,httpRoutes:D,mutators:M}}=v();Mt([...k,...M].map(y=>y.filePath)),Mt(D.filter(y=>y.stream).map(y=>y.filePath),"http-stream");for(let y=1;;y+=1){const T=Or({agents:t,functions:k,httpRoutes:D,mutators:M,useUmbrella:d,workflows:p}),$=Ur({agents:t,functions:k,migrations:i,mutators:M,shapes:c,useUmbrella:d,usesSandbox:l});if(y>=Wd||ds(a,s,T)&&ds(a,n,$))return{apiContent:T,erased:S,functions:k,functionsContent:$,httpRoutes:D,mutators:M};ye(a,s,T),ye(a,n,$),{erased:S,value:{functions:k,httpRoutes:D,mutators:M}}=v()}},Hd=e=>{const t=Bd(e);return t?new Ft({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ft({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},op=(e,t)=>{const s=m(t),n=h(t,"schema.ts");P(n)&&s.push(n);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const r=new Set(s.map(c=>us(c))),i=us(t),a=`${i}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===i||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===i||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ip=e=>{const t=jd(),s=t?_e.now():0,n=h(e.projectRoot,e.lunoraDirectory??"lunora"),r=h(n,"schema.ts");if(!P(r))throw new U("INTERNAL",`schema.ts not found at ${r}`);const i=e.project??Hd(n);Vn(wa);const a=hr(i,r,e.projectRoot),{agents:c,capabilities:l,containers:d,crons:p,dataModelContent:v,dependencies:S,entryCronTriggers:k,env:D,featureUsage:M,hasFlags:y,hasNotify:T,identity:$,platformGate:B,queues:C,serverContent:G,services:Z,storageRulesMetadata:ee,topics:Y,usesSandbox:ae,useUmbrella:z,workflows:R}=Mo({lunoraDirectory:n,project:i,projectRoot:e.projectRoot,schema:a,target:e.target});lc(a,a.jurisdiction===void 0?void 0:ac(i,n)),io(a,M.artifacts);const F=h(n,"_generated"),I=h(F,"dataModel.ts"),Zs=h(F,"server.ts"),en=h(F,"api.ts"),tn=h(F,"functions.ts");ye(i,I,v),ye(i,Zs,G);const ce=or(i,n),Q=yr(i,n),{apiContent:ct,erased:sn,functions:q,functionsContent:lt,httpRoutes:Ce,mutators:le}=Vd({agents:c,apiPath:en,generatedFunctionsPath:tn,lunoraDirectory:n,migrations:ce,project:i,shapes:Q,useUmbrella:z,usesSandbox:ae,workflows:R}),ut=vn(i,n),Oe=En(ut,a,[...q,...Ce].map(f=>f.filePath)),ue=ut.length>0,V=e.lint===!1&&!ue?void 0:{inserts:nr(i,n),queries:fr(i,n),tableWrites:td(i,n),workflowCalls:Kd(i,n)},de=e.lint===!1||V===void 0?void 0:mn({adminRoutes:qo(i,n),aiRawRuns:Jo(i,n),aiToolSideEffects:ci(i,n),argumentDerivedFetches:di(i,n),argumentValidators:yi(i,n),authApiCalls:Hn(i,n),authConfigs:Ri(i,n),browserUrlAccesses:Di(i,n),configCalls:Gi(i,n),containerKeyAccesses:Qi(i,n),containerOverrides:sa(i,n),containers:d,exportSinks:ia(i,n),staleMigrationImports:$u(i,n),failOpenGuards:da(i,n),flagReads:Sa(i,n),flagSecurityDefaults:Na(i,n),geoIndexUsages:Ta(i,n),httpActionGuards:za(i,n),httpHeaderWrites:Qa(i,n),hyperdriveCalls:sr(i,n),identityClaimReads:sc(i,n),imageDeliveryUrlAccesses:rc(i,n),inserts:V.inserts,kvKeyAccesses:dc(i,n,q),mailRecipientAccesses:hc(i,n),maskProcedures:rr(i,n),maskStrategies:Nc(i,n),mutatorWrites:Oc(i,n),nondeterministicCalls:lr(i,n),normalizeIdAuthorizations:Vc(i,n),notifyCalls:dr(i,n),notifyConfig:ur(i,n),mutators:le,ownerFieldWrites:tl(i,n,q,le),unrestrictedWhereBranches:Rd(i,n),paymentWebhooks:ll(i,n),privilegedDispatches:Sl(i,n),procedureProtections:ru(i,n),queries:V.queries,queues:C,r2sqlCalls:pr(i,n),ratelimitKeySelectors:du(i,n),rawRowReturns:Eu(i,n),relationLoads:yu(i,n),rlsProcedures:gr(i,n),schema:a,secretLiterals:Cu(i,n),modules:Oe,shapes:Q,softDeleteReads:Ru(i,n),sqlInterpolations:Mu(i,n),storageKeyAccesses:Uu(i,n,q),storageUploads:Hu(i,n),tableWrites:V.tableWrites,vectorNamespaceAccesses:Dd(i,n),workflowCalls:V.workflowCalls,workflows:R,wranglerVariables:e.wranglerVariables}),dt=de===void 0?[]:Br(e.projectRoot,[...fn(de,{source:"static"}),...md(i,n,{byName:new Set([...R,...C,...c,...d].map(f=>f.exportName)),byPath:new Set([...q,...le,...Q,...ce].map(f=>`${f.filePath}:${f.exportName}`))}),...od(i,n),...Jn(sn,n)]),nn=mr(i,n),ft=yc(i,n);qd(Q,ft,xc(i,n));const rn=y?ma(i,n):[],Re=B.signals.vectorStore!==!1,te=Gu(M,{containerCount:d.length,cronCount:p.length,dependencies:S,hasPaymentTables:rl(a.tables),queueCount:C.length,storageColumnCount:Object.keys(bs(a)).length,storageRuleCount:ee.rules.length,vectorIndexCount:a.vectorIndexes.length,target:As(e.projectRoot,e.target),vectorStoreSupported:Re,workflowCount:R.length}),pt=t?_e.now():0,Fe=Ir(a,ce.map(f=>f.id)),gt=Bn({advisories:dt.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:de?.procedureProtections??[],agents:c,capabilities:l,containers:d,env:D,flagKeys:rn,hasFlags:y,hasNotify:T,hasVectors:Re,maskMetadata:ft,mutators:le,queues:C,rlsMetadata:nn,schema:a,schemaSnapshot:Fe,shapes:Q,services:Z,storageRules:ee,studioFeatures:te,topics:Y,useUmbrella:z,workflows:R}),mt=Tr(Q,S.has("@lunora/db"),z),ht=Rr(d,a.jurisdiction),vt=Fr(R),Et=kr(c),xt=Lr(C),St=Dr(p),on=Mr(te.scheduler),an=_r(a.tables,z),yt=Kr(a.vectorIndexes),fe=zr(a,z),At=Cr(S.has("@lunora/seed")),pe=e.apiSpec??"openapi",ke=pe==="openapi"||pe==="both",Le=pe==="openrpc"||pe==="both",bt=Ar({capabilities:l,emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({className:f.className,exportName:f.exportName})),hasAccess:S.has("@lunora/cloudflare-access"),hasAuth:S.has("@lunora/auth"),hasFramework:S.has("@lunora/astro")||S.has("@lunora/svelte")||S.has("@lunora/vue")||P(h(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(f=>ps(f)),hasHyperdriveGlobal:a.tables.some(f=>gs(f)),hasKvIntrospector:te.kv,hasNotify:T,hasQueue:C.some(f=>f.mode==="push"),hasScheduler:te.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:te.storage,hasVectors:Re,hasWorkflow:R.length>0,identity:$,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(f=>({name:f.name,shardMode:f.shardMode})),useUmbrella:z,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsArchitecture:ue,wantsOpenApi:ke,wantsOpenRpc:Le}),Nt=Ud(e.projectRoot),wt=ue?Oe:[],Pt=br({functions:q,httpRoutes:Ce,modules:wt,version:Nt}),It=wr({functions:q,modules:wt,version:Nt}),Tt=`${JSON.stringify(Pt,void 0,2)}
9
+ `,Ct=`${JSON.stringify(It,void 0,2)}
10
+ `,ge=ue&&V!==void 0?ro({...V,callEdges:zi(i,n),crons:p,functions:q,httpRoutes:Ce,modules:Oe,queues:C,schema:a,services:Z,topics:Y,workflows:R}):void 0,Ot=Nr(Pt),Rt=Pr(It),De=h(n,$d),cn=P(De),Me=[];if(!e.dryRun){P(F)||ln(F,{recursive:!0});const f=(H,X)=>{Je(h(F,H),X),Me.push(H)},w=(H,X)=>{zd(h(F,H),X),X!==""&&Me.push(H)};f("app.ts",bt),f("dataModel.ts",v),f("api.ts",ct),f("server.ts",G),f("functions.ts",lt),f("shard.ts",gt),f("crons.ts",St),f("vectors.ts",yt),f("drizzle.global.ts",fe.global),f("drizzle.shard.ts",fe.shard),w("containers.ts",ht),w("workflows.ts",vt),w("agents.ts",Et),w("queues.ts",xt),w("scheduler.ts",on),w("shardRegistry.ts",an),w("seed.ts",At),w("collections.ts",mt),w("openapi.json",ke?Tt:""),w("openapi.ts",ke?Ot:""),w("openrpc.json",Le?Ct:""),w("openrpc.ts",Le?Rt:""),w("architecture.json",ge===void 0?"":`${JSON.stringify(ge,void 0,2)}
11
+ `),w("architecture.ts",ge===void 0?"":oo(ge)),(!cn||e.updateSchemaBaseline===!0)&&Je(De,gn(Fe))}if(t){const f=_e.now(),w=Math.round(f-s),H=Math.round(pt-s),X=Math.round(f-pt);console.error(`@lunora/codegen: codegen took ${w.toString()}ms (discovery ${H.toString()}ms, emit ${X.toString()}ms)`)}return{advisories:dt,advisorContext:de,agents:c,containers:d,cronTriggers:[...new Set([...$r(p),...k])],generated:{agents:Et,api:ct,app:bt,collections:mt,containers:ht,crons:St,dataModel:v,drizzleGlobal:fe.global,drizzleShard:fe.shard,functions:lt,openApi:Tt,openApiModule:Ot,openRpc:Ct,openRpcModule:Rt,queues:xt,seed:At,server:G,shard:gt,vectors:yt,workflows:vt},migrations:ce,outputDirectory:F,platformDiagnostics:B.diagnostics,queues:C,schemaSnapshot:Fe,schemaSnapshotPath:De,workflows:R,writtenFiles:Me}};export{$d as SCHEMA_SNAPSHOT_FILENAME,Hd as createCodegenProject,Bd as findTsconfig,op as refreshCodegenProject,ip as runCodegen};
@@ -1 +1 @@
1
- import{existsSync as l}from"node:fs";import{join as m}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as p}from"./module-specifiers-WF8iAydP.mjs";import{p as g}from"./parse-validator-C6fHL7OS.mjs";import{findObjectProperty as f}from"./listLunoraSourceFiles-CSlcBYlo.mjs";const d="shapes.ts",S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return p(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},h=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&p(i.getModuleSpecifierValue())}return!1},x=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&h(t)}return!1},b=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=f(t,"table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},y=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=f(t,"args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:g(i)},N=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const s=i,a=s.getExpression();if(!x(a))continue;const n=e.getNameNode();if(!o.isIdentifier(n))throw u(n,"defineShape exports must be plain named exports (no destructuring)");t.push({args:y(s),exportName:n.getText(),filePath:"shapes",table:b(s)})}return t},L=(r,t)=>{const e=m(t,d);if(!l(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),s=N(i);return s.sort((a,n)=>a.exportName.localeCompare(n.exportName)),s};export{d as SHAPES_FILENAME,L as discoverShapes};
1
+ import{existsSync as l}from"node:fs";import{join as m}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as p}from"./module-specifiers-WF8iAydP.mjs";import{p as g}from"./parse-validator-0q0Uz-Cx.mjs";import{findObjectProperty as f}from"./listLunoraSourceFiles-jTik1QWu.mjs";const d="shapes.ts",S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return p(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},h=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&p(i.getModuleSpecifierValue())}return!1},x=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&h(t)}return!1},b=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=f(t,"table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},y=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=f(t,"args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:g(i)},N=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const s=i,a=s.getExpression();if(!x(a))continue;const n=e.getNameNode();if(!o.isIdentifier(n))throw u(n,"defineShape exports must be plain named exports (no destructuring)");t.push({args:y(s),exportName:n.getText(),filePath:"shapes",table:b(s)})}return t},L=(r,t)=>{const e=m(t,d);if(!l(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),s=N(i);return s.sort((a,n)=>a.exportName.localeCompare(n.exportName)),s};export{d as SHAPES_FILENAME,L as discoverShapes};
@@ -0,0 +1 @@
1
+ import{existsSync as k}from"node:fs";import{join as y}from"node:path";import{LunoraError as w}from"@lunora/errors";import{isValidCronExpression as b}from"@lunora/scheduler";import{workflowDefaultName as E,workflowClassName as v}from"@lunora/workflow";import{Node as n,VariableDeclarationKind as S,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as L,findObjectProperty as d,stringPropertyFor as P}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{r as $}from"./handler-reference-DLDPO906.mjs";const A="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),W=o=>{const e=o.getSymbol();if(!e)return o.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(n.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},m=P("workflow"),C=(o,e,t)=>{if(n.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`workflow "${e}": \`${t}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},f=(o,e)=>{const t=d(o,e);return t&&n.isPropertyAssignment(t)?t.getInitializerOrThrow():void 0},g=(o,e,t)=>{if(n.isObjectLiteralExpression(o))return o;throw c(o,`workflow "${e}": \`${t}\` must be an inline object literal — it is deploy configuration codegen writes into wrangler.jsonc`)},D=(o,e)=>{if(!n.isArrayLiteralExpression(o)||o.getElements().length===0)throw c(o,`workflow "${e}": \`schedules\` must be a non-empty inline array of cron expression string literals`);return o.getElements().map(t=>{const r=m(t,e,"schedules[]");if(!b(r))throw c(t,`workflow "${e}": schedule "${r}" is not a valid cron expression`);return r})},I=(o,e)=>{const t={},r=f(o,"schedules");r!==void 0&&(t.schedules=D(r,e));const s=f(o,"limits");if(s!==void 0){const i=f(g(s,e,"limits"),"steps");if(i===void 0)t.limits={};else{const a=C(i,e,"limits.steps");if(!Number.isInteger(a)||a<=0)throw c(i,`workflow "${e}": \`limits.steps\` must be a positive integer (got ${String(a)})`);t.limits={steps:a}}}const l=f(o,"defaultRetention");if(l!==void 0){const i=g(l,e,"defaultRetention"),a={};for(const u of["errorRetention","successRetention"]){const p=f(i,u);p!==void 0&&(a[u]=m(p,e,`defaultRetention.${u}`))}t.defaultRetention=a}return t},O=o=>{const e=o.getExpression();if(!n.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:n.isIdentifier(t)&&t.getText()==="step"},F=o=>{if(!o)return[];const e=[];for(const t of o.getDescendantsOfKind(x.CallExpression)){if(!O(t))continue;const r=t.getArguments()[0];!r||!(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))||e.push({line:t.getStartLineNumber(),method:t.getExpression().getName(),name:r.getLiteralValue()})}return e},h=o=>{let e=o;for(;e&&(n.isAsExpression(e)||n.isSatisfiesExpression(e)||n.isParenthesizedExpression(e));)e=e.getExpression();return e},T=o=>{const e=h(o);if(e&&n.isObjectLiteralExpression(e))return e;if(!(!e||!n.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const s=n.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===S.Const?h(t.getInitializer()):void 0;if(s&&n.isObjectLiteralExpression(s))return s}},R=(o,e)=>{const t=d(o,"handler"),r=$(t,e);return r!==void 0?r:{body:t!==void 0&&n.isPropertyAssignment(t)?t.getInitializer():t}},j=(o,e,t)=>{const r=T(o.getArguments()[0]);if(!r)throw c(o,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const s=R(r,t),l={className:v(e),exportName:e,name:E(e),steps:F(s.body),...s.file===void 0?{}:{handlerFile:s.file},...s.site===void 0?{}:{handlerSite:s.site}},i=d(r,"name");return i&&n.isPropertyAssignment(i)&&(l.name=m(i.getInitializerOrThrow(),e,"name")),{...l,...I(r,e)}},K=(o,e)=>{const t=[];for(const r of o.getVariableDeclarations()){if(!r.isExported())continue;const s=L(r.getInitializer());if(!s)continue;const l=s.getExpression();if(!n.isIdentifier(l)||!W(l))continue;const i=r.getNameNode();if(!n.isIdentifier(i))throw c(i,"defineWorkflow exports must be plain named exports (no destructuring)");t.push(j(s,i.getText(),e))}return t},V=o=>{const e=new Map,t=new Map;for(const r of o){const s=e.get(r.name);if(s!==void 0)throw new w("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${r.name}": produced by both "${s}" and "${r.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(r.name,r.exportName);const l=t.get(r.className);if(l!==void 0)throw new w("DUPLICATE_WORKFLOW_CLASS",`Duplicate workflow class "${r.className}": produced by both "${l}" and "${r.exportName}". Workflow export names must yield unique generated class names.`,{status:500});t.set(r.className,r.exportName)}},Q=(o,e)=>{const t=y(e,A);if(!k(t))return[];const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),s=K(r,e);return s.sort((l,i)=>l.exportName.localeCompare(i.exportName)),V(s),s};export{A as WORKFLOWS_FILENAME,Q as discoverWorkflows};
@@ -0,0 +1 @@
1
+ import{callSiteCallers as x}from"@lunora/advisor";import{Node as a,SyntaxKind as u,ts as b}from"ts-morph";const m=new WeakMap,y=t=>t.getStatements().flatMap(o=>a.isFunctionDeclaration(o)?[o]:a.isVariableStatement(o)?o.getDeclarations().filter(e=>a.isIdentifier(e.getNameNode())):[]),S=t=>a.isFunctionDeclaration(t)?t.hasExportKeyword()?t.hasDefaultKeyword()?"default":t.getName()??"default":void 0:t.getVariableStatement()?.hasExportKeyword()===!0?t.getName():void 0,v=t=>t.getStatements().flatMap(o=>{if(a.isExportDeclaration(o)&&!o.hasModuleSpecifier()&&!o.isTypeOnly())return o.getNamedExports().map(n=>[n.getNameNode().getText(),n.getAliasNode()?.getText()??n.getName()]);const e=a.isExportAssignment(o)&&!o.isExportEquals()?o.getExpression():void 0;return e!==void 0&&a.isIdentifier(e)?[[e.getText(),"default"]]:[]}),k=(t,o)=>{const e=new Map(o.map(i=>[i.getName(),i])),n=new Map,r=(i,c)=>{if(i===void 0||c===void 0)return;const s=n.get(i.compilerNode);(s===void 0||c<s)&&n.set(i.compilerNode,c)};for(const i of o)r(i,S(i));for(const[i,c]of v(t))r(e.get(i),c);return n},g=(t,o)=>{for(const e of t.getAncestors()){if(a.isExportAssignment(e)&&!e.isExportEquals())return{kind:"export",name:"default"};if((a.isFunctionDeclaration(e)&&a.isSourceFile(e.getParent())||a.isVariableDeclaration(e)&&a.isSourceFile(e.getVariableStatement()?.getParent())&&a.isIdentifier(e.getNameNode()))&&(a.isFunctionDeclaration(e)||a.isVariableDeclaration(e))){const r=o.get(e.compilerNode);return r===void 0?{declaration:e,kind:"helper"}:{kind:"export",name:r}}}return{kind:"untracked"}},w=t=>{for(const o of t.getAncestors()){if(a.isExpressionWithTypeArguments(o)){const e=o.getParent();return!(a.isHeritageClause(e)&&e.getToken()===u.ExtendsKeyword&&(a.isClassDeclaration(e.getParent())||a.isClassExpression(e.getParent())))}if(b.isTypeNode(o.compilerNode))return!0}return!1},E=t=>{const o=t.getParent();return a.isShorthandPropertyAssignment(o)&&o.getNameNode()===t?o.getValueSymbol():t.getSymbol()},D=t=>{const o=new Map,e=new Set,n=new Set;for(const r of t){const i=r.getNameNode(),c=i?.getSymbol()?.compilerSymbol;i!==void 0&&c!==void 0&&(o.set(c,r.compilerNode),e.add(i.compilerNode),n.add(i.getText()))}return{bySymbol:o,nameNodes:e,spellings:n}},O=(t,o,e)=>{const{bySymbol:n,nameNodes:r,spellings:i}=D(o),c=new Map;for(const s of t.getDescendantsOfKind(u.Identifier)){if(!i.has(s.getText())||r.has(s.compilerNode)||w(s))continue;const l=E(s)?.compilerSymbol,d=l===void 0?void 0:n.get(l);d!==void 0&&c.set(d,[...c.get(d)??[],g(s,e)])}return c},M=(t,o)=>{const e=new Map(t.map(s=>[s.compilerNode,new Set])),n=new Set,r=s=>(e.get(s)?.size??0)+(n.has(s)?1:0),i=(s,l)=>{const d=r(s),p=e.get(s),f=l.kind==="helper"?l.declaration.compilerNode:void 0;l.kind==="export"&&p?.add(l.name);for(const h of f===void 0?[]:e.get(f)??[])p?.add(h);return(l.kind==="untracked"||f!==void 0&&n.has(f))&&n.add(s),r(s)!==d};let c=!0;for(;c;){c=!1;for(const[s,l]of o)for(const d of l)c=i(s,d)||c}return new Map([...e].map(([s,l])=>[s,{callers:[...l].toSorted((d,p)=>d.localeCompare(p)),untracked:n.has(s)}]))},N=t=>{const o=m.get(t.compilerNode);if(o!==void 0)return o;const e=y(t),n=k(t,e),r=e.filter(c=>!n.has(c.compilerNode)),i={exportNames:n,helperReach:r.length===0?new Map:M(r,O(t,r,n))};return m.set(t.compilerNode,i),i},A=t=>{const o=N(t.getSourceFile()),e=g(t,o.exportNames);switch(e.kind){case"export":return{kind:"export",name:e.name};case"helper":{const n=e.declaration.getName(),r=o.helperReach.get(e.declaration.compilerNode);if(n===void 0||r===void 0)throw new Error(`call-site attribution: helper at ${e.declaration.getSourceFile().getFilePath()} is not indexed`);return{callers:r.callers,kind:"helper",name:n,...r.untracked?{untracked:!0}:{}}}default:return{kind:"module"}}},T=(t,o)=>{const e=x(t).map(r=>o(r));return e.includes("public")?"public":e.length===0||e.includes(void 0)||t.kind==="helper"&&t.untracked===!0?void 0:"internal"},V=(t,o)=>{const e=new Map(o.map(n=>[`${n.filePath}:${n.exportName}`,n.visibility]));return t.map(n=>{const r=T(n.scope,i=>e.get(`${n.file}:${i}`));return r===void 0?n:{...n,visibility:r}})},K=t=>N(t.getSourceFile()).exportNames.get(t.compilerNode);export{A as c,K as e,E as r,V as w};
@@ -1,3 +1,3 @@
1
- import{m as b}from"./modules-DyCocr1e.mjs";import{r as E}from"./json-data-Chfs2Cz5.mjs";import{s as l}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as P,objectSchema as g,validatorIrToJsonSchema as m}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{G as A}from"./shared-DjUziztz.mjs";const T="/_lunora/rest",x=["authorization","cf-access-jwt-assertion","cookie","payment-signature","x-payment"],v=["x-d1-bookmark","x-lunora-shard-key"],j=e=>[...x,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],O=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,$=(...e)=>{const t=[];for(const r of e)for(const n of r?.split(",")??[]){const s=n.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},k=(e,t)=>{const r=[t,`max-age=${String(O(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(O(e.staleWhileRevalidate))}`),r.join(", ")},N=e=>e.scope==="public"?$(e.vary,...j(e),...v):$(e.vary,...v),q=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},_=e=>{const t=q(e);if(t!==void 0)return`${T}/${t.namespace}/${t.name}`},C=e=>e==="query"?"GET":"POST",y="#/components/responses/LunoraError",R=/:([A-Za-z_$][\w$]*)/gu,w=e=>[...e.matchAll(R)].map(t=>t[1]),D=e=>e.replaceAll(R,"{$1}"),f=e=>e.kind==="optional"?e.inner??e:e,I=e=>{const t=new Set(w(e.path)),r=[];for(const[n,s]of Object.entries(e.searchParams)){const c=f(s);r.push({description:`Query parameter \`${n}\``,in:"query",name:n,required:s.kind!=="optional",schema:m(c)})}for(const[n,s]of Object.entries(e.params)){const c=f(s);r.push({description:`Path parameter \`${n}\``,in:t.has(n)?"path":"query",name:n,required:t.has(n)?!0:s.kind!=="optional",schema:m(c)})}return r},S=e=>e?{content:{"application/json":{schema:m(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},L=(e,t)=>{const r=I(e),n={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${l(e.path)}`,responses:{200:S(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:y}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(n.parameters=r),Object.keys(e.body).length>0&&(n.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(n["x-lunora-stream"]="text/event-stream"),n},F=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n={additionalProperties:!1,properties:{args:g(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:n}},required:!0},responses:{200:S(e.output),default:{$ref:y}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},H=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},n={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:k(r,r.scope),type:"string"}}};r.tag!==void 0&&(n["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=N(r);return s!==void 0&&(n.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:n}},M=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n=_(r);if(n===void 0)return;const s=C(e.kind),c=s==="GET",i={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${l(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...H(e.expose?.cache,c?"get":"post")},default:{$ref:y}},summary:`${s} ${n}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const d=Object.entries(e.args).map(([u,h])=>{const o=f(h);return{description:`Argument \`${u}\` (JSON-encoded for non-string values).`,in:"query",name:u,required:h.kind!=="optional",schema:m(o)}});return d.length>0&&(i.parameters=d),{method:"get",operation:i,path:n}}return i.requestBody={content:{"application/json":{schema:g(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:i,path:n}},J=e=>{const t=e.version??"0.0.0",r=Object.create(null),n=o=>r[o]??Object.create(null),s=new Set,c=e.modules??[],i=o=>b(c,o);for(const o of e.httpRoutes){const a=D(o.path),p=n(a);p[o.method.toLowerCase()]=L(o,i(o.filePath)),r[a]=p,s.add(i(o.filePath))}const d=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream");for(const o of d){const{operation:a,pathKey:p}=F(o,i(o.filePath));r[p]={post:a},s.add(i(o.filePath))}for(const o of d){if(o.expose?.rest!==!0)continue;const a=M(o,i(o.filePath));if(a===void 0)continue;const p=n(a.path);p[a.method]=a.operation,r[a.path]=p}const u=[...s].toSorted((o,a)=>o.localeCompare(a)).map(o=>({description:c.find(p=>p.name===o)?.description??`Operations declared in \`lunora/${o}\`.`,name:o}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:P,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:Object.fromEntries(Object.entries(r).map(([o,a])=>[o,{...a}])),tags:u}},z=e=>`${JSON.stringify(J(e),void 0,2)}
1
+ import{m as b}from"./modules-B7lb5-dN.mjs";import{r as E}from"./json-data-Chfs2Cz5.mjs";import{s as l}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as P,objectSchema as g,validatorIrToJsonSchema as m}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{G as A}from"./shared-DjUziztz.mjs";const T="/_lunora/rest",x=["authorization","cf-access-jwt-assertion","cookie","payment-signature","x-payment"],v=["x-d1-bookmark","x-lunora-shard-key"],j=e=>[...x,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],O=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,$=(...e)=>{const t=[];for(const r of e)for(const n of r?.split(",")??[]){const s=n.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},k=(e,t)=>{const r=[t,`max-age=${String(O(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(O(e.staleWhileRevalidate))}`),r.join(", ")},N=e=>e.scope==="public"?$(e.vary,...j(e),...v):$(e.vary,...v),q=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},_=e=>{const t=q(e);if(t!==void 0)return`${T}/${t.namespace}/${t.name}`},C=e=>e==="query"?"GET":"POST",y="#/components/responses/LunoraError",R=/:([A-Za-z_$][\w$]*)/gu,w=e=>[...e.matchAll(R)].map(t=>t[1]),D=e=>e.replaceAll(R,"{$1}"),f=e=>e.kind==="optional"?e.inner??e:e,I=e=>{const t=new Set(w(e.path)),r=[];for(const[n,s]of Object.entries(e.searchParams)){const c=f(s);r.push({description:`Query parameter \`${n}\``,in:"query",name:n,required:s.kind!=="optional",schema:m(c)})}for(const[n,s]of Object.entries(e.params)){const c=f(s);r.push({description:`Path parameter \`${n}\``,in:t.has(n)?"path":"query",name:n,required:t.has(n)?!0:s.kind!=="optional",schema:m(c)})}return r},S=e=>e?{content:{"application/json":{schema:m(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},L=(e,t)=>{const r=I(e),n={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${l(e.path)}`,responses:{200:S(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:y}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(n.parameters=r),Object.keys(e.body).length>0&&(n.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(n["x-lunora-stream"]="text/event-stream"),n},F=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n={additionalProperties:!1,properties:{args:g(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:n}},required:!0},responses:{200:S(e.output),default:{$ref:y}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},H=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},n={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:k(r,r.scope),type:"string"}}};r.tag!==void 0&&(n["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=N(r);return s!==void 0&&(n.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:n}},M=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n=_(r);if(n===void 0)return;const s=C(e.kind),c=s==="GET",i={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${l(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...H(e.expose?.cache,c?"get":"post")},default:{$ref:y}},summary:`${s} ${n}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const d=Object.entries(e.args).map(([u,h])=>{const o=f(h);return{description:`Argument \`${u}\` (JSON-encoded for non-string values).`,in:"query",name:u,required:h.kind!=="optional",schema:m(o)}});return d.length>0&&(i.parameters=d),{method:"get",operation:i,path:n}}return i.requestBody={content:{"application/json":{schema:g(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:i,path:n}},J=e=>{const t=e.version??"0.0.0",r=Object.create(null),n=o=>r[o]??Object.create(null),s=new Set,c=e.modules??[],i=o=>b(c,o);for(const o of e.httpRoutes){const a=D(o.path),p=n(a);p[o.method.toLowerCase()]=L(o,i(o.filePath)),r[a]=p,s.add(i(o.filePath))}const d=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream");for(const o of d){const{operation:a,pathKey:p}=F(o,i(o.filePath));r[p]={post:a},s.add(i(o.filePath))}for(const o of d){if(o.expose?.rest!==!0)continue;const a=M(o,i(o.filePath));if(a===void 0)continue;const p=n(a.path);p[a.method]=a.operation,r[a.path]=p}const u=[...s].toSorted((o,a)=>o.localeCompare(a)).map(o=>({description:c.find(p=>p.name===o)?.description??`Operations declared in \`lunora/${o}\`.`,name:o}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:P,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:Object.fromEntries(Object.entries(r).map(([o,a])=>[o,{...a}])),tags:u}},z=e=>`${JSON.stringify(J(e),void 0,2)}
2
2
  `,K=e=>`${A}export const openApiSpec = ${E(e,"Record<string, unknown>")};
3
3
  `;export{J as buildOpenApiDocument,z as emitOpenApi,K as emitOpenApiModule};
@@ -1 +1 @@
1
- import{SyntaxKind as c,Node as r}from"ts-morph";import{CAPABILITIES as f}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{bindingKeyName as p,listLunoraSourceFiles as g}from"./listLunoraSourceFiles-CSlcBYlo.mjs";import{scanImportDeclaration as u,noSandboxUsage as l}from"./discoverSandboxUsage-DC6q7rZy.mjs";const d="ctx",x=e=>{const t=new Set,n=new Set([d]),s=o=>{if(r.isObjectBindingPattern(o))for(const i of o.getElements()){const m=p(i);m&&t.add(m)}};for(const o of e.getDescendantsOfKind(c.BindingElement)){if(p(o)!==d)continue;const i=o.getNameNode();r.isIdentifier(i)?n.add(i.getText()):s(i)}const a=o=>r.isIdentifier(o)&&n.has(o.getText());for(const o of e.getDescendantsOfKind(c.PropertyAccessExpression))a(o.getExpression())&&t.add(o.getName());for(const o of e.getDescendantsOfKind(c.VariableDeclaration)){const i=o.getInitializer();i!==void 0&&a(i)&&s(o.getNameNode())}return t},E=e=>{if(e.isTypeOnly())return!0;if(r.isExportDeclaration(e)){const n=e.getNamedExports();return!e.isNamespaceExport()&&n.length>0&&n.every(s=>s.isTypeOnly())}const t=e.getNamedImports();return e.getDefaultImport()===void 0&&e.getNamespaceImport()===void 0&&t.length>0&&t.every(n=>n.isTypeOnly())},S=e=>{const t=new Set;for(const n of e.getDescendantsOfKind(c.CallExpression)){const[s]=n.getArguments();n.getExpression().getKind()===c.ImportKeyword&&(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s))&&t.add(s.getLiteralValue())}return t},y=e=>{const t=e.getImportDeclarations(),n=l();for(const s of t){const a=u(s);for(const o of Object.keys(n))n[o]||=a[o]}return{contextReads:x(e),dynamicImports:S(e),sandboxTools:n,valueImports:new Set([...t,...e.getExportDeclarations()].flatMap(s=>{const a=s.getModuleSpecifierValue();return a===void 0||E(s)?[]:[a]}))}},T=e=>{const t=new Set,n=new Set,s=l(),a=new Set;for(const o of e){for(const i of o.contextReads)t.add(i);for(const i of o.dynamicImports)n.add(i);for(const i of o.valueImports)a.add(i);for(const i of Object.keys(s))s[i]||=o.sandboxTools[i]}return{contextReads:t,dynamicImports:n,sandboxTools:s,valueImports:a}},I=e=>new Set(f.filter(({contextProperty:t,moduleSpecifier:n})=>e.valueImports.has(n)||t!==void 0&&e.contextReads.has(t)).map(({key:t})=>t)),N=new RegExp(String.raw`\b${d}\b`,"u"),b=new RegExp(String.raw`\b(?:${f.flatMap(({contextProperty:e})=>e===void 0?[]:[e]).join("|")})\b`,"u"),C=e=>N.test(e)&&b.test(e),D=(e,t)=>{const n=T(g(t).map(a=>y(e.getSourceFile(a)??e.addSourceFileAtPath(a)))),s=I(n);return Object.fromEntries(f.map(({key:a})=>[a,s.has(a)]))};export{I as capabilitiesUsedBy,x as contextPropertiesRead,D as discoverFeatureUsage,T as foldCapabilitySignals,C as mayReadCapabilityContext,y as sourceCapabilitySignals};
1
+ import{SyntaxKind as c,Node as r}from"ts-morph";import{CAPABILITIES as f}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{bindingKeyName as p,listLunoraSourceFiles as g}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{scanImportDeclaration as u,noSandboxUsage as l}from"./discoverSandboxUsage-CJPFsjOS.mjs";const d="ctx",x=e=>{const t=new Set,n=new Set([d]),s=o=>{if(r.isObjectBindingPattern(o))for(const i of o.getElements()){const m=p(i);m&&t.add(m)}};for(const o of e.getDescendantsOfKind(c.BindingElement)){if(p(o)!==d)continue;const i=o.getNameNode();r.isIdentifier(i)?n.add(i.getText()):s(i)}const a=o=>r.isIdentifier(o)&&n.has(o.getText());for(const o of e.getDescendantsOfKind(c.PropertyAccessExpression))a(o.getExpression())&&t.add(o.getName());for(const o of e.getDescendantsOfKind(c.VariableDeclaration)){const i=o.getInitializer();i!==void 0&&a(i)&&s(o.getNameNode())}return t},E=e=>{if(e.isTypeOnly())return!0;if(r.isExportDeclaration(e)){const n=e.getNamedExports();return!e.isNamespaceExport()&&n.length>0&&n.every(s=>s.isTypeOnly())}const t=e.getNamedImports();return e.getDefaultImport()===void 0&&e.getNamespaceImport()===void 0&&t.length>0&&t.every(n=>n.isTypeOnly())},S=e=>{const t=new Set;for(const n of e.getDescendantsOfKind(c.CallExpression)){const[s]=n.getArguments();n.getExpression().getKind()===c.ImportKeyword&&(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s))&&t.add(s.getLiteralValue())}return t},y=e=>{const t=e.getImportDeclarations(),n=l();for(const s of t){const a=u(s);for(const o of Object.keys(n))n[o]||=a[o]}return{contextReads:x(e),dynamicImports:S(e),sandboxTools:n,valueImports:new Set([...t,...e.getExportDeclarations()].flatMap(s=>{const a=s.getModuleSpecifierValue();return a===void 0||E(s)?[]:[a]}))}},T=e=>{const t=new Set,n=new Set,s=l(),a=new Set;for(const o of e){for(const i of o.contextReads)t.add(i);for(const i of o.dynamicImports)n.add(i);for(const i of o.valueImports)a.add(i);for(const i of Object.keys(s))s[i]||=o.sandboxTools[i]}return{contextReads:t,dynamicImports:n,sandboxTools:s,valueImports:a}},I=e=>new Set(f.filter(({contextProperty:t,moduleSpecifier:n})=>e.valueImports.has(n)||t!==void 0&&e.contextReads.has(t)).map(({key:t})=>t)),N=new RegExp(String.raw`\b${d}\b`,"u"),b=new RegExp(String.raw`\b(?:${f.flatMap(({contextProperty:e})=>e===void 0?[]:[e]).join("|")})\b`,"u"),C=e=>N.test(e)&&b.test(e),D=(e,t)=>{const n=T(g(t).map(a=>y(e.getSourceFile(a)??e.addSourceFileAtPath(a)))),s=I(n);return Object.fromEntries(f.map(({key:a})=>[a,s.has(a)]))};export{I as capabilitiesUsedBy,x as contextPropertiesRead,D as discoverFeatureUsage,T as foldCapabilitySignals,C as mayReadCapabilityContext,y as sourceCapabilitySignals};
@@ -0,0 +1 @@
1
+ import{w as a}from"./classify-procedure-call-DcsbRyEV.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-CSlcBYlo.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const A=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},h=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,x=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&h(r.getExpression(),e)),w=(t,i)=>f(t).some(e=>e.name===i),P=(t,i,e)=>x(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},N={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper"},I=t=>t==="whisper"?"query":"mutation",C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},D=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=N[e];if(n)return{kind:I(n),lifecycle:n,visibility:"internal"}};export{A as a,f as b,D as c,P as d,w as e,x as w};
1
+ import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const A=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},h=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,x=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&h(r.getExpression(),e)),w=(t,i)=>f(t).some(e=>e.name===i),P=(t,i,e)=>x(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},N={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper"},I=t=>t==="whisper"?"query":"mutation",C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},D=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=N[e];if(n)return{kind:I(n),lifecycle:n,visibility:"internal"}};export{A as a,f as b,D as c,P as d,w as e,x as w};
@@ -1 +1 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-CSlcBYlo.mjs";import{c as u}from"./classify-procedure-call-CmcShAze.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{c as u}from"./classify-procedure-call-DcsbRyEV.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
@@ -0,0 +1 @@
1
+ import{Node as t}from"ts-morph";import{collectCallRows as n,propertyKeyName as p}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{c as a}from"./attribution-DpIyvmtn.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};