cvx-kit 0.1.24 → 0.1.26
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/README.md +26 -5
- package/dist/modules/contracts/domain.d.mts +1 -1
- package/dist/modules/contracts/domain.mjs +1 -1
- package/dist/modules/contracts/domain.mjs.map +1 -1
- package/dist/modules/contracts/lazy.d.mts +8 -0
- package/dist/modules/contracts/lazy.mjs +2 -0
- package/dist/modules/contracts/lazy.mjs.map +1 -0
- package/dist/modules/effect/command.mjs +1 -1
- package/dist/modules/effect/command.mjs.map +1 -1
- package/dist/modules/effect/query.mjs +1 -1
- package/dist/modules/effect/query.mjs.map +1 -1
- package/dist/oxlint/architecture.d.mts +2 -0
- package/dist/oxlint/architecture.mjs.map +1 -1
- package/dist/oxlint.mjs +1 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/querying/planner.d.mts +17 -0
- package/dist/querying/planner.mjs +1 -1
- package/dist/querying/planner.mjs.map +1 -1
- package/dist/querying/relationships.mjs +1 -1
- package/dist/querying/relationships.mjs.map +1 -1
- package/dist/querying/schema-snapshot.mjs.map +1 -1
- package/dist/querying/shared/filters.d.mts +7 -0
- package/dist/querying/shared/filters.mjs +1 -1
- package/dist/querying/shared/filters.mjs.map +1 -1
- package/dist/querying.mjs +1 -1
- package/dist/querying.mjs.map +1 -1
- package/dist/relations-public.d.mts +2 -2
- package/dist/relations-public.mjs +1 -1
- package/dist/relations.d.mts +8 -1
- package/dist/relations.mjs +1 -1
- package/dist/relations.mjs.map +1 -1
- package/dist/zod-table.mjs +1 -1
- package/dist/zod-table.mjs.map +1 -1
- package/package.json +1 -1
package/dist/oxlint.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createResolver as e,inspectArchitecture as t,narrowRootDeclaration as n,resolveImport as r}from"./oxlint/architecture.mjs";import{appFile as i,binding as a,componentRoot as o,exportName as s,exportedNames as c,imported as l,isDbWrite as u,isFunctionsImport as d,isTableChain as f,localInitializer as p,metadata as m,propertyName as h,readProvenance as g,sourceVisitors as _,staticString as v}from"./oxlint/ast.mjs";import{reservedDomainFiles as y}from"./oxlint/reserved-files.mjs";import{ownershipRules as b}from"./oxlint/ownership.mjs";import{basename as x,dirname as S,relative as C,sep as w}from"node:path";function T(e={}){return t(e)}const E=O({...b,"root-wiring-only":{...b[`root-wiring-only`],create(e){let t=i(e)??``;return[`relations.ts`,`querying.ts`].includes(t)?n(t,e.sourceCode.text)?{}:{Program(n){e.report({node:n,messageId:`ownership`,data:{reason:`${t} must export one kit factory declaration and contain only declarative configuration`}})}}:b[`root-wiring-only`].create(e)}},"reserved-domain-file-anatomy":y,"root-facade-ownership":{meta:m(`Configure shared kit infrastructure once in its root facade.`,{facade:`Configure {{name}} once in convex/{{file}}; import that facade elsewhere.`}),create(e){if(o(e,e.filename))return{};let t=/* @__PURE__ */ new Set;function n(n){let r=l(e,n.callee);if(!r)return;let a=null;[`cvx-kit`,`cvx-kit/querying`].includes(r.source)&&r.name===`createQueryEngine`&&(a=`querying.ts`),[`cvx-kit`,`cvx-kit/relations`].includes(r.source)&&r.name===`defineRelations`&&(a=`relations.ts`),[`cvx-kit`,`cvx-kit/auth`].includes(r.source)&&r.name===`createAuthFunctions`&&(a=`functions.ts`),[`cvx-kit`,`cvx-kit/triggers`].includes(r.source)&&r.name===`createTriggers`&&(a=`triggers.ts`),[`cvx-kit`,`cvx-kit/components/foundation`].includes(r.source)&&r.name===`Foundation`&&(a=`foundation.ts`),(r.source===`cvx-kit/effect`&&r.name===`createEffectFoundation`||r.source===`cvx-kit`&&r.name===`createFoundation`)&&(a=`foundation.ts`),a&&((i(e)!==a||t.has(r.name))&&e.report({node:n,messageId:`facade`,data:{name:r.name,file:a}}),t.add(r.name))}return{CallExpression:n,NewExpression:n}}},"no-raw-builders":{meta:m(`Build host functions through the auth-aware root constructors.`,{builder:`Import raw builders only in convex/functions.ts; use auth*/role*/admin* or system* elsewhere.`}),create(t){if(i(t)===`functions.ts`||o(t,t.filename))return{};let n=e();return{ImportDeclaration(e){if(e.importKind===`type`)return;let a=e.source.value,o=r(n,t.filename,a),c=o&&i(t,o)?.startsWith(`_generated/`)?i(t,o):a;if(/(?:^|\/)_generated\/server(?:\.[cm]?[jt]s)?$/.test(c)||c===`convex/server`)for(let n of e.specifiers){if(n.type===`ImportSpecifier`&&n.importKind===`type`)continue;let e=n.type===`ImportSpecifier`?s(n.imported):null;(e===null&&c!==`convex/server`||e&&/^(?:internal)?(?:Query|Mutation|Action)(?:Generic)?$|^(?:query|mutation|action)(?:Generic)?$/.test(e))&&t.report({node:n,messageId:`builder`})}},CallExpression(e){let n=l(t,e.callee);n?.source===`convex/server`&&/^(?:internal)?(?:Query|Mutation|Action)Generic$|^(?:query|mutation|action)Generic$/.test(n.name)&&e.callee.type===`MemberExpression`&&t.report({node:e,messageId:`builder`})}}}},"no-handwritten-references":{meta:m(`Use generated api/internal references.`,{reference:`Use generated api/internal references instead of makeFunctionReference.`}),create(e){return{CallExpression(t){let n=l(e,t.callee);n?.source===`convex/server`&&n.name===`makeFunctionReference`&&e.report({node:t,messageId:`reference`})}}}},"domain-import-boundaries":{meta:m(`Keep api, application, domain, and shared dependencies directed.`,{boundary:`Follow api → application/domain → shared; sibling modules expose only rules.ts and queries.ts.`}),create(t){let n=i(t),a=e();return _(t,(e,o)=>{if(!n)return;let s=r(a,t.filename,o);if(!s)return;let c=i(t,s)?.replace(/\.[cm]?[jt]s$/,``);if(!c){s.split(w).includes(`node_modules`)||t.report({node:e,messageId:`boundary`});return}let l=n.split(`/`),u=c.split(`/`),d=!1;l[0]===`domain`?(d=[`api`,`application`,`migrations`].includes(u[0]),u[0]===`domain`&&l[1]!==u[1]&&u[1]!==`shared`&&l[1]!==`table.ts`&&(d=l[1]===`shared`||![`rules`,`queries`,`contracts`].includes(u.slice(2).join(`/`)))):l[0]===`api`?d=[`api`,`migrations`].includes(u[0])||u[0]===`domain`&&u[1]!==`shared`&&u[1]!==(l.length>2?l[1]:x(n).replace(/\.[cm]?[jt]s$/,``)):l[0]===`application`?d=[`api`,`migrations`].includes(u[0]):[`relations.ts`,`querying.ts`].includes(n)&&u[0]===`domain`&&(d=!(n===`relations.ts`?[`schema`,`table`]:[`queries`,`contracts`]).includes(u.slice(2).join(`/`))&&(n!==`relations.ts`||c!==`domain/table`)),u[0]===`migrations`&&l[0]!==`migrations`&&(d=!0),[`api`,`domain`,`application`].includes(l[0])&&u.length>1&&![`api`,`domain`,`application`,`_generated`,`components`,`migrations`].includes(u[0])&&(d=!0),d&&t.report({node:e,messageId:`boundary`})})}},"public-functions-in-api":{meta:m(`Expose authenticated public functions only through api/.`,{public:`Declare public auth*/role*/admin* functions in convex/api/<module>.ts.`}),create(e){return i(e)?.startsWith(`api/`)?{}:{CallExpression(t){let n=l(e,t.callee);t.callee.type!==`CallExpression`&&n&&d(e,n.source)&&/^(auth|role|admin)(Query|Mutation|Action)$/.test(n.name)&&e.report({node:t,messageId:`public`})}}}},"thin-api-adapters":{meta:m(`Keep business decisions and writes in domain executors.`,{adapter:`Move business branches, private helpers, and database writes into the owning domain executor.`}),create(e){return i(e)?.startsWith(`api/`)?{IfStatement(t){e.report({node:t,messageId:`adapter`})},SwitchStatement(t){e.report({node:t,messageId:`adapter`})},ConditionalExpression(t){e.report({node:t,messageId:`adapter`})},Program(t){let n=c(t);for(let r of t.body)if(r.type===`FunctionDeclaration`&&r.id&&!n.has(r.id.name)&&e.report({node:r,messageId:`adapter`}),r.type===`VariableDeclaration`)for(let t of r.declarations)t.id.type===`Identifier`&&!n.has(t.id.name)&&[`ArrowFunctionExpression`,`FunctionExpression`].includes(t.init?.type??``)&&e.report({node:t,messageId:`adapter`})},CallExpression(t){u(t)&&e.report({node:t,messageId:`adapter`})}}:{}}},"no-inline-enums":{meta:m(`Keep vocabularies in named constants.ts tuples.`,{vocabulary:`Define a named readonly tuple in constants.ts and pass it to z.enum().`}),create(e){return{CallExpression(t){let n=l(e,t.callee),r=t.arguments[0];for(;r?.type===`TSAsExpression`||r?.type===`TSSatisfiesExpression`;)r=r.expression;n&&/^zod(?:\/v4)?$/.test(n.source)&&n.name===`enum`&&r?.type===`ArrayExpression`&&e.report({node:t,messageId:`vocabulary`})}}}},"no-unbounded-reads":{meta:m(`Bound collection reads through include or pagination.`,{bounded:`Use include(...).execute(limit) or bounded pagination; do not collect() or resolve() an unbounded query.`,order:`Apply eligibility filters in the indexed query before take(), execute(), or paginate(); filtering a bounded result can omit eligible rows. Do not move the predicate automatically.`}),create(e){return o(e,e.filename)?{}:{CallExpression(t){if(t.callee.type!==`MemberExpression`)return;let n=h(t.callee),r=g(e,t.callee.object);n===`filter`&&r===`bounded`&&e.report({node:t,messageId:`order`}),(n===`collect`&&(r===`stream`||r===`relationship`)||n===`resolve`&&r===`stream`)&&e.report({node:t,messageId:`bounded`})}}}},"no-manual-id-projection":{meta:m(`Use the table DTO boundary to project public IDs.`,{projection:`Use toPublicDto(row, true) to include _id; do not add IDs manually after a table DTO parse or projection.`}),create(e){return{ObjectExpression(t){if(t.properties.some(t=>t.type===`SpreadElement`&&g(e,t.argument)===`dto`))for(let n of t.properties)n.type===`Property`&&[`id`,`_id`].includes((n.computed?v(n.key):s(n.key))??``)&&e.report({node:n,messageId:`projection`})},AssignmentExpression(t){t.left.type===`MemberExpression`&&[`id`,`_id`].includes(h(t.left)??``)&&g(e,t.left.object)===`dto`&&e.report({node:t,messageId:`projection`})}}}},"no-copied-pagination":{meta:m(`Use native or table pagination schemas instead of copying their shape.`,{pagination:`Use the native paginationOptsValidator (or paginated(table.dto())) for native pagination, or table.paginationOpts(selection) for table queries; do not copy pagination fields.`}),create(e){return{CallExpression(t){let n=l(e,t.callee);if(!(n?.name===`object`&&[`zod`,`zod/v4`,`convex/values`].includes(n.source)))return;let r=t.arguments[0],i=r&&(p(e,r)??r);if(i?.type!==`ObjectExpression`)return;let a=new Set(i.properties.flatMap(e=>e.type===`Property`?[e.computed?v(e.key):s(e.key)]:[]));(a.has(`numItems`)&&a.has(`cursor`)||[`page`,`isDone`,`continueCursor`].every(e=>a.has(e)))&&e.report({node:t,messageId:`pagination`})}}}},"no-manual-timestamps":{meta:m(`Let timestamps triggers own createdAt and updatedAt.`,{timestamp:`Remove {{field}} from this write; register the timestamps trigger instead.`}),create(e){return o(e,e.filename)?{}:{CallExpression(t){if(!u(t))return;let n=t.arguments.at(-1);if(n?.type===`ObjectExpression`)for(let t of n.properties){if(t.type!==`Property`)continue;let n=t.computed?v(t.key):s(t.key);(n===`createdAt`||n===`updatedAt`)&&e.report({node:t,messageId:`timestamp`,data:{field:n}})}}}}},"component-boundaries":{meta:m(`Keep portable components isolated and consume their client facades.`,{boundary:`Components may import only their own files and npm dependencies; inject host policy through the client API.`,facade:`Import a component through its client.ts facade, not its private implementation.`}),create(t){let n=o(t,t.filename),a=e();return _(t,(e,s)=>{s.startsWith(`.`)||/^cvx-kit\/components\/[^/]+\//.test(s)&&!/^cvx-kit\/components\/[^/]+\/convex\.config(?:\.js)?$/.test(s)&&t.report({node:e,messageId:`facade`});let c=r(a,t.filename,s);c&&!c.split(w).includes(`node_modules`)&&(n&&(C(n,c).startsWith(`..${w}`)||c===S(n))?t.report({node:e,messageId:`boundary`}):!n&&o(t,c)&&!/^client(?:\.[cm]?[jt]s)?$/.test(x(c))&&!(i(t)===`convex.config.ts`&&/^convex\.config(?:\.[cm]?[jt]s)?$/.test(x(c)))&&t.report({node:e,messageId:`facade`}))})}},"no-component-env":{meta:m(`Pass environment configuration into portable components.`,{env:`Portable components must receive configuration through arguments; do not read process.env.`}),create(e){if(!o(e,e.filename))return{};function t(t){if(t.type!==`Identifier`)return!1;let n=a(e,t);return t.name===`process`&&!n?.defs.length||n?.defs.some(e=>e.type===`ImportBinding`&&e.parent?.type===`ImportDeclaration`&&[`node:process`,`process`].includes(e.parent.source.value)&&[`ImportDefaultSpecifier`,`ImportNamespaceSpecifier`].includes(e.node.type))}return{ImportDeclaration(t){if([`node:process`,`process`].includes(t.source.value))for(let n of t.specifiers)n.type===`ImportSpecifier`&&s(n.imported)===`env`&&e.report({node:n,messageId:`env`})},MemberExpression(n){if(h(n)!==`env`)return;let r=n.object,i=r.type===`MemberExpression`&&h(r)===`process`&&r.object.type===`Identifier`&&r.object.name===`globalThis`&&!a(e,r.object)?.defs.length;(t(r)||i)&&e.report({node:n,messageId:`env`})},VariableDeclarator(n){if(n.init&&t(n.init)&&n.id.type===`ObjectPattern`)for(let t of n.id.properties)t.type===`Property`&&(t.computed?v(t.key):s(t.key))===`env`&&e.report({node:t,messageId:`env`})}}}},"schema-file-boundaries":{meta:m(`Keep storage shapes and indexes in their documented owners.`,{schema:`{{builder}} belongs in {{file}}.`}),create(e){return{CallExpression(t){let n=l(e,t.callee),r=i(e);if(!r)return;let a=null;n?.source===`convex/server`&&(n.name===`defineSchema`&&r!==`schema.ts`&&!(o(e,e.filename)&&x(r)===`schema.ts`)&&(a=`the root schema.ts (or a component schema.ts)`),n.name===`defineTable`&&!(o(e,e.filename)&&[`schema.ts`,`table.ts`].includes(x(r)))&&(a=`a component schema.ts/table.ts; host tables use zodTable in domain/<module>/schema.ts`)),n&&[`cvx-kit`,`cvx-kit/zod-table`].includes(n.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(n.name)&&!/^domain\/[^/]+\/schema\.ts$/.test(r)&&(a=`domain/<module>/schema.ts`),a&&e.report({node:t,messageId:`schema`,data:{builder:n?.name??`table`,file:a}}),t.callee.type===`MemberExpression`&&[`index`,`searchIndex`,`vectorIndex`].includes(h(t.callee)??``)&&f(t.callee.object)&&!o(e,e.filename)&&!/^domain\/[^/]+\/table\.ts$/.test(r)&&e.report({node:t,messageId:`schema`,data:{builder:`Table indexes`,file:`domain/<module>/table.ts`}})}}}},"no-internal-reexports":{meta:m(`Import from owning modules directly; consumer apps have no barrels.`,{reexport:`Import from the owning file directly; do not re-export imports inside convex/.`}),create(e){function t(t){if(t.source){e.report({node:t,messageId:`reexport`});return}for(let n of t.type===`ExportNamedDeclaration`?t.specifiers:[])a(e,n.local)?.defs.some(e=>e.type===`ImportBinding`)&&e.report({node:n,messageId:`reexport`})}return{ExportNamedDeclaration:t,ExportAllDeclaration:t,ExportDefaultDeclaration(t){t.declaration.type===`Identifier`&&a(e,t.declaration)?.defs.some(e=>e.type===`ImportBinding`)&&e.report({node:t,messageId:`reexport`})}}}},"public-api-first":{meta:m(`Place private helper implementations after the exported API.`,{order:`Move this private helper below the exported API so the file reads from public purpose to implementation.`}),create(e){return{Program(t){let n=c(t),r=t.body.findLastIndex(e=>e.type.startsWith(`Export`));for(let i of t.body.slice(0,r<0?0:r))i.type===`FunctionDeclaration`&&i.id&&!n.has(i.id.name)&&e.report({node:i,messageId:`order`})}}}},"named-private-helpers":{meta:m(`Use named declarations for top-level private helper functions.`,{helper:`Declare this private helper with function name(...) at the bottom of the file.`}),create(e){return{Program(t){let n=c(t);for(let r of t.body)if(r.type===`VariableDeclaration`)for(let t of r.declarations)t.id.type===`Identifier`&&!n.has(t.id.name)&&(t.init?.type===`ArrowFunctionExpression`||t.init?.type===`FunctionExpression`)&&e.report({node:t,messageId:`helper`})}}}}}),D={meta:{name:`cvx`},rules:E};function O(e){let t={...e},n=Object.keys(e);for(let r of n){let n=e[r];t[r]={meta:{...n.meta,schema:[{type:`object`,properties:{convexDir:{type:`string`,minLength:1}},additionalProperties:!1}]},create(e){let t=i(e);return!t||/(?:^|\/)(?:_generated|__tests__)(?:\/|$)/.test(t)||/\.(?:test|spec)\.[cm]?[jt]s$/.test(t)?{}:n.create(e)}}}return t}export{T as checkArchitecture,D as default,E as rules};
|
|
1
|
+
import{forceRegistry as e}from"./modules/contracts/lazy.mjs";import{createResolver as t,inspectArchitecture as n,narrowRootDeclaration as r,resolveImport as i}from"./oxlint/architecture.mjs";import{appFile as a,binding as o,componentRoot as s,exportName as c,exportedNames as l,imported as u,isDbWrite as d,isFunctionsImport as f,isTableChain as p,localInitializer as m,metadata as h,propertyName as g,readProvenance as _,sourceVisitors as v,staticString as y}from"./oxlint/ast.mjs";import{reservedDomainFiles as b}from"./oxlint/reserved-files.mjs";import{ownershipRules as x}from"./oxlint/ownership.mjs";import{basename as S,dirname as C,relative as w,sep as T}from"node:path";function E(t={}){for(let n of t.registries??[])e(n);return n(t)}const D=k({...x,"root-wiring-only":{...x[`root-wiring-only`],create(e){let t=a(e)??``;return[`relations.ts`,`querying.ts`].includes(t)?r(t,e.sourceCode.text)?{}:{Program(n){e.report({node:n,messageId:`ownership`,data:{reason:`${t} must export one kit factory declaration and contain only declarative configuration`}})}}:x[`root-wiring-only`].create(e)}},"reserved-domain-file-anatomy":b,"root-facade-ownership":{meta:h(`Configure shared kit infrastructure once in its root facade.`,{facade:`Configure {{name}} once in convex/{{file}}; import that facade elsewhere.`}),create(e){if(s(e,e.filename))return{};let t=/* @__PURE__ */ new Set;function n(n){let r=u(e,n.callee);if(!r)return;let i=null;[`cvx-kit`,`cvx-kit/querying`].includes(r.source)&&r.name===`createQueryEngine`&&(i=`querying.ts`),[`cvx-kit`,`cvx-kit/relations`].includes(r.source)&&r.name===`defineRelations`&&(i=`relations.ts`),[`cvx-kit`,`cvx-kit/auth`].includes(r.source)&&r.name===`createAuthFunctions`&&(i=`functions.ts`),[`cvx-kit`,`cvx-kit/triggers`].includes(r.source)&&r.name===`createTriggers`&&(i=`triggers.ts`),[`cvx-kit`,`cvx-kit/components/foundation`].includes(r.source)&&r.name===`Foundation`&&(i=`foundation.ts`),(r.source===`cvx-kit/effect`&&r.name===`createEffectFoundation`||r.source===`cvx-kit`&&r.name===`createFoundation`)&&(i=`foundation.ts`),i&&((a(e)!==i||t.has(r.name))&&e.report({node:n,messageId:`facade`,data:{name:r.name,file:i}}),t.add(r.name))}return{CallExpression:n,NewExpression:n}}},"no-raw-builders":{meta:h(`Build host functions through the auth-aware root constructors.`,{builder:`Import raw builders only in convex/functions.ts; use auth*/role*/admin* or system* elsewhere.`}),create(e){if(a(e)===`functions.ts`||s(e,e.filename))return{};let n=t();return{ImportDeclaration(t){if(t.importKind===`type`)return;let r=t.source.value,o=i(n,e.filename,r),s=o&&a(e,o)?.startsWith(`_generated/`)?a(e,o):r;if(/(?:^|\/)_generated\/server(?:\.[cm]?[jt]s)?$/.test(s)||s===`convex/server`)for(let n of t.specifiers){if(n.type===`ImportSpecifier`&&n.importKind===`type`)continue;let t=n.type===`ImportSpecifier`?c(n.imported):null;(t===null&&s!==`convex/server`||t&&/^(?:internal)?(?:Query|Mutation|Action)(?:Generic)?$|^(?:query|mutation|action)(?:Generic)?$/.test(t))&&e.report({node:n,messageId:`builder`})}},CallExpression(t){let n=u(e,t.callee);n?.source===`convex/server`&&/^(?:internal)?(?:Query|Mutation|Action)Generic$|^(?:query|mutation|action)Generic$/.test(n.name)&&t.callee.type===`MemberExpression`&&e.report({node:t,messageId:`builder`})}}}},"no-handwritten-references":{meta:h(`Use generated api/internal references.`,{reference:`Use generated api/internal references instead of makeFunctionReference.`}),create(e){return{CallExpression(t){let n=u(e,t.callee);n?.source===`convex/server`&&n.name===`makeFunctionReference`&&e.report({node:t,messageId:`reference`})}}}},"domain-import-boundaries":{meta:h(`Keep api, application, domain, and shared dependencies directed.`,{boundary:`Follow api → application/domain → shared; sibling modules expose only rules.ts and queries.ts.`}),create(e){let n=a(e),r=t();return v(e,(t,o)=>{if(!n)return;let s=i(r,e.filename,o);if(!s)return;let c=a(e,s)?.replace(/\.[cm]?[jt]s$/,``);if(!c){s.split(T).includes(`node_modules`)||e.report({node:t,messageId:`boundary`});return}let l=n.split(`/`),u=c.split(`/`),d=!1;l[0]===`domain`?(d=[`api`,`application`,`migrations`].includes(u[0]),u[0]===`domain`&&l[1]!==u[1]&&u[1]!==`shared`&&l[1]!==`table.ts`&&(d=l[1]===`shared`||![`rules`,`queries`,`contracts`].includes(u.slice(2).join(`/`)))):l[0]===`api`?d=[`api`,`migrations`].includes(u[0])||u[0]===`domain`&&u[1]!==`shared`&&u[1]!==(l.length>2?l[1]:S(n).replace(/\.[cm]?[jt]s$/,``)):l[0]===`application`?d=[`api`,`migrations`].includes(u[0]):[`relations.ts`,`querying.ts`].includes(n)&&u[0]===`domain`&&(d=!(n===`relations.ts`?[`schema`,`table`]:[`queries`,`contracts`]).includes(u.slice(2).join(`/`))&&(n!==`relations.ts`||c!==`domain/table`)),u[0]===`migrations`&&l[0]!==`migrations`&&(d=!0),[`api`,`domain`,`application`].includes(l[0])&&u.length>1&&![`api`,`domain`,`application`,`_generated`,`components`,`migrations`].includes(u[0])&&(d=!0),d&&e.report({node:t,messageId:`boundary`})})}},"public-functions-in-api":{meta:h(`Expose authenticated public functions only through api/.`,{public:`Declare public auth*/role*/admin* functions in convex/api/<module>.ts.`}),create(e){return a(e)?.startsWith(`api/`)?{}:{CallExpression(t){let n=u(e,t.callee);t.callee.type!==`CallExpression`&&n&&f(e,n.source)&&/^(auth|role|admin)(Query|Mutation|Action)$/.test(n.name)&&e.report({node:t,messageId:`public`})}}}},"thin-api-adapters":{meta:h(`Keep business decisions and writes in domain executors.`,{adapter:`Move business branches, private helpers, and database writes into the owning domain executor.`}),create(e){return a(e)?.startsWith(`api/`)?{IfStatement(t){e.report({node:t,messageId:`adapter`})},SwitchStatement(t){e.report({node:t,messageId:`adapter`})},ConditionalExpression(t){e.report({node:t,messageId:`adapter`})},Program(t){let n=l(t);for(let r of t.body)if(r.type===`FunctionDeclaration`&&r.id&&!n.has(r.id.name)&&e.report({node:r,messageId:`adapter`}),r.type===`VariableDeclaration`)for(let t of r.declarations)t.id.type===`Identifier`&&!n.has(t.id.name)&&[`ArrowFunctionExpression`,`FunctionExpression`].includes(t.init?.type??``)&&e.report({node:t,messageId:`adapter`})},CallExpression(t){d(t)&&e.report({node:t,messageId:`adapter`})}}:{}}},"no-inline-enums":{meta:h(`Keep vocabularies in named constants.ts tuples.`,{vocabulary:`Define a named readonly tuple in constants.ts and pass it to z.enum().`}),create(e){return{CallExpression(t){let n=u(e,t.callee),r=t.arguments[0];for(;r?.type===`TSAsExpression`||r?.type===`TSSatisfiesExpression`;)r=r.expression;n&&/^zod(?:\/v4)?$/.test(n.source)&&n.name===`enum`&&r?.type===`ArrayExpression`&&e.report({node:t,messageId:`vocabulary`})}}}},"no-unbounded-reads":{meta:h(`Bound collection reads through include or pagination.`,{bounded:`Use include(...).execute(limit) or bounded pagination; do not collect() or resolve() an unbounded query.`,order:`Apply eligibility filters in the indexed query before take(), execute(), or paginate(); filtering a bounded result can omit eligible rows. Do not move the predicate automatically.`}),create(e){return s(e,e.filename)?{}:{CallExpression(t){if(t.callee.type!==`MemberExpression`)return;let n=g(t.callee),r=_(e,t.callee.object);n===`filter`&&r===`bounded`&&e.report({node:t,messageId:`order`}),(n===`collect`&&(r===`stream`||r===`relationship`)||n===`resolve`&&r===`stream`)&&e.report({node:t,messageId:`bounded`})}}}},"no-manual-id-projection":{meta:h(`Use the table DTO boundary to project public IDs.`,{projection:`Use toPublicDto(row, true) to include _id; do not add IDs manually after a table DTO parse or projection.`}),create(e){return{ObjectExpression(t){if(t.properties.some(t=>t.type===`SpreadElement`&&_(e,t.argument)===`dto`))for(let n of t.properties)n.type===`Property`&&[`id`,`_id`].includes((n.computed?y(n.key):c(n.key))??``)&&e.report({node:n,messageId:`projection`})},AssignmentExpression(t){t.left.type===`MemberExpression`&&[`id`,`_id`].includes(g(t.left)??``)&&_(e,t.left.object)===`dto`&&e.report({node:t,messageId:`projection`})}}}},"no-copied-pagination":{meta:h(`Use native or table pagination schemas instead of copying their shape.`,{pagination:`Use the native paginationOptsValidator (or paginated(table.dto())) for native pagination, or table.paginationOpts(selection) for table queries; do not copy pagination fields.`}),create(e){return{CallExpression(t){let n=u(e,t.callee);if(!(n?.name===`object`&&[`zod`,`zod/v4`,`convex/values`].includes(n.source)))return;let r=t.arguments[0],i=r&&(m(e,r)??r);if(i?.type!==`ObjectExpression`)return;let a=new Set(i.properties.flatMap(e=>e.type===`Property`?[e.computed?y(e.key):c(e.key)]:[]));(a.has(`numItems`)&&a.has(`cursor`)||[`page`,`isDone`,`continueCursor`].every(e=>a.has(e)))&&e.report({node:t,messageId:`pagination`})}}}},"no-manual-timestamps":{meta:h(`Let timestamps triggers own createdAt and updatedAt.`,{timestamp:`Remove {{field}} from this write; register the timestamps trigger instead.`}),create(e){return s(e,e.filename)?{}:{CallExpression(t){if(!d(t))return;let n=t.arguments.at(-1);if(n?.type===`ObjectExpression`)for(let t of n.properties){if(t.type!==`Property`)continue;let n=t.computed?y(t.key):c(t.key);(n===`createdAt`||n===`updatedAt`)&&e.report({node:t,messageId:`timestamp`,data:{field:n}})}}}}},"component-boundaries":{meta:h(`Keep portable components isolated and consume their client facades.`,{boundary:`Components may import only their own files and npm dependencies; inject host policy through the client API.`,facade:`Import a component through its client.ts facade, not its private implementation.`}),create(e){let n=s(e,e.filename),r=t();return v(e,(t,o)=>{o.startsWith(`.`)||/^cvx-kit\/components\/[^/]+\//.test(o)&&!/^cvx-kit\/components\/[^/]+\/convex\.config(?:\.js)?$/.test(o)&&e.report({node:t,messageId:`facade`});let c=i(r,e.filename,o);c&&!c.split(T).includes(`node_modules`)&&(n&&(w(n,c).startsWith(`..${T}`)||c===C(n))?e.report({node:t,messageId:`boundary`}):!n&&s(e,c)&&!/^client(?:\.[cm]?[jt]s)?$/.test(S(c))&&!(a(e)===`convex.config.ts`&&/^convex\.config(?:\.[cm]?[jt]s)?$/.test(S(c)))&&e.report({node:t,messageId:`facade`}))})}},"no-component-env":{meta:h(`Pass environment configuration into portable components.`,{env:`Portable components must receive configuration through arguments; do not read process.env.`}),create(e){if(!s(e,e.filename))return{};function t(t){if(t.type!==`Identifier`)return!1;let n=o(e,t);return t.name===`process`&&!n?.defs.length||n?.defs.some(e=>e.type===`ImportBinding`&&e.parent?.type===`ImportDeclaration`&&[`node:process`,`process`].includes(e.parent.source.value)&&[`ImportDefaultSpecifier`,`ImportNamespaceSpecifier`].includes(e.node.type))}return{ImportDeclaration(t){if([`node:process`,`process`].includes(t.source.value))for(let n of t.specifiers)n.type===`ImportSpecifier`&&c(n.imported)===`env`&&e.report({node:n,messageId:`env`})},MemberExpression(n){if(g(n)!==`env`)return;let r=n.object,i=r.type===`MemberExpression`&&g(r)===`process`&&r.object.type===`Identifier`&&r.object.name===`globalThis`&&!o(e,r.object)?.defs.length;(t(r)||i)&&e.report({node:n,messageId:`env`})},VariableDeclarator(n){if(n.init&&t(n.init)&&n.id.type===`ObjectPattern`)for(let t of n.id.properties)t.type===`Property`&&(t.computed?y(t.key):c(t.key))===`env`&&e.report({node:t,messageId:`env`})}}}},"schema-file-boundaries":{meta:h(`Keep storage shapes and indexes in their documented owners.`,{schema:`{{builder}} belongs in {{file}}.`}),create(e){return{CallExpression(t){let n=u(e,t.callee),r=a(e);if(!r)return;let i=null;n?.source===`convex/server`&&(n.name===`defineSchema`&&r!==`schema.ts`&&!(s(e,e.filename)&&S(r)===`schema.ts`)&&(i=`the root schema.ts (or a component schema.ts)`),n.name===`defineTable`&&!(s(e,e.filename)&&[`schema.ts`,`table.ts`].includes(S(r)))&&(i=`a component schema.ts/table.ts; host tables use zodTable in domain/<module>/schema.ts`)),n&&[`cvx-kit`,`cvx-kit/zod-table`].includes(n.source)&&[`zodTable`,`tenantTable`,`zodVariantTable`].includes(n.name)&&!/^domain\/[^/]+\/schema\.ts$/.test(r)&&(i=`domain/<module>/schema.ts`),i&&e.report({node:t,messageId:`schema`,data:{builder:n?.name??`table`,file:i}}),t.callee.type===`MemberExpression`&&[`index`,`searchIndex`,`vectorIndex`].includes(g(t.callee)??``)&&p(t.callee.object)&&!s(e,e.filename)&&!/^domain\/[^/]+\/table\.ts$/.test(r)&&e.report({node:t,messageId:`schema`,data:{builder:`Table indexes`,file:`domain/<module>/table.ts`}})}}}},"no-internal-reexports":{meta:h(`Import from owning modules directly; consumer apps have no barrels.`,{reexport:`Import from the owning file directly; do not re-export imports inside convex/.`}),create(e){function t(t){if(t.source){e.report({node:t,messageId:`reexport`});return}for(let n of t.type===`ExportNamedDeclaration`?t.specifiers:[])o(e,n.local)?.defs.some(e=>e.type===`ImportBinding`)&&e.report({node:n,messageId:`reexport`})}return{ExportNamedDeclaration:t,ExportAllDeclaration:t,ExportDefaultDeclaration(t){t.declaration.type===`Identifier`&&o(e,t.declaration)?.defs.some(e=>e.type===`ImportBinding`)&&e.report({node:t,messageId:`reexport`})}}}},"public-api-first":{meta:h(`Place private helper implementations after the exported API.`,{order:`Move this private helper below the exported API so the file reads from public purpose to implementation.`}),create(e){return{Program(t){let n=l(t),r=t.body.findLastIndex(e=>e.type.startsWith(`Export`));for(let i of t.body.slice(0,r<0?0:r))i.type===`FunctionDeclaration`&&i.id&&!n.has(i.id.name)&&e.report({node:i,messageId:`order`})}}}},"named-private-helpers":{meta:h(`Use named declarations for top-level private helper functions.`,{helper:`Declare this private helper with function name(...) at the bottom of the file.`}),create(e){return{Program(t){let n=l(t);for(let r of t.body)if(r.type===`VariableDeclaration`)for(let t of r.declarations)t.id.type===`Identifier`&&!n.has(t.id.name)&&(t.init?.type===`ArrowFunctionExpression`||t.init?.type===`FunctionExpression`)&&e.report({node:t,messageId:`helper`})}}}}}),O={meta:{name:`cvx`},rules:D};function k(e){let t={...e},n=Object.keys(e);for(let r of n){let n=e[r];t[r]={meta:{...n.meta,schema:[{type:`object`,properties:{convexDir:{type:`string`,minLength:1}},additionalProperties:!1}]},create(e){let t=a(e);return!t||/(?:^|\/)(?:_generated|__tests__)(?:\/|$)/.test(t)||/\.(?:test|spec)\.[cm]?[jt]s$/.test(t)?{}:n.create(e)}}}return t}export{E as checkArchitecture,O as default,D as rules};
|
|
2
2
|
//# sourceMappingURL=oxlint.mjs.map
|
package/dist/oxlint.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.mjs","names":["checkArchitecture","inspectArchitecture","options","rules","scopeRules","ownershipRules","file","appFile","context","narrowRootDeclaration","reservedDomainFiles","metadata","componentRoot","seen","check","ref","imported","node","resolver","createResolver","importedSource","target","resolveImport","source","specifier","name","exportName","sourceVisitors","resolved","sep","from","to","forbidden","basename","isFunctionsImport","exported","exportedNames","statement","declaration","isDbWrite","values","propertyName","origin","readProvenance","property","staticString","argument","fieldsNode","localInitializer","fields","field","data","owner","relative","dirname","isProcess","variable","binding","def","object","globalProcess","expected","isTableChain","exports","lastExport","plugin","scoped","names","rule"],"sources":["../src/oxlint.ts"],"sourcesContent":["import { basename, dirname, relative, sep } from 'node:path'\nimport type { CreateRule, ESTree, Plugin, Rule } from '@oxlint/plugins'\nimport {\n\tinspectArchitecture,\n\tcreateResolver,\n\tresolveImport,\n\tnarrowRootDeclaration,\n\ttype ArchitectureOptions,\n\ttype ArchitectureDiagnostic,\n} from './oxlint/architecture'\nimport { reservedDomainFiles } from './oxlint/reserved-files'\nimport { ownershipRules, type OwnershipRuleName } from './oxlint/ownership'\nimport {\n\tappFile,\n\timported,\n\tsourceVisitors,\n\tisFunctionsImport,\n\tisTableChain,\n\tisDbWrite,\n\tmetadata,\n\tcomponentRoot,\n\tstaticString,\n\tpropertyName,\n\tbinding,\n\treadProvenance,\n\tlocalInitializer,\n\texportedNames,\n\texportName,\n} from './oxlint/ast'\n\nexport type { ArchitectureOptions, ArchitectureDiagnostic } from './oxlint/architecture'\n\nexport function checkArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\treturn inspectArchitecture(options)\n}\n\nexport type RuleName =\n\t| OwnershipRuleName\n\t| 'component-boundaries'\n\t| 'no-component-env'\n\t| 'schema-file-boundaries'\n\t| 'no-internal-reexports'\n\t| 'public-api-first'\n\t| 'named-private-helpers'\n\t| 'no-raw-builders'\n\t| 'no-handwritten-references'\n\t| 'domain-import-boundaries'\n\t| 'public-functions-in-api'\n\t| 'thin-api-adapters'\n\t| 'no-inline-enums'\n\t| 'no-unbounded-reads'\n\t| 'no-manual-timestamps'\n\t| 'reserved-domain-file-anatomy'\n\t| 'root-facade-ownership'\n\t| 'no-manual-id-projection'\n\t| 'no-copied-pagination'\n\n/** Consumer application rules derived from docs/conventions.md. */\nconst applicationRules: Record<RuleName, CreateRule> = {\n\t...ownershipRules,\n\t'root-wiring-only': {\n\t\t...ownershipRules['root-wiring-only'],\n\t\tcreate(context) {\n\t\t\tconst file = appFile(context) ?? ''\n\t\t\tif (['relations.ts', 'querying.ts'].includes(file)) {\n\t\t\t\tif (narrowRootDeclaration(file, context.sourceCode.text)) return {}\n\t\t\t\treturn {\n\t\t\t\t\tProgram(node) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'ownership',\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\treason: `${file} must export one kit factory declaration and contain only declarative configuration`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ownershipRules['root-wiring-only'].create(context)\n\t\t},\n\t},\n\t'reserved-domain-file-anatomy': reservedDomainFiles,\n\t'root-facade-ownership': {\n\t\tmeta: metadata('Configure shared kit infrastructure once in its root facade.', {\n\t\t\tfacade: 'Configure {{name}} once in convex/{{file}}; import that facade elsewhere.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\tconst seen = new Set<string>()\n\t\t\tfunction check(node: ESTree.CallExpression | ESTree.NewExpression) {\n\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\tif (!ref) return\n\t\t\t\tlet file: string | null = null\n\t\t\t\tif (\n\t\t\t\t\t['cvx-kit', 'cvx-kit/querying'].includes(ref.source) &&\n\t\t\t\t\tref.name === 'createQueryEngine'\n\t\t\t\t)\n\t\t\t\t\tfile = 'querying.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/relations'].includes(ref.source) && ref.name === 'defineRelations')\n\t\t\t\t\tfile = 'relations.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/auth'].includes(ref.source) && ref.name === 'createAuthFunctions')\n\t\t\t\t\tfile = 'functions.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/triggers'].includes(ref.source) && ref.name === 'createTriggers')\n\t\t\t\t\tfile = 'triggers.ts'\n\t\t\t\tif (\n\t\t\t\t\t['cvx-kit', 'cvx-kit/components/foundation'].includes(ref.source) &&\n\t\t\t\t\tref.name === 'Foundation'\n\t\t\t\t)\n\t\t\t\t\tfile = 'foundation.ts'\n\t\t\t\tif (\n\t\t\t\t\t(ref.source === 'cvx-kit/effect' && ref.name === 'createEffectFoundation') ||\n\t\t\t\t\t(ref.source === 'cvx-kit' && ref.name === 'createFoundation')\n\t\t\t\t)\n\t\t\t\t\tfile = 'foundation.ts'\n\t\t\t\tif (!file) return\n\t\t\t\tif (appFile(context) !== file || seen.has(ref.name))\n\t\t\t\t\tcontext.report({ node, messageId: 'facade', data: { name: ref.name, file } })\n\t\t\t\tseen.add(ref.name)\n\t\t\t}\n\t\t\treturn { CallExpression: check, NewExpression: check }\n\t\t},\n\t},\n\t'no-raw-builders': {\n\t\tmeta: metadata('Build host functions through the auth-aware root constructors.', {\n\t\t\tbuilder:\n\t\t\t\t'Import raw builders only in convex/functions.ts; use auth*/role*/admin* or system* elsewhere.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (appFile(context) === 'functions.ts' || componentRoot(context, context.filename)) return {}\n\t\t\tconst resolver = createResolver()\n\t\t\treturn {\n\t\t\t\tImportDeclaration(node) {\n\t\t\t\t\tif (node.importKind === 'type') return\n\t\t\t\t\tconst importedSource = node.source.value\n\t\t\t\t\tconst target = resolveImport(resolver, context.filename, importedSource)\n\t\t\t\t\tconst source =\n\t\t\t\t\t\ttarget && appFile(context, target)?.startsWith('_generated/')\n\t\t\t\t\t\t\t? appFile(context, target)!\n\t\t\t\t\t\t\t: importedSource\n\t\t\t\t\tif (\n\t\t\t\t\t\t!/(?:^|\\/)_generated\\/server(?:\\.[cm]?[jt]s)?$/.test(source) &&\n\t\t\t\t\t\tsource !== 'convex/server'\n\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\tfor (const specifier of node.specifiers) {\n\t\t\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\t\t\tconst name =\n\t\t\t\t\t\t\tspecifier.type === 'ImportSpecifier' ? exportName(specifier.imported) : null\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(name === null && source !== 'convex/server') ||\n\t\t\t\t\t\t\t(name &&\n\t\t\t\t\t\t\t\t/^(?:internal)?(?:Query|Mutation|Action)(?:Generic)?$|^(?:query|mutation|action)(?:Generic)?$/.test(\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'builder' })\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (\n\t\t\t\t\t\tref?.source === 'convex/server' &&\n\t\t\t\t\t\t/^(?:internal)?(?:Query|Mutation|Action)Generic$|^(?:query|mutation|action)Generic$/.test(\n\t\t\t\t\t\t\tref.name,\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\tnode.callee.type === 'MemberExpression'\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'builder' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-handwritten-references': {\n\t\tmeta: metadata('Use generated api/internal references.', {\n\t\t\treference: 'Use generated api/internal references instead of makeFunctionReference.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (ref?.source === 'convex/server' && ref.name === 'makeFunctionReference')\n\t\t\t\t\t\tcontext.report({ node, messageId: 'reference' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'domain-import-boundaries': {\n\t\tmeta: metadata('Keep api, application, domain, and shared dependencies directed.', {\n\t\t\tboundary:\n\t\t\t\t'Follow api → application/domain → shared; sibling modules expose only rules.ts and queries.ts.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tconst file = appFile(context)\n\t\t\tconst resolver = createResolver()\n\t\t\treturn sourceVisitors(context, (node, source) => {\n\t\t\t\tif (!file) return\n\t\t\t\tconst resolved = resolveImport(resolver, context.filename, source)\n\t\t\t\tif (!resolved) return\n\t\t\t\tconst target = appFile(context, resolved)?.replace(/\\.[cm]?[jt]s$/, '')\n\t\t\t\tif (!target) {\n\t\t\t\t\tif (!resolved.split(sep).includes('node_modules'))\n\t\t\t\t\t\tcontext.report({ node, messageId: 'boundary' })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst from = file.split('/')\n\t\t\t\tconst to = target.split('/')\n\t\t\t\tlet forbidden = false\n\t\t\t\tif (from[0] === 'domain') {\n\t\t\t\t\tforbidden = ['api', 'application', 'migrations'].includes(to[0])\n\t\t\t\t\tif (\n\t\t\t\t\t\tto[0] === 'domain' &&\n\t\t\t\t\t\tfrom[1] !== to[1] &&\n\t\t\t\t\t\tto[1] !== 'shared' &&\n\t\t\t\t\t\tfrom[1] !== 'table.ts'\n\t\t\t\t\t) {\n\t\t\t\t\t\tforbidden =\n\t\t\t\t\t\t\tfrom[1] === 'shared' ||\n\t\t\t\t\t\t\t!['rules', 'queries', 'contracts'].includes(to.slice(2).join('/'))\n\t\t\t\t\t}\n\t\t\t\t} else if (from[0] === 'api') {\n\t\t\t\t\tforbidden =\n\t\t\t\t\t\t['api', 'migrations'].includes(to[0]) ||\n\t\t\t\t\t\t(to[0] === 'domain' &&\n\t\t\t\t\t\t\tto[1] !== 'shared' &&\n\t\t\t\t\t\t\tto[1] !== (from.length > 2 ? from[1] : basename(file).replace(/\\.[cm]?[jt]s$/, '')))\n\t\t\t\t} else if (from[0] === 'application') forbidden = ['api', 'migrations'].includes(to[0])\n\t\t\t\telse if (['relations.ts', 'querying.ts'].includes(file) && to[0] === 'domain') {\n\t\t\t\t\tconst allowed = file === 'relations.ts' ? ['schema', 'table'] : ['queries', 'contracts']\n\t\t\t\t\tforbidden =\n\t\t\t\t\t\t!allowed.includes(to.slice(2).join('/')) &&\n\t\t\t\t\t\t!(file === 'relations.ts' && target === 'domain/table')\n\t\t\t\t}\n\t\t\t\tif (to[0] === 'migrations' && from[0] !== 'migrations') forbidden = true\n\t\t\t\tif (\n\t\t\t\t\t['api', 'domain', 'application'].includes(from[0]) &&\n\t\t\t\t\tto.length > 1 &&\n\t\t\t\t\t!['api', 'domain', 'application', '_generated', 'components', 'migrations'].includes(\n\t\t\t\t\t\tto[0],\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tforbidden = true\n\t\t\t\tif (forbidden) context.report({ node, messageId: 'boundary' })\n\t\t\t})\n\t\t},\n\t},\n\t'public-functions-in-api': {\n\t\tmeta: metadata('Expose authenticated public functions only through api/.', {\n\t\t\tpublic: 'Declare public auth*/role*/admin* functions in convex/api/<module>.ts.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (appFile(context)?.startsWith('api/')) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.callee.type !== 'CallExpression' &&\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\tisFunctionsImport(context, ref.source) &&\n\t\t\t\t\t\t/^(auth|role|admin)(Query|Mutation|Action)$/.test(ref.name)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'public' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'thin-api-adapters': {\n\t\tmeta: metadata('Keep business decisions and writes in domain executors.', {\n\t\t\tadapter:\n\t\t\t\t'Move business branches, private helpers, and database writes into the owning domain executor.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (!appFile(context)?.startsWith('api/')) return {}\n\t\t\treturn {\n\t\t\t\tIfStatement(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tSwitchStatement(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tConditionalExpression(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exported = exportedNames(node)\n\t\t\t\t\tfor (const statement of node.body) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstatement.type === 'FunctionDeclaration' &&\n\t\t\t\t\t\t\tstatement.id &&\n\t\t\t\t\t\t\t!exported.has(statement.id.name)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontext.report({ node: statement, messageId: 'adapter' })\n\t\t\t\t\t\tif (statement.type === 'VariableDeclaration')\n\t\t\t\t\t\t\tfor (const declaration of statement.declarations) {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tdeclaration.id.type === 'Identifier' &&\n\t\t\t\t\t\t\t\t\t!exported.has(declaration.id.name) &&\n\t\t\t\t\t\t\t\t\t['ArrowFunctionExpression', 'FunctionExpression'].includes(\n\t\t\t\t\t\t\t\t\t\tdeclaration.init?.type ?? '',\n\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\tcontext.report({ node: declaration, messageId: 'adapter' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (isDbWrite(node)) context.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-inline-enums': {\n\t\tmeta: metadata('Keep vocabularies in named constants.ts tuples.', {\n\t\t\tvocabulary: 'Define a named readonly tuple in constants.ts and pass it to z.enum().',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tlet values = node.arguments[0]\n\t\t\t\t\twhile (values?.type === 'TSAsExpression' || values?.type === 'TSSatisfiesExpression')\n\t\t\t\t\t\tvalues = values.expression\n\t\t\t\t\tif (\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\t/^zod(?:\\/v4)?$/.test(ref.source) &&\n\t\t\t\t\t\tref.name === 'enum' &&\n\t\t\t\t\t\tvalues?.type === 'ArrayExpression'\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'vocabulary' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-unbounded-reads': {\n\t\tmeta: metadata('Bound collection reads through include or pagination.', {\n\t\t\tbounded:\n\t\t\t\t'Use include(...).execute(limit) or bounded pagination; do not collect() or resolve() an unbounded query.',\n\t\t\torder:\n\t\t\t\t'Apply eligibility filters in the indexed query before take(), execute(), or paginate(); filtering a bounded result can omit eligible rows. Do not move the predicate automatically.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (node.callee.type !== 'MemberExpression') return\n\t\t\t\t\tconst name = propertyName(node.callee)\n\t\t\t\t\tconst origin = readProvenance(context, node.callee.object)\n\t\t\t\t\tif (name === 'filter' && origin === 'bounded')\n\t\t\t\t\t\tcontext.report({ node, messageId: 'order' })\n\t\t\t\t\tif (\n\t\t\t\t\t\t(name === 'collect' && (origin === 'stream' || origin === 'relationship')) ||\n\t\t\t\t\t\t(name === 'resolve' && origin === 'stream')\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'bounded' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-manual-id-projection': {\n\t\tmeta: metadata('Use the table DTO boundary to project public IDs.', {\n\t\t\tprojection:\n\t\t\t\t'Use toPublicDto(row, true) to include _id; do not add IDs manually after a table DTO parse or projection.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tObjectExpression(node) {\n\t\t\t\t\tconst dto = node.properties.some(\n\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\tproperty.type === 'SpreadElement' &&\n\t\t\t\t\t\t\treadProvenance(context, property.argument) === 'dto',\n\t\t\t\t\t)\n\t\t\t\t\tif (!dto) return\n\t\t\t\t\tfor (const property of node.properties) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t['id', '_id'].includes(\n\t\t\t\t\t\t\t\t(property.computed ? staticString(property.key) : exportName(property.key)) ?? '',\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'projection' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tAssignmentExpression(node) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.left.type === 'MemberExpression' &&\n\t\t\t\t\t\t['id', '_id'].includes(propertyName(node.left) ?? '') &&\n\t\t\t\t\t\treadProvenance(context, node.left.object) === 'dto'\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'projection' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-copied-pagination': {\n\t\tmeta: metadata('Use native or table pagination schemas instead of copying their shape.', {\n\t\t\tpagination:\n\t\t\t\t'Use the native paginationOptsValidator (or paginated(table.dto())) for native pagination, or table.paginationOpts(selection) for table queries; do not copy pagination fields.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (!(ref?.name === 'object' && ['zod', 'zod/v4', 'convex/values'].includes(ref.source)))\n\t\t\t\t\t\treturn\n\t\t\t\t\tconst argument = node.arguments[0]\n\t\t\t\t\tconst fieldsNode = argument && (localInitializer(context, argument) ?? argument)\n\t\t\t\t\tif (fieldsNode?.type !== 'ObjectExpression') return\n\t\t\t\t\tconst fields = new Set(\n\t\t\t\t\t\tfieldsNode.properties.flatMap((property) =>\n\t\t\t\t\t\t\tproperty.type === 'Property'\n\t\t\t\t\t\t\t\t? [property.computed ? staticString(property.key) : exportName(property.key)]\n\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tif (\n\t\t\t\t\t\t(fields.has('numItems') && fields.has('cursor')) ||\n\t\t\t\t\t\t['page', 'isDone', 'continueCursor'].every((field) => fields.has(field))\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'pagination' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-manual-timestamps': {\n\t\tmeta: metadata('Let timestamps triggers own createdAt and updatedAt.', {\n\t\t\ttimestamp: 'Remove {{field}} from this write; register the timestamps trigger instead.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (!isDbWrite(node)) return\n\t\t\t\t\tconst data = node.arguments.at(-1)\n\t\t\t\t\tif (data?.type !== 'ObjectExpression') return\n\t\t\t\t\tfor (const property of data.properties) {\n\t\t\t\t\t\tif (property.type !== 'Property') continue\n\t\t\t\t\t\tconst field = property.computed ? staticString(property.key) : exportName(property.key)\n\t\t\t\t\t\tif (field === 'createdAt' || field === 'updatedAt')\n\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'timestamp', data: { field } })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'component-boundaries': {\n\t\tmeta: metadata('Keep portable components isolated and consume their client facades.', {\n\t\t\tboundary:\n\t\t\t\t'Components may import only their own files and npm dependencies; inject host policy through the client API.',\n\t\t\tfacade: 'Import a component through its client.ts facade, not its private implementation.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tconst owner = componentRoot(context, context.filename)\n\t\t\tconst resolver = createResolver()\n\n\t\t\treturn sourceVisitors(context, (node, specifier) => {\n\t\t\t\tif (!specifier.startsWith('.')) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t/^cvx-kit\\/components\\/[^/]+\\//.test(specifier) &&\n\t\t\t\t\t\t!/^cvx-kit\\/components\\/[^/]+\\/convex\\.config(?:\\.js)?$/.test(specifier)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'facade' })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst target = resolveImport(resolver, context.filename, specifier)\n\t\t\t\tif (!target || target.split(sep).includes('node_modules')) return\n\t\t\t\tif (\n\t\t\t\t\towner &&\n\t\t\t\t\t(relative(owner, target).startsWith(`..${sep}`) || target === dirname(owner))\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({ node, messageId: 'boundary' })\n\t\t\t\t} else if (\n\t\t\t\t\t!owner &&\n\t\t\t\t\tcomponentRoot(context, target) &&\n\t\t\t\t\t!/^client(?:\\.[cm]?[jt]s)?$/.test(basename(target)) &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tappFile(context) === 'convex.config.ts' &&\n\t\t\t\t\t\t/^convex\\.config(?:\\.[cm]?[jt]s)?$/.test(basename(target))\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({ node, messageId: 'facade' })\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t},\n\t'no-component-env': {\n\t\tmeta: metadata('Pass environment configuration into portable components.', {\n\t\t\tenv: 'Portable components must receive configuration through arguments; do not read process.env.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (!componentRoot(context, context.filename)) return {}\n\t\t\tfunction isProcess(node: ESTree.Node) {\n\t\t\t\tif (node.type !== 'Identifier') return false\n\t\t\t\tconst variable = binding(context, node)\n\t\t\t\tif (node.name === 'process' && !variable?.defs.length) return true\n\t\t\t\treturn variable?.defs.some(\n\t\t\t\t\t(def) =>\n\t\t\t\t\t\tdef.type === 'ImportBinding' &&\n\t\t\t\t\t\tdef.parent?.type === 'ImportDeclaration' &&\n\t\t\t\t\t\t['node:process', 'process'].includes(def.parent.source.value) &&\n\t\t\t\t\t\t['ImportDefaultSpecifier', 'ImportNamespaceSpecifier'].includes(def.node.type),\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tImportDeclaration(node) {\n\t\t\t\t\tif (['node:process', 'process'].includes(node.source.value)) {\n\t\t\t\t\t\tfor (const specifier of node.specifiers) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tspecifier.type === 'ImportSpecifier' &&\n\t\t\t\t\t\t\t\texportName(specifier.imported) === 'env'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'env' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tMemberExpression(node) {\n\t\t\t\t\tif (propertyName(node) !== 'env') return\n\t\t\t\t\tconst object = node.object\n\t\t\t\t\tconst globalProcess =\n\t\t\t\t\t\tobject.type === 'MemberExpression' &&\n\t\t\t\t\t\tpropertyName(object) === 'process' &&\n\t\t\t\t\t\tobject.object.type === 'Identifier' &&\n\t\t\t\t\t\tobject.object.name === 'globalThis' &&\n\t\t\t\t\t\t!binding(context, object.object)?.defs.length\n\t\t\t\t\tif (isProcess(object) || globalProcess) context.report({ node, messageId: 'env' })\n\t\t\t\t},\n\t\t\t\tVariableDeclarator(node) {\n\t\t\t\t\tif (node.init && isProcess(node.init) && node.id.type === 'ObjectPattern') {\n\t\t\t\t\t\tfor (const property of node.id.properties) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t(property.computed ? staticString(property.key) : exportName(property.key)) ===\n\t\t\t\t\t\t\t\t\t'env'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'env' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'schema-file-boundaries': {\n\t\tmeta: metadata('Keep storage shapes and indexes in their documented owners.', {\n\t\t\tschema: '{{builder}} belongs in {{file}}.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tconst file = appFile(context)\n\t\t\t\t\tif (!file) return\n\t\t\t\t\tlet expected: string | null = null\n\t\t\t\t\tif (ref?.source === 'convex/server') {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tref.name === 'defineSchema' &&\n\t\t\t\t\t\t\tfile !== 'schema.ts' &&\n\t\t\t\t\t\t\t!(componentRoot(context, context.filename) && basename(file) === 'schema.ts')\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\texpected = 'the root schema.ts (or a component schema.ts)'\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tref.name === 'defineTable' &&\n\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\tcomponentRoot(context, context.filename) &&\n\t\t\t\t\t\t\t\t['schema.ts', 'table.ts'].includes(basename(file))\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\texpected =\n\t\t\t\t\t\t\t\t'a component schema.ts/table.ts; host tables use zodTable in domain/<module>/schema.ts'\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\t['cvx-kit', 'cvx-kit/zod-table'].includes(ref.source) &&\n\t\t\t\t\t\t['zodTable', 'tenantTable', 'zodVariantTable'].includes(ref.name) &&\n\t\t\t\t\t\t!/^domain\\/[^/]+\\/schema\\.ts$/.test(file)\n\t\t\t\t\t)\n\t\t\t\t\t\texpected = 'domain/<module>/schema.ts'\n\t\t\t\t\tif (expected)\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'schema',\n\t\t\t\t\t\t\tdata: { builder: ref?.name ?? 'table', file: expected },\n\t\t\t\t\t\t})\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.callee.type === 'MemberExpression' &&\n\t\t\t\t\t\t['index', 'searchIndex', 'vectorIndex'].includes(propertyName(node.callee) ?? '') &&\n\t\t\t\t\t\tisTableChain(node.callee.object) &&\n\t\t\t\t\t\t!componentRoot(context, context.filename) &&\n\t\t\t\t\t\t!/^domain\\/[^/]+\\/table\\.ts$/.test(file)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'schema',\n\t\t\t\t\t\t\tdata: { builder: 'Table indexes', file: 'domain/<module>/table.ts' },\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-internal-reexports': {\n\t\tmeta: metadata('Import from owning modules directly; consumer apps have no barrels.', {\n\t\t\treexport: 'Import from the owning file directly; do not re-export imports inside convex/.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tfunction check(node: ESTree.ExportNamedDeclaration | ESTree.ExportAllDeclaration) {\n\t\t\t\tif (node.source) {\n\t\t\t\t\tcontext.report({ node, messageId: 'reexport' })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tfor (const specifier of node.type === 'ExportNamedDeclaration' ? node.specifiers : []) {\n\t\t\t\t\tif (binding(context, specifier.local)?.defs.some((def) => def.type === 'ImportBinding')) {\n\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'reexport' })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tExportNamedDeclaration: check,\n\t\t\t\tExportAllDeclaration: check,\n\t\t\t\tExportDefaultDeclaration(node) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.declaration.type === 'Identifier' &&\n\t\t\t\t\t\tbinding(context, node.declaration)?.defs.some((def) => def.type === 'ImportBinding')\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'reexport' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'public-api-first': {\n\t\tmeta: metadata('Place private helper implementations after the exported API.', {\n\t\t\torder:\n\t\t\t\t'Move this private helper below the exported API so the file reads from public purpose to implementation.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exports = exportedNames(node)\n\t\t\t\t\tconst lastExport = node.body.findLastIndex((statement) =>\n\t\t\t\t\t\tstatement.type.startsWith('Export'),\n\t\t\t\t\t)\n\t\t\t\t\tfor (const statement of node.body.slice(0, lastExport < 0 ? 0 : lastExport)) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstatement.type === 'FunctionDeclaration' &&\n\t\t\t\t\t\t\tstatement.id &&\n\t\t\t\t\t\t\t!exports.has(statement.id.name)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontext.report({ node: statement, messageId: 'order' })\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'named-private-helpers': {\n\t\tmeta: metadata('Use named declarations for top-level private helper functions.', {\n\t\t\thelper: 'Declare this private helper with function name(...) at the bottom of the file.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exports = exportedNames(node)\n\t\t\t\t\tfor (const statement of node.body) {\n\t\t\t\t\t\tif (statement.type !== 'VariableDeclaration') continue\n\t\t\t\t\t\tfor (const declaration of statement.declarations) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tdeclaration.id.type === 'Identifier' &&\n\t\t\t\t\t\t\t\t!exports.has(declaration.id.name) &&\n\t\t\t\t\t\t\t\t(declaration.init?.type === 'ArrowFunctionExpression' ||\n\t\t\t\t\t\t\t\t\tdeclaration.init?.type === 'FunctionExpression')\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: declaration, messageId: 'helper' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n}\n\nexport const rules: Record<RuleName, Rule> = scopeRules(applicationRules)\nconst plugin: Plugin = { meta: { name: 'cvx' }, rules }\nexport default plugin\n\nfunction scopeRules(source: Record<RuleName, CreateRule>): Record<RuleName, Rule> {\n\tconst scoped = { ...source }\n\t// SAFETY: source is the closed applicationRules record; its own keys are exactly RuleName.\n\tconst names = Object.keys(source) as RuleName[]\n\tfor (const name of names) {\n\t\tconst rule = source[name]\n\t\tscoped[name] = {\n\t\t\tmeta: {\n\t\t\t\t...rule.meta,\n\t\t\t\tschema: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\tproperties: { convexDir: { type: 'string', minLength: 1 } },\n\t\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tcreate(context) {\n\t\t\t\tconst file = appFile(context)\n\t\t\t\tif (\n\t\t\t\t\t!file ||\n\t\t\t\t\t/(?:^|\\/)(?:_generated|__tests__)(?:\\/|$)/.test(file) ||\n\t\t\t\t\t/\\.(?:test|spec)\\.[cm]?[jt]s$/.test(file)\n\t\t\t\t)\n\t\t\t\t\treturn {}\n\t\t\t\treturn rule.create(context)\n\t\t\t},\n\t\t}\n\t}\n\treturn scoped\n}\n"],"mappings":"ymBAgCA,SAAgBA,EAAkB,EAA+B,CAAC,EAA6B,CAC9F,OAAOC,EAAoBC,CAAO,CACnC,CAyoBA,MAAaC,EAAgCC,EAAW,CAhnBvD,GAAGC,EACH,mBAAoB,CACnB,GAAGA,EAAe,oBAClB,OAAO,EAAS,CACf,IAAMC,EAAOC,EAAQC,CAAO,GAAK,GAejC,MAdI,CAAC,eAAgB,aAAa,CAAC,CAAC,SAASF,CAAI,EAC5CG,EAAsBH,EAAME,EAAQ,WAAW,IAAI,E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EAAa,UAAW,QAAS,CAAC,CAI7D,CACD,CACD,CACD,CAGuD,CAAgB,EAClE2B,EAAiB,CAAE,KAAM,CAAE,KAAM,KAAM,EAAG,OAAM,EAGtD,SAAS7D,EAAW,EAA8D,CACjF,IAAM8D,EAAS,CAAE,GAAG3C,CAAO,EAErB4C,EAAQ,OAAO,KAAK5C,CAAM,EAChC,IAAK,IAAME,KAAQ0C,EAAO,CACzB,IAAMC,EAAO7C,EAAOE,GACpB,EAAOA,GAAQ,CACd,KAAM,CACL,GAAG2C,EAAK,KACR,OAAQ,CACP,CACC,KAAM,SACN,WAAY,CAAE,UAAW,CAAE,KAAM,SAAU,UAAW,CAAE,CAAE,EAC1D,qBAAsB,EACvB,CACD,CACD,EACA,OAAO,EAAS,CACf,IAAM9D,EAAOC,EAAQC,CAAO,EAO5B,MALC,CAACF,GACD,2CAA2C,KAAKA,CAAI,GACpD,+BAA+B,KAAKA,CAAI,EAEjC,CAAC,EACF8D,EAAK,OAAO5D,CAAO,CAC3B,CACD,CACD,CACA,OAAO0D,CACR"}
|
|
1
|
+
{"version":3,"file":"oxlint.mjs","names":["checkArchitecture","registry","options","forceRegistry","inspectArchitecture","rules","scopeRules","ownershipRules","file","appFile","context","narrowRootDeclaration","reservedDomainFiles","metadata","componentRoot","seen","check","ref","imported","node","resolver","createResolver","importedSource","target","resolveImport","source","specifier","name","exportName","sourceVisitors","resolved","sep","from","to","forbidden","basename","isFunctionsImport","exported","exportedNames","statement","declaration","isDbWrite","values","propertyName","origin","readProvenance","property","staticString","argument","fieldsNode","localInitializer","fields","field","data","owner","relative","dirname","isProcess","variable","binding","def","object","globalProcess","expected","isTableChain","exports","lastExport","plugin","scoped","names","rule"],"sources":["../src/oxlint.ts"],"sourcesContent":["import { forceRegistry } from './modules/contracts/lazy'\nimport { basename, dirname, relative, sep } from 'node:path'\nimport type { CreateRule, ESTree, Plugin, Rule } from '@oxlint/plugins'\nimport {\n\tinspectArchitecture,\n\tcreateResolver,\n\tresolveImport,\n\tnarrowRootDeclaration,\n\ttype ArchitectureOptions,\n\ttype ArchitectureDiagnostic,\n} from './oxlint/architecture'\nimport { reservedDomainFiles } from './oxlint/reserved-files'\nimport { ownershipRules, type OwnershipRuleName } from './oxlint/ownership'\nimport {\n\tappFile,\n\timported,\n\tsourceVisitors,\n\tisFunctionsImport,\n\tisTableChain,\n\tisDbWrite,\n\tmetadata,\n\tcomponentRoot,\n\tstaticString,\n\tpropertyName,\n\tbinding,\n\treadProvenance,\n\tlocalInitializer,\n\texportedNames,\n\texportName,\n} from './oxlint/ast'\n\nexport type { ArchitectureOptions, ArchitectureDiagnostic } from './oxlint/architecture'\n\nexport function checkArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\tfor (const registry of options.registries ?? []) forceRegistry(registry)\n\treturn inspectArchitecture(options)\n}\n\nexport type RuleName =\n\t| OwnershipRuleName\n\t| 'component-boundaries'\n\t| 'no-component-env'\n\t| 'schema-file-boundaries'\n\t| 'no-internal-reexports'\n\t| 'public-api-first'\n\t| 'named-private-helpers'\n\t| 'no-raw-builders'\n\t| 'no-handwritten-references'\n\t| 'domain-import-boundaries'\n\t| 'public-functions-in-api'\n\t| 'thin-api-adapters'\n\t| 'no-inline-enums'\n\t| 'no-unbounded-reads'\n\t| 'no-manual-timestamps'\n\t| 'reserved-domain-file-anatomy'\n\t| 'root-facade-ownership'\n\t| 'no-manual-id-projection'\n\t| 'no-copied-pagination'\n\n/** Consumer application rules derived from docs/conventions.md. */\nconst applicationRules: Record<RuleName, CreateRule> = {\n\t...ownershipRules,\n\t'root-wiring-only': {\n\t\t...ownershipRules['root-wiring-only'],\n\t\tcreate(context) {\n\t\t\tconst file = appFile(context) ?? ''\n\t\t\tif (['relations.ts', 'querying.ts'].includes(file)) {\n\t\t\t\tif (narrowRootDeclaration(file, context.sourceCode.text)) return {}\n\t\t\t\treturn {\n\t\t\t\t\tProgram(node) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'ownership',\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\treason: `${file} must export one kit factory declaration and contain only declarative configuration`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ownershipRules['root-wiring-only'].create(context)\n\t\t},\n\t},\n\t'reserved-domain-file-anatomy': reservedDomainFiles,\n\t'root-facade-ownership': {\n\t\tmeta: metadata('Configure shared kit infrastructure once in its root facade.', {\n\t\t\tfacade: 'Configure {{name}} once in convex/{{file}}; import that facade elsewhere.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\tconst seen = new Set<string>()\n\t\t\tfunction check(node: ESTree.CallExpression | ESTree.NewExpression) {\n\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\tif (!ref) return\n\t\t\t\tlet file: string | null = null\n\t\t\t\tif (\n\t\t\t\t\t['cvx-kit', 'cvx-kit/querying'].includes(ref.source) &&\n\t\t\t\t\tref.name === 'createQueryEngine'\n\t\t\t\t)\n\t\t\t\t\tfile = 'querying.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/relations'].includes(ref.source) && ref.name === 'defineRelations')\n\t\t\t\t\tfile = 'relations.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/auth'].includes(ref.source) && ref.name === 'createAuthFunctions')\n\t\t\t\t\tfile = 'functions.ts'\n\t\t\t\tif (['cvx-kit', 'cvx-kit/triggers'].includes(ref.source) && ref.name === 'createTriggers')\n\t\t\t\t\tfile = 'triggers.ts'\n\t\t\t\tif (\n\t\t\t\t\t['cvx-kit', 'cvx-kit/components/foundation'].includes(ref.source) &&\n\t\t\t\t\tref.name === 'Foundation'\n\t\t\t\t)\n\t\t\t\t\tfile = 'foundation.ts'\n\t\t\t\tif (\n\t\t\t\t\t(ref.source === 'cvx-kit/effect' && ref.name === 'createEffectFoundation') ||\n\t\t\t\t\t(ref.source === 'cvx-kit' && ref.name === 'createFoundation')\n\t\t\t\t)\n\t\t\t\t\tfile = 'foundation.ts'\n\t\t\t\tif (!file) return\n\t\t\t\tif (appFile(context) !== file || seen.has(ref.name))\n\t\t\t\t\tcontext.report({ node, messageId: 'facade', data: { name: ref.name, file } })\n\t\t\t\tseen.add(ref.name)\n\t\t\t}\n\t\t\treturn { CallExpression: check, NewExpression: check }\n\t\t},\n\t},\n\t'no-raw-builders': {\n\t\tmeta: metadata('Build host functions through the auth-aware root constructors.', {\n\t\t\tbuilder:\n\t\t\t\t'Import raw builders only in convex/functions.ts; use auth*/role*/admin* or system* elsewhere.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (appFile(context) === 'functions.ts' || componentRoot(context, context.filename)) return {}\n\t\t\tconst resolver = createResolver()\n\t\t\treturn {\n\t\t\t\tImportDeclaration(node) {\n\t\t\t\t\tif (node.importKind === 'type') return\n\t\t\t\t\tconst importedSource = node.source.value\n\t\t\t\t\tconst target = resolveImport(resolver, context.filename, importedSource)\n\t\t\t\t\tconst source =\n\t\t\t\t\t\ttarget && appFile(context, target)?.startsWith('_generated/')\n\t\t\t\t\t\t\t? appFile(context, target)!\n\t\t\t\t\t\t\t: importedSource\n\t\t\t\t\tif (\n\t\t\t\t\t\t!/(?:^|\\/)_generated\\/server(?:\\.[cm]?[jt]s)?$/.test(source) &&\n\t\t\t\t\t\tsource !== 'convex/server'\n\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\tfor (const specifier of node.specifiers) {\n\t\t\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\t\t\tconst name =\n\t\t\t\t\t\t\tspecifier.type === 'ImportSpecifier' ? exportName(specifier.imported) : null\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(name === null && source !== 'convex/server') ||\n\t\t\t\t\t\t\t(name &&\n\t\t\t\t\t\t\t\t/^(?:internal)?(?:Query|Mutation|Action)(?:Generic)?$|^(?:query|mutation|action)(?:Generic)?$/.test(\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'builder' })\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (\n\t\t\t\t\t\tref?.source === 'convex/server' &&\n\t\t\t\t\t\t/^(?:internal)?(?:Query|Mutation|Action)Generic$|^(?:query|mutation|action)Generic$/.test(\n\t\t\t\t\t\t\tref.name,\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\tnode.callee.type === 'MemberExpression'\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'builder' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-handwritten-references': {\n\t\tmeta: metadata('Use generated api/internal references.', {\n\t\t\treference: 'Use generated api/internal references instead of makeFunctionReference.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (ref?.source === 'convex/server' && ref.name === 'makeFunctionReference')\n\t\t\t\t\t\tcontext.report({ node, messageId: 'reference' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'domain-import-boundaries': {\n\t\tmeta: metadata('Keep api, application, domain, and shared dependencies directed.', {\n\t\t\tboundary:\n\t\t\t\t'Follow api → application/domain → shared; sibling modules expose only rules.ts and queries.ts.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tconst file = appFile(context)\n\t\t\tconst resolver = createResolver()\n\t\t\treturn sourceVisitors(context, (node, source) => {\n\t\t\t\tif (!file) return\n\t\t\t\tconst resolved = resolveImport(resolver, context.filename, source)\n\t\t\t\tif (!resolved) return\n\t\t\t\tconst target = appFile(context, resolved)?.replace(/\\.[cm]?[jt]s$/, '')\n\t\t\t\tif (!target) {\n\t\t\t\t\tif (!resolved.split(sep).includes('node_modules'))\n\t\t\t\t\t\tcontext.report({ node, messageId: 'boundary' })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst from = file.split('/')\n\t\t\t\tconst to = target.split('/')\n\t\t\t\tlet forbidden = false\n\t\t\t\tif (from[0] === 'domain') {\n\t\t\t\t\tforbidden = ['api', 'application', 'migrations'].includes(to[0])\n\t\t\t\t\tif (\n\t\t\t\t\t\tto[0] === 'domain' &&\n\t\t\t\t\t\tfrom[1] !== to[1] &&\n\t\t\t\t\t\tto[1] !== 'shared' &&\n\t\t\t\t\t\tfrom[1] !== 'table.ts'\n\t\t\t\t\t) {\n\t\t\t\t\t\tforbidden =\n\t\t\t\t\t\t\tfrom[1] === 'shared' ||\n\t\t\t\t\t\t\t!['rules', 'queries', 'contracts'].includes(to.slice(2).join('/'))\n\t\t\t\t\t}\n\t\t\t\t} else if (from[0] === 'api') {\n\t\t\t\t\tforbidden =\n\t\t\t\t\t\t['api', 'migrations'].includes(to[0]) ||\n\t\t\t\t\t\t(to[0] === 'domain' &&\n\t\t\t\t\t\t\tto[1] !== 'shared' &&\n\t\t\t\t\t\t\tto[1] !== (from.length > 2 ? from[1] : basename(file).replace(/\\.[cm]?[jt]s$/, '')))\n\t\t\t\t} else if (from[0] === 'application') forbidden = ['api', 'migrations'].includes(to[0])\n\t\t\t\telse if (['relations.ts', 'querying.ts'].includes(file) && to[0] === 'domain') {\n\t\t\t\t\tconst allowed = file === 'relations.ts' ? ['schema', 'table'] : ['queries', 'contracts']\n\t\t\t\t\tforbidden =\n\t\t\t\t\t\t!allowed.includes(to.slice(2).join('/')) &&\n\t\t\t\t\t\t!(file === 'relations.ts' && target === 'domain/table')\n\t\t\t\t}\n\t\t\t\tif (to[0] === 'migrations' && from[0] !== 'migrations') forbidden = true\n\t\t\t\tif (\n\t\t\t\t\t['api', 'domain', 'application'].includes(from[0]) &&\n\t\t\t\t\tto.length > 1 &&\n\t\t\t\t\t!['api', 'domain', 'application', '_generated', 'components', 'migrations'].includes(\n\t\t\t\t\t\tto[0],\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tforbidden = true\n\t\t\t\tif (forbidden) context.report({ node, messageId: 'boundary' })\n\t\t\t})\n\t\t},\n\t},\n\t'public-functions-in-api': {\n\t\tmeta: metadata('Expose authenticated public functions only through api/.', {\n\t\t\tpublic: 'Declare public auth*/role*/admin* functions in convex/api/<module>.ts.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (appFile(context)?.startsWith('api/')) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.callee.type !== 'CallExpression' &&\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\tisFunctionsImport(context, ref.source) &&\n\t\t\t\t\t\t/^(auth|role|admin)(Query|Mutation|Action)$/.test(ref.name)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'public' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'thin-api-adapters': {\n\t\tmeta: metadata('Keep business decisions and writes in domain executors.', {\n\t\t\tadapter:\n\t\t\t\t'Move business branches, private helpers, and database writes into the owning domain executor.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (!appFile(context)?.startsWith('api/')) return {}\n\t\t\treturn {\n\t\t\t\tIfStatement(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tSwitchStatement(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tConditionalExpression(node) {\n\t\t\t\t\tcontext.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exported = exportedNames(node)\n\t\t\t\t\tfor (const statement of node.body) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstatement.type === 'FunctionDeclaration' &&\n\t\t\t\t\t\t\tstatement.id &&\n\t\t\t\t\t\t\t!exported.has(statement.id.name)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontext.report({ node: statement, messageId: 'adapter' })\n\t\t\t\t\t\tif (statement.type === 'VariableDeclaration')\n\t\t\t\t\t\t\tfor (const declaration of statement.declarations) {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tdeclaration.id.type === 'Identifier' &&\n\t\t\t\t\t\t\t\t\t!exported.has(declaration.id.name) &&\n\t\t\t\t\t\t\t\t\t['ArrowFunctionExpression', 'FunctionExpression'].includes(\n\t\t\t\t\t\t\t\t\t\tdeclaration.init?.type ?? '',\n\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\tcontext.report({ node: declaration, messageId: 'adapter' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (isDbWrite(node)) context.report({ node, messageId: 'adapter' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-inline-enums': {\n\t\tmeta: metadata('Keep vocabularies in named constants.ts tuples.', {\n\t\t\tvocabulary: 'Define a named readonly tuple in constants.ts and pass it to z.enum().',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tlet values = node.arguments[0]\n\t\t\t\t\twhile (values?.type === 'TSAsExpression' || values?.type === 'TSSatisfiesExpression')\n\t\t\t\t\t\tvalues = values.expression\n\t\t\t\t\tif (\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\t/^zod(?:\\/v4)?$/.test(ref.source) &&\n\t\t\t\t\t\tref.name === 'enum' &&\n\t\t\t\t\t\tvalues?.type === 'ArrayExpression'\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'vocabulary' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-unbounded-reads': {\n\t\tmeta: metadata('Bound collection reads through include or pagination.', {\n\t\t\tbounded:\n\t\t\t\t'Use include(...).execute(limit) or bounded pagination; do not collect() or resolve() an unbounded query.',\n\t\t\torder:\n\t\t\t\t'Apply eligibility filters in the indexed query before take(), execute(), or paginate(); filtering a bounded result can omit eligible rows. Do not move the predicate automatically.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (node.callee.type !== 'MemberExpression') return\n\t\t\t\t\tconst name = propertyName(node.callee)\n\t\t\t\t\tconst origin = readProvenance(context, node.callee.object)\n\t\t\t\t\tif (name === 'filter' && origin === 'bounded')\n\t\t\t\t\t\tcontext.report({ node, messageId: 'order' })\n\t\t\t\t\tif (\n\t\t\t\t\t\t(name === 'collect' && (origin === 'stream' || origin === 'relationship')) ||\n\t\t\t\t\t\t(name === 'resolve' && origin === 'stream')\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'bounded' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-manual-id-projection': {\n\t\tmeta: metadata('Use the table DTO boundary to project public IDs.', {\n\t\t\tprojection:\n\t\t\t\t'Use toPublicDto(row, true) to include _id; do not add IDs manually after a table DTO parse or projection.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tObjectExpression(node) {\n\t\t\t\t\tconst dto = node.properties.some(\n\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\tproperty.type === 'SpreadElement' &&\n\t\t\t\t\t\t\treadProvenance(context, property.argument) === 'dto',\n\t\t\t\t\t)\n\t\t\t\t\tif (!dto) return\n\t\t\t\t\tfor (const property of node.properties) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t['id', '_id'].includes(\n\t\t\t\t\t\t\t\t(property.computed ? staticString(property.key) : exportName(property.key)) ?? '',\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'projection' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tAssignmentExpression(node) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.left.type === 'MemberExpression' &&\n\t\t\t\t\t\t['id', '_id'].includes(propertyName(node.left) ?? '') &&\n\t\t\t\t\t\treadProvenance(context, node.left.object) === 'dto'\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'projection' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-copied-pagination': {\n\t\tmeta: metadata('Use native or table pagination schemas instead of copying their shape.', {\n\t\t\tpagination:\n\t\t\t\t'Use the native paginationOptsValidator (or paginated(table.dto())) for native pagination, or table.paginationOpts(selection) for table queries; do not copy pagination fields.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tif (!(ref?.name === 'object' && ['zod', 'zod/v4', 'convex/values'].includes(ref.source)))\n\t\t\t\t\t\treturn\n\t\t\t\t\tconst argument = node.arguments[0]\n\t\t\t\t\tconst fieldsNode = argument && (localInitializer(context, argument) ?? argument)\n\t\t\t\t\tif (fieldsNode?.type !== 'ObjectExpression') return\n\t\t\t\t\tconst fields = new Set(\n\t\t\t\t\t\tfieldsNode.properties.flatMap((property) =>\n\t\t\t\t\t\t\tproperty.type === 'Property'\n\t\t\t\t\t\t\t\t? [property.computed ? staticString(property.key) : exportName(property.key)]\n\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tif (\n\t\t\t\t\t\t(fields.has('numItems') && fields.has('cursor')) ||\n\t\t\t\t\t\t['page', 'isDone', 'continueCursor'].every((field) => fields.has(field))\n\t\t\t\t\t)\n\t\t\t\t\t\tcontext.report({ node, messageId: 'pagination' })\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-manual-timestamps': {\n\t\tmeta: metadata('Let timestamps triggers own createdAt and updatedAt.', {\n\t\t\ttimestamp: 'Remove {{field}} from this write; register the timestamps trigger instead.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (componentRoot(context, context.filename)) return {}\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tif (!isDbWrite(node)) return\n\t\t\t\t\tconst data = node.arguments.at(-1)\n\t\t\t\t\tif (data?.type !== 'ObjectExpression') return\n\t\t\t\t\tfor (const property of data.properties) {\n\t\t\t\t\t\tif (property.type !== 'Property') continue\n\t\t\t\t\t\tconst field = property.computed ? staticString(property.key) : exportName(property.key)\n\t\t\t\t\t\tif (field === 'createdAt' || field === 'updatedAt')\n\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'timestamp', data: { field } })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'component-boundaries': {\n\t\tmeta: metadata('Keep portable components isolated and consume their client facades.', {\n\t\t\tboundary:\n\t\t\t\t'Components may import only their own files and npm dependencies; inject host policy through the client API.',\n\t\t\tfacade: 'Import a component through its client.ts facade, not its private implementation.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tconst owner = componentRoot(context, context.filename)\n\t\t\tconst resolver = createResolver()\n\n\t\t\treturn sourceVisitors(context, (node, specifier) => {\n\t\t\t\tif (!specifier.startsWith('.')) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t/^cvx-kit\\/components\\/[^/]+\\//.test(specifier) &&\n\t\t\t\t\t\t!/^cvx-kit\\/components\\/[^/]+\\/convex\\.config(?:\\.js)?$/.test(specifier)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'facade' })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst target = resolveImport(resolver, context.filename, specifier)\n\t\t\t\tif (!target || target.split(sep).includes('node_modules')) return\n\t\t\t\tif (\n\t\t\t\t\towner &&\n\t\t\t\t\t(relative(owner, target).startsWith(`..${sep}`) || target === dirname(owner))\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({ node, messageId: 'boundary' })\n\t\t\t\t} else if (\n\t\t\t\t\t!owner &&\n\t\t\t\t\tcomponentRoot(context, target) &&\n\t\t\t\t\t!/^client(?:\\.[cm]?[jt]s)?$/.test(basename(target)) &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tappFile(context) === 'convex.config.ts' &&\n\t\t\t\t\t\t/^convex\\.config(?:\\.[cm]?[jt]s)?$/.test(basename(target))\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({ node, messageId: 'facade' })\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t},\n\t'no-component-env': {\n\t\tmeta: metadata('Pass environment configuration into portable components.', {\n\t\t\tenv: 'Portable components must receive configuration through arguments; do not read process.env.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tif (!componentRoot(context, context.filename)) return {}\n\t\t\tfunction isProcess(node: ESTree.Node) {\n\t\t\t\tif (node.type !== 'Identifier') return false\n\t\t\t\tconst variable = binding(context, node)\n\t\t\t\tif (node.name === 'process' && !variable?.defs.length) return true\n\t\t\t\treturn variable?.defs.some(\n\t\t\t\t\t(def) =>\n\t\t\t\t\t\tdef.type === 'ImportBinding' &&\n\t\t\t\t\t\tdef.parent?.type === 'ImportDeclaration' &&\n\t\t\t\t\t\t['node:process', 'process'].includes(def.parent.source.value) &&\n\t\t\t\t\t\t['ImportDefaultSpecifier', 'ImportNamespaceSpecifier'].includes(def.node.type),\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tImportDeclaration(node) {\n\t\t\t\t\tif (['node:process', 'process'].includes(node.source.value)) {\n\t\t\t\t\t\tfor (const specifier of node.specifiers) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tspecifier.type === 'ImportSpecifier' &&\n\t\t\t\t\t\t\t\texportName(specifier.imported) === 'env'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'env' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tMemberExpression(node) {\n\t\t\t\t\tif (propertyName(node) !== 'env') return\n\t\t\t\t\tconst object = node.object\n\t\t\t\t\tconst globalProcess =\n\t\t\t\t\t\tobject.type === 'MemberExpression' &&\n\t\t\t\t\t\tpropertyName(object) === 'process' &&\n\t\t\t\t\t\tobject.object.type === 'Identifier' &&\n\t\t\t\t\t\tobject.object.name === 'globalThis' &&\n\t\t\t\t\t\t!binding(context, object.object)?.defs.length\n\t\t\t\t\tif (isProcess(object) || globalProcess) context.report({ node, messageId: 'env' })\n\t\t\t\t},\n\t\t\t\tVariableDeclarator(node) {\n\t\t\t\t\tif (node.init && isProcess(node.init) && node.id.type === 'ObjectPattern') {\n\t\t\t\t\t\tfor (const property of node.id.properties) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t(property.computed ? staticString(property.key) : exportName(property.key)) ===\n\t\t\t\t\t\t\t\t\t'env'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: property, messageId: 'env' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'schema-file-boundaries': {\n\t\tmeta: metadata('Keep storage shapes and indexes in their documented owners.', {\n\t\t\tschema: '{{builder}} belongs in {{file}}.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tCallExpression(node) {\n\t\t\t\t\tconst ref = imported(context, node.callee)\n\t\t\t\t\tconst file = appFile(context)\n\t\t\t\t\tif (!file) return\n\t\t\t\t\tlet expected: string | null = null\n\t\t\t\t\tif (ref?.source === 'convex/server') {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tref.name === 'defineSchema' &&\n\t\t\t\t\t\t\tfile !== 'schema.ts' &&\n\t\t\t\t\t\t\t!(componentRoot(context, context.filename) && basename(file) === 'schema.ts')\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\texpected = 'the root schema.ts (or a component schema.ts)'\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tref.name === 'defineTable' &&\n\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\tcomponentRoot(context, context.filename) &&\n\t\t\t\t\t\t\t\t['schema.ts', 'table.ts'].includes(basename(file))\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\texpected =\n\t\t\t\t\t\t\t\t'a component schema.ts/table.ts; host tables use zodTable in domain/<module>/schema.ts'\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tref &&\n\t\t\t\t\t\t['cvx-kit', 'cvx-kit/zod-table'].includes(ref.source) &&\n\t\t\t\t\t\t['zodTable', 'tenantTable', 'zodVariantTable'].includes(ref.name) &&\n\t\t\t\t\t\t!/^domain\\/[^/]+\\/schema\\.ts$/.test(file)\n\t\t\t\t\t)\n\t\t\t\t\t\texpected = 'domain/<module>/schema.ts'\n\t\t\t\t\tif (expected)\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'schema',\n\t\t\t\t\t\t\tdata: { builder: ref?.name ?? 'table', file: expected },\n\t\t\t\t\t\t})\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.callee.type === 'MemberExpression' &&\n\t\t\t\t\t\t['index', 'searchIndex', 'vectorIndex'].includes(propertyName(node.callee) ?? '') &&\n\t\t\t\t\t\tisTableChain(node.callee.object) &&\n\t\t\t\t\t\t!componentRoot(context, context.filename) &&\n\t\t\t\t\t\t!/^domain\\/[^/]+\\/table\\.ts$/.test(file)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tmessageId: 'schema',\n\t\t\t\t\t\t\tdata: { builder: 'Table indexes', file: 'domain/<module>/table.ts' },\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'no-internal-reexports': {\n\t\tmeta: metadata('Import from owning modules directly; consumer apps have no barrels.', {\n\t\t\treexport: 'Import from the owning file directly; do not re-export imports inside convex/.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\tfunction check(node: ESTree.ExportNamedDeclaration | ESTree.ExportAllDeclaration) {\n\t\t\t\tif (node.source) {\n\t\t\t\t\tcontext.report({ node, messageId: 'reexport' })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tfor (const specifier of node.type === 'ExportNamedDeclaration' ? node.specifiers : []) {\n\t\t\t\t\tif (binding(context, specifier.local)?.defs.some((def) => def.type === 'ImportBinding')) {\n\t\t\t\t\t\tcontext.report({ node: specifier, messageId: 'reexport' })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tExportNamedDeclaration: check,\n\t\t\t\tExportAllDeclaration: check,\n\t\t\t\tExportDefaultDeclaration(node) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.declaration.type === 'Identifier' &&\n\t\t\t\t\t\tbinding(context, node.declaration)?.defs.some((def) => def.type === 'ImportBinding')\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontext.report({ node, messageId: 'reexport' })\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'public-api-first': {\n\t\tmeta: metadata('Place private helper implementations after the exported API.', {\n\t\t\torder:\n\t\t\t\t'Move this private helper below the exported API so the file reads from public purpose to implementation.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exports = exportedNames(node)\n\t\t\t\t\tconst lastExport = node.body.findLastIndex((statement) =>\n\t\t\t\t\t\tstatement.type.startsWith('Export'),\n\t\t\t\t\t)\n\t\t\t\t\tfor (const statement of node.body.slice(0, lastExport < 0 ? 0 : lastExport)) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstatement.type === 'FunctionDeclaration' &&\n\t\t\t\t\t\t\tstatement.id &&\n\t\t\t\t\t\t\t!exports.has(statement.id.name)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontext.report({ node: statement, messageId: 'order' })\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n\t'named-private-helpers': {\n\t\tmeta: metadata('Use named declarations for top-level private helper functions.', {\n\t\t\thelper: 'Declare this private helper with function name(...) at the bottom of the file.',\n\t\t}),\n\t\tcreate(context) {\n\t\t\treturn {\n\t\t\t\tProgram(node) {\n\t\t\t\t\tconst exports = exportedNames(node)\n\t\t\t\t\tfor (const statement of node.body) {\n\t\t\t\t\t\tif (statement.type !== 'VariableDeclaration') continue\n\t\t\t\t\t\tfor (const declaration of statement.declarations) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tdeclaration.id.type === 'Identifier' &&\n\t\t\t\t\t\t\t\t!exports.has(declaration.id.name) &&\n\t\t\t\t\t\t\t\t(declaration.init?.type === 'ArrowFunctionExpression' ||\n\t\t\t\t\t\t\t\t\tdeclaration.init?.type === 'FunctionExpression')\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontext.report({ node: declaration, messageId: 'helper' })\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t},\n}\n\nexport const rules: Record<RuleName, Rule> = scopeRules(applicationRules)\nconst plugin: Plugin = { meta: { name: 'cvx' }, rules }\nexport default plugin\n\nfunction scopeRules(source: Record<RuleName, CreateRule>): Record<RuleName, Rule> {\n\tconst scoped = { ...source }\n\t// SAFETY: source is the closed applicationRules record; its own keys are exactly RuleName.\n\tconst names = Object.keys(source) as RuleName[]\n\tfor (const name of names) {\n\t\tconst rule = source[name]\n\t\tscoped[name] = {\n\t\t\tmeta: {\n\t\t\t\t...rule.meta,\n\t\t\t\tschema: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\tproperties: { convexDir: { type: 'string', minLength: 1 } },\n\t\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tcreate(context) {\n\t\t\t\tconst file = appFile(context)\n\t\t\t\tif (\n\t\t\t\t\t!file ||\n\t\t\t\t\t/(?:^|\\/)(?:_generated|__tests__)(?:\\/|$)/.test(file) ||\n\t\t\t\t\t/\\.(?:test|spec)\\.[cm]?[jt]s$/.test(file)\n\t\t\t\t)\n\t\t\t\t\treturn {}\n\t\t\t\treturn rule.create(context)\n\t\t\t},\n\t\t}\n\t}\n\treturn scoped\n}\n"],"mappings":"sqBAiCA,SAAgBA,EAAkB,EAA+B,CAAC,EAA6B,CAC9F,IAAK,IAAMC,KAAYC,EAAQ,YAAc,CAAC,EAAGC,EAAcF,CAAQ,EACvE,OAAOG,EAAoBF,CAAO,CACnC,CAyoBA,MAAaG,EAAgCC,EAAW,CAhnBvD,GAAGC,EACH,mBAAoB,CACnB,GAAGA,EAAe,oBAClB,OAAO,EAAS,CACf,IAAMC,EAAOC,EAAQC,CAAO,GAAK,GAejC,MAdI,CAAC,eAAgB,aAAa,CAAC,CAAC,SAASF,CAAI,EAC5CG,EAAsBH,EAAME,EAAQ,WAAW,IAAI,EAAU,CAAC,EAC3D,CACN,QAAQ,EAAM,CACbA,EAAQ,OAAO,CACd,OACA,UAAW,YACX,KAAM,CACL,OAAQ,GAAGF,EAAK,oFACjB,CACD,CAAC,CACF,CACD,EAEMD,EAAe,mBAAmB,CAAC,OAAOG,CAAO,CACzD,CACD,E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EAErB4C,EAAQ,OAAO,KAAK5C,CAAM,EAChC,IAAK,IAAME,KAAQ0C,EAAO,CACzB,IAAMC,EAAO7C,EAAOE,GACpB,EAAOA,GAAQ,CACd,KAAM,CACL,GAAG2C,EAAK,KACR,OAAQ,CACP,CACC,KAAM,SACN,WAAY,CAAE,UAAW,CAAE,KAAM,SAAU,UAAW,CAAE,CAAE,EAC1D,qBAAsB,EACvB,CACD,CACD,EACA,OAAO,EAAS,CACf,IAAM9D,EAAOC,EAAQC,CAAO,EAO5B,MALC,CAACF,GACD,2CAA2C,KAAKA,CAAI,GACpD,+BAA+B,KAAKA,CAAI,EAEjC,CAAC,EACF8D,EAAK,OAAO5D,CAAO,CAC3B,CACD,CACD,CACA,OAAO0D,CACR"}
|
|
@@ -5,6 +5,20 @@ import { GenericSchema, SchemaDefinition } from "convex/server";
|
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { Value } from "convex/values";
|
|
7
7
|
//#region src/querying/planner.d.ts
|
|
8
|
+
interface SelectionTree {
|
|
9
|
+
[name: string]: true | SelectionTree;
|
|
10
|
+
}
|
|
11
|
+
interface GroupTree {
|
|
12
|
+
relations: Record<string, GroupTree>;
|
|
13
|
+
}
|
|
14
|
+
/** What one cursor binding can depend on: a root, the path to its table and what it reads there. */
|
|
15
|
+
export interface RegistryScope {
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly path: readonly string[];
|
|
18
|
+
readonly selection: SelectionTree;
|
|
19
|
+
readonly groups: GroupTree;
|
|
20
|
+
readonly filters: readonly FilterAst[];
|
|
21
|
+
}
|
|
8
22
|
export type QueryInput = z.input<ReturnType<ReturnType<typeof getRelationExecutor>['pagination']>>;
|
|
9
23
|
export type StoredConstraint = NonNullable<QueryInput['filters']>;
|
|
10
24
|
export declare function createPlanner(schema: SchemaDefinition<GenericSchema, boolean>, relations: RelationRegistryIdentity): {
|
|
@@ -13,6 +27,7 @@ export declare function createPlanner(schema: SchemaDefinition<GenericSchema, bo
|
|
|
13
27
|
groups: (table: string, groups: GroupSelection) => GroupSelection;
|
|
14
28
|
validateDocument: (table: string, row: Record<string, import('convex/values').Value>) => void;
|
|
15
29
|
streamSchema: SchemaDefinition<GenericSchema, boolean>;
|
|
30
|
+
registryVersion: (scope: RegistryScope) => Promise<string>;
|
|
16
31
|
beforeLeaf(table: string): void;
|
|
17
32
|
complete(table: string, document: Record<string, Value>, permitted: boolean, residual: FilterAst, groups?: readonly string[]): any;
|
|
18
33
|
plan(table: string, input: QueryInput, conditions: readonly IndexCondition[], constraints: readonly StoredConstraint[], ordering?: string, traversal?: 'root' | 'relation'): {
|
|
@@ -44,5 +59,7 @@ export declare function createPlanner(schema: SchemaDefinition<GenericSchema, bo
|
|
|
44
59
|
};
|
|
45
60
|
};
|
|
46
61
|
export declare function scalarMatches(ast: FilterAst, document: Record<string, Value | undefined>): boolean;
|
|
62
|
+
/** Lowercase hex SHA-256 of the UTF-8 text. */
|
|
63
|
+
export declare function digest(text: string): Promise<string>;
|
|
47
64
|
//#endregion
|
|
48
65
|
//# sourceMappingURL=planner.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{evaluateFilter as e}from"./shared/evaluate.mjs";import{parseFilterPlan as t}from"./filters.mjs";import{getRelationExecutor as n,getRelationMetadata as r}from"../relations.mjs";import"convex/values";function i(e,i){let
|
|
1
|
+
import{evaluateFilter as e}from"./shared/evaluate.mjs";import{parseFilterPlan as t}from"./filters.mjs";import{getRelationExecutor as n,getRelationMetadata as r}from"../relations.mjs";import"convex/values";function i(e,i){let s=n(i);s.assertSchema(e.tables);let c=r(i),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;function d(e){let t=/* @__PURE__ */ new Set([e.root]),n=/* @__PURE__ */ new Map;function r(e,t){let r=c.declarations[e]?.[t];if(!r)throw Error(`INVALID_RELATION`);return n.set(JSON.stringify([e,t]),[e,t]),r.target}function i(e,t){for(let[n,a]of Object.entries(t)){let t=r(e,n);a!==!0&&i(t,a)}}function a(e,t){for(let[n,i]of Object.entries(t.relations))a(r(e,n),i)}function l(e,t){if(t.kind===`and`||t.kind===`or`)for(let n of t.children)l(e,n);else if(t.kind===`not`||t.kind===`variant`)l(e,t.child);else if(t.kind===`relation`){let n=r(e,t.name);t.predicate&&l(n,t.predicate)}}let d=e.root;for(let t of e.path)d=r(d,t);t.add(d),i(d,e.selection),a(d,e.groups);for(let t of e.filters)l(d,t);let f=JSON.stringify([[...t].sort(),[...n.keys()].sort()]),p=u.get(f);return p||(p=o(s.scopedIdentity([...t],[...n.values()])),u.size>=256&&u.clear(),u.set(f,p)),p}return{metadata:c,select:s.select,groups:s.groups,validateDocument:s.validateDocument,streamSchema:s.streamSchema,registryVersion:d,beforeLeaf(e){if(!Object.hasOwn(c.tables,e))throw Error(`Unknown query table`)},complete(e,t,n,r,i=[]){return s.project(e,t,()=>n&&a(r,t),i)},plan(e,n,r,i,a,o=`root`){if(!Object.hasOwn(c.tables,e))throw Error(`Unknown query table`);let u=l.get(e);u||(u=s.pagination(e),l.set(e,u));let d=i.length===1?i[0]:i.length?{and:i}:void 0,{args:f,compiled:p}=t(u,n,o===`relation`&&a===void 0?[]:c.tables[e].indexes,r,d,a);if(p.residual.kind!==`and`)throw Error(`Invalid compiled filter root`);let[m,h]=p.residual.children,g={kind:`and`,children:[]},_={kind:`and`,children:[m,g]},v=p.sets.size?{kind:`and`,children:[h,g],traversal:{version:2,expansion:p.expansion}}:{kind:`and`,children:[h,g]};return{...p,args:f,clientIdentity:_,serverIdentity:v}}}}function a(t,n){return e(t,n)===!0}async function o(e){return Array.from(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))),e=>e.toString(16).padStart(2,`0`)).join(``)}export{i as createPlanner,o as digest,a as scalarMatches};
|
|
2
2
|
//# sourceMappingURL=planner.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.mjs","names":["createPlanner","owned","getRelationExecutor","relations","schema","metadata","getRelationMetadata","inputs","table","document","permitted","scalarMatches","residual","groups","validator","where","constraints","parseFilterPlan","input","traversal","ordering","conditions","compiled","client","server","empty","clientIdentity","serverIdentity","evaluateFilter","ast"],"sources":["../../src/querying/planner.ts"],"sourcesContent":["import { evaluateFilter } from './shared/evaluate'\nimport type { z } from 'zod'\nimport type { SchemaDefinition, GenericSchema } from 'convex/server'\nimport { type Value } from 'convex/values'\nimport {\n\tgetRelationExecutor,\n\tgetRelationMetadata,\n\ttype RelationRegistryIdentity,\n} from '../relations'\nimport { parseFilterPlan, type FilterAst, type IndexCondition } from './filters'\n\nexport type QueryInput = z.input<ReturnType<ReturnType<typeof getRelationExecutor>['pagination']>>\nexport type StoredConstraint = NonNullable<QueryInput['filters']>\n\nexport function createPlanner(\n\tschema: SchemaDefinition<GenericSchema, boolean>,\n\trelations: RelationRegistryIdentity,\n) {\n\tconst owned = getRelationExecutor(relations)\n\towned.assertSchema(schema.tables)\n\tconst metadata = getRelationMetadata(relations)\n\t// Build each immutable filter grammar only when that table is queried. Engine\n\t// declarations also load in mutations, which never need pagination validators.\n\tconst inputs = new Map<string, ReturnType<typeof owned.pagination>>()\n\treturn {\n\t\tmetadata,\n\t\tselect: owned.select,\n\t\tgroups: owned.groups,\n\t\tvalidateDocument: owned.validateDocument,\n\t\tstreamSchema: owned.streamSchema,\n\t\tbeforeLeaf(table: string) {\n\t\t\tif (!Object.hasOwn(metadata.tables, table)) throw new Error('Unknown query table')\n\t\t},\n\t\tcomplete(\n\t\t\ttable: string,\n\t\t\tdocument: Record<string, Value>,\n\t\t\tpermitted: boolean,\n\t\t\tresidual: FilterAst,\n\t\t\tgroups: readonly string[] = [],\n\t\t) {\n\t\t\treturn owned.project(\n\t\t\t\ttable,\n\t\t\t\tdocument,\n\t\t\t\t() => permitted && scalarMatches(residual, document),\n\t\t\t\tgroups,\n\t\t\t)\n\t\t},\n\t\tplan(\n\t\t\ttable: string,\n\t\t\tinput: QueryInput,\n\t\t\tconditions: readonly IndexCondition[],\n\t\t\tconstraints: readonly StoredConstraint[],\n\t\t\tordering?: string,\n\t\t\ttraversal: 'root' | 'relation' = 'root',\n\t\t) {\n\t\t\tif (!Object.hasOwn(metadata.tables, table)) throw new Error('Unknown query table')\n\t\t\tlet validator = inputs.get(table)\n\t\t\tif (!validator) {\n\t\t\t\tvalidator = owned.pagination(table)\n\t\t\t\tinputs.set(table, validator)\n\t\t\t}\n\t\t\t// Server constraints are independently validated against stored fields,\n\t\t\t// not the endpoint's public input/filter mask. Client values cannot replace them.\n\t\t\tconst where =\n\t\t\t\tconstraints.length === 1\n\t\t\t\t\t? constraints[0]\n\t\t\t\t\t: constraints.length\n\t\t\t\t\t\t? { and: constraints }\n\t\t\t\t\t\t: undefined\n\t\t\tconst { args, compiled } = parseFilterPlan(\n\t\t\t\tvalidator,\n\t\t\t\tinput,\n\t\t\t\ttraversal === 'relation' && ordering === undefined ? [] : metadata.tables[table].indexes,\n\t\t\t\tconditions,\n\t\t\t\twhere,\n\t\t\t\tordering,\n\t\t\t)\n\t\t\tif (compiled.residual.kind !== 'and') throw new Error('Invalid compiled filter root')\n\t\t\tconst [client, server] = compiled.residual.children\n\t\t\tconst empty: FilterAst = { kind: 'and', children: [] }\n\t\t\tconst clientIdentity = { kind: 'and', children: [client, empty] }\n\t\t\tconst serverIdentity = compiled.sets.size\n\t\t\t\t? {\n\t\t\t\t\t\tkind: 'and',\n\t\t\t\t\t\tchildren: [server, empty],\n\t\t\t\t\t\ttraversal: { version: 2, expansion: compiled.expansion },\n\t\t\t\t\t}\n\t\t\t\t: { kind: 'and', children: [server, empty] }\n\t\t\t// SAFETY: normalized AST nodes contain only validated native scalar Values.\n\t\t\treturn {\n\t\t\t\t...compiled,\n\t\t\t\targs,\n\t\t\t\tclientIdentity: clientIdentity as Value,\n\t\t\t\tserverIdentity: serverIdentity as Value,\n\t\t\t}\n\t\t},\n\t}\n}\n\nexport function scalarMatches(\n\tast: FilterAst,\n\tdocument: Record<string, Value | undefined>,\n): boolean {\n\treturn evaluateFilter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AAM,MACN,SAAU,CAACE,EAAQC,CAAK,EACxB,UAAW,CAAE,QAAS,EAAG,UAAWH,EAAS,SAAU,CACxD,EACC,CAAE,KAAM,MAAO,SAAU,CAACE,EAAQC,CAAK,CAAE,EAE5C,MAAO,CACN,GAAGH,EACH,OACgB,iBACA,gBACjB,CACD,CACD,CACD,CAEA,SAAgBX,EACf,EACA,EACU,CACV,OAAOiB,EAAeC,EAAKpB,CAAQ,IAAM,EAC1C"}
|
|
1
|
+
{"version":3,"file":"planner.mjs","names":["createPlanner","owned","getRelationExecutor","relations","schema","metadata","getRelationMetadata","inputs","versions","registryVersion","tables","scope","edges","walk","edge","table","name","select","nested","selection","target","group","groups","filter","ast","child","key","version","digest","document","permitted","scalarMatches","residual","validator","where","constraints","parseFilterPlan","input","traversal","ordering","conditions","compiled","client","server","empty","clientIdentity","serverIdentity","evaluateFilter","text","byte"],"sources":["../../src/querying/planner.ts"],"sourcesContent":["import { evaluateFilter } from './shared/evaluate'\nimport type { z } from 'zod'\nimport type { SchemaDefinition, GenericSchema } from 'convex/server'\nimport { type Value } from 'convex/values'\nimport {\n\tgetRelationExecutor,\n\tgetRelationMetadata,\n\ttype RelationRegistryIdentity,\n} from '../relations'\nimport { parseFilterPlan, type FilterAst, type IndexCondition } from './filters'\n\ninterface SelectionTree {\n\t[name: string]: true | SelectionTree\n}\ninterface GroupTree {\n\trelations: Record<string, GroupTree>\n}\n/** What one cursor binding can depend on: a root, the path to its table and what it reads there. */\nexport interface RegistryScope {\n\treadonly root: string\n\treadonly path: readonly string[]\n\treadonly selection: SelectionTree\n\treadonly groups: GroupTree\n\treadonly filters: readonly FilterAst[]\n}\n\nexport type QueryInput = z.input<ReturnType<ReturnType<typeof getRelationExecutor>['pagination']>>\nexport type StoredConstraint = NonNullable<QueryInput['filters']>\n\nexport function createPlanner(\n\tschema: SchemaDefinition<GenericSchema, boolean>,\n\trelations: RelationRegistryIdentity,\n) {\n\tconst owned = getRelationExecutor(relations)\n\towned.assertSchema(schema.tables)\n\tconst metadata = getRelationMetadata(relations)\n\t// Build each immutable filter grammar only when that table is queried. Engine\n\t// declarations also load in mutations, which never need pagination validators.\n\tconst inputs = new Map<string, ReturnType<typeof owned.pagination>>()\n\t// Digests per used scope; a scope is a few sorted names, so the cap only bounds abuse.\n\tconst versions = new Map<string, Promise<string>>()\n\t/**\n\t * The registry version a cursor binds: a digest of the identity of every table\n\t * and edge the query can read. That is its table, the path edges to it, and\n\t * every edge its selection, field groups and relation filters walk, with the\n\t * tables those edges touch. Nothing else can change what such a cursor means.\n\t */\n\tfunction registryVersion(scope: RegistryScope): Promise<string> {\n\t\tconst tables = new Set([scope.root])\n\t\tconst edges = new Map<string, readonly [string, string]>()\n\t\tfunction walk(table: string, name: string): string {\n\t\t\tconst edge = metadata.declarations[table]?.[name]\n\t\t\tif (!edge) throw new Error('INVALID_RELATION')\n\t\t\tedges.set(JSON.stringify([table, name]), [table, name])\n\t\t\treturn edge.target\n\t\t}\n\t\tfunction select(table: string, selection: SelectionTree): void {\n\t\t\tfor (const [name, nested] of Object.entries(selection)) {\n\t\t\t\tconst target = walk(table, name)\n\t\t\t\tif (nested !== true) select(target, nested)\n\t\t\t}\n\t\t}\n\t\tfunction group(table: string, groups: GroupTree): void {\n\t\t\tfor (const [name, nested] of Object.entries(groups.relations))\n\t\t\t\tgroup(walk(table, name), nested)\n\t\t}\n\t\tfunction filter(table: string, ast: FilterAst): void {\n\t\t\tif (ast.kind === 'and' || ast.kind === 'or')\n\t\t\t\tfor (const child of ast.children) filter(table, child)\n\t\t\telse if (ast.kind === 'not' || ast.kind === 'variant') filter(table, ast.child)\n\t\t\telse if (ast.kind === 'relation') {\n\t\t\t\tconst target = walk(table, ast.name)\n\t\t\t\tif (ast.predicate) filter(target, ast.predicate)\n\t\t\t}\n\t\t}\n\t\tlet table = scope.root\n\t\tfor (const name of scope.path) table = walk(table, name)\n\t\ttables.add(table)\n\t\tselect(table, scope.selection)\n\t\tgroup(table, scope.groups)\n\t\tfor (const ast of scope.filters) filter(table, ast)\n\t\tconst key = JSON.stringify([[...tables].sort(), [...edges.keys()].sort()])\n\t\tlet version = versions.get(key)\n\t\tif (!version) {\n\t\t\tversion = digest(owned.scopedIdentity([...tables], [...edges.values()]))\n\t\t\tif (versions.size >= 256) versions.clear()\n\t\t\tversions.set(key, version)\n\t\t}\n\t\treturn version\n\t}\n\treturn {\n\t\tmetadata,\n\t\tselect: owned.select,\n\t\tgroups: owned.groups,\n\t\tvalidateDocument: owned.validateDocument,\n\t\tstreamSchema: owned.streamSchema,\n\t\tregistryVersion,\n\t\tbeforeLeaf(table: string) {\n\t\t\tif (!Object.hasOwn(metadata.tables, table)) throw new Error('Unknown query table')\n\t\t},\n\t\tcomplete(\n\t\t\ttable: string,\n\t\t\tdocument: Record<string, Value>,\n\t\t\tpermitted: boolean,\n\t\t\tresidual: FilterAst,\n\t\t\tgroups: readonly string[] = [],\n\t\t) {\n\t\t\treturn owned.project(\n\t\t\t\ttable,\n\t\t\t\tdocument,\n\t\t\t\t() => permitted && scalarMatches(residual, document),\n\t\t\t\tgroups,\n\t\t\t)\n\t\t},\n\t\tplan(\n\t\t\ttable: string,\n\t\t\tinput: QueryInput,\n\t\t\tconditions: readonly IndexCondition[],\n\t\t\tconstraints: readonly StoredConstraint[],\n\t\t\tordering?: string,\n\t\t\ttraversal: 'root' | 'relation' = 'root',\n\t\t) {\n\t\t\tif (!Object.hasOwn(metadata.tables, table)) throw new Error('Unknown query table')\n\t\t\tlet validator = inputs.get(table)\n\t\t\tif (!validator) {\n\t\t\t\tvalidator = owned.pagination(table)\n\t\t\t\tinputs.set(table, validator)\n\t\t\t}\n\t\t\t// Server constraints are independently validated against stored fields,\n\t\t\t// not the endpoint's public input/filter mask. Client values cannot replace them.\n\t\t\tconst where =\n\t\t\t\tconstraints.length === 1\n\t\t\t\t\t? constraints[0]\n\t\t\t\t\t: constraints.length\n\t\t\t\t\t\t? { and: constraints }\n\t\t\t\t\t\t: undefined\n\t\t\tconst { args, compiled } = parseFilterPlan(\n\t\t\t\tvalidator,\n\t\t\t\tinput,\n\t\t\t\ttraversal === 'relation' && ordering === undefined ? [] : metadata.tables[table].indexes,\n\t\t\t\tconditions,\n\t\t\t\twhere,\n\t\t\t\tordering,\n\t\t\t)\n\t\t\tif (compiled.residual.kind !== 'and') throw new Error('Invalid compiled filter root')\n\t\t\tconst [client, server] = compiled.residual.children\n\t\t\tconst empty: FilterAst = { kind: 'and', children: [] }\n\t\t\tconst clientIdentity = { kind: 'and', children: [client, empty] }\n\t\t\tconst serverIdentity = compiled.sets.size\n\t\t\t\t? {\n\t\t\t\t\t\tkind: 'and',\n\t\t\t\t\t\tchildren: [server, empty],\n\t\t\t\t\t\ttraversal: { version: 2, expansion: compiled.expansion },\n\t\t\t\t\t}\n\t\t\t\t: { kind: 'and', children: [server, empty] }\n\t\t\t// SAFETY: normalized AST nodes contain only validated native scalar Values.\n\t\t\treturn {\n\t\t\t\t...compiled,\n\t\t\t\targs,\n\t\t\t\tclientIdentity: clientIdentity as Value,\n\t\t\t\tserverIdentity: serverIdentity as Value,\n\t\t\t}\n\t\t},\n\t}\n}\n\nexport function scalarMatches(\n\tast: FilterAst,\n\tdocument: Record<string, Value | undefined>,\n): boolean {\n\treturn evaluateFilter(ast, document) === true\n}\n\n/** Lowercase hex SHA-256 of the UTF-8 text. */\nexport async function digest(text: string): Promise<string> {\n\treturn Array.from(\n\t\tnew Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))),\n\t\t(byte) => byte.toString(16).padStart(2, '0'),\n\t).join('')\n}\n"],"mappings":"6MA6BA,SAAgBA,EACf,EACA,EACC,CACD,IAAMC,EAAQC,EAAoBC,CAAS,EAC3CF,EAAM,aAAaG,EAAO,MAAM,EAChC,IAAMC,EAAWC,EAAoBH,CAAS,EAGxCI,kBAAS,IAAI,IAEbC,kBAAW,IAAI,IAOrB,SAASC,EAAgB,EAAuC,CAC/D,IAAMC,kBAAS,IAAI,IAAI,CAACC,EAAM,IA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AACC,EAAQC,GAAUF,EAAS,SAAS,SACrCG,EAAmB,CAAE,KAAM,MAAO,SAAU,CAAC,CAAE,EAC/CC,EAAiB,CAAE,KAAM,MAAO,SAAU,CAACH,EAAQE,CAAK,CAAE,EAC1DE,EAAiBL,EAAS,KAAK,KAClC,CACA,KAAM,MACN,SAAU,CAACE,EAAQC,CAAK,EACxB,UAAW,CAAE,QAAS,EAAG,UAAWH,EAAS,SAAU,CACxD,EACC,CAAE,KAAM,MAAO,SAAU,CAACE,EAAQC,CAAK,CAAE,EAE5C,MAAO,CACN,GAAGH,EACH,OACgB,iBACA,gBACjB,CACD,CACD,CACD,CAEA,SAAgBV,EACf,EACA,EACU,CACV,OAAOgB,EAAevB,EAAKK,CAAQ,IAAM,EAC1C,CAGA,eAAsBD,EAAO,EAA+B,CAC3D,OAAO,MAAM,KACZ,IAAI,WAAW,MAAM,OAAO,OAAO,OAAO,UAAW,IAAI,YAAY,CAAC,CAAC,OAAOoB,CAAI,CAAC,CAAC,EACnF,GAASC,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAC5C,CAAC,CAAC,KAAK,EAAE,CACV"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{expansionForIndex as e,rangeForIndex as t,withinRange as n}from"./filters.mjs";import{scalarMatches as r}from"./planner.mjs";import{CursorError as i}from"./cursors.mjs";import{executeStream as a,nativeIndexRange as o,rethrowQueryError as s}from"./execution.mjs";import{z as c}from"zod";import{compareValues as l}from"convex/values";import{EmptyStream as u,getIndexFields as d,stream as f}from"convex-helpers/server/stream";const p=c.object({cursor:c.string(),ancestors:c.array(c.string()).max(3)}).strict();var m=class extends Error{code;constructor(e){super(e),this.code=e,this.name=`RelationshipError`}};function h(e,t){for(let n of Object.values(e)){if(t>=4)throw new m(`INVALID_RELATION`);n!==!0&&h(n,t+1)}}function g(g,v,y,b,x,S){let C=y.metadata,w=e=>`base`in e?e.base:e;function T(e,t){let n=C.declarations[e]?.[t];if(!n)throw new m(`INVALID_RELATION`);return n}let E=(e,t)=>!t||e[t.discriminator]===t.tag,D=c.string();function O(e,t){if(!t)return!0;let n=D.safeParse(e);return n.success&&v.db.normalizeId(t.table,n.data)!==null}function k(e,t){if(!t||!E(t,e.sourceGuard))return;let n=t[w(e.from).field];return O(n,e.sourceMember)&&O(n,e.targetMember)?n:void 0}function A(e,t,n){let r=t===`_id`?{name:`by_id`,fields:[`_id`]}:C.tables[e].indexes.find(e=>{let r=e.fields.indexOf(t);return r>=0&&e.fields.slice(0,r).every(e=>e===n?.discriminator)});if(!r)throw new m(`INVALID_RELATION`);return r}function j(e,t){function n(e,t,n,r){S?.checkOrder(e,A(e,t,n).fields.filter(e=>e!==t&&e!==n?.discriminator),r)}`base`in e.from&&`base`in e.to?(n(e.from.junction.table,e.from.junction.field,e.junctionGuard),n(e.target,e.to.base.field,e.targetGuard,t)):n(e.target,w(e.to).field,e.targetGuard,t)}function M(e,t,n,r,i){let a=t===`_id`?[{name:`by_id`,fields:[`_id`]}]:C.tables[e].indexes,o=e=>e===t||e===i?.discriminator||n.bindings.has(e),s=e=>e.fields.includes(t)&&e.fields.slice(0,e.fields.indexOf(t)).every(o),c=e=>{let t=0;for(let n of e.fields){if(!o(n))break;t++}return t},l=r.find(e=>e.value!==null&&e.value!==void 0);if(l){let e=a.find(e=>e.name===l.index&&s(e));if(!e)throw Error(`Explicit index "${l.index}" is incompatible with declared relationship lookup`);return e}let u=a.filter(s).sort((e,t)=>c(t)-c(e)||Number(n.sets.has(t.fields[c(t)]))-Number(n.sets.has(e.fields[c(e)]))||Number(n.ranges.has(t.fields[c(t)]))-Number(n.ranges.has(e.fields[c(e)]))||e.name.localeCompare(t.name)||e.fields.join(`\0`).localeCompare(t.fields.join(`\0`)));if(!u.length)throw new m(`INVALID_RELATION`);return u[0]}function N(e,t,n,r,i){let a=[];for(let o of e.fields)if(o===t)a.push({field:o,value:n});else if(o===i?.discriminator)a.push({field:o,value:i.tag});else if(r?.bindings.has(o))a.push({field:o,value:r.bindings.get(o)});else break;return a}async function P(e,t){if(y.beforeLeaf(e),t==null||!v.db.normalizeId(e,t))return null;let n=await v.db.get(e,t);return n&&y.validateDocument(e,n),n}async function*F(e,t,n,r,i,a){if(v.expand(r,0),n==null||!O(n,a))return;if(t===`_id`){let o=await P(e,n);o&&E(o,i)&&O(o[t],a)&&(v.expand(r),yield o);return}y.beforeLeaf(e);let o=A(e,t,i),s=v.leafQuery(e).withIndex(o.name,e=>{let r=e;for(let e of N(o,t,n,void 0,i))r=r.eq(e.field,e.value);return r})[Symbol.asyncIterator]();try{for(;;){y.beforeLeaf(e);let n=await s.next();if(n.done)return;await v.authorize(e,n.value)&&(y.validateDocument(e,n.value),E(n.value,i)&&O(n.value[t],a)&&(v.expand(r),yield n.value))}}finally{await s.return?.()}}async function*I(e,t,n){v.expand(n,0);let r=k(e,t);if(r!=null){if(`base`in e.from&&`base`in e.to)for await(let t of F(e.from.junction.table,e.from.junction.field,r,n,e.junctionGuard))yield*F(e.target,e.to.base.field,t[e.to.junction.field],n,e.targetGuard);else yield*F(e.target,w(e.to).field,r,n,e.targetGuard,e.targetMember)}}async function L(e,t,n){let r=null;for await(let i of I(e,t,n)){if(r)throw new m(`AMBIGUOUS_RELATION`);r=i}return r}async function R(e,t,n,i=0){if(v.expand(i,0),C.tables[e].variant&&y.validateDocument(e,t),_(n))return r(n,t);if(n.kind===`variant`)return t[n.discriminator]===n.tag&&R(e,t,n.child,i);if(n.kind===`scalar`)return r(n,t);if(n.kind===`not`)return!await R(e,t,n.child,i);if(n.kind===`and`||n.kind===`or`){for(let r of n.children){let a=await R(e,t,r,i);if(n.kind===`and`&&!a)return!1;if(n.kind===`or`&&a)return!0}return n.kind===`and`}if(n.kind!==`relation`)throw new m(`INVALID_RELATION`);let a=T(e,n.name);if(n.mode===`one`){let e=await L(a,t,i+1);return n.predicate===null?e===null:e!==null&&await R(a.target,e,n.predicate,i+1)}for await(let e of I(a,t,i+1))if(await R(a.target,e,n.predicate,i+1))return n.mode===`some`;return n.mode===`none`}async function z(e,t,n,r,i=[],a=0,o=[]){v.expand(a,0);let s=y.complete(e,t,!0,{kind:`and`,children:[]},S?.allowed(i));for(let[c,l]of Object.entries(n)){let n=T(e,c),u=l===!0?{}:l;if(n.cardinality===`one`){let e=await L(n,t,a+1);s[c]=e?await z(n.target,e,u,r,[...i,c],a+1,[...o,t._id]):null}else s[c]=await V(e,t,c,u,{numItems:r.numItems,cursor:null,order:r.order},[],[],[...i,c],a+1,[...o,t._id])}return s}function B(t,n,r,a,o,s,c,l,u){if(u!==void 0&&o.some(e=>e.value!==null&&e.value!==void 0))throw Error(`orderBy cannot be combined with an active when selector`);y.select(T(t,n).target,r),h(r,c.length);let d=T(t,n);if(d.cardinality!==`many`)throw new m(`INVALID_RELATION`);let f=d.targetGuard?{fields:{[d.targetGuard.discriminator]:d.targetGuard.tag}}:void 0,g=y.plan(d.target,a,[],f?[...s,f]:s,u,`relation`),_=d.from,C=d.to,E=`base`in _&&`base`in C?{table:_.junction.table,field:_.junction.field,targetField:C.base.field,targetReference:C.junction.field}:null;if(u!==void 0&&E)throw Error(`orderBy is unsupported for junction relationships`);let D=E?E.table:d.target,O=E?E.field:w(C).field,k=M(d.target,E?E.targetField:O,g,u===void 0?o:[{value:!0,index:u}],d.targetGuard);S?.checkOrder(d.target,k.fields.filter(e=>e!==(E?E.targetField:O)&&e!==d.targetGuard?.discriminator&&!g.bindings.has(e)),c);let j=E?A(D,O,d.junctionGuard):k;E&&S?.checkOrder(D,j.fields.filter(e=>e!==O&&e!==d.junctionGuard?.discriminator));let P=E||g.unsatisfiable?null:e(j,N(j,O,null,g,d.targetGuard),g.sets,u!==void 0||o.some(e=>e.value!==null&&e.value!==void 0)),F={},I=S?.at(c);I&&(Object.keys(I.fieldGroups).length||Object.keys(I.relations).length)&&(F.fieldGroups=I);let L={...x,table:D,index:j.name,order:g.args.order??`asc`,clientFilters:g.clientIdentity,serverFilters:{predicates:g.sets.size?{predicates:g.serverIdentity,traversal:{version:2,expansion:P?{...P}:null}}:g.serverIdentity,selection:r,...F,scope:{...v.scope},rootTable:x.table,lookupIndex:k.name,guards:{source:d.sourceGuard?{...d.sourceGuard}:null,target:d.targetGuard?{...d.targetGuard}:null,junction:d.junctionGuard?{...d.junctionGuard}:null},...(d.sourceMember||d.targetMember)&&{members:{source:d.sourceMember?{...d.sourceMember}:null,target:d.targetMember?{...d.targetMember}:null}}},relationPath:c,parent:l};function R(e){try{return p.parse(JSON.parse(b.open(e,L)))}catch{throw new i}}return{declared:d,plan:g,through:E,sourceTable:D,field:O,index:j,targetIndex:k,binding:L,open:R,expansion:P}}async function V(e,r,i,s,c,p=[],m=[],h=[i],_=1,x=[],S=B(e,i,s,c,p,m,h,x[0]??r._id),C){v.expand(_,0);let{declared:T,plan:D,through:A,sourceTable:j,field:M,index:F,targetIndex:I,binding:L,expansion:V}=S,H=k(T,r),U={...D.args,...C??{cursor:null}},W={...D,expansion:V,index:F,prefix:H==null?[]:A?N(F,M,H,void 0,T.junctionGuard):N(F,M,H,D,T.targetGuard),unsatisfiable:H==null||D.unsatisfiable};if(W.range=A?null:t(F,W.prefix,D.ranges),!A)for(let e of W.prefix){let t=D.ranges.get(e.field);D.bindings.has(e.field)&&l(e.value,D.bindings.get(e.field))!==0&&(W.unsatisfiable=!0),t&&!n(e.value,t)&&(W.unsatisfiable=!0)}let G=A&&A.targetField!==`_id`;return await a(g,v,j,W,y,b,L,U,async(e,t)=>{if(t&&y.validateDocument(G?T.target:j,e),!t||A&&!G&&!E(e,T.junctionGuard))return null;v.expand(_);let n;return n=A&&!G?await P(T.target,e[A.targetReference]):e,!n||!E(n,T.targetGuard)||!O(n[w(T.to).field],T.targetMember)||!await R(T.target,n,D.residual,_)?null:z(T.target,n,s,D.args,h,_,x)},e=>b.seal(JSON.stringify({cursor:e,ancestors:x.slice(1)}),L),G?(e,n)=>{let r=g,i=d(T.target,I.name,r);return e.flatMap(async e=>{v.expand(_);let a=await v.authorize(j,e);a&&y.validateDocument(j,e);let s=e[A.targetReference];return!a||!E(e,T.junctionGuard)||s==null?new u(D.args.order??`asc`,i):f(n,r).query(T.target).withIndex(I.name,e=>{let n=N(I,A.targetField,s,D,T.targetGuard);return o(e,n,t(I,n,D.ranges))}).order(D.args.order??`asc`)},i)}:void 0,G?T.target:j)}async function H(e,t,n,r,a,o,c,u){if(!n.length||n.length>4||!v.db.normalizeId(e,t))throw new m(`INVALID_RELATION`);let d=e,f=n.map(e=>{let t=T(d,e);return d=t.target,t});if(u!==void 0&&f.some(e=>`base`in e.from||`base`in e.to))throw Error(`orderBy is unsupported for junction relationships`);let p=f.at(-1);for(let e of f.slice(0,-1))(e.cardinality===`one`||`base`in e.from||`base`in e.to)&&j(e);let h=B(p.source,n.at(-1),r,a,o,c,n,t,u),g=a.cursor===null?null:h.open(a.cursor),_=a.endCursor==null?null:h.open(a.endCursor),y=g?.ancestors??_?.ancestors??[];if(y.length!==n.length-1||g&&_&&JSON.stringify(g.ancestors)!==JSON.stringify(_.ancestors)||y.some((e,t)=>!v.db.normalizeId(f[t].target,e)))throw new i;try{let i=await P(e,t);for(let e=0;i&&e<y.length;e++){let t=f[e],n=null;if(t.cardinality===`many`&&!(`base`in t.from)&&!(`base`in t.to)){v.expand(e+1,0);let r=k(t,i),a=r==null?null:await P(t.target,y[e]),o=t.to.field;r!=null&&a&&E(a,t.targetGuard)&&O(a[o],t.targetMember)&&a[o]!==void 0&&l(r,a[o])===0&&(v.expand(e+1),n=a)}else if(t.cardinality===`one`){let r=await L(t,i,e+1);r?._id===y[e]&&(n=r)}else for await(let r of I(t,i,e+1))if(r._id===y[e]){n=r;break}i=n}return await V(p.source,i,n.at(-1),r,a,o,c,n,n.length,[t,...y],h,{cursor:g?.cursor??null,endCursor:_?.cursor??a.endCursor})}catch(e){s(e)}}function U(e,t,n,r=[]){for(let[i,a]of Object.entries(t)){let t=T(e,i),o=a===!0?{}:a,s=[...r,i];t.cardinality===`many`?B(e,i,o,{numItems:n.numItems,cursor:null,order:n.order},[],[],s,``):j(t,s),U(t.target,o,n,s)}}return{matches:R,output:z,continuation:H,edge:T,preflight:U}}function _(e){return e.kind===`relation`?!1:e.kind===`and`||e.kind===`or`?e.children.every(_):e.kind===`not`||e.kind===`variant`?_(e.child):!0}export{m as RelationshipError,h as assertRelationshipDepth,g as relationshipExecutor};
|
|
1
|
+
import{expansionForIndex as e,rangeForIndex as t,withinRange as n}from"./filters.mjs";import{scalarMatches as r}from"./planner.mjs";import{CursorError as i}from"./cursors.mjs";import{executeStream as a,nativeIndexRange as o,rethrowQueryError as s}from"./execution.mjs";import{z as c}from"zod";import{compareValues as l}from"convex/values";import{EmptyStream as u,getIndexFields as d,stream as f}from"convex-helpers/server/stream";const p={fieldGroups:{},relations:{}},m=c.object({cursor:c.string(),ancestors:c.array(c.string()).max(3)}).strict();var h=class extends Error{code;constructor(e){super(e),this.code=e,this.name=`RelationshipError`}};function g(e,t){for(let n of Object.values(e)){if(t>=4)throw new h(`INVALID_RELATION`);n!==!0&&g(n,t+1)}}function _(_,y,b,x,S,C){let w=b.metadata,T=e=>`base`in e?e.base:e;function E(e,t){let n=w.declarations[e]?.[t];if(!n)throw new h(`INVALID_RELATION`);return n}let D=(e,t)=>!t||e[t.discriminator]===t.tag,O=c.string();function k(e,t){if(!t)return!0;let n=O.safeParse(e);return n.success&&y.db.normalizeId(t.table,n.data)!==null}function A(e,t){if(!t||!D(t,e.sourceGuard))return;let n=t[T(e.from).field];return k(n,e.sourceMember)&&k(n,e.targetMember)?n:void 0}function j(e,t,n){let r=t===`_id`?{name:`by_id`,fields:[`_id`]}:w.tables[e].indexes.find(e=>{let r=e.fields.indexOf(t);return r>=0&&e.fields.slice(0,r).every(e=>e===n?.discriminator)});if(!r)throw new h(`INVALID_RELATION`);return r}function M(e,t){function n(e,t,n,r){C?.checkOrder(e,j(e,t,n).fields.filter(e=>e!==t&&e!==n?.discriminator),r)}`base`in e.from&&`base`in e.to?(n(e.from.junction.table,e.from.junction.field,e.junctionGuard),n(e.target,e.to.base.field,e.targetGuard,t)):n(e.target,T(e.to).field,e.targetGuard,t)}function N(e,t,n,r,i){let a=t===`_id`?[{name:`by_id`,fields:[`_id`]}]:w.tables[e].indexes,o=e=>e===t||e===i?.discriminator||n.bindings.has(e),s=e=>e.fields.includes(t)&&e.fields.slice(0,e.fields.indexOf(t)).every(o),c=e=>{let t=0;for(let n of e.fields){if(!o(n))break;t++}return t},l=r.find(e=>e.value!==null&&e.value!==void 0);if(l){let e=a.find(e=>e.name===l.index&&s(e));if(!e)throw Error(`Explicit index "${l.index}" is incompatible with declared relationship lookup`);return e}let u=a.filter(s).sort((e,t)=>c(t)-c(e)||Number(n.sets.has(t.fields[c(t)]))-Number(n.sets.has(e.fields[c(e)]))||Number(n.ranges.has(t.fields[c(t)]))-Number(n.ranges.has(e.fields[c(e)]))||e.name.localeCompare(t.name)||e.fields.join(`\0`).localeCompare(t.fields.join(`\0`)));if(!u.length)throw new h(`INVALID_RELATION`);return u[0]}function P(e,t,n,r,i){let a=[];for(let o of e.fields)if(o===t)a.push({field:o,value:n});else if(o===i?.discriminator)a.push({field:o,value:i.tag});else if(r?.bindings.has(o))a.push({field:o,value:r.bindings.get(o)});else break;return a}async function F(e,t){if(b.beforeLeaf(e),t==null||!y.db.normalizeId(e,t))return null;let n=await y.db.get(e,t);return n&&b.validateDocument(e,n),n}async function*I(e,t,n,r,i,a){if(y.expand(r,0),n==null||!k(n,a))return;if(t===`_id`){let o=await F(e,n);o&&D(o,i)&&k(o[t],a)&&(y.expand(r),yield o);return}b.beforeLeaf(e);let o=j(e,t,i),s=y.leafQuery(e).withIndex(o.name,e=>{let r=e;for(let e of P(o,t,n,void 0,i))r=r.eq(e.field,e.value);return r})[Symbol.asyncIterator]();try{for(;;){b.beforeLeaf(e);let n=await s.next();if(n.done)return;await y.authorize(e,n.value)&&(b.validateDocument(e,n.value),D(n.value,i)&&k(n.value[t],a)&&(y.expand(r),yield n.value))}}finally{await s.return?.()}}async function*L(e,t,n){y.expand(n,0);let r=A(e,t);if(r!=null){if(`base`in e.from&&`base`in e.to)for await(let t of I(e.from.junction.table,e.from.junction.field,r,n,e.junctionGuard))yield*I(e.target,e.to.base.field,t[e.to.junction.field],n,e.targetGuard);else yield*I(e.target,T(e.to).field,r,n,e.targetGuard,e.targetMember)}}async function R(e,t,n){let r=null;for await(let i of L(e,t,n)){if(r)throw new h(`AMBIGUOUS_RELATION`);r=i}return r}async function z(e,t,n,i=0){if(y.expand(i,0),w.tables[e].variant&&b.validateDocument(e,t),v(n))return r(n,t);if(n.kind===`variant`)return t[n.discriminator]===n.tag&&z(e,t,n.child,i);if(n.kind===`scalar`)return r(n,t);if(n.kind===`not`)return!await z(e,t,n.child,i);if(n.kind===`and`||n.kind===`or`){for(let r of n.children){let a=await z(e,t,r,i);if(n.kind===`and`&&!a)return!1;if(n.kind===`or`&&a)return!0}return n.kind===`and`}if(n.kind!==`relation`)throw new h(`INVALID_RELATION`);let a=E(e,n.name);if(n.mode===`one`){let e=await R(a,t,i+1);return n.predicate===null?e===null:e!==null&&await z(a.target,e,n.predicate,i+1)}for await(let e of L(a,t,i+1))if(await z(a.target,e,n.predicate,i+1))return n.mode===`some`;return n.mode===`none`}async function B(e,t,n,r,i=[],a=0,o=[]){y.expand(a,0);let s=b.complete(e,t,!0,{kind:`and`,children:[]},C?.allowed(i));for(let[c,l]of Object.entries(n)){let n=E(e,c),u=l===!0?{}:l;if(n.cardinality===`one`){let e=await R(n,t,a+1);s[c]=e?await B(n.target,e,u,r,[...i,c],a+1,[...o,t._id]):null}else s[c]=await H(e,t,c,u,{numItems:r.numItems,cursor:null,order:r.order},[],[],[...i,c],a+1,[...o,t._id])}return s}function V(t,n,r,a,o,s,c,l,u){if(u!==void 0&&o.some(e=>e.value!==null&&e.value!==void 0))throw Error(`orderBy cannot be combined with an active when selector`);b.select(E(t,n).target,r),g(r,c.length);let d=E(t,n);if(d.cardinality!==`many`)throw new h(`INVALID_RELATION`);let f=d.targetGuard?{fields:{[d.targetGuard.discriminator]:d.targetGuard.tag}}:void 0,_=b.plan(d.target,a,[],f?[...s,f]:s,u,`relation`),v=d.from,w=d.to,D=`base`in v&&`base`in w?{table:v.junction.table,field:v.junction.field,targetField:w.base.field,targetReference:w.junction.field}:null;if(u!==void 0&&D)throw Error(`orderBy is unsupported for junction relationships`);let O=D?D.table:d.target,k=D?D.field:T(w).field,A=N(d.target,D?D.targetField:k,_,u===void 0?o:[{value:!0,index:u}],d.targetGuard);C?.checkOrder(d.target,A.fields.filter(e=>e!==(D?D.targetField:k)&&e!==d.targetGuard?.discriminator&&!_.bindings.has(e)),c);let M=D?j(O,k,d.junctionGuard):A;D&&C?.checkOrder(O,M.fields.filter(e=>e!==k&&e!==d.junctionGuard?.discriminator));let F=D||_.unsatisfiable?null:e(M,P(M,k,null,_,d.targetGuard),_.sets,u!==void 0||o.some(e=>e.value!==null&&e.value!==void 0)),I={},L=C?.at(c);L&&(Object.keys(L.fieldGroups).length||Object.keys(L.relations).length)&&(I.fieldGroups=L);let R={...S,table:O,index:M.name,order:_.args.order??`asc`,clientFilters:_.clientIdentity,serverFilters:{predicates:_.sets.size?{predicates:_.serverIdentity,traversal:{version:2,expansion:F?{...F}:null}}:_.serverIdentity,selection:r,...I,scope:{...y.scope},rootTable:S.table,lookupIndex:A.name,guards:{source:d.sourceGuard?{...d.sourceGuard}:null,target:d.targetGuard?{...d.targetGuard}:null,junction:d.junctionGuard?{...d.junctionGuard}:null},...(d.sourceMember||d.targetMember)&&{members:{source:d.sourceMember?{...d.sourceMember}:null,target:d.targetMember?{...d.targetMember}:null}}},relationPath:c,parent:l},z;function B(){return z??=b.registryVersion({root:S.table,path:c,selection:r,groups:L??p,filters:[_.residual]}).then(e=>({...R,registryVersion:e})),z}async function V(e){try{return m.parse(JSON.parse(x.open(e,await B())))}catch{throw new i}}return{declared:d,plan:_,through:D,sourceTable:O,field:k,index:M,targetIndex:A,bind:B,open:V,expansion:F}}async function H(e,r,i,s,c,p=[],m=[],h=[i],g=1,v=[],S=V(e,i,s,c,p,m,h,v[0]??r._id),C){y.expand(g,0);let{declared:w,plan:E,through:O,sourceTable:j,field:M,index:N,targetIndex:I,expansion:L}=S,R=await S.bind(),H=A(w,r),U={...E.args,...C??{cursor:null}},W={...E,expansion:L,index:N,prefix:H==null?[]:O?P(N,M,H,void 0,w.junctionGuard):P(N,M,H,E,w.targetGuard),unsatisfiable:H==null||E.unsatisfiable};if(W.range=O?null:t(N,W.prefix,E.ranges),!O)for(let e of W.prefix){let t=E.ranges.get(e.field);E.bindings.has(e.field)&&l(e.value,E.bindings.get(e.field))!==0&&(W.unsatisfiable=!0),t&&!n(e.value,t)&&(W.unsatisfiable=!0)}let G=O&&O.targetField!==`_id`;return await a(_,y,j,W,b,x,R,U,async(e,t)=>{if(t&&b.validateDocument(G?w.target:j,e),!t||O&&!G&&!D(e,w.junctionGuard))return null;y.expand(g);let n;return n=O&&!G?await F(w.target,e[O.targetReference]):e,!n||!D(n,w.targetGuard)||!k(n[T(w.to).field],w.targetMember)||!await z(w.target,n,E.residual,g)?null:B(w.target,n,s,E.args,h,g,v)},e=>x.seal(JSON.stringify({cursor:e,ancestors:v.slice(1)}),R),G?(e,n)=>{let r=_,i=d(w.target,I.name,r);return e.flatMap(async e=>{y.expand(g);let a=await y.authorize(j,e);a&&b.validateDocument(j,e);let s=e[O.targetReference];return!a||!D(e,w.junctionGuard)||s==null?new u(E.args.order??`asc`,i):f(n,r).query(w.target).withIndex(I.name,e=>{let n=P(I,O.targetField,s,E,w.targetGuard);return o(e,n,t(I,n,E.ranges))}).order(E.args.order??`asc`)},i)}:void 0,G?w.target:j)}async function U(e,t,n,r,a,o,c,u){if(!n.length||n.length>4||!y.db.normalizeId(e,t))throw new h(`INVALID_RELATION`);let d=e,f=n.map(e=>{let t=E(d,e);return d=t.target,t});if(u!==void 0&&f.some(e=>`base`in e.from||`base`in e.to))throw Error(`orderBy is unsupported for junction relationships`);let p=f.at(-1);for(let e of f.slice(0,-1))(e.cardinality===`one`||`base`in e.from||`base`in e.to)&&M(e);let m=V(p.source,n.at(-1),r,a,o,c,n,t,u),g=a.cursor===null?null:await m.open(a.cursor),_=a.endCursor==null?null:await m.open(a.endCursor),v=g?.ancestors??_?.ancestors??[];if(v.length!==n.length-1||g&&_&&JSON.stringify(g.ancestors)!==JSON.stringify(_.ancestors)||v.some((e,t)=>!y.db.normalizeId(f[t].target,e)))throw new i;try{let i=await F(e,t);for(let e=0;i&&e<v.length;e++){let t=f[e],n=null;if(t.cardinality===`many`&&!(`base`in t.from)&&!(`base`in t.to)){y.expand(e+1,0);let r=A(t,i),a=r==null?null:await F(t.target,v[e]),o=t.to.field;r!=null&&a&&D(a,t.targetGuard)&&k(a[o],t.targetMember)&&a[o]!==void 0&&l(r,a[o])===0&&(y.expand(e+1),n=a)}else if(t.cardinality===`one`){let r=await R(t,i,e+1);r?._id===v[e]&&(n=r)}else for await(let r of L(t,i,e+1))if(r._id===v[e]){n=r;break}i=n}return await H(p.source,i,n.at(-1),r,a,o,c,n,n.length,[t,...v],m,{cursor:g?.cursor??null,endCursor:_?.cursor??a.endCursor})}catch(e){s(e)}}function W(e,t,n,r=[]){for(let[i,a]of Object.entries(t)){let t=E(e,i),o=a===!0?{}:a,s=[...r,i];t.cardinality===`many`?V(e,i,o,{numItems:n.numItems,cursor:null,order:n.order},[],[],s,``):M(t,s),W(t.target,o,n,s)}}return{matches:z,output:B,continuation:U,edge:E,preflight:W}}function v(e){return e.kind===`relation`?!1:e.kind===`and`||e.kind===`or`?e.children.every(v):e.kind===`not`||e.kind===`variant`?v(e.child):!0}export{h as RelationshipError,g as assertRelationshipDepth,_ as relationshipExecutor};
|
|
2
2
|
//# sourceMappingURL=relationships.mjs.map
|