@lunora/codegen 1.0.0-alpha.385 → 1.0.0-alpha.387

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as i,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{formatAdvisories as f,lintSchema as m,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-DKYJ2K4t.mjs";import{CodegenDiagnosticError as A,diagnosticAt as v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as C,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-5mDMAMWy.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-JdN4KXhV.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-DZMYREsq.mjs";import{CONTAINERS_FILENAME as F,discoverContainers as L}from"./packem_shared/CONTAINERS_FILENAME-BJYrxnq2.mjs";import{default as P}from"./packem_shared/discoverCrons-D-vJXsgx.mjs";import{capabilitiesUsedBy as b,createTargetScope as y,foldCapabilitySignals as U,mayReadCapabilityContext as G,sourceCapabilitySignals as H}from"./packem_shared/capabilitiesUsedBy-CN8HACEL.mjs";import{FLAGS_FILENAME as B,discoverFlags as k}from"./packem_shared/FLAGS_FILENAME-BEMyglH0.mjs";import{d as K}from"./packem_shared/index-o449rQLQ.mjs";import{default as z}from"./packem_shared/discoverHttpRoutes-D9Q0lBBb.mjs";import{default as q}from"./packem_shared/discoverHyperdriveCalls-DlyCZKX3.mjs";import{default as J}from"./packem_shared/discoverInserts-7Xdawmuk.mjs";import{d as X}from"./packem_shared/index-CNI4vSyc.mjs";import{default as $}from"./packem_shared/discoverMigrations-C649uAWL.mjs";import{MUTATORS_FILENAME as re,discoverMutators as oe}from"./packem_shared/MUTATORS_FILENAME-D9WbOFm7.mjs";import{default as ie}from"./packem_shared/discoverNondeterministicCalls-DQgVTcLv.mjs";import{NOTIFY_FILENAME as se,discoverNotifyCalls as fe,discoverNotifyChannels as me,discoverNotifyConfig as de}from"./packem_shared/NOTIFY_FILENAME-CRU_TEKs.mjs";import{default as ne}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-C75OdGHl.mjs";import{QUEUES_FILENAME as Se,discoverQueues as Ee}from"./packem_shared/QUEUES_FILENAME-BeGwgqcw.mjs";import{default as Ae}from"./packem_shared/discoverR2sqlCalls-BrDIti5c.mjs";import{default as ge}from"./packem_shared/discoverRlsProcedures-BiyDg2ej.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-DqZpiGts.mjs";import{discoverSandboxUsage as Re}from"./packem_shared/discoverSandboxUsage-CdGRnVU2.mjs";import{default as he}from"./packem_shared/discoverSchema-Bs5JUiOE.mjs";import{readServiceBindings as _e,resolveServiceBindings as Fe}from"./packem_shared/readServiceBindings-BA49C6aN.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Pe}from"./packem_shared/SHAPES_FILENAME-D9beIrs1.mjs";import{default as be}from"./packem_shared/discoverStorageRulesMetadata-H3RJzkH_.mjs";import{WORKFLOWS_FILENAME as Ue,discoverWorkflows as Ge}from"./packem_shared/WORKFLOWS_FILENAME--RWiu_Vy.mjs";import{emitApp as je}from"./packem_shared/emitApp-L7PnfjJK.mjs";import{isD1GlobalTable as ke,isHyperdriveGlobalTable as We}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ve,emitOpenApi as ze,emitOpenApiModule as Qe}from"./packem_shared/buildOpenApiDocument-67-fasdW.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as Je,emitOpenRpc as Ye,emitOpenRpcModule as Xe}from"./packem_shared/OPENRPC_VERSION-CT_E2DcI.mjs";import{DEFAULT_TARGET as $e,platformMatrixIds as er,readProjectTarget as rr,resolveCodegenTarget as or}from"./packem_shared/DEFAULT_TARGET-3OLdJhTj.mjs";import{loadProjectConfig as ir,readProjectConfigLiterals as ar}from"./packem_shared/loadProjectConfig-B7RmxIeD.mjs";import{PROJECT_CONFIG_FILENAMES as fr,findCodegenConfigFile as mr,findProjectConfigFile as dr,projectConfigCandidatePaths as pr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{SCHEMA_SNAPSHOT_FILENAME as cr,runCodegen as lr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DXilYf6b.mjs";import{SchemaSnapshotParseError as Sr,buildSchemaSnapshot as Er,evaluateSchemaDrift as ur,indexReferencesOf as Ar,parseSchemaSnapshot as vr}from"./packem_shared/SchemaSnapshotParseError-DnAuFdpl.mjs";import{default as Cr}from"./packem_shared/fingerprintSchemaSources-DIYx5eO0.mjs";import{schemaFromIr as Or}from"./packem_shared/schemaFromIr-CByOxuZb.mjs";import{LUNORA_ERROR_CODES as Tr,validatorIrToJsonSchema as hr}from"./packem_shared/LUNORA_ERROR_CODES-CjACC-MQ.mjs";import{SDK_LANGUAGES as _r,SDK_TARGETS as Fr,generateSdk as Lr}from"./sdk/index.mjs";import{redact as Pr,secretKindOf as Dr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as yr}from"./packem_shared/emitDrizzleSchema-Dszoyymv.mjs";import{e as Gr}from"./packem_shared/server-qWq5nN-R.mjs";import{e as jr}from"./packem_shared/shard-BqfSKnmG.mjs";import{G as kr}from"./packem_shared/shared-DhqnD5R3.mjs";import{MESSAGE_SOLUTIONS as Kr,findSolutionByMessage as Vr}from"@lunora/errors";import{createCodegenProject as Qr,findTsconfig as qr,refreshCodegenProject as wr,tsconfigFingerprint as Jr}from"./packem_shared/createCodegenProject-DmXl8m_P.mjs";import{t as Xr,u as Zr,v as $r}from"./packem_shared/shard-runtime-C1P_uVye.mjs";import{emitApi as ro,emitCollections as oo,emitInternalApi as to}from"./packem_shared/emitApi-DWJW8Vu9.mjs";import{emitCrons as ao,emitScheduler as so,emitVectors as fo,emitWranglerCronTriggers as mo}from"./packem_shared/emitCrons-BvqxeNRr.mjs";import{emitDataModel as no}from"./packem_shared/emitDataModel-MjAOi3KM.mjs";import{emitFunctions as lo}from"./packem_shared/emitFunctions-CvMrX_cX.mjs";import{isTypedSchema as So}from"./packem_shared/isTypedSchema-CDv3pJB6.mjs";const e="0.0.0";export{C as AGENTS_FILENAME,E as CAPABILITY_PROBES,F as CONTAINERS_FILENAME,A as CodegenDiagnosticError,$e as DEFAULT_TARGET,B as FLAGS_FILENAME,kr as GENERATED_HEADER,Tr as LUNORA_ERROR_CODES,Kr as LUNORA_SOLUTION_RULES,re as MUTATORS_FILENAME,se as NOTIFY_FILENAME,we as OPENRPC_VERSION,fr as PROJECT_CONFIG_FILENAMES,Se as QUEUES_FILENAME,cr as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,_r as SDK_LANGUAGES,Fr as SDK_TARGETS,Me as SHAPES_FILENAME,Sr as SchemaSnapshotParseError,e as VERSION,Ue as WORKFLOWS_FILENAME,Ve as buildOpenApiDocument,Je as buildOpenRpcDocument,Er as buildSchemaSnapshot,b as capabilitiesUsedBy,Qr as createCodegenProject,y as createTargetScope,n as describeErrorLevelFindings,v as diagnosticAt,i as diffSchemaSnapshots,N as discoverAgents,I as discoverAuthApiCalls,L as discoverContainers,P as discoverCrons,k as discoverFlags,K as discoverFunctions,z as discoverHttpRoutes,q as discoverHyperdriveCalls,J as discoverInserts,X as discoverMaskProcedures,$ as discoverMigrations,oe as discoverMutators,ie as discoverNondeterministicCalls,fe as discoverNotifyCalls,me as discoverNotifyChannels,de as discoverNotifyConfig,le as discoverQueries,Ee as discoverQueues,Ae as discoverR2sqlCalls,Ne as discoverRlsMetadata,ge as discoverRlsProcedures,Re as discoverSandboxUsage,he as discoverSchema,Pe as discoverShapes,be as discoverStorageRulesMetadata,Ge as discoverWorkflows,Xr as emitAgents,ro as emitApi,je as emitApp,oo as emitCollections,Zr as emitContainers,ao as emitCrons,no as emitDataModel,yr as emitDrizzleSchema,lo as emitFunctions,to as emitInternalApi,ze as emitOpenApi,Qe as emitOpenApiModule,Ye as emitOpenRpc,Xe as emitOpenRpcModule,so as emitScheduler,Gr as emitServer,jr as emitShard,fo as emitVectors,$r as emitWorkflows,mo as emitWranglerCronTriggers,c as errorAdvisoryNames,l as errorPlatformDiagnosticNames,ur as evaluateSchemaDrift,mr as findCodegenConfigFile,Vr as findLunoraSolution,dr as findProjectConfigFile,qr as findTsconfig,Cr as fingerprintSchemaSources,U as foldCapabilitySignals,f as formatAdvisories,Lr as generateSdk,Ar as indexReferencesOf,ke as isD1GlobalTable,We as isHyperdriveGlobalTable,R as isTestPath,So as isTypedSchema,m as lintSchema,T as listLunoraSourceFiles,ir as loadProjectConfig,G as mayReadCapabilityContext,vr as parseSchemaSnapshot,er as platformMatrixIds,pr as projectConfigCandidatePaths,ne as readPackageDependencies,ar as readProjectConfigLiterals,rr as readProjectTarget,_e as readServiceBindings,Pr as redact,wr as refreshCodegenProject,or as resolveCodegenTarget,Fe as resolveServiceBindings,lr as runCodegen,Or as schemaFromIr,Dr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,H as sourceCapabilitySignals,d as toAdvisorContext,Jr as tsconfigFingerprint,hr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as i,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{formatAdvisories as f,lintSchema as m,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-DKYJ2K4t.mjs";import{CodegenDiagnosticError as A,diagnosticAt as v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as C,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-5mDMAMWy.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-JdN4KXhV.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-DZMYREsq.mjs";import{CONTAINERS_FILENAME as F,discoverContainers as L}from"./packem_shared/CONTAINERS_FILENAME-BJYrxnq2.mjs";import{default as P}from"./packem_shared/discoverCrons-D-vJXsgx.mjs";import{capabilitiesUsedBy as b,createTargetScope as y,foldCapabilitySignals as U,mayReadCapabilityContext as G,sourceCapabilitySignals as H}from"./packem_shared/capabilitiesUsedBy-CN8HACEL.mjs";import{FLAGS_FILENAME as B,discoverFlags as k}from"./packem_shared/FLAGS_FILENAME-BEMyglH0.mjs";import{d as K}from"./packem_shared/index-o449rQLQ.mjs";import{default as z}from"./packem_shared/discoverHttpRoutes-D9Q0lBBb.mjs";import{default as q}from"./packem_shared/discoverHyperdriveCalls-DlyCZKX3.mjs";import{default as J}from"./packem_shared/discoverInserts-7Xdawmuk.mjs";import{d as X}from"./packem_shared/index-CNI4vSyc.mjs";import{default as $}from"./packem_shared/discoverMigrations-C649uAWL.mjs";import{MUTATORS_FILENAME as re,discoverMutators as oe}from"./packem_shared/MUTATORS_FILENAME-D9WbOFm7.mjs";import{default as ie}from"./packem_shared/discoverNondeterministicCalls-DQgVTcLv.mjs";import{NOTIFY_FILENAME as se,discoverNotifyCalls as fe,discoverNotifyChannels as me,discoverNotifyConfig as de}from"./packem_shared/NOTIFY_FILENAME-CRU_TEKs.mjs";import{default as ne}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-C75OdGHl.mjs";import{QUEUES_FILENAME as Se,discoverQueues as Ee}from"./packem_shared/QUEUES_FILENAME-BeGwgqcw.mjs";import{default as Ae}from"./packem_shared/discoverR2sqlCalls-BrDIti5c.mjs";import{default as ge}from"./packem_shared/discoverRlsProcedures-BiyDg2ej.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-DqZpiGts.mjs";import{discoverSandboxUsage as Re}from"./packem_shared/discoverSandboxUsage-CdGRnVU2.mjs";import{default as he}from"./packem_shared/discoverSchema-Bs5JUiOE.mjs";import{readServiceBindings as _e,resolveServiceBindings as Fe}from"./packem_shared/readServiceBindings-BA49C6aN.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Pe}from"./packem_shared/SHAPES_FILENAME-D9beIrs1.mjs";import{default as be}from"./packem_shared/discoverStorageRulesMetadata-H3RJzkH_.mjs";import{WORKFLOWS_FILENAME as Ue,discoverWorkflows as Ge}from"./packem_shared/WORKFLOWS_FILENAME--RWiu_Vy.mjs";import{emitApp as je}from"./packem_shared/emitApp-L7PnfjJK.mjs";import{isD1GlobalTable as ke,isHyperdriveGlobalTable as We}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ve,emitOpenApi as ze,emitOpenApiModule as Qe}from"./packem_shared/buildOpenApiDocument-67-fasdW.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as Je,emitOpenRpc as Ye,emitOpenRpcModule as Xe}from"./packem_shared/OPENRPC_VERSION-CT_E2DcI.mjs";import{DEFAULT_TARGET as $e,platformMatrixIds as er,readProjectTarget as rr,resolveCodegenTarget as or}from"./packem_shared/DEFAULT_TARGET-3OLdJhTj.mjs";import{loadProjectConfig as ir,readProjectConfigLiterals as ar}from"./packem_shared/loadProjectConfig-B7RmxIeD.mjs";import{PROJECT_CONFIG_FILENAMES as fr,findCodegenConfigFile as mr,findProjectConfigFile as dr,projectConfigCandidatePaths as pr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{SCHEMA_SNAPSHOT_FILENAME as cr,runCodegen as lr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-CA_Jy0Mi.mjs";import{SchemaSnapshotParseError as Sr,buildSchemaSnapshot as Er,evaluateSchemaDrift as ur,indexReferencesOf as Ar,parseSchemaSnapshot as vr}from"./packem_shared/SchemaSnapshotParseError-DnAuFdpl.mjs";import{default as Cr}from"./packem_shared/fingerprintSchemaSources-DIYx5eO0.mjs";import{schemaFromIr as Or}from"./packem_shared/schemaFromIr-CByOxuZb.mjs";import{LUNORA_ERROR_CODES as Tr,validatorIrToJsonSchema as hr}from"./packem_shared/LUNORA_ERROR_CODES-CjACC-MQ.mjs";import{SDK_LANGUAGES as _r,SDK_TARGETS as Fr,generateSdk as Lr}from"./sdk/index.mjs";import{redact as Pr,secretKindOf as Dr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as yr}from"./packem_shared/emitDrizzleSchema-Dszoyymv.mjs";import{e as Gr}from"./packem_shared/server-qWq5nN-R.mjs";import{e as jr}from"./packem_shared/shard-t1Jkywmh.mjs";import{G as kr}from"./packem_shared/shared-DhqnD5R3.mjs";import{MESSAGE_SOLUTIONS as Kr,findSolutionByMessage as Vr}from"@lunora/errors";import{createCodegenProject as Qr,findTsconfig as qr,refreshCodegenProject as wr,tsconfigFingerprint as Jr}from"./packem_shared/createCodegenProject-DmXl8m_P.mjs";import{t as Xr,u as Zr,v as $r}from"./packem_shared/shard-runtime-C1P_uVye.mjs";import{emitApi as ro,emitCollections as oo,emitInternalApi as to}from"./packem_shared/emitApi-DWJW8Vu9.mjs";import{emitCrons as ao,emitScheduler as so,emitVectors as fo,emitWranglerCronTriggers as mo}from"./packem_shared/emitCrons-BvqxeNRr.mjs";import{emitDataModel as no}from"./packem_shared/emitDataModel-MjAOi3KM.mjs";import{emitFunctions as lo}from"./packem_shared/emitFunctions-C4PzKb4H.mjs";import{isTypedSchema as So}from"./packem_shared/isTypedSchema-CDv3pJB6.mjs";const e="0.0.0";export{C as AGENTS_FILENAME,E as CAPABILITY_PROBES,F as CONTAINERS_FILENAME,A as CodegenDiagnosticError,$e as DEFAULT_TARGET,B as FLAGS_FILENAME,kr as GENERATED_HEADER,Tr as LUNORA_ERROR_CODES,Kr as LUNORA_SOLUTION_RULES,re as MUTATORS_FILENAME,se as NOTIFY_FILENAME,we as OPENRPC_VERSION,fr as PROJECT_CONFIG_FILENAMES,Se as QUEUES_FILENAME,cr as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,_r as SDK_LANGUAGES,Fr as SDK_TARGETS,Me as SHAPES_FILENAME,Sr as SchemaSnapshotParseError,e as VERSION,Ue as WORKFLOWS_FILENAME,Ve as buildOpenApiDocument,Je as buildOpenRpcDocument,Er as buildSchemaSnapshot,b as capabilitiesUsedBy,Qr as createCodegenProject,y as createTargetScope,n as describeErrorLevelFindings,v as diagnosticAt,i as diffSchemaSnapshots,N as discoverAgents,I as discoverAuthApiCalls,L as discoverContainers,P as discoverCrons,k as discoverFlags,K as discoverFunctions,z as discoverHttpRoutes,q as discoverHyperdriveCalls,J as discoverInserts,X as discoverMaskProcedures,$ as discoverMigrations,oe as discoverMutators,ie as discoverNondeterministicCalls,fe as discoverNotifyCalls,me as discoverNotifyChannels,de as discoverNotifyConfig,le as discoverQueries,Ee as discoverQueues,Ae as discoverR2sqlCalls,Ne as discoverRlsMetadata,ge as discoverRlsProcedures,Re as discoverSandboxUsage,he as discoverSchema,Pe as discoverShapes,be as discoverStorageRulesMetadata,Ge as discoverWorkflows,Xr as emitAgents,ro as emitApi,je as emitApp,oo as emitCollections,Zr as emitContainers,ao as emitCrons,no as emitDataModel,yr as emitDrizzleSchema,lo as emitFunctions,to as emitInternalApi,ze as emitOpenApi,Qe as emitOpenApiModule,Ye as emitOpenRpc,Xe as emitOpenRpcModule,so as emitScheduler,Gr as emitServer,jr as emitShard,fo as emitVectors,$r as emitWorkflows,mo as emitWranglerCronTriggers,c as errorAdvisoryNames,l as errorPlatformDiagnosticNames,ur as evaluateSchemaDrift,mr as findCodegenConfigFile,Vr as findLunoraSolution,dr as findProjectConfigFile,qr as findTsconfig,Cr as fingerprintSchemaSources,U as foldCapabilitySignals,f as formatAdvisories,Lr as generateSdk,Ar as indexReferencesOf,ke as isD1GlobalTable,We as isHyperdriveGlobalTable,R as isTestPath,So as isTypedSchema,m as lintSchema,T as listLunoraSourceFiles,ir as loadProjectConfig,G as mayReadCapabilityContext,vr as parseSchemaSnapshot,er as platformMatrixIds,pr as projectConfigCandidatePaths,ne as readPackageDependencies,ar as readProjectConfigLiterals,rr as readProjectTarget,_e as readServiceBindings,Pr as redact,wr as refreshCodegenProject,or as resolveCodegenTarget,Fe as resolveServiceBindings,lr as runCodegen,Or as schemaFromIr,Dr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,H as sourceCapabilitySignals,d as toAdvisorContext,Jr as tsconfigFingerprint,hr as validatorIrToJsonSchema};
@@ -1,4 +1,4 @@
1
- import{existsSync as z,readFileSync as Qe,mkdirSync as qt,writeFileSync as yr,rmSync as Pe,readdirSync as Ln}from"node:fs";import{dirname as jt,join as E,relative as Ht}from"node:path";import{performance as Et}from"node:perf_hooks";import{runAdvisor as br}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{serializeSchemaSnapshot as Nr}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{toAdvisorContext as Pr}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,Project as Gt,ts as wr,VariableDeclarationKind as Yt}from"ts-morph";import{listLunoraSourceFiles as y,lunoraRelativePath as w,descendantsOfKind as x,bindingKeyName as ue,collectCallRows as O,findObjectProperty as W,collectSecurityCallRows as Ir,propertyInitializer as L,listSecurityScanFiles as Xe,objectLiteralFromCallbackBody as Dn,limitNameOf as Mn,optionsObjectLiteral as _n,handlerOf as Tr,collectNodeRows as ie,chainRootOf as Je,outermostValueWrapper as C,isWriteTarget as Ze,isSameNode as b,unwrapExpression as h,isConstDeclaration as re,memberAccessOf as Qt,returningFunctionOf as Ct,walkChain as Cr,RUN_METHODS as zn,functionReferenceSegments as Or,isTestPath as kr,isFunctionLike as oe,functionKeyOf as Kn,withSourceListMemo as Rr}from"./isTestPath-JdN4KXhV.mjs";import{j as J,h as G,d as M,b as Xt,c as S,a as et,w as Jt,k as Fr,l as Lr,f as Dr,m as Mr,g as Ot,i as _r}from"./attribution-CTMkuBkn.mjs";import{b as Ks,r as xt,a as Q,e as zr,m as $n,c as tt,f as Zt,E as Bn,C as Vn,d as Kr,g as $r,i as Br}from"./context-root-DtpwprsY.mjs";import{a as T,i as Un,c as te,d as Wn,e as Vr,f as Ur,g as qn}from"./classify-procedure-call-DtqiTjPg.mjs";import{a as A,s as Wr}from"./property-name-7cBlgK_O.mjs";import{b as qr,a as st}from"./module-specifiers-BctA0m_p.mjs";import{r as nt,s as jr}from"./parse-validator-BisfC8bR.mjs";import Hr from"./discoverAuthApiCalls-DZMYREsq.mjs";import{i as K,r as jn}from"./database-calls-Cn47SfSU.mjs";import{i as kt,p as Hn,w as Gr,d as Yr}from"./index-o449rQLQ.mjs";import Qr from"./discoverHyperdriveCalls-DlyCZKX3.mjs";import{diagnosticAt as ae}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as es,a as Ue,s as Gn,d as Xr}from"./index-CNI4vSyc.mjs";import{MUTATORS_FILENAME as Jr,isDefineMutatorCallee as Zr,mutatorServerImplOf as eo,discoverMutators as to}from"./MUTATORS_FILENAME-D9WbOFm7.mjs";import so from"./discoverNondeterministicCalls-DQgVTcLv.mjs";import{discoverNotifyConfig as no,discoverNotifyCalls as io}from"./NOTIFY_FILENAME-CRU_TEKs.mjs";import ro from"./discoverR2sqlCalls-BrDIti5c.mjs";import oo from"./discoverRlsProcedures-BiyDg2ej.mjs";import{s as ts,n as ao}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as co,redact as lo,isHeuristicSecretKind as uo,isSecretishName as fo}from"./redact-Cy14LEnc.mjs";import{readProjectConfigLiterals as Yn,readMergeDurableObjects as go}from"./loadProjectConfig-B7RmxIeD.mjs";import{a as De,d as po,r as mo}from"./modules-DEBCI7Gm.mjs";import{WORKFLOWS_FILENAME as ho,discoverWorkflows as vo}from"./WORKFLOWS_FILENAME--RWiu_Vy.mjs";import{r as Eo}from"./json-data-Chfs2Cz5.mjs";import{a as xo,I as So,g as Ao,G as Qn,d as yo,i as bo}from"./shared-DhqnD5R3.mjs";import{createCodegenProject as No}from"./createCodegenProject-DmXl8m_P.mjs";import{findTsconfig as BE,refreshCodegenProject as VE,tsconfigFingerprint as UE}from"./createCodegenProject-DmXl8m_P.mjs";import{CAPABILITIES as Po,usedCapabilities as wo}from"./CAPABILITY_PROBES-DKYJ2K4t.mjs";import{isD1GlobalTable as Xn,isHyperdriveGlobalTable as Jn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Io}from"./AGENTS_FILENAME-5mDMAMWy.mjs";import{discoverContainers as To}from"./CONTAINERS_FILENAME-BJYrxnq2.mjs";import Co from"./discoverCrons-D-vJXsgx.mjs";import{contextPropertiesRead as Oo,fileWiresRequestSecretTool as ko,createTargetScope as Ro,discoverFeatureUsage as Fo}from"./capabilitiesUsedBy-CN8HACEL.mjs";import Zn from"./readPackageDependencies-RHhGiz0k.mjs";import{PROJECT_CONFIG_FILENAMES as Lo,findProjectConfigFile as Do}from"./PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{discoverQueueDeclarations as Mo}from"./QUEUES_FILENAME-BeGwgqcw.mjs";import{discoverSandboxUsage as _o}from"./discoverSandboxUsage-CdGRnVU2.mjs";import{resolveServiceBindings as zo}from"./readServiceBindings-BA49C6aN.mjs";import Ko from"./discoverStorageRulesMetadata-H3RJzkH_.mjs";import{resolveCodegenTarget as Rt,gatePlatformFeatures as $o,readTargetDiagnostics as Bo,vectorizeDimensionDiagnostics as Vo,liveStreamsDeliveryAuthorizationDiagnostic as Uo,socketRoutesDeliveryAuthorizationDiagnostic as Wo,studioPlatformFor as qo,platformFeatureAvailable as jo}from"./DEFAULT_TARGET-3OLdJhTj.mjs";import{i as Ho}from"./schema-BgM8A3XV.mjs";import{b as ei,e as Go}from"./shard-BqfSKnmG.mjs";import{e as Yo,a as Qo}from"./server-qWq5nN-R.mjs";import{emitDataModel as Xo}from"./emitDataModel-MjAOi3KM.mjs";import{i as Jo,b as Zo,e as ea,d as ta,f as sa,c as na}from"./unwrap-handler-return-c2s2-nk9.mjs";import ia from"./discoverHttpRoutes-D9Q0lBBb.mjs";import ra from"./discoverInserts-7Xdawmuk.mjs";import{e as ti}from"./exported-procedure-chains-CRM-MVfP.mjs";import oa from"./discoverMigrations-C649uAWL.mjs";import $s from"./discoverQueries-C75OdGHl.mjs";import aa from"./discoverRlsMetadata-DqZpiGts.mjs";import ca from"./discoverSchema-Bs5JUiOE.mjs";import{discoverShapes as la}from"./SHAPES_FILENAME-D9beIrs1.mjs";import{i as da}from"./reserved-words-CW1QFbTd.mjs";import{emitAuthModule as ua,emitApp as fa}from"./emitApp-L7PnfjJK.mjs";import{readJsonSync as ga}from"@visulima/fs";import{indexReferencesOf as pa,buildSchemaSnapshot as ma}from"./SchemaSnapshotParseError-DnAuFdpl.mjs";import{buildOpenApiDocument as ha,emitOpenApiModule as va}from"./buildOpenApiDocument-67-fasdW.mjs";import{buildOpenRpcDocument as Ea,emitOpenRpcModule as xa}from"./OPENRPC_VERSION-CT_E2DcI.mjs";import{w as Sa,u as Aa,v as ya,t as ba,x as Na}from"./shard-runtime-C1P_uVye.mjs";import{emitCollections as Pa,emitSeed as wa,emitApi as Ia,emitInternalApi as Ta}from"./emitApi-DWJW8Vu9.mjs";import{emitCrons as Ca,emitScheduler as Oa,emitShardRegistry as ka,emitDurableObjects as Ra,emitVectors as Fa,emitWranglerCronTriggers as La}from"./emitCrons-BvqxeNRr.mjs";import Da from"./emitDrizzleSchema-Dszoyymv.mjs";import{LAZY_FUNCTION_DIRECTORY as si,emitFunctions as Ma,emitLazyFunctionModules as _a}from"./emitFunctions-CvMrX_cX.mjs";const za=(e,t=!1)=>{if(e.length===0)return"";const s=yo(t),n=e.map(c=>{if(xo(c.exportName,"live stream export name"),!So.test(c.filePath))throw new Error(`@lunora/codegen: live stream file path is not safe to import: ${JSON.stringify(c.filePath)}`);return`import type { ${c.exportName} as ${c.exportName}Stream } from "../${c.filePath}.js";`}),i=e.map(c=>{const l=c.topics.map(u=>{Ao(u.name,"live topic name");const f=`(typeof ${c.exportName}Stream)["topics"]["${u.name}"]`,g=`LiveTopicRef<LiveTopicPayload<${f}>>`,m=JSON.stringify(c.id);if(u.fields.length===0)return` ${u.name}: (): ${g} => ({ __lunoraLive: ${m}, topic: ${JSON.stringify(u.name)} }),`;const v=u.fields.map(B=>`\${encodeURIComponent(key.${B})}`).join(":");return` ${u.name}: (key: LiveTopicKey<${f}>): ${g} => ({
1
+ import{existsSync as z,readFileSync as Qe,mkdirSync as qt,writeFileSync as yr,rmSync as Pe,readdirSync as Ln}from"node:fs";import{dirname as jt,join as E,relative as Ht}from"node:path";import{performance as Et}from"node:perf_hooks";import{runAdvisor as br}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{serializeSchemaSnapshot as Nr}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{toAdvisorContext as Pr}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,Project as Gt,ts as wr,VariableDeclarationKind as Yt}from"ts-morph";import{listLunoraSourceFiles as y,lunoraRelativePath as w,descendantsOfKind as x,bindingKeyName as ue,collectCallRows as O,findObjectProperty as W,collectSecurityCallRows as Ir,propertyInitializer as L,listSecurityScanFiles as Xe,objectLiteralFromCallbackBody as Dn,limitNameOf as Mn,optionsObjectLiteral as _n,handlerOf as Tr,collectNodeRows as ie,chainRootOf as Je,outermostValueWrapper as C,isWriteTarget as Ze,isSameNode as b,unwrapExpression as h,isConstDeclaration as re,memberAccessOf as Qt,returningFunctionOf as Ct,walkChain as Cr,RUN_METHODS as zn,functionReferenceSegments as Or,isTestPath as kr,isFunctionLike as oe,functionKeyOf as Kn,withSourceListMemo as Rr}from"./isTestPath-JdN4KXhV.mjs";import{j as J,h as G,d as M,b as Xt,c as S,a as et,w as Jt,k as Fr,l as Lr,f as Dr,m as Mr,g as Ot,i as _r}from"./attribution-CTMkuBkn.mjs";import{b as Ks,r as xt,a as Q,e as zr,m as $n,c as tt,f as Zt,E as Bn,C as Vn,d as Kr,g as $r,i as Br}from"./context-root-DtpwprsY.mjs";import{a as T,i as Un,c as te,d as Wn,e as Vr,f as Ur,g as qn}from"./classify-procedure-call-DtqiTjPg.mjs";import{a as A,s as Wr}from"./property-name-7cBlgK_O.mjs";import{b as qr,a as st}from"./module-specifiers-BctA0m_p.mjs";import{r as nt,s as jr}from"./parse-validator-BisfC8bR.mjs";import Hr from"./discoverAuthApiCalls-DZMYREsq.mjs";import{i as K,r as jn}from"./database-calls-Cn47SfSU.mjs";import{i as kt,p as Hn,w as Gr,d as Yr}from"./index-o449rQLQ.mjs";import Qr from"./discoverHyperdriveCalls-DlyCZKX3.mjs";import{diagnosticAt as ae}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as es,a as Ue,s as Gn,d as Xr}from"./index-CNI4vSyc.mjs";import{MUTATORS_FILENAME as Jr,isDefineMutatorCallee as Zr,mutatorServerImplOf as eo,discoverMutators as to}from"./MUTATORS_FILENAME-D9WbOFm7.mjs";import so from"./discoverNondeterministicCalls-DQgVTcLv.mjs";import{discoverNotifyConfig as no,discoverNotifyCalls as io}from"./NOTIFY_FILENAME-CRU_TEKs.mjs";import ro from"./discoverR2sqlCalls-BrDIti5c.mjs";import oo from"./discoverRlsProcedures-BiyDg2ej.mjs";import{s as ts,n as ao}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as co,redact as lo,isHeuristicSecretKind as uo,isSecretishName as fo}from"./redact-Cy14LEnc.mjs";import{readProjectConfigLiterals as Yn,readMergeDurableObjects as go}from"./loadProjectConfig-B7RmxIeD.mjs";import{a as De,d as po,r as mo}from"./modules-DEBCI7Gm.mjs";import{WORKFLOWS_FILENAME as ho,discoverWorkflows as vo}from"./WORKFLOWS_FILENAME--RWiu_Vy.mjs";import{r as Eo}from"./json-data-Chfs2Cz5.mjs";import{a as xo,I as So,g as Ao,G as Qn,d as yo,i as bo}from"./shared-DhqnD5R3.mjs";import{createCodegenProject as No}from"./createCodegenProject-DmXl8m_P.mjs";import{findTsconfig as BE,refreshCodegenProject as VE,tsconfigFingerprint as UE}from"./createCodegenProject-DmXl8m_P.mjs";import{CAPABILITIES as Po,usedCapabilities as wo}from"./CAPABILITY_PROBES-DKYJ2K4t.mjs";import{isD1GlobalTable as Xn,isHyperdriveGlobalTable as Jn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Io}from"./AGENTS_FILENAME-5mDMAMWy.mjs";import{discoverContainers as To}from"./CONTAINERS_FILENAME-BJYrxnq2.mjs";import Co from"./discoverCrons-D-vJXsgx.mjs";import{contextPropertiesRead as Oo,fileWiresRequestSecretTool as ko,createTargetScope as Ro,discoverFeatureUsage as Fo}from"./capabilitiesUsedBy-CN8HACEL.mjs";import Zn from"./readPackageDependencies-RHhGiz0k.mjs";import{PROJECT_CONFIG_FILENAMES as Lo,findProjectConfigFile as Do}from"./PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{discoverQueueDeclarations as Mo}from"./QUEUES_FILENAME-BeGwgqcw.mjs";import{discoverSandboxUsage as _o}from"./discoverSandboxUsage-CdGRnVU2.mjs";import{resolveServiceBindings as zo}from"./readServiceBindings-BA49C6aN.mjs";import Ko from"./discoverStorageRulesMetadata-H3RJzkH_.mjs";import{resolveCodegenTarget as Rt,gatePlatformFeatures as $o,readTargetDiagnostics as Bo,vectorizeDimensionDiagnostics as Vo,liveStreamsDeliveryAuthorizationDiagnostic as Uo,socketRoutesDeliveryAuthorizationDiagnostic as Wo,studioPlatformFor as qo,platformFeatureAvailable as jo}from"./DEFAULT_TARGET-3OLdJhTj.mjs";import{i as Ho}from"./schema-BgM8A3XV.mjs";import{b as ei,e as Go}from"./shard-t1Jkywmh.mjs";import{e as Yo,a as Qo}from"./server-qWq5nN-R.mjs";import{emitDataModel as Xo}from"./emitDataModel-MjAOi3KM.mjs";import{i as Jo,b as Zo,e as ea,d as ta,f as sa,c as na}from"./unwrap-handler-return-c2s2-nk9.mjs";import ia from"./discoverHttpRoutes-D9Q0lBBb.mjs";import ra from"./discoverInserts-7Xdawmuk.mjs";import{e as ti}from"./exported-procedure-chains-CRM-MVfP.mjs";import oa from"./discoverMigrations-C649uAWL.mjs";import $s from"./discoverQueries-C75OdGHl.mjs";import aa from"./discoverRlsMetadata-DqZpiGts.mjs";import ca from"./discoverSchema-Bs5JUiOE.mjs";import{discoverShapes as la}from"./SHAPES_FILENAME-D9beIrs1.mjs";import{i as da}from"./reserved-words-CW1QFbTd.mjs";import{emitAuthModule as ua,emitApp as fa}from"./emitApp-L7PnfjJK.mjs";import{readJsonSync as ga}from"@visulima/fs";import{indexReferencesOf as pa,buildSchemaSnapshot as ma}from"./SchemaSnapshotParseError-DnAuFdpl.mjs";import{buildOpenApiDocument as ha,emitOpenApiModule as va}from"./buildOpenApiDocument-67-fasdW.mjs";import{buildOpenRpcDocument as Ea,emitOpenRpcModule as xa}from"./OPENRPC_VERSION-CT_E2DcI.mjs";import{w as Sa,u as Aa,v as ya,t as ba,x as Na}from"./shard-runtime-C1P_uVye.mjs";import{emitCollections as Pa,emitSeed as wa,emitApi as Ia,emitInternalApi as Ta}from"./emitApi-DWJW8Vu9.mjs";import{emitCrons as Ca,emitScheduler as Oa,emitShardRegistry as ka,emitDurableObjects as Ra,emitVectors as Fa,emitWranglerCronTriggers as La}from"./emitCrons-BvqxeNRr.mjs";import Da from"./emitDrizzleSchema-Dszoyymv.mjs";import{LAZY_FUNCTION_DIRECTORY as si,emitFunctions as Ma,emitLazyFunctionModules as _a}from"./emitFunctions-C4PzKb4H.mjs";const za=(e,t=!1)=>{if(e.length===0)return"";const s=yo(t),n=e.map(c=>{if(xo(c.exportName,"live stream export name"),!So.test(c.filePath))throw new Error(`@lunora/codegen: live stream file path is not safe to import: ${JSON.stringify(c.filePath)}`);return`import type { ${c.exportName} as ${c.exportName}Stream } from "../${c.filePath}.js";`}),i=e.map(c=>{const l=c.topics.map(u=>{Ao(u.name,"live topic name");const f=`(typeof ${c.exportName}Stream)["topics"]["${u.name}"]`,g=`LiveTopicRef<LiveTopicPayload<${f}>>`,m=JSON.stringify(c.id);if(u.fields.length===0)return` ${u.name}: (): ${g} => ({ __lunoraLive: ${m}, topic: ${JSON.stringify(u.name)} }),`;const v=u.fields.map(B=>`\${encodeURIComponent(key.${B})}`).join(":");return` ${u.name}: (key: LiveTopicKey<${f}>): ${g} => ({
2
2
  __lunoraLive: ${m},
