cvx-kit 0.1.35 → 2.0.0-beta.0
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 +92 -49
- package/dist/agent-tools.d.mts +21 -25
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +20 -14
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +4 -5
- package/dist/components/approvals/_generated/api.mjs.map +1 -1
- package/dist/components/approvals/_generated/component.d.mts +0 -2
- package/dist/components/approvals/_generated/dataModel.d.mts +1 -3
- package/dist/components/approvals/_generated/server.d.mts +0 -2
- package/dist/components/approvals/_generated/server.mjs.map +1 -1
- package/dist/components/approvals/audit.d.mts +0 -1
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +0 -1
- package/dist/components/approvals/client.mjs +1 -1
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.d.mts +0 -1
- package/dist/components/approvals/constants.mjs.map +1 -1
- package/dist/components/approvals/convex.config.d.mts +0 -2
- package/dist/components/approvals/convex.config.mjs.map +1 -1
- package/dist/components/approvals/decisions.d.mts +1 -4
- package/dist/components/approvals/decisions.mjs +1 -1
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.d.mts +0 -1
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.d.mts +0 -1
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.d.mts +106 -123
- package/dist/components/approvals/requests.mjs +1 -1
- package/dist/components/approvals/requests.mjs.map +1 -1
- package/dist/components/approvals/schema.d.ts +106 -315
- package/dist/components/approvals/schema.js +1 -1
- package/dist/components/approvals/validators.d.mts +321 -393
- package/dist/components/approvals/validators.mjs +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.d.mts +0 -1
- package/dist/components/approvals/workflow.mjs +1 -1
- package/dist/components/approvals/workflow.mjs.map +1 -1
- package/dist/components/approvals/workflow_steps.d.mts +1 -2
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/_generated/api.d.mts +3 -4
- package/dist/components/foundation/_generated/api.mjs.map +1 -1
- package/dist/components/foundation/_generated/component.d.mts +0 -2
- package/dist/components/foundation/_generated/dataModel.d.mts +1 -3
- package/dist/components/foundation/_generated/server.d.mts +0 -2
- package/dist/components/foundation/_generated/server.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +0 -1
- package/dist/components/foundation/client.mjs +1 -1
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/convex.config.d.mts +0 -2
- package/dist/components/foundation/convex.config.mjs.map +1 -1
- package/dist/components/foundation/functions.d.mts +0 -1
- package/dist/components/foundation/functions.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +0 -1
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/command/lifecycle.d.mts +0 -2
- package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
- package/dist/components/foundation/modules/observability/observability.d.mts +0 -1
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/modules/query/query.d.mts +0 -1
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +2 -3
- package/dist/components/foundation/operation.mjs.map +1 -1
- package/dist/components/foundation/result.d.mts +0 -1
- package/dist/components/foundation/result.mjs.map +1 -1
- package/dist/components/foundation/schema.d.ts +0 -2
- package/dist/components/foundation/telemetry.d.mts +0 -1
- package/dist/components/foundation/telemetry.mjs +1 -1
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/contracts.d.mts +2 -2
- package/dist/contracts.mjs +1 -1
- package/dist/crud.d.mts +93 -97
- package/dist/crud.mjs +1 -1
- package/dist/crud.mjs.map +1 -1
- package/dist/effect.d.mts +2 -3
- package/dist/effect.mjs +1 -1
- package/dist/errors.d.mts +2 -4
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filters.d.mts +1 -1
- package/dist/filters.mjs +1 -1
- package/dist/idempotency.mjs +1 -1
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +1 -1
- package/dist/json-schema.d.mts +40 -0
- package/dist/json-schema.mjs +2 -0
- package/dist/json-schema.mjs.map +1 -0
- package/dist/k/compile.d.mts +17 -0
- package/dist/k/compile.mjs +2 -0
- package/dist/k/compile.mjs.map +1 -0
- package/dist/k/dates.d.mts +23 -0
- package/dist/k/dates.mjs +2 -0
- package/dist/k/dates.mjs.map +1 -0
- package/dist/k/formats.d.mts +24 -0
- package/dist/k/formats.mjs +2 -0
- package/dist/k/formats.mjs.map +1 -0
- package/dist/k/index.d.mts +32 -0
- package/dist/k/index.mjs +2 -0
- package/dist/k/index.mjs.map +1 -0
- package/dist/k/issues.d.mts +31 -0
- package/dist/k/issues.mjs +2 -0
- package/dist/k/issues.mjs.map +1 -0
- package/dist/k/kinds.d.mts +81 -0
- package/dist/k/kinds.mjs +2 -0
- package/dist/k/kinds.mjs.map +1 -0
- package/dist/k/object.d.mts +43 -0
- package/dist/k/object.mjs +2 -0
- package/dist/k/object.mjs.map +1 -0
- package/dist/k/parse.d.mts +29 -0
- package/dist/k/parse.mjs +2 -0
- package/dist/k/parse.mjs.map +1 -0
- package/dist/k/schema.d.mts +100 -0
- package/dist/k/schema.mjs +2 -0
- package/dist/k/schema.mjs.map +1 -0
- package/dist/k/standard.d.mts +8 -0
- package/dist/k/standard.mjs +2 -0
- package/dist/k/standard.mjs.map +1 -0
- package/dist/k/types.d.mts +64 -0
- package/dist/k/types.mjs +1 -0
- package/dist/k.d.mts +8 -0
- package/dist/k.mjs +1 -0
- package/dist/middleware.d.mts +0 -2
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/modules/contracts/binding.d.mts +1 -2
- package/dist/modules/contracts/binding.mjs.map +1 -1
- package/dist/modules/contracts/contract.d.mts +0 -2
- package/dist/modules/contracts/contract.mjs.map +1 -1
- package/dist/modules/contracts/convex.d.mts +1 -3
- package/dist/modules/contracts/convex.mjs.map +1 -1
- package/dist/modules/contracts/domain.d.mts +1 -2
- package/dist/modules/contracts/domain.mjs.map +1 -1
- package/dist/modules/contracts/errors.d.mts +161 -2
- package/dist/modules/contracts/errors.mjs +1 -1
- package/dist/modules/contracts/errors.mjs.map +1 -1
- package/dist/modules/contracts/exposure.d.mts +1 -2
- package/dist/modules/contracts/exposure.mjs.map +1 -1
- package/dist/modules/contracts/idempotency.d.mts +1 -2
- package/dist/modules/contracts/idempotency.mjs +1 -1
- package/dist/modules/contracts/idempotency.mjs.map +1 -1
- package/dist/modules/contracts/lazy.d.mts +0 -2
- package/dist/modules/contracts/lazy.mjs.map +1 -1
- package/dist/modules/contracts/standard.d.mts +7 -5
- package/dist/modules/contracts/standard.mjs +1 -1
- package/dist/modules/contracts/standard.mjs.map +1 -1
- package/dist/modules/contracts/workflow.d.mts +1 -2
- package/dist/modules/contracts/workflow.mjs.map +1 -1
- package/dist/modules/effect/action.d.mts +6 -7
- package/dist/modules/effect/action.mjs +1 -1
- package/dist/modules/effect/action.mjs.map +1 -1
- package/dist/modules/effect/agent-tools.mjs +1 -1
- package/dist/modules/effect/api-runtime.d.mts +1 -2
- package/dist/modules/effect/api-runtime.mjs +1 -1
- package/dist/modules/effect/api-runtime.mjs.map +1 -1
- package/dist/modules/effect/api.d.mts +41 -15
- package/dist/modules/effect/api.mjs +1 -1
- package/dist/modules/effect/api.mjs.map +1 -1
- package/dist/modules/effect/auth.d.mts +5 -6
- package/dist/modules/effect/auth.mjs +1 -1
- package/dist/modules/effect/auth.mjs.map +1 -1
- package/dist/modules/effect/client.d.mts +7 -8
- package/dist/modules/effect/client.mjs +1 -1
- package/dist/modules/effect/command.d.mts +7 -5
- package/dist/modules/effect/command.mjs +1 -1
- package/dist/modules/effect/command.mjs.map +1 -1
- package/dist/modules/effect/crud.d.mts +272 -206
- package/dist/modules/effect/crud.mjs +1 -1
- package/dist/modules/effect/crud.mjs.map +1 -1
- package/dist/modules/effect/domain.d.mts +5 -6
- package/dist/modules/effect/domain.mjs.map +1 -1
- package/dist/modules/effect/errors.d.mts +4 -2
- package/dist/modules/effect/errors.mjs +1 -1
- package/dist/modules/effect/errors.mjs.map +1 -1
- package/dist/modules/effect/failure-audit.d.mts +2 -2
- package/dist/modules/effect/failure-audit.mjs +1 -1
- package/dist/modules/effect/failure-audit.mjs.map +1 -1
- package/dist/modules/effect/failures.d.mts +1 -2
- package/dist/modules/effect/failures.mjs.map +1 -1
- package/dist/modules/effect/foundation.d.mts +0 -2
- package/dist/modules/effect/foundation.mjs.map +1 -1
- package/dist/modules/effect/idempotency.d.mts +2 -3
- package/dist/modules/effect/idempotency.mjs +1 -1
- package/dist/modules/effect/idempotency.mjs.map +1 -1
- package/dist/modules/effect/input.d.mts +10 -0
- package/dist/modules/effect/input.mjs +2 -0
- package/dist/modules/effect/input.mjs.map +1 -0
- package/dist/modules/effect/normalize.d.mts +0 -2
- package/dist/modules/effect/normalize.mjs.map +1 -1
- package/dist/modules/effect/operation.d.mts +2 -3
- package/dist/modules/effect/operation.mjs.map +1 -1
- package/dist/modules/effect/query.d.mts +6 -4
- package/dist/modules/effect/query.mjs +1 -1
- package/dist/modules/effect/query.mjs.map +1 -1
- package/dist/modules/effect/schema.d.mts +0 -2
- package/dist/modules/effect/schema.mjs.map +1 -1
- package/dist/modules/effect/scope.d.mts +0 -2
- package/dist/modules/effect/scope.mjs.map +1 -1
- package/dist/modules/effect/workflow.d.mts +4 -5
- package/dist/modules/effect/workflow.mjs +1 -1
- package/dist/modules/effect/workflow.mjs.map +1 -1
- package/dist/modules/foundation/foundation.d.mts +4 -5
- package/dist/modules/foundation/foundation.mjs +1 -1
- package/dist/modules/foundation/foundation.mjs.map +1 -1
- package/dist/modules/foundation/operation.d.mts +2 -3
- package/dist/modules/foundation/operation.mjs.map +1 -1
- package/dist/namespace.d.mts +104 -0
- package/dist/namespace.mjs +2 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/oxlint/architecture.d.mts +0 -2
- package/dist/oxlint/architecture.mjs +1 -1
- package/dist/oxlint/architecture.mjs.map +1 -1
- package/dist/oxlint/ast.d.mts +16 -8
- package/dist/oxlint/ast.mjs +1 -1
- package/dist/oxlint/ast.mjs.map +1 -1
- package/dist/oxlint/components.d.mts +0 -2
- package/dist/oxlint/components.mjs.map +1 -1
- package/dist/oxlint/ownership.d.mts +0 -2
- package/dist/oxlint/ownership.mjs +1 -1
- package/dist/oxlint/ownership.mjs.map +1 -1
- package/dist/oxlint/reserved-files.d.mts +0 -2
- package/dist/oxlint/reserved-files.mjs +1 -1
- package/dist/oxlint/reserved-files.mjs.map +1 -1
- package/dist/oxlint.d.mts +0 -2
- package/dist/oxlint.mjs +1 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/querying/cursors.d.mts +27 -9
- package/dist/querying/cursors.mjs +1 -1
- package/dist/querying/cursors.mjs.map +1 -1
- package/dist/querying/execution.d.mts +6 -7
- package/dist/querying/execution.mjs +1 -1
- package/dist/querying/execution.mjs.map +1 -1
- package/dist/querying/failures.d.mts +0 -2
- package/dist/querying/failures.mjs +1 -1
- package/dist/querying/failures.mjs.map +1 -1
- package/dist/querying/filter-boundary.d.mts +18 -9
- package/dist/querying/filter-boundary.mjs +1 -1
- package/dist/querying/filter-boundary.mjs.map +1 -1
- package/dist/querying/filters.d.mts +71 -35
- package/dist/querying/filters.mjs +1 -1
- package/dist/querying/filters.mjs.map +1 -1
- package/dist/querying/planner.d.mts +16 -20
- package/dist/querying/planner.mjs +1 -1
- package/dist/querying/planner.mjs.map +1 -1
- package/dist/querying/relationships.d.mts +6 -6
- package/dist/querying/relationships.mjs +1 -1
- package/dist/querying/relationships.mjs.map +1 -1
- package/dist/querying/search.d.mts +12 -12
- package/dist/querying/search.mjs +1 -1
- package/dist/querying/search.mjs.map +1 -1
- package/dist/querying/security.d.mts +2 -3
- package/dist/querying/security.mjs.map +1 -1
- package/dist/querying/shared/ast.d.mts +0 -2
- package/dist/querying/shared/ast.mjs.map +1 -1
- package/dist/querying/shared/contract.d.mts +17 -23
- package/dist/querying/shared/contract.mjs +1 -1
- package/dist/querying/shared/contract.mjs.map +1 -1
- package/dist/querying/shared/evaluate.d.mts +0 -2
- package/dist/querying/shared/evaluate.mjs.map +1 -1
- package/dist/querying/shared/filters.d.mts +47 -29
- package/dist/querying/shared/filters.mjs +1 -1
- package/dist/querying/shared/filters.mjs.map +1 -1
- package/dist/querying/shared/native-json.d.mts +7 -0
- package/dist/querying/shared/native-json.mjs +2 -0
- package/dist/querying/shared/native-json.mjs.map +1 -0
- package/dist/querying/shared/page.d.mts +19 -22
- package/dist/querying/shared/page.mjs +1 -1
- package/dist/querying/shared/page.mjs.map +1 -1
- package/dist/querying.d.mts +6 -9
- package/dist/querying.mjs +1 -1
- package/dist/querying.mjs.map +1 -1
- package/dist/react/failures.d.mts +0 -2
- package/dist/react/failures.mjs.map +1 -1
- package/dist/react/optimistic.d.mts +2 -3
- package/dist/react/optimistic.mjs.map +1 -1
- package/dist/react/pagination-state.d.mts +1 -2
- package/dist/react/pagination-state.mjs.map +1 -1
- package/dist/react/use-command.d.mts +0 -2
- package/dist/react/use-command.mjs.map +1 -1
- package/dist/react/use-paginated-list.d.mts +1 -3
- package/dist/react/use-paginated-list.mjs +1 -1
- package/dist/react/use-paginated-list.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.mjs +1 -1
- package/dist/registration.d.mts +65 -0
- package/dist/registration.mjs +2 -0
- package/dist/registration.mjs.map +1 -0
- package/dist/relations-public.d.mts +2 -2
- package/dist/relations-public.mjs +1 -1
- package/dist/relations.d.mts +55 -46
- package/dist/relations.mjs +1 -1
- package/dist/relations.mjs.map +1 -1
- package/dist/state-machine.d.mts +0 -2
- package/dist/state-machine.mjs.map +1 -1
- package/dist/table.d.mts +222 -0
- package/dist/table.mjs +2 -0
- package/dist/table.mjs.map +1 -0
- package/dist/tenancy.d.mts +0 -2
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.d.mts +2 -4
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +9 -9
- package/dist/webhooks.mjs +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/dist/workflow.mjs +1 -1
- package/dist/zod.d.mts +30 -0
- package/dist/zod.mjs +2 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +51 -29
- package/dist/modules/effect/api-zod.d.mts +0 -34
- package/dist/modules/effect/api-zod.mjs +0 -2
- package/dist/modules/effect/api-zod.mjs.map +0 -1
- package/dist/querying/schema-snapshot.d.mts +0 -49
- package/dist/querying/schema-snapshot.mjs +0 -2
- package/dist/querying/schema-snapshot.mjs.map +0 -1
- package/dist/zod-convex.d.mts +0 -10
- package/dist/zod-convex.mjs +0 -2
- package/dist/zod-convex.mjs.map +0 -1
- package/dist/zod-registration.d.mts +0 -15
- package/dist/zod-registration.mjs +0 -2
- package/dist/zod-registration.mjs.map +0 -1
- package/dist/zod-table.d.mts +0 -351
- package/dist/zod-table.mjs +0 -2
- package/dist/zod-table.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foundation.mjs","names":["createFoundation","observability","Observability","options","Command","registry","configuration","Query","section","command","definitions","domainFactory","operationFactory","operations","snapshotOperations","exec","operation","definition","parsed","decode","input","permission","CommandPermissionError","host","context","run","enriched","guard","executeCommandLifecycle","promiseLifecycle","prepared","result","value","entry","called","next","raw","settings","selectOperation","owner","schema","decoded","decodeContract","issue"],"sources":["../../../src/modules/foundation/foundation.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Private heterogeneous executor storage; public overloads restore schema-owned values and callbacks before dispatch. */\nimport type { AuditEntryInput } from '../../components/foundation/client'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Host registries share the deployed component's Effect-free interpreter.\nimport {\n\texecuteCommandLifecycle,\n\tpromiseLifecycle,\n\tCommandPermissionError,\n\ttype PromiseExecution,\n} from '../../components/foundation/modules/command/lifecycle'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Host-only observability is shared without entering the deployment graph.\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from '../../components/foundation/modules/observability/observability'\nimport {\n\tdecodeContract,\n\ttype ContractInput,\n\ttype ContractOutput,\n\ttype NeutralSchema,\n} from '../contracts/contract'\nimport type { DomainContract, DomainAuditInput } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport {\n\tselectOperation,\n\ttype SelectedOperation,\n\ttype OperationPublicResult,\n} from '../contracts/exposure'\nimport {\n\tdomainFactory,\n\toperationFactory,\n\ttype DomainFactory,\n\ttype DomainImplementations,\n\ttype InlineFactory,\n\ttype NormalEntry,\n\ttype Audit,\n\ttype CheckedOperation,\n\ttype ExactOperations,\n\ttype ValidatedOperations,\n} from './operation'\n\ntype Supported<Value> = Value | PromiseLike<Value>\ntype Resolver = (host: never) => unknown\ntype Domain<Resolve extends Resolver> = Awaited<ReturnType<Resolve>>\ntype Host<Resolve extends Resolver> = Parameters<Resolve>[0]\ntype CallbackHost<Callback> = Callback extends (host: infer Host, ...args: never[]) => unknown\n\t? Host\n\t: unknown\nexport type FoundationRegistryOptions = {\n\tobservability: ObservabilityOptions\n\twriteAudit: (host: never, entry: AuditEntryInput) => Supported<unknown>\n\tcheckPermission?: (\n\t\thost: never,\n\t\tinput: { operation: string; permission: string },\n\t) => Supported<void>\n}\ntype Registry<Context> = Readonly<\n\tRecord<\n\t\tstring,\n\t\tNormalEntry & { handler: (input: never, context: never) => unknown } & CheckedOperation<Context>\n\t>\n>\ntype AuditedRegistry<Context> = Registry<Context> &\n\tReadonly<Record<string, { audit: (resolution: never, context: never) => Supported<Audit> }>>\ntype Defaults<Context> = { guard?: (context: Context) => Supported<void>; metadata?: object }\nexport type FoundationRegistry<\n\tResolve extends Resolver,\n\tOperations extends Registry<Domain<Resolve>>,\n> = {\n\texec<Key extends Extract<keyof Operations, string>>(\n\t\toperation: Key,\n\t\tinput: ContractInput<Operations[Key]['input']>,\n\t\thost: Host<Resolve>,\n\t): Promise<ContractOutput<Operations[Key]['result']>>\n\twithContext(host: Host<Resolve>): {\n\t\texec<Key extends Extract<keyof Operations, string>>(\n\t\t\toperation: Key,\n\t\t\tinput: ContractInput<Operations[Key]['input']>,\n\t\t): Promise<ContractOutput<Operations[Key]['result']>>\n\t}\n\texpose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(\n\t\towner: Owner,\n\t\toperation: Key,\n\t): SelectedOperation<Owner, Key, Operations[Key]['input'], OperationPublicResult<Operations[Key]>>\n}\ntype RuntimeDefinition = NormalEntry & {\n\tclassification?: string\n\tpermission?: string\n\tmetadata?: object\n\taggregates?: readonly string[]\n\thandler: (input: unknown, context: unknown) => Supported<unknown>\n\tguard?: (context: unknown, input: unknown) => Supported<void>\n\tprepare?: (\n\t\tcontext: unknown,\n\t\tinput: unknown,\n\t) => Supported<\n\t\t| { kind: 'replay'; result: unknown }\n\t\t| { kind: 'execute'; complete?: (result: unknown) => Supported<void> }\n\t>\n\taudit: (resolution: { command: unknown; result: unknown }, context: unknown) => Supported<Audit>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tcommand: unknown\n\t\tinput: unknown\n\t\tcontext: unknown\n\t\tmetadata: object\n\t\tnext: (options?: { context?: object }) => Promise<unknown>\n\t}) => Supported<unknown>\n}\ntype RuntimeConfiguration = {\n\tcontext: Resolver\n\tcontract?: DomainContract\n\toperations: (definitions: never) => Readonly<Record<string, object>>\n\taudit?: (resolution: never, context: never) => Supported<Audit>\n\tdefaults?: Defaults<never>\n}\n\n// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n/** Promise-based registries share the same command protocol as the optional Effect adapter. */\nexport function createFoundation<const Options extends FoundationRegistryOptions>(\n\toptions: Options,\n) {\n\tconst observability = new Observability(options.observability)\n\ttype PolicyHost = CallbackHost<Options['writeAudit']> & CallbackHost<Options['checkPermission']>\n\ttype Compatible<Resolve extends Resolver> =\n\t\tHost<Resolve> extends PolicyHost ? unknown : { context: never }\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, NormalEntry & { classification: string }>>\n\t\t},\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue,\n\t\t\tfalse\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Contract['commands']>,\n\t\t\t\tcontext: Domain<Resolve>,\n\t\t\t) => Supported<Audit>\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['commands'], true, false>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['commands']>>\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, NormalEntry & { classification: string }>>\n\t\t},\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue,\n\t\t\ttrue\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: never\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['commands'], true, true>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['commands']>>\n\tfunction Command<Resolve extends Resolver, const Operations extends Registry<Domain<Resolve>>>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Operations>,\n\t\t\t\tcontext: Domain<Resolve>,\n\t\t\t) => Supported<Audit>\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, false>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends AuditedRegistry<Domain<Resolve>>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, true>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Command(configuration: RuntimeConfiguration): unknown {\n\t\treturn registry(configuration, true)\n\t}\n\tfunction Query<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & { queries: Readonly<Record<string, NormalEntry>> },\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['queries'],\n\t\t\tfalse,\n\t\t\ttrue\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['queries']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['queries'], false, true>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['queries']>>\n\tfunction Query<Resolve extends Resolver, const Operations extends Registry<Domain<Resolve>>>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, true>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Query(configuration: RuntimeConfiguration): unknown {\n\t\treturn registry(configuration, false)\n\t}\n\tfunction registry(configuration: RuntimeConfiguration, command: boolean) {\n\t\tconst section = command ? 'commands' : 'queries'\n\t\t// SAFETY: public overloads restrict Promise registries to neutral schemas.\n\t\tconst definitions = configuration.contract\n\t\t\t? domainFactory(\n\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\t(configuration.contract[section] as Readonly<Record<string, NormalEntry>>) ?? {},\n\t\t\t\t\tcommand,\n\t\t\t\t)\n\t\t\t: operationFactory()\n\t\t// SAFETY: helper overloads checked the selected callbacks; storage erases only their parameters.\n\t\tconst operations = snapshotOperations(\n\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\tconfiguration.operations(definitions as never),\n\t\t\tconfiguration.contract,\n\t\t\tsection,\n\t\t\tconfiguration.audit,\n\t\t)\n\t\tasync function exec(operation: string, input: unknown, host: never) {\n\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\tthrow Error(`The selected ${command ? 'command' : 'query'} operation is not configured`)\n\t\t\t// SAFETY: helpers verified callbacks against these paired schemas; only the runtime storage erases values.\n\t\t\tconst definition = operations[operation] as RuntimeDefinition\n\t\t\tconst parsed = await decode(definition.input, input)\n\t\t\treturn observability.observe(\n\t\t\t\t{ operation, classification: definition.classification ?? 'query' },\n\t\t\t\tasync () => {\n\t\t\t\t\tconst permission = async () => {\n\t\t\t\t\t\tif (!definition.permission) return\n\t\t\t\t\t\tif (!options.checkPermission) throw new CommandPermissionError(operation)\n\t\t\t\t\t\tawait options.checkPermission(host, { operation, permission: definition.permission })\n\t\t\t\t\t}\n\t\t\t\t\tif (!command) await permission()\n\t\t\t\t\tconst context = await configuration.context(host)\n\t\t\t\t\tconst run = (enriched: unknown) => Promise.resolve(definition.handler(parsed, enriched))\n\t\t\t\t\tconst guard = async (enriched: unknown) => {\n\t\t\t\t\t\t// SAFETY: base resolver context is the public default guard context.\n\t\t\t\t\t\tawait configuration.defaults?.guard?.(enriched as never)\n\t\t\t\t\t\tawait definition.guard?.(enriched, parsed)\n\t\t\t\t\t}\n\t\t\t\t\tif (command)\n\t\t\t\t\t\treturn executeCommandLifecycle<PromiseExecution, unknown, unknown, unknown, unknown>(\n\t\t\t\t\t\t\tpromiseLifecycle,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tclassification: definition.classification!,\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\tcommand: parsed,\n\t\t\t\t\t\t\t\tpermission,\n\t\t\t\t\t\t\t\tprepare: async () => {\n\t\t\t\t\t\t\t\t\tconst prepared = await definition.prepare?.(context, parsed)\n\t\t\t\t\t\t\t\t\treturn prepared?.kind === 'execute'\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t...prepared,\n\t\t\t\t\t\t\t\t\t\t\t\tcomplete: prepared.complete\n\t\t\t\t\t\t\t\t\t\t\t\t\t? async (result) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tawait prepared.complete!(result)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: prepared\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tmiddleware: definition.middleware\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t(input) =>\n\t\t\t\t\t\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefinition.middleware!({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t...input,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinput: parsed,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...configuration.defaults?.metadata,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...definition.metadata,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t\tdefaultGuard: async () => {},\n\t\t\t\t\t\t\t\tguard,\n\t\t\t\t\t\t\t\trun,\n\t\t\t\t\t\t\t\tdecodeReplay: (value) =>\n\t\t\t\t\t\t\t\t\tdecode(definition.replayResult ?? definition.result, value),\n\t\t\t\t\t\t\t\tdecodeResult: (value) => decode(definition.result, value),\n\t\t\t\t\t\t\t\taudit: async (result) => definition.audit({ command: parsed, result }, context),\n\t\t\t\t\t\t\t\twriteAudit: async (entry) => options.writeAudit(host, entry),\n\t\t\t\t\t\t\t\taggregates: definition.aggregates,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\tlet called = false\n\t\t\t\t\tconst next = async (enriched = context) => {\n\t\t\t\t\t\tif (called) throw Error('A query middleware called next() more than once')\n\t\t\t\t\t\tcalled = true\n\t\t\t\t\t\tawait guard(enriched)\n\t\t\t\t\t\treturn run(enriched)\n\t\t\t\t\t}\n\t\t\t\t\tconst raw = definition.middleware\n\t\t\t\t\t\t? await definition.middleware({\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tcommand: parsed,\n\t\t\t\t\t\t\t\tinput: parsed,\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\tmetadata: { ...configuration.defaults?.metadata, ...definition.metadata },\n\t\t\t\t\t\t\t\tnext: (settings) =>\n\t\t\t\t\t\t\t\t\tnext(\n\t\t\t\t\t\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\t\t\t\t\t\tsettings?.context ? { ...(context as object), ...settings.context } : context,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: await next()\n\t\t\t\t\treturn decode(definition.result, raw)\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\texec,\n\t\t\twithContext: (host: never) => ({\n\t\t\t\texec: (operation: string, input: unknown) => exec(operation, input, host),\n\t\t\t}),\n\t\t\texpose: (owner: symbol, operation: string) => {\n\t\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\t\tthrow Error('The selected operation is not configured')\n\t\t\t\treturn selectOperation(\n\t\t\t\t\towner,\n\t\t\t\t\tcommand ? 'mutation' : 'query',\n\t\t\t\t\toperation,\n\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\toperations[operation] as RuntimeDefinition,\n\t\t\t\t)\n\t\t\t},\n\t\t}\n\t}\n\treturn { Command, Query, observability }\n}\n\nasync function decode(schema: NeutralSchema, value: unknown) {\n\tif ('kind' in schema && schema.kind !== 'contract')\n\t\tthrow Error('Effect contracts require the Effect registry')\n\tconst decoded = await decodeContract(schema, value)\n\tif (decoded.issues) throw Error(decoded.issues.map((issue) => issue.message).join('; '))\n\treturn decoded.value\n}\n"],"mappings":"qfAsHA,SAAgBA,EACf,EACC,CACD,IAAMC,EAAgB,IAAIC,EAAcC,EAAQ,aAAa,EA0F7D,SAASC,EAAQ,EAA8C,CAC9D,OAAOC,EAASC,EAAe,EAAI,CACpC,CAoCA,SAASC,EAAM,EAA8C,CAC5D,OAAOF,EAASC,EAAe,EAAK,CACrC,CACA,SAASD,EAAS,EAAqC,EAAkB,CACxE,IAAMG,EAAUC,EAAU,WAAa,UAEjCC,EAAcJ,EAAc,SAC/BK,EAECL,EAAc,SAASE,IAAsD,CAAC,EAC/EC,CACD,EACCG,EAAiB,EAEdC,EAAaC,EAElBR,EAAc,WAAWI,CAAoB,EAC7CJ,EAAc,SACdE,EACAF,EAAc,KACf,EACA,eAAeS,EAAK,EAAmB,EAAgB,EAAa,CACnE,GAAI,CAAC,OAAO,OAAOF,EAAYG,CAAS,EACvC,MAAM,MAAM,gBAAgBP,EAAU,UAAY,QAAQ,6BAA6B,EAExF,IAAMQ,EAAaJ,EAAWG,GACxBE,EAAS,MAAMC,EAAOF,EAAW,MAAOG,CAAK,EACnD,OAAOnB,EAAc,QACpB,CAAE,YAAW,eAAgBgB,EAAW,gBAAkB,OAAQ,EAClE,SAAY,CACX,IAAMI,EAAa,SAAY,CAC9B,GAAKJ,EAAW,WAChB,IAAI,CAACd,EAAQ,gBAAiB,MAAM,IAAImB,EAAuBN,CAAS,EACxE,MAAMb,EAAQ,gBAAgBoB,EAAM,CAAE,YAAW,WAAYN,EAAW,UAAW,CAAC,CADZ,CAEzE,EACKR,GAAS,MAAMY,EAAW,EAC/B,IAAMG,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ASC,EACT,MAAOA,EACP,UACA,SAAU,CAAE,GAAGZ,EAAc,UAAU,SAAU,GAAGW,EAAW,QAAS,EACxE,KAAO,GACNkB,EAECE,GAAU,QAAU,CAAE,GAAIb,EAAoB,GAAGa,EAAS,OAAQ,EAAIb,CACvE,CACF,CAAC,EACA,MAAMW,EAAK,EACd,OAAOhB,EAAOF,EAAW,OAAQmB,CAAG,CACrC,CACD,CACD,CACA,MAAO,CACN,OACA,YAAc,IAAiB,CAC9B,MAAO,EAAmB,IAAmBrB,EAAKC,EAAWI,EAAOG,CAAI,CACzE,GACA,QAAS,EAAe,IAAsB,CAC7C,GAAI,CAAC,OAAO,OAAOV,EAAYG,CAAS,EACvC,MAAM,MAAM,0CAA0C,EACvD,OAAOsB,EACNC,EACA9B,EAAU,WAAa,QACvBO,EAEAH,EAAWG,EACZ,CACD,CACD,CACD,CACA,MAAO,CAAE,UAAS,QAAO,eAAc,CACxC,CAEA,eAAeG,EAAO,EAAuB,EAAgB,CAC5D,GAAI,SAAUqB,GAAUA,EAAO,OAAS,WACvC,MAAM,MAAM,8CAA8C,EAC3D,IAAMC,EAAU,MAAMC,EAAeF,EAAQR,CAAK,EAClD,GAAIS,EAAQ,OAAQ,MAAM,MAAMA,EAAQ,OAAO,IAAK,GAAUE,EAAM,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,EACvF,OAAOF,EAAQ,KAChB"}
|
|
1
|
+
{"version":3,"file":"foundation.mjs","names":["createFoundation","observability","Observability","options","Command","registry","configuration","Query","section","command","definitions","domainFactory","operationFactory","operations","snapshotOperations","exec","operation","definition","parsed","decode","input","permission","CommandPermissionError","host","context","run","enriched","guard","executeCommandLifecycle","promiseLifecycle","prepared","result","value","entry","called","next","raw","settings","selectOperation","owner","schema","decoded","decodeContract","issue"],"sources":["../../../src/modules/foundation/foundation.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Private heterogeneous executor storage; public overloads restore schema-owned values and callbacks before dispatch. */\nimport type { AuditEntryInput } from '../../components/foundation/client'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Host registries share the deployed component's Effect-free interpreter.\nimport {\n\texecuteCommandLifecycle,\n\tpromiseLifecycle,\n\tCommandPermissionError,\n\ttype PromiseExecution,\n} from '../../components/foundation/modules/command/lifecycle'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Host-only observability is shared without entering the deployment graph.\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from '../../components/foundation/modules/observability/observability'\nimport {\n\tdecodeContract,\n\ttype ContractInput,\n\ttype ContractOutput,\n\ttype NeutralSchema,\n} from '../contracts/contract'\nimport type { DomainContract, DomainAuditInput } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport {\n\tselectOperation,\n\ttype SelectedOperation,\n\ttype OperationPublicResult,\n} from '../contracts/exposure'\nimport {\n\tdomainFactory,\n\toperationFactory,\n\ttype DomainFactory,\n\ttype DomainImplementations,\n\ttype InlineFactory,\n\ttype NormalEntry,\n\ttype Audit,\n\ttype CheckedOperation,\n\ttype ExactOperations,\n\ttype ValidatedOperations,\n} from './operation'\n\ntype Supported<Value> = Value | PromiseLike<Value>\ntype Resolver = (host: never) => unknown\ntype Domain<Resolve extends Resolver> = Awaited<ReturnType<Resolve>>\ntype Host<Resolve extends Resolver> = Parameters<Resolve>[0]\ntype CallbackHost<Callback> = Callback extends (host: infer Host, ...args: never[]) => unknown\n\t? Host\n\t: unknown\nexport type FoundationRegistryOptions = {\n\tobservability: ObservabilityOptions\n\twriteAudit: (host: never, entry: AuditEntryInput) => Supported<unknown>\n\tcheckPermission?: (\n\t\thost: never,\n\t\tinput: { operation: string; permission: string },\n\t) => Supported<void>\n}\ntype Registry<Context> = Readonly<\n\tRecord<\n\t\tstring,\n\t\tNormalEntry & { handler: (input: never, context: never) => unknown } & CheckedOperation<Context>\n\t>\n>\ntype AuditedRegistry<Context> = Registry<Context> &\n\tReadonly<Record<string, { audit: (resolution: never, context: never) => Supported<Audit> }>>\ntype Defaults<Context> = { guard?: (context: Context) => Supported<void>; metadata?: object }\nexport type FoundationRegistry<\n\tResolve extends Resolver,\n\tOperations extends Registry<Domain<Resolve>>,\n> = {\n\texec<Key extends Extract<keyof Operations, string>>(\n\t\toperation: Key,\n\t\tinput: ContractInput<Operations[Key]['input']>,\n\t\thost: Host<Resolve>,\n\t): Promise<ContractOutput<Operations[Key]['result']>>\n\twithContext(host: Host<Resolve>): {\n\t\texec<Key extends Extract<keyof Operations, string>>(\n\t\t\toperation: Key,\n\t\t\tinput: ContractInput<Operations[Key]['input']>,\n\t\t): Promise<ContractOutput<Operations[Key]['result']>>\n\t}\n\texpose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(\n\t\towner: Owner,\n\t\toperation: Key,\n\t): SelectedOperation<Owner, Key, Operations[Key]['input'], OperationPublicResult<Operations[Key]>>\n}\ntype RuntimeDefinition = NormalEntry & {\n\tclassification?: string\n\tpermission?: string\n\tmetadata?: object\n\taggregates?: readonly string[]\n\thandler: (input: unknown, context: unknown) => Supported<unknown>\n\tguard?: (context: unknown, input: unknown) => Supported<void>\n\tprepare?: (\n\t\tcontext: unknown,\n\t\tinput: unknown,\n\t) => Supported<\n\t\t| { kind: 'replay'; result: unknown }\n\t\t| { kind: 'execute'; complete?: (result: unknown) => Supported<void> }\n\t>\n\taudit: (resolution: { command: unknown; result: unknown }, context: unknown) => Supported<Audit>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tcommand: unknown\n\t\tinput: unknown\n\t\tcontext: unknown\n\t\tmetadata: object\n\t\tnext: (options?: { context?: object }) => Promise<unknown>\n\t}) => Supported<unknown>\n}\ntype RuntimeConfiguration = {\n\tcontext: Resolver\n\tcontract?: DomainContract\n\toperations: (definitions: never) => Readonly<Record<string, object>>\n\taudit?: (resolution: never, context: never) => Supported<Audit>\n\tdefaults?: Defaults<never>\n}\n\n// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n/** Promise-based registries share the same command protocol as the optional Effect adapter. */\nexport function createFoundation<const Options extends FoundationRegistryOptions>(\n\toptions: Options,\n) {\n\tconst observability = new Observability(options.observability)\n\ttype PolicyHost = CallbackHost<Options['writeAudit']> & CallbackHost<Options['checkPermission']>\n\ttype Compatible<Resolve extends Resolver> =\n\t\tHost<Resolve> extends PolicyHost ? unknown : { context: never }\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, NormalEntry & { classification: string }>>\n\t\t},\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue,\n\t\t\tfalse\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Contract['commands']>,\n\t\t\t\tcontext: Domain<Resolve>,\n\t\t\t) => Supported<Audit>\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['commands'], true, false>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['commands']>>\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, NormalEntry & { classification: string }>>\n\t\t},\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue,\n\t\t\ttrue\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: never\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['commands'], true, true>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['commands']>>\n\tfunction Command<Resolve extends Resolver, const Operations extends Registry<Domain<Resolve>>>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Operations>,\n\t\t\t\tcontext: Domain<Resolve>,\n\t\t\t) => Supported<Audit>\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, false>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends AuditedRegistry<Domain<Resolve>>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, true>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Command(configuration: RuntimeConfiguration): unknown {\n\t\treturn registry(configuration, true)\n\t}\n\tfunction Query<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & { queries: Readonly<Record<string, NormalEntry>> },\n\t\tconst Operations extends DomainImplementations<\n\t\t\tDomain<Resolve>,\n\t\t\tContract['queries'],\n\t\t\tfalse,\n\t\t\ttrue\n\t\t>,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactOperations<Operations, Contract['queries']> &\n\t\t\t\t\t\tValidatedOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: DomainFactory<Domain<Resolve>, Contract['queries'], false, true>,\n\t\t\t) => Operations\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, BoundOperations<Operations, Contract['queries']>>\n\tfunction Query<Resolve extends Resolver, const Operations extends Registry<Domain<Resolve>>>(\n\t\tconfiguration: {\n\t\t\tcontract?: never\n\t\t\tcontext: Resolve\n\t\t\toperations: (\n\t\t\t\tdefinitions: InlineFactory<Domain<Resolve>, true>,\n\t\t\t) => Operations & NoInfer<ValidatedOperations<Operations>>\n\t\t\tdefaults?: Defaults<Domain<Resolve>>\n\t\t} & Compatible<Resolve>,\n\t): FoundationRegistry<Resolve, Operations>\n\tfunction Query(configuration: RuntimeConfiguration): unknown {\n\t\treturn registry(configuration, false)\n\t}\n\tfunction registry(configuration: RuntimeConfiguration, command: boolean) {\n\t\tconst section = command ? 'commands' : 'queries'\n\t\t// SAFETY: public overloads restrict Promise registries to neutral schemas.\n\t\tconst definitions = configuration.contract\n\t\t\t? domainFactory(\n\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\t(configuration.contract[section] as Readonly<Record<string, NormalEntry>>) ?? {},\n\t\t\t\t\tcommand,\n\t\t\t\t)\n\t\t\t: operationFactory()\n\t\t// SAFETY: helper overloads checked the selected callbacks; storage erases only their parameters.\n\t\tconst operations = snapshotOperations(\n\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\tconfiguration.operations(definitions as never),\n\t\t\tconfiguration.contract,\n\t\t\tsection,\n\t\t\tconfiguration.audit,\n\t\t)\n\t\tasync function exec(operation: string, input: unknown, host: never) {\n\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\tthrow Error(`The selected ${command ? 'command' : 'query'} operation is not configured`)\n\t\t\t// SAFETY: helpers verified callbacks against these paired schemas; only the runtime storage erases values.\n\t\t\tconst definition = operations[operation] as RuntimeDefinition\n\t\t\tconst parsed = await decode(definition.input, input)\n\t\t\treturn observability.observe(\n\t\t\t\t{ operation, classification: definition.classification ?? 'query' },\n\t\t\t\tasync () => {\n\t\t\t\t\tconst permission = async () => {\n\t\t\t\t\t\tif (!definition.permission) return\n\t\t\t\t\t\tif (!options.checkPermission) throw new CommandPermissionError(operation)\n\t\t\t\t\t\tawait options.checkPermission(host, { operation, permission: definition.permission })\n\t\t\t\t\t}\n\t\t\t\t\tif (!command) await permission()\n\t\t\t\t\tconst context = await configuration.context(host)\n\t\t\t\t\tconst run = (enriched: unknown) => Promise.resolve(definition.handler(parsed, enriched))\n\t\t\t\t\tconst guard = async (enriched: unknown) => {\n\t\t\t\t\t\t// SAFETY: base resolver context is the public default guard context.\n\t\t\t\t\t\tawait configuration.defaults?.guard?.(enriched as never)\n\t\t\t\t\t\tawait definition.guard?.(enriched, parsed)\n\t\t\t\t\t}\n\t\t\t\t\tif (command)\n\t\t\t\t\t\treturn executeCommandLifecycle<PromiseExecution, unknown, unknown, unknown, unknown>(\n\t\t\t\t\t\t\tpromiseLifecycle,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tclassification: definition.classification!,\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\tcommand: parsed,\n\t\t\t\t\t\t\t\tpermission,\n\t\t\t\t\t\t\t\tprepare: async () => {\n\t\t\t\t\t\t\t\t\tconst prepared = await definition.prepare?.(context, parsed)\n\t\t\t\t\t\t\t\t\treturn prepared?.kind === 'execute'\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t...prepared,\n\t\t\t\t\t\t\t\t\t\t\t\tcomplete: prepared.complete\n\t\t\t\t\t\t\t\t\t\t\t\t\t? async (result) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tawait prepared.complete!(result)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: prepared\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tmiddleware: definition.middleware\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t(input) =>\n\t\t\t\t\t\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefinition.middleware!({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t...input,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinput: parsed,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...configuration.defaults?.metadata,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...definition.metadata,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t\tdefaultGuard: async () => {},\n\t\t\t\t\t\t\t\tguard,\n\t\t\t\t\t\t\t\trun,\n\t\t\t\t\t\t\t\tdecodeReplay: (value) =>\n\t\t\t\t\t\t\t\t\tdecode(definition.replayResult ?? definition.result, value),\n\t\t\t\t\t\t\t\tdecodeResult: (value) => decode(definition.result, value),\n\t\t\t\t\t\t\t\taudit: async (result) => definition.audit({ command: parsed, result }, context),\n\t\t\t\t\t\t\t\twriteAudit: async (entry) => options.writeAudit(host, entry),\n\t\t\t\t\t\t\t\taggregates: definition.aggregates,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\tlet called = false\n\t\t\t\t\tconst next = async (enriched = context) => {\n\t\t\t\t\t\tif (called) throw Error('A query middleware called next() more than once')\n\t\t\t\t\t\tcalled = true\n\t\t\t\t\t\tawait guard(enriched)\n\t\t\t\t\t\treturn run(enriched)\n\t\t\t\t\t}\n\t\t\t\t\tconst raw = definition.middleware\n\t\t\t\t\t\t? await definition.middleware({\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tcommand: parsed,\n\t\t\t\t\t\t\t\tinput: parsed,\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\tmetadata: { ...configuration.defaults?.metadata, ...definition.metadata },\n\t\t\t\t\t\t\t\tnext: (settings) =>\n\t\t\t\t\t\t\t\t\tnext(\n\t\t\t\t\t\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\t\t\t\t\t\tsettings?.context ? { ...(context as object), ...settings.context } : context,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: await next()\n\t\t\t\t\treturn decode(definition.result, raw)\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\texec,\n\t\t\twithContext: (host: never) => ({\n\t\t\t\texec: (operation: string, input: unknown) => exec(operation, input, host),\n\t\t\t}),\n\t\t\texpose: (owner: symbol, operation: string) => {\n\t\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\t\tthrow Error('The selected operation is not configured')\n\t\t\t\treturn selectOperation(\n\t\t\t\t\towner,\n\t\t\t\t\tcommand ? 'mutation' : 'query',\n\t\t\t\t\toperation,\n\t\t\t\t\t// SAFETY: public helper signatures and the paired schema check this erased runtime invocation.\n\t\t\t\t\toperations[operation] as RuntimeDefinition,\n\t\t\t\t)\n\t\t\t},\n\t\t}\n\t}\n\treturn { Command, Query, observability }\n}\n\nasync function decode(schema: NeutralSchema, value: unknown) {\n\tif ('kind' in schema && schema.kind !== 'contract')\n\t\tthrow Error('Effect contracts require the Effect registry')\n\tconst decoded = await decodeContract(schema, value)\n\tif (decoded.issues) throw Error(decoded.issues.map((issue) => issue.message).join('; '))\n\treturn decoded.value\n}\n"],"mappings":"A,qfAsHA,SAAgBA,EACf,EACC,CACD,IAAMC,EAAgB,IAAIC,EAAcC,EAAQ,aAAa,EA0F7D,SAASC,EAAQ,EAA8C,CAC9D,OAAOC,EAASC,EAAe,EAAI,CACpC,CAoCA,SAASC,EAAM,EAA8C,CAC5D,OAAOF,EAASC,EAAe,EAAK,CACrC,CACA,SAASD,EAAS,EAAqC,EAAkB,CACxE,IAAMG,EAAUC,EAAU,WAAa,UAEjCC,EAAcJ,EAAc,SAC/BK,EAECL,EAAc,SAASE,IAAsD,CAAC,EAC/EC,CACD,EACCG,EAAiB,EAEdC,EAAaC,EAElBR,EAAc,WAAWI,CAAoB,EAC7CJ,EAAc,SACdE,EACAF,EAAc,KACf,EACA,eAAeS,EAAK,EAAmB,EAAgB,EAAa,CACnE,GAAI,CAAC,OAAO,OAAOF,EAAYG,CAAS,EACvC,MAAM,MAAM,gBAAgBP,EAAU,UAAY,QAAQ,6BAA6B,EAExF,IAAMQ,EAAaJ,EAAWG,GACxBE,EAAS,MAAMC,EAAOF,EAAW,MAAOG,CAAK,EACnD,OAAOnB,EAAc,QACpB,CAAE,YAAW,eAAgBgB,EAAW,gBAAkB,OAAQ,EAClE,SAAY,CACX,IAAMI,EAAa,SAAY,CAC9B,GAAKJ,EAAW,WAChB,IAAI,CAACd,EAAQ,gBAAiB,MAAM,IAAImB,EAAuBN,CAAS,EACxE,MAAMb,EAAQ,gBAAgBoB,EAAM,CAAE,YAAW,WAAYN,EAAW,UAAW,CAAC,CADZ,CAEzE,EACKR,GAAS,MAAMY,EAAW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,CAC5B,YACA,QAASC,EACT,MAAOA,EACP,UACA,SAAU,CAAE,GAAGZ,EAAc,UAAU,SAAU,GAAGW,EAAW,QAAS,EACxE,KAAO,GACNkB,EAECE,GAAU,QAAU,CAAE,GAAIb,EAAoB,GAAGa,EAAS,OAAQ,EAAIb,CACvE,CACF,CAAC,EACA,MAAMW,EAAK,EACd,OAAOhB,EAAOF,EAAW,OAAQmB,CAAG,CACrC,CACD,CACD,CACA,MAAO,CACN,OACA,YAAc,IAAiB,CAC9B,MAAO,EAAmB,IAAmBrB,EAAKC,EAAWI,EAAOG,CAAI,CACzE,GACA,QAAS,EAAe,IAAsB,CAC7C,GAAI,CAAC,OAAO,OAAOV,EAAYG,CAAS,EACvC,MAAM,MAAM,0CAA0C,EACvD,OAAOsB,EACNC,EACA9B,EAAU,WAAa,QACvBO,EAEAH,EAAWG,EACZ,CACD,CACD,CACD,CACA,MAAO,CAAE,UAAS,QAAO,eAAc,CACxC,CAEA,eAAeG,EAAO,EAAuB,EAAgB,CAC5D,GAAI,SAAUqB,GAAUA,EAAO,OAAS,WACvC,MAAM,MAAM,8CAA8C,EAC3D,IAAMC,EAAU,MAAMC,EAAeF,EAAQR,CAAK,EAClD,GAAIS,EAAQ,OAAQ,MAAM,MAAMA,EAAQ,OAAO,IAAK,GAAUE,EAAM,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,EACvF,OAAOF,EAAQ,KAChB,C"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ContractInput, ContractOutput, NeutralSchema } from "../contracts/contract.mjs";
|
|
2
1
|
import { AuditEntryInput } from "../../components/foundation/client.mjs";
|
|
2
|
+
import { ContractInput, ContractOutput, NeutralSchema } from "../contracts/contract.mjs";
|
|
3
3
|
import { DomainOperationContract, ExactOperationKeys } from "../contracts/domain.mjs";
|
|
4
4
|
import { DeclaredSchemas } from "../contracts/binding.mjs";
|
|
5
|
-
//#region src/modules/foundation/operation.d.ts
|
|
6
5
|
type Supported<A> = A | PromiseLike<A>;
|
|
7
6
|
export type Audit = Omit<AuditEntryInput, 'classification'> | null;
|
|
8
7
|
export type NormalEntry = DomainOperationContract & {
|
|
@@ -136,5 +135,5 @@ export declare function operationFactory<Context, Required extends boolean = tru
|
|
|
136
135
|
}, false, true>) => CheckedDefinition<Context, typeof implementation>;
|
|
137
136
|
};
|
|
138
137
|
export type InlineFactory<Context, Required extends boolean> = ReturnType<typeof operationFactory<Context, Required>>;
|
|
139
|
-
|
|
138
|
+
export {};
|
|
140
139
|
//# sourceMappingURL=operation.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.mjs","names":["domainFactory","helpers","domainHelpers","entries","command","operationFactory","implementation","query"],"sources":["../../../src/modules/foundation/operation.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- Internal helper storage is heterogeneous; the exported mapped signatures validate the schema-paired implementation. */\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, NeutralSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\n\ntype Supported<A> = A | PromiseLike<A>\nexport type Audit = Omit<AuditEntryInput, 'classification'> | null\nexport type NormalEntry = DomainOperationContract & {\n\tinput: NeutralSchema\n\tresult: NeutralSchema\n\treplayResult?: NeutralSchema\n\twire?: { schema: NeutralSchema; project: Function }\n}\ndeclare const checkedOperation: unique symbol\nexport type CheckedDefinition<Context, Definition, Key = unknown> = NoInfer<Definition> & {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: Definition\n\t\tkey: Key\n\t}\n}\nexport type CheckedOperation<Context> = {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: unknown\n\t\tkey: unknown\n\t}\n}\nexport type ValidatedOperations<Operations> = {\n\t[Key in keyof Operations]: Operations[Key] extends {\n\t\treadonly [checkedOperation]: { definition: infer Definition }\n\t}\n\t\t? Operations[Key] extends Definition\n\t\t\t? Operations[Key]\n\t\t\t: never\n\t\t: never\n}\nexport type ExactOperations<Operations, Entries> = ExactOperationKeys<Operations, Entries> & {\n\t[Key in keyof Operations]: Operations[Key] extends { readonly [checkedOperation]: { key: Key } }\n\t\t? Operations[Key]\n\t\t: never\n}\ntype Definition<Context, Entry extends NormalEntry> = {\n\thandler: (\n\t\tinput: ContractOutput<Entry['input']>,\n\t\tcontext: Context,\n\t) => Supported<ContractInput<Entry['result']>>\n\tpermission?: string\n\tmetadata?: object\n\taggregates?: readonly string[]\n\tguard?: (context: Context, input: ContractOutput<Entry['input']>) => Supported<void>\n\tprepare?: (\n\t\tcontext: Context,\n\t\tinput: ContractOutput<Entry['input']>,\n\t) => Supported<\n\t\t| { kind: 'replay'; result: unknown }\n\t\t| { kind: 'execute'; complete?: (result: ContractOutput<Entry['result']>) => Supported<void> }\n\t>\n\taudit?: (\n\t\tresolution: {\n\t\t\tcommand: ContractOutput<Entry['input']>\n\t\t\tresult: ContractOutput<Entry['result']>\n\t\t},\n\t\tcontext: Context,\n\t) => Supported<Audit>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tinput: ContractOutput<Entry['input']>\n\t\tcommand: ContractOutput<Entry['input']>\n\t\tcontext: Context\n\t\tmetadata: object\n\t\tnext: (options?: { context?: object }) => Promise<ContractInput<Entry['result']>>\n\t}) => Supported<ContractInput<Entry['result']>>\n}\ntype CommandRules<\n\tContext,\n\tEntry extends NormalEntry,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Command extends false\n\t? { audit?: never; prepare?: never; aggregates?: never; replayResult?: never }\n\t: Required extends true\n\t\t? { audit: NonNullable<Definition<Context, Entry>['audit']> }\n\t\t: {}\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype HandlerOptions<\n\tContext,\n\tInput extends NeutralSchema,\n\tResult extends NeutralSchema,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Omit<Definition<Context, { input: Input; result: Result }>, 'handler'> &\n\tForbidden & { handler?: never } & CommandRules<\n\t\tContext,\n\t\t{ input: Input; result: Result },\n\t\tCommand,\n\t\tRequired\n\t>\ntype HandlerArguments<Options, Required extends boolean> = Required extends true\n\t? [options: Options]\n\t: [options?: Options]\n\nexport type DomainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Kind in Command extends true ? 'command' : 'query']: {\n\t\t[Key in keyof Entries]: <const Implementation extends object>(\n\t\t\timplementation: Implementation &\n\t\t\t\tDefinition<Context, Entries[Key]> &\n\t\t\t\tForbidden &\n\t\t\t\tCommandRules<Context, Entries[Key], Command, Required>,\n\t\t) => DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\t\tCheckedDefinition<Context, Entries[Key] & Implementation, Key>\n\t} & {\n\t\thandler: <\n\t\t\tconst Input extends NeutralSchema,\n\t\t\tconst Result extends NeutralSchema,\n\t\t\tKey extends keyof Entries,\n\t\t\tHandler extends Supported<ContractInput<Result>>,\n\t\t\tconst Implementation extends object = Record<never, never>,\n\t\t>(\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t\t\t...options: HandlerArguments<\n\t\t\t\tImplementation & HandlerOptions<Context, Input, Result, Command, Required>,\n\t\t\t\tCommand extends true ? Required : false\n\t\t\t>\n\t\t) => DeclaredSchemas<{ input: Input; result: Result }> &\n\t\t\tCheckedDefinition<\n\t\t\t\tContext,\n\t\t\t\tNoInfer<Implementation> & {\n\t\t\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t\t\t},\n\t\t\t\tKey\n\t\t\t>\n\t}\n}\nexport type DomainImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tCheckedDefinition<\n\t\t\tContext,\n\t\t\tDefinition<Context, Entries[Key]> & CommandRules<Context, Entries[Key], Command, Required>,\n\t\t\tKey\n\t\t>\n}\nexport function domainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n>(entries: Entries, command: Command): DomainFactory<Context, Entries, Command, Required> {\n\tconst helpers = domainHelpers(entries)\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn { [command ? 'command' : 'query']: helpers } as DomainFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tRequired\n\t>\n}\nexport function operationFactory<Context, Required extends boolean = true>() {\n\tfunction command<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Replay extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification: string\n\t\t\treplayResult?: Replay &\n\t\t\t\t(ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, true, Required>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\tfunction query<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification?: string\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, false, true>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\treturn { command, query }\n}\nexport type InlineFactory<Context, Required extends boolean> = ReturnType<\n\ttypeof operationFactory<Context, Required>\n>\n"],"mappings":"yDA+JA,SAAgBA,EAKd,EAAkB,EAAsE,CACzF,IAAMC,EAAUC,EAAcC,CAAO,EAErC,MAAO,EAAGC,EAAU,UAAY,SAAUH,CAAQ,CAMnD,CACA,SAAgBI,GAA6D,CAC5E,SAASD,EAOR,EASC,CAED,OAAOE,CACR,CACA,SAASC,EAMR,EAOC,CAED,OAAOD,CACR,CACA,MAAO,CAAE,UAAS,OAAM,CACzB"}
|
|
1
|
+
{"version":3,"file":"operation.mjs","names":["domainFactory","helpers","domainHelpers","entries","command","operationFactory","implementation","query"],"sources":["../../../src/modules/foundation/operation.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- Internal helper storage is heterogeneous; the exported mapped signatures validate the schema-paired implementation. */\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, NeutralSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\n\ntype Supported<A> = A | PromiseLike<A>\nexport type Audit = Omit<AuditEntryInput, 'classification'> | null\nexport type NormalEntry = DomainOperationContract & {\n\tinput: NeutralSchema\n\tresult: NeutralSchema\n\treplayResult?: NeutralSchema\n\twire?: { schema: NeutralSchema; project: Function }\n}\ndeclare const checkedOperation: unique symbol\nexport type CheckedDefinition<Context, Definition, Key = unknown> = NoInfer<Definition> & {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: Definition\n\t\tkey: Key\n\t}\n}\nexport type CheckedOperation<Context> = {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: unknown\n\t\tkey: unknown\n\t}\n}\nexport type ValidatedOperations<Operations> = {\n\t[Key in keyof Operations]: Operations[Key] extends {\n\t\treadonly [checkedOperation]: { definition: infer Definition }\n\t}\n\t\t? Operations[Key] extends Definition\n\t\t\t? Operations[Key]\n\t\t\t: never\n\t\t: never\n}\nexport type ExactOperations<Operations, Entries> = ExactOperationKeys<Operations, Entries> & {\n\t[Key in keyof Operations]: Operations[Key] extends { readonly [checkedOperation]: { key: Key } }\n\t\t? Operations[Key]\n\t\t: never\n}\ntype Definition<Context, Entry extends NormalEntry> = {\n\thandler: (\n\t\tinput: ContractOutput<Entry['input']>,\n\t\tcontext: Context,\n\t) => Supported<ContractInput<Entry['result']>>\n\tpermission?: string\n\tmetadata?: object\n\taggregates?: readonly string[]\n\tguard?: (context: Context, input: ContractOutput<Entry['input']>) => Supported<void>\n\tprepare?: (\n\t\tcontext: Context,\n\t\tinput: ContractOutput<Entry['input']>,\n\t) => Supported<\n\t\t| { kind: 'replay'; result: unknown }\n\t\t| { kind: 'execute'; complete?: (result: ContractOutput<Entry['result']>) => Supported<void> }\n\t>\n\taudit?: (\n\t\tresolution: {\n\t\t\tcommand: ContractOutput<Entry['input']>\n\t\t\tresult: ContractOutput<Entry['result']>\n\t\t},\n\t\tcontext: Context,\n\t) => Supported<Audit>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tinput: ContractOutput<Entry['input']>\n\t\tcommand: ContractOutput<Entry['input']>\n\t\tcontext: Context\n\t\tmetadata: object\n\t\tnext: (options?: { context?: object }) => Promise<ContractInput<Entry['result']>>\n\t}) => Supported<ContractInput<Entry['result']>>\n}\ntype CommandRules<\n\tContext,\n\tEntry extends NormalEntry,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Command extends false\n\t? { audit?: never; prepare?: never; aggregates?: never; replayResult?: never }\n\t: Required extends true\n\t\t? { audit: NonNullable<Definition<Context, Entry>['audit']> }\n\t\t: {}\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype HandlerOptions<\n\tContext,\n\tInput extends NeutralSchema,\n\tResult extends NeutralSchema,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Omit<Definition<Context, { input: Input; result: Result }>, 'handler'> &\n\tForbidden & { handler?: never } & CommandRules<\n\t\tContext,\n\t\t{ input: Input; result: Result },\n\t\tCommand,\n\t\tRequired\n\t>\ntype HandlerArguments<Options, Required extends boolean> = Required extends true\n\t? [options: Options]\n\t: [options?: Options]\n\nexport type DomainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Kind in Command extends true ? 'command' : 'query']: {\n\t\t[Key in keyof Entries]: <const Implementation extends object>(\n\t\t\timplementation: Implementation &\n\t\t\t\tDefinition<Context, Entries[Key]> &\n\t\t\t\tForbidden &\n\t\t\t\tCommandRules<Context, Entries[Key], Command, Required>,\n\t\t) => DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\t\tCheckedDefinition<Context, Entries[Key] & Implementation, Key>\n\t} & {\n\t\thandler: <\n\t\t\tconst Input extends NeutralSchema,\n\t\t\tconst Result extends NeutralSchema,\n\t\t\tKey extends keyof Entries,\n\t\t\tHandler extends Supported<ContractInput<Result>>,\n\t\t\tconst Implementation extends object = Record<never, never>,\n\t\t>(\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t\t\t...options: HandlerArguments<\n\t\t\t\tImplementation & HandlerOptions<Context, Input, Result, Command, Required>,\n\t\t\t\tCommand extends true ? Required : false\n\t\t\t>\n\t\t) => DeclaredSchemas<{ input: Input; result: Result }> &\n\t\t\tCheckedDefinition<\n\t\t\t\tContext,\n\t\t\t\tNoInfer<Implementation> & {\n\t\t\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t\t\t},\n\t\t\t\tKey\n\t\t\t>\n\t}\n}\nexport type DomainImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tCheckedDefinition<\n\t\t\tContext,\n\t\t\tDefinition<Context, Entries[Key]> & CommandRules<Context, Entries[Key], Command, Required>,\n\t\t\tKey\n\t\t>\n}\nexport function domainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n>(entries: Entries, command: Command): DomainFactory<Context, Entries, Command, Required> {\n\tconst helpers = domainHelpers(entries)\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn { [command ? 'command' : 'query']: helpers } as DomainFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tRequired\n\t>\n}\nexport function operationFactory<Context, Required extends boolean = true>() {\n\tfunction command<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Replay extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification: string\n\t\t\treplayResult?: Replay &\n\t\t\t\t(ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, true, Required>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\tfunction query<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification?: string\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, false, true>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\treturn { command, query }\n}\nexport type InlineFactory<Context, Required extends boolean> = ReturnType<\n\ttypeof operationFactory<Context, Required>\n>\n"],"mappings":"A,yDA+JA,SAAgBA,EAKd,EAAkB,EAAsE,CACzF,IAAMC,EAAUC,EAAcC,CAAO,EAErC,MAAO,EAAGC,EAAU,UAAY,SAAUH,CAAQ,CAMnD,CACA,SAAgBI,GAA6D,CAC5E,SAASD,EAOR,EASC,CAED,OAAOE,CACR,CACA,SAASC,EAMR,EAOC,CAED,OAAOD,CACR,CACA,MAAO,CAAE,UAAS,OAAM,CACzB,C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { TableDefinition } from "convex/server";
|
|
2
|
+
/**
|
|
3
|
+
* Merges per-module table maps into the application schema map, rejecting
|
|
4
|
+
* duplicate table names across modules — the module-registry combinator for
|
|
5
|
+
* domain/table.ts: `defineSchema(createModule(catalogTables, salesTables))`.
|
|
6
|
+
* Accepts plain maps and `namespace(...)` maps side by side; namespaces add
|
|
7
|
+
* no keys, so the result is the same flat `{ tableName: TableDefinition }`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createModule<const Maps extends readonly Record<string, TableDefinition<any>>[]>(...maps: Maps): FlatTables<UnionToIntersection<Maps[number]>>;
|
|
10
|
+
type FlatTables<Map> = { [Key in keyof Map as Key extends string ? Key : never]: Map[Key]; };
|
|
11
|
+
declare const namespaceKey: unique symbol;
|
|
12
|
+
/** Declaration-level metadata carried by a `namespace(...)` table map. */
|
|
13
|
+
export type NamespaceInfo<Name extends string, Tables extends string> = {
|
|
14
|
+
readonly name: Name;
|
|
15
|
+
readonly tables: readonly Tables[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A table map tagged with a namespace. It is still a plain
|
|
19
|
+
* `{ tableName: TableDefinition }` map (the tag is a non-enumerable symbol),
|
|
20
|
+
* so `createModule`/`defineSchema` see exactly the tables they saw before.
|
|
21
|
+
*/
|
|
22
|
+
export type Namespace<Name extends string, Tables extends Record<string, TableDefinition<any>>> = Tables & NamespaceTag<Name, keyof Tables & string>;
|
|
23
|
+
/** The metadata-only shape of a `namespace(...)` map. */
|
|
24
|
+
export type NamespaceTag<Name extends string, Tables extends string> = {
|
|
25
|
+
readonly [namespaceKey]: NamespaceInfo<Name, Tables>;
|
|
26
|
+
};
|
|
27
|
+
type DotsToUnderscores<Name extends string> = Name extends `${infer Head}.${infer Tail}` ? `${Head}_${DotsToUnderscores<Tail>}` : Name;
|
|
28
|
+
/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */
|
|
29
|
+
export type NamespacePrefix<Name extends string> = `${DotsToUnderscores<Name>}_`;
|
|
30
|
+
/**
|
|
31
|
+
* Member name of a table. A table stored with its namespace prefix drops it
|
|
32
|
+
* (`Inventory_Items` in `Inventory` → `Items`); any other table name is
|
|
33
|
+
* PascalCased (`itemLedgerEntries` → `ItemLedgerEntries`).
|
|
34
|
+
*/
|
|
35
|
+
export type MemberName<TableName extends string, Name extends string = never> = [Name] extends [never] ? Capitalize<TableName> : TableName extends `${NamespacePrefix<Name>}${infer Rest extends string}` ? Rest extends '' ? Capitalize<TableName> : Rest : Capitalize<TableName>;
|
|
36
|
+
/** Fully qualified name: `<Namespace>.<Member>`, e.g. `Inventory.Items`. */
|
|
37
|
+
export type QualifiedName<Name extends string, TableName extends string> = `${Name}.${MemberName<TableName, Name>}`;
|
|
38
|
+
/** Options for `namespace(...)`. */
|
|
39
|
+
export type NamespaceOptions<Prefixed extends boolean = boolean> = {
|
|
40
|
+
/** Require every key to start with the namespace prefix (`Inventory_`). */
|
|
41
|
+
prefixed?: Prefixed;
|
|
42
|
+
};
|
|
43
|
+
type NamespaceMember = TableDefinition<any> | {
|
|
44
|
+
tableName: string;
|
|
45
|
+
table: TableDefinition<any>;
|
|
46
|
+
};
|
|
47
|
+
type MemberTables<Members extends Record<string, NamespaceMember>> = { [Key in keyof Members]: Members[Key] extends {
|
|
48
|
+
table: infer Table extends TableDefinition<any>;
|
|
49
|
+
} ? Table : Extract<Members[Key], TableDefinition<any>>; };
|
|
50
|
+
type CheckedMembers<Members extends Record<string, NamespaceMember>, Name extends string, Prefixed extends boolean> = { [Key in keyof Members]: Prefixed extends true ? Key extends `${NamespacePrefix<Name>}${infer Rest}` ? Rest extends '' ? never : CheckedMember<Members[Key], Key> : never : CheckedMember<Members[Key], Key>; };
|
|
51
|
+
type CheckedMember<Member, Key> = Member extends {
|
|
52
|
+
tableName: infer TableName;
|
|
53
|
+
} ? TableName extends Key ? Member : {
|
|
54
|
+
tableName: Key;
|
|
55
|
+
table: TableDefinition<any>;
|
|
56
|
+
} : Member;
|
|
57
|
+
type CheckedNamespaceName<Name extends string> = Name extends '' ? never : Name extends `${string}..${string}` | `.${string}` | `${string}.` ? never : Name;
|
|
58
|
+
/**
|
|
59
|
+
* Groups tables under a declaration-level namespace, like AL's
|
|
60
|
+
* `namespace Microsoft.Inventory.Item;`. Keys are the real (stored) table
|
|
61
|
+
* names, exactly as in an un-namespaced module map. A key stored with the
|
|
62
|
+
* namespace prefix (`Inventory_Items`, or `Microsoft_Inventory_Items` for
|
|
63
|
+
* `Microsoft.Inventory`) has the remainder as its member name (`Items`);
|
|
64
|
+
* any other key is PascalCased (`items` → `Items`). The qualified name is
|
|
65
|
+
* `<Namespace>.<Member>` (`Inventory.Items`). Storage, ids, queries and
|
|
66
|
+
* generated types are unchanged.
|
|
67
|
+
*
|
|
68
|
+
* `{ prefixed: true }` requires every key to carry the prefix: a key
|
|
69
|
+
* without it is a type error and a runtime error.
|
|
70
|
+
*
|
|
71
|
+
* A member may be a `TableDefinition` (`items.table.index(...)`) or a table
|
|
72
|
+
* boundary (`items`); a boundary whose `tableName` differs from its key is a
|
|
73
|
+
* type error and a runtime error. Dotted names (`Microsoft.Inventory`) are
|
|
74
|
+
* allowed; each segment is an identifier (`Microsoft.Inventory`, `sales`).
|
|
75
|
+
*/
|
|
76
|
+
export declare function namespace<const Name extends string, const Members extends Record<string, NamespaceMember>, const Prefixed extends boolean = false>(name: Name & CheckedNamespaceName<Name>, members: Members & CheckedMembers<Members, Name, Prefixed>, options?: NamespaceOptions<Prefixed>): Namespace<Name, MemberTables<Members>>;
|
|
77
|
+
/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */
|
|
78
|
+
export declare function namespacePrefix<const Name extends string>(name: Name): NamespacePrefix<Name>;
|
|
79
|
+
/**
|
|
80
|
+
* Member name of a table name: without the namespace prefix when given and
|
|
81
|
+
* present (`memberName('Inventory_Items', 'Inventory')` → `Items`), else PascalCased.
|
|
82
|
+
*/
|
|
83
|
+
export declare function memberName<const TableName extends string, const Name extends string = never>(tableName: TableName, namespaceName?: Name): MemberName<TableName, Name>;
|
|
84
|
+
/** The namespace name of a `namespace(...)` map. */
|
|
85
|
+
export declare function namespaceName<const Name extends string>(ns: NamespaceTag<Name, string>): Name;
|
|
86
|
+
/** The stored table names declared in a namespace, in declaration order. */
|
|
87
|
+
export declare function tablesOf<const Tables extends string>(ns: NamespaceTag<string, Tables>): readonly Tables[];
|
|
88
|
+
type NamespaceEntries<Spaces extends readonly NamespaceTag<string, string>[]> = { [Index in keyof Spaces]: Spaces[Index] extends NamespaceTag<infer Name, infer Tables> ? { [TableName in Tables]: Name; } : never; }[number];
|
|
89
|
+
/**
|
|
90
|
+
* Typed, read-only qualified-name lookup over namespaces (no global registry:
|
|
91
|
+
* build one next to `createModule` and import it where labels are needed).
|
|
92
|
+
* Rejects duplicate namespace names and tables claimed by two namespaces.
|
|
93
|
+
*/
|
|
94
|
+
export declare function namespaceIndex<const Spaces extends readonly NamespaceTag<string, string>[]>(...spaces: Spaces): {
|
|
95
|
+
qualifiedName<const Table extends keyof UnionToIntersection<NamespaceEntries<Spaces>> & string>(table: Table): { [Key in Table]: QualifiedName<UnionToIntersection<NamespaceEntries<Spaces>>[Key] & string, Key>; }[Table];
|
|
96
|
+
namespaceOf<const Table extends keyof UnionToIntersection<NamespaceEntries<Spaces>> & string>(table: Table): UnionToIntersection<NamespaceEntries<Spaces>>[Table];
|
|
97
|
+
memberName: typeof memberName;
|
|
98
|
+
tablesOf<const Name extends Spaces[number] extends NamespaceTag<infer Name_1 extends string, string> ? Name_1 : never>(name: Name): readonly { [Table in keyof UnionToIntersection<NamespaceEntries<Spaces>> & string]: UnionToIntersection<NamespaceEntries<Spaces>>[Table] extends Name ? Table : never; }[keyof UnionToIntersection<NamespaceEntries<Spaces>> & string][];
|
|
99
|
+
namespaces: (Spaces[number] extends NamespaceTag<infer Name_1 extends string, string> ? Name_1 : never)[];
|
|
100
|
+
has(table: string): table is keyof UnionToIntersection<NamespaceEntries<Spaces>> & string;
|
|
101
|
+
};
|
|
102
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (member: Union) => void : never) extends ((member: infer Intersection) => void) ? Intersection : never;
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=namespace.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(...e){let t={},n=/* @__PURE__ */ new Set;for(let r of e){let e=u(r);if(e){if(n.has(e.name))throw Error(`Namespace "${e.name}" is declared more than once`);n.add(e.name)}for(let[e,n]of Object.entries(r)){if(e in t)throw Error(`Table "${e}" is declared by more than one module`);t[e]=n}}return t}const t=Symbol.for(`cvx-kit/table/namespace`),n=/^[A-Za-z][A-Za-z0-9]*$/,r=/^[A-Za-z][A-Za-z0-9_]*$/;function i(e,i,o={}){if(!e.split(`.`).every(e=>n.test(e)))throw Error(`Namespace "${e}" must be dot-separated identifiers (e.g. "Microsoft.Inventory" or "sales")`);let s={};for(let[t,n]of Object.entries(i)){if(!r.test(t))throw Error(`Namespace "${e}" member "${t}" must be a table name (letters, digits and underscores)`);if(o.prefixed&&!d(t,e))throw Error(`Namespace "${e}" member "${t}" must start with "${a(e)}"`);if(`tableName`in n){if(n.tableName!==t)throw Error(`Namespace "${e}" member "${t}" holds table "${n.tableName}"; keys must be the table name`);s[t]=n.table}else s[t]=n}return Object.defineProperty(s,t,{value:Object.freeze({name:e,tables:Object.freeze(Object.keys(s))}),enumerable:!1}),s}function a(e){return`${e.replaceAll(`.`,`_`)}_`}function o(e,t){return t!==void 0&&d(e,t)?e.slice(a(t).length):e.charAt(0).toUpperCase()+e.slice(1)}function s(e){return u(e).name}function c(e){return u(e).tables}function l(...e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e){let e=u(r);if(!e)throw Error(`namespaceIndex accepts only namespace(...) maps`);if(n.has(e.name))throw Error(`Namespace "${e.name}" is declared more than once`);n.set(e.name,e.tables);for(let n of e.tables){let r=t.get(n);if(r)throw Error(`Table "${n}" is declared by namespaces "${r}" and "${e.name}"`);t.set(n,e.name)}}let r=e=>{let n=t.get(e);if(n===void 0)throw Error(`Table "${e}" is not in a namespace`);return n};return{qualifiedName(e){let t=r(e);return`${t}.${o(e,t)}`},namespaceOf(e){return r(e)},memberName:o,tablesOf(e){let t=n.get(e);if(!t)throw Error(`Namespace "${e}" is not indexed`);return t},namespaces:f(n),has(e){return t.has(e)}}}function u(e){return e[t]}function d(e,t){let n=a(t);return e.startsWith(n)&&e.length>n.length}function f(e){let t=[];for(let n of e.keys())t.push(n);return t}export{e as createModule,o as memberName,i as namespace,l as namespaceIndex,s as namespaceName,a as namespacePrefix,c as tablesOf};
|
|
2
|
+
//# sourceMappingURL=namespace.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.mjs","names":["createModule","maps","combined","namespaceNames","map","meta","namespaceMeta","tableName","definition","namespaceKey","NAMESPACE_SEGMENT","TABLE_NAME","namespace","name","segment","tables","key","member","members","options","hasPrefix","namespacePrefix","memberName","namespaceName","ns","tablesOf","namespaceIndex","spaces","byTable","byName","space","table","owner","indexedNames","prefix","names"],"sources":["../src/namespace.ts"],"sourcesContent":["import type { TableDefinition } from 'convex/server'\n\n/**\n * Merges per-module table maps into the application schema map, rejecting\n * duplicate table names across modules — the module-registry combinator for\n * domain/table.ts: `defineSchema(createModule(catalogTables, salesTables))`.\n * Accepts plain maps and `namespace(...)` maps side by side; namespaces add\n * no keys, so the result is the same flat `{ tableName: TableDefinition }`.\n */\nexport function createModule<const Maps extends readonly Record<string, TableDefinition<any>>[]>(\n\t...maps: Maps\n): FlatTables<UnionToIntersection<Maps[number]>> {\n\tconst combined: Record<string, TableDefinition<any>> = {}\n\tconst namespaceNames = new Set<string>()\n\tfor (const map of maps) {\n\t\tconst meta = namespaceMeta(map)\n\t\tif (meta) {\n\t\t\tif (namespaceNames.has(meta.name)) {\n\t\t\t\tthrow new Error(`Namespace \"${meta.name}\" is declared more than once`)\n\t\t\t}\n\t\t\tnamespaceNames.add(meta.name)\n\t\t}\n\t\tfor (const [tableName, definition] of Object.entries(map)) {\n\t\t\tif (tableName in combined) {\n\t\t\t\tthrow new Error(`Table \"${tableName}\" is declared by more than one module`)\n\t\t\t}\n\t\t\tcombined[tableName] = definition\n\t\t}\n\t}\n\t// SAFETY: every string-keyed input entry is copied, and duplicate keys are rejected above.\n\treturn combined as FlatTables<UnionToIntersection<Maps[number]>>\n}\n\ntype FlatTables<Map> = { [Key in keyof Map as Key extends string ? Key : never]: Map[Key] }\n\nconst namespaceKey: unique symbol = Symbol.for('cvx-kit/table/namespace')\n\n/** Declaration-level metadata carried by a `namespace(...)` table map. */\nexport type NamespaceInfo<Name extends string, Tables extends string> = {\n\treadonly name: Name\n\treadonly tables: readonly Tables[]\n}\n\n/**\n * A table map tagged with a namespace. It is still a plain\n * `{ tableName: TableDefinition }` map (the tag is a non-enumerable symbol),\n * so `createModule`/`defineSchema` see exactly the tables they saw before.\n */\nexport type Namespace<\n\tName extends string,\n\tTables extends Record<string, TableDefinition<any>>,\n> = Tables & NamespaceTag<Name, keyof Tables & string>\n\n/** The metadata-only shape of a `namespace(...)` map. */\nexport type NamespaceTag<Name extends string, Tables extends string> = {\n\treadonly [namespaceKey]: NamespaceInfo<Name, Tables>\n}\n\ntype DotsToUnderscores<Name extends string> = Name extends `${infer Head}.${infer Tail}`\n\t? `${Head}_${DotsToUnderscores<Tail>}`\n\t: Name\n\n/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */\nexport type NamespacePrefix<Name extends string> = `${DotsToUnderscores<Name>}_`\n\n/**\n * Member name of a table. A table stored with its namespace prefix drops it\n * (`Inventory_Items` in `Inventory` → `Items`); any other table name is\n * PascalCased (`itemLedgerEntries` → `ItemLedgerEntries`).\n */\nexport type MemberName<TableName extends string, Name extends string = never> = [Name] extends [\n\tnever,\n]\n\t? Capitalize<TableName>\n\t: TableName extends `${NamespacePrefix<Name>}${infer Rest extends string}`\n\t\t? Rest extends ''\n\t\t\t? Capitalize<TableName>\n\t\t\t: Rest\n\t\t: Capitalize<TableName>\n\n/** Fully qualified name: `<Namespace>.<Member>`, e.g. `Inventory.Items`. */\nexport type QualifiedName<\n\tName extends string,\n\tTableName extends string,\n> = `${Name}.${MemberName<TableName, Name>}`\n\n/** Options for `namespace(...)`. */\nexport type NamespaceOptions<Prefixed extends boolean = boolean> = {\n\t/** Require every key to start with the namespace prefix (`Inventory_`). */\n\tprefixed?: Prefixed\n}\n\ntype NamespaceMember = TableDefinition<any> | { tableName: string; table: TableDefinition<any> }\ntype MemberTables<Members extends Record<string, NamespaceMember>> = {\n\t[Key in keyof Members]: Members[Key] extends { table: infer Table extends TableDefinition<any> }\n\t\t? Table\n\t\t: Extract<Members[Key], TableDefinition<any>>\n}\ntype CheckedMembers<\n\tMembers extends Record<string, NamespaceMember>,\n\tName extends string,\n\tPrefixed extends boolean,\n> = {\n\t[Key in keyof Members]: Prefixed extends true\n\t\t? Key extends `${NamespacePrefix<Name>}${infer Rest}`\n\t\t\t? Rest extends ''\n\t\t\t\t? never\n\t\t\t\t: CheckedMember<Members[Key], Key>\n\t\t\t: never\n\t\t: CheckedMember<Members[Key], Key>\n}\ntype CheckedMember<Member, Key> = Member extends { tableName: infer TableName }\n\t? TableName extends Key\n\t\t? Member\n\t\t: { tableName: Key; table: TableDefinition<any> }\n\t: Member\ntype CheckedNamespaceName<Name extends string> = Name extends ''\n\t? never\n\t: Name extends `${string}..${string}` | `.${string}` | `${string}.`\n\t\t? never\n\t\t: Name\n\nconst NAMESPACE_SEGMENT = /^[A-Za-z][A-Za-z0-9]*$/\n// Convex table names: letters, digits and underscores, not starting with an underscore.\nconst TABLE_NAME = /^[A-Za-z][A-Za-z0-9_]*$/\n\n/**\n * Groups tables under a declaration-level namespace, like AL's\n * `namespace Microsoft.Inventory.Item;`. Keys are the real (stored) table\n * names, exactly as in an un-namespaced module map. A key stored with the\n * namespace prefix (`Inventory_Items`, or `Microsoft_Inventory_Items` for\n * `Microsoft.Inventory`) has the remainder as its member name (`Items`);\n * any other key is PascalCased (`items` → `Items`). The qualified name is\n * `<Namespace>.<Member>` (`Inventory.Items`). Storage, ids, queries and\n * generated types are unchanged.\n *\n * `{ prefixed: true }` requires every key to carry the prefix: a key\n * without it is a type error and a runtime error.\n *\n * A member may be a `TableDefinition` (`items.table.index(...)`) or a table\n * boundary (`items`); a boundary whose `tableName` differs from its key is a\n * type error and a runtime error. Dotted names (`Microsoft.Inventory`) are\n * allowed; each segment is an identifier (`Microsoft.Inventory`, `sales`).\n */\nexport function namespace<\n\tconst Name extends string,\n\tconst Members extends Record<string, NamespaceMember>,\n\tconst Prefixed extends boolean = false,\n>(\n\tname: Name & CheckedNamespaceName<Name>,\n\tmembers: Members & CheckedMembers<Members, Name, Prefixed>,\n\toptions: NamespaceOptions<Prefixed> = {},\n): Namespace<Name, MemberTables<Members>> {\n\tif (!name.split('.').every((segment) => NAMESPACE_SEGMENT.test(segment))) {\n\t\tthrow new Error(\n\t\t\t`Namespace \"${name}\" must be dot-separated identifiers (e.g. \"Microsoft.Inventory\" or \"sales\")`,\n\t\t)\n\t}\n\tconst tables: Record<string, TableDefinition<any>> = {}\n\t// SAFETY: CheckedMembers only narrows member types; every member is still a NamespaceMember.\n\tfor (const [key, member] of Object.entries(members as Record<string, NamespaceMember>)) {\n\t\tif (!TABLE_NAME.test(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Namespace \"${name}\" member \"${key}\" must be a table name (letters, digits and underscores)`,\n\t\t\t)\n\t\t}\n\t\tif (options.prefixed && !hasPrefix(key, name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Namespace \"${name}\" member \"${key}\" must start with \"${namespacePrefix(name)}\"`,\n\t\t\t)\n\t\t}\n\t\tif ('tableName' in member) {\n\t\t\tif (member.tableName !== key) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Namespace \"${name}\" member \"${key}\" holds table \"${member.tableName}\"; keys must be the table name`,\n\t\t\t\t)\n\t\t\t}\n\t\t\ttables[key] = member.table\n\t\t} else {\n\t\t\ttables[key] = member\n\t\t}\n\t}\n\tObject.defineProperty(tables, namespaceKey, {\n\t\tvalue: Object.freeze({ name, tables: Object.freeze(Object.keys(tables)) }),\n\t\tenumerable: false,\n\t})\n\t// SAFETY: tables holds one TableDefinition per member key plus the symbol tag.\n\treturn tables as Namespace<Name, MemberTables<Members>>\n}\n\n/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */\nexport function namespacePrefix<const Name extends string>(name: Name) {\n\t// SAFETY: replacing every dot with an underscore and appending one is what NamespacePrefix computes.\n\treturn `${name.replaceAll('.', '_')}_` as NamespacePrefix<Name>\n}\n\n/**\n * Member name of a table name: without the namespace prefix when given and\n * present (`memberName('Inventory_Items', 'Inventory')` → `Items`), else PascalCased.\n */\nexport function memberName<const TableName extends string, const Name extends string = never>(\n\ttableName: TableName,\n\tnamespaceName?: Name,\n) {\n\tconst name =\n\t\tnamespaceName !== undefined && hasPrefix(tableName, namespaceName)\n\t\t\t? tableName.slice(namespacePrefix(namespaceName).length)\n\t\t\t: tableName.charAt(0).toUpperCase() + tableName.slice(1)\n\t// SAFETY: the prefix is stripped or the name capitalised exactly as MemberName computes.\n\treturn name as MemberName<TableName, Name>\n}\n\n/** The namespace name of a `namespace(...)` map. */\nexport function namespaceName<const Name extends string>(ns: NamespaceTag<Name, string>): Name {\n\t// SAFETY: a NamespaceTag is only produced by namespace(...), which records its Name in the tag.\n\treturn namespaceMeta(ns)!.name as Name\n}\n\n/** The stored table names declared in a namespace, in declaration order. */\nexport function tablesOf<const Tables extends string>(\n\tns: NamespaceTag<string, Tables>,\n): readonly Tables[] {\n\t// SAFETY: a NamespaceTag is only produced by namespace(...), which records its member keys in the tag.\n\treturn namespaceMeta(ns)!.tables as readonly Tables[]\n}\n\ntype NamespaceEntries<Spaces extends readonly NamespaceTag<string, string>[]> = {\n\t[Index in keyof Spaces]: Spaces[Index] extends NamespaceTag<infer Name, infer Tables>\n\t\t? { [TableName in Tables]: Name }\n\t\t: never\n}[number]\ntype TableNamespaceMap<Spaces extends readonly NamespaceTag<string, string>[]> =\n\tUnionToIntersection<NamespaceEntries<Spaces>>\n\n/**\n * Typed, read-only qualified-name lookup over namespaces (no global registry:\n * build one next to `createModule` and import it where labels are needed).\n * Rejects duplicate namespace names and tables claimed by two namespaces.\n */\nexport function namespaceIndex<const Spaces extends readonly NamespaceTag<string, string>[]>(\n\t...spaces: Spaces\n) {\n\ttype Map = TableNamespaceMap<Spaces>\n\ttype TableName = keyof Map & string\n\ttype NameOf = Spaces[number] extends NamespaceTag<infer Name, string> ? Name : never\n\tconst byTable = new Map<string, string>()\n\tconst byName = new Map<string, readonly string[]>()\n\tfor (const space of spaces) {\n\t\tconst meta = namespaceMeta(space)\n\t\tif (!meta) throw new Error('namespaceIndex accepts only namespace(...) maps')\n\t\tif (byName.has(meta.name)) {\n\t\t\tthrow new Error(`Namespace \"${meta.name}\" is declared more than once`)\n\t\t}\n\t\tbyName.set(meta.name, meta.tables)\n\t\tfor (const table of meta.tables) {\n\t\t\tconst owner = byTable.get(table)\n\t\t\tif (owner) {\n\t\t\t\tthrow new Error(`Table \"${table}\" is declared by namespaces \"${owner}\" and \"${meta.name}\"`)\n\t\t\t}\n\t\t\tbyTable.set(table, meta.name)\n\t\t}\n\t}\n\tconst owner = (table: string) => {\n\t\tconst name = byTable.get(table)\n\t\tif (name === undefined) throw new Error(`Table \"${table}\" is not in a namespace`)\n\t\treturn name\n\t}\n\treturn {\n\t\tqualifiedName<const Table extends TableName>(table: Table) {\n\t\t\tconst name = owner(table)\n\t\t\t// SAFETY: owner returns the namespace that declared this table, as Map records.\n\t\t\treturn `${name}.${memberName(table, name)}` as {\n\t\t\t\t[Key in Table]: QualifiedName<Map[Key] & string, Key>\n\t\t\t}[Table]\n\t\t},\n\t\tnamespaceOf<const Table extends TableName>(table: Table) {\n\t\t\t// SAFETY: owner returns the namespace that declared this table, as Map records.\n\t\t\treturn owner(table) as Map[Table]\n\t\t},\n\t\tmemberName,\n\t\ttablesOf<const Name extends NameOf>(name: Name) {\n\t\t\tconst tables = byName.get(name)\n\t\t\tif (!tables) throw new Error(`Namespace \"${name}\" is not indexed`)\n\t\t\t// SAFETY: byName records exactly the tables of each indexed namespace.\n\t\t\treturn tables as readonly {\n\t\t\t\t[Table in TableName]: Map[Table] extends Name ? Table : never\n\t\t\t}[TableName][]\n\t\t},\n\t\tnamespaces: indexedNames<NameOf>(byName),\n\t\thas(table: string): table is TableName {\n\t\t\treturn byTable.has(table)\n\t\t},\n\t}\n}\n\ntype UnionToIntersection<Union> = (\n\tUnion extends unknown ? (member: Union) => void : never\n) extends (member: infer Intersection) => void\n\t? Intersection\n\t: never\n\n/** A table map as `createModule` and `namespaceIndex` receive it; a namespace adds a symbol tag. */\ntype TableMap = Record<string, TableDefinition<any>> | NamespaceTag<string, string>\n\nfunction namespaceMeta(map: TableMap): NamespaceInfo<string, string> | undefined {\n\t// SAFETY: the tag is either absent or the frozen NamespaceInfo that namespace(...) defined.\n\treturn (map as { [namespaceKey]?: NamespaceInfo<string, string> })[namespaceKey]\n}\n\nfunction hasPrefix(tableName: string, name: string) {\n\tconst prefix = namespacePrefix(name)\n\treturn tableName.startsWith(prefix) && tableName.length > prefix.length\n}\n\nfunction indexedNames<Name extends string>(byName: ReadonlyMap<string, readonly string[]>) {\n\tconst names: Name[] = []\n\tfor (const name of byName.keys()) {\n\t\t// SAFETY: namespaceIndex keys byName by the names of the namespaces it indexed, which Name lists.\n\t\tnames.push(name as Name)\n\t}\n\treturn names\n}\n"],"mappings":"AASA,SAAgBA,EACf,GAAGC,EAC6C,CAChD,IAAMC,EAAiD,CAAC,EAClDC,kBAAiB,IAAI,IAC3B,IAAK,IAAMC,KAAOH,EAAM,CACvB,IAAMI,EAAOC,EAAcF,CAAG,EAC9B,GAAIC,EAAM,CACT,GAAIF,EAAe,IAAIE,EAAK,IAAI,EAC/B,MAAU,MAAM,cAAcA,EAAK,KAAK,6BAA6B,EAEtEF,EAAe,IAAIE,EAAK,IAAI,CAC7B,CACA,IAAK,GAAM,CAACE,EAAWC,KAAe,OAAO,QAAQJ,CAAG,EAAG,CAC1D,GAAIG,KAAaL,EAChB,MAAU,MAAM,UAAUK,EAAU,sCAAsC,EAE3E,EAASA,GAAaC,CACvB,CACD,CAEA,OAAON,CACR,CAIA,MAAMO,EAA8B,OAAO,IAAI,yBAAyB,EAuFlEC,EAAoB,yBAEpBC,EAAa,0BAoBnB,SAAgBC,EAKf,EACA,EACA,EAAsC,CAAC,EACE,CACzC,GAAI,CAACC,EAAK,MAAM,GAAG,CAAC,CAAC,MAAO,GAAYH,EAAkB,KAAKI,CAAO,CAAC,EACtE,MAAU,MACT,cAAcD,EAAK,4EACpB,EAED,IAAME,EAA+C,CAAC,EAEtD,IAAK,GAAM,CAACC,EAAKC,KAAW,OAAO,QAAQC,CAA0C,EAAG,CACvF,GAAI,CAACP,EAAW,KAAKK,CAAG,EACvB,MAAU,MACT,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|
|
|
1
1
|
import { ResolverFactory } from "oxc-resolver";
|
|
2
|
-
//#region src/oxlint/architecture.d.ts
|
|
3
2
|
export interface ArchitectureOptions {
|
|
4
3
|
cwd?: string;
|
|
5
4
|
convexDir?: string;
|
|
@@ -21,5 +20,4 @@ export declare function resolveImport(resolver: ResolverFactory, filename: strin
|
|
|
21
20
|
export declare function architectureAnchor(root: string): string | null;
|
|
22
21
|
/** Only these two factory declarations may omit root business ownership. */
|
|
23
22
|
export declare function narrowRootDeclaration(file: string, source: string): boolean;
|
|
24
|
-
//#endregion
|
|
25
23
|
//# sourceMappingURL=architecture.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{conventionalComponentRoot as e,findComponentRoot as t}from"./components.mjs";import{dirname as n,relative as r,resolve as i,sep as a}from"node:path";import{existsSync as o,readFileSync as s,readdirSync as c,realpathSync as l}from"node:fs";import{Visitor as u,parseSync as d}from"oxc-parser";import{ResolverFactory as f}from"oxc-resolver";function p(c={}){let u=i(c.cwd??process.cwd(),c.convexDir??`convex`),f=o(u)?l(u):u,p=[];if(!o(f))return[{code:`missing-root`,file:`.`,message:`Convex directory does not exist: ${f}`}];let g=(c.componentDirs??[]).map(e=>i(f,e)),S=[...v(f,p)],D=/* @__PURE__ */ new Map;for(let n of S){let o=t(i(f,n),g)??e(i(f,n),f);o&&(o===f||o.startsWith(f+a))&&D.set(n,r(f,o).split(a).join(`/`))}let O=new Set(D.values());for(let e=p.length-1;e>=0;e--){let t=p[e];t.code===`root-directory`&&[...O].some(e=>!e||e===t.file||e.startsWith(t.file+`/`))&&!S.some(e=>e.startsWith(t.file+`/`)&&!D.has(e))&&p.splice(e,1)}let k=/* @__PURE__ */ new Set,A=/* @__PURE__ */ new Set,j=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Map,N=/* @__PURE__ */ new Map,P=m();for(let e of S){let t=i(f,e),o=d(t,s(t,`utf8`));if(o.errors.length){p.push({code:`parse`,file:e,message:`Cannot validate ${e}: ${o.errors[0].message}`});continue}if(y(e)){e.includes(`__tests__/`)?n(e).endsWith(`__tests__`)&&x(o.program)&&A.add(n(n(e))):p.push({code:`test-location`,file:e,message:`Place tests in a sibling __tests__/ directory.`});continue}if(e.split(`/`).includes(`__tests__`))continue;let c=D.get(e),l=c===void 0?e:r(i(f,c),t).split(a).join(`/`);c===void 0&&/^domain\/[^/]+$/.test(e)&&e!==`domain/table.ts`&&p.push({code:`domain-entry`,file:e,message:`Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.`}),b(o.program)&&e!==`domain/table.ts`&&!_(l,s(t,`utf8`))&&k.add(n(e));let u=w(e)??``,m=/* @__PURE__ */ new Set;N.set(e,m);for(let n of C(o.program)){let i=h(P,t,n);if(!i)continue;let o=r(f,i).split(a).join(`/`);if(m.add(o),c!==void 0&&D.get(o)===c){let t=M.get(e)??/* @__PURE__ */ new Set;M.set(e,t),t.add(o)}let s=w(o);if(u&&s&&u!==s){let e=j.get(u)??/* @__PURE__ */ new Set;j.set(u,e),e.add(s)}}}for(let e of k)A.has(e)||p.push({code:`tests`,file:e,message:`${e}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`});p.push(...E(N));for(let e of[...T(j),...T(M)])p.push({code:`cycle`,file:e[0],message:`Module dependency cycle: ${e.join(` → `)}.`});return p.sort((e,t)=>e.file.localeCompare(t.file)||e.code.localeCompare(t.code))}function m(e=!0){return new f({tsconfig:`auto`,extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],extensionAlias:{".js":[`.ts`,`.tsx`,`.js`],".mjs":[`.mts`,`.mjs`],".cjs":[`.cts`,`.cjs`]},conditionNames:[`types`,`import`,`node`,`default`],symlinks:e})}function h(e,t,r){return e.resolveFileSync(t,r).path||(r.startsWith(`.`)?i(n(t),r):null)}function g(e){if(!o(e))return null;if(o(i(e,`convex.config.ts`)))return l(i(e,`convex.config.ts`));e=l(e);for(let t of v(e,[]))if(!t.includes(`__tests__/`)&&!y(t))return i(e,t);return null}function _(e,t){let n=e===`relations.ts`?`defineRelations`:e===`querying.ts`?`createQueryEngine`:null;if(!n)return!1;let r=d(e,t);if(r.errors.length)return!1;let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=0,s=!1;function c(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name))return null;let n=a.get(e.name);return n?c(n,new Set(t).add(e.name)):i.get(e.name)??null}return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&c(e.object,t)===`*`?e.property.name:null}function l(e,t,n=!1){if(e.type===`Identifier`||e.type===`Literal`)return!0;if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return l(e.expression,t,n);if(e.type===`MemberExpression`)return!e.computed&&l(e.object,t);if(e.type===`ArrayExpression`)return e.elements.every(e=>e!==null&&l(e,t));if(e.type===`ObjectExpression`)return e.properties.every(e=>e.type===`Property`&&!e.computed&&e.kind===`init`&&!e.method&&l(e.value,t));if(e.type===`ArrowFunctionExpression`&&n&&!t&&e.params.length===1&&e.params[0].type===`Identifier`&&!e.async){let t=e.body.type===`ParenthesizedExpression`?e.body.expression:e.body;return t.type===`ObjectExpression`&&l(t,e.params[0].name)}if(e.type===`CallExpression`&&t){let n=e.callee,r=[];for(;n.type===`MemberExpression`&&!n.computed&&n.property.type===`Identifier`;)r.unshift(n.property.name),n=n.object;return n.type===`Identifier`&&n.name===t&&(r.length===2&&[`one`,`many`].includes(r[0])||r.length===3&&r[2]===`through`)&&e.arguments.every(e=>l(e,t))}return!1}for(let t of r.program.body){if(t.type===`ImportDeclaration`){if(t.importKind===`type`)continue;for(let n of t.specifiers)(n.type!==`ImportSpecifier`||n.importKind!==`type`)&&[`cvx-kit`,`cvx-kit/${e.slice(0,-3)}`].includes(t.source.value)&&i.set(n.local.name,n.type===`ImportSpecifier`?n.imported.type===`Identifier`?n.imported.name:``:n.type===`ImportNamespaceSpecifier`?`*`:``);continue}if(t.type===`EmptyStatement`||t.type===`TSTypeAliasDeclaration`||t.type===`TSInterfaceDeclaration`)continue;let r=t.type===`ExportNamedDeclaration`?t.declaration:t;if(r?.type!==`VariableDeclaration`||r.kind!==`const`)return!1;for(let e of r.declarations){if(e.id.type!==`Identifier`||!e.init)return!1;if(e.init.type===`CallExpression`&&c(e.init.callee)===n){if(!e.init.arguments.every((e,t)=>l(e,void 0,n===`defineRelations`&&t===1)))return!1;o++,s||=t.type===`ExportNamedDeclaration`}else if(t.type===`ExportNamedDeclaration`||!l(e.init))return!1;a.set(e.id.name,e.init)}}return o===1&&s}function*v(e,t){let n=/* @__PURE__ */ new Set([`_generated`,`__tests__`,`api`,`domain`,`application`,`migrations`,`components`]);function*o(s){for(let l of c(s,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let c=i(s,l.name),u=r(e,c).split(a).join(`/`);if(l.isSymbolicLink()){t.push({code:`symlink`,file:u,message:`Keep application source inside its owning directory; symlinked files and folders are not allowed.`});continue}l.isDirectory()?(s===e&&!n.has(l.name)&&t.push({code:`root-directory`,file:u,message:`Root folder ${l.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`}),l.name!==`_generated`&&l.name!==`node_modules`&&!l.name.startsWith(`.`)&&(yield*o(c))):/\.[cm]?[jt]sx?$/.test(l.name)&&!/\.d\.[cm]?ts$/.test(l.name)&&(yield u)}}yield*o(e)}function y(e){return/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(e)}function b(e){return e.body.some(e=>{let t=e.type===`ExportNamedDeclaration`?e.declaration:e;return t&&`declare`in t&&t.declare||e.type===`ImportDeclaration`||e.type===`EmptyStatement`?!1:e.type===`ExportNamedDeclaration`?e.exportKind===`type`||!e.declaration?!1:![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`].includes(e.declaration.type):![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`,`ExportAllDeclaration`].includes(e.type)})}function x(e){let t=/* @__PURE__ */ new Map([[`test`,`test`],[`it`,`it`],[`describe`,`describe`],[`suite`,`suite`]]);for(let n of e.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`FunctionDeclaration`&&e.id&&t.delete(e.id.name),e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.delete(n.id.name);if(n.type===`ImportDeclaration`)for(let e of n.specifiers)t.delete(e.local.name),[`vitest`,`vite-plus/test`,`bun:test`,`node:test`,`@jest/globals`].includes(n.source.value)&&(e.type===`ImportNamespaceSpecifier`?t.set(e.local.name,`*`):e.type===`ImportDefaultSpecifier`?t.set(e.local.name,`test`):e.imported.type===`Identifier`&&t.set(e.local.name,e.imported.name))}let n=[];new u({CallExpression(e){n.push(e)}}).visit(e);let r=n.filter(e=>{let n=S(e.callee,t);return[`test`,`it`,`describe`,`suite`].includes(n[0])&&(n.some(e=>[`skip`,`todo`,`skipIf`,`runIf`].includes(e))||e.arguments.some(e=>e.type===`ObjectExpression`&&e.properties.some(e=>e.type===`Property`&&[`skip`,`todo`].includes(e.key.type===`Identifier`?e.key.name:e.key.type===`Literal`?String(e.key.value):``)&&(e.value.type!==`Literal`||e.value.value!==!1))))});return n.some(e=>{let n=S(e.callee,t);return![`test`,`it`].includes(n[0])||r.some(t=>e.start>=t.start&&e.end<=t.end)?!1:e.arguments.some(e=>(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`)&&e.body&&(e.body.type!==`BlockStatement`||e.body.body.some(e=>e.type!==`EmptyStatement`)))})}function S(e,t){if(e.type===`Identifier`){let n=t.get(e.name);return n?[n]:[]}if(e.type===`CallExpression`)return S(e.callee,t);if(e.type===`MemberExpression`){let n=S(e.object,t),r=!e.computed&&e.property.type===`Identifier`?e.property.name:e.property.type===`Literal`?String(e.property.value):``;return!n.length||!r?[]:n[0]===`*`?[r]:[...n,r]}return[]}function C(e){let t=[];return new u({ImportDeclaration(e){e.importKind!==`type`&&(e.specifiers.length===0||e.specifiers.some(e=>e.type!==`ImportSpecifier`||e.importKind!==`type`))&&t.push(e.source.value)},ExportNamedDeclaration(e){e.source&&e.exportKind!==`type`&&e.specifiers.some(e=>e.exportKind!==`type`)&&t.push(e.source.value)},ExportAllDeclaration(e){e.exportKind!==`type`&&t.push(e.source.value)},ImportExpression(e){e.source.type===`Literal`&&String(e.source.value)===e.source.value&&t.push(String(e.source.value))}}).visit(e),t}function w(e){let t=e.split(`/`);return t[0]===`domain`&&t.length>=3&&t[1]!==`__tests__`?`domain/${t[1]}`:null}function T(e){let t=/* @__PURE__ */ new Set,n=[],r=[];function i(a){let o=n.indexOf(a);if(o>=0){r.push([...n.slice(o),a]);return}if(!t.has(a)){n.push(a);for(let t of e.get(a)??[])i(t);n.pop(),t.add(a)}}for(let t of e.keys())i(t);return r}function E(e){let t=/* @__PURE__ */ new Map;for(let[n,r]of e){let i=w(n)??``;if(!i||i===`domain/shared`)continue;let a=/* @__PURE__ */ new Set;function o(n){if(!n.startsWith(`domain/shared/`)||a.has(n))return;a.add(n);let r=t.get(n)??/* @__PURE__ */ new Set;r.add(i),t.set(n,r);for(let t of e.get(n)??[])o(t)}for(let e of r)o(e)}let n=[];for(let[e,r]of t)r.size===1&&n.push({code:`shared-owner`,file:e,message:`This shared implementation is used only by ${[...r][0]}. Move it into that module until another module needs it.`});return n}export{g as architectureAnchor,m as createResolver,p as inspectArchitecture,_ as narrowRootDeclaration,h as resolveImport};
|
|
1
|
+
import{conventionalComponentRoot as e,findComponentRoot as t}from"./components.mjs";import{dirname as n,relative as r,resolve as i,sep as a}from"node:path";import{existsSync as o,readFileSync as s,readdirSync as c,realpathSync as l}from"node:fs";import{Visitor as u,parseSync as d}from"oxc-parser";import{ResolverFactory as f}from"oxc-resolver";function p(c={}){let u=i(c.cwd??process.cwd(),c.convexDir??`convex`),f=o(u)?l(u):u,p=[];if(!o(f))return[{code:`missing-root`,file:`.`,message:`Convex directory does not exist: ${f}`}];let g=(c.componentDirs??[]).map(e=>i(f,e)),S=[...v(f,p)],D=/* @__PURE__ */ new Map;for(let n of S){let o=t(i(f,n),g)??e(i(f,n),f);o&&(o===f||o.startsWith(f+a))&&D.set(n,r(f,o).split(a).join(`/`))}let O=new Set(D.values());for(let e=p.length-1;e>=0;e--){let t=p[e];t.code===`root-directory`&&[...O].some(e=>!e||e===t.file||e.startsWith(t.file+`/`))&&!S.some(e=>e.startsWith(t.file+`/`)&&!D.has(e))&&p.splice(e,1)}let k=/* @__PURE__ */ new Set,A=/* @__PURE__ */ new Set,j=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Map,N=/* @__PURE__ */ new Map,P=m();for(let e of S){let t=i(f,e),o=d(t,s(t,`utf8`));if(o.errors.length){p.push({code:`parse`,file:e,message:`Cannot validate ${e}: ${o.errors[0].message}`});continue}if(y(e)){e.includes(`__tests__/`)?n(e).endsWith(`__tests__`)&&x(o.program)&&A.add(n(n(e))):p.push({code:`test-location`,file:e,message:`Place tests in a sibling __tests__/ directory.`});continue}if(e.split(`/`).includes(`__tests__`))continue;let c=D.get(e),l=c===void 0?e:r(i(f,c),t).split(a).join(`/`);c===void 0&&/^domain\/[^/]+$/.test(e)&&e!==`domain/table.ts`&&p.push({code:`domain-entry`,file:e,message:`Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.`}),b(o.program)&&e!==`domain/table.ts`&&!_(l,s(t,`utf8`))&&k.add(n(e));let u=w(e)??``,m=/* @__PURE__ */ new Set;N.set(e,m);for(let n of C(o.program)){let i=h(P,t,n);if(!i)continue;let o=r(f,i).split(a).join(`/`);if(m.add(o),c!==void 0&&D.get(o)===c){let t=M.get(e)??/* @__PURE__ */ new Set;M.set(e,t),t.add(o)}let s=w(o);if(u&&s&&u!==s){let e=j.get(u)??/* @__PURE__ */ new Set;j.set(u,e),e.add(s)}}}for(let e of k)A.has(e)||p.push({code:`tests`,file:e,message:`${e}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`});p.push(...E(N));for(let e of[...T(j),...T(M)])p.push({code:`cycle`,file:e[0],message:`Module dependency cycle: ${e.join(` → `)}.`});return p.sort((e,t)=>e.file.localeCompare(t.file)||e.code.localeCompare(t.code))}function m(e=!0){return new f({tsconfig:`auto`,extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],extensionAlias:{".js":[`.ts`,`.tsx`,`.js`],".mjs":[`.mts`,`.mjs`],".cjs":[`.cts`,`.cjs`]},conditionNames:[`types`,`import`,`node`,`default`],symlinks:e})}function h(e,t,r){return e.resolveFileSync(t,r).path||(r.startsWith(`.`)?i(n(t),r):null)}function g(e){if(!o(e))return null;if(o(i(e,`convex.config.ts`)))return l(i(e,`convex.config.ts`));e=l(e);for(let t of v(e,[]))if(!t.includes(`__tests__/`)&&!y(t))return i(e,t);return null}function _(e,t){let n=e===`relations.ts`?`defineRelations`:e===`querying.ts`?`createQueryEngine`:null;if(!n)return!1;let r=d(e,t);if(r.errors.length)return!1;let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=0,s=!1;function c(e,t=/* @__PURE__ */ new Set){if(e.type===`Identifier`){if(t.has(e.name))return null;let n=a.get(e.name);return n?c(n,new Set(t).add(e.name)):i.get(e.name)??null}return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&c(e.object,t)===`*`?e.property.name:null}function l(e,t,n=!1){if(e.type===`Identifier`||e.type===`Literal`)return!0;if(e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`ParenthesizedExpression`)return l(e.expression,t,n);if(e.type===`MemberExpression`)return!e.computed&&l(e.object,t);if(e.type===`ArrayExpression`)return e.elements.every(e=>e!==null&&l(e,t));if(e.type===`ObjectExpression`)return e.properties.every(e=>e.type===`Property`&&!e.computed&&e.kind===`init`&&!e.method&&l(e.value,t));if(e.type===`ArrowFunctionExpression`&&n&&!t&&e.params.length===1&&e.params[0].type===`Identifier`&&!e.async){let t=e.body.type===`ParenthesizedExpression`?e.body.expression:e.body;return t.type===`ObjectExpression`&&l(t,e.params[0].name)}if(e.type===`CallExpression`&&t){let n=e.callee,r=[];for(;n.type===`MemberExpression`&&!n.computed&&n.property.type===`Identifier`;)r.unshift(n.property.name),n=n.object;return n.type===`Identifier`&&n.name===t&&(r.length===2&&[`one`,`many`].includes(r[0])||r.length===3&&r[2]===`through`)&&e.arguments.every(e=>l(e,t))}return!1}for(let t of r.program.body){if(t.type===`ImportDeclaration`){if(t.importKind===`type`)continue;for(let n of t.specifiers)(n.type!==`ImportSpecifier`||n.importKind!==`type`)&&[`cvx-kit`,`cvx-kit/${e.slice(0,-3)}`].includes(t.source.value)&&i.set(n.local.name,n.type===`ImportSpecifier`?n.imported.type===`Identifier`?n.imported.name:``:n.type===`ImportNamespaceSpecifier`?`*`:``);continue}if(t.type===`EmptyStatement`||t.type===`TSTypeAliasDeclaration`||t.type===`TSInterfaceDeclaration`)continue;let r=t.type===`ExportNamedDeclaration`?t.declaration:t;if(r?.type!==`VariableDeclaration`||r.kind!==`const`)return!1;for(let e of r.declarations){if(e.id.type!==`Identifier`||!e.init)return!1;if(e.init.type===`CallExpression`&&c(e.init.callee)===n){if(!e.init.arguments.every((e,t)=>l(e,void 0,n===`defineRelations`&&t===1)))return!1;o++,s||=t.type===`ExportNamedDeclaration`}else if(t.type===`ExportNamedDeclaration`||!l(e.init))return!1;a.set(e.id.name,e.init)}}return o===1&&s}function*v(e,t){let n=/* @__PURE__ */ new Set([`_generated`,`__tests__`,`api`,`domain`,`application`,`migrations`,`components`]);function*o(s){for(let l of c(s,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let c=i(s,l.name),u=r(e,c).split(a).join(`/`);l.isSymbolicLink()?t.push({code:`symlink`,file:u,message:`Keep application source inside its owning directory; symlinked files and folders are not allowed.`}):l.isDirectory()?(s===e&&!n.has(l.name)&&t.push({code:`root-directory`,file:u,message:`Root folder ${l.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`}),l.name!==`_generated`&&l.name!==`node_modules`&&!l.name.startsWith(`.`)&&(yield*o(c))):/\.[cm]?[jt]sx?$/.test(l.name)&&!/\.d\.[cm]?ts$/.test(l.name)&&(yield u)}}yield*o(e)}function y(e){return/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(e)}function b(e){return e.body.some(e=>{let t=e.type===`ExportNamedDeclaration`?e.declaration:e;return t&&`declare`in t&&t.declare||e.type===`ImportDeclaration`||e.type===`EmptyStatement`?!1:e.type===`ExportNamedDeclaration`?e.exportKind===`type`||!e.declaration?!1:![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`].includes(e.declaration.type):![`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSDeclareFunction`,`ExportAllDeclaration`].includes(e.type)})}function x(e){let t=/* @__PURE__ */ new Map([[`test`,`test`],[`it`,`it`],[`describe`,`describe`],[`suite`,`suite`]]);for(let n of e.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`FunctionDeclaration`&&e.id&&t.delete(e.id.name),e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.delete(n.id.name);if(n.type===`ImportDeclaration`)for(let e of n.specifiers)t.delete(e.local.name),[`vitest`,`vite-plus/test`,`bun:test`,`node:test`,`@jest/globals`].includes(n.source.value)&&(e.type===`ImportNamespaceSpecifier`?t.set(e.local.name,`*`):e.type===`ImportDefaultSpecifier`?t.set(e.local.name,`test`):e.imported.type===`Identifier`&&t.set(e.local.name,e.imported.name))}let n=[];new u({CallExpression(e){n.push(e)}}).visit(e);let r=n.filter(e=>{let n=S(e.callee,t);return[`test`,`it`,`describe`,`suite`].includes(n[0])&&(n.some(e=>[`skip`,`todo`,`skipIf`,`runIf`].includes(e))||e.arguments.some(e=>e.type===`ObjectExpression`&&e.properties.some(e=>e.type===`Property`&&[`skip`,`todo`].includes(e.key.type===`Identifier`?e.key.name:e.key.type===`Literal`?String(e.key.value):``)&&(e.value.type!==`Literal`||e.value.value!==!1))))});return n.some(e=>{let n=S(e.callee,t);return![`test`,`it`].includes(n[0])||r.some(t=>e.start>=t.start&&e.end<=t.end)?!1:e.arguments.some(e=>(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`)&&e.body&&(e.body.type!==`BlockStatement`||e.body.body.some(e=>e.type!==`EmptyStatement`)))})}function S(e,t){if(e.type===`Identifier`){let n=t.get(e.name);return n?[n]:[]}if(e.type===`CallExpression`)return S(e.callee,t);if(e.type===`MemberExpression`){let n=S(e.object,t),r=!e.computed&&e.property.type===`Identifier`?e.property.name:e.property.type===`Literal`?String(e.property.value):``;return!n.length||!r?[]:n[0]===`*`?[r]:[...n,r]}return[]}function C(e){let t=[];return new u({ImportDeclaration(e){e.importKind!==`type`&&(e.specifiers.length===0||e.specifiers.some(e=>e.type!==`ImportSpecifier`||e.importKind!==`type`))&&t.push(e.source.value)},ExportNamedDeclaration(e){e.source&&e.exportKind!==`type`&&e.specifiers.some(e=>e.exportKind!==`type`)&&t.push(e.source.value)},ExportAllDeclaration(e){e.exportKind!==`type`&&t.push(e.source.value)},ImportExpression(e){e.source.type===`Literal`&&String(e.source.value)===e.source.value&&t.push(String(e.source.value))}}).visit(e),t}function w(e){let t=e.split(`/`);return t[0]===`domain`&&t.length>=3&&t[1]!==`__tests__`?`domain/${t[1]}`:null}function T(e){let t=/* @__PURE__ */ new Set,n=[],r=[];function i(a){let o=n.indexOf(a);if(o>=0)r.push([...n.slice(o),a]);else if(!t.has(a)){n.push(a);for(let t of e.get(a)??[])i(t);n.pop(),t.add(a)}}for(let t of e.keys())i(t);return r}function E(e){let t=/* @__PURE__ */ new Map;for(let[n,r]of e){let i=w(n)??``;if(!i||i===`domain/shared`)continue;let a=/* @__PURE__ */ new Set;function o(n){if(!n.startsWith(`domain/shared/`)||a.has(n))return;a.add(n);let r=t.get(n)??/* @__PURE__ */ new Set;r.add(i),t.set(n,r);for(let t of e.get(n)??[])o(t)}for(let e of r)o(e)}let n=[];for(let[e,r]of t)r.size===1&&n.push({code:`shared-owner`,file:e,message:`This shared implementation is used only by ${[...r][0]}. Move it into that module until another module needs it.`});return n}export{g as architectureAnchor,m as createResolver,p as inspectArchitecture,_ as narrowRootDeclaration,h as resolveImport};
|
|
2
2
|
//# sourceMappingURL=architecture.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"architecture.mjs","names":["inspectArchitecture","requestedRoot","resolve","options","root","existsSync","realpathSync","diagnostics","explicitRoots","path","files","sourceFiles","owners","file","owner","findComponentRoot","conventionalComponentRoot","sep","relative","componentRoots","index","issue","required","tested","graph","componentGraph","dependencies","resolver","createResolver","filename","parsed","parseSync","readFileSync","testFile","dirname","hasRunnableTest","component","localFile","executable","narrowRootDeclaration","moduleOwner","targets","source","runtimeImports","target","resolveImport","targetFile","edges","targetOwner","directory","sharedOwnership","cycle","cycles","a","b","ResolverFactory","architectureAnchor","factory","imports","aliases","factories","exported","factoryName","node","active","init","declarative","relationParameter","registryCallback","value","property","body","callee","argument","statement","specifier","declaration","item","allowed","scan","entry","readdirSync","program","names","calls","Visitor","skipped","parts","testCallee","part","skip","name","base","s","completed","stack","found","visit","dependency","consumers","visited","next"],"sources":["../../src/oxlint/architecture.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, relative, resolve, sep } from 'node:path'\nimport { parseSync, Visitor, type Program, type Node, type CallExpression } from 'oxc-parser'\nimport { ResolverFactory } from 'oxc-resolver'\nimport { findComponentRoot, conventionalComponentRoot } from './components'\n\nexport interface ArchitectureOptions {\n\tcwd?: string\n\tconvexDir?: string\n\t/** Additional component roots, relative to convexDir. */\n\tcomponentDirs?: readonly string[]\n\t/** Build these registries to surface deferred configuration errors in tests. */\n\tregistries?: readonly object[]\n}\nexport interface ArchitectureDiagnostic {\n\tcode:\n\t\t| 'missing-root'\n\t\t| 'root-directory'\n\t\t| 'tests'\n\t\t| 'test-location'\n\t\t| 'parse'\n\t\t| 'cycle'\n\t\t| 'symlink'\n\t\t| 'domain-entry'\n\t\t| 'shared-owner'\n\tfile: string\n\tmessage: string\n}\n\n/** Full-project checks, independent of the consumer's test runner. No persistent cache. */\nexport function inspectArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\tconst requestedRoot = resolve(options.cwd ?? process.cwd(), options.convexDir ?? 'convex')\n\tconst root = existsSync(requestedRoot) ? realpathSync(requestedRoot) : requestedRoot\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tif (!existsSync(root))\n\t\treturn [\n\t\t\t{ code: 'missing-root', file: '.', message: `Convex directory does not exist: ${root}` },\n\t\t]\n\tconst explicitRoots = (options.componentDirs ?? []).map((path) => resolve(root, path))\n\tconst files = [...sourceFiles(root, diagnostics)]\n\tconst owners = new Map<string, string>()\n\tfor (const file of files) {\n\t\tconst owner =\n\t\t\tfindComponentRoot(resolve(root, file), explicitRoots) ??\n\t\t\tconventionalComponentRoot(resolve(root, file), root)\n\t\tif (owner && (owner === root || owner.startsWith(root + sep)))\n\t\t\towners.set(file, relative(root, owner).split(sep).join('/'))\n\t}\n\tconst componentRoots = new Set(owners.values())\n\t// Component submodules have their own layout; only host directories use the app allowlist.\n\tfor (let index = diagnostics.length - 1; index >= 0; index--) {\n\t\tconst issue = diagnostics[index]\n\t\tif (\n\t\t\tissue.code === 'root-directory' &&\n\t\t\t[...componentRoots].some(\n\t\t\t\t(owner) => !owner || owner === issue.file || owner.startsWith(issue.file + '/'),\n\t\t\t) &&\n\t\t\t!files.some((file) => file.startsWith(issue.file + '/') && !owners.has(file))\n\t\t)\n\t\t\tdiagnostics.splice(index, 1)\n\t}\n\tconst required = new Set<string>()\n\tconst tested = new Set<string>()\n\tconst graph = new Map<string, Set<string>>()\n\tconst componentGraph = new Map<string, Set<string>>()\n\tconst dependencies = new Map<string, Set<string>>()\n\tconst resolver = createResolver()\n\tfor (const file of files) {\n\t\tconst filename = resolve(root, file)\n\t\tconst parsed = parseSync(filename, readFileSync(filename, 'utf8'))\n\t\tif (parsed.errors.length) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'parse',\n\t\t\t\tfile,\n\t\t\t\tmessage: `Cannot validate ${file}: ${parsed.errors[0].message}`,\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (testFile(file)) {\n\t\t\tif (!file.includes('__tests__/'))\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'test-location',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage: 'Place tests in a sibling __tests__/ directory.',\n\t\t\t\t})\n\t\t\telse if (dirname(file).endsWith('__tests__') && hasRunnableTest(parsed.program))\n\t\t\t\ttested.add(dirname(dirname(file)))\n\t\t\tcontinue\n\t\t}\n\t\tif (file.split('/').includes('__tests__')) continue\n\t\tconst component = owners.get(file)\n\t\tconst localFile =\n\t\t\tcomponent === undefined\n\t\t\t\t? file\n\t\t\t\t: relative(resolve(root, component), filename).split(sep).join('/')\n\t\tif (component === undefined && /^domain\\/[^/]+$/.test(file) && file !== 'domain/table.ts')\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'domain-entry',\n\t\t\t\tfile,\n\t\t\t\tmessage:\n\t\t\t\t\t'Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.',\n\t\t\t})\n\t\tif (\n\t\t\texecutable(parsed.program) &&\n\t\t\tfile !== 'domain/table.ts' &&\n\t\t\t!narrowRootDeclaration(localFile, readFileSync(filename, 'utf8'))\n\t\t)\n\t\t\trequired.add(dirname(file))\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tconst targets = new Set<string>()\n\t\tdependencies.set(file, targets)\n\t\tfor (const source of runtimeImports(parsed.program)) {\n\t\t\tconst target = resolveImport(resolver, filename, source)\n\t\t\tif (!target) continue\n\t\t\tconst targetFile = relative(root, target).split(sep).join('/')\n\t\t\ttargets.add(targetFile)\n\t\t\tif (component !== undefined && owners.get(targetFile) === component) {\n\t\t\t\tconst edges = componentGraph.get(file) ?? new Set<string>()\n\t\t\t\tcomponentGraph.set(file, edges)\n\t\t\t\tedges.add(targetFile)\n\t\t\t}\n\t\t\tconst targetOwner = moduleOwner(targetFile)\n\t\t\tif (owner && targetOwner && owner !== targetOwner) {\n\t\t\t\tconst edges = graph.get(owner) ?? new Set<string>()\n\t\t\t\tgraph.set(owner, edges)\n\t\t\t\tedges.add(targetOwner)\n\t\t\t}\n\t\t}\n\t}\n\tfor (const directory of required) {\n\t\tif (!tested.has(directory))\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'tests',\n\t\t\t\tfile: directory,\n\t\t\t\tmessage: `${directory}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`,\n\t\t\t})\n\t}\n\tdiagnostics.push(...sharedOwnership(dependencies))\n\tfor (const cycle of [...cycles(graph), ...cycles(componentGraph)])\n\t\tdiagnostics.push({\n\t\t\tcode: 'cycle',\n\t\t\tfile: cycle[0],\n\t\t\tmessage: `Module dependency cycle: ${cycle.join(' → ')}.`,\n\t\t})\n\treturn diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.code.localeCompare(b.code))\n}\n\nexport function createResolver(symlinks = true) {\n\treturn new ResolverFactory({\n\t\ttsconfig: 'auto',\n\t\textensions: ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.json'],\n\t\textensionAlias: {\n\t\t\t'.js': ['.ts', '.tsx', '.js'],\n\t\t\t'.mjs': ['.mts', '.mjs'],\n\t\t\t'.cjs': ['.cts', '.cjs'],\n\t\t},\n\t\tconditionNames: ['types', 'import', 'node', 'default'],\n\t\tsymlinks,\n\t})\n}\n\nexport function resolveImport(resolver: ResolverFactory, filename: string, source: string) {\n\tconst found = resolver.resolveFileSync(filename, source).path\n\tif (found) return found\n\t// Keep path checks useful in unsaved/editor fixtures and before Convex codegen.\n\treturn source.startsWith('.') ? resolve(dirname(filename), source) : null\n}\n\n/** The lint rule runs the project scan on one deterministic source file. */\nexport function architectureAnchor(root: string) {\n\tif (!existsSync(root)) return null\n\tif (existsSync(resolve(root, 'convex.config.ts')))\n\t\treturn realpathSync(resolve(root, 'convex.config.ts'))\n\troot = realpathSync(root)\n\tfor (const file of sourceFiles(root, []))\n\t\tif (!file.includes('__tests__/') && !testFile(file)) return resolve(root, file)\n\treturn null\n}\n\n/** Only these two factory declarations may omit root business ownership. */\nexport function narrowRootDeclaration(file: string, source: string): boolean {\n\tconst factory =\n\t\tfile === 'relations.ts'\n\t\t\t? 'defineRelations'\n\t\t\t: file === 'querying.ts'\n\t\t\t\t? 'createQueryEngine'\n\t\t\t\t: null\n\tif (!factory) return false\n\tconst parsed = parseSync(file, source)\n\tif (parsed.errors.length) return false\n\tconst imports = new Map<string, string>()\n\tconst aliases = new Map<string, Node>()\n\tlet factories = 0\n\tlet exported = false\n\tfunction factoryName(node: Node, active = new Set<string>()): string | null {\n\t\tif (node.type === 'Identifier') {\n\t\t\tif (active.has(node.name)) return null\n\t\t\tconst init = aliases.get(node.name)\n\t\t\treturn init\n\t\t\t\t? factoryName(init, new Set(active).add(node.name))\n\t\t\t\t: (imports.get(node.name) ?? null)\n\t\t}\n\t\tif (\n\t\t\tnode.type === 'MemberExpression' &&\n\t\t\t!node.computed &&\n\t\t\tnode.property.type === 'Identifier' &&\n\t\t\tfactoryName(node.object, active) === '*'\n\t\t)\n\t\t\treturn node.property.name\n\t\treturn null\n\t}\n\tfunction declarative(node: Node, relationParameter?: string, registryCallback = false): boolean {\n\t\tif (node.type === 'Identifier' || node.type === 'Literal') return true\n\t\tif (\n\t\t\tnode.type === 'TSAsExpression' ||\n\t\t\tnode.type === 'TSSatisfiesExpression' ||\n\t\t\tnode.type === 'ParenthesizedExpression'\n\t\t)\n\t\t\treturn declarative(node.expression, relationParameter, registryCallback)\n\t\tif (node.type === 'MemberExpression')\n\t\t\treturn !node.computed && declarative(node.object, relationParameter)\n\t\tif (node.type === 'ArrayExpression')\n\t\t\treturn node.elements.every((value) => value !== null && declarative(value, relationParameter))\n\t\tif (node.type === 'ObjectExpression')\n\t\t\treturn node.properties.every(\n\t\t\t\t(property) =>\n\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t!property.computed &&\n\t\t\t\t\tproperty.kind === 'init' &&\n\t\t\t\t\t!property.method &&\n\t\t\t\t\tdeclarative(property.value, relationParameter),\n\t\t\t)\n\t\tif (\n\t\t\tnode.type === 'ArrowFunctionExpression' &&\n\t\t\tregistryCallback &&\n\t\t\t!relationParameter &&\n\t\t\tnode.params.length === 1 &&\n\t\t\tnode.params[0].type === 'Identifier' &&\n\t\t\t!node.async\n\t\t) {\n\t\t\tconst body = node.body.type === 'ParenthesizedExpression' ? node.body.expression : node.body\n\t\t\treturn body.type === 'ObjectExpression' && declarative(body, node.params[0].name)\n\t\t}\n\t\tif (node.type === 'CallExpression' && relationParameter) {\n\t\t\tlet callee: Node = node.callee\n\t\t\tconst path: string[] = []\n\t\t\twhile (\n\t\t\t\tcallee.type === 'MemberExpression' &&\n\t\t\t\t!callee.computed &&\n\t\t\t\tcallee.property.type === 'Identifier'\n\t\t\t) {\n\t\t\t\tpath.unshift(callee.property.name)\n\t\t\t\tcallee = callee.object\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tcallee.type === 'Identifier' &&\n\t\t\t\tcallee.name === relationParameter &&\n\t\t\t\t((path.length === 2 && ['one', 'many'].includes(path[0])) ||\n\t\t\t\t\t(path.length === 3 && path[2] === 'through')) &&\n\t\t\t\tnode.arguments.every((argument) => declarative(argument, relationParameter))\n\t\t\t)\n\t\t}\n\t\treturn false\n\t}\n\tfor (const statement of parsed.program.body) {\n\t\tif (statement.type === 'ImportDeclaration') {\n\t\t\tif (statement.importKind === 'type') continue\n\t\t\tfor (const specifier of statement.specifiers) {\n\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\tif (['cvx-kit', `cvx-kit/${file.slice(0, -3)}`].includes(statement.source.value))\n\t\t\t\t\timports.set(\n\t\t\t\t\t\tspecifier.local.name,\n\t\t\t\t\t\tspecifier.type === 'ImportSpecifier'\n\t\t\t\t\t\t\t? specifier.imported.type === 'Identifier'\n\t\t\t\t\t\t\t\t? specifier.imported.name\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t: specifier.type === 'ImportNamespaceSpecifier'\n\t\t\t\t\t\t\t\t? '*'\n\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (\n\t\t\tstatement.type === 'EmptyStatement' ||\n\t\t\tstatement.type === 'TSTypeAliasDeclaration' ||\n\t\t\tstatement.type === 'TSInterfaceDeclaration'\n\t\t)\n\t\t\tcontinue\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const') return false\n\t\tfor (const item of declaration.declarations) {\n\t\t\tif (item.id.type !== 'Identifier' || !item.init) return false\n\t\t\tif (item.init.type === 'CallExpression' && factoryName(item.init.callee) === factory) {\n\t\t\t\tif (\n\t\t\t\t\t!item.init.arguments.every((argument, index) =>\n\t\t\t\t\t\tdeclarative(argument, undefined, factory === 'defineRelations' && index === 1),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t\tfactories++\n\t\t\t\texported ||= statement.type === 'ExportNamedDeclaration'\n\t\t\t} else if (statement.type === 'ExportNamedDeclaration' || !declarative(item.init))\n\t\t\t\treturn false\n\t\t\taliases.set(item.id.name, item.init)\n\t\t}\n\t}\n\treturn factories === 1 && exported\n}\n\nfunction* sourceFiles(root: string, diagnostics: ArchitectureDiagnostic[]): Generator<string> {\n\tconst allowed = new Set([\n\t\t'_generated',\n\t\t'__tests__',\n\t\t'api',\n\t\t'domain',\n\t\t'application',\n\t\t'migrations',\n\t\t'components',\n\t])\n\tfunction* scan(directory: string): Generator<string> {\n\t\tfor (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>\n\t\t\ta.name.localeCompare(b.name),\n\t\t)) {\n\t\t\tconst path = resolve(directory, entry.name)\n\t\t\tconst file = relative(root, path).split(sep).join('/')\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'symlink',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t'Keep application source inside its owning directory; symlinked files and folders are not allowed.',\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tif (directory === root && !allowed.has(entry.name))\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: 'root-directory',\n\t\t\t\t\t\tfile,\n\t\t\t\t\t\tmessage: `Root folder ${entry.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`,\n\t\t\t\t\t})\n\t\t\t\tif (\n\t\t\t\t\tentry.name !== '_generated' &&\n\t\t\t\t\tentry.name !== 'node_modules' &&\n\t\t\t\t\t!entry.name.startsWith('.')\n\t\t\t\t)\n\t\t\t\t\tyield* scan(path)\n\t\t\t} else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !/\\.d\\.[cm]?ts$/.test(entry.name)) yield file\n\t\t}\n\t}\n\tyield* scan(root)\n}\n\nfunction testFile(file: string) {\n\treturn /\\.(?:test|spec)\\.[cm]?[jt]sx?$/.test(file)\n}\n\nfunction executable(program: Program) {\n\treturn program.body.some((statement) => {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration && 'declare' in declaration && declaration.declare) return false\n\t\tif (statement.type === 'ImportDeclaration' || statement.type === 'EmptyStatement') return false\n\t\tif (statement.type === 'ExportNamedDeclaration') {\n\t\t\tif (statement.exportKind === 'type' || !statement.declaration) return false\n\t\t\treturn !['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSDeclareFunction'].includes(\n\t\t\t\tstatement.declaration.type,\n\t\t\t)\n\t\t}\n\t\treturn ![\n\t\t\t'TSInterfaceDeclaration',\n\t\t\t'TSTypeAliasDeclaration',\n\t\t\t'TSDeclareFunction',\n\t\t\t'ExportAllDeclaration',\n\t\t].includes(statement.type)\n\t})\n}\n\nfunction hasRunnableTest(program: Program) {\n\tconst names = new Map([\n\t\t['test', 'test'],\n\t\t['it', 'it'],\n\t\t['describe', 'describe'],\n\t\t['suite', 'suite'],\n\t])\n\tfor (const statement of program.body) {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type === 'FunctionDeclaration' && declaration.id)\n\t\t\tnames.delete(declaration.id.name)\n\t\tif (declaration?.type === 'VariableDeclaration')\n\t\t\tfor (const item of declaration.declarations) {\n\t\t\t\tif (item.id.type === 'Identifier') names.delete(item.id.name)\n\t\t\t}\n\t\tif (statement.type !== 'ImportDeclaration') continue\n\t\tfor (const specifier of statement.specifiers) {\n\t\t\tnames.delete(specifier.local.name)\n\t\t\tif (\n\t\t\t\t!['vitest', 'vite-plus/test', 'bun:test', 'node:test', '@jest/globals'].includes(\n\t\t\t\t\tstatement.source.value,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (specifier.type === 'ImportNamespaceSpecifier') names.set(specifier.local.name, '*')\n\t\t\telse if (specifier.type === 'ImportDefaultSpecifier') names.set(specifier.local.name, 'test')\n\t\t\telse if (specifier.imported.type === 'Identifier')\n\t\t\t\tnames.set(specifier.local.name, specifier.imported.name)\n\t\t}\n\t}\n\tconst calls: CallExpression[] = []\n\tnew Visitor({\n\t\tCallExpression(node) {\n\t\t\tcalls.push(node)\n\t\t},\n\t}).visit(program)\n\tconst skipped = calls.filter((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\treturn (\n\t\t\t['test', 'it', 'describe', 'suite'].includes(parts[0]) &&\n\t\t\t(parts.some((part) => ['skip', 'todo', 'skipIf', 'runIf'].includes(part)) ||\n\t\t\t\tnode.arguments.some(\n\t\t\t\t\t(argument) =>\n\t\t\t\t\t\targument.type === 'ObjectExpression' &&\n\t\t\t\t\t\targument.properties.some(\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t['skip', 'todo'].includes(\n\t\t\t\t\t\t\t\t\tproperty.key.type === 'Identifier'\n\t\t\t\t\t\t\t\t\t\t? property.key.name\n\t\t\t\t\t\t\t\t\t\t: property.key.type === 'Literal'\n\t\t\t\t\t\t\t\t\t\t\t? String(property.key.value)\n\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t!(property.value.type === 'Literal' && property.value.value === false),\n\t\t\t\t\t\t),\n\t\t\t\t))\n\t\t)\n\t})\n\treturn calls.some((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\tif (\n\t\t\t!['test', 'it'].includes(parts[0]) ||\n\t\t\tskipped.some((skip) => node.start >= skip.start && node.end <= skip.end)\n\t\t)\n\t\t\treturn false\n\t\t// each(...) is a factory; only the outer call has the test callback.\n\t\treturn node.arguments.some(\n\t\t\t(argument) =>\n\t\t\t\t(argument.type === 'ArrowFunctionExpression' || argument.type === 'FunctionExpression') &&\n\t\t\t\targument.body &&\n\t\t\t\t(argument.body.type !== 'BlockStatement' ||\n\t\t\t\t\targument.body.body.some((statement) => statement.type !== 'EmptyStatement')),\n\t\t)\n\t})\n}\n\nfunction testCallee(node: Node, names: Map<string, string>): string[] {\n\tif (node.type === 'Identifier') {\n\t\tconst name = names.get(node.name)\n\t\treturn name ? [name] : []\n\t}\n\tif (node.type === 'CallExpression') return testCallee(node.callee, names)\n\tif (node.type === 'MemberExpression') {\n\t\tconst base = testCallee(node.object, names)\n\t\tconst property =\n\t\t\t!node.computed && node.property.type === 'Identifier'\n\t\t\t\t? node.property.name\n\t\t\t\t: node.property.type === 'Literal'\n\t\t\t\t\t? String(node.property.value)\n\t\t\t\t\t: ''\n\t\tif (!base.length || !property) return []\n\t\treturn base[0] === '*' ? [property] : [...base, property]\n\t}\n\treturn []\n}\n\nfunction runtimeImports(program: Program) {\n\tconst imports: string[] = []\n\tnew Visitor({\n\t\tImportDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.importKind !== 'type' &&\n\t\t\t\t(node.specifiers.length === 0 ||\n\t\t\t\t\tnode.specifiers.some((s) => s.type !== 'ImportSpecifier' || s.importKind !== 'type'))\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportNamedDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.source &&\n\t\t\t\tnode.exportKind !== 'type' &&\n\t\t\t\tnode.specifiers.some((specifier) => specifier.exportKind !== 'type')\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportAllDeclaration(node) {\n\t\t\tif (node.exportKind !== 'type') imports.push(node.source.value)\n\t\t},\n\t\tImportExpression(node) {\n\t\t\tif (node.source.type === 'Literal' && String(node.source.value) === node.source.value)\n\t\t\t\timports.push(String(node.source.value))\n\t\t},\n\t}).visit(program)\n\treturn imports\n}\n\nfunction moduleOwner(file: string) {\n\tconst parts = file.split('/')\n\treturn parts[0] === 'domain' && parts.length >= 3 && parts[1] !== '__tests__'\n\t\t? `domain/${parts[1]}`\n\t\t: null\n}\n\nfunction cycles(graph: Map<string, Set<string>>) {\n\tconst completed = new Set<string>()\n\tconst stack: string[] = []\n\tconst found: string[][] = []\n\tfunction visit(owner: string) {\n\t\tconst index = stack.indexOf(owner)\n\t\tif (index >= 0) {\n\t\t\tfound.push([...stack.slice(index), owner])\n\t\t\treturn\n\t\t}\n\t\tif (completed.has(owner)) return\n\t\tstack.push(owner)\n\t\tfor (const dependency of graph.get(owner) ?? []) visit(dependency)\n\t\tstack.pop()\n\t\tcompleted.add(owner)\n\t}\n\tfor (const owner of graph.keys()) visit(owner)\n\treturn found\n}\n\nfunction sharedOwnership(dependencies: Map<string, Set<string>>): ArchitectureDiagnostic[] {\n\tconst consumers = new Map<string, Set<string>>()\n\tfor (const [file, targets] of dependencies) {\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tif (!owner || owner === 'domain/shared') continue\n\t\tconst visited = new Set<string>()\n\t\tfunction visit(target: string) {\n\t\t\tif (!target.startsWith('domain/shared/') || visited.has(target)) return\n\t\t\tvisited.add(target)\n\t\t\tconst owners = consumers.get(target) ?? new Set<string>()\n\t\t\towners.add(owner)\n\t\t\tconsumers.set(target, owners)\n\t\t\tfor (const next of dependencies.get(target) ?? []) visit(next)\n\t\t}\n\t\tfor (const target of targets) visit(target)\n\t}\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tfor (const [file, owners] of consumers) {\n\t\tif (owners.size === 1)\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'shared-owner',\n\t\t\t\tfile,\n\t\t\t\tmessage: `This shared implementation is used only by ${[...owners][0]}. Move it into that module until another module needs it.`,\n\t\t\t})\n\t}\n\treturn diagnostics\n}\n"],"mappings":"yVA8BA,SAAgBA,EAAoB,EAA+B,CAAC,EAA6B,CAChG,IAAMC,EAAgBC,EAAQC,EAAQ,KAAO,QAAQ,IAAI,EAAGA,EAAQ,WAAa,QAAQ,EACnFC,EAAOC,EAAWJ,CAAa,EAAIK,EAAaL,CAAa,EAAIA,EACjEM,EAAwC,CAAC,EAC/C,GAAI,CAACF,EAAWD,CAAI,EACnB,MAAO,CACN,CAAE,KAAM,eAAgB,KAAM,IAAK,QAAS,oCAAoCA,GAAO,CACxF,EACD,IAAMI,GAAiBL,EAAQ,eAAiB,CAAC,EAAA,CAAG,IAAK,GAASD,EAAQE,EAAMK,CAAI,CAAC,EAC/EC,EAAQ,CAAC,GAAGC,EAAYP,EAAMG,CAAW,CAAC,EAC1CK,kBAAS,IAAI,IACnB,IAAK,IAAMC,KAAQH,EAAO,CACzB,IAAMI,EACLC,EAAkB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,CAAK,EAAGN,CAAK,CAAC,EACzC,MACD,CACA,GAAI,GAAU,IAAIA,CAAK,EACvB,GAAM,KAAKA,CAAK,EAChB,IAAK,IAAMoF,KAAc1E,EAAM,IAAIV,CAAK,GAAK,CAAC,EAAGmF,EAAMC,CAAU,EACjEH,EAAM,IAAI,EACVD,EAAU,IAAIhF,CAAK,CAHH,CAIjB,CACA,IAAK,IAAMA,KAASU,EAAM,KAAK,EAAGyE,EAAMnF,CAAK,EAC7C,OAAOkF,CACR,CAEA,SAAS9C,EAAgB,EAAkE,CAC1F,IAAMiD,kBAAY,IAAI,IACtB,IAAK,GAAM,CAACtF,EAAM4B,KAAYf,EAAc,CAC3C,IAAMZ,EAAQ0B,EAAY3B,CAAI,GAAK,GACnC,GAAI,CAACC,GAASA,IAAU,gBAAiB,SACzC,IAAMsF,kBAAU,IAAI,IACpB,SAASH,EAAM,EAAgB,CAC9B,GAAI,CAACrD,EAAO,WAAW,gBAAgB,GAAKwD,EAAQ,IAAIxD,CAAM,EAAG,OACjEwD,EAAQ,IAAIxD,CAAM,EAClB,IAAMhC,EAASuF,EAAU,IAAIvD,CAAM,mBAAK,IAAI,IAC5ChC,EAAO,IAAIE,CAAK,EAChBqF,EAAU,IAAIvD,EAAQhC,CAAM,EAC5B,IAAK,IAAMyF,KAAQ3E,EAAa,IAAIkB,CAAM,GAAK,CAAC,EAAGqD,EAAMI,CAAI,CAC9D,CACA,IAAK,IAAMzD,KAAUH,EAASwD,EAAMrD,CAAM,CAC3C,CACA,IAAMrC,EAAwC,CAAC,EAC/C,IAAK,GAAM,CAACM,EAAMD,KAAWuF,EACxBvF,EAAO,OAAS,GACnBL,EAAY,KAAK,CAChB,KAAM,eACN,OACA,QAAS,8CAA8C,CAAC,GAAGK,CAAM,CAAC,CAAC,GAAG,0DACvE,CAAC,EAEH,OAAOL,CACR"}
|
|
1
|
+
{"version":3,"file":"architecture.mjs","names":["inspectArchitecture","requestedRoot","resolve","options","root","existsSync","realpathSync","diagnostics","explicitRoots","path","files","sourceFiles","owners","file","owner","findComponentRoot","conventionalComponentRoot","sep","relative","componentRoots","index","issue","required","tested","graph","componentGraph","dependencies","resolver","createResolver","filename","parsed","parseSync","readFileSync","testFile","dirname","hasRunnableTest","component","localFile","executable","narrowRootDeclaration","moduleOwner","targets","source","runtimeImports","target","resolveImport","targetFile","edges","targetOwner","directory","sharedOwnership","cycle","cycles","a","b","ResolverFactory","architectureAnchor","factory","imports","aliases","factories","exported","factoryName","node","active","init","declarative","relationParameter","registryCallback","value","property","body","callee","argument","statement","specifier","declaration","item","allowed","scan","entry","readdirSync","program","names","calls","Visitor","skipped","parts","testCallee","part","skip","name","base","s","completed","stack","found","visit","dependency","consumers","visited","next"],"sources":["../../src/oxlint/architecture.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, relative, resolve, sep } from 'node:path'\nimport { parseSync, Visitor, type Program, type Node, type CallExpression } from 'oxc-parser'\nimport { ResolverFactory } from 'oxc-resolver'\nimport { findComponentRoot, conventionalComponentRoot } from './components'\n\nexport interface ArchitectureOptions {\n\tcwd?: string\n\tconvexDir?: string\n\t/** Additional component roots, relative to convexDir. */\n\tcomponentDirs?: readonly string[]\n\t/** Build these registries to surface deferred configuration errors in tests. */\n\tregistries?: readonly object[]\n}\nexport interface ArchitectureDiagnostic {\n\tcode:\n\t\t| 'missing-root'\n\t\t| 'root-directory'\n\t\t| 'tests'\n\t\t| 'test-location'\n\t\t| 'parse'\n\t\t| 'cycle'\n\t\t| 'symlink'\n\t\t| 'domain-entry'\n\t\t| 'shared-owner'\n\tfile: string\n\tmessage: string\n}\n\n/** Full-project checks, independent of the consumer's test runner. No persistent cache. */\nexport function inspectArchitecture(options: ArchitectureOptions = {}): ArchitectureDiagnostic[] {\n\tconst requestedRoot = resolve(options.cwd ?? process.cwd(), options.convexDir ?? 'convex')\n\tconst root = existsSync(requestedRoot) ? realpathSync(requestedRoot) : requestedRoot\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tif (!existsSync(root))\n\t\treturn [\n\t\t\t{ code: 'missing-root', file: '.', message: `Convex directory does not exist: ${root}` },\n\t\t]\n\tconst explicitRoots = (options.componentDirs ?? []).map((path) => resolve(root, path))\n\tconst files = [...sourceFiles(root, diagnostics)]\n\tconst owners = new Map<string, string>()\n\tfor (const file of files) {\n\t\tconst owner =\n\t\t\tfindComponentRoot(resolve(root, file), explicitRoots) ??\n\t\t\tconventionalComponentRoot(resolve(root, file), root)\n\t\tif (owner && (owner === root || owner.startsWith(root + sep)))\n\t\t\towners.set(file, relative(root, owner).split(sep).join('/'))\n\t}\n\tconst componentRoots = new Set(owners.values())\n\t// Component submodules have their own layout; only host directories use the app allowlist.\n\tfor (let index = diagnostics.length - 1; index >= 0; index--) {\n\t\tconst issue = diagnostics[index]\n\t\tif (\n\t\t\tissue.code === 'root-directory' &&\n\t\t\t[...componentRoots].some(\n\t\t\t\t(owner) => !owner || owner === issue.file || owner.startsWith(issue.file + '/'),\n\t\t\t) &&\n\t\t\t!files.some((file) => file.startsWith(issue.file + '/') && !owners.has(file))\n\t\t)\n\t\t\tdiagnostics.splice(index, 1)\n\t}\n\tconst required = new Set<string>()\n\tconst tested = new Set<string>()\n\tconst graph = new Map<string, Set<string>>()\n\tconst componentGraph = new Map<string, Set<string>>()\n\tconst dependencies = new Map<string, Set<string>>()\n\tconst resolver = createResolver()\n\tfor (const file of files) {\n\t\tconst filename = resolve(root, file)\n\t\tconst parsed = parseSync(filename, readFileSync(filename, 'utf8'))\n\t\tif (parsed.errors.length) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'parse',\n\t\t\t\tfile,\n\t\t\t\tmessage: `Cannot validate ${file}: ${parsed.errors[0].message}`,\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (testFile(file)) {\n\t\t\tif (!file.includes('__tests__/'))\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'test-location',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage: 'Place tests in a sibling __tests__/ directory.',\n\t\t\t\t})\n\t\t\telse if (dirname(file).endsWith('__tests__') && hasRunnableTest(parsed.program))\n\t\t\t\ttested.add(dirname(dirname(file)))\n\t\t\tcontinue\n\t\t}\n\t\tif (file.split('/').includes('__tests__')) continue\n\t\tconst component = owners.get(file)\n\t\tconst localFile =\n\t\t\tcomponent === undefined\n\t\t\t\t? file\n\t\t\t\t: relative(resolve(root, component), filename).split(sep).join('/')\n\t\tif (component === undefined && /^domain\\/[^/]+$/.test(file) && file !== 'domain/table.ts')\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'domain-entry',\n\t\t\t\tfile,\n\t\t\t\tmessage:\n\t\t\t\t\t'Domain source belongs in domain/<module>/ or domain/shared/. Only domain/table.ts assembles module tables.',\n\t\t\t})\n\t\tif (\n\t\t\texecutable(parsed.program) &&\n\t\t\tfile !== 'domain/table.ts' &&\n\t\t\t!narrowRootDeclaration(localFile, readFileSync(filename, 'utf8'))\n\t\t)\n\t\t\trequired.add(dirname(file))\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tconst targets = new Set<string>()\n\t\tdependencies.set(file, targets)\n\t\tfor (const source of runtimeImports(parsed.program)) {\n\t\t\tconst target = resolveImport(resolver, filename, source)\n\t\t\tif (!target) continue\n\t\t\tconst targetFile = relative(root, target).split(sep).join('/')\n\t\t\ttargets.add(targetFile)\n\t\t\tif (component !== undefined && owners.get(targetFile) === component) {\n\t\t\t\tconst edges = componentGraph.get(file) ?? new Set<string>()\n\t\t\t\tcomponentGraph.set(file, edges)\n\t\t\t\tedges.add(targetFile)\n\t\t\t}\n\t\t\tconst targetOwner = moduleOwner(targetFile)\n\t\t\tif (owner && targetOwner && owner !== targetOwner) {\n\t\t\t\tconst edges = graph.get(owner) ?? new Set<string>()\n\t\t\t\tgraph.set(owner, edges)\n\t\t\t\tedges.add(targetOwner)\n\t\t\t}\n\t\t}\n\t}\n\tfor (const directory of required) {\n\t\tif (!tested.has(directory))\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'tests',\n\t\t\t\tfile: directory,\n\t\t\t\tmessage: `${directory}/__tests__/ must contain a .test or .spec file with a nonempty, non-skipped test. Parent or child suites do not count.`,\n\t\t\t})\n\t}\n\tdiagnostics.push(...sharedOwnership(dependencies))\n\tfor (const cycle of [...cycles(graph), ...cycles(componentGraph)])\n\t\tdiagnostics.push({\n\t\t\tcode: 'cycle',\n\t\t\tfile: cycle[0],\n\t\t\tmessage: `Module dependency cycle: ${cycle.join(' → ')}.`,\n\t\t})\n\treturn diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.code.localeCompare(b.code))\n}\n\nexport function createResolver(symlinks = true) {\n\treturn new ResolverFactory({\n\t\ttsconfig: 'auto',\n\t\textensions: ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.json'],\n\t\textensionAlias: {\n\t\t\t'.js': ['.ts', '.tsx', '.js'],\n\t\t\t'.mjs': ['.mts', '.mjs'],\n\t\t\t'.cjs': ['.cts', '.cjs'],\n\t\t},\n\t\tconditionNames: ['types', 'import', 'node', 'default'],\n\t\tsymlinks,\n\t})\n}\n\nexport function resolveImport(resolver: ResolverFactory, filename: string, source: string) {\n\tconst found = resolver.resolveFileSync(filename, source).path\n\tif (found) return found\n\t// Keep path checks useful in unsaved/editor fixtures and before Convex codegen.\n\treturn source.startsWith('.') ? resolve(dirname(filename), source) : null\n}\n\n/** The lint rule runs the project scan on one deterministic source file. */\nexport function architectureAnchor(root: string) {\n\tif (!existsSync(root)) return null\n\tif (existsSync(resolve(root, 'convex.config.ts')))\n\t\treturn realpathSync(resolve(root, 'convex.config.ts'))\n\troot = realpathSync(root)\n\tfor (const file of sourceFiles(root, []))\n\t\tif (!file.includes('__tests__/') && !testFile(file)) return resolve(root, file)\n\treturn null\n}\n\n/** Only these two factory declarations may omit root business ownership. */\nexport function narrowRootDeclaration(file: string, source: string): boolean {\n\tconst factory =\n\t\tfile === 'relations.ts'\n\t\t\t? 'defineRelations'\n\t\t\t: file === 'querying.ts'\n\t\t\t\t? 'createQueryEngine'\n\t\t\t\t: null\n\tif (!factory) return false\n\tconst parsed = parseSync(file, source)\n\tif (parsed.errors.length) return false\n\tconst imports = new Map<string, string>()\n\tconst aliases = new Map<string, Node>()\n\tlet factories = 0\n\tlet exported = false\n\tfunction factoryName(node: Node, active = new Set<string>()): string | null {\n\t\tif (node.type === 'Identifier') {\n\t\t\tif (active.has(node.name)) return null\n\t\t\tconst init = aliases.get(node.name)\n\t\t\treturn init\n\t\t\t\t? factoryName(init, new Set(active).add(node.name))\n\t\t\t\t: (imports.get(node.name) ?? null)\n\t\t}\n\t\tif (\n\t\t\tnode.type === 'MemberExpression' &&\n\t\t\t!node.computed &&\n\t\t\tnode.property.type === 'Identifier' &&\n\t\t\tfactoryName(node.object, active) === '*'\n\t\t)\n\t\t\treturn node.property.name\n\t\treturn null\n\t}\n\tfunction declarative(node: Node, relationParameter?: string, registryCallback = false): boolean {\n\t\tif (node.type === 'Identifier' || node.type === 'Literal') return true\n\t\tif (\n\t\t\tnode.type === 'TSAsExpression' ||\n\t\t\tnode.type === 'TSSatisfiesExpression' ||\n\t\t\tnode.type === 'ParenthesizedExpression'\n\t\t)\n\t\t\treturn declarative(node.expression, relationParameter, registryCallback)\n\t\tif (node.type === 'MemberExpression')\n\t\t\treturn !node.computed && declarative(node.object, relationParameter)\n\t\tif (node.type === 'ArrayExpression')\n\t\t\treturn node.elements.every((value) => value !== null && declarative(value, relationParameter))\n\t\tif (node.type === 'ObjectExpression')\n\t\t\treturn node.properties.every(\n\t\t\t\t(property) =>\n\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t!property.computed &&\n\t\t\t\t\tproperty.kind === 'init' &&\n\t\t\t\t\t!property.method &&\n\t\t\t\t\tdeclarative(property.value, relationParameter),\n\t\t\t)\n\t\tif (\n\t\t\tnode.type === 'ArrowFunctionExpression' &&\n\t\t\tregistryCallback &&\n\t\t\t!relationParameter &&\n\t\t\tnode.params.length === 1 &&\n\t\t\tnode.params[0].type === 'Identifier' &&\n\t\t\t!node.async\n\t\t) {\n\t\t\tconst body = node.body.type === 'ParenthesizedExpression' ? node.body.expression : node.body\n\t\t\treturn body.type === 'ObjectExpression' && declarative(body, node.params[0].name)\n\t\t}\n\t\tif (node.type === 'CallExpression' && relationParameter) {\n\t\t\tlet callee: Node = node.callee\n\t\t\tconst path: string[] = []\n\t\t\twhile (\n\t\t\t\tcallee.type === 'MemberExpression' &&\n\t\t\t\t!callee.computed &&\n\t\t\t\tcallee.property.type === 'Identifier'\n\t\t\t) {\n\t\t\t\tpath.unshift(callee.property.name)\n\t\t\t\tcallee = callee.object\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tcallee.type === 'Identifier' &&\n\t\t\t\tcallee.name === relationParameter &&\n\t\t\t\t((path.length === 2 && ['one', 'many'].includes(path[0])) ||\n\t\t\t\t\t(path.length === 3 && path[2] === 'through')) &&\n\t\t\t\tnode.arguments.every((argument) => declarative(argument, relationParameter))\n\t\t\t)\n\t\t}\n\t\treturn false\n\t}\n\tfor (const statement of parsed.program.body) {\n\t\tif (statement.type === 'ImportDeclaration') {\n\t\t\tif (statement.importKind === 'type') continue\n\t\t\tfor (const specifier of statement.specifiers) {\n\t\t\t\tif (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') continue\n\t\t\t\tif (['cvx-kit', `cvx-kit/${file.slice(0, -3)}`].includes(statement.source.value))\n\t\t\t\t\timports.set(\n\t\t\t\t\t\tspecifier.local.name,\n\t\t\t\t\t\tspecifier.type === 'ImportSpecifier'\n\t\t\t\t\t\t\t? specifier.imported.type === 'Identifier'\n\t\t\t\t\t\t\t\t? specifier.imported.name\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t: specifier.type === 'ImportNamespaceSpecifier'\n\t\t\t\t\t\t\t\t? '*'\n\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (\n\t\t\tstatement.type === 'EmptyStatement' ||\n\t\t\tstatement.type === 'TSTypeAliasDeclaration' ||\n\t\t\tstatement.type === 'TSInterfaceDeclaration'\n\t\t)\n\t\t\tcontinue\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const') return false\n\t\tfor (const item of declaration.declarations) {\n\t\t\tif (item.id.type !== 'Identifier' || !item.init) return false\n\t\t\tif (item.init.type === 'CallExpression' && factoryName(item.init.callee) === factory) {\n\t\t\t\tif (\n\t\t\t\t\t!item.init.arguments.every((argument, index) =>\n\t\t\t\t\t\tdeclarative(argument, undefined, factory === 'defineRelations' && index === 1),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t\tfactories++\n\t\t\t\texported ||= statement.type === 'ExportNamedDeclaration'\n\t\t\t} else if (statement.type === 'ExportNamedDeclaration' || !declarative(item.init))\n\t\t\t\treturn false\n\t\t\taliases.set(item.id.name, item.init)\n\t\t}\n\t}\n\treturn factories === 1 && exported\n}\n\nfunction* sourceFiles(root: string, diagnostics: ArchitectureDiagnostic[]): Generator<string> {\n\tconst allowed = new Set([\n\t\t'_generated',\n\t\t'__tests__',\n\t\t'api',\n\t\t'domain',\n\t\t'application',\n\t\t'migrations',\n\t\t'components',\n\t])\n\tfunction* scan(directory: string): Generator<string> {\n\t\tfor (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>\n\t\t\ta.name.localeCompare(b.name),\n\t\t)) {\n\t\t\tconst path = resolve(directory, entry.name)\n\t\t\tconst file = relative(root, path).split(sep).join('/')\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: 'symlink',\n\t\t\t\t\tfile,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t'Keep application source inside its owning directory; symlinked files and folders are not allowed.',\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tif (directory === root && !allowed.has(entry.name))\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: 'root-directory',\n\t\t\t\t\t\tfile,\n\t\t\t\t\t\tmessage: `Root folder ${entry.name}/ is not allowed. Use api/, domain/, application/, migrations/, components/, __tests__/, or _generated/.`,\n\t\t\t\t\t})\n\t\t\t\tif (\n\t\t\t\t\tentry.name !== '_generated' &&\n\t\t\t\t\tentry.name !== 'node_modules' &&\n\t\t\t\t\t!entry.name.startsWith('.')\n\t\t\t\t)\n\t\t\t\t\tyield* scan(path)\n\t\t\t} else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !/\\.d\\.[cm]?ts$/.test(entry.name)) yield file\n\t\t}\n\t}\n\tyield* scan(root)\n}\n\nfunction testFile(file: string) {\n\treturn /\\.(?:test|spec)\\.[cm]?[jt]sx?$/.test(file)\n}\n\nfunction executable(program: Program) {\n\treturn program.body.some((statement) => {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration && 'declare' in declaration && declaration.declare) return false\n\t\tif (statement.type === 'ImportDeclaration' || statement.type === 'EmptyStatement') return false\n\t\tif (statement.type === 'ExportNamedDeclaration') {\n\t\t\tif (statement.exportKind === 'type' || !statement.declaration) return false\n\t\t\treturn !['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSDeclareFunction'].includes(\n\t\t\t\tstatement.declaration.type,\n\t\t\t)\n\t\t}\n\t\treturn ![\n\t\t\t'TSInterfaceDeclaration',\n\t\t\t'TSTypeAliasDeclaration',\n\t\t\t'TSDeclareFunction',\n\t\t\t'ExportAllDeclaration',\n\t\t].includes(statement.type)\n\t})\n}\n\nfunction hasRunnableTest(program: Program) {\n\tconst names = new Map([\n\t\t['test', 'test'],\n\t\t['it', 'it'],\n\t\t['describe', 'describe'],\n\t\t['suite', 'suite'],\n\t])\n\tfor (const statement of program.body) {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tif (declaration?.type === 'FunctionDeclaration' && declaration.id)\n\t\t\tnames.delete(declaration.id.name)\n\t\tif (declaration?.type === 'VariableDeclaration')\n\t\t\tfor (const item of declaration.declarations) {\n\t\t\t\tif (item.id.type === 'Identifier') names.delete(item.id.name)\n\t\t\t}\n\t\tif (statement.type !== 'ImportDeclaration') continue\n\t\tfor (const specifier of statement.specifiers) {\n\t\t\tnames.delete(specifier.local.name)\n\t\t\tif (\n\t\t\t\t!['vitest', 'vite-plus/test', 'bun:test', 'node:test', '@jest/globals'].includes(\n\t\t\t\t\tstatement.source.value,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (specifier.type === 'ImportNamespaceSpecifier') names.set(specifier.local.name, '*')\n\t\t\telse if (specifier.type === 'ImportDefaultSpecifier') names.set(specifier.local.name, 'test')\n\t\t\telse if (specifier.imported.type === 'Identifier')\n\t\t\t\tnames.set(specifier.local.name, specifier.imported.name)\n\t\t}\n\t}\n\tconst calls: CallExpression[] = []\n\tnew Visitor({\n\t\tCallExpression(node) {\n\t\t\tcalls.push(node)\n\t\t},\n\t}).visit(program)\n\tconst skipped = calls.filter((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\treturn (\n\t\t\t['test', 'it', 'describe', 'suite'].includes(parts[0]) &&\n\t\t\t(parts.some((part) => ['skip', 'todo', 'skipIf', 'runIf'].includes(part)) ||\n\t\t\t\tnode.arguments.some(\n\t\t\t\t\t(argument) =>\n\t\t\t\t\t\targument.type === 'ObjectExpression' &&\n\t\t\t\t\t\targument.properties.some(\n\t\t\t\t\t\t\t(property) =>\n\t\t\t\t\t\t\t\tproperty.type === 'Property' &&\n\t\t\t\t\t\t\t\t['skip', 'todo'].includes(\n\t\t\t\t\t\t\t\t\tproperty.key.type === 'Identifier'\n\t\t\t\t\t\t\t\t\t\t? property.key.name\n\t\t\t\t\t\t\t\t\t\t: property.key.type === 'Literal'\n\t\t\t\t\t\t\t\t\t\t\t? String(property.key.value)\n\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t!(property.value.type === 'Literal' && property.value.value === false),\n\t\t\t\t\t\t),\n\t\t\t\t))\n\t\t)\n\t})\n\treturn calls.some((node) => {\n\t\tconst parts = testCallee(node.callee, names)\n\t\tif (\n\t\t\t!['test', 'it'].includes(parts[0]) ||\n\t\t\tskipped.some((skip) => node.start >= skip.start && node.end <= skip.end)\n\t\t)\n\t\t\treturn false\n\t\t// each(...) is a factory; only the outer call has the test callback.\n\t\treturn node.arguments.some(\n\t\t\t(argument) =>\n\t\t\t\t(argument.type === 'ArrowFunctionExpression' || argument.type === 'FunctionExpression') &&\n\t\t\t\targument.body &&\n\t\t\t\t(argument.body.type !== 'BlockStatement' ||\n\t\t\t\t\targument.body.body.some((statement) => statement.type !== 'EmptyStatement')),\n\t\t)\n\t})\n}\n\nfunction testCallee(node: Node, names: Map<string, string>): string[] {\n\tif (node.type === 'Identifier') {\n\t\tconst name = names.get(node.name)\n\t\treturn name ? [name] : []\n\t}\n\tif (node.type === 'CallExpression') return testCallee(node.callee, names)\n\tif (node.type === 'MemberExpression') {\n\t\tconst base = testCallee(node.object, names)\n\t\tconst property =\n\t\t\t!node.computed && node.property.type === 'Identifier'\n\t\t\t\t? node.property.name\n\t\t\t\t: node.property.type === 'Literal'\n\t\t\t\t\t? String(node.property.value)\n\t\t\t\t\t: ''\n\t\tif (!base.length || !property) return []\n\t\treturn base[0] === '*' ? [property] : [...base, property]\n\t}\n\treturn []\n}\n\nfunction runtimeImports(program: Program) {\n\tconst imports: string[] = []\n\tnew Visitor({\n\t\tImportDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.importKind !== 'type' &&\n\t\t\t\t(node.specifiers.length === 0 ||\n\t\t\t\t\tnode.specifiers.some((s) => s.type !== 'ImportSpecifier' || s.importKind !== 'type'))\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportNamedDeclaration(node) {\n\t\t\tif (\n\t\t\t\tnode.source &&\n\t\t\t\tnode.exportKind !== 'type' &&\n\t\t\t\tnode.specifiers.some((specifier) => specifier.exportKind !== 'type')\n\t\t\t)\n\t\t\t\timports.push(node.source.value)\n\t\t},\n\t\tExportAllDeclaration(node) {\n\t\t\tif (node.exportKind !== 'type') imports.push(node.source.value)\n\t\t},\n\t\tImportExpression(node) {\n\t\t\tif (node.source.type === 'Literal' && String(node.source.value) === node.source.value)\n\t\t\t\timports.push(String(node.source.value))\n\t\t},\n\t}).visit(program)\n\treturn imports\n}\n\nfunction moduleOwner(file: string) {\n\tconst parts = file.split('/')\n\treturn parts[0] === 'domain' && parts.length >= 3 && parts[1] !== '__tests__'\n\t\t? `domain/${parts[1]}`\n\t\t: null\n}\n\nfunction cycles(graph: Map<string, Set<string>>) {\n\tconst completed = new Set<string>()\n\tconst stack: string[] = []\n\tconst found: string[][] = []\n\tfunction visit(owner: string) {\n\t\tconst index = stack.indexOf(owner)\n\t\tif (index >= 0) {\n\t\t\tfound.push([...stack.slice(index), owner])\n\t\t\treturn\n\t\t}\n\t\tif (completed.has(owner)) return\n\t\tstack.push(owner)\n\t\tfor (const dependency of graph.get(owner) ?? []) visit(dependency)\n\t\tstack.pop()\n\t\tcompleted.add(owner)\n\t}\n\tfor (const owner of graph.keys()) visit(owner)\n\treturn found\n}\n\nfunction sharedOwnership(dependencies: Map<string, Set<string>>): ArchitectureDiagnostic[] {\n\tconst consumers = new Map<string, Set<string>>()\n\tfor (const [file, targets] of dependencies) {\n\t\tconst owner = moduleOwner(file) ?? ''\n\t\tif (!owner || owner === 'domain/shared') continue\n\t\tconst visited = new Set<string>()\n\t\tfunction visit(target: string) {\n\t\t\tif (!target.startsWith('domain/shared/') || visited.has(target)) return\n\t\t\tvisited.add(target)\n\t\t\tconst owners = consumers.get(target) ?? new Set<string>()\n\t\t\towners.add(owner)\n\t\t\tconsumers.set(target, owners)\n\t\t\tfor (const next of dependencies.get(target) ?? []) visit(next)\n\t\t}\n\t\tfor (const target of targets) visit(target)\n\t}\n\tconst diagnostics: ArchitectureDiagnostic[] = []\n\tfor (const [file, owners] of consumers) {\n\t\tif (owners.size === 1)\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: 'shared-owner',\n\t\t\t\tfile,\n\t\t\t\tmessage: `This shared implementation is used only by ${[...owners][0]}. Move it into that module until another module needs it.`,\n\t\t\t})\n\t}\n\treturn diagnostics\n}\n"],"mappings":"A,yVA8BA,SAAgBA,EAAoB,EAA+B,CAAC,EAA6B,CAChG,IAAMC,EAAgBC,EAAQC,EAAQ,KAAO,QAAQ,IAAI,EAAGA,EAAQ,WAAa,QAAQ,EACnFC,EAAOC,EAAWJ,CAAa,EAAIK,EAAaL,CAAa,EAAIA,EACjEM,EAAwC,CAAC,EAC/C,GAAI,CAACF,EAAWD,CAAI,EACnB,MAAO,CACN,CAAE,KAAM,eAAgB,KAAM,IAAK,QAAS,oCAAoCA,GAAO,CACxF,EACD,IAAMI,GAAiBL,EAAQ,eAAiB,CAAC,EAAA,CAAG,IAAK,GAASD,EAAQE,EAAMK,CAAI,CAAC,EAC/EC,EAAQ,CAAC,GAAGC,EAAYP,EAAMG,CAAW,CAAC,EAC1CK,kBAAS,IAAI,IACnB,IAAK,IAAMC,KAAQH,EAAO,CACzB,IAAMI,EACLC,EAAkBb,EAAQE,EAAMS,CAAI,EAAGL,CAAa,GACpDQ,EAA0Bd,EAAQE,EAAMS,CAAI,EAAGT,CAAI,EAChDU,IAAUA,IAAUV,GAAQU,EAAM,WAAWV,EAAOa,CAAG,IAC1DL,EAAO,IAAIC,EAAMK,EAASd,EAAMU,CAAK,CAAC,CAAC,MAAMG,CAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAC7D,CACA,IAAME,EAAiB,IAAI,IAAIP,EAAO,OAAO,CAAC,EAE9C,IAAK,IAAIQ,EAAQb,EAAY,OAAS,EAAGa,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