@lunora/codegen 1.0.0-alpha.8 → 1.0.0-alpha.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +2576 -823
- package/dist/index.d.ts +2576 -823
- package/dist/index.mjs +1 -29
- package/dist/packem_shared/AGENTS_FILENAME-BesaDYkL.mjs +1 -0
- package/dist/packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs +1 -0
- package/dist/packem_shared/CodegenDiagnosticError-DPezpZTz.mjs +1 -0
- package/dist/packem_shared/DEFAULT_TARGET-BYPEwgZu.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-UPE377GV.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-BSvZOCvj.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-CsAoG-d2.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-zA5OFFbv.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-Dco0Fvm4.mjs +3 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-fCPRec_w.mjs +12 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs +2 -0
- package/dist/packem_shared/SHAPES_FILENAME-DyVUZzIk.mjs +1 -0
- package/dist/packem_shared/SchemaSnapshotParseError-0KRzSjo4.mjs +14 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-CfLCgKoc.mjs +3 -0
- package/dist/packem_shared/discover-ast-CezKqEhE.mjs +1 -0
- package/dist/packem_shared/discover-queries-Ctpk9SA-.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-CYdI8pkP.mjs +1 -0
- package/dist/packem_shared/discoverCrons-CwtPaymU.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-CVYkUBTm.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-DmTedJlp.mjs +1 -0
- package/dist/packem_shared/discoverInserts-CssZuKb6.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-qyXaVjw1.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-GNP4oKrf.mjs +1 -0
- package/dist/packem_shared/discoverQueries-2A0lbpxV.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-B7uqLnVS.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-Bt0QK8VM.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-Bb2JzaIW.mjs +1 -0
- package/dist/packem_shared/discoverSchema-DUl8rbP3.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-VJ_uXOFe.mjs +1 -0
- package/dist/packem_shared/emit-B6-LPmOS.mjs +2170 -0
- package/dist/packem_shared/emitApp-DGiGQ1P4.mjs +449 -0
- package/dist/packem_shared/formatAdvisories-BCEfzLT0.mjs +2 -0
- package/dist/packem_shared/module-specifiers-8FEEiUcv.mjs +1 -0
- package/dist/packem_shared/parse-validator-_jDrFxwt.mjs +1 -0
- package/dist/packem_shared/paths-BmX5O1sG.mjs +1 -0
- package/dist/packem_shared/redact-6jD4lAhq.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-R1ZFzVyy.mjs +1 -0
- package/package.json +12 -7
- package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
- package/dist/packem_shared/GENERATED_HEADER-DF1hQcix.mjs +0 -2495
- package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
- package/dist/packem_shared/OPENRPC_VERSION-C7zKVeKi.mjs +0 -60
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Ic_wUaIc.mjs +0 -937
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs +0 -233
- package/dist/packem_shared/WORKFLOWS_FILENAME-D62dcBGg.mjs +0 -84
- package/dist/packem_shared/buildOpenApiDocument-Cns1EkCQ.mjs +0 -183
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-C35R6z0T.mjs +0 -62
- package/dist/packem_shared/discoverCrons-nHPo3UeE.mjs +0 -257
- package/dist/packem_shared/discoverFunctions-DEgAcRuD.mjs +0 -460
- package/dist/packem_shared/discoverHttpRoutes-C978pBiG.mjs +0 -131
- package/dist/packem_shared/discoverInserts-pLBFsSAV.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-B64zA740.mjs +0 -217
- package/dist/packem_shared/discoverMigrations-Dy24kmeD.mjs +0 -97
- package/dist/packem_shared/discoverNondeterministicCalls-4KiPQxQU.mjs +0 -122
- package/dist/packem_shared/discoverQueries-BkIi0dBD.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-BpDqvcUn.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-DpRB1HMe.mjs +0 -280
- package/dist/packem_shared/discoverSchema-fVmAXacI.mjs +0 -775
- package/dist/packem_shared/discoverStorageRulesMetadata-DAqJUxUv.mjs +0 -97
- package/dist/packem_shared/emitApp-Ci_hcJNO.mjs +0 -599
- package/dist/packem_shared/formatAdvisories-8NIv1k0I.mjs +0 -69
- package/dist/packem_shared/parse-validator-tuQtHrsr.mjs +0 -132
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as T}from"@lunora/errors";import{Node as s,SyntaxKind as j}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{c as w}from"./parse-validator-_jDrFxwt.mjs";import{createRequire as N}from"node:module";import{join as O}from"node:path";const $=e=>{switch(typeof e){case"bigint":return e.toString();case"boolean":case"number":return String(e);case"string":return JSON.stringify(e);default:return e===null?"null":void 0}},_=e=>({...e?.defaultValue!==void 0||e?.defaultFn!==void 0||e?.serverDefault!==void 0?{hasDefault:!0}:{},...e?.onUpdateFn===void 0?{}:{hasOnUpdate:!0},notNull:e?.notNull??!0,...e?.unique===!0?{unique:!0}:{}}),f=e=>{const r=e?._meta??{},t=e?.kind??"unknown",n={column:_(r.column),kind:t};switch(t){case"array":case"optional":{n.inner=f(r.inner);break}case"id":{n.tableName=r.tableName;break}case"literal":{n.literalValue=$(r.value);break}case"object":{const i=r.shape??{};n.shape=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,f(a)]));break}case"record":{n.valueType=f(r.valueValidator),r.keyValidator!==void 0&&(n.keyType=f(r.keyValidator));break}case"storage":{typeof r.bucket=="string"&&(n.bucket=r.bucket);break}case"union":{const i=r.members??[];n.members=i.map(o=>f(o));break}}return n},M=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",z=(e,r)=>{const t=[];e.relationMap&&Object.keys(e.relationMap).length>0&&t.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&t.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&t.push("vector indexes"),t.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${r}" declares ${t.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},D=(e,r)=>{const t=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return z(e,r),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:n,name:r,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(i=>({field:i.field,...i.filterFields?{filterFields:i.filterFields}:{},...i.language===void 0?{}:{language:i.language},...i.staged===void 0?{}:{staged:i.staged},...i.strategy===void 0?{}:{strategy:i.strategy},name:i.name})),shape:Object.fromEntries(Object.entries(t).map(([i,o])=>[i,f(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},B=e=>{const{key:r,tables:t}=e;if(typeof r!="string"||typeof t!="object"||t===null)return;const n=Object.entries(t).map(([a,l])=>D(l,a)),i=e.vectorIndexes??{},o=Object.entries(i??{}).map(([a,l])=>({...l.dimensions===void 0?{}:{dimensions:l.dimensions},...l.field===void 0?{}:{field:l.field},...l.metadata===void 0?{}:{metadata:l.metadata},...l.metric===void 0?{}:{metric:l.metric},name:a,table:l.table??""}));return{bareTables:n,bareVectorIndexes:o,key:r}},q=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r.getText():void 0}},F=e=>{const r=q(e);if(r===void 0)return;const t=s.isPropertyAccessExpression(e)?e.getName():void 0,n=t===void 0?[]:[t];for(const i of e.getSourceFile().getImportDeclarations()){const o=i.getModuleSpecifierValue();for(const a of i.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===r)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:n};if(i.getDefaultImport()?.getText()===r)return{importedName:"default",moduleSpecifier:o,propertyPath:n};if(i.getNamespaceImport()?.getText()===r&&t!==void 0)return{importedName:t,moduleSpecifier:o,propertyPath:[]}}},C=(e,r)=>{let t=e[r.importedName];for(const n of r.propertyPath){if(typeof t!="object"||t===null)return;t=t[n]}return t},V=(e,r)=>{const t=F(e);if(t)try{const n=N(O(r,"noop.cjs")),i=n.resolve(t.moduleSpecifier),o=n(i),a=C(o,t);return typeof a!="object"||a===null?void 0:B(a)}catch{return}},R=new Set(["cosine","dot-product","euclidean"]),J=new Set(["cascade","restrict","set null"]),v=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),U=(e,r)=>{if(v.has(e))throw u(r,`table name "${e}" is reserved — it collides with a \`ctx.db\` member (one of ${[...v].map(t=>`"${t}"`).join(", ")}). Rename the table.`)},d=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},m=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isNumericLiteral(n))return Number(n.getLiteralText())}},K=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&(s.isTrueLiteral(n)||s.isFalseLiteral(n)))return n.getLiteralValue()}},h=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isArrayLiteralExpression(n))return n.getElements().filter(i=>s.isStringLiteral(i)).map(i=>i.getLiteralText())}},E=e=>e&&R.has(e)?e:void 0,G=e=>e&&J.has(e)?e:void 0,H=e=>{if(!s.isArrowFunction(e))return;let r=e.getBody();if(s.isParenthesizedExpression(r))r=r.getExpression();else if(s.isBlock(r)){const t=r.getStatements().find(n=>s.isReturnStatement(n));r=t&&s.isReturnStatement(t)?t.getExpression()??r:r}return s.isObjectLiteralExpression(r)?r:void 0},Q=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return;const n=t.getName();if(n!=="one"&&n!=="many")return;const[i,o]=r.getArguments(),a=i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_";let l="_unknown_",c="_id",g;return o&&s.isObjectLiteralExpression(o)&&(l=d(o,"field")??l,c=d(o,"references")??c,g=n==="one"?G(d(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:g,references:c,table:a}},W=e=>{const r=H(e);if(!r)return[];const t=[];for(const n of r.getProperties()){const i=Q(n);i&&t.push(i)}return t},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",X=(e,r,t)=>{if(!r.includes("."))return;const[n="",...i]=r.split("."),o=`${n}${i.map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("")}`;throw u(e,`index "${t}" indexes the nested path ${JSON.stringify(r)} — Lunora indexes only top-level columns. Denormalise the value into its own column (e.g. \`${o}\`), index that instead, and keep it in sync with a table \`.triggers()\` beforeInsert/beforeUpdate.`)},Y=e=>{if(!e||!s.isObjectLiteralExpression(e))return!1;const r=e.getProperty("unique");if(!r||!s.isPropertyAssignment(r))return!1;const t=r.getInitializer();if(t===void 0)return!1;if(!s.isTrueLiteral(t)&&!s.isFalseLiteral(t))throw u(t,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(t.getText())}`);return s.isTrueLiteral(t)},Z=e=>{const[r,t,n]=e,i=Y(n),o=x(r),a=t&&s.isArrayLiteralExpression(t)?t.getElements():[];for(const c of a)if(!s.isStringLiteral(c))throw u(c,`index "${o}" lists a non-literal field (${JSON.stringify(c.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=a.filter(c=>s.isStringLiteral(c));for(const c of l)X(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:i}},ee=e=>{const[r,t]=e;let n="_unknown_",i,o,a,l;return t&&s.isObjectLiteralExpression(t)&&(n=d(t,"field")??n,i=h(t,"filterFields"),o=d(t,"language"),a=K(t,"staged"),l=d(t,"strategy")),{field:n,filterFields:i,language:o,name:x(r),staged:a,strategy:l}},te=e=>{const[r,t]=e;let n="_unknown_",i;return t&&s.isObjectLiteralExpression(t)&&(n=d(t,"field")??n,i=m(t,"precision")),{field:n,name:x(r),precision:i}},re=e=>{const[r,t]=e,n=r&&s.isStringLiteral(r)?r.getLiteralText():"_unknown_";let i;return t&&s.isObjectLiteralExpression(t)&&(i=m(t,"after")),{after:i,field:n}},ne=e=>{if(!s.isObjectLiteralExpression(e))return;const r=d(e,"field");return r===void 0?void 0:{direction:d(e,"direction")==="desc"?"desc":"asc",field:r}},ie=e=>{const[r,t]=e;let n=[],i;if(t&&s.isObjectLiteralExpression(t)){const o=t.getProperty("sortBy");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();a&&s.isArrayLiteralExpression(a)&&(n=a.getElements().map(l=>ne(l)).filter(l=>l!==void 0))}i=h(t,"partitionBy")}return{name:x(r),partitionBy:i,sortBy:n}},se=(e,r)=>{const[t,n]=e,i=t&&s.isStringLiteral(t)?t.getLiteralText():"_unknown_";if(!(!n||!s.isObjectLiteralExpression(n)))return{dimensions:m(n,"dimensions"),field:i,metadata:h(n,"metadata"),metric:E(d(n,"metric")),name:d(n,"index")??"_unnamed_",table:r}},oe=e=>{const r=e[0];return r&&s.isObjectLiteralExpression(r)&&d(r,"backend")==="hyperdrive"?"hyperdrive":"d1"},ae=e=>{if(e&&s.isObjectLiteralExpression(e)){const r=e.getProperty("field");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},p=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},le=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isArrayLiteralExpression(n)){const i=n.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText());return i.length>0?i:void 0}}},ce=e=>{const r=e[0];return!r||!s.isObjectLiteralExpression(r)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(r,"binding")??"",columns:le(r,"columns"),hasReconcile:r.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:r.getProperty("softDeleteColumn")!==void 0,hasTenantBy:r.getProperty("tenantBy")!==void 0,idColumn:p(r,"idColumn"),mode:p(r,"mode"),query:p(r,"query")}},de=(e,r,t,n)=>{switch(r){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(te(t));break}case"global":{e.shardMode="global",e.globalBackend=oe(t);break}case"index":{e.indexes.push(Z(t));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(ie(t));break}case"relations":{const i=t[0];i&&e.relations.push(...W(i));break}case"searchIndex":{e.searchIndexes.push(ee(t));break}case"shardBy":{const i=t[0];e.shardMode={field:i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:ae(t[0])};break}case"source":{e.externalSource=ce(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=re(t);break}case"vectorize":{const i=se(t,n);i&&e.vectorIndexes.push(i);break}}},L=(e,r)=>{const t={externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let n={},i=e;for(;s.isCallExpression(i);){const o=i.getExpression(),a=i.getArguments();if(s.isPropertyAccessExpression(o))de(t,o.getName(),a,r),i=o.getExpression();else if(s.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];if(l&&s.isObjectLiteralExpression(l))n=w(l);else if(l)throw u(l,`table "${r}" calls defineTable(${JSON.stringify(l.getText())}), but codegen reads the field map syntactically and can only read an object literal. Inline the fields into the defineTable(...) call. To reuse them in an \`.input()\`, derive from the generated \`Doc_${r}\` / \`Insert_${r}\` type instead of sharing the runtime value.`);break}else break}return t.softDelete&&!(t.softDelete.field in n)&&(n={...n,[t.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),{externallyManaged:t.externallyManaged,externalSource:t.externalSource,geoIndexes:t.geoIndexes,globalBackend:t.shardMode==="global"?t.globalBackend??"d1":void 0,indexes:t.indexes,isPublic:t.isPublic,name:r,rankIndexes:t.rankIndexes,relations:t.relations,searchIndexes:t.searchIndexes,shape:n,shardMode:t.shardMode,softDelete:t.softDelete,ttl:t.ttl,vectorIndexes:t.vectorIndexes}},ue=e=>{const r=e.getProperty("source");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isObjectLiteralExpression(t))return d(t,"table")??"_unknown_"}return"_unknown_"},ge=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isIdentifier(t)||t.getText()!=="defineVectorIndex")return;const n=r.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))return;const i=e.getNameNode(),o=s.isStringLiteral(i)?i.getLiteralText():i.getText();return{dimensions:m(n,"dimensions"),metric:E(d(n,"metric")),name:o,table:ue(n)}},P=e=>{const r=[];for(const t of e.getProperties()){const n=ge(t);n&&r.push(n)}return r},k=(e,r)=>`${e}_${r}`,y=(e,r,t)=>t.has(e)?k(r,e):e,fe=(e,r,t)=>{const n=k(r,e.name);return{...e,extensionKey:r,name:n,relations:e.relations.map(i=>({...i,table:y(i.table,r,t)})),vectorIndexes:e.vectorIndexes.map(i=>({...i,table:y(i.table,r,t)}))}},pe=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},me=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t))return t.getInitializer()},xe=e=>{if(!s.isCallExpression(e))return!1;const r=e.getExpression();return s.isIdentifier(r)&&r.getText()==="defineSchemaExtension"},be=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r:void 0}},ye=e=>{if(s.isObjectLiteralExpression(e))return e;if(s.isCallExpression(e)){const r=e.getExpression();let t;if(s.isIdentifier(r)?t=r.getText():s.isPropertyAccessExpression(r)&&(t=r.getName()),t==="definePlugin"){const n=e.getArguments()[1];return n&&s.isObjectLiteralExpression(n)?n:void 0}}},he=(e,r)=>{const t=pe(e);if(t){if(s.isPropertyAccessExpression(r)){const n=ye(t);return n?me(n,r.getName()):void 0}return t}},ke=e=>{let r=e,t=0;for(;r&&t<32;){if(t+=1,xe(r))return r;const n=be(r),i=n&&s.isIdentifier(n)?n.getSymbol():void 0,o=(i?.getAliasedSymbol()?.getDeclarations()??i?.getDeclarations()??[])[0];if(!o)return;const a=o.getSourceFile();if(a.isInNodeModules()||a.isDeclarationFile())return;r=he(o,r)}},Ie=e=>{const[r,t]=e.getArguments();if(!(!r||!s.isStringLiteral(r))&&!(!t||!s.isObjectLiteralExpression(t)))return{key:r.getLiteralText(),options:t}},ve=e=>{const r=e.getProperty("tables");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();if(!t||!s.isObjectLiteralExpression(t))return[];const n=[];for(const i of t.getProperties()){if(!s.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.push(L(o,i.getName()))}return n},Ee=e=>{const r=e.getProperty("vectorIndexes");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();return!t||!s.isObjectLiteralExpression(t)?[]:P(t)},S=(e,r,t)=>{const n=new Set(r.map(a=>a.name)),i=r.map(a=>fe(a,e,n)),o=t.map(a=>({...a,name:k(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Le=(e,r)=>S(e,ve(r),Ee(r)),Pe=(e,r)=>{const t=e.getArguments()[0];if(!t)return;const n=ke(t);if(!n){if(r!==void 0){const o=V(t,r);if(o)return S(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${t.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${r===void 0?"no project root was available to resolve the package":"the package could not be imported/introspected"}. Extension tables will be absent from the generated types.`);return}const i=Ie(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Le(i.key,i.options)},Se=e=>{const r=[];let t=e;for(;;){const n=t.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;n.getName()==="extend"&&r.push(i),t=i}return r},A=(e,r,t,n,i)=>{let o=e;for(;;){const a=o.getParent();if(!a||!s.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!s.isCallExpression(l))break;if(a.getName()===r){const c=l.getArguments()[0];if(!c||!s.isStringLiteral(c))throw u(l,`\`.${r}(...)\` expects a string literal (${i})`);const g=c.getLiteralText();if(!n.has(g))throw u(c,`unknown ${t} ${JSON.stringify(g)} — expected ${i}`);return g}o=l}},Ae=new Set(["eu","fedramp","us"]),Te=e=>A(e,"jurisdiction","jurisdiction",Ae,'"eu", "us", or "fedramp"'),je=new Set(["required"]),we=e=>A(e,"rls","rls mode",je,'"required"'),Ne=e=>{const r=[];for(const t of e.getProperties()){if(!s.isPropertyAssignment(t))continue;const n=t.getInitializer();if(n){const i=t.getName();U(i,t.getNameNode()),r.push(L(n,i))}}return r},Oe=(e,r,t)=>{const n=new Set(r.map(o=>o.name)),i=[];for(const o of Se(e)){const a=Pe(o,t);if(a){for(const l of a.tables){if(n.has(l.name))throw u(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);n.add(l.name),r.push(l)}i.push(...a.vectorIndexes)}}return i},qe=(e,r,t)=>{const n=e.addSourceFileAtPath(r).getDescendantsOfKind(j.CallExpression).find(b=>{const I=b.getExpression();return s.isIdentifier(I)&&I.getText()==="defineSchema"});if(!n)throw new T("INTERNAL",`defineSchema() not found in ${r}`);const i=n.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw u(n,"defineSchema() expects an object literal");const o=Ne(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?P(a):[],c=Oe(n,o,t),g=[...o.flatMap(b=>b.vectorIndexes),...l,...c];return{jurisdiction:Te(n),rlsMode:we(n),tables:o,vectorIndexes:g}};export{qe as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,classifyProcedureCall as g}from"./discoverFunctions-CVYkUBTm.mjs";const x=new Set(["delete","list","read","write"]),m=s=>{if(!i.isCallExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)?r.getText()==="storageRules":i.isPropertyAccessExpression(r)&&r.getName()==="storageRules"},E=s=>{const r=[];let t=s;for(;i.isCallExpression(t);){const e=t.getExpression();if(!i.isPropertyAccessExpression(e))break;if(e.getName()==="use"){const o=t.getArguments()[0];o&&m(o)&&r.push(o)}t=e.getExpression()}return r},u=(s,r)=>{if(!i.isObjectLiteralExpression(s))return;const t=s.getProperty(r);if(!t||!i.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&i.isStringLiteral(e)?e.getLiteralText():void 0},d=(s,r,t)=>{const e=s.getArguments()[0];if(!e||!i.isArrayLiteralExpression(e))return[];const o=[];for(const n of e.getElements()){if(!i.isObjectLiteralExpression(n))continue;const c=u(n,"on");if(c===void 0||!x.has(c))continue;const a=u(n,"prefix"),l={bucket:u(n,"bucket")??"",file:r,on:c,procedure:t};a!==void 0&&(l.prefix=a),o.push(l)}return o},v=s=>{const r=[];for(const t of s.getVariableStatements())if(t.isExported())for(const e of t.getDeclarations()){const o=e.getInitializer(),n=o&&i.isCallExpression(o)?g(o):void 0;n?.receiver&&r.push({name:e.getName(),receiver:n.receiver})}return r},A=(s,r)=>{const t=[];for(const e of f(r)){const o=s.getSourceFile(e)??s.addSourceFileAtPath(e),n=p(r,e);for(const{name:c,receiver:a}of v(o))for(const l of E(a))t.push(...d(l,n,c))}return{rules:t}};export{A as default};
|