cvx-kit 0.1.27 → 0.1.28
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 +2 -2
- package/dist/index.mjs +1 -1
- package/dist/oxlint/architecture.d.mts +3 -1
- package/dist/oxlint/architecture.mjs +1 -1
- package/dist/oxlint/architecture.mjs.map +1 -1
- package/dist/oxlint/ast.d.mts +2 -0
- package/dist/oxlint/ast.mjs +1 -1
- package/dist/oxlint/ast.mjs.map +1 -1
- package/dist/oxlint/components.d.mts +6 -0
- package/dist/oxlint/components.mjs +2 -0
- package/dist/oxlint/components.mjs.map +1 -0
- package/dist/oxlint/ownership.mjs +1 -1
- package/dist/oxlint/ownership.mjs.map +1 -1
- package/dist/oxlint.mjs +1 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/triggers.d.mts +5 -1
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,7 @@ import { CrudConfig, createCrudCommands } from "./crud.mjs";
|
|
|
11
11
|
import { RateLimiterLike, rateLimit } from "./middleware.mjs";
|
|
12
12
|
import { WebhookBoundaryConfig, createWebhookBoundary, recordWebhookEvent, webhookEventsTable } from "./webhooks.mjs";
|
|
13
13
|
import { createStateMachine } from "./state-machine.mjs";
|
|
14
|
-
import { Change, Trigger, Triggers, appendOnly, createTriggers, noDelete, tenantOwnership, timestamps } from "./triggers.mjs";
|
|
14
|
+
import { Change, Trigger, Triggers, appendOnly, createTriggers, noDelete, tenantOwnership, timestamps, triggerContext } from "./triggers.mjs";
|
|
15
15
|
import { FoundationRegistry, FoundationRegistryOptions, createFoundation } from "./modules/foundation/foundation.mjs";
|
|
16
16
|
import { QueryEngineConfig, createQueryEngine } from "./querying.mjs";
|
|
17
|
-
export { type Actor, type AgentToolHandlers, type AgentToolRecord, type AnyCommandMiddleware, type AnyQueryMiddleware, type ApplicationCommand, type AuditEntryInput, type AuditWriter, type AuditedOperation, type AuditedRegistry, type AuthBundle, type AuthFunctions, type AuthFunctionsConfig, type Change, type CommandConstructor, type CommandDefaults, type CommandMiddleware, type CrudConfig, type DefaultRole, type DtoOptions, type ErrorFactory, type FieldReference, Foundation, type FoundationOptions, type FoundationRegistry, type FoundationRegistryOptions, type Include, type IncludedQuery, KitError, type PermissionChecker, type QueryEngineConfig, type QueryMiddleware, type RLSConfig, type RateLimiterLike, type RelationBuilder, type RelationDeclarations, type RelationEdge, type RelationFilterSelection, type RelationFilters, type RelationRegistry, type RelationRegistryIdentity, type RelationRow, type RelationSelection, type RelationTable, type RelationTableHelpers, type RelationTables, type Rules, type ScalarFilters, type ScalarSelection, type SecurityConfig, type ServerFilter, TENANT_FIELD, TIMESTAMP_FIELDS, type TableBoundaryOptions, type ThroughReference, type Trigger, Triggers, type WebhookBoundaryConfig, appendOnly, assertTenantOwned, composeRules, createAgentTools, createAuthFunctions, createCrudCommands, createFoundation, createInclude, createModule, createQueryEngine, createStateMachine, createTable, createTenantRules, createTriggers, createWebhookBoundary, defaultErrors, defaultRoleMap, defineRelations, jsonSafeZid, noDelete, paginated, rateLimit, recordWebhookEvent, requireTenantReference, tenantOwnership, tenantTable, timestamps, webhookEventsTable, zodTable, zodVariantTable };
|
|
17
|
+
export { type Actor, type AgentToolHandlers, type AgentToolRecord, type AnyCommandMiddleware, type AnyQueryMiddleware, type ApplicationCommand, type AuditEntryInput, type AuditWriter, type AuditedOperation, type AuditedRegistry, type AuthBundle, type AuthFunctions, type AuthFunctionsConfig, type Change, type CommandConstructor, type CommandDefaults, type CommandMiddleware, type CrudConfig, type DefaultRole, type DtoOptions, type ErrorFactory, type FieldReference, Foundation, type FoundationOptions, type FoundationRegistry, type FoundationRegistryOptions, type Include, type IncludedQuery, KitError, type PermissionChecker, type QueryEngineConfig, type QueryMiddleware, type RLSConfig, type RateLimiterLike, type RelationBuilder, type RelationDeclarations, type RelationEdge, type RelationFilterSelection, type RelationFilters, type RelationRegistry, type RelationRegistryIdentity, type RelationRow, type RelationSelection, type RelationTable, type RelationTableHelpers, type RelationTables, type Rules, type ScalarFilters, type ScalarSelection, type SecurityConfig, type ServerFilter, TENANT_FIELD, TIMESTAMP_FIELDS, type TableBoundaryOptions, type ThroughReference, type Trigger, Triggers, type WebhookBoundaryConfig, appendOnly, assertTenantOwned, composeRules, createAgentTools, createAuthFunctions, createCrudCommands, createFoundation, createInclude, createModule, createQueryEngine, createStateMachine, createTable, createTenantRules, createTriggers, createWebhookBoundary, defaultErrors, defaultRoleMap, defineRelations, jsonSafeZid, noDelete, paginated, rateLimit, recordWebhookEvent, requireTenantReference, tenantOwnership, tenantTable, timestamps, triggerContext, webhookEventsTable, zodTable, zodVariantTable };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createAgentTools as e}from"./agent-tools.mjs";import{KitError as t,defaultErrors as n}from"./errors.mjs";import{TENANT_FIELD as r,assertTenantOwned as i,composeRules as a,createTenantRules as o,requireTenantReference as s}from"./tenancy.mjs";import{createAuthFunctions as c,createInclude as l,defaultRoleMap as u}from"./auth.mjs";import{createCrudCommands as d}from"./crud.mjs";import{TIMESTAMP_FIELDS as f,createModule as p,createTable as m,jsonSafeZid as h,paginated as g,tenantTable as _,zodTable as v,zodVariantTable as y}from"./zod-table.mjs";import{rateLimit as b}from"./middleware.mjs";import{createWebhookBoundary as x,recordWebhookEvent as S,webhookEventsTable as C}from"./webhooks.mjs";import{createStateMachine as w}from"./state-machine.mjs";import{Triggers as T,appendOnly as E,createTriggers as D,noDelete as O,tenantOwnership as k,timestamps as A}from"./triggers.mjs";import{Foundation as
|
|
1
|
+
import{createAgentTools as e}from"./agent-tools.mjs";import{KitError as t,defaultErrors as n}from"./errors.mjs";import{TENANT_FIELD as r,assertTenantOwned as i,composeRules as a,createTenantRules as o,requireTenantReference as s}from"./tenancy.mjs";import{createAuthFunctions as c,createInclude as l,defaultRoleMap as u}from"./auth.mjs";import{createCrudCommands as d}from"./crud.mjs";import{TIMESTAMP_FIELDS as f,createModule as p,createTable as m,jsonSafeZid as h,paginated as g,tenantTable as _,zodTable as v,zodVariantTable as y}from"./zod-table.mjs";import{rateLimit as b}from"./middleware.mjs";import{createWebhookBoundary as x,recordWebhookEvent as S,webhookEventsTable as C}from"./webhooks.mjs";import{createStateMachine as w}from"./state-machine.mjs";import{Triggers as T,appendOnly as E,createTriggers as D,noDelete as O,tenantOwnership as k,timestamps as A,triggerContext as j}from"./triggers.mjs";import{Foundation as M}from"./components/foundation/client.mjs";import{createFoundation as N}from"./modules/foundation/foundation.mjs";import{defineRelations as P}from"./relations.mjs";import{createQueryEngine as F}from"./querying.mjs";export{M as Foundation,t as KitError,r as TENANT_FIELD,f as TIMESTAMP_FIELDS,T as Triggers,E as appendOnly,i as assertTenantOwned,a as composeRules,e as createAgentTools,c as createAuthFunctions,d as createCrudCommands,N as createFoundation,l as createInclude,p as createModule,F as createQueryEngine,w as createStateMachine,m as createTable,o as createTenantRules,D as createTriggers,x as createWebhookBoundary,n as defaultErrors,u as defaultRoleMap,P as defineRelations,h as jsonSafeZid,O as noDelete,g as paginated,b as rateLimit,S as recordWebhookEvent,s as requireTenantReference,k as tenantOwnership,_ as tenantTable,A as timestamps,j as triggerContext,C as webhookEventsTable,v as zodTable,y as zodVariantTable};
|
|
@@ -3,6 +3,8 @@ import { ResolverFactory } from "oxc-resolver";
|
|
|
3
3
|
export interface ArchitectureOptions {
|
|
4
4
|
cwd?: string;
|
|
5
5
|
convexDir?: string;
|
|
6
|
+
/** Additional component roots, relative to convexDir. */
|
|
7
|
+
componentDirs?: readonly string[];
|
|
6
8
|
/** Build these registries to surface deferred configuration errors in tests. */
|
|
7
9
|
registries?: readonly object[];
|
|
8
10
|
}
|
|
@@ -13,7 +15,7 @@ export interface ArchitectureDiagnostic {
|
|
|
13
15
|
}
|
|
14
16
|
/** Full-project checks, independent of the consumer's test runner. No persistent cache. */
|
|
15
17
|
export declare function inspectArchitecture(options?: ArchitectureOptions): ArchitectureDiagnostic[];
|
|
16
|
-
export declare function createResolver(): ResolverFactory;
|
|
18
|
+
export declare function createResolver(symlinks?: boolean): ResolverFactory;
|
|
17
19
|
export declare function resolveImport(resolver: ResolverFactory, filename: string, source: string): string | null;
|
|
18
20
|
/** The lint rule runs the project scan on one deterministic source file. */
|
|
19
21
|
export declare function architectureAnchor(root: string): string | null;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{dirname as e,relative as t,resolve as n,sep as r}from"node:path";import{existsSync as i,readFileSync as a,readdirSync as o,realpathSync as s}from"node:fs";import{Visitor as c,parseSync as l}from"oxc-parser";import{ResolverFactory as u}from"oxc-resolver";function d(o={}){let c=n(o.cwd??process.cwd(),o.convexDir??`convex`),u=i(c)?s(c):c,d=[];if(!i(u))return[{code:`missing-root`,file:`.`,message:`Convex directory does not exist: ${u}`}];let m=g(u,d),b=/* @__PURE__ */ new Set,T=/* @__PURE__ */ new Set,E=/* @__PURE__ */ new Map,D=/* @__PURE__ */ new Map,O=f();for(let i of m){let o=n(u,i),s=l(o,a(o,`utf8`));if(s.errors.length){d.push({code:`parse`,file:i,message:`Cannot validate ${i}: ${s.errors[0].message}`});continue}if(_(i)){i.includes(`__tests__/`)?e(i).endsWith(`__tests__`)&&y(s.program)&&T.add(e(e(i))):d.push({code:`test-location`,file:i,message:`Place tests in a sibling __tests__/ directory.`});continue}if(i.split(`/`).includes(`__tests__`))continue;/^domain\/[^/]+$/.test(i)&&i!==`domain/table.ts`&&d.push({code:`domain-entry`,file:i,message:`Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.`}),v(s.program)&&i!==`domain/table.ts`&&!h(i,a(o,`utf8`))&&b.add(e(i));let c=S(i)??``,f=/* @__PURE__ */ new Set;D.set(i,f);for(let e of x(s.program)){let n=p(O,o,e);if(!n)continue;let i=t(u,n).split(r).join(`/`);f.add(i);let a=S(i);if(c&&a&&c!==a){let e=E.get(c)??/* @__PURE__ */ new Set;E.set(c,e),e.add(a)}}}for(let e of b)T.has(e)||d.push({code:`tests`,file:e,message:`${e}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`});d.push(...w(D));for(let e of C(E))d.push({code:`cycle`,file:e[0],message:`Module dependency cycle: ${e.join(` → `)}.`});return d.sort((e,t)=>e.file.localeCompare(t.file)||e.code.localeCompare(t.code))}function f(){return new u({tsconfig:`auto`,extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],extensionAlias:{".js":[`.ts`,`.tsx`,`.js`],".mjs":[`.mts`,`.mjs`],".cjs":[`.cts`,`.cjs`]},conditionNames:[`types`,`import`,`node`,`default`],symlinks:!0})}function p(t,r,i){return t.resolveFileSync(r,i).path||(i.startsWith(`.`)?n(e(r),i):null)}function m(e){if(!i(e))return null;if(i(n(e,`convex.config.ts`)))return s(n(e,`convex.config.ts`));e=s(e);for(let t of g(e,[]))if(!t.includes(`__tests__/`)&&!_(t))return n(e,t);return null}function h(e,t){let n=e===`relations.ts`?`defineRelations`:e===`querying.ts`?`createQueryEngine`:null;if(!n)return!1;let r=l(e,t);if(r.errors.length)return!1;let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=0,s=!1;function c(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name))return null;let n=a.get(e.name);return n?c(n,new Set(t).add(e.name)):i.get(e.name)??null}return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&c(e.object,t)===`*`?e.property.name:null}function u(e,t,n=!1){if(e.type===`Identifier`||e.type===`Literal`)return!0;if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return u(e.expression,t,n);if(e.type===`MemberExpression`)return!e.computed&&u(e.object,t);if(e.type===`ArrayExpression`)return e.elements.every(e=>e!==null&&u(e,t));if(e.type===`ObjectExpression`)return e.properties.every(e=>e.type===`Property`&&!e.computed&&e.kind===`init`&&!e.method&&u(e.value,t));if(e.type===`ArrowFunctionExpression`&&n&&!t&&e.params.length===1&&e.params[0].type===`Identifier`&&!e.async){let t=e.body.type===`ParenthesizedExpression`?e.body.expression:e.body;return t.type===`ObjectExpression`&&u(t,e.params[0].name)}if(e.type===`CallExpression`&&t){let n=e.callee,r=[];for(;n.type===`MemberExpression`&&!n.computed&&n.property.type===`Identifier`;)r.unshift(n.property.name),n=n.object;return n.type===`Identifier`&&n.name===t&&(r.length===2&&[`one`,`many`].includes(r[0])||r.length===3&&r[2]===`through`)&&e.arguments.every(e=>u(e,t))}return!1}for(let t of r.program.body){if(t.type===`ImportDeclaration`){if(t.importKind===`type`)continue;for(let n of t.specifiers)(n.type!==`ImportSpecifier`||n.importKind!==`type`)&&[`cvx-kit`,`cvx-kit/${e.slice(0,-3)}`].includes(t.source.value)&&i.set(n.local.name,n.type===`ImportSpecifier`?n.imported.type===`Identifier`?n.imported.name:``:n.type===`ImportNamespaceSpecifier`?`*`:``);continue}if(t.type===`EmptyStatement`||t.type===`TSTypeAliasDeclaration`||t.type===`TSInterfaceDeclaration`)continue;let r=t.type===`ExportNamedDeclaration`?t.declaration:t;if(r?.type!==`VariableDeclaration`||r.kind!==`const`)return!1;for(let e of r.declarations){if(e.id.type!==`Identifier`||!e.init)return!1;if(e.init.type===`CallExpression`&&c(e.init.callee)===n){if(!e.init.arguments.every((e,t)=>u(e,void 0,n===`defineRelations`&&t===1)))return!1;o++,s||=t.type===`ExportNamedDeclaration`}else if(t.type===`ExportNamedDeclaration`||!u(e.init))return!1;a.set(e.id.name,e.init)}}return o===1&&s}function*g(e,i){let a=/* @__PURE__ */ new Set([`_generated`,`__tests__`,`api`,`domain`,`application`,`migrations`,`components`]);function*s(c){for(let l of o(c,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let o=n(c,l.name),u=t(e,o).split(r).join(`/`);if(l.isSymbolicLink()){i.push({code:`symlink`,file:u,message:`Keep application source inside its owning directory; symlinked files and folders are not allowed.`});continue}l.isDirectory()?(c===e&&!a.has(l.name)&&i.push({code:`root-directory`,file:u,message:`Root folder ${l.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`}),l.name!==`_generated`&&l.name!==`node_modules`&&!l.name.startsWith(`.`)&&(yield*s(o))):/\.[cm]?[jt]sx?$/.test(l.name)&&!/\.d\.[cm]?ts$/.test(l.name)&&(yield u)}}yield*s(e)}function _(e){return/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(e)}function v(e){return e.body.some(e=>{let t=e.type===`ExportNamedDeclaration`?e.declaration:e;return t&&`declare`in t&&t.declare||e.type===`ImportDeclaration`||e.type===`EmptyStatement`?!1:e.type===`ExportNamedDeclaration`?e.exportKind===`type`||!e.declaration?!1:![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`].includes(e.declaration.type):![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`,`ExportAllDeclaration`].includes(e.type)})}function y(e){let t=/* @__PURE__ */ new Map([[`test`,`test`],[`it`,`it`],[`describe`,`describe`],[`suite`,`suite`]]);for(let n of e.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`FunctionDeclaration`&&e.id&&t.delete(e.id.name),e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.delete(n.id.name);if(n.type===`ImportDeclaration`)for(let e of n.specifiers)t.delete(e.local.name),[`vitest`,`vite-plus/test`,`bun:test`,`node:test`,`@jest/globals`].includes(n.source.value)&&(e.type===`ImportNamespaceSpecifier`?t.set(e.local.name,`*`):e.type===`ImportDefaultSpecifier`?t.set(e.local.name,`test`):e.imported.type===`Identifier`&&t.set(e.local.name,e.imported.name))}let n=[];new c({CallExpression(e){n.push(e)}}).visit(e);let r=n.filter(e=>{let n=b(e.callee,t);return[`test`,`it`,`describe`,`suite`].includes(n[0])&&(n.some(e=>[`skip`,`todo`,`skipIf`,`runIf`].includes(e))||e.arguments.some(e=>e.type===`ObjectExpression`&&e.properties.some(e=>e.type===`Property`&&[`skip`,`todo`].includes(e.key.type===`Identifier`?e.key.name:e.key.type===`Literal`?String(e.key.value):``)&&(e.value.type!==`Literal`||e.value.value!==!1))))});return n.some(e=>{let n=b(e.callee,t);return![`test`,`it`].includes(n[0])||r.some(t=>e.start>=t.start&&e.end<=t.end)?!1:e.arguments.some(e=>(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`)&&e.body&&(e.body.type!==`BlockStatement`||e.body.body.some(e=>e.type!==`EmptyStatement`)))})}function b(e,t){if(e.type===`Identifier`){let n=t.get(e.name);return n?[n]:[]}if(e.type===`CallExpression`)return b(e.callee,t);if(e.type===`MemberExpression`){let n=b(e.object,t),r=!e.computed&&e.property.type===`Identifier`?e.property.name:e.property.type===`Literal`?String(e.property.value):``;return!n.length||!r?[]:n[0]===`*`?[r]:[...n,r]}return[]}function x(e){let t=[];return new c({ImportDeclaration(e){e.importKind!==`type`&&(e.specifiers.length===0||e.specifiers.some(e=>e.type!==`ImportSpecifier`||e.importKind!==`type`))&&t.push(e.source.value)},ExportNamedDeclaration(e){e.source&&e.exportKind!==`type`&&e.specifiers.some(e=>e.exportKind!==`type`)&&t.push(e.source.value)},ExportAllDeclaration(e){e.exportKind!==`type`&&t.push(e.source.value)},ImportExpression(e){e.source.type===`Literal`&&String(e.source.value)===e.source.value&&t.push(String(e.source.value))}}).visit(e),t}function S(e){let t=e.split(`/`);return t[0]===`domain`&&t.length>=3&&t[1]!==`__tests__`?`domain/${t[1]}`:null}function C(e){let t=/* @__PURE__ */ new Set,n=[],r=[];function i(a){let o=n.indexOf(a);if(o>=0){r.push([...n.slice(o),a]);return}if(!t.has(a)){n.push(a);for(let t of e.get(a)??[])i(t);n.pop(),t.add(a)}}for(let t of e.keys())i(t);return r}function w(e){let t=/* @__PURE__ */ new Map;for(let[n,r]of e){let i=S(n)??``;if(!i||i===`domain/shared`)continue;let a=/* @__PURE__ */ new Set;function o(n){if(!n.startsWith(`domain/shared/`)||a.has(n))return;a.add(n);let r=t.get(n)??/* @__PURE__ */ new Set;r.add(i),t.set(n,r);for(let t of e.get(n)??[])o(t)}for(let e of r)o(e)}let n=[];for(let[e,r]of t)r.size===1&&n.push({code:`shared-owner`,file:e,message:`This shared implementation is used only by ${[...r][0]}. Move it into that module until another module needs it.`});return n}export{m as architectureAnchor,f as createResolver,d as inspectArchitecture,h as narrowRootDeclaration,p as resolveImport};
|
|
1
|
+
import{conventionalComponentRoot as e,findComponentRoot as t}from"./components.mjs";import{dirname as n,relative as r,resolve as i,sep as a}from"node:path";import{existsSync as o,readFileSync as s,readdirSync as c,realpathSync as l}from"node:fs";import{Visitor as u,parseSync as d}from"oxc-parser";import{ResolverFactory as f}from"oxc-resolver";function p(c={}){let u=i(c.cwd??process.cwd(),c.convexDir??`convex`),f=o(u)?l(u):u,p=[];if(!o(f))return[{code:`missing-root`,file:`.`,message:`Convex directory does not exist: ${f}`}];let g=(c.componentDirs??[]).map(e=>i(f,e)),S=[...v(f,p)],D=/* @__PURE__ */ new Map;for(let n of S){let o=t(i(f,n),g)??e(i(f,n),f);o&&(o===f||o.startsWith(f+a))&&D.set(n,r(f,o).split(a).join(`/`))}let O=new Set(D.values());for(let e=p.length-1;e>=0;e--){let t=p[e];t.code===`root-directory`&&[...O].some(e=>!e||e===t.file||e.startsWith(t.file+`/`))&&!S.some(e=>e.startsWith(t.file+`/`)&&!D.has(e))&&p.splice(e,1)}let k=/* @__PURE__ */ new Set,A=/* @__PURE__ */ new Set,j=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Map,N=/* @__PURE__ */ new Map,P=m();for(let e of S){let t=i(f,e),o=d(t,s(t,`utf8`));if(o.errors.length){p.push({code:`parse`,file:e,message:`Cannot validate ${e}: ${o.errors[0].message}`});continue}if(y(e)){e.includes(`__tests__/`)?n(e).endsWith(`__tests__`)&&x(o.program)&&A.add(n(n(e))):p.push({code:`test-location`,file:e,message:`Place tests in a sibling __tests__/ directory.`});continue}if(e.split(`/`).includes(`__tests__`))continue;let c=D.get(e),l=c===void 0?e:r(i(f,c),t).split(a).join(`/`);c===void 0&&/^domain\/[^/]+$/.test(e)&&e!==`domain/table.ts`&&p.push({code:`domain-entry`,file:e,message:`Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.`}),b(o.program)&&e!==`domain/table.ts`&&!_(l,s(t,`utf8`))&&k.add(n(e));let u=w(e)??``,m=/* @__PURE__ */ new Set;N.set(e,m);for(let n of C(o.program)){let i=h(P,t,n);if(!i)continue;let o=r(f,i).split(a).join(`/`);if(m.add(o),c!==void 0&&D.get(o)===c){let t=M.get(e)??/* @__PURE__ */ new Set;M.set(e,t),t.add(o)}let s=w(o);if(u&&s&&u!==s){let e=j.get(u)??/* @__PURE__ */ new Set;j.set(u,e),e.add(s)}}}for(let e of k)A.has(e)||p.push({code:`tests`,file:e,message:`${e}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`});p.push(...E(N));for(let e of[...T(j),...T(M)])p.push({code:`cycle`,file:e[0],message:`Module dependency cycle: ${e.join(` → `)}.`});return p.sort((e,t)=>e.file.localeCompare(t.file)||e.code.localeCompare(t.code))}function m(e=!0){return new f({tsconfig:`auto`,extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],extensionAlias:{".js":[`.ts`,`.tsx`,`.js`],".mjs":[`.mts`,`.mjs`],".cjs":[`.cts`,`.cjs`]},conditionNames:[`types`,`import`,`node`,`default`],symlinks:e})}function h(e,t,r){return e.resolveFileSync(t,r).path||(r.startsWith(`.`)?i(n(t),r):null)}function g(e){if(!o(e))return null;if(o(i(e,`convex.config.ts`)))return l(i(e,`convex.config.ts`));e=l(e);for(let t of v(e,[]))if(!t.includes(`__tests__/`)&&!y(t))return i(e,t);return null}function _(e,t){let n=e===`relations.ts`?`defineRelations`:e===`querying.ts`?`createQueryEngine`:null;if(!n)return!1;let r=d(e,t);if(r.errors.length)return!1;let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=0,s=!1;function c(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name))return null;let n=a.get(e.name);return n?c(n,new Set(t).add(e.name)):i.get(e.name)??null}return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&c(e.object,t)===`*`?e.property.name:null}function l(e,t,n=!1){if(e.type===`Identifier`||e.type===`Literal`)return!0;if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return l(e.expression,t,n);if(e.type===`MemberExpression`)return!e.computed&&l(e.object,t);if(e.type===`ArrayExpression`)return e.elements.every(e=>e!==null&&l(e,t));if(e.type===`ObjectExpression`)return e.properties.every(e=>e.type===`Property`&&!e.computed&&e.kind===`init`&&!e.method&&l(e.value,t));if(e.type===`ArrowFunctionExpression`&&n&&!t&&e.params.length===1&&e.params[0].type===`Identifier`&&!e.async){let t=e.body.type===`ParenthesizedExpression`?e.body.expression:e.body;return t.type===`ObjectExpression`&&l(t,e.params[0].name)}if(e.type===`CallExpression`&&t){let n=e.callee,r=[];for(;n.type===`MemberExpression`&&!n.computed&&n.property.type===`Identifier`;)r.unshift(n.property.name),n=n.object;return n.type===`Identifier`&&n.name===t&&(r.length===2&&[`one`,`many`].includes(r[0])||r.length===3&&r[2]===`through`)&&e.arguments.every(e=>l(e,t))}return!1}for(let t of r.program.body){if(t.type===`ImportDeclaration`){if(t.importKind===`type`)continue;for(let n of t.specifiers)(n.type!==`ImportSpecifier`||n.importKind!==`type`)&&[`cvx-kit`,`cvx-kit/${e.slice(0,-3)}`].includes(t.source.value)&&i.set(n.local.name,n.type===`ImportSpecifier`?n.imported.type===`Identifier`?n.imported.name:``:n.type===`ImportNamespaceSpecifier`?`*`:``);continue}if(t.type===`EmptyStatement`||t.type===`TSTypeAliasDeclaration`||t.type===`TSInterfaceDeclaration`)continue;let r=t.type===`ExportNamedDeclaration`?t.declaration:t;if(r?.type!==`VariableDeclaration`||r.kind!==`const`)return!1;for(let e of r.declarations){if(e.id.type!==`Identifier`||!e.init)return!1;if(e.init.type===`CallExpression`&&c(e.init.callee)===n){if(!e.init.arguments.every((e,t)=>l(e,void 0,n===`defineRelations`&&t===1)))return!1;o++,s||=t.type===`ExportNamedDeclaration`}else if(t.type===`ExportNamedDeclaration`||!l(e.init))return!1;a.set(e.id.name,e.init)}}return o===1&&s}function*v(e,t){let n=/* @__PURE__ */ new Set([`_generated`,`__tests__`,`api`,`domain`,`application`,`migrations`,`components`]);function*o(s){for(let l of c(s,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let c=i(s,l.name),u=r(e,c).split(a).join(`/`);if(l.isSymbolicLink()){t.push({code:`symlink`,file:u,message:`Keep application source inside its owning directory; symlinked files and folders are not allowed.`});continue}l.isDirectory()?(s===e&&!n.has(l.name)&&t.push({code:`root-directory`,file:u,message:`Root folder ${l.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`}),l.name!==`_generated`&&l.name!==`node_modules`&&!l.name.startsWith(`.`)&&(yield*o(c))):/\.[cm]?[jt]sx?$/.test(l.name)&&!/\.d\.[cm]?ts$/.test(l.name)&&(yield u)}}yield*o(e)}function y(e){return/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(e)}function b(e){return e.body.some(e=>{let t=e.type===`ExportNamedDeclaration`?e.declaration:e;return t&&`declare`in t&&t.declare||e.type===`ImportDeclaration`||e.type===`EmptyStatement`?!1:e.type===`ExportNamedDeclaration`?e.exportKind===`type`||!e.declaration?!1:![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`].includes(e.declaration.type):![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`,`ExportAllDeclaration`].includes(e.type)})}function x(e){let t=/* @__PURE__ */ new Map([[`test`,`test`],[`it`,`it`],[`describe`,`describe`],[`suite`,`suite`]]);for(let n of e.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`FunctionDeclaration`&&e.id&&t.delete(e.id.name),e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.delete(n.id.name);if(n.type===`ImportDeclaration`)for(let e of n.specifiers)t.delete(e.local.name),[`vitest`,`vite-plus/test`,`bun:test`,`node:test`,`@jest/globals`].includes(n.source.value)&&(e.type===`ImportNamespaceSpecifier`?t.set(e.local.name,`*`):e.type===`ImportDefaultSpecifier`?t.set(e.local.name,`test`):e.imported.type===`Identifier`&&t.set(e.local.name,e.imported.name))}let n=[];new u({CallExpression(e){n.push(e)}}).visit(e);let r=n.filter(e=>{let n=S(e.callee,t);return[`test`,`it`,`describe`,`suite`].includes(n[0])&&(n.some(e=>[`skip`,`todo`,`skipIf`,`runIf`].includes(e))||e.arguments.some(e=>e.type===`ObjectExpression`&&e.properties.some(e=>e.type===`Property`&&[`skip`,`todo`].includes(e.key.type===`Identifier`?e.key.name:e.key.type===`Literal`?String(e.key.value):``)&&(e.value.type!==`Literal`||e.value.value!==!1))))});return n.some(e=>{let n=S(e.callee,t);return![`test`,`it`].includes(n[0])||r.some(t=>e.start>=t.start&&e.end<=t.end)?!1:e.arguments.some(e=>(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`)&&e.body&&(e.body.type!==`BlockStatement`||e.body.body.some(e=>e.type!==`EmptyStatement`)))})}function S(e,t){if(e.type===`Identifier`){let n=t.get(e.name);return n?[n]:[]}if(e.type===`CallExpression`)return S(e.callee,t);if(e.type===`MemberExpression`){let n=S(e.object,t),r=!e.computed&&e.property.type===`Identifier`?e.property.name:e.property.type===`Literal`?String(e.property.value):``;return!n.length||!r?[]:n[0]===`*`?[r]:[...n,r]}return[]}function C(e){let t=[];return new u({ImportDeclaration(e){e.importKind!==`type`&&(e.specifiers.length===0||e.specifiers.some(e=>e.type!==`ImportSpecifier`||e.importKind!==`type`))&&t.push(e.source.value)},ExportNamedDeclaration(e){e.source&&e.exportKind!==`type`&&e.specifiers.some(e=>e.exportKind!==`type`)&&t.push(e.source.value)},ExportAllDeclaration(e){e.exportKind!==`type`&&t.push(e.source.value)},ImportExpression(e){e.source.type===`Literal`&&String(e.source.value)===e.source.value&&t.push(String(e.source.value))}}).visit(e),t}function w(e){let t=e.split(`/`);return t[0]===`domain`&&t.length>=3&&t[1]!==`__tests__`?`domain/${t[1]}`:null}function T(e){let t=/* @__PURE__ */ new Set,n=[],r=[];function i(a){let o=n.indexOf(a);if(o>=0){r.push([...n.slice(o),a]);return}if(!t.has(a)){n.push(a);for(let t of e.get(a)??[])i(t);n.pop(),t.add(a)}}for(let t of e.keys())i(t);return r}function E(e){let t=/* @__PURE__ */ new Map;for(let[n,r]of e){let i=w(n)??``;if(!i||i===`domain/shared`)continue;let a=/* @__PURE__ */ new Set;function o(n){if(!n.startsWith(`domain/shared/`)||a.has(n))return;a.add(n);let r=t.get(n)??/* @__PURE__ */ new Set;r.add(i),t.set(n,r);for(let t of e.get(n)??[])o(t)}for(let e of r)o(e)}let n=[];for(let[e,r]of t)r.size===1&&n.push({code:`shared-owner`,file:e,message:`This shared implementation is used only by ${[...r][0]}. Move it into that module until another module needs it.`});return n}export{g as architectureAnchor,m as createResolver,p as inspectArchitecture,_ as narrowRootDeclaration,h as resolveImport};
|
|
2
2
|
//# sourceMappingURL=architecture.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"architecture.mjs","names":["inspectArchitecture","requestedRoot","resolve","options","root","existsSync","realpathSync","diagnostics","files","sourceFiles","required","tested","graph","dependencies","resolver","createResolver","file","filename","parsed","parseSync","readFileSync","testFile","dirname","hasRunnableTest","executable","narrowRootDeclaration","owner","moduleOwner","targets","source","runtimeImports","target","resolveImport","targetFile","relative","sep","targetOwner","edges","directory","sharedOwnership","cycle","cycles","a","b","ResolverFactory","architectureAnchor","factory","imports","aliases","factories","exported","factoryName","node","active","init","declarative","relationParameter","registryCallback","value","property","body","callee","path","argument","statement","specifier","declaration","item","index","allowed","scan","entry","readdirSync","program","names","calls","Visitor","skipped","parts","testCallee","part","skip","name","base","s","completed","stack","found","visit","dependency","consumers","visited","owners","next"],"sources":["../../src/oxlint/architecture.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, relative, resolve, sep } from 'node:path'\nimport { parseSync, Visitor, type Program, type Node, type CallExpression } from 'oxc-parser'\nimport { ResolverFactory } from 'oxc-resolver'\n\nexport interface ArchitectureOptions {\n\tcwd?: string\n\tconvexDir?: string\n\t/** Build these registries to surface deferred configuration errors in tests. */\n\tregistries?: readonly object[]\n}\nexport interface ArchitectureDiagnostic {\n\tcode:\n\t\t| 'missing-root'\n\t\t| 'root-directory'\n\t\t| 'tests'\n\t\t| 'test-location'\n\t\t| 'parse'\n\t\t| 'cycle'\n\t\t| 'symlink'\n\t\t| 'domain-entry'\n\t\t| 'shared-owner'\n\tfile: string\n\tmessage: string\n}\n\n/** Full-project checks, independent of the consumer's test runner. No persistent cache. */\nexport function inspectArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\tconst requestedRoot = resolve(options.cwd ?? process.cwd(), options.convexDir ?? 'convex')\n\tconst root = existsSync(requestedRoot) ? realpathSync(requestedRoot) : requestedRoot\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tif (!existsSync(root))\n\t\treturn [\n\t\t\t{ code: 'missing-root', file: '.', message: `Convex directory does not exist: ${root}` },\n\t\t]\n\tconst files = sourceFiles(root, diagnostics)\n\tconst required = new Set<string>()\n\tconst tested = new Set<string>()\n\tconst graph = new Map<string, Set<string>>()\n\tconst dependencies = new Map<string, Set<string>>()\n\tconst resolver = createResolver()\n\tfor (const file of files) {\n\t\tconst filename = resolve(root, file)\n\t\tconst parsed = parseSync(filename, readFileSync(filename, 'utf8'))\n\t\tif (parsed.errors.length) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'parse',\n\t\t\t\tfile,\n\t\t\t\tmessage: `Cannot validate ${file}: ${parsed.errors[0].message}`,\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (testFile(file)) {\n\t\t\tif (!file.includes('__tests__/'))\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'test-location',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage: 'Place tests in a sibling __tests__/ directory.',\n\t\t\t\t})\n\t\t\telse if (dirname(file).endsWith('__tests__') && hasRunnableTest(parsed.program))\n\t\t\t\ttested.add(dirname(dirname(file)))\n\t\t\tcontinue\n\t\t}\n\t\tif (file.split('/').includes('__tests__')) continue\n\t\tif (/^domain\\/[^/]+$/.test(file) && file !== 'domain/table.ts')\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'domain-entry',\n\t\t\t\tfile,\n\t\t\t\tmessage:\n\t\t\t\t\t'Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.',\n\t\t\t})\n\t\tif (\n\t\t\texecutable(parsed.program) &&\n\t\t\tfile !== 'domain/table.ts' &&\n\t\t\t!narrowRootDeclaration(file, readFileSync(filename, 'utf8'))\n\t\t)\n\t\t\trequired.add(dirname(file))\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tconst targets = new Set<string>()\n\t\tdependencies.set(file, targets)\n\t\tfor (const source of runtimeImports(parsed.program)) {\n\t\t\tconst target = resolveImport(resolver, filename, source)\n\t\t\tif (!target) continue\n\t\t\tconst targetFile = relative(root, target).split(sep).join('/')\n\t\t\ttargets.add(targetFile)\n\t\t\tconst targetOwner = moduleOwner(targetFile)\n\t\t\tif (owner && targetOwner && owner !== targetOwner) {\n\t\t\t\tconst edges = graph.get(owner) ?? new Set<string>()\n\t\t\t\tgraph.set(owner, edges)\n\t\t\t\tedges.add(targetOwner)\n\t\t\t}\n\t\t}\n\t}\n\tfor (const directory of required) {\n\t\tif (!tested.has(directory))\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'tests',\n\t\t\t\tfile: directory,\n\t\t\t\tmessage: `${directory}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`,\n\t\t\t})\n\t}\n\tdiagnostics.push(...sharedOwnership(dependencies))\n\tfor (const cycle of cycles(graph))\n\t\tdiagnostics.push({\n\t\t\tcode: 'cycle',\n\t\t\tfile: cycle[0],\n\t\t\tmessage: `Module dependency cycle: ${cycle.join(' → ')}.`,\n\t\t})\n\treturn diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.code.localeCompare(b.code))\n}\n\nexport function createResolver() {\n\treturn new ResolverFactory({\n\t\ttsconfig: 'auto',\n\t\textensions: ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.json'],\n\t\textensionAlias: {\n\t\t\t'.js': ['.ts', '.tsx', '.js'],\n\t\t\t'.mjs': ['.mts', '.mjs'],\n\t\t\t'.cjs': ['.cts', '.cjs'],\n\t\t},\n\t\tconditionNames: ['types', 'import', 'node', 'default'],\n\t\tsymlinks: true,\n\t})\n}\n\nexport function resolveImport(resolver: ResolverFactory, filename: string, source: string) {\n\tconst found = resolver.resolveFileSync(filename, source).path\n\tif (found) return found\n\t// Keep path checks useful in unsaved/editor fixtures and before Convex codegen.\n\treturn source.startsWith('.') ? resolve(dirname(filename), source) : null\n}\n\n/** The lint rule runs the project scan on one deterministic source file. */\nexport function architectureAnchor(root: string) {\n\tif (!existsSync(root)) return null\n\tif (existsSync(resolve(root, 'convex.config.ts')))\n\t\treturn realpathSync(resolve(root, 'convex.config.ts'))\n\troot = realpathSync(root)\n\tfor (const file of sourceFiles(root, []))\n\t\tif (!file.includes('__tests__/') && !testFile(file)) return resolve(root, file)\n\treturn null\n}\n\n/** Only these two factory declarations may omit root business ownership. */\nexport function narrowRootDeclaration(file: string, source: string): boolean {\n\tconst factory =\n\t\tfile === 'relations.ts'\n\t\t\t? 'defineRelations'\n\t\t\t: file === 'querying.ts'\n\t\t\t\t? 'createQueryEngine'\n\t\t\t\t: null\n\tif (!factory) return false\n\tconst parsed = parseSync(file, source)\n\tif (parsed.errors.length) return false\n\tconst imports = new Map<string, string>()\n\tconst aliases = new Map<string, Node>()\n\tlet factories = 0\n\tlet exported = false\n\tfunction factoryName(node: Node, active = new Set<string>()): string | null {\n\t\tif (node.type === 'Identifier') {\n\t\t\tif (active.has(node.name)) return null\n\t\t\tconst init = aliases.get(node.name)\n\t\t\treturn init\n\t\t\t\t? factoryName(init, new Set(active).add(node.name))\n\t\t\t\t: (imports.get(node.name) ?? null)\n\t\t}\n\t\tif (\n\t\t\tnode.type === 'MemberExpression' &&\n\t\t\t!node.computed &&\n\t\t\tnode.property.type === 'Identifier' &&\n\t\t\tfactoryName(node.object, active) === '*'\n\t\t)\n\t\t\treturn node.property.name\n\t\treturn null\n\t}\n\tfunction declarative(node: Node, relationParameter?: string, registryCallback = false): boolean {\n\t\tif (node.type === 'Identifier' || node.type === 'Literal') return true\n\t\tif (\n\t\t\tnode.type === 'TSAsExpression' ||\n\t\t\tnode.type === 'TSSatisfiesExpression' ||\n\t\t\tnode.type === 'ParenthesizedExpression'\n\t\t)\n\t\t\treturn declarative(node.expression, relationParameter, registryCallback)\n\t\tif (node.type === 'MemberExpression')\n\t\t\treturn !node.computed && declarative(node.object, relationParameter)\n\t\tif (node.type === 'ArrayExpression')\n\t\t\treturn node.elements.every((value) => value !== null && declarative(value, relationParameter))\n\t\tif (node.type === 'ObjectExpression')\n\t\t\treturn node.properties.every(\n\t\t\t\t(property) =>\n\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t!property.computed &&\n\t\t\t\t\tproperty.kind === 'init' &&\n\t\t\t\t\t!property.method &&\n\t\t\t\t\tdeclarative(property.value, relationParameter),\n\t\t\t)\n\t\tif (\n\t\t\tnode.type === 'ArrowFunctionExpression' &&\n\t\t\tregistryCallback &&\n\t\t\t!relationParameter &&\n\t\t\tnode.params.length === 1 &&\n\t\t\tnode.params[0].type === 'Identifier' &&\n\t\t\t!node.async\n\t\t) {\n\t\t\tconst body = node.body.type === 'ParenthesizedExpression' ? node.body.expression : node.body\n\t\t\treturn body.type === 'ObjectExpression' && declarative(body, node.params[0].name)\n\t\t}\n\t\tif (node.type === 'CallExpression' && relationParameter) {\n\t\t\tlet callee: Node = node.callee\n\t\t\tconst path: string[] = []\n\t\t\twhile (\n\t\t\t\tcallee.type === 'MemberExpression' &&\n\t\t\t\t!callee.computed &&\n\t\t\t\tcallee.property.type === 'Identifier'\n\t\t\t) {\n\t\t\t\tpath.unshift(callee.property.name)\n\t\t\t\tcallee = callee.object\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tcallee.type === 'Identifier' &&\n\t\t\t\tcallee.name === relationParameter &&\n\t\t\t\t((path.length === 2 && ['one', 'many'].includes(path[0])) ||\n\t\t\t\t\t(path.length === 3 && path[2] === 'through')) &&\n\t\t\t\tnode.arguments.every((argument) => declarative(argument, relationParameter))\n\t\t\t)\n\t\t}\n\t\treturn false\n\t}\n\tfor (const statement of parsed.program.body) {\n\t\tif (statement.type === 'ImportDeclaration') {\n\t\t\tif (statement.importKind === 'type') continue\n\t\t\tfor (const specifier of statement.specifiers) {\n\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\tif (['cvx-kit', `cvx-kit/${file.slice(0, -3)}`].includes(statement.source.value))\n\t\t\t\t\timports.set(\n\t\t\t\t\t\tspecifier.local.name,\n\t\t\t\t\t\tspecifier.type === 'ImportSpecifier'\n\t\t\t\t\t\t\t? specifier.imported.type === 'Identifier'\n\t\t\t\t\t\t\t\t? specifier.imported.name\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t: specifier.type === 'ImportNamespaceSpecifier'\n\t\t\t\t\t\t\t\t? '*'\n\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (\n\t\t\tstatement.type === 'EmptyStatement' ||\n\t\t\tstatement.type === 'TSTypeAliasDeclaration' ||\n\t\t\tstatement.type === 'TSInterfaceDeclaration'\n\t\t)\n\t\t\tcontinue\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const') return false\n\t\tfor (const item of declaration.declarations) {\n\t\t\tif (item.id.type !== 'Identifier' || !item.init) return false\n\t\t\tif (item.init.type === 'CallExpression' && factoryName(item.init.callee) === factory) {\n\t\t\t\tif (\n\t\t\t\t\t!item.init.arguments.every((argument, index) =>\n\t\t\t\t\t\tdeclarative(argument, undefined, factory === 'defineRelations' && index === 1),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t\tfactories++\n\t\t\t\texported ||= statement.type === 'ExportNamedDeclaration'\n\t\t\t} else if (statement.type === 'ExportNamedDeclaration' || !declarative(item.init))\n\t\t\t\treturn false\n\t\t\taliases.set(item.id.name, item.init)\n\t\t}\n\t}\n\treturn factories === 1 && exported\n}\n\nfunction* sourceFiles(root: string, diagnostics: ArchitectureDiagnostic[]): Generator<string> {\n\tconst allowed = new Set([\n\t\t'_generated',\n\t\t'__tests__',\n\t\t'api',\n\t\t'domain',\n\t\t'application',\n\t\t'migrations',\n\t\t'components',\n\t])\n\tfunction* scan(directory: string): Generator<string> {\n\t\tfor (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>\n\t\t\ta.name.localeCompare(b.name),\n\t\t)) {\n\t\t\tconst path = resolve(directory, entry.name)\n\t\t\tconst file = relative(root, path).split(sep).join('/')\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'symlink',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t'Keep application source inside its owning directory; symlinked files and folders are not allowed.',\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tif (directory === root && !allowed.has(entry.name))\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: 'root-directory',\n\t\t\t\t\t\tfile,\n\t\t\t\t\t\tmessage: `Root folder ${entry.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`,\n\t\t\t\t\t})\n\t\t\t\tif (\n\t\t\t\t\tentry.name !== '_generated' &&\n\t\t\t\t\tentry.name !== 'node_modules' &&\n\t\t\t\t\t!entry.name.startsWith('.')\n\t\t\t\t)\n\t\t\t\t\tyield* scan(path)\n\t\t\t} else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !/\\.d\\.[cm]?ts$/.test(entry.name)) yield file\n\t\t}\n\t}\n\tyield* scan(root)\n}\n\nfunction testFile(file: string) {\n\treturn /\\.(?:test|spec)\\.[cm]?[jt]sx?$/.test(file)\n}\n\nfunction executable(program: Program) {\n\treturn program.body.some((statement) => {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration && 'declare' in declaration && declaration.declare) return false\n\t\tif (statement.type === 'ImportDeclaration' || statement.type === 'EmptyStatement') return false\n\t\tif (statement.type === 'ExportNamedDeclaration') {\n\t\t\tif (statement.exportKind === 'type' || !statement.declaration) return false\n\t\t\treturn !['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSDeclareFunction'].includes(\n\t\t\t\tstatement.declaration.type,\n\t\t\t)\n\t\t}\n\t\treturn ![\n\t\t\t'TSInterfaceDeclaration',\n\t\t\t'TSTypeAliasDeclaration',\n\t\t\t'TSDeclareFunction',\n\t\t\t'ExportAllDeclaration',\n\t\t].includes(statement.type)\n\t})\n}\n\nfunction hasRunnableTest(program: Program) {\n\tconst names = new Map([\n\t\t['test', 'test'],\n\t\t['it', 'it'],\n\t\t['describe', 'describe'],\n\t\t['suite', 'suite'],\n\t])\n\tfor (const statement of program.body) {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type === 'FunctionDeclaration' && declaration.id)\n\t\t\tnames.delete(declaration.id.name)\n\t\tif (declaration?.type === 'VariableDeclaration')\n\t\t\tfor (const item of declaration.declarations) {\n\t\t\t\tif (item.id.type === 'Identifier') names.delete(item.id.name)\n\t\t\t}\n\t\tif (statement.type !== 'ImportDeclaration') continue\n\t\tfor (const specifier of statement.specifiers) {\n\t\t\tnames.delete(specifier.local.name)\n\t\t\tif (\n\t\t\t\t!['vitest', 'vite-plus/test', 'bun:test', 'node:test', '@jest/globals'].includes(\n\t\t\t\t\tstatement.source.value,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (specifier.type === 'ImportNamespaceSpecifier') names.set(specifier.local.name, '*')\n\t\t\telse if (specifier.type === 'ImportDefaultSpecifier') names.set(specifier.local.name, 'test')\n\t\t\telse if (specifier.imported.type === 'Identifier')\n\t\t\t\tnames.set(specifier.local.name, specifier.imported.name)\n\t\t}\n\t}\n\tconst calls: CallExpression[] = []\n\tnew Visitor({\n\t\tCallExpression(node) {\n\t\t\tcalls.push(node)\n\t\t},\n\t}).visit(program)\n\tconst skipped = calls.filter((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\treturn (\n\t\t\t['test', 'it', 'describe', 'suite'].includes(parts[0]) &&\n\t\t\t(parts.some((part) => ['skip', 'todo', 'skipIf', 'runIf'].includes(part)) ||\n\t\t\t\tnode.arguments.some(\n\t\t\t\t\t(argument) =>\n\t\t\t\t\t\targument.type === 'ObjectExpression' &&\n\t\t\t\t\t\targument.properties.some(\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t['skip', 'todo'].includes(\n\t\t\t\t\t\t\t\t\tproperty.key.type === 'Identifier'\n\t\t\t\t\t\t\t\t\t\t? property.key.name\n\t\t\t\t\t\t\t\t\t\t: property.key.type === 'Literal'\n\t\t\t\t\t\t\t\t\t\t\t? String(property.key.value)\n\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t!(property.value.type === 'Literal' && property.value.value === false),\n\t\t\t\t\t\t),\n\t\t\t\t))\n\t\t)\n\t})\n\treturn calls.some((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\tif (\n\t\t\t!['test', 'it'].includes(parts[0]) ||\n\t\t\tskipped.some((skip) => node.start >= skip.start && node.end <= skip.end)\n\t\t)\n\t\t\treturn false\n\t\t// each(...) is a factory; only the outer call has the test callback.\n\t\treturn node.arguments.some(\n\t\t\t(argument) =>\n\t\t\t\t(argument.type === 'ArrowFunctionExpression' || argument.type === 'FunctionExpression') &&\n\t\t\t\targument.body &&\n\t\t\t\t(argument.body.type !== 'BlockStatement' ||\n\t\t\t\t\targument.body.body.some((statement) => statement.type !== 'EmptyStatement')),\n\t\t)\n\t})\n}\n\nfunction testCallee(node: Node, names: Map<string, string>): string[] {\n\tif (node.type === 'Identifier') {\n\t\tconst name = names.get(node.name)\n\t\treturn name ? [name] : []\n\t}\n\tif (node.type === 'CallExpression') return testCallee(node.callee, names)\n\tif (node.type === 'MemberExpression') {\n\t\tconst base = testCallee(node.object, names)\n\t\tconst property =\n\t\t\t!node.computed && node.property.type === 'Identifier'\n\t\t\t\t? node.property.name\n\t\t\t\t: node.property.type === 'Literal'\n\t\t\t\t\t? String(node.property.value)\n\t\t\t\t\t: ''\n\t\tif (!base.length || !property) return []\n\t\treturn base[0] === '*' ? [property] : [...base, property]\n\t}\n\treturn []\n}\n\nfunction runtimeImports(program: Program) {\n\tconst imports: string[] = []\n\tnew Visitor({\n\t\tImportDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.importKind !== 'type' &&\n\t\t\t\t(node.specifiers.length === 0 ||\n\t\t\t\t\tnode.specifiers.some((s) => s.type !== 'ImportSpecifier' || s.importKind !== 'type'))\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportNamedDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.source &&\n\t\t\t\tnode.exportKind !== 'type' &&\n\t\t\t\tnode.specifiers.some((specifier) => specifier.exportKind !== 'type')\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportAllDeclaration(node) {\n\t\t\tif (node.exportKind !== 'type') imports.push(node.source.value)\n\t\t},\n\t\tImportExpression(node) {\n\t\t\tif (node.source.type === 'Literal' && String(node.source.value) === node.source.value)\n\t\t\t\timports.push(String(node.source.value))\n\t\t},\n\t}).visit(program)\n\treturn imports\n}\n\nfunction moduleOwner(file: string) {\n\tconst parts = file.split('/')\n\treturn parts[0] === 'domain' && parts.length >= 3 && parts[1] !== '__tests__'\n\t\t? `domain/${parts[1]}`\n\t\t: null\n}\n\nfunction cycles(graph: Map<string, Set<string>>) {\n\tconst completed = new Set<string>()\n\tconst stack: string[] = []\n\tconst found: string[][] = []\n\tfunction visit(owner: string) {\n\t\tconst index = stack.indexOf(owner)\n\t\tif (index >= 0) {\n\t\t\tfound.push([...stack.slice(index), owner])\n\t\t\treturn\n\t\t}\n\t\tif (completed.has(owner)) return\n\t\tstack.push(owner)\n\t\tfor (const dependency of graph.get(owner) ?? []) visit(dependency)\n\t\tstack.pop()\n\t\tcompleted.add(owner)\n\t}\n\tfor (const owner of graph.keys()) visit(owner)\n\treturn found\n}\n\nfunction sharedOwnership(dependencies: Map<string, Set<string>>): ArchitectureDiagnostic[] {\n\tconst consumers = new Map<string, Set<string>>()\n\tfor (const [file, targets] of dependencies) {\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tif (!owner || owner === 'domain/shared') continue\n\t\tconst visited = new Set<string>()\n\t\tfunction visit(target: string) {\n\t\t\tif (!target.startsWith('domain/shared/') || visited.has(target)) return\n\t\t\tvisited.add(target)\n\t\t\tconst owners = consumers.get(target) ?? new Set<string>()\n\t\t\towners.add(owner)\n\t\t\tconsumers.set(target, owners)\n\t\t\tfor (const next of dependencies.get(target) ?? []) visit(next)\n\t\t}\n\t\tfor (const target of targets) visit(target)\n\t}\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tfor (const [file, owners] of consumers) {\n\t\tif (owners.size === 1)\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'shared-owner',\n\t\t\t\tfile,\n\t\t\t\tmessage: `This shared implementation is used only by ${[...owners][0]}. Move it into that module until another module needs it.`,\n\t\t\t})\n\t}\n\treturn diagnostics\n}\n"],"mappings":"qQA2BA,SAAgBA,EAAoB,EAA+B,CAAC,EAA6B,CAChG,IAAMC,EAAgBC,EAAQC,EAAQ,KAAO,QAAQ,IAAI,EAAGA,EAAQ,WAAa,QAAQ,EACnFC,EAAOC,EAAWJ,CAAa,EAAIK,EAAaL,CAAa,EAAIA,EACjEM,EAAwC,CAAC,EAC/C,GAAI,CAACF,EAAWD,CAAI,EACnB,MAAO,CACN,CAAE,KAAM,eAAgB,KAAM,IAAK,QAAS,oCAAoCA,GAAO,CACxF,EACD,IAAMI,EAAQC,EAAYL,EAAMG,CAAW,EACrCG,kBAAW,IAAI,IACfC,kBAAS,IAAI,IACbC,kBAAQ,IAAI,IACZC,kBAAe,IAAI,IACnBC,EAAWC,EAAe,EAChC,IAAK,IAAMC,KAAQR,EAAO,CACzB,IAAMS,EAAWf,EAAQE,EAAMY,CAAI,EAC7BE,EAASC,EAAUF,EAAUG,EAAaH,EAAU,MAAM,CAAC,EACjE,GAAIC,EAAO,OAAO,OAAQ,CACzBX,EAAY,KAAK,CAChB,KAAM,QACN,OACA,QAAS,mBAAmBS,EAAK,IAAIE,EAAO,OAAO,EAAE,CAAC,SACvD,CAAC,EACD,QACD,CACA,GAAIG,EAASL,CAAI,EAAG,CACdA,EAAK,SAAS,YAAY,EAMtBM,EAAQN,CAAI,CAAC,CAAC,SAAS,WAAW,GAAKO,EAAgBL,EAAO,OAAO,GAC7EP,EAAO,IAAIW,EAAQA,EAAQN,CAAI,CAAC,CAAC,EANjCT,EAAY,KAAK,CAChB,KAAM,gBACN,OACA,QAAS,gDACV,CAAC,EAGF,QACD,CACA,GAAIS,EA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EAAQ,IAAI5D,CAAM,EAAG,OACjE4D,EAAQ,IAAI5D,CAAM,EAClB,IAAM6D,EAASF,EAAU,IAAI3D,CAAM,mBAAK,IAAI,IAC5C6D,EAAO,IAAIlE,CAAK,EAChBgE,EAAU,IAAI3D,EAAQ6D,CAAM,EAC5B,IAAK,IAAMC,KAAQhF,EAAa,IAAIkB,CAAM,GAAK,CAAC,EAAGyD,EAAMK,CAAI,CAC9D,CACA,IAAK,IAAM9D,KAAUH,EAAS4D,EAAMzD,CAAM,CAC3C,CACA,IAAMxB,EAAwC,CAAC,EAC/C,IAAK,GAAM,CAACS,EAAM4E,KAAWF,EACxBE,EAAO,OAAS,GACnBrF,EAAY,KAAK,CAChB,KAAM,eACN,OACA,QAAS,8CAA8C,CAAC,GAAGqF,CAAM,CAAC,CAAC,GAAG,0DACvE,CAAC,EAEH,OAAOrF,CACR"}
|
|
1
|
+
{"version":3,"file":"architecture.mjs","names":["inspectArchitecture","requestedRoot","resolve","options","root","existsSync","realpathSync","diagnostics","explicitRoots","path","files","sourceFiles","owners","file","owner","findComponentRoot","conventionalComponentRoot","sep","relative","componentRoots","index","issue","required","tested","graph","componentGraph","dependencies","resolver","createResolver","filename","parsed","parseSync","readFileSync","testFile","dirname","hasRunnableTest","component","localFile","executable","narrowRootDeclaration","moduleOwner","targets","source","runtimeImports","target","resolveImport","targetFile","edges","targetOwner","directory","sharedOwnership","cycle","cycles","a","b","ResolverFactory","architectureAnchor","factory","imports","aliases","factories","exported","factoryName","node","active","init","declarative","relationParameter","registryCallback","value","property","body","callee","argument","statement","specifier","declaration","item","allowed","scan","entry","readdirSync","program","names","calls","Visitor","skipped","parts","testCallee","part","skip","name","base","s","completed","stack","found","visit","dependency","consumers","visited","next"],"sources":["../../src/oxlint/architecture.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, relative, resolve, sep } from 'node:path'\nimport { parseSync, Visitor, type Program, type Node, type CallExpression } from 'oxc-parser'\nimport { ResolverFactory } from 'oxc-resolver'\nimport { findComponentRoot, conventionalComponentRoot } from './components'\n\nexport interface ArchitectureOptions {\n\tcwd?: string\n\tconvexDir?: string\n\t/** Additional component roots, relative to convexDir. */\n\tcomponentDirs?: readonly string[]\n\t/** Build these registries to surface deferred configuration errors in tests. */\n\tregistries?: readonly object[]\n}\nexport interface ArchitectureDiagnostic {\n\tcode:\n\t\t| 'missing-root'\n\t\t| 'root-directory'\n\t\t| 'tests'\n\t\t| 'test-location'\n\t\t| 'parse'\n\t\t| 'cycle'\n\t\t| 'symlink'\n\t\t| 'domain-entry'\n\t\t| 'shared-owner'\n\tfile: string\n\tmessage: string\n}\n\n/** Full-project checks, independent of the consumer's test runner. No persistent cache. */\nexport function inspectArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\tconst requestedRoot = resolve(options.cwd ?? process.cwd(), options.convexDir ?? 'convex')\n\tconst root = existsSync(requestedRoot) ? realpathSync(requestedRoot) : requestedRoot\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tif (!existsSync(root))\n\t\treturn [\n\t\t\t{ code: 'missing-root', file: '.', message: `Convex directory does not exist: ${root}` },\n\t\t]\n\tconst explicitRoots = (options.componentDirs ?? []).map((path) => resolve(root, path))\n\tconst files = [...sourceFiles(root, diagnostics)]\n\tconst owners = new Map<string, string>()\n\tfor (const file of files) {\n\t\tconst owner =\n\t\t\tfindComponentRoot(resolve(root, file), explicitRoots) ??\n\t\t\tconventionalComponentRoot(resolve(root, file), root)\n\t\tif (owner && (owner === root || owner.startsWith(root + sep)))\n\t\t\towners.set(file, relative(root, owner).split(sep).join('/'))\n\t}\n\tconst componentRoots = new Set(owners.values())\n\t// Component submodules have their own layout; only host directories use the app allowlist.\n\tfor (let index = diagnostics.length - 1; index >= 0; index--) {\n\t\tconst issue = diagnostics[index]\n\t\tif (\n\t\t\tissue.code === 'root-directory' &&\n\t\t\t[...componentRoots].some(\n\t\t\t\t(owner) => !owner || owner === issue.file || owner.startsWith(issue.file + '/'),\n\t\t\t) &&\n\t\t\t!files.some((file) => file.startsWith(issue.file + '/') && !owners.has(file))\n\t\t)\n\t\t\tdiagnostics.splice(index, 1)\n\t}\n\tconst required = new Set<string>()\n\tconst tested = new Set<string>()\n\tconst graph = new Map<string, Set<string>>()\n\tconst componentGraph = new Map<string, Set<string>>()\n\tconst dependencies = new Map<string, Set<string>>()\n\tconst resolver = createResolver()\n\tfor (const file of files) {\n\t\tconst filename = resolve(root, file)\n\t\tconst parsed = parseSync(filename, readFileSync(filename, 'utf8'))\n\t\tif (parsed.errors.length) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'parse',\n\t\t\t\tfile,\n\t\t\t\tmessage: `Cannot validate ${file}: ${parsed.errors[0].message}`,\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (testFile(file)) {\n\t\t\tif (!file.includes('__tests__/'))\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'test-location',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage: 'Place tests in a sibling __tests__/ directory.',\n\t\t\t\t})\n\t\t\telse if (dirname(file).endsWith('__tests__') && hasRunnableTest(parsed.program))\n\t\t\t\ttested.add(dirname(dirname(file)))\n\t\t\tcontinue\n\t\t}\n\t\tif (file.split('/').includes('__tests__')) continue\n\t\tconst component = owners.get(file)\n\t\tconst localFile =\n\t\t\tcomponent === undefined\n\t\t\t\t? file\n\t\t\t\t: relative(resolve(root, component), filename).split(sep).join('/')\n\t\tif (component === undefined && /^domain\\/[^/]+$/.test(file) && file !== 'domain/table.ts')\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'domain-entry',\n\t\t\t\tfile,\n\t\t\t\tmessage:\n\t\t\t\t\t'Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.',\n\t\t\t})\n\t\tif (\n\t\t\texecutable(parsed.program) &&\n\t\t\tfile !== 'domain/table.ts' &&\n\t\t\t!narrowRootDeclaration(localFile, readFileSync(filename, 'utf8'))\n\t\t)\n\t\t\trequired.add(dirname(file))\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tconst targets = new Set<string>()\n\t\tdependencies.set(file, targets)\n\t\tfor (const source of runtimeImports(parsed.program)) {\n\t\t\tconst target = resolveImport(resolver, filename, source)\n\t\t\tif (!target) continue\n\t\t\tconst targetFile = relative(root, target).split(sep).join('/')\n\t\t\ttargets.add(targetFile)\n\t\t\tif (component !== undefined && owners.get(targetFile) === component) {\n\t\t\t\tconst edges = componentGraph.get(file) ?? new Set<string>()\n\t\t\t\tcomponentGraph.set(file, edges)\n\t\t\t\tedges.add(targetFile)\n\t\t\t}\n\t\t\tconst targetOwner = moduleOwner(targetFile)\n\t\t\tif (owner && targetOwner && owner !== targetOwner) {\n\t\t\t\tconst edges = graph.get(owner) ?? new Set<string>()\n\t\t\t\tgraph.set(owner, edges)\n\t\t\t\tedges.add(targetOwner)\n\t\t\t}\n\t\t}\n\t}\n\tfor (const directory of required) {\n\t\tif (!tested.has(directory))\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'tests',\n\t\t\t\tfile: directory,\n\t\t\t\tmessage: `${directory}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`,\n\t\t\t})\n\t}\n\tdiagnostics.push(...sharedOwnership(dependencies))\n\tfor (const cycle of [...cycles(graph), ...cycles(componentGraph)])\n\t\tdiagnostics.push({\n\t\t\tcode: 'cycle',\n\t\t\tfile: cycle[0],\n\t\t\tmessage: `Module dependency cycle: ${cycle.join(' → ')}.`,\n\t\t})\n\treturn diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.code.localeCompare(b.code))\n}\n\nexport function createResolver(symlinks = true) {\n\treturn new ResolverFactory({\n\t\ttsconfig: 'auto',\n\t\textensions: ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.json'],\n\t\textensionAlias: {\n\t\t\t'.js': ['.ts', '.tsx', '.js'],\n\t\t\t'.mjs': ['.mts', '.mjs'],\n\t\t\t'.cjs': ['.cts', '.cjs'],\n\t\t},\n\t\tconditionNames: ['types', 'import', 'node', 'default'],\n\t\tsymlinks,\n\t})\n}\n\nexport function resolveImport(resolver: ResolverFactory, filename: string, source: string) {\n\tconst found = resolver.resolveFileSync(filename, source).path\n\tif (found) return found\n\t// Keep path checks useful in unsaved/editor fixtures and before Convex codegen.\n\treturn source.startsWith('.') ? resolve(dirname(filename), source) : null\n}\n\n/** The lint rule runs the project scan on one deterministic source file. */\nexport function architectureAnchor(root: string) {\n\tif (!existsSync(root)) return null\n\tif (existsSync(resolve(root, 'convex.config.ts')))\n\t\treturn realpathSync(resolve(root, 'convex.config.ts'))\n\troot = realpathSync(root)\n\tfor (const file of sourceFiles(root, []))\n\t\tif (!file.includes('__tests__/') && !testFile(file)) return resolve(root, file)\n\treturn null\n}\n\n/** Only these two factory declarations may omit root business ownership. */\nexport function narrowRootDeclaration(file: string, source: string): boolean {\n\tconst factory =\n\t\tfile === 'relations.ts'\n\t\t\t? 'defineRelations'\n\t\t\t: file === 'querying.ts'\n\t\t\t\t? 'createQueryEngine'\n\t\t\t\t: null\n\tif (!factory) return false\n\tconst parsed = parseSync(file, source)\n\tif (parsed.errors.length) return false\n\tconst imports = new Map<string, string>()\n\tconst aliases = new Map<string, Node>()\n\tlet factories = 0\n\tlet exported = false\n\tfunction factoryName(node: Node, active = new Set<string>()): string | null {\n\t\tif (node.type === 'Identifier') {\n\t\t\tif (active.has(node.name)) return null\n\t\t\tconst init = aliases.get(node.name)\n\t\t\treturn init\n\t\t\t\t? factoryName(init, new Set(active).add(node.name))\n\t\t\t\t: (imports.get(node.name) ?? null)\n\t\t}\n\t\tif (\n\t\t\tnode.type === 'MemberExpression' &&\n\t\t\t!node.computed &&\n\t\t\tnode.property.type === 'Identifier' &&\n\t\t\tfactoryName(node.object, active) === '*'\n\t\t)\n\t\t\treturn node.property.name\n\t\treturn null\n\t}\n\tfunction declarative(node: Node, relationParameter?: string, registryCallback = false): boolean {\n\t\tif (node.type === 'Identifier' || node.type === 'Literal') return true\n\t\tif (\n\t\t\tnode.type === 'TSAsExpression' ||\n\t\t\tnode.type === 'TSSatisfiesExpression' ||\n\t\t\tnode.type === 'ParenthesizedExpression'\n\t\t)\n\t\t\treturn declarative(node.expression, relationParameter, registryCallback)\n\t\tif (node.type === 'MemberExpression')\n\t\t\treturn !node.computed && declarative(node.object, relationParameter)\n\t\tif (node.type === 'ArrayExpression')\n\t\t\treturn node.elements.every((value) => value !== null && declarative(value, relationParameter))\n\t\tif (node.type === 'ObjectExpression')\n\t\t\treturn node.properties.every(\n\t\t\t\t(property) =>\n\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t!property.computed &&\n\t\t\t\t\tproperty.kind === 'init' &&\n\t\t\t\t\t!property.method &&\n\t\t\t\t\tdeclarative(property.value, relationParameter),\n\t\t\t)\n\t\tif (\n\t\t\tnode.type === 'ArrowFunctionExpression' &&\n\t\t\tregistryCallback &&\n\t\t\t!relationParameter &&\n\t\t\tnode.params.length === 1 &&\n\t\t\tnode.params[0].type === 'Identifier' &&\n\t\t\t!node.async\n\t\t) {\n\t\t\tconst body = node.body.type === 'ParenthesizedExpression' ? node.body.expression : node.body\n\t\t\treturn body.type === 'ObjectExpression' && declarative(body, node.params[0].name)\n\t\t}\n\t\tif (node.type === 'CallExpression' && relationParameter) {\n\t\t\tlet callee: Node = node.callee\n\t\t\tconst path: string[] = []\n\t\t\twhile (\n\t\t\t\tcallee.type === 'MemberExpression' &&\n\t\t\t\t!callee.computed &&\n\t\t\t\tcallee.property.type === 'Identifier'\n\t\t\t) {\n\t\t\t\tpath.unshift(callee.property.name)\n\t\t\t\tcallee = callee.object\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tcallee.type === 'Identifier' &&\n\t\t\t\tcallee.name === relationParameter &&\n\t\t\t\t((path.length === 2 && ['one', 'many'].includes(path[0])) ||\n\t\t\t\t\t(path.length === 3 && path[2] === 'through')) &&\n\t\t\t\tnode.arguments.every((argument) => declarative(argument, relationParameter))\n\t\t\t)\n\t\t}\n\t\treturn false\n\t}\n\tfor (const statement of parsed.program.body) {\n\t\tif (statement.type === 'ImportDeclaration') {\n\t\t\tif (statement.importKind === 'type') continue\n\t\t\tfor (const specifier of statement.specifiers) {\n\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\tif (['cvx-kit', `cvx-kit/${file.slice(0, -3)}`].includes(statement.source.value))\n\t\t\t\t\timports.set(\n\t\t\t\t\t\tspecifier.local.name,\n\t\t\t\t\t\tspecifier.type === 'ImportSpecifier'\n\t\t\t\t\t\t\t? specifier.imported.type === 'Identifier'\n\t\t\t\t\t\t\t\t? specifier.imported.name\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t: specifier.type === 'ImportNamespaceSpecifier'\n\t\t\t\t\t\t\t\t? '*'\n\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (\n\t\t\tstatement.type === 'EmptyStatement' ||\n\t\t\tstatement.type === 'TSTypeAliasDeclaration' ||\n\t\t\tstatement.type === 'TSInterfaceDeclaration'\n\t\t)\n\t\t\tcontinue\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const') return false\n\t\tfor (const item of declaration.declarations) {\n\t\t\tif (item.id.type !== 'Identifier' || !item.init) return false\n\t\t\tif (item.init.type === 'CallExpression' && factoryName(item.init.callee) === factory) {\n\t\t\t\tif (\n\t\t\t\t\t!item.init.arguments.every((argument, index) =>\n\t\t\t\t\t\tdeclarative(argument, undefined, factory === 'defineRelations' && index === 1),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t\tfactories++\n\t\t\t\texported ||= statement.type === 'ExportNamedDeclaration'\n\t\t\t} else if (statement.type === 'ExportNamedDeclaration' || !declarative(item.init))\n\t\t\t\treturn false\n\t\t\taliases.set(item.id.name, item.init)\n\t\t}\n\t}\n\treturn factories === 1 && exported\n}\n\nfunction* sourceFiles(root: string, diagnostics: ArchitectureDiagnostic[]): Generator<string> {\n\tconst allowed = new Set([\n\t\t'_generated',\n\t\t'__tests__',\n\t\t'api',\n\t\t'domain',\n\t\t'application',\n\t\t'migrations',\n\t\t'components',\n\t])\n\tfunction* scan(directory: string): Generator<string> {\n\t\tfor (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>\n\t\t\ta.name.localeCompare(b.name),\n\t\t)) {\n\t\t\tconst path = resolve(directory, entry.name)\n\t\t\tconst file = relative(root, path).split(sep).join('/')\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'symlink',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t'Keep application source inside its owning directory; symlinked files and folders are not allowed.',\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tif (directory === root && !allowed.has(entry.name))\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: 'root-directory',\n\t\t\t\t\t\tfile,\n\t\t\t\t\t\tmessage: `Root folder ${entry.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`,\n\t\t\t\t\t})\n\t\t\t\tif (\n\t\t\t\t\tentry.name !== '_generated' &&\n\t\t\t\t\tentry.name !== 'node_modules' &&\n\t\t\t\t\t!entry.name.startsWith('.')\n\t\t\t\t)\n\t\t\t\t\tyield* scan(path)\n\t\t\t} else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !/\\.d\\.[cm]?ts$/.test(entry.name)) yield file\n\t\t}\n\t}\n\tyield* scan(root)\n}\n\nfunction testFile(file: string) {\n\treturn /\\.(?:test|spec)\\.[cm]?[jt]sx?$/.test(file)\n}\n\nfunction executable(program: Program) {\n\treturn program.body.some((statement) => {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration && 'declare' in declaration && declaration.declare) return false\n\t\tif (statement.type === 'ImportDeclaration' || statement.type === 'EmptyStatement') return false\n\t\tif (statement.type === 'ExportNamedDeclaration') {\n\t\t\tif (statement.exportKind === 'type' || !statement.declaration) return false\n\t\t\treturn !['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSDeclareFunction'].includes(\n\t\t\t\tstatement.declaration.type,\n\t\t\t)\n\t\t}\n\t\treturn ![\n\t\t\t'TSInterfaceDeclaration',\n\t\t\t'TSTypeAliasDeclaration',\n\t\t\t'TSDeclareFunction',\n\t\t\t'ExportAllDeclaration',\n\t\t].includes(statement.type)\n\t})\n}\n\nfunction hasRunnableTest(program: Program) {\n\tconst names = new Map([\n\t\t['test', 'test'],\n\t\t['it', 'it'],\n\t\t['describe', 'describe'],\n\t\t['suite', 'suite'],\n\t])\n\tfor (const statement of program.body) {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type === 'FunctionDeclaration' && declaration.id)\n\t\t\tnames.delete(declaration.id.name)\n\t\tif (declaration?.type === 'VariableDeclaration')\n\t\t\tfor (const item of declaration.declarations) {\n\t\t\t\tif (item.id.type === 'Identifier') names.delete(item.id.name)\n\t\t\t}\n\t\tif (statement.type !== 'ImportDeclaration') continue\n\t\tfor (const specifier of statement.specifiers) {\n\t\t\tnames.delete(specifier.local.name)\n\t\t\tif (\n\t\t\t\t!['vitest', 'vite-plus/test', 'bun:test', 'node:test', '@jest/globals'].includes(\n\t\t\t\t\tstatement.source.value,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (specifier.type === 'ImportNamespaceSpecifier') names.set(specifier.local.name, '*')\n\t\t\telse if (specifier.type === 'ImportDefaultSpecifier') names.set(specifier.local.name, 'test')\n\t\t\telse if (specifier.imported.type === 'Identifier')\n\t\t\t\tnames.set(specifier.local.name, specifier.imported.name)\n\t\t}\n\t}\n\tconst calls: CallExpression[] = []\n\tnew Visitor({\n\t\tCallExpression(node) {\n\t\t\tcalls.push(node)\n\t\t},\n\t}).visit(program)\n\tconst skipped = calls.filter((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\treturn (\n\t\t\t['test', 'it', 'describe', 'suite'].includes(parts[0]) &&\n\t\t\t(parts.some((part) => ['skip', 'todo', 'skipIf', 'runIf'].includes(part)) ||\n\t\t\t\tnode.arguments.some(\n\t\t\t\t\t(argument) =>\n\t\t\t\t\t\targument.type === 'ObjectExpression' &&\n\t\t\t\t\t\targument.properties.some(\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t['skip', 'todo'].includes(\n\t\t\t\t\t\t\t\t\tproperty.key.type === 'Identifier'\n\t\t\t\t\t\t\t\t\t\t? property.key.name\n\t\t\t\t\t\t\t\t\t\t: property.key.type === 'Literal'\n\t\t\t\t\t\t\t\t\t\t\t? String(property.key.value)\n\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t!(property.value.type === 'Literal' && property.value.value === false),\n\t\t\t\t\t\t),\n\t\t\t\t))\n\t\t)\n\t})\n\treturn calls.some((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\tif (\n\t\t\t!['test', 'it'].includes(parts[0]) ||\n\t\t\tskipped.some((skip) => node.start >= skip.start && node.end <= skip.end)\n\t\t)\n\t\t\treturn false\n\t\t// each(...) is a factory; only the outer call has the test callback.\n\t\treturn node.arguments.some(\n\t\t\t(argument) =>\n\t\t\t\t(argument.type === 'ArrowFunctionExpression' || argument.type === 'FunctionExpression') &&\n\t\t\t\targument.body &&\n\t\t\t\t(argument.body.type !== 'BlockStatement' ||\n\t\t\t\t\targument.body.body.some((statement) => statement.type !== 'EmptyStatement')),\n\t\t)\n\t})\n}\n\nfunction testCallee(node: Node, names: Map<string, string>): string[] {\n\tif (node.type === 'Identifier') {\n\t\tconst name = names.get(node.name)\n\t\treturn name ? [name] : []\n\t}\n\tif (node.type === 'CallExpression') return testCallee(node.callee, names)\n\tif (node.type === 'MemberExpression') {\n\t\tconst base = testCallee(node.object, names)\n\t\tconst property =\n\t\t\t!node.computed && node.property.type === 'Identifier'\n\t\t\t\t? node.property.name\n\t\t\t\t: node.property.type === 'Literal'\n\t\t\t\t\t? String(node.property.value)\n\t\t\t\t\t: ''\n\t\tif (!base.length || !property) return []\n\t\treturn base[0] === '*' ? [property] : [...base, property]\n\t}\n\treturn []\n}\n\nfunction runtimeImports(program: Program) {\n\tconst imports: string[] = []\n\tnew Visitor({\n\t\tImportDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.importKind !== 'type' &&\n\t\t\t\t(node.specifiers.length === 0 ||\n\t\t\t\t\tnode.specifiers.some((s) => s.type !== 'ImportSpecifier' || s.importKind !== 'type'))\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportNamedDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.source &&\n\t\t\t\tnode.exportKind !== 'type' &&\n\t\t\t\tnode.specifiers.some((specifier) => specifier.exportKind !== 'type')\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportAllDeclaration(node) {\n\t\t\tif (node.exportKind !== 'type') imports.push(node.source.value)\n\t\t},\n\t\tImportExpression(node) {\n\t\t\tif (node.source.type === 'Literal' && String(node.source.value) === node.source.value)\n\t\t\t\timports.push(String(node.source.value))\n\t\t},\n\t}).visit(program)\n\treturn imports\n}\n\nfunction moduleOwner(file: string) {\n\tconst parts = file.split('/')\n\treturn parts[0] === 'domain' && parts.length >= 3 && parts[1] !== '__tests__'\n\t\t? `domain/${parts[1]}`\n\t\t: null\n}\n\nfunction cycles(graph: Map<string, Set<string>>) {\n\tconst completed = new Set<string>()\n\tconst stack: string[] = []\n\tconst found: string[][] = []\n\tfunction visit(owner: string) {\n\t\tconst index = stack.indexOf(owner)\n\t\tif (index >= 0) {\n\t\t\tfound.push([...stack.slice(index), owner])\n\t\t\treturn\n\t\t}\n\t\tif (completed.has(owner)) return\n\t\tstack.push(owner)\n\t\tfor (const dependency of graph.get(owner) ?? []) visit(dependency)\n\t\tstack.pop()\n\t\tcompleted.add(owner)\n\t}\n\tfor (const owner of graph.keys()) visit(owner)\n\treturn found\n}\n\nfunction sharedOwnership(dependencies: Map<string, Set<string>>): ArchitectureDiagnostic[] {\n\tconst consumers = new Map<string, Set<string>>()\n\tfor (const [file, targets] of dependencies) {\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tif (!owner || owner === 'domain/shared') continue\n\t\tconst visited = new Set<string>()\n\t\tfunction visit(target: string) {\n\t\t\tif (!target.startsWith('domain/shared/') || visited.has(target)) return\n\t\t\tvisited.add(target)\n\t\t\tconst owners = consumers.get(target) ?? new Set<string>()\n\t\t\towners.add(owner)\n\t\t\tconsumers.set(target, owners)\n\t\t\tfor (const next of dependencies.get(target) ?? []) visit(next)\n\t\t}\n\t\tfor (const target of targets) visit(target)\n\t}\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tfor (const [file, owners] of consumers) {\n\t\tif (owners.size === 1)\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'shared-owner',\n\t\t\t\tfile,\n\t\t\t\tmessage: `This shared implementation is used only by ${[...owners][0]}. Move it into that module until another module needs it.`,\n\t\t\t})\n\t}\n\treturn diagnostics\n}\n"],"mappings":"yVA8BA,SAAgBA,EAAoB,EAA+B,CAAC,EAA6B,CAChG,IAAMC,EAAgBC,EAAQC,EAAQ,KAAO,QAAQ,IAAI,EAAGA,EAAQ,WAAa,QAAQ,EACnFC,EAAOC,EAAWJ,CAAa,EAAIK,EAAaL,CAAa,EAAIA,EACjEM,EAAwC,CAAC,EAC/C,GAAI,CAACF,EAAWD,CAAI,EACnB,MAAO,CACN,CAAE,KA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C,EAC/C,IAAK,GAAM,CAACM,EAAMD,KAAWuF,EACxBvF,EAAO,OAAS,GACnBL,EAAY,KAAK,CAChB,KAAM,eACN,OACA,QAAS,8CAA8C,CAAC,GAAGK,CAAM,CAAC,CAAC,GAAG,0DACvE,CAAC,EAEH,OAAOL,CACR"}
|
package/dist/oxlint/ast.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ import { Context, ESTree, RuleMeta, Visitor } from "@oxlint/plugins";
|
|
|
3
3
|
//#region src/oxlint/ast.d.ts
|
|
4
4
|
export declare const consumerOptions: z.ZodObject<{
|
|
5
5
|
convexDir: z.ZodDefault<z.ZodString>;
|
|
6
|
+
componentDirs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
7
|
+
domainPublicFiles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
6
8
|
}, z.core.$strip>;
|
|
7
9
|
export declare function appFile(context: Context, filename?: string): string | null;
|
|
8
10
|
export declare function imported(context: Context, node: ESTree.Node, active?: Set<ESTree.Node>): {
|
package/dist/oxlint/ast.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createResolver as e,resolveImport as t}from"./architecture.mjs";import{z as n}from"zod";import{dirname as r,relative as i,resolve as a,sep as o}from"node:path";import{existsSync as s,readFileSync as c,realpathSync as l}from"node:fs";import{parseSync as u}from"oxc-parser";const d=n.object({convexDir:n.string().min(1).default(`convex`)});function f(e,t=e.filename){let n=a(e.cwd,d.parse(e.options[0]??{}).convexDir),r=s(n)?l(n):n,c=i(r,s(t)?l(t):t).split(o).join(`/`);return c===`..`||c.startsWith(`../`)||c.startsWith(`/`)?null:c}function p(e,t,n=/* @__PURE__ */ new Set){if(n.has(t)||n.size>32)return null;if(n=new Set(n).add(t),t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSNonNullExpression`)return p(e,t.expression,n);if(t.type===`CallExpression`)return p(e,t.callee,n);if(t.type===`MemberExpression`){let r=p(e,t.object,n),i=N(t);return r&&i&&[`*`,`z`,`v`,`default`].includes(r.name)?{source:r.source,name:i}:null}if(t.type!==`Identifier`)return null;let r=m(e,t);if(r&&r.type!==`CallExpression`&&r.type!==`AwaitExpression`)return p(e,r,n);let i=h(e,t);if(i){let t=p(e,i.expression,n);return t&&[`*`,`z`,`v`,`default`].includes(t.name)?{source:t.source,name:i.name}:null}for(let n of P(e,t)?.defs??[]){if(n.type!==`ImportBinding`||n.parent?.type!==`ImportDeclaration`||n.parent.importKind===`type`)continue;let e=n.node;if(e.type!==`ImportSpecifier`||e.importKind!==`type`)return{source:n.parent.source.value,name:e.type===`ImportSpecifier`?I(e.imported)??``:e.type===`ImportDefaultSpecifier`?`default`:`*`}}return null}function m(e,t){let n=P(e,t);if(!n||n.references.some(e=>e.isWrite()&&!e.init))return null;let r=n.defs.length===1?n.defs[0]:null;return r?.type===`Variable`&&r.parent?.type===`VariableDeclaration`&&r.parent.kind===`const`&&r.node.type===`VariableDeclarator`&&r.node.id.type===`Identifier`?r.node.init:null}function h(e,t){let n=P(e,t);if(!n||n.references.some(e=>e.isWrite()&&!e.init))return null;let r=n.defs.length===1?n.defs[0]:null;if(r?.type!==`Variable`||r.parent?.type!==`VariableDeclaration`||r.parent.kind!==`const`||r.node.type!==`VariableDeclarator`||r.node.id.type!==`ObjectPattern`||!r.node.init)return null;for(let e of r.node.id.properties)if(e.type===`Property`&&e.value.type===`Identifier`&&e.value.name===n.name){let t=e.computed?M(e.key):I(e.key);if(t)return{expression:r.node.init,name:t}}return null}const g=[`query`,`internalQuery`,`mutation`,`internalMutation`],_=/* @__PURE__ */ new WeakMap;function v(e,t){let n=B(e).nodes;if(n.has(t))return n.get(t)??null;n.set(t,null);let r=[{node:t,evaluation:V(e,t)}],i=null;for(;r.length;){let t=r[r.length-1],a=t.evaluation.next(i);a.done?(i=a.value,n.set(t.node,i),r.pop()):n.has(a.value)?i=n.get(a.value)??null:(n.set(a.value,null),r.push({node:a.value,evaluation:V(e,a.value)}),i=null)}return i}function y(e,t){function n(e,n){let r=M(n);r&&t(e,r)}return{ImportDeclaration(e){n(e,e.source)},ExportNamedDeclaration(e){n(e,e.source)},ExportAllDeclaration(e){n(e,e.source)},ImportExpression(e){n(e,e.source)},TSImportType(e){n(e,e.source)},CallExpression(t){t.callee.type===`Identifier`&&t.callee.name===`require`&&!P(e,t.callee)?.defs.length&&n(t,t.arguments[0])}}}function b(n,i){let o=i.startsWith(`.`)?a(r(n.filename),i):t(e(),n.filename,i);return o!==null&&f(n,o)?.replace(/\.[cm]?[jt]s$/,``)===`functions`}function x(e){return e.type===`TSImportType`||e.type===`ImportDeclaration`&&(e.importKind===`type`||e.specifiers.length>0&&e.specifiers.every(e=>e.type===`ImportSpecifier`&&e.importKind===`type`))||(e.type===`ExportNamedDeclaration`||e.type===`ExportAllDeclaration`)&&e.exportKind===`type`}function S(e){return e.callee.type===`MemberExpression`&&e.callee.object.type===`MemberExpression`&&N(e.callee.object)===`db`}function C(e,t){let n=p(e,t.callee);return n&&/^(?:node:)?(?:https?|net|tls|fs)(?:\/|$)|^(?:undici|axios)(?:\/|$)/.test(n.source)?!0:t.callee.type===`Identifier`&&t.callee.name===`fetch`&&!P(e,t.callee)?.defs.length||t.callee.type===`MemberExpression`&&N(t.callee)===`fetch`&&t.callee.object.type===`Identifier`&&t.callee.object.name===`globalThis`&&!P(e,t.callee.object)?.defs.length}function w(e,t){if(t.type===`MemberExpression`){let n=p(e,t.object);return n?.name===`components`&&/_generated\/api/.test(n.source)?!0:w(e,t.object)}return t.type===`ObjectExpression`&&t.properties.some(t=>t.type===`Property`&&w(e,t.value))}function T(e){return e.type===`MemberExpression`?T(e.object):e}function E(e){return e.type===`Identifier`?[e.name]:e.type===`MemberExpression`?[...E(e.object),N(e)??``]:[]}function D(e){return e.type===`MemberExpression`?N(e)===`table`||D(e.object):e.type===`CallExpression`&&D(e.callee)}function O(e){return e.callee.type===`MemberExpression`&&[`insert`,`patch`,`replace`,`delete`].includes(N(e.callee)??``)&&e.callee.object.type===`MemberExpression`&&N(e.callee.object)===`db`}function k(e,t){return e.type===`CallExpression`?e.callee.type===`MemberExpression`&&N(e.callee)===t&&(t!==`query`||N(e.callee.object)===`db`)||k(e.callee,t):e.type===`MemberExpression`&&k(e.object,t)}function A(e,t){return{type:`problem`,docs:{description:e},schema:[],messages:t}}function j(e,t){let n=a(e.cwd,d.parse(e.options[0]??{}).convexDir),r=s(n)?l(n):n,c=i(r,s(t)?l(t):t).split(o).join(`/`).match(/^components\/([^/]+)(?:\/|$)/);return c?a(r,`components`,c[1]):null}function M(e){return e?.type===`Literal`&&`value`in e&&String(e.value)===e.value?String(e.value):e?.type===`TemplateLiteral`&&e.expressions.length===0?e.quasis[0].value.cooked:null}function N(e){return e.type===`MemberExpression`?e.computed?M(e.property):e.property.name:null}function P(e,t){if(t.type!==`Identifier`)return null;let n=e.sourceCode.getScope(t);for(;n;){let e=n.set.get(t.name);if(e)return e;n=n.upper}return null}function F(e){let t=/* @__PURE__ */ new Set;for(let n of e.body)if(n.type===`ExportNamedDeclaration`&&!n.source)for(let e of n.specifiers)t.add(I(e.local)??``);else n.type===`ExportDefaultDeclaration`&&n.declaration.type===`Identifier`&&t.add(n.declaration.name);return t}function I(e){return e.type===`Identifier`?e.name:M(e)}function L(e){return e.type===`CallExpression`?!0:e.type===`AwaitExpression`?L(e.argument):e.type===`BlockStatement`&&e.body.length>0&&e.body.every(e=>e.type===`ReturnStatement`&&e.argument!==null&&L(e.argument)||e.type===`ExpressionStatement`&&L(e.expression))}function R(e,n){let r=B(e),i=t(r.resolver,e.filename,n.source),a=i&&f(e,i);if(!i||!a||!/^(?:domain\/.+\/schema\.ts|querying\.ts|foundation\.ts)$/.test(a)||!s(i))return null;let o=`${i}:${n.name}`;if(r.imports.has(o))return r.imports.get(o)??null;let c=z(e,i,n.name);return r.imports.set(o,c),c}function z(e,t,n){let r=B(e),i=r.files.get(t);if(i||(i=u(t,c(t,`utf8`)),r.files.set(t,i)),i.errors.length)return null;let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map;for(let e of i.program.body){if(e.type===`ImportDeclaration`&&e.importKind!==`type`)for(let t of e.specifiers)t.type===`ImportSpecifier`&&t.importKind!==`type`&&a.set(t.local.name,{source:e.source.value,name:t.imported.type===`Identifier`?t.imported.name:``}),t.type===`ImportNamespaceSpecifier`&&a.set(t.local.name,{source:e.source.value,name:`*`});let t=e.type===`ExportNamedDeclaration`?e.declaration:e;if(t?.type===`VariableDeclaration`&&t.kind===`const`){for(let n of t.declarations)if(n.init){if(n.id.type===`ObjectPattern`)for(let t of n.id.properties){if(t.type!==`Property`||t.value.type!==`Identifier`)continue;let r=t.computed?G(t.key):t.key.type===`Identifier`?t.key.name:null;r&&(o.set(t.value.name,n.init),s.set(t.value.name,r),e.type===`ExportNamedDeclaration`&&l.set(t.value.name,t.value.name))}n.id.type===`Identifier`&&(o.set(n.id.name,n.init),e.type===`ExportNamedDeclaration`&&l.set(n.id.name,n.id.name))}}if(e.type===`ExportNamedDeclaration`&&!e.source&&e.exportKind!==`type`)for(let t of e.specifiers)t.exportKind!==`type`&&t.local.type===`Identifier`&&t.exported.type===`Identifier`&&l.set(t.exported.name,t.local.name)}let d=l.get(n);if(!d)return null;function f(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name)||t.size>16)return null;let n=a.get(e.name);if(n)return n;let r=o.get(e.name);return r?f(r,new Set(t).add(e.name)):null}if(e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`){let n=f(e.object,t);if(n?.name===`*`)return{source:n.source,name:e.property.name}}return null}function p(e,t=/* @__PURE__ */ new Set){if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return p(e.expression,t);if(e.type===`Identifier`){if(t.has(e.name)||t.size>16)return null;let n=o.get(e.name),r=n?p(n,new Set(t).add(e.name)):null;return s.has(e.name)?r===`foundation`&&s.get(e.name)===`Query`?`queryRegistry`:null:r}if(e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`)return p(e.object,t)===`foundation`&&e.property.name===`Query`?`queryRegistry`:null;if(e.type!==`CallExpression`&&e.type!==`NewExpression`)return null;let n=f(e.callee);return n&&U(n)?`foundation`:n&&[`cvx-kit`,`cvx-kit/zod-table`,`cvx-kit/tenancy`].includes(n.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(n.name)?`table`:n&&[`cvx-kit`,`cvx-kit/querying`].includes(n.source)&&n.name===`createQueryEngine`?`engine`:null}let m=o.get(d),h=m?p(m):null;return s.has(d)?h===`foundation`&&s.get(d)===`Query`?`queryRegistry`:null:h}function B(t){let n=_.get(t);return n||(n={nodes:/* @__PURE__ */ new Map,files:/* @__PURE__ */ new Map,imports:/* @__PURE__ */ new Map,resolver:e()},_.set(t,n)),n}function*V(e,t){if(t.type===`AwaitExpression`)return yield t.argument;if(t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSNonNullExpression`)return yield t.expression;if(t.type===`Identifier`){if(P(e,t)?.references.some(e=>e.isWrite()&&!e.init))return null;let n=m(e,t);if(n)return yield n;let r=h(e,t);if(r){let e=yield r.expression;if(e===`context`&&r.name===`db`)return`db`;if(e===`page`&&r.name===`page`)return`bounded`;if(e===`table`&&r.name===`publicDto`)return`dtoSchema`;if(e===`foundation`&&r.name===`Query`)return`queryRegistry`}let i=P(e,t)?.defs[0];if(i?.type===`Parameter`&&(i.node.type===`ArrowFunctionExpression`||i.node.type===`FunctionExpression`)){let t=i.node.parent;if(t?.type===`CallExpression`&&t.arguments[0]===i.node&&i.node.params[0]===i.name&&(t.callee.type===`Identifier`||t.callee.type===`MemberExpression`)){let n=p(e,t.callee);if(n&&H(n))return`context`}if(t?.type===`CallExpression`&&t.callee.type===`MemberExpression`){let e=yield t.callee.object,n=N(t.callee);if(n===`handler`&&e===`queryOperation`&&t.arguments[0]===i.node&&i.node.params[1]===i.name)return`context`;if(i.node.params[0]!==i.name)return null;if((n===`execute`||n===`paginate`)&&t.arguments[1]===i.node&&(e===`stream`||e===`relationship`))return`bounded`;if(n===`then`&&t.arguments[0]===i.node&&(e===`bounded`||e===`page`))return e}let n=i.node.parent,r=n?.type===`Property`?n.parent:null,a=r?.type===`ObjectExpression`?r.parent:null,o=a?.type===`CallExpression`?p(e,a.callee):null;if(n?.type===`Property`&&(n.computed?M(n.key):I(n.key))===`operations`&&a?.type===`CallExpression`&&a.arguments[0]===r&&(yield a.callee)===`queryRegistry`&&r?.type===`ObjectExpression`&&i.node.params[0]?.type===`ObjectPattern`&&i.node.params[0].properties.some(e=>e.type===`Property`&&e.value===i.name&&(e.computed?M(e.key):I(e.key))===`query`)&&W(e,r))return`queryOperation`;if(n?.type===`Property`&&(n.computed?M(n.key):I(n.key))===`handler`&&a?.type===`CallExpression`&&a.arguments[0]===r&&i.node.params[1]===i.name&&(yield a.callee)===`queryOperation`||n?.type===`Property`&&(n.computed?M(n.key):I(n.key))===`handler`&&i.node.params[0]===i.name&&o&&(a?.type===`CallExpression`&&a.arguments[0]===r&&(a.callee.type===`Identifier`||a.callee.type===`MemberExpression`)&&H(o)||b(e,o.source)&&/^(?:auth|role|admin|system)(?:Query|Mutation)$/.test(o.name)))return`context`}let a=p(e,t);return a&&[`zod`,`zod/v4`,`convex/values`].includes(a.source)&&[`z`,`v`,`*`,`default`].includes(a.name)?`validator`:a?R(e,a):null}if(t.type===`MemberExpression`){let n=p(e,t);if(n){let t=R(e,n);if(t)return t}let r=yield t.object,i=N(t);return r===`context`&&i===`db`?`db`:r===`foundation`&&i===`Query`?`queryRegistry`:r===`reader`?`stream`:r===`page`&&i===`page`?`bounded`:r===`table`&&[`publicDto`,`dto`].includes(i??``)?`dtoSchema`:r===`validator`?`validator`:null}if(t.type!==`CallExpression`&&t.type!==`NewExpression`)return null;let n=yield t.callee;if(n===`engine`)return`reader`;if(n===`include`&&t.arguments[0]&&(yield t.arguments[0])===`stream`)return`stream`;let r=p(e,t.callee);if(r&&U(r))return`foundation`;if(r&&[`cvx-kit`,`cvx-kit/zod-table`,`cvx-kit/tenancy`].includes(r.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(r.name))return`table`;if(r&&[`cvx-kit`,`cvx-kit/querying`].includes(r.source)&&r.name===`createQueryEngine`)return`engine`;if(r&&[`cvx-kit`,`cvx-kit/auth`].includes(r.source)&&r.name===`createInclude`)return`include`;if(r?.source===`convex-helpers/server/stream`&&r.name===`stream`&&t.arguments[0]&&(yield t.arguments[0])===`db`)return`db`;if(t.callee.type!==`MemberExpression`)return null;let i=yield t.callee.object,a=N(t.callee);if(i===`table`&&a===`toPublicDto`)return`dto`;if(i===`table`&&[`select`,`dto`].includes(a??``))return`dtoSchema`;if(i===`dtoSchema`&&[`parse`,`parseAsync`].includes(a??``))return`dto`;if(i===`db`&&a===`query`)return`stream`;if(i===`stream`&&a===`relation`)return`relationship`;if(i===`context`&&a===`include`&&t.arguments[0]&&(yield t.arguments[0])===`stream`)return`stream`;if(i===`stream`||i===`relationship`){if([`take`,`execute`].includes(a??``))return`bounded`;if(a===`paginate`)return`page`;if([`withIndex`,`withSearchIndex`,`filter`,`filterWith`,`map`,`flatMap`,`distinct`,`order`,`matching`,`when`,`otherwise`,`fullTableScan`,`where`,`with`].includes(a??``))return i}return i===`bounded`&&a===`map`?`bounded`:i===`validator`?`validator`:null}function H(e){return/_generated\/server(?:\.[cm]?[jt]s)?$/.test(e.source)&&g.includes(e.name)||e.source===`convex/server`&&g.some(t=>e.name===`${t}Generic`)}function U(e){return e.source===`cvx-kit`&&e.name===`createFoundation`||e.source===`cvx-kit/effect`&&e.name===`createEffectFoundation`||[`cvx-kit`,`cvx-kit/components/foundation`].includes(e.source)&&e.name===`Foundation`}function W(e,t){let n=t.properties.find(e=>e.type===`Property`&&(e.computed?M(e.key):I(e.key))===`context`);if(n?.type!==`Property`)return!1;let r=n.value;if(r.type!==`ArrowFunctionExpression`&&r.type!==`FunctionExpression`)return!1;let i=r.params[0];if(i?.type!==`Identifier`||P(e,i)?.references.some(e=>e.isWrite()&&!e.init))return!1;let a=r.body,o=a?.type===`BlockStatement`&&a.body.length===1&&a.body[0].type===`ReturnStatement`?a.body[0].argument:a;return o?.type===`Identifier`&&P(e,o)===P(e,i)}function G(e){return e.type===`Literal`&&String(e.value)===e.value?String(e.value):e.type===`TemplateLiteral`&&e.expressions.length===0?e.quasis[0].value.cooked:null}export{f as appFile,P as binding,j as componentRoot,d as consumerOptions,w as containsComponentReference,L as delegatingBody,I as exportName,F as exportedNames,k as hasCall,p as imported,S as isDbAccess,O as isDbWrite,C as isExternalCall,b as isFunctionsImport,D as isTableChain,h as localDestructured,m as localInitializer,E as memberPath,A as metadata,N as propertyName,v as readProvenance,T as rootMember,y as sourceVisitors,M as staticString,x as typeOnlySource};
|
|
1
|
+
import{conventionalComponentRoot as e,findComponentRoot as t}from"./components.mjs";import{createResolver as n,resolveImport as r}from"./architecture.mjs";import{z as i}from"zod";import{dirname as a,relative as o,resolve as s,sep as c}from"node:path";import{existsSync as l,readFileSync as u,realpathSync as d}from"node:fs";import{parseSync as f}from"oxc-parser";const p=i.object({convexDir:i.string().min(1).default(`convex`),componentDirs:i.array(i.string().min(1)).default([]),domainPublicFiles:i.record(i.string(),i.array(i.string().min(1))).default({})});function m(e,t=e.filename){let n=s(e.cwd,p.parse(e.options[0]??{}).convexDir),r=l(n)?d(n):n,i=o(r,l(t)?d(t):t).split(c).join(`/`);return i===`..`||i.startsWith(`../`)||i.startsWith(`/`)?null:i}function h(e,t,n=/* @__PURE__ */ new Set){if(n.has(t)||n.size>32)return null;if(n=new Set(n).add(t),t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSNonNullExpression`)return h(e,t.expression,n);if(t.type===`CallExpression`)return h(e,t.callee,n);if(t.type===`MemberExpression`){let r=h(e,t.object,n),i=I(t);return r&&i&&[`*`,`z`,`v`,`default`].includes(r.name)?{source:r.source,name:i}:null}if(t.type!==`Identifier`)return null;let r=g(e,t);if(r&&r.type!==`CallExpression`&&r.type!==`AwaitExpression`)return h(e,r,n);let i=_(e,t);if(i){let t=h(e,i.expression,n);return t&&[`*`,`z`,`v`,`default`].includes(t.name)?{source:t.source,name:i.name}:null}for(let n of L(e,t)?.defs??[]){if(n.type!==`ImportBinding`||n.parent?.type!==`ImportDeclaration`||n.parent.importKind===`type`)continue;let e=n.node;if(e.type!==`ImportSpecifier`||e.importKind!==`type`)return{source:n.parent.source.value,name:e.type===`ImportSpecifier`?z(e.imported)??``:e.type===`ImportDefaultSpecifier`?`default`:`*`}}return null}function g(e,t){let n=L(e,t);if(!n||n.references.some(e=>e.isWrite()&&!e.init))return null;let r=n.defs.length===1?n.defs[0]:null;return r?.type===`Variable`&&r.parent?.type===`VariableDeclaration`&&r.parent.kind===`const`&&r.node.type===`VariableDeclarator`&&r.node.id.type===`Identifier`?r.node.init:null}function _(e,t){let n=L(e,t);if(!n||n.references.some(e=>e.isWrite()&&!e.init))return null;let r=n.defs.length===1?n.defs[0]:null;if(r?.type!==`Variable`||r.parent?.type!==`VariableDeclaration`||r.parent.kind!==`const`||r.node.type!==`VariableDeclarator`||r.node.id.type!==`ObjectPattern`||!r.node.init)return null;for(let e of r.node.id.properties)if(e.type===`Property`&&e.value.type===`Identifier`&&e.value.name===n.name){let t=e.computed?F(e.key):z(e.key);if(t)return{expression:r.node.init,name:t}}return null}const v=[`query`,`internalQuery`,`mutation`,`internalMutation`],y=/* @__PURE__ */ new WeakMap;function b(e,t){let n=U(e).nodes;if(n.has(t))return n.get(t)??null;n.set(t,null);let r=[{node:t,evaluation:W(e,t)}],i=null;for(;r.length;){let t=r[r.length-1],a=t.evaluation.next(i);a.done?(i=a.value,n.set(t.node,i),r.pop()):n.has(a.value)?i=n.get(a.value)??null:(n.set(a.value,null),r.push({node:a.value,evaluation:W(e,a.value)}),i=null)}return i}function x(e,t){function n(e,n){let r=F(n);r&&t(e,r)}return{ImportDeclaration(e){n(e,e.source)},ExportNamedDeclaration(e){n(e,e.source)},ExportAllDeclaration(e){n(e,e.source)},ImportExpression(e){n(e,e.source)},TSImportType(e){n(e,e.source)},CallExpression(t){t.callee.type===`Identifier`&&t.callee.name===`require`&&!L(e,t.callee)?.defs.length&&n(t,t.arguments[0])}}}function S(e,t){let i=t.startsWith(`.`)?s(a(e.filename),t):r(n(),e.filename,t);if(!i)return!1;let l=P(e,e.filename);return(l?o(l,i).split(c).join(`/`):m(e,i))?.replace(/\.[cm]?[jt]s$/,``)===`functions`}function C(e){return e.type===`TSImportType`||e.type===`ImportDeclaration`&&(e.importKind===`type`||e.specifiers.length>0&&e.specifiers.every(e=>e.type===`ImportSpecifier`&&e.importKind===`type`))||(e.type===`ExportNamedDeclaration`||e.type===`ExportAllDeclaration`)&&e.exportKind===`type`}function w(e){return e.callee.type===`MemberExpression`&&e.callee.object.type===`MemberExpression`&&I(e.callee.object)===`db`}function T(e,t){let n=h(e,t.callee);return n&&/^(?:node:)?(?:https?|net|tls|fs)(?:\/|$)|^(?:undici|axios)(?:\/|$)/.test(n.source)?!0:t.callee.type===`Identifier`&&t.callee.name===`fetch`&&!L(e,t.callee)?.defs.length||t.callee.type===`MemberExpression`&&I(t.callee)===`fetch`&&t.callee.object.type===`Identifier`&&t.callee.object.name===`globalThis`&&!L(e,t.callee.object)?.defs.length}function E(e,t){if(t.type===`MemberExpression`){let n=h(e,t.object);return n?.name===`components`&&/_generated\/api/.test(n.source)?!0:E(e,t.object)}return t.type===`ObjectExpression`&&t.properties.some(t=>t.type===`Property`&&E(e,t.value))}function D(e){return e.type===`MemberExpression`?D(e.object):e}function O(e){return e.type===`Identifier`?[e.name]:e.type===`MemberExpression`?[...O(e.object),I(e)??``]:[]}function k(e){return e.type===`MemberExpression`?I(e)===`table`||k(e.object):e.type===`CallExpression`&&k(e.callee)}function A(e){return e.callee.type===`MemberExpression`&&[`insert`,`patch`,`replace`,`delete`].includes(I(e.callee)??``)&&e.callee.object.type===`MemberExpression`&&I(e.callee.object)===`db`}function j(e,t){return e.type===`CallExpression`?e.callee.type===`MemberExpression`&&I(e.callee)===t&&(t!==`query`||I(e.callee.object)===`db`)||j(e.callee,t):e.type===`MemberExpression`&&j(e.object,t)}function M(e,t){return{type:`problem`,docs:{description:e},schema:[],messages:t}}const N=/* @__PURE__ */ new WeakMap;function P(n,r){let i=N.get(n);if(i||(i=/* @__PURE__ */ new Map,N.set(n,i)),i.has(r))return i.get(r)??null;let a=s(n.cwd,p.parse(n.options[0]??{}).convexDir),o=l(a)?d(a):a,c=l(r)?d(r):s(r),u=p.parse(n.options[0]??{}).componentDirs.map(e=>s(o,e)),f=t(c,u)??e(c,o);return i.set(r,f),f}function F(e){return e?.type===`Literal`&&`value`in e&&String(e.value)===e.value?String(e.value):e?.type===`TemplateLiteral`&&e.expressions.length===0?e.quasis[0].value.cooked:null}function I(e){return e.type===`MemberExpression`?e.computed?F(e.property):e.property.name:null}function L(e,t){if(t.type!==`Identifier`)return null;let n=e.sourceCode.getScope(t);for(;n;){let e=n.set.get(t.name);if(e)return e;n=n.upper}return null}function R(e){let t=/* @__PURE__ */ new Set;for(let n of e.body)if(n.type===`ExportNamedDeclaration`&&!n.source)for(let e of n.specifiers)t.add(z(e.local)??``);else n.type===`ExportDefaultDeclaration`&&n.declaration.type===`Identifier`&&t.add(n.declaration.name);return t}function z(e){return e.type===`Identifier`?e.name:F(e)}function B(e){return e.type===`CallExpression`?!0:e.type===`AwaitExpression`?B(e.argument):e.type===`BlockStatement`&&e.body.length>0&&e.body.every(e=>e.type===`ReturnStatement`&&e.argument!==null&&B(e.argument)||e.type===`ExpressionStatement`&&B(e.expression))}function V(e,t){let n=U(e),i=r(n.resolver,e.filename,t.source),a=i&&m(e,i);if(!i||!a||!/^(?:domain\/.+\/schema\.ts|querying\.ts|foundation\.ts)$/.test(a)&&!(P(e,i)&&/(?:^|\/)(?:schema|table|foundation)\.ts$/.test(a))||!l(i))return null;let o=`${i}:${t.name}`;if(n.imports.has(o))return n.imports.get(o)??null;let s=H(e,i,t.name);return n.imports.set(o,s),s}function H(e,t,n){let r=U(e),i=r.files.get(t);if(i||(i=f(t,u(t,`utf8`)),r.files.set(t,i)),i.errors.length)return null;let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;for(let e of i.program.body){if(e.type===`ImportDeclaration`&&e.importKind!==`type`)for(let t of e.specifiers)t.type===`ImportSpecifier`&&t.importKind!==`type`&&a.set(t.local.name,{source:e.source.value,name:t.imported.type===`Identifier`?t.imported.name:``}),t.type===`ImportNamespaceSpecifier`&&a.set(t.local.name,{source:e.source.value,name:`*`});let t=e.type===`ExportNamedDeclaration`?e.declaration:e;if(t?.type===`VariableDeclaration`&&t.kind===`const`){for(let n of t.declarations)if(n.init){if(n.id.type===`ObjectPattern`)for(let t of n.id.properties){if(t.type!==`Property`||t.value.type!==`Identifier`)continue;let r=t.computed?J(t.key):t.key.type===`Identifier`?t.key.name:null;r&&(o.set(t.value.name,n.init),s.set(t.value.name,r),e.type===`ExportNamedDeclaration`&&c.set(t.value.name,t.value.name))}n.id.type===`Identifier`&&(o.set(n.id.name,n.init),e.type===`ExportNamedDeclaration`&&c.set(n.id.name,n.id.name))}}if(e.type===`ExportNamedDeclaration`&&!e.source&&e.exportKind!==`type`)for(let t of e.specifiers)t.exportKind!==`type`&&t.local.type===`Identifier`&&t.exported.type===`Identifier`&&c.set(t.exported.name,t.local.name)}let l=c.get(n);if(!l)return null;function d(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name)||t.size>16)return null;let n=a.get(e.name);if(n)return n;let r=o.get(e.name);return r?d(r,new Set(t).add(e.name)):null}if(e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`){let n=d(e.object,t);if(n?.name===`*`)return{source:n.source,name:e.property.name}}return null}function p(e,t=/* @__PURE__ */ new Set){if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return p(e.expression,t);if(e.type===`Identifier`){if(t.has(e.name)||t.size>16)return null;let n=o.get(e.name),r=n?p(n,new Set(t).add(e.name)):null;return s.has(e.name)?r===`foundation`&&s.get(e.name)===`Query`?`queryRegistry`:null:r}if(e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`)return p(e.object,t)===`foundation`&&e.property.name===`Query`?`queryRegistry`:null;if(e.type!==`CallExpression`&&e.type!==`NewExpression`)return null;let n=d(e.callee);return n&&K(n)?`foundation`:n&&[`cvx-kit`,`cvx-kit/zod-table`,`cvx-kit/tenancy`].includes(n.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(n.name)?`table`:n&&[`cvx-kit`,`cvx-kit/querying`].includes(n.source)&&n.name===`createQueryEngine`?`engine`:null}let m=o.get(l),h=m?p(m):null;return s.has(l)?h===`foundation`&&s.get(l)===`Query`?`queryRegistry`:null:h}function U(e){let t=y.get(e);return t||(t={nodes:/* @__PURE__ */ new Map,files:/* @__PURE__ */ new Map,imports:/* @__PURE__ */ new Map,resolver:n()},y.set(e,t)),t}function*W(e,t){if(t.type===`AwaitExpression`)return yield t.argument;if(t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSNonNullExpression`)return yield t.expression;if(t.type===`Identifier`){if(L(e,t)?.references.some(e=>e.isWrite()&&!e.init))return null;let n=g(e,t);if(n)return yield n;let r=_(e,t);if(r){let e=yield r.expression;if(e===`context`&&r.name===`db`)return`db`;if(e===`page`&&r.name===`page`)return`bounded`;if(e===`table`&&r.name===`publicDto`)return`dtoSchema`;if(e===`foundation`&&r.name===`Query`)return`queryRegistry`}let i=L(e,t)?.defs[0];if(i?.type===`Parameter`&&(i.node.type===`ArrowFunctionExpression`||i.node.type===`FunctionExpression`)){let t=i.node.parent;if(t?.type===`CallExpression`&&t.arguments[0]===i.node&&i.node.params[0]===i.name&&(t.callee.type===`Identifier`||t.callee.type===`MemberExpression`)){let n=h(e,t.callee);if(n&&G(n))return`context`}if(t?.type===`CallExpression`&&t.callee.type===`MemberExpression`){let e=yield t.callee.object,n=I(t.callee);if(n===`handler`&&e===`queryOperation`&&t.arguments[0]===i.node&&i.node.params[1]===i.name)return`context`;if(i.node.params[0]!==i.name)return null;if((n===`execute`||n===`paginate`)&&t.arguments[1]===i.node&&(e===`stream`||e===`relationship`))return`bounded`;if(n===`then`&&t.arguments[0]===i.node&&(e===`bounded`||e===`page`))return e}let n=i.node.parent,r=n?.type===`Property`?n.parent:null,a=r?.type===`ObjectExpression`?r.parent:null,o=a?.type===`CallExpression`?h(e,a.callee):null;if(n?.type===`Property`&&(n.computed?F(n.key):z(n.key))===`operations`&&a?.type===`CallExpression`&&a.arguments[0]===r&&(yield a.callee)===`queryRegistry`&&r?.type===`ObjectExpression`&&i.node.params[0]?.type===`ObjectPattern`&&i.node.params[0].properties.some(e=>e.type===`Property`&&e.value===i.name&&(e.computed?F(e.key):z(e.key))===`query`)&&q(e,r))return`queryOperation`;if(n?.type===`Property`&&(n.computed?F(n.key):z(n.key))===`handler`&&a?.type===`CallExpression`&&a.arguments[0]===r&&i.node.params[1]===i.name&&(yield a.callee)===`queryOperation`||n?.type===`Property`&&(n.computed?F(n.key):z(n.key))===`handler`&&i.node.params[0]===i.name&&o&&(a?.type===`CallExpression`&&a.arguments[0]===r&&(a.callee.type===`Identifier`||a.callee.type===`MemberExpression`)&&G(o)||S(e,o.source)&&/^(?:auth|role|admin|system)(?:Query|Mutation)$/.test(o.name)))return`context`}let a=h(e,t);return a&&[`zod`,`zod/v4`,`convex/values`].includes(a.source)&&[`z`,`v`,`*`,`default`].includes(a.name)?`validator`:a?V(e,a):null}if(t.type===`MemberExpression`){let n=h(e,t);if(n){let t=V(e,n);if(t)return t}let r=yield t.object,i=I(t);return r===`context`&&i===`db`?`db`:r===`foundation`&&i===`Query`?`queryRegistry`:r===`reader`?`stream`:r===`page`&&i===`page`?`bounded`:r===`table`&&[`publicDto`,`dto`].includes(i??``)?`dtoSchema`:r===`validator`?`validator`:null}if(t.type!==`CallExpression`&&t.type!==`NewExpression`)return null;let n=yield t.callee;if(n===`engine`)return`reader`;if(n===`include`&&t.arguments[0]&&(yield t.arguments[0])===`stream`)return`stream`;let r=h(e,t.callee);if(r&&K(r))return`foundation`;if(r&&[`cvx-kit`,`cvx-kit/zod-table`,`cvx-kit/tenancy`].includes(r.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(r.name))return`table`;if(r&&[`cvx-kit`,`cvx-kit/querying`].includes(r.source)&&r.name===`createQueryEngine`)return`engine`;if(r&&[`cvx-kit`,`cvx-kit/auth`].includes(r.source)&&r.name===`createInclude`)return`include`;if(r?.source===`convex-helpers/server/stream`&&r.name===`stream`&&t.arguments[0]&&(yield t.arguments[0])===`db`)return`db`;if(t.callee.type!==`MemberExpression`)return null;let i=yield t.callee.object,a=I(t.callee);if(i===`table`&&a===`toPublicDto`)return`dto`;if(i===`table`&&[`select`,`dto`].includes(a??``))return`dtoSchema`;if(i===`dtoSchema`&&[`parse`,`parseAsync`].includes(a??``))return`dto`;if(i===`db`&&a===`query`)return`stream`;if(i===`stream`&&a===`relation`)return`relationship`;if(i===`context`&&a===`include`&&t.arguments[0]&&(yield t.arguments[0])===`stream`)return`stream`;if(i===`stream`||i===`relationship`){if([`take`,`execute`].includes(a??``))return`bounded`;if(a===`paginate`)return`page`;if([`withIndex`,`withSearchIndex`,`filter`,`filterWith`,`map`,`flatMap`,`distinct`,`order`,`matching`,`when`,`otherwise`,`fullTableScan`,`where`,`with`].includes(a??``))return i}return i===`bounded`&&a===`map`?`bounded`:i===`validator`?`validator`:null}function G(e){return/_generated\/server(?:\.[cm]?[jt]s)?$/.test(e.source)&&v.includes(e.name)||e.source===`convex/server`&&v.some(t=>e.name===`${t}Generic`)}function K(e){return e.source===`cvx-kit`&&e.name===`createFoundation`||e.source===`cvx-kit/effect`&&e.name===`createEffectFoundation`||[`cvx-kit`,`cvx-kit/components/foundation`].includes(e.source)&&e.name===`Foundation`}function q(e,t){let n=t.properties.find(e=>e.type===`Property`&&(e.computed?F(e.key):z(e.key))===`context`);if(n?.type!==`Property`)return!1;let r=n.value;if(r.type!==`ArrowFunctionExpression`&&r.type!==`FunctionExpression`)return!1;let i=r.params[0];if(i?.type!==`Identifier`||L(e,i)?.references.some(e=>e.isWrite()&&!e.init))return!1;let a=r.body,o=a?.type===`BlockStatement`&&a.body.length===1&&a.body[0].type===`ReturnStatement`?a.body[0].argument:a;return o?.type===`Identifier`&&L(e,o)===L(e,i)}function J(e){return e.type===`Literal`&&String(e.value)===e.value?String(e.value):e.type===`TemplateLiteral`&&e.expressions.length===0?e.quasis[0].value.cooked:null}export{m as appFile,L as binding,P as componentRoot,p as consumerOptions,E as containsComponentReference,B as delegatingBody,z as exportName,R as exportedNames,j as hasCall,h as imported,w as isDbAccess,A as isDbWrite,T as isExternalCall,S as isFunctionsImport,k as isTableChain,_ as localDestructured,g as localInitializer,O as memberPath,M as metadata,I as propertyName,b as readProvenance,D as rootMember,x as sourceVisitors,F as staticString,C as typeOnlySource};
|
|
2
2
|
//# sourceMappingURL=ast.mjs.map
|