3
3
  topic: \`${u.name}:${v}\`,
4
4
  }),`});return` ${c.exportName}: {
@@ -1,30 +1,34 @@
1
- import{LunoraError as L}from"@lunora/errors";import{L as pe,i as me,G as U,d as J,I as F,s as ge,b as C,r as fe,c as ye}from"./shared-DhqnD5R3.mjs";import{v as $e}from"./parse-validator-BisfC8bR.mjs";import{renderAgentFunctionRegistry as we,renderSandboxFunctionRegistry as Re}from"./emitApi-DWJW8Vu9.mjs";import{b as ke,a as be,r as j,c as Ne}from"./qualifiers-ClaCHu0X.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const ve=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),B=t=>t.column!==void 0,Oe=(t,r)=>{switch(t){case"bigint":return`if (typeof ${r} !== "bigint") return DEFER;
1
+ import{LunoraError as L}from"@lunora/errors";import{L as pe,i as ge,G as U,d as J,I as F,s as fe,b as C,r as ye,c as $e}from"./shared-DhqnD5R3.mjs";import{v as we}from"./parse-validator-BisfC8bR.mjs";import{renderAgentFunctionRegistry as Re,renderSandboxFunctionRegistry as be}from"./emitApi-DWJW8Vu9.mjs";import{b as ke,a as Ne,r as j,c as ve}from"./qualifiers-ClaCHu0X.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const Oe=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),B=t=>t.column!==void 0,Se=(t,r)=>{switch(t){case"bigint":return`if (typeof ${r} !== "bigint") return DEFER;
2
2
  `;case"boolean":return`if (typeof ${r} !== "boolean") return DEFER;
