@lunora/codegen 1.0.0-alpha.104 → 1.0.0-alpha.105

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.d.mts CHANGED
@@ -3387,7 +3387,15 @@ interface OpenRpcDocument {
3387
3387
  type RuntimeVerb = "action" | "mutation" | "query";
3388
3388
  /** One RPC function, parsed and language-neutral. */
3389
3389
  interface SdkMethod {
3390
- /** Generated args model name, or `undefined` when the function takes none. */
3390
+ /**
3391
+ * Generated args model name, or `undefined` when NO model could be named for
3392
+ * this function's arguments.
3393
+ *
3394
+ * `undefined` does NOT mean "takes no arguments" — see {@link SdkMethod.takesArgs}.
3395
+ * A schema carrying a `v.bigint()` or `v.bytes()` gets no model deliberately
3396
+ * (`hasUnrepresentableWireType`), and a backend that cannot name a shape leaves
3397
+ * it undeclared. Both still take arguments, just untyped ones.
3398
+ */
3391
3399
  argsType: string | undefined;
3392
3400
  /** Raw exported function name (`"list"`), before any naming convention. */
3393
3401
  functionName: string;
@@ -3399,6 +3407,16 @@ interface SdkMethod {
3399
3407
  resultType: string | undefined;
3400
3408
  /** Human summary for the doc comment. */
3401
3409
  summary: string;
3410
+ /**
3411
+ * Whether this function declares arguments at all, independent of whether a
3412
+ * model could be named for them.
3413
+ *
3414
+ * A target emits three shapes from this: a TYPED parameter when `argsType` is
3415
+ * set, an UNTYPED wire-shaped parameter when it is not but this is true, and no
3416
+ * parameter at all when this is false. Collapsing the middle case into the last
3417
+ * is what made `v.bigint()` functions uncallable with arguments.
3418
+ */
3419
+ takesArgs: boolean;
3402
3420
  /** Which runtime verb this dispatches to. */
3403
3421
  verb: RuntimeVerb;
3404
3422
  }
package/dist/index.d.ts CHANGED
@@ -3387,7 +3387,15 @@ interface OpenRpcDocument {
3387
3387
  type RuntimeVerb = "action" | "mutation" | "query";
3388
3388
  /** One RPC function, parsed and language-neutral. */
3389
3389
  interface SdkMethod {
3390
- /** Generated args model name, or `undefined` when the function takes none. */
3390
+ /**
3391
+ * Generated args model name, or `undefined` when NO model could be named for
3392
+ * this function's arguments.
3393
+ *
3394
+ * `undefined` does NOT mean "takes no arguments" — see {@link SdkMethod.takesArgs}.
3395
+ * A schema carrying a `v.bigint()` or `v.bytes()` gets no model deliberately
3396
+ * (`hasUnrepresentableWireType`), and a backend that cannot name a shape leaves
3397
+ * it undeclared. Both still take arguments, just untyped ones.
3398
+ */
3391
3399
  argsType: string | undefined;
3392
3400
  /** Raw exported function name (`"list"`), before any naming convention. */
3393
3401
  functionName: string;
@@ -3399,6 +3407,16 @@ interface SdkMethod {
3399
3407
  resultType: string | undefined;
3400
3408
  /** Human summary for the doc comment. */
3401
3409
  summary: string;
3410
+ /**
3411
+ * Whether this function declares arguments at all, independent of whether a
3412
+ * model could be named for them.
3413
+ *
3414
+ * A target emits three shapes from this: a TYPED parameter when `argsType` is
3415
+ * set, an UNTYPED wire-shaped parameter when it is not but this is true, and no
3416
+ * parameter at all when this is false. Collapsing the middle case into the last
3417
+ * is what made `v.bigint()` functions uncallable with arguments.
3418
+ */
3419
+ takesArgs: boolean;
3402
3420
  /** Which runtime verb this dispatches to. */
3403
3421
  verb: RuntimeVerb;
3404
3422
  }
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-CQvIhQ04.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-Dk-k250h.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-XfNbxqlq.mjs";import{CONTAINERS_FILENAME as g,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-DQpyhY6c.mjs";import{default as h}from"./packem_shared/discoverCrons-RlATa0_t.mjs";import{FLAGS_FILENAME as L,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-Boqm0YCP.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-4TNKUv7P.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-DQivLBqT.mjs";import{default as G}from"./packem_shared/discoverInserts-D6szWzrV.mjs";import{default as y}from"./packem_shared/discoverMaskProcedures-BBPqLXA5.mjs";import{default as k}from"./packem_shared/discoverMigrations-rbjxflR8.mjs";import{MUTATORS_FILENAME as W,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-Cp_JxLSz.mjs";import{default as j}from"./packem_shared/discoverNondeterministicCalls-Bxr652Rz.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as B,discoverNotifyConfig as q}from"./packem_shared/NOTIFY_FILENAME-DwyJ5I4Q.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-CogJX1Ia.mjs";import{y as X}from"./packem_shared/discover-queries-i4Vd2si7.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-QpMZsde0.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-DMxG6gHr.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-B63ARnKG.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-DBM98vVh.mjs";import{default as fe}from"./packem_shared/discoverSchema-BNr7PVcZ.mjs";import{SHAPES_FILENAME as ne,discoverShapes as Se}from"./packem_shared/SHAPES_FILENAME-WxXOsYfe.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-_40MGqRX.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-Dz80zqeT.mjs";import{S as Ne,h as Oe,P as Re,B as ge,p as Ce,L as Me,R as he,C as _e,V as Le,Q as Ie,$ as Te,E as Fe,m as De,F as Pe}from"./packem_shared/emit-B8FxCABN.mjs";import{emitApp as Ge}from"./packem_shared/emitApp-Dg-jOuj6.mjs";import{buildOpenApiDocument as ye,emitOpenApi as be,emitOpenApiModule as ke}from"./packem_shared/buildOpenApiDocument-CDYoRVC6.mjs";import{OPENRPC_VERSION as We,buildOpenRpcDocument as Ke,emitOpenRpc as Qe,emitOpenRpcModule as je}from"./packem_shared/OPENRPC_VERSION-CBWjXJgS.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as Be,readProjectTarget as qe,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CH5disA3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as $e,createCodegenProject as Xe,refreshCodegenProject as Ze,runCodegen as er}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BM6kIe4w.mjs";import{SchemaSnapshotParseError as or,buildSchemaSnapshot as tr,evaluateSchemaDrift as sr,parseSchemaSnapshot as ar}from"./packem_shared/SchemaSnapshotParseError-BkgxjBPQ.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as fr}from"./packem_shared/LUNORA_ERROR_CODES-zfAI2OFs.mjs";import{SDK_LANGUAGES as nr,SDK_TARGETS as Sr,generateSdk as lr}from"./packem_shared/SDK_LANGUAGES-CAGhWtBh.mjs";import{redact as xr,secretKindOf as Ar}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as vr,findSolutionByMessage as Nr}from"@lunora/errors";import{isTypedSchema as Rr}from"./packem_shared/isTypedSchema-C-UHYeJq.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,g as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,L as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,vr as LUNORA_SOLUTION_RULES,W as MUTATORS_FILENAME,w as NOTIFY_FILENAME,We as OPENRPC_VERSION,ee as QUEUES_FILENAME,$e as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,nr as SDK_LANGUAGES,Sr as SDK_TARGETS,ne as SHAPES_FILENAME,or as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,ye as buildOpenApiDocument,Ke as buildOpenRpcDocument,tr as buildSchemaSnapshot,Xe as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,y as discoverMaskProcedures,k as discoverMigrations,K as discoverMutators,j as discoverNondeterministicCalls,B as discoverNotifyCalls,q as discoverNotifyConfig,X as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,fe as discoverSchema,Se as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,Oe as emitAgents,Re as emitApi,Ge as emitApp,ge as emitCollections,Ce as emitContainers,Me as emitCrons,he as emitDataModel,_e as emitDrizzleSchema,Le as emitFunctions,be as emitOpenApi,ke as emitOpenApiModule,Qe as emitOpenRpc,je as emitOpenRpcModule,Ie as emitServer,Te as emitShard,Fe as emitVectors,De as emitWorkflows,Pe as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,sr as evaluateSchemaDrift,Nr as findLunoraSolution,m as formatAdvisories,lr as generateSdk,Rr as isTypedSchema,d as lintSchema,ar as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,qe as readProjectTarget,xr as redact,Ze as refreshCodegenProject,Je as resolveCodegenTarget,er as runCodegen,mr as schemaFromIr,Ar as secretKindOf,a as serializeSchemaSnapshot,p as toAdvisorContext,fr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-CQvIhQ04.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-Dk-k250h.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-XfNbxqlq.mjs";import{CONTAINERS_FILENAME as g,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-DQpyhY6c.mjs";import{default as h}from"./packem_shared/discoverCrons-RlATa0_t.mjs";import{FLAGS_FILENAME as L,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-Boqm0YCP.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-4TNKUv7P.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-DQivLBqT.mjs";import{default as G}from"./packem_shared/discoverInserts-D6szWzrV.mjs";import{default as y}from"./packem_shared/discoverMaskProcedures-BBPqLXA5.mjs";import{default as k}from"./packem_shared/discoverMigrations-rbjxflR8.mjs";import{MUTATORS_FILENAME as W,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-Cp_JxLSz.mjs";import{default as j}from"./packem_shared/discoverNondeterministicCalls-Bxr652Rz.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as B,discoverNotifyConfig as q}from"./packem_shared/NOTIFY_FILENAME-DwyJ5I4Q.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-CogJX1Ia.mjs";import{y as X}from"./packem_shared/discover-queries-i4Vd2si7.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-QpMZsde0.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-DMxG6gHr.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-B63ARnKG.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-DBM98vVh.mjs";import{default as fe}from"./packem_shared/discoverSchema-BNr7PVcZ.mjs";import{SHAPES_FILENAME as ne,discoverShapes as Se}from"./packem_shared/SHAPES_FILENAME-WxXOsYfe.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-_40MGqRX.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-Dz80zqeT.mjs";import{S as Ne,h as Oe,P as Re,B as ge,p as Ce,L as Me,R as he,C as _e,V as Le,Q as Ie,$ as Te,E as Fe,m as De,F as Pe}from"./packem_shared/emit-B8FxCABN.mjs";import{emitApp as Ge}from"./packem_shared/emitApp-Dg-jOuj6.mjs";import{buildOpenApiDocument as ye,emitOpenApi as be,emitOpenApiModule as ke}from"./packem_shared/buildOpenApiDocument-CDYoRVC6.mjs";import{OPENRPC_VERSION as We,buildOpenRpcDocument as Ke,emitOpenRpc as Qe,emitOpenRpcModule as je}from"./packem_shared/OPENRPC_VERSION-CBWjXJgS.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as Be,readProjectTarget as qe,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CH5disA3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as $e,createCodegenProject as Xe,refreshCodegenProject as Ze,runCodegen as er}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BM6kIe4w.mjs";import{SchemaSnapshotParseError as or,buildSchemaSnapshot as tr,evaluateSchemaDrift as sr,parseSchemaSnapshot as ar}from"./packem_shared/SchemaSnapshotParseError-BkgxjBPQ.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as fr}from"./packem_shared/LUNORA_ERROR_CODES-zfAI2OFs.mjs";import{SDK_LANGUAGES as nr,SDK_TARGETS as Sr,generateSdk as lr}from"./packem_shared/SDK_LANGUAGES-fIqQtE14.mjs";import{redact as xr,secretKindOf as Ar}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as vr,findSolutionByMessage as Nr}from"@lunora/errors";import{isTypedSchema as Rr}from"./packem_shared/isTypedSchema-9wiKtXr2.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,g as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,L as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,vr as LUNORA_SOLUTION_RULES,W as MUTATORS_FILENAME,w as NOTIFY_FILENAME,We as OPENRPC_VERSION,ee as QUEUES_FILENAME,$e as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,nr as SDK_LANGUAGES,Sr as SDK_TARGETS,ne as SHAPES_FILENAME,or as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,ye as buildOpenApiDocument,Ke as buildOpenRpcDocument,tr as buildSchemaSnapshot,Xe as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,y as discoverMaskProcedures,k as discoverMigrations,K as discoverMutators,j as discoverNondeterministicCalls,B as discoverNotifyCalls,q as discoverNotifyConfig,X as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,fe as discoverSchema,Se as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,Oe as emitAgents,Re as emitApi,Ge as emitApp,ge as emitCollections,Ce as emitContainers,Me as emitCrons,he as emitDataModel,_e as emitDrizzleSchema,Le as emitFunctions,be as emitOpenApi,ke as emitOpenApiModule,Qe as emitOpenRpc,je as emitOpenRpcModule,Ie as emitServer,Te as emitShard,Fe as emitVectors,De as emitWorkflows,Pe as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,sr as evaluateSchemaDrift,Nr as findLunoraSolution,m as formatAdvisories,lr as generateSdk,Rr as isTypedSchema,d as lintSchema,ar as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,qe as readProjectTarget,xr as redact,Ze as refreshCodegenProject,Je as resolveCodegenTarget,er as runCodegen,mr as schemaFromIr,Ar as secretKindOf,a as serializeSchemaSnapshot,p as toAdvisorContext,fr as validatorIrToJsonSchema};
@@ -1,19 +1,19 @@
1
- import{modelSources as ne,toPascalCase as s,generatedHeaderLines as f,commentText as l,stringLiteral as d,kotlinLiteral as h,referencedModels as R,allMethods as C,toSnakeCase as H,parseSpec as me,assertGeneratable as $e,withDeclaredModels as fe,unrepresentableFunctions as ye,undeclaredModels as he}from"./isTypedSchema-C-UHYeJq.mjs";import{isTypedSchema as Ir}from"./isTypedSchema-C-UHYeJq.mjs";const ge=async(e,r)=>{if(r.quicktype===void 0)return"";const t=ne(e);if(t.length===0)return"";const{InputData:n,JSONSchemaInput:a,JSONSchemaStore:i,quicktype:o}=await import("quicktype-core");class c extends i{fetch(){return Promise.resolve(void 0)}}const p=new a(new c);for(const O of t)await p.addSource({name:O.name,schema:JSON.stringify(O.schema)});const u=new n;u.addInput(p);const{lines:$}=await o({inputData:u,lang:r.quicktype.lang,rendererOptions:r.quicktype.rendererOptions??{}});return $.join(`
2
- `)},W=`${f("go").map(e=>`// ${e}`).join(`
1
+ import{modelSources as ae,toPascalCase as s,generatedHeaderLines as y,commentText as l,argsChoice as d,stringLiteral as p,kotlinLiteral as g,referencedModels as H,allMethods as M,toSnakeCase as z,parseSpec as he,assertGeneratable as ge,withDeclaredModels as be,unrepresentableFunctions as ve,undeclaredModels as we}from"./isTypedSchema-9wiKtXr2.mjs";import{isTypedSchema as zr}from"./isTypedSchema-9wiKtXr2.mjs";const je=async(e,r)=>{if(r.quicktype===void 0)return"";const t=ae(e);if(t.length===0)return"";const{InputData:n,JSONSchemaInput:a,JSONSchemaStore:i,quicktype:o}=await import("quicktype-core");class c extends i{fetch(){return Promise.resolve(void 0)}}const $=new a(new c);for(const W of t)await $.addSource({name:W.name,schema:JSON.stringify(W.schema)});const u=new n;u.addInput($);const{lines:f}=await o({inputData:u,lang:r.quicktype.lang,rendererOptions:r.quicktype.rendererOptions??{}});return f.join(`
2
+ `)},V=`${y("go").map(e=>`// ${e}`).join(`
3
3
  `)}
4
4
 
5
- `,y="lunoraapi",j="lunorasdk",ve=`${j}/lunora`,be="1.22",M=e=>s(e),U=(e,r)=>{const t=r.argsType===void 0?"":`args ${r.argsType}, `,n=r.argsType===void 0?"nil":"args",a=r.resultType??"any",i=`lunora.Verb${r.verb.charAt(0).toUpperCase()}${r.verb.slice(1)}`,o=`lunora.Call[${a}](a.client, ${i}, "${d(r.functionPath)}", ${n}, shardKey)`;return[`// ${M(r.functionName)} invokes ${l(r.summary)}.`,`func (a *${e}) ${M(r.functionName)}(${t}shardKey string) (${a}, error) {`,` return ${o}`,"}"].join(`
6
- `)},we=(e,r)=>{const t=r.argsType===void 0?"":`args ${r.argsType}, `,n=r.argsType===void 0?"nil":"args",a=`Subscribe${M(r.functionName)}`;return[`// ${a} opens a live ${l(r.functionPath)}; it re-runs on every write to the tables it reads.`,`func (a *${e}) ${a}(${t}onData lunora.DataHandler, onError lunora.ErrorHandler, shardKey string) lunora.Unsubscribe {`,` return a.client.Subscribe("${d(r.functionPath)}", ${n}, onData, onError, shardKey)`,"}"].join(`
7
- `)},je=e=>{const r=`${s(e.name)}API`,t=e.methods.map(n=>n.verb==="query"?`${U(r,n)}
5
+ `,h="lunoraapi",k="lunorasdk",ke=`${k}/lunora`,_e="1.22",E=e=>s(e),B=(e,r)=>{const t=d(r,{none:"",typed:c=>`args ${c}, `,untyped:"args any, "}),n=d(r,{none:"nil",typed:()=>"args",untyped:"args"}),a=r.resultType??"any",i=`lunora.Verb${r.verb.charAt(0).toUpperCase()}${r.verb.slice(1)}`,o=`lunora.Call[${a}](a.client, ${i}, "${p(r.functionPath)}", ${n}, shardKey)`;return[`// ${E(r.functionName)} invokes ${l(r.summary)}.`,`func (a *${e}) ${E(r.functionName)}(${t}shardKey string) (${a}, error) {`,` return ${o}`,"}"].join(`
6
+ `)},Se=(e,r)=>{const t=d(r,{none:"",typed:i=>`args ${i}, `,untyped:"args any, "}),n=d(r,{none:"nil",typed:()=>"args",untyped:"args"}),a=`Subscribe${E(r.functionName)}`;return[`// ${a} opens a live ${l(r.functionPath)}; it re-runs on every write to the tables it reads.`,`func (a *${e}) ${a}(${t}onData lunora.DataHandler, onError lunora.ErrorHandler, shardKey string) lunora.Unsubscribe {`,` return a.client.Subscribe("${p(r.functionPath)}", ${n}, onData, onError, shardKey)`,"}"].join(`
7
+ `)},Ae=e=>{const r=`${s(e.name)}API`,t=e.methods.map(n=>n.verb==="query"?`${B(r,n)}
8
8
 
9
- ${we(r,n)}`:U(r,n)).join(`
9
+ ${Se(r,n)}`:B(r,n)).join(`
10
10
 
11
11
  `);return[`// ${r} groups the functions declared in ${l(e.name)}.`,`type ${r} struct{ client *lunora.Client }`,"",t].join(`
12
- `)},ke=({models:e,namespaces:r})=>{const t=r.map(o=>` ${s(o.name)} *${s(o.name)}API`).join(`
12
+ `)},Te=({models:e,namespaces:r})=>{const t=r.map(o=>` ${s(o.name)} *${s(o.name)}API`).join(`
13
13
  `),n=r.map(o=>` ${s(o.name)}: &${s(o.name)}API{client: client},`).join(`
14
- `),a=[W,`package ${y}
14
+ `),a=[V,`package ${h}
15
15
  `,`
16
- `,`import "${ve}"
16
+ `,`import "${ke}"
17
17
  `,`
18
18
  `,`// API is the typed entry point: api.<Namespace>.<Function>(args, shardKey).
19
19
  `,`type API struct {
@@ -27,45 +27,45 @@ ${we(r,n)}`:U(r,n)).join(`
27
27
  `,` }
28
28
  `,`}
29
29
  `,`
30
- `,r.map(o=>je(o)).join(`
30
+ `,r.map(o=>Ae(o)).join(`
31
31
 
32
32
  `),`
33
- `].join(""),i=e.length>0?`${W}package ${y}
33
+ `].join(""),i=e.length>0?`${V}package ${h}
34
34
 
35
35
  ${e}
36
- `:`${W}package ${y}
36
+ `:`${V}package ${h}
37
37
 
38
38
  // No typed argument or result schemas in this deployment.
39
- `;return{[`${y}/api.go`]:a,[`${y}/models.go`]:i,"go.mod":[`// The generated Lunora Go SDK, with the transport vendored under ./lunora.
39
+ `;return{[`${h}/api.go`]:a,[`${h}/models.go`]:i,"go.mod":[`// The generated Lunora Go SDK, with the transport vendored under ./lunora.
40
40
  `,`//
41
41
  `,`// A consuming module wires it in without a network fetch:
42
42
  `,`//
43
- `,`// require ${j} v0.0.0
44
- `,`// replace ${j} => ./path/to/this/directory
45
- `,`module ${j}
43
+ `,`// require ${k} v0.0.0
44
+ `,`// replace ${k} => ./path/to/this/directory
45
+ `,`module ${k}
46
46
  `,`
47
- `,`go ${be}
48
- `].join("")}},Te={id:"go",quicktype:{lang:"go",rendererOptions:{"just-types":"true",package:y}},render:ke,requires:[],vendor:[{from:"lunora",to:"lunora"}]},g="lunoraapi.models",E="lunoraapi/models",_e=24,Se=new Set(["abstract","as","assert","boolean","break","byte","case","catch","char","class","const","continue","default","do","double","else","enum","extends","false","final","finally","float","for","fromWire","fun","goto","if","implements","import","in","instanceof","int","interface","is","long","native","new","null","object","package","private","protected","public","return","short","static","strictfp","super","switch","synchronized","this","throw","throws","toWire","transient","true","try","typealias","typeof","val","var","void","volatile","when","while","wireValue"]),Ae=/[^A-Za-z0-9]+/gu,Oe=/([a-z0-9])([A-Z])/gu,We=/^[A-Za-z]/u,Ve=/^[A-Z]/u;let ae=class extends Error{};const m=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0,Le=e=>{const r=e.anyOf??e.oneOf;if(!Array.isArray(r)||r.length===0)return;const t=r.map(n=>m(n)?.const);if(t.every(n=>typeof n=="string"))return[...new Set(t)].toSorted((n,a)=>n.localeCompare(a))},ie=e=>{const r=e.anyOf??e.oneOf;if(!Array.isArray(r)||r.length!==2)return e;const t=r.filter(n=>m(n)?.type!=="null");return t.length===1?m(t[0])??e:e},Ne=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1),n=We.test(t)?t:`value${r}`;return Se.has(n)?`${n}_`:n},Ce=e=>{const r=e.replaceAll(Oe,"$1_$2").replaceAll(Ae,"_").toUpperCase().split("_").filter(t=>t.length>0).join("_");return Ve.test(r)?r:`VALUE_${r}`},oe=(e,r)=>{if(!r.has(e))return r.add(e),e;let t=2;for(;r.has(`${e}${String(t)}`);)t+=1;return r.add(`${e}${String(t)}`),`${e}${String(t)}`},B=(e,r)=>{if(e.has(r.name))throw new ae(`sdk: two schemas both produce the JVM model "${r.name}"`);e.set(r.name,r)},Me=(e,r,t,n,a)=>{const i=new Set(Array.isArray(r)?r.filter(c=>typeof c=="string"):[]),o=new Set;return Object.entries(e).map(([c,p])=>{const u=m(p)??{},$=!i.has(c);return{name:oe(Ne(c),o),nullable:!$&&ie(u)!==u,optional:$,type:v(u,`${t}${s(c)}`,n+1,a),wireKey:c}})},v=(e,r,t,n)=>{if(t>=_e)return{kind:"unknown"};const a=Le(e);if(a!==void 0){const u=new Set;return B(n,{constants:a.map($=>({name:oe(Ce($),u),wireValue:$})),kind:"enum",name:r}),{kind:"enum",name:r}}const i=ie(e);if(i!==e)return v(i,r,t+1,n);const o=m(e.properties);if(o!==void 0)return B(n,{fields:Me(o,e.required,r,t,n),kind:"class",name:r}),{kind:"class",name:r};const c=m(e.additionalProperties);if(c!==void 0)return{kind:"record",value:v(c,`${r}Value`,t+1,n)};const p=m(e.items);if(p!==void 0)return{item:v(p,`${r}Item`,t+1,n),kind:"list"};switch(e.type){case"boolean":return{kind:"boolean"};case"integer":case"number":return{kind:"number"};case"string":return{kind:"string"};default:return{kind:"unknown"}}},se=e=>{const r=new Map;for(const t of ne(e)){if(m(t.schema.properties)===void 0)continue;const n=new Map;try{v(t.schema,t.name,0,n)}catch(a){if(a instanceof ae)continue;throw a}if(![...n.keys()].some(a=>r.has(a)))for(const[a,i]of n)r.set(a,i)}return[...r.values()].toSorted((t,n)=>t.name.localeCompare(n.name))},A=e=>[`// GENERATED by \`lunora sdk generate --lang ${e}\` — do not edit.`,"// Run the command again to regenerate."],T=e=>{switch(e.kind){case"boolean":return"Boolean";case"class":case"enum":return e.name;case"list":return`java.util.List<${T(e.item)}>`;case"number":return"Double";case"record":return`java.util.Map<String, ${T(e.value)}>`;case"string":return"String";default:return"Object"}},P=e=>{switch(e.kind){case"class":case"enum":return!0;case"list":return P(e.item);case"record":return P(e.value);default:return!1}},K=(e,r,t)=>{if(!P(e))return r;const n=`item${String(t)}`;switch(e.kind){case"class":return`${r} == null ? null : ${r}.toWire()`;case"enum":return`${r} == null ? null : ${r}.toValue()`;case"list":return`ModelWire.writeList(${r}, ${n} -> ${K(e.item,n,t+1)})`;case"record":return`ModelWire.writeRecord(${r}, ${n} -> ${K(e.value,n,t+1)})`;default:return r}},x=(e,r,t)=>{const n=`item${String(t)}`;switch(e.kind){case"boolean":return`ModelWire.flag(${r})`;case"class":return`ModelWire.readObject(${r}, ${e.name}::fromWire)`;case"enum":return`ModelWire.readEnum(${r}, ${e.name}::forValue)`;case"list":return`ModelWire.readList(${r}, ${n} -> ${x(e.item,n,t+1)})`;case"number":return`ModelWire.number(${r})`;case"record":return`ModelWire.readRecord(${r}, ${n} -> ${x(e.value,n,t+1)})`;case"string":return`ModelWire.text(${r})`;default:return r}},Ee=e=>{const r=l(e.wireKey);return e.optional?[" /**",` * Wire key {@code ${r}} — OPTIONAL: null omits the key entirely, because`," * `v.optional` accepts the value or `undefined` and rejects an explicit null."," */"]:[` /** Wire key {@code ${r}}.${e.nullable?" Nullable: null is sent as an explicit null.":""} */`]},Pe=100,Ke=e=>{const r=e.fields.map(n=>`${T(n.type)} ${n.name}`),t=` public ${e.name}(${r.join(", ")}) {`;return t.length<=Pe?[t]:[` public ${e.name}(`,...r.map((n,a)=>` ${n}${a===r.length-1?") {":","}`)]},xe=e=>{const r=e.fields.flatMap(n=>{const a=`wire.put("${d(n.wireKey)}", ${K(n.type,`this.${n.name}`,0)});`;return n.optional?[` if (this.${n.name} != null) {`,` ${a}`," }"]:[` ${a}`]}),t=e.fields.map(n=>` ${x(n.type,`wire.get("${d(n.wireKey)}")`,0)}`);return[...A("java"),"",`package ${g};`,"","/**",` * The \`${e.name}\` model.`," *"," * <p>Field names are local; the keys {@link #toWire()} and {@link #fromWire(Object)} use are"," * the schema's own, emitted verbatim, so a renamed field cannot reach the wire."," */",`public final class ${e.name} {`,...e.fields.flatMap(n=>[...Ee(n),` public final ${T(n.type)} ${n.name};`,""]),...Ke(e),...e.fields.map(n=>` this.${n.name} = ${n.name};`)," }",""," /** This model as the wire-shaped map the transport encodes. */"," public java.util.Map<String, Object> toWire() {"," java.util.Map<String, Object> wire = new java.util.LinkedHashMap<>();",...r,""," return wire;"," }",""," /** Rebuild from a decoded wire value. */",` public static ${e.name} fromWire(Object value) {`," java.util.Map<String, Object> wire = ModelWire.object(value);","",...t.length===0?[` return new ${e.name}();`]:[` return new ${e.name}(`,`${t.join(`,
47
+ `,`go ${_e}
48
+ `].join("")}},Oe={id:"go",quicktype:{lang:"go",rendererOptions:{"just-types":"true",package:h}},render:Te,requires:[],vendor:[{from:"lunora",to:"lunora"}]},b="lunoraapi.models",P="lunoraapi/models",We=24,Ve=new Set(["abstract","as","assert","boolean","break","byte","case","catch","char","class","const","continue","default","do","double","else","enum","extends","false","final","finally","float","for","fromWire","fun","goto","if","implements","import","in","instanceof","int","interface","is","long","native","new","null","object","package","private","protected","public","return","short","static","strictfp","super","switch","synchronized","this","throw","throws","toWire","transient","true","try","typealias","typeof","val","var","void","volatile","when","while","wireValue"]),Le=/[^A-Za-z0-9]+/gu,Ne=/([a-z0-9])([A-Z])/gu,Ce=/^[A-Za-z]/u,Me=/^[A-Z]/u;let ie=class extends Error{};const m=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0,Ee=e=>{const r=e.anyOf??e.oneOf;if(!Array.isArray(r)||r.length===0)return;const t=r.map(n=>m(n)?.const);if(t.every(n=>typeof n=="string"))return[...new Set(t)].toSorted((n,a)=>n.localeCompare(a))},oe=e=>{const r=e.anyOf??e.oneOf;if(!Array.isArray(r)||r.length!==2)return e;const t=r.filter(n=>m(n)?.type!=="null");return t.length===1?m(t[0])??e:e},Pe=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1),n=Ce.test(t)?t:`value${r}`;return Ve.has(n)?`${n}_`:n},Ke=e=>{const r=e.replaceAll(Ne,"$1_$2").replaceAll(Le,"_").toUpperCase().split("_").filter(t=>t.length>0).join("_");return Me.test(r)?r:`VALUE_${r}`},se=(e,r)=>{if(!r.has(e))return r.add(e),e;let t=2;for(;r.has(`${e}${String(t)}`);)t+=1;return r.add(`${e}${String(t)}`),`${e}${String(t)}`},J=(e,r)=>{if(e.has(r.name))throw new ie(`sdk: two schemas both produce the JVM model "${r.name}"`);e.set(r.name,r)},xe=(e,r,t,n,a)=>{const i=new Set(Array.isArray(r)?r.filter(c=>typeof c=="string"):[]),o=new Set;return Object.entries(e).map(([c,$])=>{const u=m($)??{},f=!i.has(c);return{name:se(Pe(c),o),nullable:!f&&oe(u)!==u,optional:f,type:v(u,`${t}${s(c)}`,n+1,a),wireKey:c}})},v=(e,r,t,n)=>{if(t>=We)return{kind:"unknown"};const a=Ee(e);if(a!==void 0){const u=new Set;return J(n,{constants:a.map(f=>({name:se(Ke(f),u),wireValue:f})),kind:"enum",name:r}),{kind:"enum",name:r}}const i=oe(e);if(i!==e)return v(i,r,t+1,n);const o=m(e.properties);if(o!==void 0)return J(n,{fields:xe(o,e.required,r,t,n),kind:"class",name:r}),{kind:"class",name:r};const c=m(e.additionalProperties);if(c!==void 0)return{kind:"record",value:v(c,`${r}Value`,t+1,n)};const $=m(e.items);if($!==void 0)return{item:v($,`${r}Item`,t+1,n),kind:"list"};switch(e.type){case"boolean":return{kind:"boolean"};case"integer":case"number":return{kind:"number"};case"string":return{kind:"string"};default:return{kind:"unknown"}}},le=e=>{const r=new Map;for(const t of ae(e)){if(m(t.schema.properties)===void 0)continue;const n=new Map;try{v(t.schema,t.name,0,n)}catch(a){if(a instanceof ie)continue;throw a}if(![...n.keys()].some(a=>r.has(a)))for(const[a,i]of n)r.set(a,i)}return[...r.values()].toSorted((t,n)=>t.name.localeCompare(n.name))},O=e=>[`// GENERATED by \`lunora sdk generate --lang ${e}\` — do not edit.`,"// Run the command again to regenerate."],S=e=>{switch(e.kind){case"boolean":return"Boolean";case"class":case"enum":return e.name;case"list":return`java.util.List<${S(e.item)}>`;case"number":return"Double";case"record":return`java.util.Map<String, ${S(e.value)}>`;case"string":return"String";default:return"Object"}},K=e=>{switch(e.kind){case"class":case"enum":return!0;case"list":return K(e.item);case"record":return K(e.value);default:return!1}},x=(e,r,t)=>{if(!K(e))return r;const n=`item${String(t)}`;switch(e.kind){case"class":return`${r} == null ? null : ${r}.toWire()`;case"enum":return`${r} == null ? null : ${r}.toValue()`;case"list":return`ModelWire.writeList(${r}, ${n} -> ${x(e.item,n,t+1)})`;case"record":return`ModelWire.writeRecord(${r}, ${n} -> ${x(e.value,n,t+1)})`;default:return r}},q=(e,r,t)=>{const n=`item${String(t)}`;switch(e.kind){case"boolean":return`ModelWire.flag(${r})`;case"class":return`ModelWire.readObject(${r}, ${e.name}::fromWire)`;case"enum":return`ModelWire.readEnum(${r}, ${e.name}::forValue)`;case"list":return`ModelWire.readList(${r}, ${n} -> ${q(e.item,n,t+1)})`;case"number":return`ModelWire.number(${r})`;case"record":return`ModelWire.readRecord(${r}, ${n} -> ${q(e.value,n,t+1)})`;case"string":return`ModelWire.text(${r})`;default:return r}},qe=e=>{const r=l(e.wireKey);return e.optional?[" /**",` * Wire key {@code ${r}} — OPTIONAL: null omits the key entirely, because`," * `v.optional` accepts the value or `undefined` and rejects an explicit null."," */"]:[` /** Wire key {@code ${r}}.${e.nullable?" Nullable: null is sent as an explicit null.":""} */`]},Ie=100,De=e=>{const r=e.fields.map(n=>`${S(n.type)} ${n.name}`),t=` public ${e.name}(${r.join(", ")}) {`;return t.length<=Ie?[t]:[` public ${e.name}(`,...r.map((n,a)=>` ${n}${a===r.length-1?") {":","}`)]},Fe=e=>{const r=e.fields.flatMap(n=>{const a=`wire.put("${p(n.wireKey)}", ${x(n.type,`this.${n.name}`,0)});`;return n.optional?[` if (this.${n.name} != null) {`,` ${a}`," }"]:[` ${a}`]}),t=e.fields.map(n=>` ${q(n.type,`wire.get("${p(n.wireKey)}")`,0)}`);return[...O("java"),"",`package ${b};`,"","/**",` * The \`${e.name}\` model.`," *"," * <p>Field names are local; the keys {@link #toWire()} and {@link #fromWire(Object)} use are"," * the schema's own, emitted verbatim, so a renamed field cannot reach the wire."," */",`public final class ${e.name} {`,...e.fields.flatMap(n=>[...qe(n),` public final ${S(n.type)} ${n.name};`,""]),...De(e),...e.fields.map(n=>` this.${n.name} = ${n.name};`)," }",""," /** This model as the wire-shaped map the transport encodes. */"," public java.util.Map<String, Object> toWire() {"," java.util.Map<String, Object> wire = new java.util.LinkedHashMap<>();",...r,""," return wire;"," }",""," /** Rebuild from a decoded wire value. */",` public static ${e.name} fromWire(Object value) {`," java.util.Map<String, Object> wire = ModelWire.object(value);","",...t.length===0?[` return new ${e.name}();`]:[` return new ${e.name}(`,`${t.join(`,
49
49
  `)});`]," }","}",""].join(`
50
- `)},qe=e=>[...A("java"),"",`package ${g};`,"",`/** The \`${e.name}\` union. Each constant keeps the wire string it encodes to. */`,`public enum ${e.name} {`,...e.constants.map((r,t)=>` ${r.name}("${d(r.wireValue)}")${t===e.constants.length-1?";":","}`),""," private final String value;","",` ${e.name}(String value) {`," this.value = value;"," }",""," /** The wire string this constant encodes to. */"," public String toValue() {"," return this.value;"," }",""," /** The constant a wire string decodes to. */",` public static ${e.name} forValue(String value) {`,` for (${e.name} candidate : values()) {`," if (candidate.value.equals(value)) {"," return candidate;"," }"," }","",` throw new IllegalArgumentException("${e.name}: unknown wire value " + value);`," }","}",""].join(`
51
- `),Ie=[{lines:[' @SuppressWarnings("unchecked")'," static java.util.Map<String, Object> object(Object value) {"," return value instanceof java.util.Map"," ? (java.util.Map<String, Object>) value"," : new java.util.LinkedHashMap<String, Object>();"," }"],name:"object"},{lines:[" static String text(Object value) {"," return value instanceof String ? (String) value : null;"," }"],name:"text"},{lines:[" static Double number(Object value) {"," return value instanceof Number ? ((Number) value).doubleValue() : null;"," }"],name:"number"},{lines:[" static Boolean flag(Object value) {"," return value instanceof Boolean ? (Boolean) value : null;"," }"],name:"flag"},{lines:[" /** A nested model, or null when the payload carried no object there. */"," static <T> T readObject(Object value, java.util.function.Function<Object, T> read) {"," return value instanceof java.util.Map ? read.apply(value) : null;"," }"],name:"readObject"},{lines:[" /** An enum constant, or null when the payload carried no string there. */"," static <T> T readEnum(Object value, java.util.function.Function<String, T> read) {"," return value instanceof String ? read.apply((String) value) : null;"," }"],name:"readEnum"},{lines:[" static <T> java.util.List<T> readList("," Object value, java.util.function.Function<Object, T> read) {"," if (!(value instanceof java.util.List)) {"," return null;"," }",""," java.util.List<T> items = new java.util.ArrayList<T>();",""," for (Object item : (java.util.List<?>) value) {"," items.add(read.apply(item));"," }",""," return items;"," }"],name:"readList"},{lines:[" static <T> java.util.Map<String, T> readRecord("," Object value, java.util.function.Function<Object, T> read) {"," if (!(value instanceof java.util.Map)) {"," return null;"," }",""," java.util.Map<String, T> entries = new java.util.LinkedHashMap<String, T>();",""," for (java.util.Map.Entry<?, ?> entry : ((java.util.Map<?, ?>) value).entrySet()) {"," entries.put(String.valueOf(entry.getKey()), read.apply(entry.getValue()));"," }",""," return entries;"," }"],name:"readRecord"},{lines:[" static <T> java.util.List<Object> writeList("," java.util.List<T> items, java.util.function.Function<T, Object> write) {"," if (items == null) {"," return null;"," }",""," java.util.List<Object> encoded = new java.util.ArrayList<Object>(items.size());",""," for (T item : items) {"," encoded.add(write.apply(item));"," }",""," return encoded;"," }"],name:"writeList"},{lines:[" static <T> java.util.Map<String, Object> writeRecord("," java.util.Map<String, T> entries, java.util.function.Function<T, Object> write) {"," if (entries == null) {"," return null;"," }",""," java.util.Map<String, Object> encoded = new java.util.LinkedHashMap<String, Object>();",""," for (java.util.Map.Entry<String, T> entry : entries.entrySet()) {"," encoded.put(entry.getKey(), write.apply(entry.getValue()));"," }",""," return encoded;"," }"],name:"writeRecord"}],De=e=>{const r=Ie.filter(t=>e.includes(`ModelWire.${t.name}(`));return[...A("java"),"",`package ${g};`,"","/** Wire readers and writers shared by the generated models. */","final class ModelWire {"," private ModelWire() {}",...r.flatMap(t=>["",...t.lines]),"}",""].join(`
52
- `)},Fe=e=>{const r=se(e);if(r.length===0)return{};const t={};for(const n of r)t[`${E}/${n.name}.java`]=n.kind==="enum"?qe(n):xe(n);return{[`${E}/ModelWire.java`]:De(Object.values(t).join(`
53
- `)),...t}},q=e=>{switch(e.kind){case"boolean":return"Boolean";case"class":case"enum":return e.name;case"list":return`List<${q(e.item)}>`;case"number":return"Double";case"record":return`Map<String, ${q(e.value)}>`;case"string":return"String";default:return"WireValue"}},b=(e,r,t)=>{const n=`item${String(t)}`,a=`entry${String(t)}`;switch(e.kind){case"boolean":return`WireValue.Bool(${r})`;case"class":return`${r}.toWire()`;case"enum":return`WireValue.Text(${r}.wireValue)`;case"list":return`WireValue.Arr(${r}.map { ${n} -> ${b(e.item,n,t+1)} })`;case"number":return`WireValue.Num(${r})`;case"record":return`WireValue.Obj(${r}.map { ${a} -> ${a}.key to ${b(e.value,`${a}.value`,t+1)} })`;case"string":return`WireValue.Text(${r})`;default:return r}},I=(e,r,t,n)=>`wireNeed(${le(e,r,t,n)}, "${h(n)}")`,le=(e,r,t,n)=>{const a=`item${String(t)}`,i=`entry${String(t)}`;switch(e.kind){case"boolean":return`wireBool(${r})`;case"class":return`wireObj(${r})?.let { ${a} -> ${e.name}.fromWire(${a}) }`;case"enum":return`wireText(${r})?.let { ${a} -> ${e.name}.forValue(${a}) }`;case"list":return`wireArr(${r})?.items?.map { ${a} -> ${I(e.item,a,t+1,`${n}[]`)} }`;case"number":return`wireNum(${r})`;case"record":return`wireObj(${r})?.fields?.associate { ${i} -> ${i}.first to ${I(e.value,`${i}.second`,t+1,`${n}{}`)} }`;case"string":return`wireText(${r})`;default:return r}},Re=e=>{const r=e.fields.map(a=>{const i=l(a.wireKey);return[...a.optional?[" /**",` * Wire key \`${i}\` — OPTIONAL: null omits the key entirely, because`," * `v.optional` accepts the value or `undefined` and rejects an explicit null."," */"]:[` /** Wire key \`${i}\`.${a.nullable?" Nullable: null is sent as an explicit null.":""} */`],` val ${a.name}: ${q(a.type)}${a.optional||a.nullable?"?":""}${a.optional?" = null":""},`]}),t=e.fields.map(a=>{const i=h(a.wireKey);return a.optional?` ${a.name}?.let { add("${i}" to ${b(a.type,"it",0)}) }`:a.nullable?` add("${i}" to (${a.name}?.let { ${b(a.type,"it",0)} } ?: WireValue.Null))`:` add("${i}" to ${b(a.type,a.name,0)})`}),n=e.fields.map(a=>{const i=`wireField(value, "${h(a.wireKey)}")`,o=a.optional||a.nullable?le(a.type,i,0,a.wireKey):I(a.type,i,0,a.wireKey);return` ${a.name} = ${o},`});return["/**",` * The \`${e.name}\` model.`," *"," * Property names are local; the keys [toWire] and [fromWire] use are the schema's own,"," * emitted verbatim, so a renamed property cannot reach the wire."," */",`class ${e.name}(`,...r.flat(),") {"," /** This model as the wire-shaped object the transport encodes. */"," fun toWire(): WireValue ="," WireValue.Obj("," buildList {",...t," },"," )",""," companion object {"," /** Rebuild from a decoded wire value. */",` fun fromWire(value: WireValue): ${e.name} =`,` ${e.name}(`,...n," )"," }","}"]},He=e=>[`/** The \`${e.name}\` union. Each entry keeps the wire string it encodes to. */`,`enum class ${e.name}(val wireValue: String) {`,...e.constants.map(r=>` ${r.name}("${h(r.wireValue)}"),`)," ;",""," companion object {"," /** The entry a wire string decodes to. */",` fun forValue(value: String): ${e.name} =`," entries.firstOrNull { it.wireValue == value }",` ?: throw IllegalArgumentException("${e.name}: unknown wire value " + value)`," }","}"],ze=[{lines:["private fun wireField(value: WireValue, key: String): WireValue? ="," (value as? WireValue.Obj)?.fields?.firstOrNull { it.first == key }?.second"],name:"wireField"},{lines:["private fun wireText(value: WireValue?): String? = (value as? WireValue.Text)?.value"],name:"wireText"},{lines:["private fun wireNum(value: WireValue?): Double? = (value as? WireValue.Num)?.value"],name:"wireNum"},{lines:["private fun wireBool(value: WireValue?): Boolean? = (value as? WireValue.Bool)?.value"],name:"wireBool"},{lines:["private fun wireArr(value: WireValue?): WireValue.Arr? = value as? WireValue.Arr"],name:"wireArr"},{lines:["private fun wireObj(value: WireValue?): WireValue.Obj? = value as? WireValue.Obj"],name:"wireObj"},{lines:["/** A required field the payload omitted or mistyped is a contract violation, not a null. */","private fun <T> wireNeed(read: T?, label: String): T =",' read ?: throw WireFormatException("lunora: the wire payload is missing or mistyped " + label)'],name:"wireNeed"}],Ue=e=>{const r=se(e);if(r.length===0)return{};const t=r.flatMap(o=>[...o.kind==="enum"?He(o):Re(o),""]),n=ze.filter(o=>t.some(c=>c.includes(`${o.name}(`))),a=n.flatMap((o,c)=>c===0?[...o.lines]:["",...o.lines]),i=[...A("kotlin"),"",`package ${g}`,"",...n.some(o=>o.name==="wireNeed")?["import dev.lunora.WireFormatException"]:[],"import dev.lunora.WireValue","",...t,...a,""].join(`
54
- `);return{[`${E}/Models.kt`]:i}},Be=`${f("java").map(e=>`// ${e}`).join(`
50
+ `)},Re=e=>[...O("java"),"",`package ${b};`,"",`/** The \`${e.name}\` union. Each constant keeps the wire string it encodes to. */`,`public enum ${e.name} {`,...e.constants.map((r,t)=>` ${r.name}("${p(r.wireValue)}")${t===e.constants.length-1?";":","}`),""," private final String value;","",` ${e.name}(String value) {`," this.value = value;"," }",""," /** The wire string this constant encodes to. */"," public String toValue() {"," return this.value;"," }",""," /** The constant a wire string decodes to. */",` public static ${e.name} forValue(String value) {`,` for (${e.name} candidate : values()) {`," if (candidate.value.equals(value)) {"," return candidate;"," }"," }","",` throw new IllegalArgumentException("${e.name}: unknown wire value " + value);`," }","}",""].join(`
51
+ `),He=[{lines:[' @SuppressWarnings("unchecked")'," static java.util.Map<String, Object> object(Object value) {"," return value instanceof java.util.Map"," ? (java.util.Map<String, Object>) value"," : new java.util.LinkedHashMap<String, Object>();"," }"],name:"object"},{lines:[" static String text(Object value) {"," return value instanceof String ? (String) value : null;"," }"],name:"text"},{lines:[" static Double number(Object value) {"," return value instanceof Number ? ((Number) value).doubleValue() : null;"," }"],name:"number"},{lines:[" static Boolean flag(Object value) {"," return value instanceof Boolean ? (Boolean) value : null;"," }"],name:"flag"},{lines:[" /** A nested model, or null when the payload carried no object there. */"," static <T> T readObject(Object value, java.util.function.Function<Object, T> read) {"," return value instanceof java.util.Map ? read.apply(value) : null;"," }"],name:"readObject"},{lines:[" /** An enum constant, or null when the payload carried no string there. */"," static <T> T readEnum(Object value, java.util.function.Function<String, T> read) {"," return value instanceof String ? read.apply((String) value) : null;"," }"],name:"readEnum"},{lines:[" static <T> java.util.List<T> readList("," Object value, java.util.function.Function<Object, T> read) {"," if (!(value instanceof java.util.List)) {"," return null;"," }",""," java.util.List<T> items = new java.util.ArrayList<T>();",""," for (Object item : (java.util.List<?>) value) {"," items.add(read.apply(item));"," }",""," return items;"," }"],name:"readList"},{lines:[" static <T> java.util.Map<String, T> readRecord("," Object value, java.util.function.Function<Object, T> read) {"," if (!(value instanceof java.util.Map)) {"," return null;"," }",""," java.util.Map<String, T> entries = new java.util.LinkedHashMap<String, T>();",""," for (java.util.Map.Entry<?, ?> entry : ((java.util.Map<?, ?>) value).entrySet()) {"," entries.put(String.valueOf(entry.getKey()), read.apply(entry.getValue()));"," }",""," return entries;"," }"],name:"readRecord"},{lines:[" static <T> java.util.List<Object> writeList("," java.util.List<T> items, java.util.function.Function<T, Object> write) {"," if (items == null) {"," return null;"," }",""," java.util.List<Object> encoded = new java.util.ArrayList<Object>(items.size());",""," for (T item : items) {"," encoded.add(write.apply(item));"," }",""," return encoded;"," }"],name:"writeList"},{lines:[" static <T> java.util.Map<String, Object> writeRecord("," java.util.Map<String, T> entries, java.util.function.Function<T, Object> write) {"," if (entries == null) {"," return null;"," }",""," java.util.Map<String, Object> encoded = new java.util.LinkedHashMap<String, Object>();",""," for (java.util.Map.Entry<String, T> entry : entries.entrySet()) {"," encoded.put(entry.getKey(), write.apply(entry.getValue()));"," }",""," return encoded;"," }"],name:"writeRecord"}],ze=e=>{const r=He.filter(t=>e.includes(`ModelWire.${t.name}(`));return[...O("java"),"",`package ${b};`,"","/** Wire readers and writers shared by the generated models. */","final class ModelWire {"," private ModelWire() {}",...r.flatMap(t=>["",...t.lines]),"}",""].join(`
52
+ `)},Ue=e=>{const r=le(e);if(r.length===0)return{};const t={};for(const n of r)t[`${P}/${n.name}.java`]=n.kind==="enum"?Re(n):Fe(n);return{[`${P}/ModelWire.java`]:ze(Object.values(t).join(`
53
+ `)),...t}},I=e=>{switch(e.kind){case"boolean":return"Boolean";case"class":case"enum":return e.name;case"list":return`List<${I(e.item)}>`;case"number":return"Double";case"record":return`Map<String, ${I(e.value)}>`;case"string":return"String";default:return"WireValue"}},w=(e,r,t)=>{const n=`item${String(t)}`,a=`entry${String(t)}`;switch(e.kind){case"boolean":return`WireValue.Bool(${r})`;case"class":return`${r}.toWire()`;case"enum":return`WireValue.Text(${r}.wireValue)`;case"list":return`WireValue.Arr(${r}.map { ${n} -> ${w(e.item,n,t+1)} })`;case"number":return`WireValue.Num(${r})`;case"record":return`WireValue.Obj(${r}.map { ${a} -> ${a}.key to ${w(e.value,`${a}.value`,t+1)} })`;case"string":return`WireValue.Text(${r})`;default:return r}},D=(e,r,t,n)=>`wireNeed(${ue(e,r,t,n)}, "${g(n)}")`,ue=(e,r,t,n)=>{const a=`item${String(t)}`,i=`entry${String(t)}`;switch(e.kind){case"boolean":return`wireBool(${r})`;case"class":return`wireObj(${r})?.let { ${a} -> ${e.name}.fromWire(${a}) }`;case"enum":return`wireText(${r})?.let { ${a} -> ${e.name}.forValue(${a}) }`;case"list":return`wireArr(${r})?.items?.map { ${a} -> ${D(e.item,a,t+1,`${n}[]`)} }`;case"number":return`wireNum(${r})`;case"record":return`wireObj(${r})?.fields?.associate { ${i} -> ${i}.first to ${D(e.value,`${i}.second`,t+1,`${n}{}`)} }`;case"string":return`wireText(${r})`;default:return r}},Be=e=>{const r=e.fields.map(a=>{const i=l(a.wireKey);return[...a.optional?[" /**",` * Wire key \`${i}\` — OPTIONAL: null omits the key entirely, because`," * `v.optional` accepts the value or `undefined` and rejects an explicit null."," */"]:[` /** Wire key \`${i}\`.${a.nullable?" Nullable: null is sent as an explicit null.":""} */`],` val ${a.name}: ${I(a.type)}${a.optional||a.nullable?"?":""}${a.optional?" = null":""},`]}),t=e.fields.map(a=>{const i=g(a.wireKey);return a.optional?` ${a.name}?.let { add("${i}" to ${w(a.type,"it",0)}) }`:a.nullable?` add("${i}" to (${a.name}?.let { ${w(a.type,"it",0)} } ?: WireValue.Null))`:` add("${i}" to ${w(a.type,a.name,0)})`}),n=e.fields.map(a=>{const i=`wireField(value, "${g(a.wireKey)}")`,o=a.optional||a.nullable?ue(a.type,i,0,a.wireKey):D(a.type,i,0,a.wireKey);return` ${a.name} = ${o},`});return["/**",` * The \`${e.name}\` model.`," *"," * Property names are local; the keys [toWire] and [fromWire] use are the schema's own,"," * emitted verbatim, so a renamed property cannot reach the wire."," */",`class ${e.name}(`,...r.flat(),") {"," /** This model as the wire-shaped object the transport encodes. */"," fun toWire(): WireValue ="," WireValue.Obj("," buildList {",...t," },"," )",""," companion object {"," /** Rebuild from a decoded wire value. */",` fun fromWire(value: WireValue): ${e.name} =`,` ${e.name}(`,...n," )"," }","}"]},Je=e=>[`/** The \`${e.name}\` union. Each entry keeps the wire string it encodes to. */`,`enum class ${e.name}(val wireValue: String) {`,...e.constants.map(r=>` ${r.name}("${g(r.wireValue)}"),`)," ;",""," companion object {"," /** The entry a wire string decodes to. */",` fun forValue(value: String): ${e.name} =`," entries.firstOrNull { it.wireValue == value }",` ?: throw IllegalArgumentException("${e.name}: unknown wire value " + value)`," }","}"],Ge=[{lines:["private fun wireField(value: WireValue, key: String): WireValue? ="," (value as? WireValue.Obj)?.fields?.firstOrNull { it.first == key }?.second"],name:"wireField"},{lines:["private fun wireText(value: WireValue?): String? = (value as? WireValue.Text)?.value"],name:"wireText"},{lines:["private fun wireNum(value: WireValue?): Double? = (value as? WireValue.Num)?.value"],name:"wireNum"},{lines:["private fun wireBool(value: WireValue?): Boolean? = (value as? WireValue.Bool)?.value"],name:"wireBool"},{lines:["private fun wireArr(value: WireValue?): WireValue.Arr? = value as? WireValue.Arr"],name:"wireArr"},{lines:["private fun wireObj(value: WireValue?): WireValue.Obj? = value as? WireValue.Obj"],name:"wireObj"},{lines:["/** A required field the payload omitted or mistyped is a contract violation, not a null. */","private fun <T> wireNeed(read: T?, label: String): T =",' read ?: throw WireFormatException("lunora: the wire payload is missing or mistyped " + label)'],name:"wireNeed"}],Ze=e=>{const r=le(e);if(r.length===0)return{};const t=r.flatMap(o=>[...o.kind==="enum"?Je(o):Be(o),""]),n=Ge.filter(o=>t.some(c=>c.includes(`${o.name}(`))),a=n.flatMap((o,c)=>c===0?[...o.lines]:["",...o.lines]),i=[...O("kotlin"),"",`package ${b}`,"",...n.some(o=>o.name==="wireNeed")?["import dev.lunora.WireFormatException"]:[],"import dev.lunora.WireValue","",...t,...a,""].join(`
54
+ `);return{[`${P}/Models.kt`]:i}},Ye=`${y("java").map(e=>`// ${e}`).join(`
55
55
  `)}
56
56
 
57
- `,J="lunoraapi",Je=new Set(["abstract","assert","boolean","break","byte","case","catch","char","class","const","continue","default","do","double","else","enum","extends","final","finally","float","for","goto","if","implements","import","instanceof","int","interface","long","native","new","package","private","protected","public","return","short","static","strictfp","super","switch","synchronized","this","throw","throws","transient","try","void","volatile","while"]),D=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return Je.has(t)?`${t}_`:t},Ge=e=>`Client.Verb.${e.toUpperCase()}`,ue=e=>e.argsType===void 0?{payload:"args",type:"java.util.Map<String, Object>"}:{payload:"args == null ? null : args.toWire()",type:e.argsType},G=e=>{const r=ue(e),t=`client.call(
58
- ${Ge(e.verb)}, "${d(e.functionPath)}", ${r.payload}, shardKey)`;return[` /** ${l(e.summary)} */`,` public ${e.resultType??"Object"} ${D(e.functionName)}(${r.type} args, String shardKey) {`,` return ${e.resultType===void 0?t:`${e.resultType}.fromWire(${t})`};`," }"].join(`
59
- `)},Ze=e=>{const r=ue(e);return[` /** live ${l(e.summary)} — re-runs on every write to the tables it reads. */`,` public Runnable subscribe${s(e.functionName)}(`,` ${r.type} args,`," java.util.function.Consumer<Object> onData,"," java.util.function.Consumer<Client.SubscriptionError> onError,"," String shardKey) {"," return client.subscribe(",` "${d(e.functionPath)}", ${r.payload}, onData, onError, shardKey);`," }"].join(`
60
- `)},Ye=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${G(n)}
57
+ `,G="lunoraapi",Qe=new Set(["abstract","assert","boolean","break","byte","case","catch","char","class","const","continue","default","do","double","else","enum","extends","final","finally","float","for","goto","if","implements","import","instanceof","int","interface","long","native","new","package","private","protected","public","return","short","static","strictfp","super","switch","synchronized","this","throw","throws","transient","try","void","volatile","while"]),F=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return Qe.has(t)?`${t}_`:t},Xe=e=>`Client.Verb.${e.toUpperCase()}`,ce=e=>e.argsType===void 0?{payload:"args",type:"java.util.Map<String, Object>"}:{payload:"args == null ? null : args.toWire()",type:e.argsType},Z=e=>{const r=ce(e),t=`client.call(
58
+ ${Xe(e.verb)}, "${p(e.functionPath)}", ${r.payload}, shardKey)`;return[` /** ${l(e.summary)} */`,` public ${e.resultType??"Object"} ${F(e.functionName)}(${r.type} args, String shardKey) {`,` return ${e.resultType===void 0?t:`${e.resultType}.fromWire(${t})`};`," }"].join(`
59
+ `)},er=e=>{const r=ce(e);return[` /** live ${l(e.summary)} — re-runs on every write to the tables it reads. */`,` public Runnable subscribe${s(e.functionName)}(`,` ${r.type} args,`," java.util.function.Consumer<Object> onData,"," java.util.function.Consumer<Client.SubscriptionError> onError,"," String shardKey) {"," return client.subscribe(",` "${p(e.functionPath)}", ${r.payload}, onData, onError, shardKey);`," }"].join(`
60
+ `)},rr=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${Z(n)}
61
61
 
62
- ${Ze(n)}`:G(n)).join(`
62
+ ${er(n)}`:Z(n)).join(`
63
63
 
64
64
  `);return[` /** Functions declared in \`${l(e.name)}\`. */`,` public static final class ${r} {`," private final Client client;","",` ${r}(Client client) {`," this.client = client;"," }","",t.replaceAll(/^ {4}/gmu," ")," }"].join(`
65
- `)},Qe=({namespaces:e})=>{const r=e.map(i=>` public final ${s(i.name)}Api ${D(i.name)};`).join(`
66
- `),t=e.map(i=>` this.${D(i.name)} = new ${s(i.name)}Api(client);`).join(`
67
- `),n=R(e).map(i=>`import ${g}.${i};
68
- `),a=[Be,`package ${J};
65
+ `)},tr=({namespaces:e})=>{const r=e.map(i=>` public final ${s(i.name)}Api ${F(i.name)};`).join(`
66
+ `),t=e.map(i=>` this.${F(i.name)} = new ${s(i.name)}Api(client);`).join(`
67
+ `),n=H(e).map(i=>`import ${b}.${i};
68
+ `),a=[Ye,`package ${G};
69
69
  `,`
70
70
  `,`import dev.lunora.Client;
71
71
  `,...n,`
@@ -77,30 +77,30 @@ ${Ze(n)}`:G(n)).join(`
77
77
  `:` // No functions in this deployment.
78
78
  `,` }
79
79
  `,`
80
- `,e.map(i=>Ye(i)).join(`
80
+ `,e.map(i=>rr(i)).join(`
81
81
 
82
82
  `),`
83
83
  }
84
- `].join("");return{[`${J}/Api.java`]:a}},Xe={id:"java",render:Qe,renderModels:Fe,requires:[],vendor:[{from:"src/dev/lunora",to:"dev/lunora"}]},er=`${f("kotlin").map(e=>`// ${e}`).join(`
84
+ `].join("");return{[`${G}/Api.java`]:a}},nr={id:"java",render:tr,renderModels:Ue,requires:[],vendor:[{from:"src/dev/lunora",to:"dev/lunora"}]},ar=`${y("kotlin").map(e=>`// ${e}`).join(`
85
85
  `)}
86
86
 
87
- `,Z="lunoraapi",rr=new Set(["as","break","class","continue","do","else","false","for","fun","if","in","interface","is","null","object","package","return","super","this","throw","true","try","typealias","typeof","val","var","when","while"]),ce=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return rr.has(t)?`\`${t}\``:t},tr=e=>`Verb.${e.toUpperCase()}`,de=e=>e.argsType===void 0?{declaration:"args: WireValue? = null",payload:"args"}:{declaration:`args: ${e.argsType}`,payload:"args.toWire()"},Y=e=>{const r=de(e),t=`client.call(${tr(e.verb)}, "${h(e.functionPath)}", ${r.payload}, shardKey)`;return[` /** ${l(e.summary)} */`,` fun ${ce(e.functionName)}(${r.declaration}, shardKey: String? = null): ${e.resultType??"WireValue"} =`,` ${e.resultType===void 0?t:`${e.resultType}.fromWire(${t})`}`].join(`
88
- `)},nr=e=>{const r=de(e);return[` /** live ${l(e.summary)} — re-runs on every write to the tables it reads. */`,` fun subscribe${s(e.functionName)}(`,` ${r.declaration},`," onData: ((WireValue) -> Unit)?,"," onError: ((SubscriptionError) -> Unit)? = null,"," shardKey: String? = null,"," ): () -> Unit =",` client.subscribe("${h(e.functionPath)}", ${r.payload}, onData, onError, shardKey)`].join(`
89
- `)},ar=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${Y(n)}
87
+ `,Y="lunoraapi",ir=new Set(["as","break","class","continue","do","else","false","for","fun","if","in","interface","is","null","object","package","return","super","this","throw","true","try","typealias","typeof","val","var","when","while"]),de=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return ir.has(t)?`\`${t}\``:t},or=e=>`Verb.${e.toUpperCase()}`,pe=e=>e.argsType===void 0?{declaration:"args: WireValue? = null",payload:"args"}:{declaration:`args: ${e.argsType}`,payload:"args.toWire()"},Q=e=>{const r=pe(e),t=`client.call(${or(e.verb)}, "${g(e.functionPath)}", ${r.payload}, shardKey)`;return[` /** ${l(e.summary)} */`,` fun ${de(e.functionName)}(${r.declaration}, shardKey: String? = null): ${e.resultType??"WireValue"} =`,` ${e.resultType===void 0?t:`${e.resultType}.fromWire(${t})`}`].join(`
88
+ `)},sr=e=>{const r=pe(e);return[` /** live ${l(e.summary)} — re-runs on every write to the tables it reads. */`,` fun subscribe${s(e.functionName)}(`,` ${r.declaration},`," onData: ((WireValue) -> Unit)?,"," onError: ((SubscriptionError) -> Unit)? = null,"," shardKey: String? = null,"," ): () -> Unit =",` client.subscribe("${g(e.functionPath)}", ${r.payload}, onData, onError, shardKey)`].join(`
89
+ `)},lr=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${Q(n)}
90
90
 
91
- ${nr(n)}`:Y(n)).join(`
91
+ ${sr(n)}`:Q(n)).join(`
92
92
 
93
93
  `);return[`/** Functions declared in \`${l(e.name)}\`. */`,`class ${r}(private val client: Client) {`,t,"}"].join(`
94
- `)},ir=({namespaces:e})=>{const r=e.map(i=>` val ${ce(i.name)}: ${s(i.name)}Api = ${s(i.name)}Api(client)`).join(`
94
+ `)},ur=({namespaces:e})=>{const r=e.map(i=>` val ${de(i.name)}: ${s(i.name)}Api = ${s(i.name)}Api(client)`).join(`
95
95
  `),t=e.flatMap(i=>i.methods),n=[`import dev.lunora.Client
96
96
  `,...t.some(i=>i.verb==="query")?[`import dev.lunora.SubscriptionError
97
97
  `]:[],`import dev.lunora.Verb
98
98
  `,...t.some(i=>i.argsType===void 0||i.resultType===void 0)?[`import dev.lunora.WireValue
99
- `]:[],...R(e).map(i=>`import ${g}.${i}
100
- `)],a=[er,`package ${Z}
99
+ `]:[],...H(e).map(i=>`import ${b}.${i}
100
+ `)],a=[ar,`package ${Y}
101
101
  `,`
102
102
  `,...n,`
103
- `,e.map(i=>ar(i)).join(`
103
+ `,e.map(i=>lr(i)).join(`
104
104
 
105
105
  `),`
106
106
 
@@ -108,26 +108,26 @@ ${nr(n)}`:Y(n)).join(`
108
108
  `,r.length>0?`${r}
109
109
  `:` init { require(true) { client } }
110
110
  `,`}
111
- `].join("");return{[`${Z}/Api.kt`]:a}},or={id:"kotlin",render:ir,renderModels:Ue,requires:[],vendor:[{from:"src",to:"dev/lunora"}]},sr=new Set(["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","False","finally","for","from","global","if","import","in","is","lambda","None","nonlocal","not","or","pass","raise","return","True","try","while","with","yield"]),w=`"""${f("python").join(`
111
+ `].join("");return{[`${Y}/Api.kt`]:a}},cr={id:"kotlin",render:ur,renderModels:Ze,requires:[],vendor:[{from:"src",to:"dev/lunora"}]},dr=new Set(["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","False","finally","for","from","global","if","import","in","is","lambda","None","nonlocal","not","or","pass","raise","return","True","try","while","with","yield"]),j=`"""${y("python").join(`
112
112
 
113
113
  `)}
114
114
  """
115
115
 
116
- `,V="lunora_api",z=e=>{const r=H(e);return sr.has(r)?`${r}_`:r},Q=e=>{const r=e.resultType??"Any",t=e.argsType===void 0?"self":`self, args: ${e.argsType}`,n=e.argsType===void 0?"{}":"args.to_dict()",a=`await self._client.${e.verb}("${d(e.functionPath)}", ${n}, shard_key)`;return[` async def ${z(e.functionName)}(${t}, *, shard_key: Optional[str] = None) -> ${r}:`,` """${l(e.summary)}"""`,` ${e.resultType===void 0?`return ${a}`:`return ${e.resultType}.from_dict(${a})`}`].join(`
117
- `)},lr=e=>{const r=e.argsType===void 0?"{}":"args.to_dict()",t=["self",...e.argsType===void 0?[]:[`args: ${e.argsType}`],"on_data: Callback","on_error: Optional[ErrorCallback] = None","*","shard_key: Optional[str] = None"];return[` def subscribe_${z(e.functionName)}(`,...t.map(n=>` ${n},`)," ) -> Unsubscribe:",` """live ${l(e.summary)} — re-runs on every write to the tables it reads."""`,` return self._client.subscribe("${d(e.functionPath)}", ${r}, on_data, on_error, shard_key)`].join(`
118
- `)},ur=e=>{const r=e.methods.map(t=>t.verb==="query"?`${Q(t)}
116
+ `,L="lunora_api",U=e=>{const r=z(e);return dr.has(r)?`${r}_`:r},$e=e=>d(e,{none:"{}",typed:()=>"args.to_dict()",untyped:"args"}),pr=(e,r,t,n)=>d(e,{none:r,typed:t,untyped:n}),X=e=>{const r=e.resultType??"Any",t=pr(e,"self",i=>`self, args: ${i}`,"self, args: Any"),n=$e(e),a=`await self._client.${e.verb}("${p(e.functionPath)}", ${n}, shard_key)`;return[` async def ${U(e.functionName)}(${t}, *, shard_key: Optional[str] = None) -> ${r}:`,` """${l(e.summary)}"""`,` ${e.resultType===void 0?`return ${a}`:`return ${e.resultType}.from_dict(${a})`}`].join(`
117
+ `)},$r=e=>{const r=$e(e),t=["self",...d(e,{none:[],typed:n=>[`args: ${n}`],untyped:["args: Any"]}),"on_data: Callback","on_error: Optional[ErrorCallback] = None","*","shard_key: Optional[str] = None"];return[` def subscribe_${U(e.functionName)}(`,...t.map(n=>` ${n},`)," ) -> Unsubscribe:",` """live ${l(e.summary)} — re-runs on every write to the tables it reads."""`,` return self._client.subscribe("${p(e.functionPath)}", ${r}, on_data, on_error, shard_key)`].join(`
118
+ `)},mr=e=>{const r=e.methods.map(t=>t.verb==="query"?`${X(t)}
119
119
 
120
- ${lr(t)}`:Q(t)).join(`
120
+ ${$r(t)}`:X(t)).join(`
121
121
 
122
122
  `);return[`class ${s(e.name)}Api:`,` """Functions declared in \`${l(e.name)}\`."""`,""," def __init__(self, client: LunoraClient) -> None:"," self._client = client","",r].join(`
123
- `)},cr=e=>e.replaceAll(/^([ \t]*)except:$/gmu,"$1except Exception:"),dr=({models:e,namespaces:r})=>{const t=R(r),n=t.length>0?`from .models import ${t.join(", ")}
124
- `:"",a=C(r).some(u=>u.verb==="query")?"Callback, ErrorCallback, LunoraClient, Unsubscribe":"LunoraClient",i=C(r).some(u=>u.resultType===void 0),o=r.map(u=>` self.${z(u.name)} = ${s(u.name)}Api(client)`).join(`
125
- `),c=[w,`from typing import ${i?"Any, Optional":"Optional"}
123
+ `)},fr=e=>e.replaceAll(/^([ \t]*)except:$/gmu,"$1except Exception:"),yr=({models:e,namespaces:r})=>{const t=H(r),n=t.length>0?`from .models import ${t.join(", ")}
124
+ `:"",a=M(r).some(u=>u.verb==="query")?"Callback, ErrorCallback, LunoraClient, Unsubscribe":"LunoraClient",i=M(r).some(u=>u.resultType===void 0),o=r.map(u=>` self.${U(u.name)} = ${s(u.name)}Api(client)`).join(`
125
+ `),c=[j,`from typing import ${i?"Any, Optional":"Optional"}
126
126
  `,`
127
127
  `,`from lunora.client import ${a}
128
128
  `,n,`
129
129
 
130
- `,r.map(u=>ur(u)).join(`
130
+ `,r.map(u=>mr(u)).join(`
131
131
 
132
132
 
133
133
  `),`
@@ -138,15 +138,15 @@ ${lr(t)}`:Q(t)).join(`
138
138
  `,` def __init__(self, client: LunoraClient) -> None:
139
139
  `,o.length>0?`${o}
140
140
  `:` pass
141
- `].join(""),p=["Api",...r.map(u=>`${s(u.name)}Api`)];return{[`${V}/__init__.py`]:[w,`from .api import ${p.join(", ")}
141
+ `].join(""),$=["Api",...r.map(u=>`${s(u.name)}Api`)];return{[`${L}/__init__.py`]:[j,`from .api import ${$.join(", ")}
142
142
  `,`
143
- `,`__all__ = [${p.map(u=>`"${u}"`).join(", ")}]
144
- `].join(""),[`${V}/api.py`]:c,[`${V}/models.py`]:e.length>0?`${w}${cr(e)}
145
- `:`${w}# No typed argument or result schemas in this deployment.
146
- `}},pr={id:"python",quicktype:{lang:"python",rendererOptions:{"python-version":"3.7"}},render:dr,requires:[],vendor:[{from:"lunora",to:"lunora"}]},L=`${f("ruby").map(e=>`# ${e}`).join(`
143
+ `,`__all__ = [${$.map(u=>`"${u}"`).join(", ")}]
144
+ `].join(""),[`${L}/api.py`]:c,[`${L}/models.py`]:e.length>0?`${j}${fr(e)}
145
+ `:`${j}# No typed argument or result schemas in this deployment.
146
+ `}},hr={id:"python",quicktype:{lang:"python",rendererOptions:{"python-version":"3.7"}},render:yr,requires:[],vendor:[{from:"lunora",to:"lunora"}]},N=`${y("ruby").map(e=>`# ${e}`).join(`
147
147
  `)}
148
148
 
149
- `,mr=new Set(["alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","false","for","if","in","module","next","nil","not","or","redo","rescue","retry","return","self","super","then","true","undef","unless","until","when","while","yield"]),pe=e=>d(e).replaceAll("#","\\#"),_=e=>{const r=H(e);return mr.has(r)?`${r}_`:r},$r=` def self.wire_args(model)
149
+ `,gr=new Set(["alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","false","for","if","in","module","next","nil","not","or","redo","rescue","retry","return","self","super","then","true","undef","unless","until","when","while","yield"]),me=e=>p(e).replaceAll("#","\\#"),A=e=>{const r=z(e);return gr.has(r)?`${r}_`:r},br=` def self.wire_args(model)
150
150
  drop_nils(model.to_dynamic)
151
151
  end
152
152
 
@@ -158,20 +158,20 @@ ${lr(t)}`:Q(t)).join(`
158
158
  end
159
159
  end
160
160
 
161
- `,X=e=>{const r=e.argsType===void 0?"shard_key: nil":"args, shard_key: nil",t=e.argsType===void 0?"{}":"LunoraApi.wire_args(args)",n=`@client.${e.verb}("${pe(e.functionPath)}", ${t}, shard_key)`,a=e.resultType===void 0?n:`${e.resultType}.from_dynamic!(${n})`;return[` # ${l(e.summary)}`,` def ${_(e.functionName)}(${r})`,` ${a}`," end"].join(`
162
- `)},fr=e=>{const r=e.argsType===void 0?"on_data, on_error = nil, shard_key: nil":"args, on_data, on_error = nil, shard_key: nil",t=e.argsType===void 0?"{}":"LunoraApi.wire_args(args)";return[` # live ${l(e.summary)} — re-runs on every write to the tables it reads.`,` def subscribe_${_(e.functionName)}(${r})`,` @client.subscribe("${pe(e.functionPath)}", ${t}, on_data, on_error, shard_key)`," end"].join(`
163
- `)},yr=e=>{const r=e.methods.map(t=>t.verb==="query"?`${X(t)}
161
+ `,fe=e=>d(e,{none:"{}",typed:()=>"LunoraApi.wire_args(args)",untyped:"args"}),ee=e=>{const r=e.argsType===void 0&&!e.takesArgs?"shard_key: nil":"args, shard_key: nil",t=fe(e),n=`@client.${e.verb}("${me(e.functionPath)}", ${t}, shard_key)`,a=e.resultType===void 0?n:`${e.resultType}.from_dynamic!(${n})`;return[` # ${l(e.summary)}`,` def ${A(e.functionName)}(${r})`,` ${a}`," end"].join(`
162
+ `)},vr=e=>{const r=e.argsType===void 0&&!e.takesArgs?"on_data, on_error = nil, shard_key: nil":"args, on_data, on_error = nil, shard_key: nil",t=fe(e);return[` # live ${l(e.summary)} — re-runs on every write to the tables it reads.`,` def subscribe_${A(e.functionName)}(${r})`,` @client.subscribe("${me(e.functionPath)}", ${t}, on_data, on_error, shard_key)`," end"].join(`
163
+ `)},wr=e=>{const r=e.methods.map(t=>t.verb==="query"?`${ee(t)}
164
164
 
165
- ${fr(t)}`:X(t)).join(`
165
+ ${vr(t)}`:ee(t)).join(`
166
166
 
167
167
  `);return[` # Functions declared in \`${l(e.name)}\`.`,` class ${s(e.name)}Api`," def initialize(client)"," @client = client"," end","",r," end"].join(`
168
- `)},hr=({models:e,namespaces:r})=>{const t=r.map(a=>`:${_(a.name)}`).join(", "),n=r.map(a=>` @${_(a.name)} = ${s(a.name)}Api.new(client)`).join(`
168
+ `)},jr=({models:e,namespaces:r})=>{const t=r.map(a=>`:${A(a.name)}`).join(", "),n=r.map(a=>` @${A(a.name)} = ${s(a.name)}Api.new(client)`).join(`
169
169
  `);return{"api.rb":[`# frozen_string_literal: true
170
170
 
171
- `,L,`require_relative "models"
171
+ `,N,`require_relative "models"
172
172
  `,`
173
173
  `,`module LunoraApi
174
- `,C(r).some(a=>a.argsType!==void 0)?$r:"",r.map(a=>yr(a)).join(`
174
+ `,M(r).some(a=>a.argsType!==void 0)?br:"",r.map(a=>wr(a)).join(`
175
175
 
176
176
  `),`
177
177
 
@@ -186,16 +186,16 @@ ${fr(t)}`:X(t)).join(`
186
186
  `,`end
187
187
  `].join(""),"models.rb":e.length>0?`# frozen_string_literal: true
188
188
 
189
- ${L}${e}
189
+ ${N}${e}
190
190
  `:`# frozen_string_literal: true
191
191
 
192
- ${L}# No typed argument or result schemas in this deployment.
193
- `}},gr={id:"ruby",quicktype:{lang:"ruby",rendererOptions:{}},render:hr,requires:["dry-struct + dry-types (gems, required by the generated models)"],vendor:[{from:"lib/lunora.rb",to:"lunora.rb"},{from:"lib/lunora",to:"lunora"}]},k=`${f("rust").map(e=>`// ${e}`).join(`
192
+ ${N}# No typed argument or result schemas in this deployment.
193
+ `}},kr={id:"ruby",quicktype:{lang:"ruby",rendererOptions:{}},render:jr,requires:["dry-struct + dry-types (gems, required by the generated models)"],vendor:[{from:"lib/lunora.rb",to:"lunora.rb"},{from:"lib/lunora",to:"lunora"}]},_=`${y("rust").map(e=>`// ${e}`).join(`
194
194
  `)}
195
195
 
196
- `,vr=`${k}pub mod api;
196
+ `,_r=`${_}pub mod api;
197
197
  pub mod models;
198
- `,br=`# The generated Lunora Rust SDK, with the transport vendored under ./lunora.
198
+ `,Sr=`# The generated Lunora Rust SDK, with the transport vendored under ./lunora.
199
199
  #
200
200
  # Add to a consuming crate:
201
201
  #
@@ -215,25 +215,25 @@ publish = false
215
215
  lunora = { path = "lunora" }
216
216
  serde = { version = "1", features = ["derive"] }
217
217
  serde_json = "1"
218
- `,wr=new Set(["abstract","as","async","await","become","box","break","const","continue","crate","do","dyn","else","enum","extern","false","final","fn","for","if","impl","in","let","loop","macro","match","mod","move","mut","override","priv","pub","ref","return","self","static","struct","super","trait","true","try","type","typeof","unsafe","unsized","use","virtual","where","while","yield"]),S=e=>{const r=H(e);return wr.has(r)?`r#${r}`:r},jr=e=>`Verb::${s(e)}`,ee=e=>{const r=e.argsType===void 0?"&self, shard_key: Option<&str>":`&self, args: &${e.argsType}, shard_key: Option<&str>`,t=e.argsType===void 0?"&WireValue::Object(Vec::new())":"&from_model_json(&serde_json::to_value(args).map_err(|error| ClientError::Transport(error.to_string()))?)",n=`self.client.call(${jr(e.verb)}, "${d(e.functionPath)}", ${t}, shard_key)`;return e.resultType===void 0?[` /// ${l(e.summary)}`,` pub fn ${S(e.functionName)}(${r}) -> Result<WireValue, ClientError> {`,` ${n}`," }"].join(`
219
- `):[` /// ${l(e.summary)}`,` pub fn ${S(e.functionName)}(${r}) -> Result<${e.resultType}, ClientError> {`,` let raw = ${n}?;`," let json = encode_wire(&raw).map_err(ClientError::Wire)?;"," serde_json::from_value(json).map_err(|error| ClientError::Transport(error.to_string()))"," }"].join(`
220
- `)},kr=e=>{const r=e.argsType===void 0?"":`args: &${e.argsType}, `,t=e.argsType===void 0?"WireValue::Object(Vec::new())":"from_model_json(&serde_json::to_value(args).map_err(|error| ClientError::Transport(error.to_string()))?)";return[` /// live ${l(e.summary)} — re-runs on every write to the tables it reads.`,` pub fn subscribe_${S(e.functionName)}(`," &mut self,",` ${r}on_data: DataHandler,`," on_error: ErrorHandler,"," shard_key: Option<&str>,"," ) -> Result<String, ClientError> {"," let _ = shard_key;",` Ok(self.client.subscribe("${d(e.functionPath)}", ${t}, on_data, on_error))`," }"].join(`
221
- `)},Tr=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${ee(n)}
218
+ `,Ar=new Set(["abstract","as","async","await","become","box","break","const","continue","crate","do","dyn","else","enum","extern","false","final","fn","for","if","impl","in","let","loop","macro","match","mod","move","mut","override","priv","pub","ref","return","self","static","struct","super","trait","true","try","type","typeof","unsafe","unsized","use","virtual","where","while","yield"]),T=e=>{const r=z(e);return Ar.has(r)?`r#${r}`:r},Tr=e=>`Verb::${s(e)}`,re=e=>{const r=d(e,{none:"&self, shard_key: Option<&str>",typed:a=>`&self, args: &${a}, shard_key: Option<&str>`,untyped:"&self, args: &WireValue, shard_key: Option<&str>"}),t=d(e,{none:"&WireValue::Object(Vec::new())",typed:()=>"&from_model_json(&serde_json::to_value(args).map_err(|error| ClientError::Transport(error.to_string()))?)",untyped:"args"}),n=`self.client.call(${Tr(e.verb)}, "${p(e.functionPath)}", ${t}, shard_key)`;return e.resultType===void 0?[` /// ${l(e.summary)}`,` pub fn ${T(e.functionName)}(${r}) -> Result<WireValue, ClientError> {`,` ${n}`," }"].join(`
219
+ `):[` /// ${l(e.summary)}`,` pub fn ${T(e.functionName)}(${r}) -> Result<${e.resultType}, ClientError> {`,` let raw = ${n}?;`," let json = encode_wire(&raw).map_err(ClientError::Wire)?;"," serde_json::from_value(json).map_err(|error| ClientError::Transport(error.to_string()))"," }"].join(`
220
+ `)},Or=e=>{const r=d(e,{none:"",typed:n=>`args: &${n}, `,untyped:"args: &WireValue, "}),t=d(e,{none:"WireValue::Object(Vec::new())",typed:()=>"from_model_json(&serde_json::to_value(args).map_err(|error| ClientError::Transport(error.to_string()))?)",untyped:"args.clone()"});return[` /// live ${l(e.summary)} — re-runs on every write to the tables it reads.`,` pub fn subscribe_${T(e.functionName)}(`," &mut self,",` ${r}on_data: DataHandler,`," on_error: ErrorHandler,"," shard_key: Option<&str>,"," ) -> Result<String, ClientError> {"," let _ = shard_key;",` Ok(self.client.subscribe("${p(e.functionPath)}", ${t}, on_data, on_error))`," }"].join(`
221
+ `)},Wr=e=>{const r=`${s(e.name)}Api`,t=e.methods.map(n=>n.verb==="query"?`${re(n)}
222
222
 
223
- ${kr(n)}`:ee(n)).join(`
223
+ ${Or(n)}`:re(n)).join(`
224
224
 
225
225
  `);return[`/// Functions declared in \`${l(e.name)}\`.`,`pub struct ${r}<'client> {`," client: &'client mut Client,","}","",`impl<'client> ${r}<'client> {`,t,"}"].join(`
226
- `)},_r=({models:e,namespaces:r})=>{const t=r.map(a=>[` /// Functions declared in \`${l(a.name)}\`.`,` pub fn ${S(a.name)}(&mut self) -> ${s(a.name)}Api<'_> {`,` ${s(a.name)}Api { client: self.client }`," }"].join(`
226
+ `)},Vr=({models:e,namespaces:r})=>{const t=r.map(a=>[` /// Functions declared in \`${l(a.name)}\`.`,` pub fn ${T(a.name)}(&mut self) -> ${s(a.name)}Api<'_> {`,` ${s(a.name)}Api { client: self.client }`," }"].join(`
227
227
  `)).join(`
228
228
 
229
- `),n=[k,`#![allow(dead_code, unused_imports)]
229
+ `),n=[_,`#![allow(dead_code, unused_imports)]
230
230
  `,`
231
231
  `,`use lunora::client::{Client, ClientError, DataHandler, ErrorHandler, Verb};
232
232
  `,`use lunora::wire::{encode_wire, from_model_json, WireValue};
233
233
  `,`
234
234
  `,`use crate::models::*;
235
235
  `,`
236
- `,r.map(a=>Tr(a)).join(`
236
+ `,r.map(a=>Wr(a)).join(`
237
237
 
238
238
  `),`
239
239
 
@@ -248,16 +248,16 @@ ${kr(n)}`:ee(n)).join(`
248
248
  `,t.length>0?`
249
249
  ${t}
250
250
  `:"",`}
251
- `].join("");return{"Cargo.toml":br,"src/api.rs":n,"src/lib.rs":vr,"src/models.rs":e.length>0?`${k}#![allow(dead_code)]
251
+ `].join("");return{"Cargo.toml":Sr,"src/api.rs":n,"src/lib.rs":_r,"src/models.rs":e.length>0?`${_}#![allow(dead_code)]
252
252
 
253
253
  ${e}
254
- `:`${k}#![allow(dead_code)]
254
+ `:`${_}#![allow(dead_code)]
255
255
 
256
256
  // No typed argument or result schemas in this deployment.
257
- `}},Sr={id:"rust",quicktype:{lang:"rust",rendererOptions:{"just-types":"true"}},render:_r,requires:["serde (derive) + serde_json — declared in the emitted Cargo.toml, fetched by cargo"],vendor:[{from:"Cargo.toml",to:"lunora/Cargo.toml"},{from:"src",to:"lunora/src"}]},N=`${f("swift").map(e=>`// ${e}`).join(`
257
+ `}},Lr={id:"rust",quicktype:{lang:"rust",rendererOptions:{"just-types":"true"}},render:Vr,requires:["serde (derive) + serde_json — declared in the emitted Cargo.toml, fetched by cargo"],vendor:[{from:"Cargo.toml",to:"lunora/Cargo.toml"},{from:"src",to:"lunora/src"}]},C=`${y("swift").map(e=>`// ${e}`).join(`
258
258
  `)}
259
259
 
260
- `,re="Sources/LunoraApi",Ar=`// swift-tools-version:5.9
260
+ `,te="Sources/LunoraApi",Nr=`// swift-tools-version:5.9
261
261
 
262
262
  import PackageDescription
263
263
 
@@ -287,20 +287,20 @@ let package = Package(
287
287
  .target(name: "LunoraApi", dependencies: ["Lunora"]),
288
288
  ]
289
289
  )
290
- `,Or=new Set(["as","associatedtype","borrowing","break","case","catch","class","consuming","continue","default","defer","deinit","do","else","enum","extension","fallthrough","false","fileprivate","for","func","guard","if","import","in","init","inout","internal","is","let","nil","nonisolated","open","operator","precedencegroup","private","protocol","public","repeat","rethrows","return","self","static","struct","subscript","super","switch","throw","throws","true","try","typealias","var","where","while"]),F=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return Or.has(t)?`\`${t}\``:t},te=e=>{const r=e.argsType===void 0?"shardKey: String? = nil":`_ args: ${e.argsType}, shardKey: String? = nil`,t=e.argsType===void 0?"nil":"try LunoraClient.wireValue(args)",n=e.resultType??"Any",a=`try client.${e.verb}("${d(e.functionPath)}", args: ${t}, shardKey: shardKey)`,i=e.resultType===void 0?`return ${a}`:[`let raw = ${a}`," let data = try JSONSerialization.data(withJSONObject: raw, options: [.fragmentsAllowed])",` return try JSONDecoder().decode(${e.resultType}.self, from: data)`].join(`
291
- `);return[` /// ${l(e.summary)}`,` public func ${F(e.functionName)}(${r}) throws -> ${n} {`,` ${i}`," }"].join(`
292
- `)},Wr=e=>{const r=e.argsType===void 0?"":`_ args: ${e.argsType}, `,t=e.argsType===void 0?"nil":"try LunoraClient.wireValue(args)";return[` /// live ${l(e.summary)} — re-runs on every write to the tables it reads.`," @discardableResult",` public func subscribe${s(e.functionName)}(`,` ${r}onData: ((Any) -> Void)?,`," onError: ((LunoraSubscriptionError) -> Void)? = nil,"," shardKey: String? = nil"," ) throws -> LunoraUnsubscribe {",` client.subscribe("${d(e.functionPath)}", args: ${t}, onData: onData, onError: onError, shardKey: shardKey)`," }"].join(`
293
- `)},Vr=e=>{const r=`${s(e.name)}API`,t=e.methods.map(n=>n.verb==="query"?`${te(n)}
290
+ `,Cr=new Set(["as","associatedtype","borrowing","break","case","catch","class","consuming","continue","default","defer","deinit","do","else","enum","extension","fallthrough","false","fileprivate","for","func","guard","if","import","in","init","inout","internal","is","let","nil","nonisolated","open","operator","precedencegroup","private","protocol","public","repeat","rethrows","return","self","static","struct","subscript","super","switch","throw","throws","true","try","typealias","var","where","while"]),R=e=>{const r=s(e),t=r.charAt(0).toLowerCase()+r.slice(1);return Cr.has(t)?`\`${t}\``:t},ye=e=>d(e,{none:"nil",typed:()=>"try LunoraClient.wireValue(args)",untyped:"args"}),ne=e=>{const r=d(e,{none:"shardKey: String? = nil",typed:o=>`_ args: ${o}, shardKey: String? = nil`,untyped:"_ args: Any, shardKey: String? = nil"}),t=ye(e),n=e.resultType??"Any",a=`try client.${e.verb}("${p(e.functionPath)}", args: ${t}, shardKey: shardKey)`,i=e.resultType===void 0?`return ${a}`:[`let raw = ${a}`," let data = try JSONSerialization.data(withJSONObject: raw, options: [.fragmentsAllowed])",` return try JSONDecoder().decode(${e.resultType}.self, from: data)`].join(`
291
+ `);return[` /// ${l(e.summary)}`,` public func ${R(e.functionName)}(${r}) throws -> ${n} {`,` ${i}`," }"].join(`
292
+ `)},Mr=e=>{const r=d(e,{none:"",typed:n=>`_ args: ${n}, `,untyped:"_ args: Any, "}),t=ye(e);return[` /// live ${l(e.summary)} — re-runs on every write to the tables it reads.`," @discardableResult",` public func subscribe${s(e.functionName)}(`,` ${r}onData: ((Any) -> Void)?,`," onError: ((LunoraSubscriptionError) -> Void)? = nil,"," shardKey: String? = nil"," ) throws -> LunoraUnsubscribe {",` client.subscribe("${p(e.functionPath)}", args: ${t}, onData: onData, onError: onError, shardKey: shardKey)`," }"].join(`
293
+ `)},Er=e=>{const r=`${s(e.name)}API`,t=e.methods.map(n=>n.verb==="query"?`${ne(n)}
294
294
 
295
- ${Wr(n)}`:te(n)).join(`
295
+ ${Mr(n)}`:ne(n)).join(`
296
296
 
297
297
  `);return[`/// Functions declared in \`${l(e.name)}\`.`,`public struct ${r} {`," let client: LunoraClient","",t,"}"].join(`
298
- `)},Lr=({models:e,namespaces:r})=>{const t=r.map(i=>` public let ${F(i.name)}: ${s(i.name)}API`).join(`
299
- `),n=r.map(i=>` ${F(i.name)} = ${s(i.name)}API(client: client)`).join(`
300
- `),a=[N,`import Foundation
298
+ `)},Pr=({models:e,namespaces:r})=>{const t=r.map(i=>` public let ${R(i.name)}: ${s(i.name)}API`).join(`
299
+ `),n=r.map(i=>` ${R(i.name)} = ${s(i.name)}API(client: client)`).join(`
300
+ `),a=[C,`import Foundation
301
301
  `,`import Lunora
302
302
  `,`
303
- `,r.map(i=>Vr(i)).join(`
303
+ `,r.map(i=>Er(i)).join(`
304
304
 
305
305
  `),`
306
306
 
@@ -312,9 +312,9 @@ ${Wr(n)}`:te(n)).join(`
312
312
  `:` _ = client
313
313
  `,` }
314
314
  `,`}
315
- `].join("");return{"Package.swift":Ar,[`${re}/Api.swift`]:a,[`${re}/Models.swift`]:e.length>0?`${N}${e}
316
- `:`${N}import Foundation
315
+ `].join("");return{"Package.swift":Nr,[`${te}/Api.swift`]:a,[`${te}/Models.swift`]:e.length>0?`${C}${e}
316
+ `:`${C}import Foundation
317
317
 
318
318
  // No typed argument or result schemas in this deployment.
319
- `}},Nr={id:"swift",quicktype:{lang:"swift",rendererOptions:{"access-level":"public"}},render:Lr,requires:[],vendor:[{from:"Sources/Lunora",to:"Sources/Lunora"}]},Cr={go:Te,java:Xe,kotlin:or,python:pr,ruby:gr,rust:Sr,swift:Nr},Pr=Object.keys(Cr).toSorted((e,r)=>e.localeCompare(r)),Kr=async(e,r)=>{const t=me(e);$e(t);const n=r.renderModels?.(e),a=n===void 0?await ge(e,r):Object.values(n).join(`
320
- `),i=fe(t,a);return{files:{...n,...r.render({models:a,namespaces:i})},undeclared:he(t,a),unrepresentable:ye(e)}};export{Pr as SDK_LANGUAGES,Cr as SDK_TARGETS,Kr as generateSdk,Ir as isTypedSchema};
319
+ `}},Kr={id:"swift",quicktype:{lang:"swift",rendererOptions:{"access-level":"public"}},render:Pr,requires:[],vendor:[{from:"Sources/Lunora",to:"Sources/Lunora"}]},xr={go:Oe,java:nr,kotlin:cr,python:hr,ruby:kr,rust:Lr,swift:Kr},Dr=Object.keys(xr).toSorted((e,r)=>e.localeCompare(r)),Fr=async(e,r)=>{const t=he(e);ge(t);const n=r.renderModels?.(e),a=n===void 0?await je(e,r):Object.values(n).join(`
320
+ `),i=be(t,a);return{files:{...n,...r.render({models:a,namespaces:i})},undeclared:we(t,a),unrepresentable:ve(e)}};export{Dr as SDK_LANGUAGES,xr as SDK_TARGETS,Fr as generateSdk,zr as isTypedSchema};
@@ -0,0 +1,2 @@
1
+ const p=/[^a-zA-Z0-9]+/gu,f=/([a-z0-9])([A-Z])/gu,l=t=>t.split(p).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),A=t=>t.replaceAll(f,"$1_$2").replaceAll(p,"_").toLowerCase(),i=t=>t===void 0?!1:["$ref","allOf","anyOf","enum","items","oneOf","properties","type"].some(e=>e in t),h=t=>t==="query"?"query":t==="action"?"action":"mutation",n=(t,e=0)=>{if(e>32||t===null||typeof t!="object")return!1;if(Array.isArray(t))return t.some(s=>n(s,e+1));const a=t;if(a.type==="integer"&&a.format==="int64"||a.type==="string"&&a.contentEncoding==="base64")return!0;const{properties:r}=a;return r!==null&&typeof r=="object"&&Object.values(r).some(s=>n(s,e+1))?!0:["additionalProperties","allOf","anyOf","items","oneOf"].some(s=>n(a[s],e+1))},b=t=>t.replaceAll(/[\n\r\u2028\u2029]+/gu," ").replaceAll("*/","* /").replaceAll('"""','" ""'),g=t=>t.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(`
2
+ `,"\\n").replaceAll("\r","\\r"),y=["$","{","'","$","'","}"].join(""),v=t=>g(t).split("$").join(y),T=(t,e)=>t.argsType!==void 0?e.typed(t.argsType):t.takesArgs?e.untyped:e.none,m=t=>{const[e="",a=""]=t.name.split(":"),r=`${l(e)}${l(a)}`,s=t.params?.[0]?.schema,o=t.result?.schema;return{argsType:i(s)&&!n(s)?`${r}Args`:void 0,takesArgs:i(s),functionName:a,functionPath:t.name,namespace:e,resultType:i(o)&&!n(o)?`${r}Result`:void 0,summary:t.summary??t.name,verb:h(t["x-lunora-function-kind"])}},S=t=>{const e=new Map;for(const a of t.methods){const r=m(a),s=e.get(r.namespace);s===void 0?e.set(r.namespace,[r]):s.push(r)}return[...e.entries()].toSorted(([a],[r])=>a.localeCompare(r)).map(([a,r])=>({methods:r.toSorted((s,o)=>s.functionName.localeCompare(o.functionName)),name:a}))},M=t=>t.methods.flatMap(e=>{const a=m(e);return[{name:a.argsType,schema:e.params?.[0]?.schema},{name:a.resultType,schema:e.result?.schema}]}).filter(e=>e.name!==void 0&&e.schema!==void 0).toSorted((e,a)=>e.name.localeCompare(a.name)),$=/^[A-Za-z][A-Za-z0-9]*$/u,d=t=>$.test(t),w=t=>{const e=new Map;for(const a of t.methods){const r=l(a.functionName);if(!d(r))throw new Error(`sdk: function "${a.functionPath}" produces the invalid identifier "${r}" — rename the export so it starts with a letter.`);const s=a.verb==="query"?[r,`Subscribe${r}`]:[r];for(const o of s){const c=e.get(o);if(c!==void 0)throw new Error(`sdk: functions "${c}" and "${a.functionPath}" both generate "${o}" — rename one so the generated methods stay distinct.`);e.set(o,a.functionPath)}}},C=t=>{const e=new Map;for(const a of t){const r=l(a.name);if(!d(r))throw new Error(`sdk: namespace "${a.name}" produces the invalid identifier "${r}" — rename the file so it starts with a letter.`);const s=e.get(r);if(s!==void 0)throw new Error(`sdk: namespaces "${s}" and "${a.name}" both generate "${r}" — rename one so the generated types stay distinct.`);e.set(r,a.name),w(a)}},u=t=>t.flatMap(e=>e.methods),k=t=>[`GENERATED by \`lunora sdk generate --lang ${t}\` — do not edit.`,"Run the command again to regenerate."],E=(t,e)=>{const a=r=>r!==void 0&&new RegExp(String.raw`\b${r}\b`,"u").test(e)?r:void 0;return t.map(r=>({methods:r.methods.map(s=>({...s,argsType:a(s.argsType),resultType:a(s.resultType)})),name:r.name}))},O=t=>t.methods.filter(e=>n(e.params?.[0]?.schema)||n(e.result?.schema)).map(e=>e.name).toSorted((e,a)=>e.localeCompare(a)),j=(t,e)=>[...new Set(u(t).flatMap(a=>[a.argsType,a.resultType]).filter(a=>a!==void 0&&!new RegExp(String.raw`\b${a}\b`,"u").test(e)))].toSorted((a,r)=>a.localeCompare(r)),x=t=>[...new Set(u(t).flatMap(e=>[e.argsType,e.resultType]).filter(e=>e!==void 0))].toSorted((e,a)=>e.localeCompare(a));export{u as allMethods,T as argsChoice,C as assertGeneratable,b as commentText,k as generatedHeaderLines,n as hasUnrepresentableWireType,i as isTypedSchema,v as kotlinLiteral,M as modelSources,m as parseMethod,S as parseSpec,x as referencedModels,g as stringLiteral,l as toPascalCase,A as toSnakeCase,j as undeclaredModels,O as unrepresentableFunctions,h as verbForKind,E as withDeclaredModels};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.104",
3
+ "version": "1.0.0-alpha.105",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1,2 +0,0 @@
1
- const m=/[^a-zA-Z0-9]+/gu,f=/([a-z0-9])([A-Z])/gu,l=t=>t.split(m).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),b=t=>t.replaceAll(f,"$1_$2").replaceAll(m,"_").toLowerCase(),c=t=>t===void 0?!1:["$ref","allOf","anyOf","enum","items","oneOf","properties","type"].some(e=>e in t),h=t=>t==="query"?"query":t==="action"?"action":"mutation",n=(t,e=0)=>{if(e>32||t===null||typeof t!="object")return!1;if(Array.isArray(t))return t.some(s=>n(s,e+1));const a=t;if(a.type==="integer"&&a.format==="int64"||a.type==="string"&&a.contentEncoding==="base64")return!0;const{properties:r}=a;return r!==null&&typeof r=="object"&&Object.values(r).some(s=>n(s,e+1))?!0:["additionalProperties","allOf","anyOf","items","oneOf"].some(s=>n(a[s],e+1))},A=t=>t.replaceAll(/[\n\r\u2028\u2029]+/gu," ").replaceAll("*/","* /").replaceAll('"""','" ""'),y=t=>t.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(`
2
- `,"\\n").replaceAll("\r","\\r"),g=["$","{","'","$","'","}"].join(""),v=t=>y(t).split("$").join(g),p=t=>{const[e="",a=""]=t.name.split(":"),r=`${l(e)}${l(a)}`,s=t.params?.[0]?.schema,o=t.result?.schema;return{argsType:c(s)&&!n(s)?`${r}Args`:void 0,functionName:a,functionPath:t.name,namespace:e,resultType:c(o)&&!n(o)?`${r}Result`:void 0,summary:t.summary??t.name,verb:h(t["x-lunora-function-kind"])}},T=t=>{const e=new Map;for(const a of t.methods){const r=p(a),s=e.get(r.namespace);s===void 0?e.set(r.namespace,[r]):s.push(r)}return[...e.entries()].toSorted(([a],[r])=>a.localeCompare(r)).map(([a,r])=>({methods:r.toSorted((s,o)=>s.functionName.localeCompare(o.functionName)),name:a}))},S=t=>t.methods.flatMap(e=>{const a=p(e);return[{name:a.argsType,schema:e.params?.[0]?.schema},{name:a.resultType,schema:e.result?.schema}]}).filter(e=>e.name!==void 0&&e.schema!==void 0).toSorted((e,a)=>e.name.localeCompare(a.name)),$=/^[A-Za-z][A-Za-z0-9]*$/u,d=t=>$.test(t),w=t=>{const e=new Map;for(const a of t.methods){const r=l(a.functionName);if(!d(r))throw new Error(`sdk: function "${a.functionPath}" produces the invalid identifier "${r}" — rename the export so it starts with a letter.`);const s=a.verb==="query"?[r,`Subscribe${r}`]:[r];for(const o of s){const i=e.get(o);if(i!==void 0)throw new Error(`sdk: functions "${i}" and "${a.functionPath}" both generate "${o}" — rename one so the generated methods stay distinct.`);e.set(o,a.functionPath)}}},M=t=>{const e=new Map;for(const a of t){const r=l(a.name);if(!d(r))throw new Error(`sdk: namespace "${a.name}" produces the invalid identifier "${r}" — rename the file so it starts with a letter.`);const s=e.get(r);if(s!==void 0)throw new Error(`sdk: namespaces "${s}" and "${a.name}" both generate "${r}" — rename one so the generated types stay distinct.`);e.set(r,a.name),w(a)}},u=t=>t.flatMap(e=>e.methods),C=t=>[`GENERATED by \`lunora sdk generate --lang ${t}\` — do not edit.`,"Run the command again to regenerate."],E=(t,e)=>{const a=r=>r!==void 0&&new RegExp(String.raw`\b${r}\b`,"u").test(e)?r:void 0;return t.map(r=>({methods:r.methods.map(s=>({...s,argsType:a(s.argsType),resultType:a(s.resultType)})),name:r.name}))},k=t=>t.methods.filter(e=>n(e.params?.[0]?.schema)||n(e.result?.schema)).map(e=>e.name).toSorted((e,a)=>e.localeCompare(a)),O=(t,e)=>[...new Set(u(t).flatMap(a=>[a.argsType,a.resultType]).filter(a=>a!==void 0&&!new RegExp(String.raw`\b${a}\b`,"u").test(e)))].toSorted((a,r)=>a.localeCompare(r)),j=t=>[...new Set(u(t).flatMap(e=>[e.argsType,e.resultType]).filter(e=>e!==void 0))].toSorted((e,a)=>e.localeCompare(a));export{u as allMethods,M as assertGeneratable,A as commentText,C as generatedHeaderLines,n as hasUnrepresentableWireType,c as isTypedSchema,v as kotlinLiteral,S as modelSources,p as parseMethod,T as parseSpec,j as referencedModels,y as stringLiteral,l as toPascalCase,b as toSnakeCase,O as undeclaredModels,k as unrepresentableFunctions,h as verbForKind,E as withDeclaredModels};