@lunora/codegen 1.0.0-alpha.131 → 1.0.0-alpha.133

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 (22) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/{GENERATED_HEADER-NWWDWOX4.mjs → GENERATED_HEADER-etEAWhHs.mjs} +1 -1
  3. package/dist/packem_shared/{MUTATORS_FILENAME-DJerSBO-.mjs → MUTATORS_FILENAME-cczs0N_f.mjs} +1 -1
  4. package/dist/packem_shared/{NOTIFY_FILENAME-CPg7zlsb.mjs → NOTIFY_FILENAME-3hraPVOT.mjs} +1 -1
  5. package/dist/packem_shared/{OPENRPC_VERSION-6XrIwoNr.mjs → OPENRPC_VERSION-l-E_pTg8.mjs} +1 -1
  6. package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME--CCXsODJ.mjs → SCHEMA_SNAPSHOT_FILENAME-DNjZUvv7.mjs} +1 -1
  7. package/dist/packem_shared/{SHAPES_FILENAME-DTp6VI6K.mjs → SHAPES_FILENAME-BTdasTq2.mjs} +1 -1
  8. package/dist/packem_shared/{buildOpenApiDocument-DDvSUMD9.mjs → buildOpenApiDocument-DBUr_qe5.mjs} +1 -1
  9. package/dist/packem_shared/discoverFunctions-5SwUVBO6.mjs +1 -0
  10. package/dist/packem_shared/{discoverHttpRoutes-BkwEwmK0.mjs → discoverHttpRoutes-oVY4IQQz.mjs} +1 -1
  11. package/dist/packem_shared/{discoverMaskProcedures-DExWLcsu.mjs → discoverMaskProcedures-BbiYrDLQ.mjs} +1 -1
  12. package/dist/packem_shared/{discoverNondeterministicCalls-xRw6-4OU.mjs → discoverNondeterministicCalls-BcWKCkrg.mjs} +1 -1
  13. package/dist/packem_shared/{discoverR2sqlCalls-Ciq0-bVB.mjs → discoverR2sqlCalls-Dy7i757M.mjs} +1 -1
  14. package/dist/packem_shared/{discoverRlsMetadata-Bnn3zDlc.mjs → discoverRlsMetadata-BqCbCx8m.mjs} +1 -1
  15. package/dist/packem_shared/{discoverSchema-gJ93Xjpx.mjs → discoverSchema-Hsu_1xIc.mjs} +1 -1
  16. package/dist/packem_shared/{discoverStorageRulesMetadata-DYAgRSL6.mjs → discoverStorageRulesMetadata-Demj7Q4c.mjs} +1 -1
  17. package/dist/packem_shared/{emit-GW3Jf9w0.mjs → emit-DBZKVUBi.mjs} +130 -130
  18. package/dist/packem_shared/{emitApp-D-mz_p6P.mjs → emitApp-wqZEBJxy.mjs} +1 -1
  19. package/dist/packem_shared/parse-validator-BFTp87yz.mjs +1 -0
  20. package/package.json +3 -3
  21. package/dist/packem_shared/discoverFunctions-CYHtspcp.mjs +0 -1
  22. package/dist/packem_shared/parse-validator-C5ycrhR3.mjs +0 -1