3
3
  `;case"date":case"number":case"timestamp":return`if (typeof ${r} !== "number" || !Number.isFinite(${r})) return DEFER;
4
4
  `;case"null":return`if (${r} !== null) return DEFER;
5
5
  `;default:return`if (typeof ${r} !== "string") return DEFER;
6
- `}},Se=(t,r)=>t.stringMaxLength===void 0?"":`if (${r}.length > ${String(t.stringMaxLength)}) return DEFER;
7
- `,Pe=(t,r)=>{const n=t.literalValue?.trim();if(!(n===void 0||!pe.test(n)))return{out:r,pre:`if (${r} !== ${n}) return DEFER;
8
- `}},E=(t,r,n)=>{if(!B(t)&&!(t.unmodelledRefinement||t.sourceText!==void 0)){if(ve.has(t.kind))return t.kind==="any"?{out:r,pre:""}:{out:r,pre:Oe(t.kind,r)+Se(t,r)};switch(t.kind){case"array":return xe(t,r,n);case"literal":return Pe(t,r);case"object":return Te(t,r,n);default:return}}},xe=(t,r,n)=>{const{inner:o}=t;if(!o)return;const s=n.next(),i=`__arr${String(s)}`,a=`__i${String(s)}`,c=`__e${String(s)}`,u=E(o,c,n);if(!u)return;const l=`if (!Array.isArray(${r})) return DEFER;
6
+ `}},Pe=(t,r)=>t.stringMaxLength===void 0?"":`if (${r}.length > ${String(t.stringMaxLength)}) return DEFER;
7
+ `,xe=(t,r)=>{const n=t.literalValue?.trim();if(!(n===void 0||!pe.test(n)))return{out:r,pre:`if (${r} !== ${n}) return DEFER;
8
+ `}},E=(t,r,n)=>{if(!B(t)&&!(t.unmodelledRefinement||t.sourceText!==void 0)){if(Oe.has(t.kind))return t.kind==="any"?{out:r,pre:""}:{out:r,pre:Se(t.kind,r)+Pe(t,r)};switch(t.kind){case"array":return Ae(t,r,n);case"literal":return xe(t,r);case"object":return Fe(t,r,n);default:return}}},Ae=(t,r,n)=>{const{inner:o}=t;if(!o)return;const s=n.next(),i=`__arr${String(s)}`,a=`__i${String(s)}`,c=`__e${String(s)}`,u=E(o,c,n);if(!u)return;const l=`if (!Array.isArray(${r})) return DEFER;
9
9
  const ${i} = new Array(${r}.length);
