cvx-kit 0.2.0 → 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 +556 -99
- package/dist/agent-tools.d.mts +39 -26
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +120 -308
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +7 -9
- package/dist/components/approvals/_generated/api.mjs.map +1 -1
- package/dist/components/approvals/_generated/component.d.mts +1 -4
- package/dist/components/approvals/_generated/dataModel.d.mts +5 -8
- package/dist/components/approvals/_generated/server.d.mts +12 -15
- package/dist/components/approvals/_generated/server.mjs.map +1 -1
- package/dist/components/approvals/audit.d.mts +8 -9
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +11 -12
- package/dist/components/approvals/client.mjs +1 -1
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.d.mts +30 -31
- 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 +13 -17
- package/dist/components/approvals/decisions.mjs +1 -1
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.d.mts +3 -4
- package/dist/components/approvals/functions.mjs +1 -1
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.d.mts +2 -3
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.d.mts +114 -131
- 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 +323 -395
- package/dist/components/approvals/validators.mjs +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.d.mts +4 -5
- 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 +16 -17
- package/dist/components/approvals/workflow_steps.mjs +1 -1
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/_generated/api.d.mts +6 -8
- package/dist/components/foundation/_generated/api.mjs.map +1 -1
- package/dist/components/foundation/_generated/component.d.mts +1 -4
- package/dist/components/foundation/_generated/dataModel.d.mts +5 -8
- package/dist/components/foundation/_generated/server.d.mts +12 -15
- package/dist/components/foundation/_generated/server.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +45 -38
- 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 +2 -3
- package/dist/components/foundation/functions.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +65 -17
- package/dist/components/foundation/modules/command/command.mjs +1 -1
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/command/lifecycle.d.mts +78 -0
- package/dist/components/foundation/modules/command/lifecycle.mjs +2 -0
- package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -0
- package/dist/components/foundation/modules/observability/observability.d.mts +13 -6
- package/dist/components/foundation/modules/observability/observability.mjs +1 -1
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/modules/query/query.d.mts +11 -12
- package/dist/components/foundation/modules/query/query.mjs +1 -1
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +72 -0
- package/dist/components/foundation/operation.mjs +2 -0
- package/dist/components/foundation/operation.mjs.map +1 -0
- package/dist/components/foundation/result.d.mts +7 -8
- 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 +2 -3
- package/dist/components/foundation/telemetry.mjs +1 -1
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/contracts.d.mts +5 -0
- package/dist/contracts.mjs +1 -0
- package/dist/crud.d.mts +185 -27
- package/dist/crud.mjs +1 -1
- package/dist/crud.mjs.map +1 -1
- package/dist/effect.d.mts +16 -0
- package/dist/effect.mjs +1 -0
- package/dist/errors.d.mts +6 -6
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filters.d.mts +4 -0
- package/dist/filters.mjs +1 -0
- package/dist/idempotency.d.mts +2 -0
- package/dist/idempotency.mjs +1 -0
- package/dist/index.d.mts +14 -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 +8 -11
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/modules/contracts/binding.d.mts +23 -0
- package/dist/modules/contracts/binding.mjs +2 -0
- package/dist/modules/contracts/binding.mjs.map +1 -0
- package/dist/modules/contracts/contract.d.mts +67 -0
- package/dist/modules/contracts/contract.mjs +2 -0
- package/dist/modules/contracts/contract.mjs.map +1 -0
- package/dist/modules/contracts/convex.d.mts +18 -0
- package/dist/modules/contracts/convex.mjs +2 -0
- package/dist/modules/contracts/convex.mjs.map +1 -0
- package/dist/modules/contracts/domain.d.mts +62 -0
- package/dist/modules/contracts/domain.mjs +2 -0
- package/dist/modules/contracts/domain.mjs.map +1 -0
- package/dist/modules/contracts/errors.d.mts +737 -0
- package/dist/modules/contracts/errors.mjs +2 -0
- package/dist/modules/contracts/errors.mjs.map +1 -0
- package/dist/modules/contracts/exposure.d.mts +103 -0
- package/dist/modules/contracts/exposure.mjs +2 -0
- package/dist/modules/contracts/exposure.mjs.map +1 -0
- package/dist/modules/contracts/idempotency.d.mts +85 -0
- package/dist/modules/contracts/idempotency.mjs +2 -0
- package/dist/modules/contracts/idempotency.mjs.map +1 -0
- package/dist/modules/contracts/lazy.d.mts +6 -0
- package/dist/modules/contracts/lazy.mjs +2 -0
- package/dist/modules/contracts/lazy.mjs.map +1 -0
- package/dist/modules/contracts/standard.d.mts +17 -0
- package/dist/modules/contracts/standard.mjs +2 -0
- package/dist/modules/contracts/standard.mjs.map +1 -0
- package/dist/modules/contracts/workflow.d.mts +165 -0
- package/dist/modules/contracts/workflow.mjs +2 -0
- package/dist/modules/contracts/workflow.mjs.map +1 -0
- package/dist/modules/effect/action.d.mts +63 -0
- package/dist/modules/effect/action.mjs +2 -0
- package/dist/modules/effect/action.mjs.map +1 -0
- package/dist/modules/effect/agent-tools.d.mts +2 -0
- package/dist/modules/effect/agent-tools.mjs +1 -0
- package/dist/modules/effect/api-runtime.d.mts +36 -0
- package/dist/modules/effect/api-runtime.mjs +2 -0
- package/dist/modules/effect/api-runtime.mjs.map +1 -0
- package/dist/modules/effect/api.d.mts +46 -0
- package/dist/modules/effect/api.mjs +2 -0
- package/dist/modules/effect/api.mjs.map +1 -0
- package/dist/modules/effect/auth.d.mts +46 -0
- package/dist/modules/effect/auth.mjs +2 -0
- package/dist/modules/effect/auth.mjs.map +1 -0
- package/dist/modules/effect/client.d.mts +15 -0
- package/dist/modules/effect/client.mjs +1 -0
- package/dist/modules/effect/command.d.mts +108 -0
- package/dist/modules/effect/command.mjs +2 -0
- package/dist/modules/effect/command.mjs.map +1 -0
- package/dist/modules/effect/crud.d.mts +885 -0
- package/dist/modules/effect/crud.mjs +2 -0
- package/dist/modules/effect/crud.mjs.map +1 -0
- package/dist/modules/effect/domain.d.mts +82 -0
- package/dist/modules/effect/domain.mjs +2 -0
- package/dist/modules/effect/domain.mjs.map +1 -0
- package/dist/modules/effect/errors.d.mts +13 -0
- package/dist/modules/effect/errors.mjs +2 -0
- package/dist/modules/effect/errors.mjs.map +1 -0
- package/dist/modules/effect/failure-audit.d.mts +48 -0
- package/dist/modules/effect/failure-audit.mjs +2 -0
- package/dist/modules/effect/failure-audit.mjs.map +1 -0
- package/dist/modules/effect/failures.d.mts +21 -0
- package/dist/modules/effect/failures.mjs +2 -0
- package/dist/modules/effect/failures.mjs.map +1 -0
- package/dist/modules/effect/foundation.d.mts +23 -0
- package/dist/modules/effect/foundation.mjs +2 -0
- package/dist/modules/effect/foundation.mjs.map +1 -0
- package/dist/modules/effect/idempotency.d.mts +29 -0
- package/dist/modules/effect/idempotency.mjs +2 -0
- package/dist/modules/effect/idempotency.mjs.map +1 -0
- 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 +7 -0
- package/dist/modules/effect/normalize.mjs +2 -0
- package/dist/modules/effect/normalize.mjs.map +1 -0
- package/dist/modules/effect/operation.d.mts +148 -0
- package/dist/modules/effect/operation.mjs +2 -0
- package/dist/modules/effect/operation.mjs.map +1 -0
- package/dist/modules/effect/query.d.mts +90 -0
- package/dist/modules/effect/query.mjs +2 -0
- package/dist/modules/effect/query.mjs.map +1 -0
- package/dist/modules/effect/schema.d.mts +30 -0
- package/dist/modules/effect/schema.mjs +2 -0
- package/dist/modules/effect/schema.mjs.map +1 -0
- package/dist/modules/effect/scope.d.mts +25 -0
- package/dist/modules/effect/scope.mjs +2 -0
- package/dist/modules/effect/scope.mjs.map +1 -0
- package/dist/modules/effect/workflow.d.mts +75 -0
- package/dist/modules/effect/workflow.mjs +2 -0
- package/dist/modules/effect/workflow.mjs.map +1 -0
- package/dist/modules/foundation/foundation.d.mts +108 -0
- package/dist/modules/foundation/foundation.mjs +2 -0
- package/dist/modules/foundation/foundation.mjs.map +1 -0
- package/dist/modules/foundation/operation.d.mts +139 -0
- package/dist/modules/foundation/operation.mjs +2 -0
- package/dist/modules/foundation/operation.mjs.map +1 -0
- 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 +23 -0
- package/dist/oxlint/architecture.mjs +2 -0
- package/dist/oxlint/architecture.mjs.map +1 -0
- package/dist/oxlint/ast.d.mts +51 -0
- package/dist/oxlint/ast.mjs +2 -0
- package/dist/oxlint/ast.mjs.map +1 -0
- package/dist/oxlint/components.d.mts +4 -0
- package/dist/oxlint/components.mjs +2 -0
- package/dist/oxlint/components.mjs.map +1 -0
- package/dist/oxlint/ownership.d.mts +59 -0
- package/dist/oxlint/ownership.mjs +2 -0
- package/dist/oxlint/ownership.mjs.map +1 -0
- package/dist/oxlint/reserved-files.d.mts +4 -0
- package/dist/oxlint/reserved-files.mjs +2 -0
- package/dist/oxlint/reserved-files.mjs.map +1 -0
- package/dist/oxlint.d.mts +9 -0
- package/dist/oxlint.mjs +2 -0
- package/dist/oxlint.mjs.map +1 -0
- package/dist/querying/cursors.d.mts +94 -0
- package/dist/querying/cursors.mjs +2 -0
- package/dist/querying/cursors.mjs.map +1 -0
- package/dist/querying/execution.d.mts +40 -0
- package/dist/querying/execution.mjs +2 -0
- package/dist/querying/execution.mjs.map +1 -0
- package/dist/querying/failures.d.mts +11 -0
- package/dist/querying/failures.mjs +2 -0
- package/dist/querying/failures.mjs.map +1 -0
- package/dist/querying/filter-boundary.d.mts +25 -0
- package/dist/querying/filter-boundary.mjs +2 -0
- package/dist/querying/filter-boundary.mjs.map +1 -0
- package/dist/querying/filters.d.mts +180 -0
- package/dist/querying/filters.mjs +2 -0
- package/dist/querying/filters.mjs.map +1 -0
- package/dist/querying/planner.d.mts +61 -0
- package/dist/querying/planner.mjs +2 -0
- package/dist/querying/planner.mjs.map +1 -0
- package/dist/querying/relationships.d.mts +58 -0
- package/dist/querying/relationships.mjs +2 -0
- package/dist/querying/relationships.mjs.map +1 -0
- package/dist/querying/search.d.mts +69 -0
- package/dist/querying/search.mjs +2 -0
- package/dist/querying/search.mjs.map +1 -0
- package/dist/querying/security.d.mts +123 -0
- package/dist/querying/security.mjs +2 -0
- package/dist/querying/security.mjs.map +1 -0
- package/dist/querying/shared/ast.d.mts +26 -0
- package/dist/querying/shared/ast.mjs +2 -0
- package/dist/querying/shared/ast.mjs.map +1 -0
- package/dist/querying/shared/contract.d.mts +98 -0
- package/dist/querying/shared/contract.mjs +2 -0
- package/dist/querying/shared/contract.mjs.map +1 -0
- package/dist/querying/shared/evaluate.d.mts +5 -0
- package/dist/querying/shared/evaluate.mjs +2 -0
- package/dist/querying/shared/evaluate.mjs.map +1 -0
- package/dist/querying/shared/filters.d.mts +65 -0
- package/dist/querying/shared/filters.mjs +2 -0
- package/dist/querying/shared/filters.mjs.map +1 -0
- 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 +20 -0
- package/dist/querying/shared/page.mjs +2 -0
- package/dist/querying/shared/page.mjs.map +1 -0
- package/dist/querying.d.mts +82 -0
- package/dist/querying.mjs +2 -0
- package/dist/querying.mjs.map +1 -0
- package/dist/react/failures.d.mts +24 -0
- package/dist/react/failures.mjs +2 -0
- package/dist/react/failures.mjs.map +1 -0
- package/dist/react/optimistic.d.mts +46 -0
- package/dist/react/optimistic.mjs +2 -0
- package/dist/react/optimistic.mjs.map +1 -0
- package/dist/react/pagination-state.d.mts +39 -0
- package/dist/react/pagination-state.mjs +2 -0
- package/dist/react/pagination-state.mjs.map +1 -0
- package/dist/react/use-command.d.mts +22 -0
- package/dist/react/use-command.mjs +2 -0
- package/dist/react/use-command.mjs.map +1 -0
- package/dist/react/use-paginated-list.d.mts +34 -0
- package/dist/react/use-paginated-list.mjs +2 -0
- package/dist/react/use-paginated-list.mjs.map +1 -0
- package/dist/react.d.mts +6 -0
- package/dist/react.mjs +1 -0
- 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 -0
- package/dist/relations-public.mjs +1 -0
- package/dist/relations.d.mts +274 -0
- package/dist/relations.mjs +2 -0
- package/dist/relations.mjs.map +1 -0
- package/dist/state-machine.d.mts +1 -4
- 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 +6 -8
- package/dist/tenancy.mjs +1 -1
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.d.mts +12 -10
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +22 -112
- package/dist/webhooks.mjs +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/dist/workflow.d.mts +2 -0
- package/dist/workflow.mjs +1 -0
- package/dist/zod.d.mts +30 -0
- package/dist/zod.mjs +2 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +145 -33
- package/src/test.ts +9 -17
- package/CHANGELOG.md +0 -145
- package/ROADMAP.md +0 -126
- package/dist/zod-table.d.mts +0 -175
- package/dist/zod-table.mjs +0 -2
- package/dist/zod-table.mjs.map +0 -1
- package/docs/agent-tools.md +0 -41
- package/docs/approvals.md +0 -200
- package/docs/architecture.md +0 -124
- package/docs/auth.md +0 -218
- package/docs/commands.md +0 -278
- package/docs/conventions.md +0 -291
- package/docs/crud.md +0 -62
- package/docs/llms.md +0 -220
- package/docs/maintainability.md +0 -124
- package/docs/migration.md +0 -351
- package/docs/plans/2026-08-14-001-feat-v0.1.0-feature-set-plan.md +0 -461
- package/docs/plans/2026-08-21-0930-feat-resolve-organization-hook-plan.md +0 -178
- package/docs/tenancy.md +0 -179
- package/docs/triggers.md +0 -75
- package/docs/upgrading.md +0 -175
- package/docs/webhooks.md +0 -58
- package/docs/zod-table.md +0 -173
- package/scripts/convex-config-bridge.mjs +0 -55
- package/scripts/extract-changelog.mjs +0 -29
- package/scripts/smoke-packed-components.mjs +0 -374
package/docs/migration.md
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
# Migrating an existing Convex project to the cvx-kit architecture
|
|
2
|
-
|
|
3
|
-
This guide takes a "raw" Convex project — the typical shape where every file at
|
|
4
|
-
the root of `convex/` exports public queries and mutations, tables are defined
|
|
5
|
-
inline in `schema.ts`, and validators are `v.*` objects repeated per function —
|
|
6
|
-
and restructures it into the cvx-kit architecture.
|
|
7
|
-
|
|
8
|
-
This is an **opinionated infrastructure**. The rules below are not
|
|
9
|
-
suggestions; they are the contract. Where the kit makes something structural
|
|
10
|
-
(auth, triggers, bounded reads, mandatory audit), the migration's job is to
|
|
11
|
-
remove every code path that circumvents the structure. Names in `<angle
|
|
12
|
-
brackets>` are placeholders for your own vocabulary — no specific entity,
|
|
13
|
-
table, field, or workflow is mandated, only the roles and rules.
|
|
14
|
-
|
|
15
|
-
Migrate incrementally: each step leaves the app deployable, and old and new
|
|
16
|
-
shapes can coexist while you move entity by entity.
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## 1. The target structure — complete
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
convex/
|
|
24
|
-
convex.config.ts # component mounting. Nothing else.
|
|
25
|
-
schema.ts # defineSchema(domainTables). Nothing else.
|
|
26
|
-
functions.ts # the single createAuthFunctions(...) call
|
|
27
|
-
triggers.ts # the single trigger registry + helper registrations
|
|
28
|
-
foundation.ts # the single new Foundation(...) facade
|
|
29
|
-
<component>.ts # one facade per mounted component (audit.ts, approvals.ts, pool.ts, workflows.ts, ...)
|
|
30
|
-
auth.ts # identity-provider client wiring
|
|
31
|
-
auth.config.ts # Convex auth providers config
|
|
32
|
-
http.ts # HTTP router (webhook endpoints delegate to domains)
|
|
33
|
-
crons.ts # cron declarations only; targets are internal domain functions
|
|
34
|
-
|
|
35
|
-
api/ # ═══ THE ONLY PUBLIC SURFACE ═══
|
|
36
|
-
<entity>.ts # thin adapters: auth* constructors → domain executors → DTOs
|
|
37
|
-
|
|
38
|
-
domain/ # ═══ ALL BUSINESS LOGIC ═══
|
|
39
|
-
table.ts # merges per-entity table maps into domainTables
|
|
40
|
-
shared/ # genuinely cross-entity code ONLY
|
|
41
|
-
schema.ts # cross-entity zod helpers (if any)
|
|
42
|
-
<provider>.ts # one configured vendor client per provider (sql, cache, email, ...)
|
|
43
|
-
<entity>/ # one directory per entity/aggregate
|
|
44
|
-
schema.ts # the zodTable declaration — shapes and masks, nothing else
|
|
45
|
-
table.ts # index topology attached to <zodTable>.table
|
|
46
|
-
constants.ts # finite vocabularies: UPPER_SNAKE readonly tuples
|
|
47
|
-
commands.ts # operation registry + command executors
|
|
48
|
-
queries.ts # domain read logic
|
|
49
|
-
rules.ts # pure domain invariants/predicates (no ctx, no db)
|
|
50
|
-
shared.ts # helpers shared by multiple files of THIS entity
|
|
51
|
-
<workflow>.ts # approval/workflow definitions this entity owns
|
|
52
|
-
<workflow>_functions.ts # internal callback targets (system* constructors)
|
|
53
|
-
actions.ts # external-side-effect logic (via shared provider clients)
|
|
54
|
-
__tests__/ # behavioral tests for this entity
|
|
55
|
-
|
|
56
|
-
components/ # only if the app authors its own portable components
|
|
57
|
-
<name>/ # own convex.config.ts, schema.ts, _generated/, __tests__/
|
|
58
|
-
|
|
59
|
-
__tests__/ # ═══ APP-WIDE GUARDRAILS ═══
|
|
60
|
-
setup.ts # env stubs for vars declared on defineApp({ env })
|
|
61
|
-
architecture.test.ts # the executable conventions (see §6)
|
|
62
|
-
facades.test.ts # each app.use exactly once; no private-child access
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### The root rule
|
|
66
|
-
|
|
67
|
-
**The root of `convex/` contains configuration and facades only.** Every root
|
|
68
|
-
file is a *declaration point* — the single place one piece of infrastructure
|
|
69
|
-
is configured — and none of them exports a public function or contains
|
|
70
|
-
business logic. If a client can call it, it lives in `api/`. If it decides
|
|
71
|
-
anything about the business, it lives in `domain/`. If `ls convex/*.ts` shows
|
|
72
|
-
anything else, the migration is not done.
|
|
73
|
-
|
|
74
|
-
### Hard prohibitions (grep-able, test-enforceable)
|
|
75
|
-
|
|
76
|
-
These patterns must not exist anywhere after migration — each one is a hole in
|
|
77
|
-
a structural guarantee:
|
|
78
|
-
|
|
79
|
-
| Forbidden | Where it's allowed instead | What it breaks otherwise |
|
|
80
|
-
|---|---|---|
|
|
81
|
-
| `query(`, `mutation(`, `action(`, `internalMutation(`, `internalAction(` from `_generated/server` | `functions.ts` only | auth, triggers, bounded reads |
|
|
82
|
-
| `defineTable(` | `domain/<entity>/table.ts` via `<zodTable>.table` | single source of truth per entity |
|
|
83
|
-
| `defineSchema(` | root `schema.ts` only | schema assembly |
|
|
84
|
-
| inline `z.enum([...])` / repeated literal unions | tuple in `constants.ts` | vocabulary ownership |
|
|
85
|
-
| `.collect()` / unbounded reads in public paths | `ctx.include(...).execute(limit)` | read bounds |
|
|
86
|
-
| `makeFunctionReference` | generated `internal` / `api` | refactoring safety |
|
|
87
|
-
| deep imports of a component's internals | the component's client facade | component boundary |
|
|
88
|
-
| sibling-domain imports (`domain/a` → `domain/b`) | `domain/shared/` or the public API | ownership |
|
|
89
|
-
| `ctx.db.insert/patch/delete` on a mounted component's tables | the component's client methods | component persistence |
|
|
90
|
-
| vendor SDK instantiation inside a domain | one shared client in `domain/shared/<provider>.ts` | connection discipline |
|
|
91
|
-
| `new Date().toISOString()` / hand-written timestamp fields | the `timestamps` trigger | server-owned lifecycle |
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## 2. Where each kind of existing code goes
|
|
96
|
-
|
|
97
|
-
A raw project's root files usually mix several kinds of code. Pull them apart:
|
|
98
|
-
|
|
99
|
-
| You have today | It becomes |
|
|
100
|
-
|---|---|
|
|
101
|
-
| `export const get/list = query({...})` at root | adapter in `api/<entity>.ts` + read logic in `domain/<entity>/queries.ts` |
|
|
102
|
-
| `export const create/update = mutation({...})` at root | adapter in `api/<entity>.ts` + operation in `domain/<entity>/commands.ts` |
|
|
103
|
-
| `internalMutation`/`internalAction` helpers | `system*` functions in `domain/<entity>/<purpose>_functions.ts` |
|
|
104
|
-
| inline `defineTable({...})` in `schema.ts` | `zodTable` in `domain/<entity>/schema.ts` + indexes in `domain/<entity>/table.ts` |
|
|
105
|
-
| `v.union(v.literal(...))` / inline `z.enum` repeated around | one `UPPER_SNAKE` tuple in `domain/<entity>/constants.ts` |
|
|
106
|
-
| validation/business `if`-chains inside handlers | pure predicates in `domain/<entity>/rules.ts` |
|
|
107
|
-
| shared grab-bag (`helpers.ts`, `utils.ts`, `lib.ts`) | split by owner into `domain/<entity>/shared.ts`; only genuinely cross-entity code into `domain/shared/` |
|
|
108
|
-
| ad-hoc vendor clients (HTTP SDKs, caches, SQL) | one configured client per provider in `domain/shared/<provider>.ts` |
|
|
109
|
-
| webhook handlers with logic in `http.ts` | route in `http.ts`, logic in `domain/<entity>/actions.ts` |
|
|
110
|
-
| cron handlers with logic in `crons.ts` | declaration in `crons.ts`, target `system*` function in the domain |
|
|
111
|
-
| audit/log/history tables mirroring component state | the component's own persistence via its facade |
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## 3. Naming — the full convention set
|
|
116
|
-
|
|
117
|
-
Naming is part of the architecture: several kit mechanisms key off it at
|
|
118
|
-
runtime (observability drops non-conforming events), and the rest makes the
|
|
119
|
-
codebase greppable.
|
|
120
|
-
|
|
121
|
-
- **Directories**: `domain/<entity>/` uses the plural camelCase table name.
|
|
122
|
-
One entity, one directory — no `domain/misc/`.
|
|
123
|
-
- **Tables**: plural camelCase (`<entities>`).
|
|
124
|
-
- **Indexes**: `by_<field>` / `by_<field>_and_<field>`, fields in declaration
|
|
125
|
-
order, nested paths flattened with `_` (`by_ownerId_and_state_status` for
|
|
126
|
-
`['ownerId', 'state.status']`). A reader must be able to reconstruct the
|
|
127
|
-
index definition from its name.
|
|
128
|
-
- **Command operations**: `<entity>.<verb>` lowercase dotted
|
|
129
|
-
(`invoices.approve`). Must match `/^[A-Za-z][A-Za-z0-9_.-]{0,159}$/` or
|
|
130
|
-
observability drops the events.
|
|
131
|
-
- **Error codes**: `UPPER_SNAKE`, matching `/^[A-Z][A-Z0-9_]{0,95}$/`. Define
|
|
132
|
-
the full set once (one owner), not per callsite.
|
|
133
|
-
- **Vocabulary tuples**: `UPPER_SNAKE_CASE` exported `as const`; derived type
|
|
134
|
-
`PascalCase` singular (`const <ENTITY>_STATES = [...] as const;
|
|
135
|
-
type <Entity>State = (typeof <ENTITY>_STATES)[number]`).
|
|
136
|
-
- **Domain executors**: `execute<Verb><Entity>` (`executeApproveInvoice`) —
|
|
137
|
-
the grep-able seam between adapters and domain.
|
|
138
|
-
- **Internal callback files**: `<purpose>_functions.ts` next to the
|
|
139
|
-
`<purpose>.ts` that references them.
|
|
140
|
-
- **Public function names** are `api/<entity>:fn` — clients never reference a
|
|
141
|
-
root-level path.
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
## 4. Step-by-step migration
|
|
146
|
-
|
|
147
|
-
### Step 0 — Inventory
|
|
148
|
-
|
|
149
|
-
List every exported function and classify it: public read, public write,
|
|
150
|
-
internal, cron target, HTTP handler. List every table, every index, every
|
|
151
|
-
literal string union, every vendor client instantiation. This is the
|
|
152
|
-
checklist; entities with the fewest dependencies migrate first.
|
|
153
|
-
|
|
154
|
-
### Step 1 — Mount the kit, declare the root files
|
|
155
|
-
|
|
156
|
-
Install `cvx-kit`, mount `foundation` (and `approvals` if needed) in
|
|
157
|
-
`convex.config.ts`, run codegen. Create `functions.ts`, `triggers.ts`,
|
|
158
|
-
`foundation.ts`, and one facade per mounted component. Declare required env
|
|
159
|
-
vars on `defineApp({ env: { ... } })` so deploys fail fast, and stub them in
|
|
160
|
-
`__tests__/setup.ts`. Nothing breaks: raw functions keep working alongside
|
|
161
|
-
the new constructors.
|
|
162
|
-
|
|
163
|
-
### Step 2 — Convert tables entity by entity
|
|
164
|
-
|
|
165
|
-
For each table:
|
|
166
|
-
|
|
167
|
-
1. `domain/<entity>/schema.ts`: a `zodTable` mirroring the current shape,
|
|
168
|
-
`v.*` converted to zod. Decide the three masks **deliberately** —
|
|
169
|
-
`serverFields` (server-assigned), `commandFields` (what a write request
|
|
170
|
-
may say), `publicFields` (what a client may see). This is where implicit
|
|
171
|
-
trust becomes explicit policy; a mis-declared mask is a security bug, so
|
|
172
|
-
review masks like auth code.
|
|
173
|
-
2. `domain/<entity>/table.ts`: move the indexes, renamed to the convention.
|
|
174
|
-
3. Register in `domain/table.ts`; shrink root `schema.ts` toward
|
|
175
|
-
`defineSchema(domainTables)`.
|
|
176
|
-
4. The kit's timestamps are `.optional()`, so existing rows validate without
|
|
177
|
-
backfill. Register `timestamps(triggers, '<table>')`; new writes maintain
|
|
178
|
-
`createdAt`/`updatedAt`. Backfill later if needed. Existing hand-rolled
|
|
179
|
-
timestamp fields (e.g. ISO strings) stay in the shape for now — migrate
|
|
180
|
-
the data separately; never couple data migration to restructuring.
|
|
181
|
-
5. Apply write discipline per table while you're here: `appendOnly` for
|
|
182
|
-
evidence tables (votes, history), `noDelete` + `archivedAt` for anything a
|
|
183
|
-
human might ask about later. Hard deletes are opt-in per table, not the
|
|
184
|
-
default.
|
|
185
|
-
|
|
186
|
-
### Step 3 — Move vocabularies to `constants.ts`
|
|
187
|
-
|
|
188
|
-
Every reusable finite vocabulary gets one owner: an exported tuple in the
|
|
189
|
-
owning entity's `constants.ts`. Schemas, validators, filters, transition
|
|
190
|
-
maps, and tests consume the tuple. Subsets and ordered presentations derive
|
|
191
|
-
from the canonical tuple, typed against its value type so an invalid literal
|
|
192
|
-
cannot compile. A file-local tuple is acceptable **only** for private
|
|
193
|
-
implementation mechanics that can never appear in another schema, contract,
|
|
194
|
-
persisted document, or UI state — and it is still `UPPER_SNAKE_CASE`.
|
|
195
|
-
|
|
196
|
-
### Step 4 — Split public functions into adapter + domain logic
|
|
197
|
-
|
|
198
|
-
For each public function at the root:
|
|
199
|
-
|
|
200
|
-
1. **Extract the domain logic.** Reads → `domain/<entity>/queries.ts`.
|
|
201
|
-
Writes → an operation in the entity's command registry with
|
|
202
|
-
classification and audit derivation (see `commands.md`) — deciding *what
|
|
203
|
-
gets audited and as what* is a product decision; make it explicitly, not
|
|
204
|
-
as an afterthought. Pure conditions the handler checks
|
|
205
|
-
(state-transition legality, permission-beyond-role predicates) →
|
|
206
|
-
`rules.ts`, so they're unit-testable without a ctx.
|
|
207
|
-
2. **Write the adapter** in `api/<entity>.ts` with `authQuery`/
|
|
208
|
-
`authMutation`/`role*`/`admin*`. Adapters do exactly four things: parse
|
|
209
|
-
args with the entity's boundary schemas, authorize via the constructor
|
|
210
|
-
choice, call the domain executor with `ctx.actor`, project through
|
|
211
|
-
`toPublicDto`. **Adapter budget: if it exceeds ~10 lines of glue or grows
|
|
212
|
-
a private helper, logic is leaking — move it into the domain.**
|
|
213
|
-
3. **Retire the old path.** Public names change to `api/<entity>:fn`; update
|
|
214
|
-
client call sites per entity, or keep a temporary re-export file at the
|
|
215
|
-
old path and delete it in the final step.
|
|
216
|
-
|
|
217
|
-
Anything "public-but-really-internal" (only called by your own scheduled
|
|
218
|
-
functions or other backend code) must stop being public: convert to `system*`
|
|
219
|
-
in the domain.
|
|
220
|
-
|
|
221
|
-
### Step 5 — Convert internal functions and the wiring files
|
|
222
|
-
|
|
223
|
-
- Replace raw `internalMutation`/`internalAction` with `systemMutation`/
|
|
224
|
-
`systemAction` from `functions.ts`, located in the owning domain's
|
|
225
|
-
`<purpose>_functions.ts`. Scheduled and callback writes now run under the
|
|
226
|
-
same trigger regime as user writes.
|
|
227
|
-
- `crons.ts` becomes declarations only, targeting `internal.domain.<entity>.
|
|
228
|
-
<purpose>_functions.*`.
|
|
229
|
-
- `http.ts` becomes routing only: verify the webhook signature, parse the
|
|
230
|
-
payload at the boundary, delegate to a domain action/function.
|
|
231
|
-
|
|
232
|
-
### Step 6 — Bound the reads
|
|
233
|
-
|
|
234
|
-
Replace `.collect()` and unbounded `.take(n)` in public paths with
|
|
235
|
-
`ctx.include(...).execute(limit)` (limit ≤ 100). Where a query can't be
|
|
236
|
-
served by an index, **add the index** — a scan is a schema problem, not a
|
|
237
|
-
query-code problem. Paginated surfaces cross the boundary with the convex
|
|
238
|
-
pagination validators bridged into zod (`convexToZod(paginationOptsValidator)`
|
|
239
|
-
and a `paginationResultValidator` built from the row validator), not with
|
|
240
|
-
hand-rolled cursor objects.
|
|
241
|
-
|
|
242
|
-
### Step 7 — Enforce everything with tests
|
|
243
|
-
|
|
244
|
-
Port the executable-architecture pattern. `__tests__/architecture.test.ts`
|
|
245
|
-
globs all production sources and asserts the Hard Prohibitions table above;
|
|
246
|
-
**each rule is proved against a synthetic violating fixture first** so a
|
|
247
|
-
broken checker cannot silently pass. `facades.test.ts` asserts each
|
|
248
|
-
`app.use(x)` appears exactly once and no file reaches a component's private
|
|
249
|
-
children. From this point the migration cannot regress — and neither can
|
|
250
|
-
future contributors or coding agents.
|
|
251
|
-
|
|
252
|
-
---
|
|
253
|
-
|
|
254
|
-
## 5. File conduct — how every source file is organized
|
|
255
|
-
|
|
256
|
-
From the origin project's code conduct. Apply to new code and files being
|
|
257
|
-
substantially changed; don't mechanically rewrite untouched files.
|
|
258
|
-
|
|
259
|
-
**File order** — readable from public purpose to private implementation:
|
|
260
|
-
|
|
261
|
-
1. Imports.
|
|
262
|
-
2. Exported types, schemas, constants, and public functions — the API.
|
|
263
|
-
3. File-local types and constants supporting the implementation.
|
|
264
|
-
4. Private helpers, as **named function declarations**, at the bottom.
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
import { parseInput } from './schema'
|
|
268
|
-
|
|
269
|
-
export async function createProjection(input: unknown) {
|
|
270
|
-
return buildProjection(parseInput(input))
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function buildProjection(input: ProjectionInput) {
|
|
274
|
-
// implementation
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Never place private helper implementations above the exported API. Prefer
|
|
279
|
-
`function` declarations over helper arrow-constants so helpers can live at
|
|
280
|
-
the bottom.
|
|
281
|
-
|
|
282
|
-
**Ownership.** Put behavior beside the entity that owns it. Consumers (api
|
|
283
|
-
adapters, cron targets, workflow callbacks) stay thin: validate, authorize,
|
|
284
|
-
call the owning operation, translate the result. A consumer accumulating
|
|
285
|
-
entity rules or a pile of private helpers is logic asking to move into the
|
|
286
|
-
domain.
|
|
287
|
-
|
|
288
|
-
**No convenience re-exports.** Import a function from the file that owns it;
|
|
289
|
-
never re-export to shorten a path. Barrel files (`index.ts` re-exporting a
|
|
290
|
-
directory) are banned inside `convex/` — they blur ownership and create
|
|
291
|
-
import cycles.
|
|
292
|
-
|
|
293
|
-
**Components own their persistence.** Never mirror a mounted component's
|
|
294
|
-
internal state (audit events, workflow steps, job results) into application
|
|
295
|
-
tables unless the product domain independently requires a durable business
|
|
296
|
-
record. Log through the facade; don't build a receipts table for it.
|
|
297
|
-
|
|
298
|
-
**Comments state constraints, not narration.** The accepted pattern for
|
|
299
|
-
schema evolution is a one-line epoch comment on an `.optional()` field
|
|
300
|
-
explaining why it's optional. Comments that restate the next line are noise.
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
## 6. Documentation the migrated repo must carry
|
|
305
|
-
|
|
306
|
-
An opinionated codebase documents its opinions, or they die at the first
|
|
307
|
-
new contributor. Minimum set:
|
|
308
|
-
|
|
309
|
-
- **`CODE_CONDUCT.md`** (or equivalent) — the repo's own conventions: file
|
|
310
|
-
order, ownership layout, vocabulary rules, naming. This guide's §3 and §5
|
|
311
|
-
are the starting template; adapt, don't link.
|
|
312
|
-
- **`CONCEPTS.md`** — the domain glossary: every entity, state, and
|
|
313
|
-
vocabulary word with its business meaning. LLMs and new hires read this
|
|
314
|
-
first; keep entries one paragraph.
|
|
315
|
-
- **`CLAUDE.md` / `AGENTS.md`** — thin pointers: the stack, the three
|
|
316
|
-
commands that matter (test, typecheck, deploy), and links to
|
|
317
|
-
`CODE_CONDUCT.md` + `node_modules/cvx-kit/src/docs/llms.md`. Agent files
|
|
318
|
-
that duplicate the conduct doc drift; keep them as an index.
|
|
319
|
-
- **Architecture tests as documentation** — the test names in
|
|
320
|
-
`architecture.test.ts` are the enforceable summary of the conduct doc;
|
|
321
|
-
a rule that exists in prose but not in the suite is a request, not a rule.
|
|
322
|
-
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
## 7. Definition of done
|
|
326
|
-
|
|
327
|
-
The migration is complete when every box checks:
|
|
328
|
-
|
|
329
|
-
- [ ] `ls convex/*.ts` shows only configuration and facades (§1 table).
|
|
330
|
-
- [ ] Every public function lives in `api/` and uses `auth*`/`role*`/`admin*`.
|
|
331
|
-
- [ ] Every internal function uses `system*` and lives in its domain.
|
|
332
|
-
- [ ] `functions.ts` is the only file importing `_generated/server` builders.
|
|
333
|
-
- [ ] Every table is a `zodTable` with deliberately reviewed masks; indexes
|
|
334
|
-
named by convention; timestamps trigger registered.
|
|
335
|
-
- [ ] Every vocabulary is a single-owner tuple in a `constants.ts`.
|
|
336
|
-
- [ ] Every state change is a command operation with classification + audit.
|
|
337
|
-
- [ ] Every public read is bounded (`include` + limit, or bridged pagination).
|
|
338
|
-
- [ ] No entry in the Hard Prohibitions table greps positive.
|
|
339
|
-
- [ ] `architecture.test.ts` + `facades.test.ts` exist, each rule fixture-proved.
|
|
340
|
-
- [ ] `CODE_CONDUCT.md` and `CONCEPTS.md` exist; agent files point at them.
|
|
341
|
-
- [ ] Transitional re-exports deleted; clients call `api/<entity>:fn` paths.
|
|
342
|
-
|
|
343
|
-
## Migration order that works
|
|
344
|
-
|
|
345
|
-
1. Root files + kit mounting (step 1) — zero behavioral change.
|
|
346
|
-
2. The smallest, least-referenced entity end-to-end (steps 2–6) — shakes out
|
|
347
|
-
masks, role mapping, and conventions on a low-stakes surface.
|
|
348
|
-
3. Architecture tests (step 7) — lock the rules in **before** the bulk.
|
|
349
|
-
4. Remaining entities in dependency order, one PR each.
|
|
350
|
-
5. Delete transitional re-exports and remaining root function files; run the
|
|
351
|
-
definition-of-done checklist.
|