@lunora/codegen 1.0.0-alpha.55 → 1.0.0-alpha.56
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 +59 -5
- package/dist/index.d.ts +59 -5
- package/dist/index.mjs +1 -38
- 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/FLAGS_FILENAME-DW5oGq1q.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-C94PuLpQ.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-BKKPROzu.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-C-c7Lg-U.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-DpV3v2W8.mjs +3 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DJsxljOQ.mjs +3 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs +15 -0
- package/dist/packem_shared/SHAPES_FILENAME-DTkSJSsg.mjs +1 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-DXX1G3GZ.mjs +3 -0
- package/dist/packem_shared/discover-ast-CezKqEhE.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-DOfSQqVK.mjs +1 -0
- package/dist/packem_shared/discoverCrons-B09_uEuL.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-BdibLQmc.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-BOWz6y_n.mjs +1 -0
- package/dist/packem_shared/discoverInserts-BtteTyNy.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-COPmwMBm.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-iGMlp9YJ.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-Dmgc4QBx.mjs +1 -0
- package/dist/packem_shared/discoverQueries-CcfuGKHh.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-CjZKvg-N.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-BXmNOgry.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-CDdBqWcM.mjs +1 -0
- package/dist/packem_shared/discoverSchema-m2voTncu.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-b71cJJHz.mjs +1 -0
- package/dist/packem_shared/emit-Dr6XSLfW.mjs +2104 -0
- package/dist/packem_shared/emitApp-B671iU7r.mjs +413 -0
- package/dist/packem_shared/formatAdvisories-DZvv-0MG.mjs +2 -0
- package/dist/packem_shared/parse-validator-CSDlMEvE.mjs +1 -0
- package/dist/packem_shared/paths-BmX5O1sG.mjs +1 -0
- package/dist/packem_shared/redact-CQ8-to6l.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-R1ZFzVyy.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/AGENTS_FILENAME-Cxx7wiSs.mjs +0 -158
- package/dist/packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs +0 -24
- package/dist/packem_shared/FLAGS_FILENAME-D5igzqwR.mjs +0 -139
- package/dist/packem_shared/GENERATED_HEADER-C8tAvxqP.mjs +0 -4
- package/dist/packem_shared/LUNORA_ERROR_CODES-DvTLozCu.mjs +0 -68
- package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +0 -81
- package/dist/packem_shared/NOTIFY_FILENAME-CK2IrsrP.mjs +0 -152
- package/dist/packem_shared/OPENRPC_VERSION-DvDChMhC.mjs +0 -60
- package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +0 -145
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-YAL6GrxI.mjs +0 -3597
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DGD73E_n.mjs +0 -252
- package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +0 -94
- package/dist/packem_shared/WORKFLOWS_FILENAME-Dtuzvluc.mjs +0 -158
- package/dist/packem_shared/buildOpenApiDocument-DCQSLuFc.mjs +0 -262
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-Dhwgf4J4.mjs +0 -62
- package/dist/packem_shared/discoverCrons-UbQLLmMS.mjs +0 -286
- package/dist/packem_shared/discoverFunctions-COG_Xkyz.mjs +0 -544
- package/dist/packem_shared/discoverHttpRoutes-CVXWZkzo.mjs +0 -139
- package/dist/packem_shared/discoverInserts-DdWnXmLS.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-BG58_fw3.mjs +0 -273
- package/dist/packem_shared/discoverMigrations-Bw1U01zr.mjs +0 -97
- package/dist/packem_shared/discoverNondeterministicCalls-BbXEFZUT.mjs +0 -122
- package/dist/packem_shared/discoverQueries-CDmxu2ET.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-Bn7QVv7J.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-D9uN35no.mjs +0 -280
- package/dist/packem_shared/discoverSandboxUsage-B5jDU6Bt.mjs +0 -38
- package/dist/packem_shared/discoverSchema-BJp5_T4o.mjs +0 -906
- package/dist/packem_shared/discoverStorageRulesMetadata-BqMhuEjo.mjs +0 -97
- package/dist/packem_shared/emit-DIbr7U31.mjs +0 -3884
- package/dist/packem_shared/emitApp-DbMM8iHe.mjs +0 -706
- package/dist/packem_shared/formatAdvisories-Cans5TWS.mjs +0 -131
- package/dist/packem_shared/parse-validator-BDGV8iue.mjs +0 -144
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/redact-oTmsol5A.mjs +0 -33
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{isValidCronExpression as A,compileCronSchedule as b,CRON_SCHEDULE_KINDS as O}from"@lunora/scheduler";import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as S}from"./discoverFunctions-BdibLQmc.mjs";import{n as $}from"./paths-BmX5O1sG.mjs";const I=new Set([...O,"cron"]),j=new Set(["@lunora/scheduler","@lunora/server"]),y=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(n.isImportSpecifier(r))return j.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},R=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const i=r.getInitializer();if(i?.getKind()!==p.CallExpression)continue;const a=i.getExpression();n.isIdentifier(a)&&y(a)&&t.add(r.getName())}return t},P=e=>{let t=e;for(;n.isCallExpression(t)||n.isPropertyAccessExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t.getText():void 0},C=(e,t)=>{const r=e.getArguments()[t];return r&&(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue();if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1;if(n.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(n.isNumericLiteral(r))return-r.getLiteralValue()}if(n.isObjectLiteralExpression(e))return g(e,t);if(n.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},g=(e,t)=>{const r={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))throw f(i,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const a=i.getInitializer();a&&(r[i.getName()]=_(a,t))}return r},x=(e,t,r)=>{const i=e.getArguments()[t];if(!i||!n.isPropertyAccessExpression(i))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=i.getName(),o=i.getExpression();if(!n.isPropertyAccessExpression(o))throw f(i,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=o.getName();return`${$(s)}:${a}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,i,a,o)=>{const s=e.getExpression();if(!n.isIdentifier(s)||s.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${i}" targets ${t}.${e.getName()}, but no such ${a} is declared in lunora/${a}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},D=(e,t,r,i,a)=>{const o=e.getArguments()[t];if(o&&n.isPropertyAccessExpression(o)){const s=T(o,"workflows",i,r,"workflow",h);return s||T(o,"agents",a,r,"agent",w)||{functionPath:x(e,t,r)}}if(o&&n.isIdentifier(o)){const s=i.get(o.getText()),c=a.get(o.getText());if(s&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(s)return h(s);if(c)return w(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:x(e,t,r)}},k=(e,t,r,i,a)=>{const o=t.getName();if(!I.has(o)||!r.has(P(t.getExpression())??""))return;const s=C(e,0);if(s===void 0||s.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});let c;if(o==="cron"){const l=C(e,1);if(l===void 0)throw f(e,`Cron job "${s}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!A(l))throw f(e,`Cron job "${s}" has an invalid cron expression "${l}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});c=l}else{const l=e.getArguments()[1];if(!l||!n.isObjectLiteralExpression(l))throw f(e,`Cron job "${s}" must pass an object-literal schedule to ".${o}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});c=b(o,g(l,s))}const u=D(e,2,s,i,a),m=e.getArguments()[3];return{args:m&&n.isObjectLiteralExpression(m)?g(m,s):{},cron:c,name:s,...u}},F=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},z=(e,t,r=[],i=[])=>{const a=S(t),o=[],s=new Map(r.map(u=>[u.exportName,u])),c=new Map(i.map(u=>[u.exportName,u]));for(const u of a){const m=e.getSourceFile(u)??e.addSourceFileAtPath(u),l=R(m);if(l.size!==0)for(const d of m.getDescendantsOfKind(p.CallExpression)){const N=d.getExpression();if(!n.isPropertyAccessExpression(N))continue;const E=k(d,N,l,s,c);E&&o.push(E)}}return o.sort((u,m)=>u.name.localeCompare(m.name)),F(o),o};export{z as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdirSync as k,lstatSync as $}from"node:fs";import{join as w,extname as D,relative as F,sep as C}from"node:path";import{Node as s,SyntaxKind as j}from"ts-morph";import{d as b}from"./parse-validator-CSDlMEvE.mjs";import{n as O}from"./paths-BmX5O1sG.mjs";const d=new Set(["action","mutation","query","stream"]),U=/\bany\b(?!\s*(?:\?\s*)?:)/u,z=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,L=/^[A-Za-z_$][\w$]*$/u,V=e=>L.test(e)?e:JSON.stringify(e),_=/\.ts$/u,M=(e,t)=>F(e,t).split(C).join("/").replace(_,""),v={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},H={onConnect:"connect",onDisconnect:"disconnect"},R=/(?:^|\/)_generated\/server(?:\.js)?$/u,B=e=>e==="@lunora/server"||R.test(e),A=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 B(n)?r.getNameNode().getText():void 0}},h=(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=A(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?h(o,!0):void 0}return}return d.has(r)?"public":v[r]?"internal":void 0},q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose"){const r=t.getArguments()[0];if(r!==void 0&&s.isObjectLiteralExpression(r)){const n=r.getProperty("rest");if(n!==void 0&&s.isPropertyAssignment(n))return{rest:n.getInitializer()?.getText()==="true"}}return{}}t=i.getExpression()}},J=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)?{}:b(r)},K=(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},Q=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},P=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),K(e,i)||Q(e).some(n=>p(n,t,i,r))?!0:P(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),G=(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())},W=8,Z=(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}[]`},X=(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(" | ")},Y=(e,t,i,r,n,o)=>{if(!P(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),y=G(c,l),I=y&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],m=[];for(const f of I){const x=o(f,t,i,r+1,n);if(x===void 0)return;m.push(x)}a.push(`${V(c.getName())}${y?"?":""}: ${m.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>W||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?Z(e,t,i,r,o,g):e.isUnion()?X(e,t,i,r,o,g):Y(e,t,i,r,o,g)},S=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"||U.test(n.replaceAll(z,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},ee=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":S(r)},te=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":S(t)},ie=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={...b(n),...t})}i=r.getExpression()}return t},re=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!d.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=h(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=A(t);if(!i)return;if(d.has(i))return{kind:i,visibility:"public"};const r=v[i];if(r)return{kind:r,visibility:"internal"};const n=H[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},E=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,me=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",xe=e=>{const t=e.getArguments()[0],i=E(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)?E(r.getInitializer()):void 0},ne=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Ee=(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},be=(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)&&ne(o.getExpression())===i)return!0;r=n.getExpression()}return!1},N=(e,t=[],i=e)=>{let r;try{r=k(e)}catch{return t}for(const n of r){const o=w(e,n),a=$(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;N(o,t,i)}else if(a.isFile()&&D(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},se=e=>{const t=re(e);if(t){if(t.receiver){const i=q(t.receiver);return{args:ie(t.receiver),...i?{expose:i}:{},kind:t.kind,returnType:te(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:J(e),kind:t.kind,returnType:ee(e),visibility:t.visibility}}},oe=8,u=(e,t=0)=>{if(t>oe)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?T(i,t+1):void 0},T=(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(j.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?T(r,t+1):void 0}},ae=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]]:[]},ce=(e,t,i)=>{const r=se(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},le=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ae(n)){const c=ce(a,o,t);c&&i.push(c)}return i},ue=e=>{const t=new Map;for(const i of e){const r=O(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)}},ve=(e,t)=>{const i=N(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=M(t,n);r.push(...le(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ue(r),r};export{Ee as chainHasStep,be as chainUsesWrappedCall,re as classifyProcedureCall,ve as discoverFunctions,E as inlineHandler,me as isDatabaseAccessor,N as listLunoraSourceFiles,M as lunoraRelativePath,xe as procedureHandler,S as unwrapHandlerReturn};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{relative as m,sep as h}from"node:path";import{Node as a}from"ts-morph";import{listLunoraSourceFiles as l,unwrapHandlerReturn as f}from"./discoverFunctions-BdibLQmc.mjs";import{s as d,d as g}from"./parse-validator-CSDlMEvE.mjs";const x=/\.ts$/u,u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),P=new Set(["handler","stream"]),A=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},y=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?g(e):{}},b=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=A(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const p=i.getName();if(u.has(p))break;if(E.has(p)){const c=y(s);o[p]={...c,...o[p]}}else if(p==="output"&&o.output===void 0){const c=s.getArguments()[0];c&&a.isExpression(c)&&(o.output=d(c))}s=i.getExpression()}const t=b(s);if(t)return o.method=t.method,o.path=t.path,o},C=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":f(e)},v=(r,e,o,n)=>{const s=e.getName();if(!P.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:C(r)}:{},...t.output?{output:t.output}:{}}},w=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const p=v(t,i,s.getName(),e);p&&o.push(p)}return o},L=(r,e)=>{const o=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s).split(h).join("/").replace(x,"");n.push(...w(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as c,Node as i}from"ts-morph";import{e as f}from"./discover-ast-CezKqEhE.mjs";import{listLunoraSourceFiles as g,lunoraRelativePath as u}from"./discoverFunctions-BdibLQmc.mjs";const m=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},p=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const n=s.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}},d=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},E=(t,e)=>{const r=[];for(const s of g(e)){const n=t.getSourceFile(s)??t.addSourceFileAtPath(s),l=u(e,s);for(const o of n.getDescendantsOfKind(c.CallExpression)){if(!m(o))continue;const a=f(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:d(o)})}}return r};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as n,SyntaxKind as P}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as E,classifyProcedureCall as g}from"./discoverFunctions-BdibLQmc.mjs";const v=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()},A=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&&v(o)&&e.push(o)}s=r.getExpression()}return e},S=t=>{const e=p(t);return{maskColumns:e.flatMap(s=>A(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():""},M=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]}},C=(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?S(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:i,tablesWritten:a}=M(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=C(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"},L=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 L(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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{relative as g,sep as u}from"node:path";import{SyntaxKind as p,Node as a}from"ts-morph";import{diagnosticAt as m}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as h}from"./discoverFunctions-BdibLQmc.mjs";const I=/\.ts$/u,x=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const e of i.getDeclarations())if(a.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/server"?!1:e.getNameNode().getText()==="defineMigration";return!1},d=(r,i)=>{const e=r.getProperty(i);if(!e||!a.isPropertyAssignment(e))return;const t=e.getInitializer();return t&&a.isStringLiteral(t)?t.getLiteralValue():void 0},E=(r,i)=>{const e=r.getInitializer();if(e?.getKind()!==p.CallExpression)return;const t=e.getExpression();if(!a.isIdentifier(t)||!x(t))return;const o=e.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=d(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw m(o,`Migration "${s}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:s,filePath:i,id:n,table:d(o,"table")??""}},S=r=>{const i=new Map;for(const e of r){const t=i.get(e.id);if(t!==void 0)throw Object.assign(new Error(`Duplicate migration id "${e.id}": declared in both "${t}" and "${e.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:e.id,name:"LunoraError",paths:[t,e.filePath],status:500});i.set(e.id,e.filePath)}},P=(r,i)=>{const e=h(i),t=[];for(const o of e){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),s=g(i,o).split(u).join("/").replace(I,"");for(const c of n.getVariableStatements())if(c.isExported())for(const f of c.getDeclarations()){const l=E(f,s);l&&t.push(l)}}return t.sort((o,n)=>o.id.localeCompare(n.id)),S(t),t};export{P as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-BdibLQmc.mjs";const d={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},f=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=t=>{if(o.isIdentifier(t))return t.getText();if(o.isPropertyAccessExpression(t)){const e=t.getExpression();if(o.isIdentifier(e)&&g.has(e.getText()))return t.getName()}},m=t=>{const e=t.getExpression();if(o.isIdentifier(e)){const i=e.getText();return i==="fetch"||i==="Date"?i:void 0}if(!o.isPropertyAccessExpression(e))return;const r=e.getName(),n=p(e.getExpression());if(n!==void 0)return r==="fetch"&&f.has(n)?"fetch":d[`${n}.${r}`]},x=t=>{const e=t.getExpression();if(!o.isIdentifier(e)||e.getText()!=="Date")return;const r=t.getArguments(),n=r.every(i=>o.isNumericLiteral(i)||o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i));return r.length>0&&n?void 0:"new Date"},h=(t,e)=>{if(e){const s=t.getArguments()[0];return s&&(o.isArrowFunction(s)||o.isFunctionExpression(s))?s:void 0}const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))return;const n=r.getProperty("handler");if(!n||!o.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},E=t=>{const e=t.getInitializer();if(!e||!o.isCallExpression(e))return;const r=l(e);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const n=h(e,r.receiver);return n?{exportName:t.getName(),handler:n,kind:r.kind}:void 0},N=(t,e)=>{const r=[];for(const n of t.handler.getDescendantsOfKind(a.CallExpression)){const i=m(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}for(const n of t.handler.getDescendantsOfKind(a.NewExpression)){const i=x(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}return r},y=(t,e)=>{const r=[];for(const n of t.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const s=E(i);s&&r.push(...N(s,e))}return r},w=(t,e)=>{const r=[];for(const n of c(e)){const i=t.getSourceFile(n)??t.addSourceFileAtPath(n);r.push(...y(i,u(e,n)))}return r};export{w as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as u,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g}from"./discoverFunctions-BdibLQmc.mjs";const p=new Set(["withIndex","withSearchIndex"]),x=r=>{const e=r.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)?t.getName()==="db":n.isIdentifier(t)&&t.getText()==="db"},d=r=>{const e=[];let t=r;for(;;){const s=t.getParent();if(!s||!n.isPropertyAccessExpression(s))break;const o=s.getParent();if(!o||!n.isCallExpression(o))break;e.push(s.getName()),t=o}return e},h=r=>{const e=r.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},S=(r,e)=>{const t=[];for(const s of f(e)){const o=r.getSourceFile(s)??r.addSourceFileAtPath(s),c=g(e,s);for(const i of o.getDescendantsOfKind(u.CallExpression)){if(!x(i))continue;const a=d(i);a.includes("filter")&&t.push({file:c,hasFilter:!0,hasIndex:a.some(l=>p.has(l)),line:i.getStartLineNumber(),table:h(i)})}}return t};export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-BdibLQmc.mjs";const p=(t,r)=>{if(r){const n=t.getArguments()[0];return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:void 0}const e=t.getArguments()[0];if(!e||!o.isObjectLiteralExpression(e))return;const s=e.getProperty("handler");if(!s||!o.isPropertyAssignment(s))return;const i=s.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},f=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=l(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const s=p(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},d=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},g=(t,r)=>{const e=[];for(const s of t.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const i=d(s);i!==void 0&&e.push({callee:i,exportName:t.exportName,file:r,kind:t.kind,line:s.getStartLineNumber()})}return e},x=(t,r)=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const i of s.getDeclarations()){const n=f(i);n&&e.push(...g(n,r))}return e},A=(t,r)=>{const e=[];for(const s of a(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s);e.push(...x(i,u(r,s)))}return e};export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as n,SyntaxKind as L}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as b,classifyProcedureCall as y}from"./discoverFunctions-BdibLQmc.mjs";const h=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="rls":n.isPropertyAccessExpression(e)?e.getName()==="rls":!1},S=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const r=[];for(const s of e.getElements()){if(!n.isObjectLiteralExpression(s))continue;const i=s.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}return r},A=t=>{const e=[];let r=t;for(;n.isCallExpression(r);){const s=r.getExpression();if(!n.isPropertyAccessExpression(s))break;if(s.getName()==="use"){const i=r.getArguments()[0];i&&h(i)&&e.push(i)}r=s.getExpression()}return e},v=t=>{const e=A(t);return{rlsTables:e.flatMap(r=>S(r)),usesRls:e.length>0}},P=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),T=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),g=(t,e)=>{const r=t.getExpression();if(!n.isPropertyAccessExpression(r)||!e.has(r.getName()))return!1;const s=r.getExpression();return n.isPropertyAccessExpression(s)?s.getName()==="db":n.isIdentifier(s)&&s.getText()==="db"},d=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},M=t=>{const e=new Set,r=new Set;for(const s of t.getDescendantsOfKind(L.CallExpression))if(g(s,P)){const i=d(s);i!==""&&e.add(i)}else if(g(s,T)){const i=d(s);i!==""&&r.add(i)}return{tablesRead:[...e],tablesWritten:[...r]}},R=(t,e)=>{if(!n.isVariableDeclaration(t))return;const r=t.getInitializer();if(!r||!n.isCallExpression(r))return;const s=y(r);if(!s)return;const i=s.receiver?v(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=M(t);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},D=(t,e)=>{const r=[];for(const s of E(e)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),o=b(e,s);for(const a of i.getVariableStatements())if(a.isExported())for(const f of a.getDeclarations()){const c=R(f,o);c&&r.push(c)}}return r},C=new Set(["delete","insert","read","update"]),l=(t,e)=>{if(!n.isObjectLiteralExpression(t))return;const r=t.getProperty(e);if(!r||!n.isPropertyAssignment(r))return;const s=r.getInitializer();return s&&n.isStringLiteral(s)?s.getLiteralText():void 0},F=(t,e,r)=>{const s=t.getArguments()[0];if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:r,table:l(o,"table")??""})}return i},m=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const r=e.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const s=[];for(const i of r.getElements()){if(n.isStringLiteral(i)){s.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}}return s},x=(t,e)=>e===void 0?t:{...t,description:e},I=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const r=t.getArguments()[1],s=r?l(r,"description"):void 0,i=r?m(r):[];return x({name:e.getLiteralText(),permissions:i},s)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:x({name:e,permissions:m(t)},l(t,"description"))}},N=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const r=e.getProperty("roles");if(!r||!n.isPropertyAssignment(r))return[];const s=r.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){const a=I(o);a&&i.push(a)}return i},O=(t,e,r)=>{const s=A(t);return{policies:s.flatMap(i=>F(i,e,r)),roles:s.flatMap(i=>N(i))}},w=t=>{const e=[];for(const r of t.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations()){const i=s.getInitializer(),o=i&&n.isCallExpression(i)?y(i):void 0;o?.receiver&&e.push({name:s.getName(),receiver:o.receiver})}return e},V=(t,e)=>{const r=[],s=new Map;for(const i of E(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=b(e,i);for(const{name:f,receiver:c}of w(o)){const p=O(c,a,f);r.push(...p.policies);for(const u of p.roles)s.has(u.name)||s.set(u.name,u)}}return{policies:r,roles:[...s.values()]}};export{D as default,V as discoverRlsMetadata};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{listLunoraSourceFiles as u}from"./discoverFunctions-BdibLQmc.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),d=o=>{const s={usesSandboxBrowser:!1,usesSandboxContainer:!1};if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=e.getNameNode().getText();n==="browserTool"?s.usesSandboxBrowser=!0:n==="containerTool"&&(s.usesSandboxContainer=!0)}return s},c=(o,s)=>{const e={usesSandboxBrowser:!1,usesSandboxContainer:!1};for(const n of u(s)){const a=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of a.getImportDeclarations()){const r=d(t);e.usesSandboxBrowser||=r.usesSandboxBrowser,e.usesSandboxContainer||=r.usesSandboxContainer}if(e.usesSandboxBrowser&&e.usesSandboxContainer)break}return e};export{c as discoverSandboxUsage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as j}from"@lunora/errors";import{Node as s,SyntaxKind as w}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{d as N}from"./parse-validator-CSDlMEvE.mjs";import{createRequire as T}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 t=e?._meta??{},r=e?.kind??"unknown",n={column:$(t.column),kind:r};switch(r){case"array":case"optional":{n.inner=f(t.inner);break}case"id":{n.tableName=t.tableName;break}case"literal":{n.literalValue=_(t.value);break}case"object":{const i=t.shape??{};n.shape=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,f(a)]));break}case"record":{n.valueType=f(t.valueValidator),t.keyValidator!==void 0&&(n.keyType=f(t.keyValidator));break}case"storage":{typeof t.bucket=="string"&&(n.bucket=t.bucket);break}case"union":{const i=t.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,t)=>{const r=[];e.relationMap&&Object.keys(e.relationMap).length>0&&r.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&r.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&r.push("vector indexes"),r.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${t}" declares ${r.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},D=(e,t)=>{const r=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return z(e,t),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:n,name:t,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(i=>({field:i.field,...i.filterFields?{filterFields:i.filterFields}:{},name:i.name})),shape:Object.fromEntries(Object.entries(r).map(([i,o])=>[i,f(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},B=e=>{const{key:t,tables:r}=e;if(typeof t!="string"||typeof r!="object"||r===null)return;const n=Object.entries(r).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:t}},q=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();return s.isIdentifier(t)?t.getText():void 0}},F=e=>{const t=q(e);if(t===void 0)return;const r=s.isPropertyAccessExpression(e)?e.getName():void 0,n=r===void 0?[]:[r];for(const i of e.getSourceFile().getImportDeclarations()){const o=i.getModuleSpecifierValue();for(const a of i.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===t)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:n};if(i.getDefaultImport()?.getText()===t)return{importedName:"default",moduleSpecifier:o,propertyPath:n};if(i.getNamespaceImport()?.getText()===t&&r!==void 0)return{importedName:r,moduleSpecifier:o,propertyPath:[]}}},C=(e,t)=>{let r=e[t.importedName];for(const n of t.propertyPath){if(typeof r!="object"||r===null)return;r=r[n]}return r},V=(e,t)=>{const r=F(e);if(r)try{const n=T(O(t,"noop.cjs")),i=n.resolve(r.moduleSpecifier),o=n(i),a=C(o,r);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"]),E=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),K=(e,t)=>{if(E.has(e))throw g(t,`table name "${e}" is reserved — it collides with a \`ctx.db\` member (one of ${[...E].map(r=>`"${r}"`).join(", ")}). Rename the table.`)},c=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},m=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isNumericLiteral(n))return Number(n.getLiteralText())}},h=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isArrayLiteralExpression(n))return n.getElements().filter(i=>s.isStringLiteral(i)).map(i=>i.getLiteralText())}},v=e=>e&&R.has(e)?e:void 0,U=e=>e&&J.has(e)?e:void 0,G=e=>{if(!s.isArrowFunction(e))return;let t=e.getBody();if(s.isParenthesizedExpression(t))t=t.getExpression();else if(s.isBlock(t)){const r=t.getStatements().find(n=>s.isReturnStatement(n));t=r&&s.isReturnStatement(r)?r.getExpression()??t:t}return s.isObjectLiteralExpression(t)?t:void 0},H=e=>{if(!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;const n=r.getName();if(n!=="one"&&n!=="many")return;const[i,o]=t.getArguments(),a=i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_";let l="_unknown_",d="_id",u;return o&&s.isObjectLiteralExpression(o)&&(l=c(o,"field")??l,d=c(o,"references")??d,u=n==="one"?U(c(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:u,references:d,table:a}},Q=e=>{const t=G(e);if(!t)return[];const r=[];for(const n of t.getProperties()){const i=H(n);i&&r.push(i)}return r},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",W=e=>{const[t,r,n]=e;let i=!1;if(n&&s.isObjectLiteralExpression(n)){const o=n.getProperty("unique");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();if(a&&!s.isTrueLiteral(a)&&!s.isFalseLiteral(a))throw g(a,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(a.getText())}`);i=a?s.isTrueLiteral(a):!1}}return{fields:r&&s.isArrayLiteralExpression(r)?r.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText()):[],name:x(t),unique:i}},X=e=>{const[t,r]=e;let n="_unknown_",i;return r&&s.isObjectLiteralExpression(r)&&(n=c(r,"field")??n,i=h(r,"filterFields")),{field:n,filterFields:i,name:x(t)}},Y=e=>{const[t,r]=e;let n="_unknown_",i;return r&&s.isObjectLiteralExpression(r)&&(n=c(r,"field")??n,i=m(r,"precision")),{field:n,name:x(t),precision:i}},Z=e=>{const[t,r]=e,n=t&&s.isStringLiteral(t)?t.getLiteralText():"_unknown_";let i;return r&&s.isObjectLiteralExpression(r)&&(i=m(r,"after")),{after:i,field:n}},ee=e=>{if(!s.isObjectLiteralExpression(e))return;const t=c(e,"field");return t===void 0?void 0:{direction:c(e,"direction")==="desc"?"desc":"asc",field:t}},te=e=>{const[t,r]=e;let n=[],i;if(r&&s.isObjectLiteralExpression(r)){const o=r.getProperty("sortBy");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();a&&s.isArrayLiteralExpression(a)&&(n=a.getElements().map(l=>ee(l)).filter(l=>l!==void 0))}i=h(r,"partitionBy")}return{name:x(t),partitionBy:i,sortBy:n}},re=(e,t)=>{const[r,n]=e,i=r&&s.isStringLiteral(r)?r.getLiteralText():"_unknown_";if(!(!n||!s.isObjectLiteralExpression(n)))return{dimensions:m(n,"dimensions"),field:i,metadata:h(n,"metadata"),metric:v(c(n,"metric")),name:c(n,"index")??"_unnamed_",table:t}},ne=e=>{const t=e[0];return t&&s.isObjectLiteralExpression(t)&&c(t,"backend")==="hyperdrive"?"hyperdrive":"d1"},ie=e=>{if(e&&s.isObjectLiteralExpression(e)){const t=e.getProperty("field");if(t&&s.isPropertyAssignment(t)){const r=t.getInitializer();if(r&&s.isStringLiteral(r))return r.getLiteralText()}}return"deletedAt"},p=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},se=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.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}}},oe=e=>{const t=e[0];return!t||!s.isObjectLiteralExpression(t)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(t,"binding")??"",columns:se(t,"columns"),hasReconcile:t.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:t.getProperty("softDeleteColumn")!==void 0,hasTenantBy:t.getProperty("tenantBy")!==void 0,idColumn:p(t,"idColumn"),mode:p(t,"mode"),query:p(t,"query")}},ae=(e,t,r,n)=>{switch(t){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(Y(r));break}case"global":{e.shardMode="global",e.globalBackend=ne(r);break}case"index":{e.indexes.push(W(r));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(te(r));break}case"relations":{const i=r[0];i&&e.relations.push(...Q(i));break}case"searchIndex":{e.searchIndexes.push(X(r));break}case"shardBy":{const i=r[0];e.shardMode={field:i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:ie(r[0])};break}case"source":{e.externalSource=oe(r),e.externallyManaged=!0;break}case"ttl":{e.ttl=Z(r);break}case"vectorize":{const i=re(r,n);i&&e.vectorIndexes.push(i);break}}},L=(e,t)=>{const r={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))ae(r,o.getName(),a,t),i=o.getExpression();else if(s.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];l&&s.isObjectLiteralExpression(l)&&(n=N(l));break}else break}return r.softDelete&&!(r.softDelete.field in n)&&(n={...n,[r.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),{externallyManaged:r.externallyManaged,externalSource:r.externalSource,geoIndexes:r.geoIndexes,globalBackend:r.shardMode==="global"?r.globalBackend??"d1":void 0,indexes:r.indexes,isPublic:r.isPublic,name:t,rankIndexes:r.rankIndexes,relations:r.relations,searchIndexes:r.searchIndexes,shape:n,shardMode:r.shardMode,softDelete:r.softDelete,ttl:r.ttl,vectorIndexes:r.vectorIndexes}},le=e=>{const t=e.getProperty("source");if(t&&s.isPropertyAssignment(t)){const r=t.getInitializer();if(r&&s.isObjectLiteralExpression(r))return c(r,"table")??"_unknown_"}return"_unknown_"},ce=e=>{if(!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const r=t.getExpression();if(!s.isIdentifier(r)||r.getText()!=="defineVectorIndex")return;const n=t.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:v(c(n,"metric")),name:o,table:le(n)}},P=e=>{const t=[];for(const r of e.getProperties()){const n=ce(r);n&&t.push(n)}return t},k=(e,t)=>`${e}_${t}`,y=(e,t,r)=>r.has(e)?k(t,e):e,de=(e,t,r)=>{const n=k(t,e.name);return{...e,extensionKey:t,name:n,relations:e.relations.map(i=>({...i,table:y(i.table,t,r)})),vectorIndexes:e.vectorIndexes.map(i=>({...i,table:y(i.table,t,r)}))}},ue=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},fe=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r))return r.getInitializer()},ge=e=>{if(!s.isCallExpression(e))return!1;const t=e.getExpression();return s.isIdentifier(t)&&t.getText()==="defineSchemaExtension"},pe=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const t=e.getExpression();return s.isIdentifier(t)?t:void 0}},me=e=>{if(s.isObjectLiteralExpression(e))return e;if(s.isCallExpression(e)){const t=e.getExpression();let r;if(s.isIdentifier(t)?r=t.getText():s.isPropertyAccessExpression(t)&&(r=t.getName()),r==="definePlugin"){const n=e.getArguments()[1];return n&&s.isObjectLiteralExpression(n)?n:void 0}}},xe=(e,t)=>{const r=ue(e);if(r){if(s.isPropertyAccessExpression(t)){const n=me(r);return n?fe(n,t.getName()):void 0}return r}},be=e=>{let t=e,r=0;for(;t&&r<32;){if(r+=1,ge(t))return t;const n=pe(t),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;t=xe(o,t)}},ye=e=>{const[t,r]=e.getArguments();if(!(!t||!s.isStringLiteral(t))&&!(!r||!s.isObjectLiteralExpression(r)))return{key:t.getLiteralText(),options:r}},he=e=>{const t=e.getProperty("tables");if(!t||!s.isPropertyAssignment(t))return[];const r=t.getInitializer();if(!r||!s.isObjectLiteralExpression(r))return[];const n=[];for(const i of r.getProperties()){if(!s.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.push(L(o,i.getName()))}return n},ke=e=>{const t=e.getProperty("vectorIndexes");if(!t||!s.isPropertyAssignment(t))return[];const r=t.getInitializer();return!r||!s.isObjectLiteralExpression(r)?[]:P(r)},S=(e,t,r)=>{const n=new Set(t.map(a=>a.name)),i=t.map(a=>de(a,e,n)),o=r.map(a=>({...a,name:k(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Ie=(e,t)=>S(e,he(t),ke(t)),Ee=(e,t)=>{const r=e.getArguments()[0];if(!r)return;const n=be(r);if(!n){if(t!==void 0){const o=V(r,t);if(o)return S(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${r.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${t===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=ye(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Ie(i.key,i.options)},ve=e=>{const t=[];let r=e;for(;;){const n=r.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;n.getName()==="extend"&&t.push(i),r=i}return t},A=(e,t,r,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()===t){const d=l.getArguments()[0];if(!d||!s.isStringLiteral(d))throw g(l,`\`.${t}(...)\` expects a string literal (${i})`);const u=d.getLiteralText();if(!n.has(u))throw g(d,`unknown ${r} ${JSON.stringify(u)} — expected ${i}`);return u}o=l}},Le=new Set(["eu","fedramp","us"]),Pe=e=>A(e,"jurisdiction","jurisdiction",Le,'"eu", "us", or "fedramp"'),Se=new Set(["required"]),Ae=e=>A(e,"rls","rls mode",Se,'"required"'),je=e=>{const t=[];for(const r of e.getProperties()){if(!s.isPropertyAssignment(r))continue;const n=r.getInitializer();if(n){const i=r.getName();K(i,r.getNameNode()),t.push(L(n,i))}}return t},we=(e,t,r)=>{const n=new Set(t.map(o=>o.name)),i=[];for(const o of ve(e)){const a=Ee(o,r);if(a){for(const l of a.tables){if(n.has(l.name))throw g(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);n.add(l.name),t.push(l)}i.push(...a.vectorIndexes)}}return i},ze=(e,t,r)=>{const n=e.addSourceFileAtPath(t).getDescendantsOfKind(w.CallExpression).find(b=>{const I=b.getExpression();return s.isIdentifier(I)&&I.getText()==="defineSchema"});if(!n)throw new j("INTERNAL",`defineSchema() not found in ${t}`);const i=n.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw g(n,"defineSchema() expects an object literal");const o=je(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?P(a):[],d=we(n,o,r),u=[...o.flatMap(b=>b.vectorIndexes),...l,...d];return{jurisdiction:Pe(n),rlsMode:Ae(n),tables:o,vectorIndexes:u}};export{ze 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-BdibLQmc.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},P=(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{P as default};
|