10
10
  for (let ${a} = 0; ${a} < ${r}.length; ${a}++) {
11
11
  const ${c} = ${r}[${a}];
12
12
  ${u.pre}${i}[${a}] = ${u.out};
13
13
  }
14
- `;return{out:i,pre:l}},Ae=(t,r,n,o)=>{const s=JSON.stringify(t);if(r.kind==="optional"){if(r.hasRefinement||r.sourceText!==void 0||B(r))return;const{inner:a}=r;if(!a)return;const c=E(a,n,o);if(!c)return;const u=o.next(),l=`__has${String(u)}`,d=`__val${String(u)}`,f=`let ${l} = false;
14
+ `;return{out:i,pre:l}},Le=(t,r,n,o)=>{const s=JSON.stringify(t);if(r.kind==="optional"){if(r.hasRefinement||r.sourceText!==void 0||B(r))return;const{inner:a}=r;if(!a)return;const c=E(a,n,o);if(!c)return;const u=o.next(),l=`__has${String(u)}`,d=`__val${String(u)}`,f=`let ${l} = false;
15
15
  let ${d};
16
16
  if (${n} !== undefined) {
17
17
  ${c.pre}${d} = ${c.out};
18
18
  ${l} = true;
19
19
  }
20
- `;return{entry:`...(${l} ? { ${s}: ${d} } : {})`,pre:f}}const i=E(r,n,o);if(i)return{entry:`${s}: ${i.out}`,pre:i.pre}},Le=new Set(Object.getOwnPropertyNames(Object.prototype)),q=(t,r,n)=>{let o="";const s=[];for(const i of Object.keys(t)){const a=t[i];if(!a)return;const c=JSON.stringify(i);let u=`${r}[${c}]`;if(Le.has(i)){const d=`__f${String(n.next())}`;o+=`const ${d} = Object.hasOwn(${r}, ${c}) ? ${r}[${c}] : undefined;
21
- `,u=d}const l=Ae(i,a,u,n);if(!l)return;o+=l.pre,s.push(l.entry)}return{entries:s.join(", "),pre:o}},H=t=>{const r=`Object.getPrototypeOf(${t})`;return`if (${r} !== Object.prototype && ${r} !== null) return DEFER;
22
- `},Te=(t,r,n)=>{const o=t.shape??{},s=q(o,r,n);if(!s)return;const i=n.next(),a=`__obj${String(i)}`,c=`if (typeof ${r} !== "object" || ${r} === null || Array.isArray(${r})) return DEFER;
23
- ${H(r)}${s.pre}const ${a} = { ${s.entries} };
24
- `;return{out:a,pre:c}},z=t=>{let r=0;const o=q(t,"source",{next:()=>(r+=1,r)});if(o)return`(source) => {
20
+ `;return{entry:`...(${l} ? { ${s}: ${d} } : {})`,pre:f}}const i=E(r,n,o);if(i)return{entry:`${s}: ${i.out}`,pre:i.pre}},Te=new Set(Object.getOwnPropertyNames(Object.prototype)),z=(t,r,n)=>{let o="";const s=[];for(const i of Object.keys(t)){const a=t[i];if(!a)return;const c=JSON.stringify(i);let u=`${r}[${c}]`;if(Te.has(i)){const d=`__f${String(n.next())}`;o+=`const ${d} = Object.hasOwn(${r}, ${c}) ? ${r}[${c}] : undefined;
21
+ `,u=d}const l=Le(i,a,u,n);if(!l)return;o+=l.pre,s.push(l.entry)}return{entries:s.join(", "),pre:o}},q=t=>{const r=`Object.getPrototypeOf(${t})`;return`if (${r} !== Object.prototype && ${r} !== null) return DEFER;
22
+ `},Fe=(t,r,n)=>{const o=t.shape??{},s=z(o,r,n);if(!s)return;const i=n.next(),a=`__obj${String(i)}`,c=`if (typeof ${r} !== "object" || ${r} === null || Array.isArray(${r})) return DEFER;
23
+ ${q(r)}${s.pre}const ${a} = { ${s.entries} };
24
+ `;return{out:a,pre:c}},H=t=>{let r=0;const o=z(t,"source",{next:()=>(r+=1,r)});if(o)return`(source) => {
25
25
  if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
26
- ${H("source")}${o.pre}return { ${o.entries} };
27
- }`},Fe=(t,r)=>`lunora_${g(t)}_${String(r)}`,D=t=>JSON.stringify(Object.entries(t).toSorted(([r],[n])=>r.localeCompare(n)).map(([r,n])=>{const o=n.kind==="optional",s=o?n.inner??{kind:"unknown"}:n,i=s.kind==="array"?s.inner?.kind:void 0,a=s.kind==="id"?s.tableName:void 0;return{kind:s.kind,name:r,optional:o,...$e(n)?{sensitive:!0}:{},...a===void 0?{}:{table:a},...i===void 0||i==="unknown"?{}:{element:i}}})),W=(t,r,n,o)=>{const s=new Map,i=a=>{s.has(a)||s.set(a,Fe(a,s.size))};for(const a of t)i(a.filePath);for(const a of r)i(a.filePath);for(const a of n)i(a.filePath);for(const a of o)i(a.filePath);return s},Q=(t,r,n,o)=>new Set([...t.filter(s=>s.typeDerivedArgs).map(s=>s.filePath),...r.map(s=>s.filePath),...n.map(s=>s.filePath),...o.map(s=>s.filePath)]),_=t=>Array.isArray(t)?`Object.freeze([${t.map(r=>_(r)).join(", ")}])`:t!==null&&typeof t=="object"?`Object.freeze({ ${Object.entries(t).map(([n,o])=>`${JSON.stringify(n)}: ${_(o)}`).join(", ")} })`:typeof t=="number"&&(!Number.isFinite(t)||Object.is(t,-0))?Object.is(t,-0)?"-0":String(t):JSON.stringify(t),S=t=>`${t}[functionPath]`,Ee=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
26
+ ${q("source")}${o.pre}return { ${o.entries} };
27
+ }`},Ee=(t,r)=>`lunora_${g(t)}_${String(r)}`,D=t=>JSON.stringify(Object.entries(t).toSorted(([r],[n])=>r.localeCompare(n)).map(([r,n])=>{const o=n.kind==="optional",s=o?n.inner??{kind:"unknown"}:n,i=s.kind==="array"?s.inner?.kind:void 0,a=s.kind==="id"?s.tableName:void 0;return{kind:s.kind,name:r,optional:o,...we(n)?{sensitive:!0}:{},...a===void 0?{}:{table:a},...i===void 0||i==="unknown"?{}:{element:i}}})),Me=t=>t?"sensitive?: true; ":"",_e=t=>t?` /** Lazy-mode stub only: the manifest's argument descriptors, read before the module loads. */
28
+ argumentDescriptors?: FunctionManifestEntry["argumentDescriptors"];
29
+ /** Lazy-mode stub only: the manifest's cache and REST exposure. */
30
+ expose?: FunctionManifestEntry["expose"];
31
+ `:"",W=(t,r,n,o)=>{const s=new Map,i=a=>{s.has(a)||s.set(a,Ee(a,s.size))};for(const a of t)i(a.filePath);for(const a of r)i(a.filePath);for(const a of n)i(a.filePath);for(const a of o)i(a.filePath);return s},Q=(t,r,n,o)=>new Set([...t.filter(s=>s.typeDerivedArgs).map(s=>s.filePath),...r.map(s=>s.filePath),...n.map(s=>s.filePath),...o.map(s=>s.filePath)]),M=t=>Array.isArray(t)?`Object.freeze([${t.map(r=>M(r)).join(", ")}])`:t!==null&&typeof t=="object"?`Object.freeze({ ${Object.entries(t).map(([n,o])=>`${JSON.stringify(n)}: ${M(o)}`).join(", ")} })`:typeof t=="number"&&(!Number.isFinite(t)||Object.is(t,-0))?Object.is(t,-0)?"-0":String(t):JSON.stringify(t),P=t=>`${t}[functionPath]`,Ie=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
28
32
  const registered = await loadFunction(functionPath);
