@lunora/codegen 1.0.0-alpha.82 → 1.0.0-alpha.84
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 +584 -549
- package/dist/index.d.ts +584 -549
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/DEFAULT_TARGET-CH5disA3.mjs +1 -0
- package/dist/packem_shared/{FLAGS_FILENAME-UPE377GV.mjs → FLAGS_FILENAME-BiJh08O0.mjs} +1 -1
- package/dist/packem_shared/GENERATED_HEADER-oy7DTIDi.mjs +1 -0
- package/dist/packem_shared/{MUTATORS_FILENAME-CsAoG-d2.mjs → MUTATORS_FILENAME-9652koWz.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-zA5OFFbv.mjs → NOTIFY_FILENAME-DeIlwPBu.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-IKkrtXye.mjs → OPENRPC_VERSION-K3RTK2CP.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DHVrsPNK.mjs +9 -0
- package/dist/packem_shared/{SHAPES_FILENAME-DyVUZzIk.mjs → SHAPES_FILENAME-Cwn4I4UB.mjs} +1 -1
- package/dist/packem_shared/{buildOpenApiDocument-XeZ1ycwi.mjs → buildOpenApiDocument-Blf3mpIz.mjs} +1 -1
- package/dist/packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs +1 -0
- package/dist/packem_shared/discover-queries-B4Lw0cEr.mjs +1 -0
- package/dist/packem_shared/{discoverAuthApiCalls-CYdI8pkP.mjs → discoverAuthApiCalls-CVTXSguP.mjs} +1 -1
- package/dist/packem_shared/discoverCrons-CZ0_RXUc.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-9GMvSwz7.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-DmTedJlp.mjs → discoverHttpRoutes-VyBQ9CbN.mjs} +1 -1
- package/dist/packem_shared/{discoverInserts-CssZuKb6.mjs → discoverInserts-BGlOx2Cg.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-DpAT4zsu.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-qyXaVjw1.mjs → discoverMigrations-CcOvlTA7.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-GNP4oKrf.mjs → discoverNondeterministicCalls-CVY5_-x1.mjs} +1 -1
- package/dist/packem_shared/discoverQueries-BFFoJLOQ.mjs +1 -0
- package/dist/packem_shared/{discoverR2sqlCalls-B7uqLnVS.mjs → discoverR2sqlCalls-BKn9ogOI.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-Bt0QK8VM.mjs → discoverRlsMetadata-B2iTIbm0.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-Bb2JzaIW.mjs → discoverSandboxUsage-rkLj3ZC0.mjs} +1 -1
- package/dist/packem_shared/discoverSchema-1zm6abY5.mjs +1 -0
- package/dist/packem_shared/{discoverStorageRulesMetadata-VJ_uXOFe.mjs → discoverStorageRulesMetadata-AD_GPKdF.mjs} +1 -1
- package/dist/packem_shared/{emit-05q6XTbd.mjs → emit-B7IUlWwi.mjs} +265 -215
- package/dist/packem_shared/{emitApp-C2DhPKWE.mjs → emitApp-jRD2D9kI.mjs} +111 -37
- package/dist/packem_shared/parse-validator-DCrBLhq7.mjs +1 -0
- package/package.json +10 -10
- package/dist/packem_shared/DEFAULT_TARGET-BYPEwgZu.mjs +0 -1
- package/dist/packem_shared/GENERATED_HEADER-Cphn03Kf.mjs +0 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DBD0oti8.mjs +0 -12
- package/dist/packem_shared/discover-queries-Ctpk9SA-.mjs +0 -1
- package/dist/packem_shared/discoverCrons-CwtPaymU.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-CVYkUBTm.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs +0 -1
- package/dist/packem_shared/discoverQueries-2A0lbpxV.mjs +0 -1
- package/dist/packem_shared/discoverSchema-CaTD2Sdx.mjs +0 -1
- package/dist/packem_shared/parse-validator-_jDrFxwt.mjs +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readdirSync as C,lstatSync as $}from"node:fs";import{join as O,extname as j,relative as z,sep as U}from"node:path";import{Node as s,SyntaxKind as V}from"ts-morph";import{t as _}from"./module-specifiers-8FEEiUcv.mjs";import{s as R,c as h}from"./parse-validator-_jDrFxwt.mjs";import{n as M}from"./paths-BmX5O1sG.mjs";const y=new Set(["action","mutation","query","stream"]),P=/\bany\b(?!\s*(?:\?\s*)?:)/u,b=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,q=/^[A-Za-z_$][\w$]*$/u,B=e=>q.test(e)?e:JSON.stringify(e),H=/\.ts$/u,W=(e,t)=>z(e,t).split(U).join("/").replace(H,""),T={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},J={onConnect:"connect",onDisconnect:"disconnect"},Q=_,N=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return Q(n)?r.getNameNode().getText():void 0}},S=(e,t=!1)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!s.isIdentifier(i))return;const r=N(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?S(o,!0):void 0}return}return y.has(r)?"public":T[r]?"internal":void 0},d=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},G=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=d(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=d(i,"tag"),c=d(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},K=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=G(e),i=e.getProperty("rest");return i!==void 0&&s.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},Z=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return K(t.getArguments()[0]);t=i.getExpression()}},X=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!s.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:h(r)},Y=(e,t)=>{for(const i of[e.getSymbol(),e.getAliasSymbol()])if(i)for(const r of i.getDeclarations()){const n=r.getSourceFile();if(!(n.isInNodeModules()||n.isDeclarationFile())&&n.getFilePath()===t&&(s.isInterfaceDeclaration(r)||s.isTypeAliasDeclaration(r))&&!r.isExported())return!0}return!1},ee=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},I=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,g=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),Y(e,i)||ee(e).some(n=>g(n,t,i,r))?!0:I(e)?e.getProperties().some(n=>g(n.getTypeAtLocation(t),t,i,r)):!1),te=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(s.isPropertySignature(i)||s.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},ie=8,re=(e,t,i,r,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},ne=(e,t,i,r,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},se=(e,t,i,r,n,o)=>{if(!I(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),m=te(c,l),D=m&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],x=[];for(const f of D){const v=o(f,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${B(c.getName())}${m?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},p=(e,t,i,r,n)=>{if(r>ie||n.has(e))return;if(!g(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?re(e,t,i,r,o,p):e.isUnion()?ne(e,t,i,r,o,p):se(e,t,i,r,o,p)},k=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const r=(i.getSymbol()??i.getAliasSymbol())?.getName();if(r==="Promise"||r==="AsyncIterable"||r==="AsyncIterableIterator"||r==="AsyncGenerator"){const a=i.getTypeArguments()[0];a&&(i=a)}const n=i.getText(e);if(!n||n==="any"||n==="never"||P.test(n.replaceAll(b,"")))return"unknown";const o=e.getSourceFile().getFilePath();return g(i,e,o)?p(i,e,o,0,new Set)??"unknown":n},Te=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const i=t.getTypeAtLocation(e).getProperty("types");if(!i)return;const r=i.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!r)return;const n=r.getTypeAtLocation(e),o=n.getText(e);if(!o||o==="any"||o==="never"||P.test(o.replaceAll(b,"")))return;const a=e.getSourceFile().getFilePath();return g(n,e,a)?p(n,e,a,0,new Set):o},oe=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":k(r)},ae=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":k(t)},ce=e=>{let t={},i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...h(n),...t})}i=r.getExpression()}return t},le=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="output"){const r=t.getArguments()[0];return r&&s.isExpression(r)?R(r):void 0}t=i.getExpression()}},ue=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!y.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=S(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=N(t);if(!i)return;if(y.has(i))return{kind:i,visibility:"public"};const r=T[i];if(r)return{kind:r,visibility:"internal"};const n=J[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},A=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,Ne=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Se=e=>{const t=e.getArguments()[0],i=A(t);if(i!==void 0)return i;if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&s.isPropertyAssignment(r)?A(r.getInitializer()):void 0},pe=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Ie=(e,t)=>{let i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},ke=(e,t,i)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=r.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&pe(o.getExpression())===i)return!0;r=n.getExpression()}return!1},w=(e,t=[],i=e)=>{let r;try{r=C(e)}catch{return t}for(const n of r){const o=O(e,n),a=$(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;w(o,t,i)}else if(a.isFile()&&j(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},ge=e=>{const t=ue(e);if(t){if(t.receiver){const i=Z(t.receiver),r=le(t.receiver);return{args:ce(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:ae(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:X(e),kind:t.kind,returnType:oe(e),visibility:t.visibility}}},fe=8,u=(e,t=0)=>{if(t>fe)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?F(i,t+1):void 0},F=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(V.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?F(r,t+1):void 0}},de=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const i=e.getInitializer(),r=i&&(s.isCallExpression(i)?i:u(i));return r?[[e.getName(),r]]:[]},L=(e,t,i)=>{const r=ge(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},ye=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=u(r.getExpression()),o=n?L(n,"default",t):void 0;o&&i.push(o)}return i},me=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of de(n)){const c=L(a,o,t);c&&i.push(c)}return i.push(...ye(e,t)),i},xe=e=>{const t=new Map;for(const i of e){const r=M(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},we=(e,t)=>{const i=w(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=W(t,n);r.push(...me(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),xe(r),r};export{Ie as chainHasStep,ke as chainUsesWrappedCall,ue as classifyProcedureCall,we as discoverFunctions,A as inlineHandler,Ne as isDatabaseAccessor,w as listLunoraSourceFiles,W as lunoraRelativePath,Se as procedureHandler,Te as resolveStandardSchemaType,k as unwrapHandlerReturn};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Node as n,SyntaxKind as P}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as E,classifyProcedureCall as g}from"./discoverFunctions-CVYkUBTm.mjs";const S=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="mask":n.isPropertyAccessExpression(e)?e.getName()==="mask":!1},f=t=>{if(n.isPropertyAssignment(t)||n.isShorthandPropertyAssignment(t)||n.isMethodDeclaration(t)||n.isGetAccessorDeclaration(t))return t.getName()},v=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,table:o})}}return s},p=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=s.getArguments()[0];o&&S(o)&&e.push(o)}s=r.getExpression()}return e},A=t=>{const e=p(t);return{maskColumns:e.flatMap(s=>v(s)),usesMask:e.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),k=new Set(["delete","insert","patch","replace"]),x=(t,e)=>{const s=t.getExpression();if(!n.isPropertyAccessExpression(s)||!e.has(s.getName()))return!1;const r=s.getExpression();return n.isPropertyAccessExpression(r)?r.getName()==="db":n.isIdentifier(r)&&r.getText()==="db"},b=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},L=t=>{const e=new Set,s=new Set;for(const r of t.getDescendantsOfKind(P.CallExpression))if(x(r,y)){const o=b(r);o!==""&&e.add(o)}else if(x(r,k)){const o=b(r);o!==""&&s.add(o)}return{tablesRead:[...e],tablesWritten:[...s]}},M=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=g(s);if(!r)return;const o=r.receiver?A(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:i,tablesWritten:a}=L(t);return{exportName:t.getName(),file:e,maskColumns:o.maskColumns,tablesRead:i,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},O=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,i);l&&s.push(l)}}return s},h=t=>{if(n.isPropertyAssignment(t)){const e=t.getInitializer();if(e&&n.isStringLiteral(e)){const s=e.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},C=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,strategy:h(a),table:o})}}return s},N=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const o=r.getInitializer(),i=o&&n.isCallExpression(o)?g(o):void 0;i?.receiver&&e.push(i.receiver)}return e},j=(t,e)=>{const s=new Map;for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const i of N(o))for(const a of p(i))for(const c of C(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},F=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isObjectLiteralExpression(r))return[];const o=[];for(const i of r.getProperties()){const a=f(i);if(a===void 0||!n.isPropertyAssignment(i))continue;const c=i.getInitializer();if(!(!c||!n.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=f(l);if(m===void 0)continue;const d=h(l);d!=="custom"&&o.push({column:m,exportName:e,file:s,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},I=(t,e)=>{if(!n.isVariableDeclaration(t))return[];const s=t.getInitializer(),r=s&&n.isCallExpression(s)?g(s):void 0;return r?.receiver?p(r.receiver).flatMap(o=>F(o,t.getName(),e)):[]},w=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...I(c,i))}return s};export{O as default,j as discoverMaskMetadata,w as discoverMaskStrategies};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"ts-morph";import{y as p}from"./discover-queries-Ctpk9SA-.mjs";import"./discoverFunctions-CVYkUBTm.mjs";export{p as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as $}from"@lunora/errors";import{Node as s,SyntaxKind as A}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{c as j}from"./parse-validator-_jDrFxwt.mjs";import{createRequire as N}from"node:module";import{join as _}from"node:path";const O=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}},z=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:z(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=O(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",D=(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.`)},B=(e,r)=>{const t=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return D(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:[]}},F=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])=>B(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}},C=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:[]}}},R=(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=C(e);if(t)try{const n=N(_(r,"noop.cjs")),i=n.resolve(t.moduleSpecifier),o=n(i),a=R(o,t);return typeof a!="object"||a===null?void 0:F(a)}catch{return}},J=new Set(["cosine","dot-product","euclidean"]),U=new Set(["cascade","restrict","set null"]),v=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),K=(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())}},Q=(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())}},L=e=>e&&J.has(e)?e:void 0,X=e=>e&&U.has(e)?e:void 0,G=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},H=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"?X(d(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:g,references:c,table:a}},W=e=>{const r=G(e);if(!r)return[];const t=[];for(const n of r.getProperties()){const i=H(n);i&&t.push(i)}return t},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",Y=(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.`)},Z=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)},ee=e=>{const[r,t,n]=e,i=Z(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)Y(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:i}},te=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=Q(t,"staged"),l=d(t,"strategy")),{field:n,filterFields:i,language:o,name:x(r),staged:a,strategy:l}},re=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}},ne=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}},ie=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}},se=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=>ie(l)).filter(l=>l!==void 0))}i=h(t,"partitionBy")}return{name:x(r),partitionBy:i,sortBy:n}},oe=(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:L(d(n,"metric")),name:d(n,"index")??"_unnamed_",table:r}},ae=e=>{const r=e[0];return r&&s.isObjectLiteralExpression(r)&&d(r,"backend")==="hyperdrive"?"hyperdrive":"d1"},le=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()}},ce=(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}}},de=e=>{const r=e[0];return!r||!s.isObjectLiteralExpression(r)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(r,"binding")??"",columns:ce(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")}},ue=(e,r,t,n)=>{switch(r){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(re(t));break}case"global":{e.shardMode="global",e.globalBackend=ae(t);break}case"index":{e.indexes.push(ee(t));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(se(t));break}case"relations":{const i=t[0];i&&e.relations.push(...W(i));break}case"searchIndex":{e.searchIndexes.push(te(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:le(t[0])};break}case"source":{e.externalSource=de(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=ne(t);break}case"vectorize":{const i=oe(t,n);i&&e.vectorIndexes.push(i);break}}},E=["__vocab","_config","_content","_data","_docsize","_idx"],ge=(e,r,t)=>{const n=new Set(t.map(i=>i.name));for(const i of t)for(const o of E){const a=`${i.name}${o}`;if(!n.has(a))continue;const l=o==="__vocab"?`the \`fts5vocab\` companion for "${a}" is created \`IF NOT EXISTS\`, so it silently resolves to "${i.name}"'s — the second index then reads the wrong vocabulary and returns wrong results, with no error`:`creating "${a}" is rejected (\`object name reserved for internal use: SQLITE_ERROR\`), which aborts the shard migration and leaves every sharded table unreadable`;throw u(e,`table "${r}" declares search indexes "${i.name}" and "${a}", whose generated FTS5 tables collide: "${i.name}" already owns "${r}__fts_${a}" as its "${o}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${E.join(", ")}.`)}},P=(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))ue(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=j(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"}}),ge(e,r,t.searchIndexes),{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}},fe=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_"},pe=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:L(d(n,"metric")),name:o,table:fe(n)}},S=e=>{const r=[];for(const t of e.getProperties()){const n=pe(t);n&&r.push(n)}return r},I=(e,r)=>`${e}_${r}`,y=(e,r,t)=>t.has(e)?I(r,e):e,me=(e,r,t)=>{const n=I(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)}))}},xe=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},be=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t))return t.getInitializer()},ye=e=>{if(!s.isCallExpression(e))return!1;const r=e.getExpression();return s.isIdentifier(r)&&r.getText()==="defineSchemaExtension"},he=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r:void 0}},Ie=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}}},ke=(e,r)=>{const t=xe(e);if(t){if(s.isPropertyAccessExpression(r)){const n=Ie(t);return n?be(n,r.getName()):void 0}return t}},ve=e=>{let r=e,t=0;for(;r&&t<32;){if(t+=1,ye(r))return r;const n=he(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=ke(o,r)}},Ee=e=>{const[r,t]=e.getArguments();if(!(!r||!s.isStringLiteral(r))&&!(!t||!s.isObjectLiteralExpression(t)))return{key:r.getLiteralText(),options:t}},Le=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(P(o,i.getName()))}return n},Pe=e=>{const r=e.getProperty("vectorIndexes");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();return!t||!s.isObjectLiteralExpression(t)?[]:S(t)},w=(e,r,t)=>{const n=new Set(r.map(a=>a.name)),i=r.map(a=>me(a,e,n)),o=t.map(a=>({...a,name:I(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Se=(e,r)=>w(e,Le(r),Pe(r)),we=(e,r)=>{const t=e.getArguments()[0];if(!t)return;const n=ve(t);if(!n){if(r!==void 0){const o=V(t,r);if(o)return w(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=Ee(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Se(i.key,i.options)},Te=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},T=(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}},$e=new Set(["eu","fedramp","us"]),Ae=e=>T(e,"jurisdiction","jurisdiction",$e,'"eu", "us", or "fedramp"'),je=new Set(["required"]),Ne=e=>T(e,"rls","rls mode",je,'"required"'),_e=e=>{const r=[];for(const t of e.getProperties()){if(!s.isPropertyAssignment(t))continue;const n=t.getInitializer();if(n){const i=t.getName();K(i,t.getNameNode()),r.push(P(n,i))}}return r},Oe=(e,r,t)=>{const n=new Set(r.map(o=>o.name)),i=[];for(const o of Te(e)){const a=we(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},Ce=(e,r,t)=>{const n=e.addSourceFileAtPath(r).getDescendantsOfKind(A.CallExpression).find(b=>{const k=b.getExpression();return s.isIdentifier(k)&&k.getText()==="defineSchema"});if(!n)throw new $("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=_e(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?S(a):[],c=Oe(n,o,t),g=[...o.flatMap(b=>b.vectorIndexes),...l,...c];return{jurisdiction:Ae(n),rlsMode:Ne(n),tables:o,vectorIndexes:g}};export{Ce as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as c}from"@lunora/errors";import{Node as r}from"ts-morph";let l;const w=e=>{l=e},d=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","unique"]),k=(e,n)=>{const t={notNull:!0,...e.column};switch(n){case"$defaultFn":case"default":case"defaultNow":{t.hasDefault=!0;break}case"$onUpdateFn":{t.hasOnUpdate=!0;break}case"$type":break;case"nullable":{t.notNull=!1;break}case"unique":{t.unique=!0;break}}return{...e,column:t}},f=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),g=new Set(["check","meta"]),o=e=>r.isCallExpression(e)?N(e):{kind:"any",sourceText:e.getText()},m=e=>{const n={};for(const t of e.getProperties()){if(!r.isPropertyAssignment(t))continue;const s=t.getNameNode();if(r.isComputedPropertyName(s))continue;const i=t.getInitializer();if(!i)continue;const a=t.getName();if(!d.test(a))throw new c("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(a)}`);n[a]=o(i)}return n},u=(e,n)=>e&&r.isExpression(e)?o(e):n,y=e=>e===void 0?"undefined":r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),b=e=>{const n=e&&l?l(e):void 0;return n===void 0?{kind:"from"}:{kind:"from",tsType:n}},x=(e,n)=>{if(f.has(e))return{kind:e};const[t,s]=n;switch(e){case"array":return{inner:u(t,{kind:"any"}),kind:"array"};case"from":return b(t);case"id":return{kind:"id",tableName:t&&r.isStringLiteral(t)?t.getLiteralText():"_unknown_"};case"literal":return{kind:"literal",literalValue:y(t)};case"object":return t&&r.isObjectLiteralExpression(t)?{kind:"object",shape:m(t)}:{kind:"object",shape:{}};case"optional":return{inner:u(t,{kind:"any"}),kind:"optional"};case"record":return{keyType:u(t,{kind:"string"}),kind:"record",valueType:u(s,{kind:"any"})};case"storage":return t&&r.isStringLiteral(t)?{bucket:t.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:n.filter(i=>r.isExpression(i)).map(i=>o(i))};default:throw new c("INTERNAL",`Unsupported validator kind: ${e}`)}},N=e=>{const n=e.getExpression();if(!r.isPropertyAccessExpression(n))return{kind:"any",sourceText:e.getText()};const t=n.getName(),s=e.getArguments();if(p.has(t)){const i=n.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return k(a,t)}if(g.has(t)){const i=n.getExpression(),a=r.isExpression(i)?o(i):{kind:"any"};return t==="check"?{...a,hasRefinement:!0}:a}return x(t,s)};export{m as c,w as p,o as s};
|