@@ -1,4 +1,4 @@
1
- import{A as S,G as D}from"./emit-GW3Jf9w0.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,v=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),m=e=>v.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],R=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],x=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],C=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,O=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],T=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=e=>{const{hasAccess:t,hasAuth:a,hasFramework:r,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:c,hasQueue:s,hasScheduler:d,hasStorage:h,hasWorkflow:u,useUmbrella:l,wantsOpenApi:p,wantsOpenRpc:b}=e,i=l?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","HttpRouterLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector","AdminTableResolver"),r&&g.push("FrameworkHostHandler");const w=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...r?["withFrameworkWorker"]:[]].join(", ");return[...a?['import type { AuthNamespaceLike, LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...R(t,a),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { applyCdcChanges, createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, listGlobalTables, readD1CdcChanges, readGlobalTablePage, retryingExec } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...x(c),...d?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...h?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...u?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...O(e),`import type { ${[...g].toSorted((f,y)=>f.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${w} } from "${i}";`,"",...A(e.identity),...T(e),...n||o?['import schema from "../schema.js";']:[],...C(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},q=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
1
+ import{A as S,G as D}from"./emit-DBZKVUBi.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,v=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),m=e=>v.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],R=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],x=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],C=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,O=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],T=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=e=>{const{hasAccess:t,hasAuth:a,hasFramework:r,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:c,hasQueue:s,hasScheduler:d,hasStorage:h,hasWorkflow:u,useUmbrella:l,wantsOpenApi:p,wantsOpenRpc:b}=e,i=l?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","HttpRouterLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector","AdminTableResolver"),r&&g.push("FrameworkHostHandler");const w=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...r?["withFrameworkWorker"]:[]].join(", ");return[...a?['import type { AuthNamespaceLike, LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...R(t,a),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { applyCdcChanges, createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, listGlobalTables, readD1CdcChanges, readGlobalTablePage, retryingExec } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...x(c),...d?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...h?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...u?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...O(e),`import type { ${[...g].toSorted((f,y)=>f.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${w} } from "${i}";`,"",...A(e.identity),...T(e),...n||o?['import schema from "../schema.js";']:[],...C(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},q=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
2
2
  interface StorageDeclaration<Env> {
3
3
  /** The default R2 bucket binding (the bare \`ctx.storage\`). */
4
4
  bucket: Selector<Env, R2BucketLike>;
@@ -0,0 +1 @@
1
+ import{LunoraError as p}from"@lunora/errors";import{Node as i}from"ts-morph";import{diagnosticAt as m}from"./CodegenDiagnosticError-BUXlG3P-.mjs";let d;const R=e=>{d=e},y=/^[A-Za-z_$][\w$]*$/u,f=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),k=(e,r)=>{const t={notNull:!0,...e.column};switch(r){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{t.hasDefault=!0;break}case"$onUpdateFn":{t.hasOnUpdate=!0;break}case"$type":break;case"nullable":{t.notNull=!1;break}case"unique":{t.unique=!0;break}}return{...e,column:t}},b=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),g=new Set(["check","email","int","length","max","min","pattern","positive","url"]),N=new Set(["meta"]),c=new Set,S=e=>{const r=e.getSymbol();let t=(r?.getAliasedSymbol()??r)?.getValueDeclaration();if(t!==void 0&&i.isShorthandPropertyAssignment(t)){const n=t.getValueSymbol();t=(n?.getAliasedSymbol()??n)?.getValueDeclaration()}if(!(t===void 0||!i.isVariableDeclaration(t)))return t.getInitializer()},E="v",h=e=>{if(i.isIdentifier(e))return!0;let r=e;for(;i.isCallExpression(r);){const t=r.getExpression();if(!i.isPropertyAccessExpression(t))return!1;r=t.getExpression()}return i.isIdentifier(r)&&r.getText()===E},o=e=>{if(i.isIdentifier(e)&&!c.has(e)){const r=S(e);if(r!==void 0&&h(r)){c.add(e);try{return o(r)}finally{c.delete(e)}}}return i.isCallExpression(e)?w(e):{kind:"any",sourceText:e.getText()}},A=e=>{const r={};for(const t of e.getProperties()){const n=i.isShorthandPropertyAssignment(t);if(!n&&!i.isPropertyAssignment(t))continue;const s=t.getNameNode();if(i.isComputedPropertyName(s))continue;const a=n?t.getNameNode():t.getInitializer();if(!a)continue;const u=t.getName();if(!y.test(u))throw new p("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(u)}`);r[u]=o(a)}return r},l=(e,r)=>e&&i.isExpression(e)?o(e):r,v=e=>e===void 0?"undefined":i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),T=e=>{const r=e&&d?d(e):void 0;return r===void 0?{kind:"from"}:{kind:"from",tsType:r}},I=(e,r,t)=>{if(b.has(e))return{kind:e};const[n,s]=r;switch(e){case"array":return{inner:l(n,{kind:"any"}),kind:"array"};case"from":return T(n);case"id":{if(!n||!i.isStringLiteral(n))throw m(n??t,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${n?n.getText():"no argument"}.`);return{kind:"id",tableName:n.getLiteralText()}}case"literal":return{kind:"literal",literalValue:v(n)};case"object":return n&&i.isObjectLiteralExpression(n)?{kind:"object",shape:A(n)}:{kind:"object",shape:{}};case"optional":return{inner:l(n,{kind:"any"}),kind:"optional"};case"record":return{keyType:l(n,{kind:"string"}),kind:"record",valueType:l(s,{kind:"any"})};case"storage":return n&&i.isStringLiteral(n)?{bucket:n.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:r.filter(a=>i.isExpression(a)).map(a=>o(a))};default:throw new p("INTERNAL",`Unsupported validator kind: ${e}`)}},w=e=>{const r=e.getExpression();if(!i.isPropertyAccessExpression(r))return{kind:"any",sourceText:e.getText()};const t=r.getName(),n=e.getArguments();if(f.has(t)||g.has(t)||N.has(t)){const s=r.getExpression(),a=i.isExpression(s)?o(s):{kind:"any"};return f.has(t)?k(a,t):g.has(t)?{...a,hasRefinement:!0}:a}return I(t,n,e)};export{A as a,o as p,R as s};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.131",
3
+ "version": "1.0.0-alpha.133",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,8 +46,8 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.94",
50
- "@lunora/agent": "1.0.0-alpha.69",
49
+ "@lunora/advisor": "1.0.0-alpha.95",
50
+ "@lunora/agent": "1.0.0-alpha.70",
51
51
  "@lunora/container": "1.0.0-alpha.35",
52
52
  "@lunora/errors": "1.0.0-alpha.24",
53
53
  "@lunora/platform": "1.0.0-alpha.18",
@@ -1 +0,0 @@
1
- import{Node as s,SyntaxKind as b}from"ts-morph";import{l as k,a as R}from"./discover-ast-D33zP-NZ.mjs";import{a as z}from"./module-specifiers-WF8iAydP.mjs";import{p as _,a as T}from"./parse-validator-C5ycrhR3.mjs";import{s as U}from"./paths-C-9fwEgQ.mjs";const m=new Set(["action","mutation","query","stream"]),N=/\bany\b(?!\s*(?:\?\s*)?:)/u,P=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,j=/^[A-Za-z_$][\w$]*$/u,$=e=>j.test(e)?e:JSON.stringify(e),S={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},M={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},V=z,h=e=>{const t=e.getSymbol();if(!t)return e.getText();const r=t.getDeclarations();for(const i of r){if(!s.isImportSpecifier(i))continue;const o=i.getImportDeclaration().getModuleSpecifierValue();return V(o)?i.getNameNode().getText():void 0}},I=(e,t=!1)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))return;r=n.getExpression()}if(!s.isIdentifier(r))return;const i=h(r);if(i===void 0){if(t)return;const n=r.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?I(o,!0):void 0}return}return m.has(i)?"public":S[i]?"internal":void 0},d=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!s.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&s.isStringLiteral(i)?i.getLiteralValue():void 0},E=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!s.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&s.isNumericLiteral(i)?i.getLiteralValue():void 0},K=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();if(r===void 0||!s.isObjectLiteralExpression(r))return;const i=d(r,"scope"),n=E(r,"maxAge"),o=E(r,"staleWhileRevalidate"),a=d(r,"tag"),c=d(r,"vary"),l={...n===void 0?{}:{maxAge:n},...i==="private"||i==="public"?{scope:i}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},B=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=K(e),r=e.getProperty("rest");return r!==void 0&&s.isPropertyAssignment(r)?{...t===void 0?{}:{cache:t},rest:r.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},H=e=>{let t=e;for(;s.isCallExpression(t);){const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;if(r.getName()==="expose")return B(t.getArguments()[0]);t=r.getExpression()}},G=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const r=t.getProperty("args");if(!r||!s.isPropertyAssignment(r))return{};const i=r.getInitializer();return!i||!s.isObjectLiteralExpression(i)?{}:T(i)},q="/_generated/",Q=(e,t,r)=>e.getImportDeclarations().some(i=>i.getModuleSpecifierSourceFile()!==t?!1:i.getNamespaceImport()!==void 0||i.getNamedImports().some(n=>n.getName()===r)),C=(e,t,r)=>{const i=e.getSourceFile();if(i.isInNodeModules()||i.isDeclarationFile()||!s.isInterfaceDeclaration(e)&&!s.isTypeAliasDeclaration(e))return!1;const n=i.getFilePath();return n.includes(q)?!1:n===r||Q(t.getSourceFile(),i,e.getName())},W=(e,t,r)=>[e.getSymbol(),e.getAliasSymbol()].flatMap(i=>i?.getDeclarations()??[]).some(i=>C(i,t,r)),X=(e,t,r)=>{const i=s.isPropertySignature(e)||s.isPropertyDeclaration(e)?e.getTypeNode():void 0;return i===void 0?!1:[i,...i.getDescendantsOfKind(b.TypeReference)].filter(n=>s.isTypeReference(n)).flatMap(n=>{const o=n.getTypeName().getSymbol();return(o?.getAliasedSymbol()??o)?.getDeclarations()??[]}).some(n=>C(n,t,r))},Y=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},F=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,g=(e,t,r,i=new Set)=>i.has(e)?!1:(i.add(e),W(e,t,r)||Y(e).some(n=>g(n,t,r,i))?!0:F(e)?e.getProperties().some(n=>n.getDeclarations().some(o=>X(o,t,r))?!0:g(n.getTypeAtLocation(t),t,r,i)):!1),J=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(s.isPropertySignature(r)||s.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(i=>i.isUndefined())},Z=8,ee=(e,t,r,i,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,r,i,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},te=(e,t,r,i,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,r,i,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},re=(e,t,r,i,n,o)=>{if(!F(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),y=J(c,l),w=y&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],v=[];for(const f of w){const x=o(f,t,r,i+1,n);if(x===void 0)return;v.push(x)}a.push(`${$(c.getName())}${y?"?":""}: ${v.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},p=(e,t,r,i,n)=>{if(i>Z||n.has(e))return;if(!g(e,t,r))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?ee(e,t,r,i,o,p):e.isUnion()?te(e,t,r,i,o,p):re(e,t,r,i,o,p)},D=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const n=(r.getSymbol()??r.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=r.getTypeArguments()[0];c&&(r=c)}const o=r.getText(e);if(!o||o==="any"||o==="never"||N.test(o.replaceAll(P,"")))return"unknown";const a=e.getSourceFile().getFilePath();return g(r,e,a)?p(r,e,a,0,new Set)??"unknown":o},Ae=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const r=t.getTypeAtLocation(e).getProperty("types");if(!r)return;const i=r.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!i)return;const n=i.getTypeAtLocation(e),o=n.getText(e);if(!o||o==="any"||o==="never"||N.test(o.replaceAll(P,"")))return;const a=e.getSourceFile().getFilePath();return g(n,e,a)?p(n,e,a,0,new Set):o},ie=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const r=t.getProperty("handler");if(!r||!s.isPropertyAssignment(r))return"unknown";const i=r.getInitializer();return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":D(i)},ne=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":D(t)},se=e=>{let t={},r=e;for(;s.isCallExpression(r);){const i=r.getExpression();if(!s.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const n=r.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...T(n),...t})}r=i.getExpression()}return t},oe=e=>{let t=e;for(;s.isCallExpression(t);){const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;if(r.getName()==="output"){const i=t.getArguments()[0];return i&&s.isExpression(i)?_(i):void 0}t=r.getExpression()}},ae=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!m.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=I(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const r=h(t);if(!r)return;if(m.has(r))return{kind:r,visibility:"public"};const i=S[r];if(i)return{kind:i,visibility:"internal"};const n=M[r];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},A=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,be=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Te=e=>{const t=e.getArguments()[0],r=A(t);if(r!==void 0)return r;if(t===void 0||!s.isObjectLiteralExpression(t))return;const i=t.getProperty("handler");return i!==void 0&&s.isPropertyAssignment(i)?A(i.getInitializer()):void 0},ce=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Ne=(e,t)=>{let r=e;for(;s.isCallExpression(r);){const i=r.getExpression();if(!s.isPropertyAccessExpression(i))break;if(i.getName()===t)return!0;r=i.getExpression()}return!1},Pe=(e,t,r)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=i.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&ce(o.getExpression())===r)return!0;i=n.getExpression()}return!1},le=e=>{const t=ae(e);if(t){if(t.receiver){const r=H(t.receiver),i=oe(t.receiver);return{args:se(t.receiver),...r?{expose:r}:{},kind:t.kind,...i?{output:i}:{},returnType:ne(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:G(e),kind:t.kind,returnType:ie(e),visibility:t.visibility}}},ue=8,u=(e,t=0)=>{if(t>ue)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const r=e.getSymbol()?.getValueDeclaration();return r?O(r,t+1):void 0},O=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const r=e.getInitializer();return r?u(r,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const r=e.getPropertyNameNode()?.getText()??e.getName(),o=e.getFirstAncestorByKind(b.VariableDeclaration)?.getInitializer()?.getType().getProperty(r)?.getValueDeclaration();return o?O(o,t+1):void 0}},pe=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const r=e.getInitializer(),i=r&&(s.isCallExpression(r)?r:u(r));return i?[[e.getName(),i]]:[]},L=(e,t,r)=>{const i=le(e);if(i)return{args:i.args,exportName:t,filePath:r,kind:i.kind,returnType:i.returnType,...i.output?{output:i.output}:{},visibility:i.visibility,...i.expose?{expose:i.expose}:{},...i.lifecycle?{lifecycle:i.lifecycle}:{}}},ge=(e,t)=>{const r=[];for(const i of e.getExportAssignments()){if(i.isExportEquals())continue;const n=u(i.getExpression()),o=n?L(n,"default",t):void 0;o&&r.push(o)}return r},fe=(e,t)=>{const r=[];for(const i of e.getVariableStatements())if(i.isExported())for(const n of i.getDeclarations())for(const[o,a]of pe(n)){const c=L(a,o,t);c&&r.push(c)}return r.push(...ge(e,t)),r},de=e=>{const t=new Map;for(const r of e){const i=U(r.filePath),n=t.get(i);if(n&&n!==r.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${r.filePath}" both resolve to "${i}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,r.filePath],status:500});t.set(i,r.filePath)}},Se=(e,t)=>{const r=k(t),i=[];for(const n of r){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=R(t,n);i.push(...fe(o,a))}return i.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),de(i),i};export{Ne as chainHasStep,Pe as chainUsesWrappedCall,ae as classifyProcedureCall,Se as discoverFunctions,A as inlineHandler,be as isDatabaseAccessor,k as listLunoraSourceFiles,R as lunoraRelativePath,Te as procedureHandler,Ae as resolveStandardSchemaType,D as unwrapHandlerReturn};
@@ -1 +0,0 @@
1
- import{LunoraError as g}from"@lunora/errors";import{Node as i}from"ts-morph";import{diagnosticAt as p}from"./CodegenDiagnosticError-BUXlG3P-.mjs";let d;const R=e=>{d=e},y=/^[A-Za-z_$][\w$]*$/u,f=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","unique"]),m=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},k=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),N=new Set(["check","meta"]),u=new Set,b=e=>{const t=e.getSymbol(),r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(!(r===void 0||!i.isVariableDeclaration(r)))return r.getInitializer()},E="v",S=e=>{if(i.isIdentifier(e))return!0;let t=e;for(;i.isCallExpression(t);){const r=t.getExpression();if(!i.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return i.isIdentifier(t)&&t.getText()===E},o=e=>{if(i.isIdentifier(e)&&!u.has(e)){const t=b(e);if(t!==void 0&&S(t)){u.add(e);try{return o(t)}finally{u.delete(e)}}}return i.isCallExpression(e)?L(e):{kind:"any",sourceText:e.getText()}},h=e=>{const t={};for(const r of e.getProperties()){const n=i.isShorthandPropertyAssignment(r);if(!n&&!i.isPropertyAssignment(r))continue;const s=r.getNameNode();if(i.isComputedPropertyName(s))continue;const a=n?r.getNameNode():r.getInitializer();if(!a)continue;const c=r.getName();if(!y.test(c))throw new g("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(c)}`);t[c]=o(a)}return t},l=(e,t)=>e&&i.isExpression(e)?o(e):t,A=e=>e===void 0?"undefined":i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),T=e=>{const t=e&&d?d(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},v=(e,t,r)=>{if(k.has(e))return{kind:e};const[n,s]=t;switch(e){case"array":return{inner:l(n,{kind:"any"}),kind:"array"};case"from":return T(n);case"id":{if(!n||!i.isStringLiteral(n))throw p(n??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${n?n.getText():"no argument"}.`);return{kind:"id",tableName:n.getLiteralText()}}case"literal":return{kind:"literal",literalValue:A(n)};case"object":return n&&i.isObjectLiteralExpression(n)?{kind:"object",shape:h(n)}:{kind:"object",shape:{}};case"optional":return{inner:l(n,{kind:"any"}),kind:"optional"};case"record":return{keyType:l(n,{kind:"string"}),kind:"record",valueType:l(s,{kind:"any"})};case"storage":return n&&i.isStringLiteral(n)?{bucket:n.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(a=>i.isExpression(a)).map(a=>o(a))};default:throw new g("INTERNAL",`Unsupported validator kind: ${e}`)}},L=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),n=e.getArguments();if(f.has(r)||N.has(r)){const s=t.getExpression(),a=i.isExpression(s)?o(s):{kind:"any"};return f.has(r)?m(a,r):r==="check"?{...a,hasRefinement:!0}:a}return v(r,n,e)};export{h as a,o as p,R as s};