29
33
 
30
34
  if (!registered) {
@@ -57,29 +61,29 @@ ${H("source")}${o.pre}return { ${o.entries} };
57
61
  }
58
62
 
59
63
  return (await registered.handler(context, args ?? {})) as R;
60
- };`,_e=(t,r,n=[],o=[],s=!1)=>{const i=W(t,r,n,o),a=Q(t,r,n,o),c=[...i.entries()].filter(([e])=>!s||a.has(e)?!0:t.some(m=>m.filePath===e&&m.channel?.kind==="room")).map(([e,m])=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);return`import ${s&&!a.has(e)?"type ":""}* as ${m} from "../${e}.js";`}).join(`
61
- `),u=t.map(e=>{if(!s||a.has(e.filePath))return` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`;const m=ge(e.args);return` "${g(e.filePath)}:${e.exportName}": { args: {}, handler: unloadedFunctionHandler, ...${JSON.stringify({argumentDescriptors:JSON.parse(D(e.args)),kind:e.kind,...m.length===0?{}:{sensitiveArgs:m},...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}})}${e.meta===void 0?"":`, [Symbol.for("lunora.procedure.meta")]: ${_(e.meta)}`} } satisfies RegisteredLunoraFunction & Pick<FunctionManifestEntry, "argumentDescriptors" | "channel" | "expose">,`}).join(`
64
+ };`,Ce=(t,r,n=[],o=[],s=!1)=>{const i=W(t,r,n,o),a=Q(t,r,n,o),c=[...i.entries()].filter(([e])=>!s||a.has(e)?!0:t.some(p=>p.filePath===e&&p.channel?.kind==="room")).map(([e,p])=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);return`import ${s&&!a.has(e)?"type ":""}* as ${p} from "../${e}.js";`}).join(`
65
+ `),u=t.map(e=>{if(!s||a.has(e.filePath))return` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`;const p=fe(e.args),w=JSON.stringify({argumentDescriptors:JSON.parse(D(e.args)),kind:e.kind,...p.length===0?{}:{sensitiveArgs:p},...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}}).slice(1,-1),k=e.meta===void 0?"":`, [Symbol.for("lunora.procedure.meta")]: ${M(e.meta)}`;return` "${g(e.filePath)}:${e.exportName}": { args: {}, handler: unloadedFunctionHandler, ${w}${k} } satisfies RegisteredLunoraFunction & Pick<FunctionManifestEntry, "argumentDescriptors" | "channel" | "expose">,`}).join(`
62
66
  `),l=r.map(e=>` ${JSON.stringify(e.id)}: ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredDataMigration,`).join(`
63
67
  `),d=n.map(e=>` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`).join(`
64
68
  `),f=o.map(e=>` "${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredShape,`).join(`
65
- `),y=n.map(e=>`${g(e.filePath)}:${e.exportName}`),$=[...t.filter(e=>e.readsIp===!0).map(e=>`${g(e.filePath)}:${e.exportName}`),...o.filter(e=>e.readsIp===!0).map(e=>e.exportName)],R=[u,d].filter(e=>e.length>0).join(`
66
- `),P=t.filter(e=>!s||a.has(e.filePath)).map(e=>{if(e.lifecycle||e.typeDerivedArgs||Object.keys(e.args).length===0)return;const m=z(e.args);return m===void 0?void 0:`installCompiledValidatorMap(${i.get(e.filePath)??""}.${e.exportName}.args, ${m});`}).filter(e=>e!==void 0).join(`
67
- `),x=t.filter(e=>e.channel?.kind==="room").map(e=>` ${JSON.stringify(e.channel?.name??"")}: RoomMessageOf<typeof ${i.get(e.filePath)??""}[${JSON.stringify(e.exportName)}]>;`).join(`
68
- `),N=[...t.map(e=>({args:e.args,definition:e,path:`${g(e.filePath)}:${e.exportName}`})),...n.map(e=>({args:e.args,definition:{...e,expose:void 0,kind:"mutation",lifecycle:void 0,visibility:void 0,x402:void 0},path:`${g(e.filePath)}:${e.exportName}`}))],v=s?N.filter(({definition:e})=>!a.has(e.filePath)):[];for(const{definition:e}of N)if(s&&e.x402&&e.x402.price===void 0)throw new L("INTERNAL",`@lunora/codegen: lazy function registry needs a literal \`.x402({ price })\` value in ${e.filePath}:${e.exportName}`);const p=s?v.map(({definition:e,path:m})=>{const k=i.get(e.filePath)??"",A="channel"in e?e.channel:void 0,b={argumentDescriptors:JSON.parse(D(e.args)),exportName:e.exportName,kind:e.kind,moduleId:k,...A?{channel:A}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}}};return` ${JSON.stringify(m)}: ${JSON.stringify(b)},`}).join(`
69
- `):"",w=[...new Set(v.map(({definition:e})=>e.filePath))],O=s?w.map(e=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);const m=i.get(e)??"";return` ${JSON.stringify(m)}: () => import(${JSON.stringify(`./fn/${m}.js`)}),`}).join(`
70
- `):"";return{dispatchBody:R.length>0?`
71
- ${R}
69
+ `),y=n.map(e=>`${g(e.filePath)}:${e.exportName}`),$=[...t.filter(e=>e.readsIp===!0).map(e=>`${g(e.filePath)}:${e.exportName}`),...o.filter(e=>e.readsIp===!0).map(e=>e.exportName)],b=[u,d].filter(e=>e.length>0).join(`
70
+ `),x=t.filter(e=>!s||a.has(e.filePath)).map(e=>{if(e.lifecycle||e.typeDerivedArgs||Object.keys(e.args).length===0)return;const p=H(e.args);return p===void 0?void 0:`installCompiledValidatorMap(${i.get(e.filePath)??""}.${e.exportName}.args, ${p});`}).filter(e=>e!==void 0).join(`
71
+ `),A=t.filter(e=>e.channel?.kind==="room").map(e=>` ${JSON.stringify(e.channel?.name??"")}: RoomMessageOf<typeof ${i.get(e.filePath)??""}[${JSON.stringify(e.exportName)}]>;`).join(`
72
+ `),v=[...t.map(e=>({args:e.args,definition:e,path:`${g(e.filePath)}:${e.exportName}`})),...n.map(e=>({args:e.args,definition:{...e,expose:void 0,kind:"mutation",lifecycle:void 0,visibility:void 0,x402:void 0},path:`${g(e.filePath)}:${e.exportName}`}))],O=s?v.filter(({definition:e})=>!a.has(e.filePath)):[];for(const{definition:e}of v)if(s&&e.x402&&e.x402.price===void 0)throw new L("INTERNAL",`@lunora/codegen: lazy function registry needs a literal \`.x402({ price })\` value in ${e.filePath}:${e.exportName}`);const m=s?O.map(({definition:e,path:p})=>{const w=i.get(e.filePath)??"",k="channel"in e?e.channel:void 0,N={argumentDescriptors:JSON.parse(D(e.args)),exportName:e.exportName,kind:e.kind,moduleId:w,...k?{channel:k}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}}};return` ${JSON.stringify(p)}: ${JSON.stringify(N)},`}).join(`
73
+ `):"",R=[...new Set(O.map(({definition:e})=>e.filePath))],S=s?R.map(e=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);const p=i.get(e)??"";return` ${JSON.stringify(p)}: () => import(${JSON.stringify(`./fn/${p}.js`)}),`}).join(`
74
+ `):"";return{dispatchBody:b.length>0?`
75
+ ${b}
72
76
  `:"",importBlock:c.length>0?`${c}
73
77
 
74
- `:"",installBlock:P,manifestBody:p.length>0?`
75
- ${p}
78
+ `:"",installBlock:x,manifestBody:m.length>0?`
79
+ ${m}
76
80
  `:"",migrationBody:l.length>0?`
77
81
  ${l}
78
- `:"",moduleLoaders:O.length>0?`
79
- ${O}
80
- `:"",ipReaderPaths:$,mutatorPaths:y,roomMessagesBody:x,shapeBody:f.length>0?`
82
+ `:"",moduleLoaders:S.length>0?`
83
+ ${S}
84
+ `:"",ipReaderPaths:$,mutatorPaths:y,roomMessagesBody:A,shapeBody:f.length>0?`
81
85
  ${f}
82
- `:""}},Me=t=>{const r=C(t,o=>{const s=j(fe(o.args),o.filePath),i=s==="{}"?"?":"",a=j(Ne(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${i}: ${s}) => Promise<AsyncIterable<${a}>>;`:`${o.exportName}: (args${i}: ${s}) => Promise<${a}>;`},"type");return{implementation:C(t,o=>`${ye(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:r}},Ie=t=>{const r={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const n of t)!n.lifecycle||n.lifecycle==="socket"||r[n.lifecycle].push(`${g(n.filePath)}:${n.exportName}`);return r},Ce=t=>{const r=new Map,n=[];for(const o of t){if(o.lifecycle!=="socket"||o.socket===void 0)continue;const{auth:s,origin:i,path:a}=o.socket,c=`${g(o.filePath)}:${o.exportName}`,u=r.get(a);if(!(u?.origin!==void 0&&u.origin===i)){if(u!==void 0)throw new L("DUPLICATE_SOCKET_PATH",`two defineWebSocket routes serve "${a}" (${u.functionPath} and ${c}); socket paths must be unique.`);r.set(a,{functionPath:c,origin:i}),n.push(` ${JSON.stringify(a)}: { auth: ${String(s)}, functionPath: ${JSON.stringify(c)} },`)}}return`
86
+ `:""}},je=t=>{const r=C(t,o=>{const s=j(ye(o.args),o.filePath),i=s==="{}"?"?":"",a=j(ve(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${i}: ${s}) => Promise<AsyncIterable<${a}>>;`:`${o.exportName}: (args${i}: ${s}) => Promise<${a}>;`},"type");return{implementation:C(t,o=>`${$e(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:r}},De=t=>{const r={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const n of t)!n.lifecycle||n.lifecycle==="socket"||r[n.lifecycle].push(`${g(n.filePath)}:${n.exportName}`);return r},Ue=t=>{const r=new Map,n=[];for(const o of t){if(o.lifecycle!=="socket"||o.socket===void 0)continue;const{auth:s,origin:i,path:a}=o.socket,c=`${g(o.filePath)}:${o.exportName}`,u=r.get(a);if(!(u?.origin!==void 0&&u.origin===i)){if(u!==void 0)throw new L("DUPLICATE_SOCKET_PATH",`two defineWebSocket routes serve "${a}" (${u.functionPath} and ${c}); socket paths must be unique.`);r.set(a,{functionPath:c,origin:i}),n.push(` ${JSON.stringify(a)}: { auth: ${String(s)}, functionPath: ${JSON.stringify(c)} },`)}}return`
83
87
  /**
84
88
  * Socket registry: the URL path of each \`defineWebSocket\` route → its function path + auth requirement.
85
89
  * Static, so building the worker never evaluates a route's module. The generated ShardDO's \`socketRoute\` override
@@ -89,7 +93,7 @@ export const LUNORA_SOCKETS: Readonly<Record<string, { auth: boolean; functionPa
89
93
  ${n.join(`
90
94
  `)}
91
95
  };
92
- `},je=(t,r)=>{const n=t.some(c=>c.lifecycle==="socket"),s=n&&r?Ce(t):n&&!r?`
96
+ `},Je=(t,r)=>{const n=t.some(c=>c.lifecycle==="socket"),s=n&&r?Ue(t):n&&!r?`
93
97
  /**
94
98
  * Socket registry: the URL path of each \`defineWebSocket\` route → its function
95
99
  * path + auth requirement. The generated ShardDO's \`socketRoute\` override
@@ -133,7 +137,7 @@ export const LUNORA_SOCKETS: Readonly<Record<string, { auth: boolean; functionPa
133
137
  * Set on a \`defineWebSocket\` registration: whether the route refuses an
134
138
  * anonymous upgrade. Read into \`LUNORA_SOCKETS\` alongside \`socketPath\`.
135
139
  */
136
- auth?: boolean;`:"",lifecycleMember:n?' | "socket"':"",registry:s}},De=(t,r,n)=>t?{channelField:` /**
140
+ auth?: boolean;`:"",lifecycleMember:n?' | "socket"':"",registry:s}},Be=(t,r,n)=>t?{channelField:` /**
137
141
  * Set on a \`defineRoom\` registration: the room's name (without the \`room:\`
138
142
  * topic prefix). The generated \`LUNORA_ROOMS\` map keys it on the room's
139
143
  * \`room:<name>\` whisper topic so the ShardDO resolves a room topic to this
@@ -148,7 +152,7 @@ export type LunoraRoomMessages = {
148
152
  ${n}
149
153
  };
150
154
  `,typeImport:`import type { RoomMessageOf } from "${r}";
151
- `}:{channelField:"",messagesBlock:"",typeImport:""},Ue=(t,r,n)=>t?r?`
155
+ `}:{channelField:"",messagesBlock:"",typeImport:""},ze=(t,r,n)=>t?r?`
152
156
  /**
153
157
  * Room routes are static metadata so building the worker never evaluates user handlers.
154
158
  */
@@ -208,44 +212,44 @@ export const LUNORA_ROOMS: Readonly<Record<string, string>> = (() => {
208
212
 
209
213
  return registry;
210
214
  })();
211
- `:"",Je=(t,r)=>{const n=Me(t),o=n.types?`
215
+ `:"",qe=(t,r)=>{const n=je(t),o=n.types?`
212
216
  ${n.types}
213
217
  `:"",s=n.implementation?`
214
218
  ${n.implementation}
215
- `:"",i=be(n.types),a=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
216
- `:"",c=t.length>0?"context":"_context";let u="";if(t.length>0){let l=Ee;r||(l=l.replace("await loadFunction(functionPath)",S("LUNORA_FUNCTIONS"))),u=`${l}
219
+ `:"",i=Ne(n.types),a=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
220
+ `:"",c=t.length>0?"context":"_context";let u="";if(t.length>0){let l=Ie;r||(l=l.replace("await loadFunction(functionPath)",P("LUNORA_FUNCTIONS"))),u=`${l}
217
221
 
218
- `}return{callRegisteredHelper:u,dataModelImport:a,implementation:s,parameter:c,types:o}},Ge=t=>{const{agents:r=[],functions:n,lazyFunctions:o=!1,migrations:s=[],mutators:i=[],shapes:a=[],useUmbrella:c=!1,usesSandbox:u=!1}=t,l=J(c),{dispatchBody:d,importBlock:f,installBlock:y,ipReaderPaths:$,manifestBody:R,migrationBody:P,moduleLoaders:x,mutatorPaths:N,roomMessagesBody:v,shapeBody:p}=_e(n,s,i,a,o),w=we(r,n),O=Re(u,n),m=r.length>0||n.some(h=>me(h))?` /**
222
+ `}return{callRegisteredHelper:u,dataModelImport:a,implementation:s,parameter:c,types:o}},Ye=t=>{const{agents:r=[],functions:n,lazyFunctions:o=!1,migrations:s=[],mutators:i=[],shapes:a=[],useUmbrella:c=!1,usesSandbox:u=!1}=t,l=J(c),{dispatchBody:d,importBlock:f,installBlock:y,ipReaderPaths:$,manifestBody:b,migrationBody:x,moduleLoaders:A,mutatorPaths:v,roomMessagesBody:O,shapeBody:m}=Ce(n,s,i,a,o),R=Re(r,n),S=be(u,n),e=r.length>0||n.some(h=>ge(h)),p=e?` /**
219
223
  * Names of the arguments whose validators carry a \`v.sensitive\` marker. Read by the
220
224
  * shard before any validator is loaded, so a lazy function's secret args are
221
225
  * masked even on a dispatch that fails before its module evaluates.
222
226
  */
223
227
  sensitiveArgs?: readonly string[];
224
- `:"",k=[w.lines,O.lines].filter(h=>h.length>0).join(`
225
- `);let A=d;k.length>0&&(A=d.length>0?`${d.trimEnd()}
226
- ${k}
228
+ `:"",w=[R.lines,S.lines].filter(h=>h.length>0).join(`
229
+ `);let k=d;w.length>0&&(k=d.length>0?`${d.trimEnd()}
230
+ ${w}
227
231
  `:`
228
- ${k}
229
- `);const b=Ie(n),G=o?"await loadFunction(functionPath)":S("LUNORA_FUNCTIONS"),V=o?` if (${S("LUNORA_FUNCTION_MANIFEST")}?.visibility === "internal") {
232
+ ${w}
233
+ `);const N=De(n),G=o?"await loadFunction(functionPath)":P("LUNORA_FUNCTIONS"),V=o?` if (${P("LUNORA_FUNCTION_MANIFEST")}?.visibility === "internal") {
230
234
  throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
231
235
  }
232
236
 
233
237
  `:"",K=a.length>0?`import type { RegisteredShape } from "${l.server}";
234
- `:"",M=n.some(h=>h.channel?.kind==="room"),T=De(M,l.server,v),Y=a.length>0?`
238
+ `:"",_=n.some(h=>h.channel?.kind==="room"),T=Be(_,l.server,O),Y=a.length>0?`
235
239
  /**
236
240
  * Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
237
241
  * The generated ShardDO's \`resolveShape\` override looks a shape up by name and
238
242
  * evaluates its trusted \`compileWhere(ctx, args)\` to authorize + scope a
239
243
  * \`shape_subscribe\` (reads-as-permissions).
240
244
  */
241
- export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${p}};
242
- `:"",Z=N.length>0?`
245
+ export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${m}};
246
+ `:"",Z=v.length>0?`
243
247
  /**
244
248
  * Custom-mutator function paths — the \`LUNORA_FUNCTIONS\` keys the generated
245
249
  * ShardDO's \`isCustomMutator\` override routes through the client-watermark push
246
250
  * protocol (\`x-lunora-client-id\`/\`x-lunora-client-seq\` ordering).
247
251
  */
248
- export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${N.map(h=>JSON.stringify(h)).join(", ")}]);
252
+ export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${v.map(h=>JSON.stringify(h)).join(", ")}]);
249
253
  `:"",X=$.length>0?`
250
254
  /**
251
255
  * Queries and shapes that may read \`ctx.ip\`, decided statically (failing closed). The generated ShardDO marks them
@@ -253,7 +257,7 @@ export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${N.map(h=>JSO
253
257
  * was read at, which a claims fingerprint leaves out.
254
258
  */
255
259
  export const LUNORA_IP_READER_PATHS: ReadonlySet<string> = new Set([${$.map(h=>JSON.stringify(h)).join(", ")}]);
256
- `:"",ee=Ue(M,o,n),{fields:te,lifecycleMember:I,registry:re}=je(n,o),ne=y.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
260
+ `:"",ee=ze(_,o,n),{fields:te,lifecycleMember:I,registry:re}=Je(n,o),ne=y.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
257
261
  `:"",oe=y.length>0?`
258
262
  /**
259
263
  * AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
@@ -261,9 +265,9 @@ export const LUNORA_IP_READER_PATHS: ReadonlySet<string> = new Set([${$.map(h=>J
261
265
  * parser as a zero-allocation fast path; anything it can't model is deferred.
262
266
  */
263
267
  ${y}
264
- `:"",se=Je(n,o),{callRegisteredHelper:ae,dataModelImport:ie,implementation:ce,parameter:le,types:de}=se,ue=o?`
268
+ `:"",se=qe(n,o),{callRegisteredHelper:ae,dataModelImport:ie,implementation:ce,parameter:le,types:de}=se,ue=_e(o),he=o?`
265
269
  export interface FunctionManifestEntry {
266
- argumentDescriptors: ReadonlyArray<{ element?: string; kind: string; name: string; optional: boolean; table?: string }>;
270
+ argumentDescriptors: ReadonlyArray<{ element?: string; kind: string; name: string; optional: boolean; ${Me(e)}table?: string }>;
267
271
  channel?: { kind: "room"; name: string };
268
272
  exportName: string;
269
273
  expose?: { cache?: { credentialHeaders?: ReadonlyArray<string>; maxAge?: number; scope?: "private" | "public"; staleWhileRevalidate?: number; tag?: string; vary?: string }; rest?: boolean };
@@ -275,9 +279,9 @@ export interface FunctionManifestEntry {
275
279
  }
276
280
 
277
281
  /** Static, codegen-derived facts. Request gates can inspect these without evaluating a user module. */
278
- export const LUNORA_FUNCTION_MANIFEST: Readonly<Record<string, FunctionManifestEntry>> = {${R}};
282
+ export const LUNORA_FUNCTION_MANIFEST: Readonly<Record<string, FunctionManifestEntry>> = {${b}};
279
283
 
280
- const MODULE_LOADERS: Record<string, () => Promise<Record<string, unknown>>> = {${x}};
284
+ const MODULE_LOADERS: Record<string, () => Promise<Record<string, unknown>>> = {${A}};
281
285
  const loadedModules = new Map<string, Promise<Record<string, unknown>>>();
282
286
  const resolvedModules = new Map<string, Record<string, unknown>>();
283
287
  const boundFunctions = new Set<string>();
@@ -287,8 +291,8 @@ const unloadedFunctionHandler = (): never => {
287
291
 
288
292
  /** Reuse an evaluated module synchronously, so dispatch does not yield after restoring request scope. */
289
293
  export const getLoadedFunction = (functionPath: string): RegisteredLunoraFunction | undefined => {
290
- const registered = ${S("LUNORA_FUNCTIONS")};
291
- const manifest = ${S("LUNORA_FUNCTION_MANIFEST")};
294
+ const registered = ${P("LUNORA_FUNCTIONS")};
295
+ const manifest = ${P("LUNORA_FUNCTION_MANIFEST")};
292
296
 
293
297
  if (!registered || !manifest) {
294
298
  return registered;
@@ -319,7 +323,7 @@ export const getLoadedFunction = (functionPath: string): RegisteredLunoraFunctio
319
323
  /** Load one function's owning module once per isolate, then merge its live builder result into the registry entry. */
320
324
  export const loadFunction = async (functionPath: string): Promise<RegisteredLunoraFunction | undefined> => {
321
325
  const registered = getLoadedFunction(functionPath);
322
- const manifest = ${S("LUNORA_FUNCTION_MANIFEST")};
326
+ const manifest = ${P("LUNORA_FUNCTION_MANIFEST")};
323
327
 
324
328
  if (registered || !manifest) {
325
329
  return registered;
@@ -346,7 +350,7 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
346
350
  return getLoadedFunction(functionPath);
347
351
  };
348
352
 
349
- `:"",he=o&&R!==""?`
353
+ `:"",me=o&&b!==""?`
350
354
  /**
351
355
  * Evaluate every lazy module now and report the ones that fail, keyed by function path. A lazy
352
356
  * registry defers a broken module's error to its first call; \`lunora build\` and \`deploy\` run this
@@ -372,7 +376,7 @@ export const loadAllFunctions = async (): Promise<{ checked: number; failures: R
372
376
 
373
377
  return { checked: functionPaths.length, failures };
374
378
  };
375
- `:"";return ke(`${U}${f}${w.importLine}${O.importLine}${ne}${K}${T.typeImport}import { LunoraError } from "${l.server}";
379
+ `:"";return ke(`${U}${f}${R.importLine}${S.importLine}${ne}${K}${T.typeImport}import { LunoraError } from "${l.server}";
376
380
  import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
377
381
  ${ie}
378
382
  /**
@@ -419,13 +423,13 @@ ${T.channelField} /**
419
423
  * paywalls it; the shard refuses to subscribe it (\`isPaidFunction\`).
420
424
  */
421
425
  x402?: { readonly price: number | string };
422
- ${m}}
423
- ${w.prelude}${O.prelude}${ue}${he}
426
+ ${ue}${p}}
427
+ ${R.prelude}${S.prelude}${he}${me}
424
428
  /**
425
429
  * Static dispatch table. The key matches the \`__lunoraRef\` the client
426
430
  * emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
427
431
  */
428
- export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${A}};
432
+ export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${k}};
429
433
  ${oe}${Y}${Z}${X}${ee}${T.messagesBlock}${re}
430
434
  /**
431
435
  * Lifecycle manifest: the function paths the generated ShardDO dispatches when a
@@ -444,11 +448,11 @@ export const LUNORA_LIFECYCLE_HOOKS: {
444
448
  reactor: readonly string[];
445
449
  whisper: readonly string[];
446
450
  } = {
447
- connect: [${b.connect.map(h=>JSON.stringify(h)).join(", ")}],
448
- disconnect: [${b.disconnect.map(h=>JSON.stringify(h)).join(", ")}],
449
- init: [${b.init.map(h=>JSON.stringify(h)).join(", ")}],
450
- reactor: [${b.reactor.map(h=>JSON.stringify(h)).join(", ")}],
451
- whisper: [${b.whisper.map(h=>JSON.stringify(h)).join(", ")}],
451
+ connect: [${N.connect.map(h=>JSON.stringify(h)).join(", ")}],
452
+ disconnect: [${N.disconnect.map(h=>JSON.stringify(h)).join(", ")}],
453
+ init: [${N.init.map(h=>JSON.stringify(h)).join(", ")}],
454
+ reactor: [${N.reactor.map(h=>JSON.stringify(h)).join(", ")}],
455
+ whisper: [${N.whisper.map(h=>JSON.stringify(h)).join(", ")}],
452
456
  };
453
457
 
454
458
  /**
@@ -501,13 +505,13 @@ export interface RegisteredDataMigration {
501
505
  * Registry of online data migrations keyed by \`defineMigration\`'s \`id\`. The
502
506
  * shard DO's admin RPC and the CLI resolve migrations to run through this map.
503
507
  */
504
- export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${P}};
505
- `,c)},Ve="fn",Ke=t=>{if(t.lazyFunctions!==!0)return{};const{functions:r}=t,n=t.migrations??[],o=t.mutators??[],s=t.shapes??[],i=W(r,n,o,s),a=Q(r,n,o,s),c=[...new Set(r.filter(d=>!a.has(d.filePath)).map(d=>d.filePath))],u=J(t.useUmbrella??!1),l={};for(const d of c){if(!F.test(d))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(d)}`);const f=i.get(d)??"",y=`../../${d}.js`,$=r.filter(p=>p.filePath===d&&!p.lifecycle&&Object.keys(p.args).length>0).flatMap(p=>{const w=z(p.args);return w===void 0?[]:[`installCompiledValidatorMap(${f}.${p.exportName}.args, ${w});`]}),R=$.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${u.values}";
506
- `:"",P=$.length>0?`import * as ${f} from "${y}";
507
- `:"",x=$.length>0?`
508
+ export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${x}};
509
+ `,c)},Ze="fn",Xe=t=>{if(t.lazyFunctions!==!0)return{};const{functions:r}=t,n=t.migrations??[],o=t.mutators??[],s=t.shapes??[],i=W(r,n,o,s),a=Q(r,n,o,s),c=[...new Set(r.filter(d=>!a.has(d.filePath)).map(d=>d.filePath))],u=J(t.useUmbrella??!1),l={};for(const d of c){if(!F.test(d))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(d)}`);const f=i.get(d)??"",y=`../../${d}.js`,$=r.filter(m=>m.filePath===d&&!m.lifecycle&&Object.keys(m.args).length>0).flatMap(m=>{const R=H(m.args);return R===void 0?[]:[`installCompiledValidatorMap(${f}.${m.exportName}.args, ${R});`]}),b=$.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${u.values}";
510
+ `:"",x=$.length>0?`import * as ${f} from "${y}";
511
+ `:"",A=$.length>0?`
508
512
  /** Install the precompiled argument parsers before the module is dispatched. */
509
513
  ${$.join(`
510
514
  `)}
511
- `:"",v=r.some(p=>p.filePath===d&&p.exportName==="default")||n.some(p=>p.filePath===d&&p.exportName==="default")?`export { default } from "${y}";
512
- `:"";l[`${f}.ts`]=`${U}${R}${P}${x}export * from "${y}";
513
- ${v}`}return l};export{Ve as LAZY_FUNCTION_DIRECTORY,Ge as emitFunctions,Ke as emitLazyFunctionModules};
515
+ `:"",O=r.some(m=>m.filePath===d&&m.exportName==="default")||n.some(m=>m.filePath===d&&m.exportName==="default")?`export { default } from "${y}";
516
+ `:"";l[`${f}.ts`]=`${U}${b}${x}${A}export * from "${y}";
517
+ ${O}`}return l};export{Ze as LAZY_FUNCTION_DIRECTORY,Ye as emitFunctions,Xe as emitLazyFunctionModules};
@@ -1 +1 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-BqfSKnmG.mjs";import"./shard-runtime-C1P_uVye.mjs";import"./shared-DhqnD5R3.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
1
+ import"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-t1Jkywmh.mjs";import"./shard-runtime-C1P_uVye.mjs";import"./shared-DhqnD5R3.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
@@ -792,7 +792,17 @@ __PREPARE_FUNCTION__ const registered = LUNORA_FUNCTIONS[functionPath
792
792
  });
793
793
  }
794
794
 
795
- const result = await registered.handler(ctx, args);
795
+ // An action's unawaited I/O can be cancelled after the response, so its
796
+ // ctx counts what is still in flight when the handler returns.
797
+ // Reported on a throw too: the pending calls are just as abandoned.
798
+ const finishActionWork = registered.kind === "action" ? this.watchActionWork(functionPath, ctx) : undefined;
799
+ let result: unknown;
800
+
801
+ try {
802
+ result = await registered.handler(ctx, args);
803
+ } finally {
804
+ finishActionWork?.();
805
+ }
796
806
 
797
807
  // Composed mutations settle their own delete queues. An action can
798
808
  // also queue deletes outside those mutations; drain its own queue here.
@@ -936,7 +946,7 @@ __PREPARE_FUNCTION__ this.ensureServable();
936
946
  // Identity is threaded EXPLICITLY from the (deferred/interleaved)
937
947
  // subscription caller — never read from the shared per-request field
938
948
  // here — so a concurrent RPC can't leak its identity into this re-run.
939
- const ctx = this.buildCtx({ functionPath, headroom: this.subscriptionHeadroom(), identity, onRead: footprint.onRead, onReadRange: footprint.onReadRange });
949
+ const ctx = this.buildCtx({ functionPath, headroom: this.subscriptionHeadroom(functionPath, identity), identity, onRead: footprint.onRead, onReadRange: footprint.onReadRange });
940
950
  const result = await registered.handler(ctx, args);
941
951
 
942
952
  // Ranges come from THIS run's reads, never a shared field on the DO:
@@ -965,7 +975,11 @@ __PREPARE_FUNCTION__ this.ensureServable();
965
975
  // frame returned, interleaved with unrelated dispatches, so
966
976
  // \`buildCtx\`'s per-request fallback would run an \`rls()\` /
967
977
  // \`ctx.auth\` stream as nobody — or as a concurrent RPC's caller.
968
- iterator: (signal) => (registered.handler as (context: unknown, args: Record<string, unknown>, signal: AbortSignal) => AsyncIterable<unknown>)(this.buildCtx({ functionPath, identity }), args, signal),
978
+ iterator: (signal) => {
979
+ const headroom = this.streamHeadroom(functionPath, identity);
980
+
981
+ return this.windowStreamReads(headroom, (registered.handler as (context: unknown, args: Record<string, unknown>, signal: AbortSignal) => AsyncIterable<unknown>)(this.buildCtx({ functionPath, headroom, identity }), args, signal));
982
+ },
969
983
  };
970
984
  }`,qr=` } catch (error) {
971
985
  // The write committed before this failed. Mark the error so the caller can tell
@@ -1394,7 +1408,7 @@ ${_.map(s=>` [${JSON.stringify(s.id)}, () => import("../${s.filePath}
1394
1408
  // reach it; \`onConnect\`/\`onDisconnect\` carry a verified identity and
1395
1409
  // stay guarded like any request.
1396
1410
  enforceRls: options.trusted !== true,
1397
- headroom: options.headroom ?? this.transactionHeadroom(),
1411
+ headroom: options.headroom ?? this.transactionHeadroom(options.functionPath),
1398
1412
  // A live predicate, not a flag: the transaction opens AFTER this ctx
1399
1413
  // is built (a mutation dispatch wraps the handler), so only a call-time
1400
1414
  // read reports the truth. \`_commitSeq\` reuses one sequence across
@@ -1747,7 +1761,7 @@ ${c?` const requestScope = this.captureRequestScope();
1747
1761
  this.ensureServable();
1748
1762
 
1749
1763
  const footprint = createReadFootprint();
1750
- const ctx = this.buildCtx({ functionPath, headroom: this.subscriptionHeadroom(), onRead: footprint.onRead, onReadRange: footprint.onReadRange, replayKey: false, trusted: true });
1764
+ const ctx = this.buildCtx({ functionPath, headroom: this.subscriptionHeadroom(functionPath), onRead: footprint.onRead, onReadRange: footprint.onReadRange, replayKey: false, trusted: true });
1751
1765
  const outcome = (await this.runMutationTransaction(ctx, async () =>
1752
1766
  registered.handler(ctx, { previousDigest } as unknown as Record<string, unknown>),
1753
1767
  )) as {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.385",
3
+ "version": "1.0.0-alpha.387",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,15 +50,15 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/advisor": "1.0.0-alpha.281",
54
- "@lunora/agent": "1.0.0-alpha.273",
55
- "@lunora/container": "1.0.0-alpha.105",
53
+ "@lunora/advisor": "1.0.0-alpha.282",
54
+ "@lunora/agent": "1.0.0-alpha.274",
55
+ "@lunora/container": "1.0.0-alpha.106",
56
56
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
57
- "@lunora/platform": "1.0.0-alpha.77",
58
- "@lunora/queue": "1.0.0-alpha.139",
59
- "@lunora/scheduler": "1.0.0-alpha.164",
60
- "@lunora/values": "1.0.0-alpha.91",
61
- "@lunora/workflow": "1.0.0-alpha.107",
57
+ "@lunora/platform": "1.0.0-alpha.78",
58
+ "@lunora/queue": "1.0.0-alpha.140",
59
+ "@lunora/scheduler": "1.0.0-alpha.165",
60
+ "@lunora/values": "1.0.0-alpha.92",
61
+ "@lunora/workflow": "1.0.0-alpha.108",
62
62
  "@visulima/fs": "7.0.0",
63
63
  "jiti": "^2.7.0",
64
64
  "quicktype-core": "^26.0.0",