@opensaas/stack-core 0.42.3 → 0.44.0-alpha.1
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/CHANGELOG.md +2745 -0
- package/README.md +182 -115
- package/dist/.build-hash +1 -0
- package/dist/access/declared-dependencies.d.ts +102 -88
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +83 -71
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +4 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +4 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +68 -20
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +151 -37
- package/dist/access/engine.js.map +1 -1
- package/dist/access/errors.d.ts +33 -48
- package/dist/access/errors.d.ts.map +1 -1
- package/dist/access/errors.js +73 -63
- package/dist/access/errors.js.map +1 -1
- package/dist/access/field-access.d.ts +76 -5
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +235 -61
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/field-visibility.d.ts +50 -4
- package/dist/access/field-visibility.d.ts.map +1 -1
- package/dist/access/field-visibility.js +143 -160
- package/dist/access/field-visibility.js.map +1 -1
- package/dist/access/index.d.ts +5 -12
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -19
- package/dist/access/index.js.map +1 -1
- package/dist/access/orm-client.d.ts +19 -0
- package/dist/access/orm-client.d.ts.map +1 -0
- package/dist/access/orm-client.js +37 -0
- package/dist/access/orm-client.js.map +1 -0
- package/dist/access/query-validation.d.ts +7 -129
- package/dist/access/query-validation.d.ts.map +1 -1
- package/dist/access/query-validation.js +12 -314
- package/dist/access/query-validation.js.map +1 -1
- package/dist/access/system-fields.d.ts +2 -0
- package/dist/access/system-fields.d.ts.map +1 -0
- package/dist/access/system-fields.js +7 -0
- package/dist/access/system-fields.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +25 -2
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +34 -17
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +217 -131
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/field-kind.d.ts +66 -0
- package/dist/config/field-kind.d.ts.map +1 -0
- package/dist/config/field-kind.js +63 -0
- package/dist/config/field-kind.js.map +1 -0
- package/dist/config/hook-only-fields.d.ts +3 -0
- package/dist/config/hook-only-fields.d.ts.map +1 -0
- package/dist/config/hook-only-fields.js +17 -0
- package/dist/config/hook-only-fields.js.map +1 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-tool-names.d.ts +3 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -0
- package/dist/config/mcp-tool-names.js +25 -0
- package/dist/config/mcp-tool-names.js.map +1 -0
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +4 -4
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts +8 -2
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +102 -38
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +966 -614
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/apply-defaults.d.ts +18 -1
- package/dist/context/apply-defaults.d.ts.map +1 -1
- package/dist/context/apply-defaults.js +30 -4
- package/dist/context/apply-defaults.js.map +1 -1
- package/dist/context/engine-context.d.ts +73 -0
- package/dist/context/engine-context.d.ts.map +1 -0
- package/dist/context/engine-context.js +67 -0
- package/dist/context/engine-context.js.map +1 -0
- package/dist/context/hook-pipeline.d.ts +9 -2
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +5 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +98 -89
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +917 -722
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +59 -0
- package/dist/context/junction.d.ts.map +1 -0
- package/dist/context/junction.js +126 -0
- package/dist/context/junction.js.map +1 -0
- package/dist/context/plugin-field-read.d.ts +33 -0
- package/dist/context/plugin-field-read.d.ts.map +1 -0
- package/dist/context/plugin-field-read.js +41 -0
- package/dist/context/plugin-field-read.js.map +1 -0
- package/dist/context/plugin-field-write.d.ts +104 -0
- package/dist/context/plugin-field-write.d.ts.map +1 -0
- package/dist/context/plugin-field-write.js +184 -0
- package/dist/context/plugin-field-write.js.map +1 -0
- package/dist/context/relationship-input.d.ts +146 -0
- package/dist/context/relationship-input.d.ts.map +1 -0
- package/dist/context/relationship-input.js +453 -0
- package/dist/context/relationship-input.js.map +1 -0
- package/dist/context/transaction-boundary.d.ts +54 -28
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +87 -169
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +33 -51
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +372 -185
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/contract/dependencies.d.ts +88 -0
- package/dist/contract/dependencies.d.ts.map +1 -0
- package/dist/contract/dependencies.js +237 -0
- package/dist/contract/dependencies.js.map +1 -0
- package/dist/contract/derive.d.ts +49 -0
- package/dist/contract/derive.d.ts.map +1 -0
- package/dist/contract/derive.js +540 -0
- package/dist/contract/derive.js.map +1 -0
- package/dist/contract/fixtures/contract-configs.d.ts +64 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
- package/dist/contract/fixtures/contract-configs.js +345 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -0
- package/dist/contract/id-boundary.d.ts +53 -0
- package/dist/contract/id-boundary.d.ts.map +1 -0
- package/dist/contract/id-boundary.js +76 -0
- package/dist/contract/id-boundary.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +11 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/prisma.d.ts +58 -0
- package/dist/contract/prisma.d.ts.map +1 -0
- package/dist/contract/prisma.js +282 -0
- package/dist/contract/prisma.js.map +1 -0
- package/dist/contract/relation-graph.d.ts +70 -0
- package/dist/contract/relation-graph.d.ts.map +1 -0
- package/dist/contract/relation-graph.js +113 -0
- package/dist/contract/relation-graph.js.map +1 -0
- package/dist/contract/types.d.ts +135 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/db/client.d.ts +55 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +73 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/dev-database.d.ts +124 -0
- package/dist/db/dev-database.d.ts.map +1 -0
- package/dist/db/dev-database.js +291 -0
- package/dist/db/dev-database.js.map +1 -0
- package/dist/db/password-front.d.ts +10 -0
- package/dist/db/password-front.d.ts.map +1 -0
- package/dist/db/password-front.js +147 -0
- package/dist/db/password-front.js.map +1 -0
- package/dist/db/process-identity.d.ts +36 -0
- package/dist/db/process-identity.d.ts.map +1 -0
- package/dist/db/process-identity.js +114 -0
- package/dist/db/process-identity.js.map +1 -0
- package/dist/db/state-file.d.ts +54 -0
- package/dist/db/state-file.d.ts.map +1 -0
- package/dist/db/state-file.js +91 -0
- package/dist/db/state-file.js.map +1 -0
- package/dist/db/url.d.ts +89 -0
- package/dist/db/url.d.ts.map +1 -0
- package/dist/db/url.js +118 -0
- package/dist/db/url.js.map +1 -0
- package/dist/extend.d.ts +13 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js +24 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +87 -42
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +457 -677
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +3 -4
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +2 -2
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -2
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +0 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +12 -5
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +47 -19
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/types.d.ts +10 -24
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +22 -31
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +33 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/transition-guard.d.ts +61 -0
- package/dist/hooks/transition-guard.d.ts.map +1 -0
- package/dist/hooks/transition-guard.js +93 -0
- package/dist/hooks/transition-guard.js.map +1 -0
- package/dist/index.d.ts +52 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -44
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +221 -0
- package/dist/validation/database-config.js.map +1 -0
- package/dist/validation/default-value.d.ts +21 -0
- package/dist/validation/default-value.d.ts.map +1 -0
- package/dist/validation/default-value.js +72 -0
- package/dist/validation/default-value.js.map +1 -0
- package/dist/validation/extension-packs.d.ts +11 -0
- package/dist/validation/extension-packs.d.ts.map +1 -0
- package/dist/validation/extension-packs.js +53 -0
- package/dist/validation/extension-packs.js.map +1 -0
- package/dist/validation/field-config.d.ts +35 -21
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +51 -41
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +15 -0
- package/dist/validation/field-names.d.ts.map +1 -0
- package/dist/validation/field-names.js +155 -0
- package/dist/validation/field-names.js.map +1 -0
- package/dist/validation/identifier-names.d.ts +4 -0
- package/dist/validation/identifier-names.d.ts.map +1 -0
- package/dist/validation/identifier-names.js +39 -0
- package/dist/validation/identifier-names.js.map +1 -0
- package/dist/validation/needs-closure.d.ts +20 -30
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +29 -105
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts +17 -0
- package/dist/validation/relations.d.ts.map +1 -0
- package/dist/validation/relations.js +268 -0
- package/dist/validation/relations.js.map +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +1 -3
- package/dist/validation/schema.js.map +1 -1
- package/dist/where/like.d.ts +32 -0
- package/dist/where/like.d.ts.map +1 -0
- package/dist/where/like.js +42 -0
- package/dist/where/like.js.map +1 -0
- package/package.json +70 -8
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -609
- package/dist/access/access-filter.d.ts +0 -241
- package/dist/access/access-filter.d.ts.map +0 -1
- package/dist/access/access-filter.js +0 -692
- package/dist/access/access-filter.js.map +0 -1
- package/dist/access/access-filter.test.d.ts +0 -2
- package/dist/access/access-filter.test.d.ts.map +0 -1
- package/dist/access/access-filter.test.js +0 -1256
- package/dist/access/access-filter.test.js.map +0 -1
- package/dist/access/declared-dependencies.test.d.ts +0 -2
- package/dist/access/declared-dependencies.test.d.ts.map +0 -1
- package/dist/access/declared-dependencies.test.js +0 -226
- package/dist/access/declared-dependencies.test.js.map +0 -1
- package/dist/access/denied-relation-visibility.test.d.ts +0 -2
- package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
- package/dist/access/denied-relation-visibility.test.js +0 -114
- package/dist/access/denied-relation-visibility.test.js.map +0 -1
- package/dist/access/engine.test.d.ts +0 -2
- package/dist/access/engine.test.d.ts.map +0 -1
- package/dist/access/engine.test.js +0 -56
- package/dist/access/engine.test.js.map +0 -1
- package/dist/access/field-access.test.d.ts +0 -2
- package/dist/access/field-access.test.d.ts.map +0 -1
- package/dist/access/field-access.test.js +0 -635
- package/dist/access/field-access.test.js.map +0 -1
- package/dist/access/multi-column-read-write.test.d.ts +0 -2
- package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
- package/dist/access/multi-column-read-write.test.js +0 -183
- package/dist/access/multi-column-read-write.test.js.map +0 -1
- package/dist/access/relationship-count.d.ts +0 -98
- package/dist/access/relationship-count.d.ts.map +0 -1
- package/dist/access/relationship-count.js +0 -262
- package/dist/access/relationship-count.js.map +0 -1
- package/dist/access/relationship-count.test.d.ts +0 -2
- package/dist/access/relationship-count.test.d.ts.map +0 -1
- package/dist/access/relationship-count.test.js +0 -247
- package/dist/access/relationship-count.test.js.map +0 -1
- package/dist/access/relationship-label-filter.d.ts +0 -45
- package/dist/access/relationship-label-filter.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.js +0 -22
- package/dist/access/relationship-label-filter.js.map +0 -1
- package/dist/access/relationship-label-filter.test.d.ts +0 -2
- package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.test.js +0 -89
- package/dist/access/relationship-label-filter.test.js.map +0 -1
- package/dist/access/synthetic-include-read.test.d.ts +0 -2
- package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
- package/dist/access/synthetic-include-read.test.js +0 -121
- package/dist/access/synthetic-include-read.test.js.map +0 -1
- package/dist/context/nested-operations.d.ts +0 -47
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -731
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1325
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -184
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3141
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -231
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
package/dist/config/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AccessControlledDB, AccessControl, FieldAccess } from '../access/types.js';
|
|
2
|
+
import type { GeneratedTables } from '../contract/dependencies.js';
|
|
2
3
|
import type { FilterSpec } from '../filter/types.js';
|
|
3
4
|
import type { z } from 'zod';
|
|
5
|
+
import type { PostgresOptionsBase, PostgresOptions } from '@prisma/orm-postgres/runtime';
|
|
4
6
|
export type FieldType = 'text' | 'integer' | 'checkbox' | 'timestamp' | 'password' | 'select' | 'relationship' | string;
|
|
5
7
|
/**
|
|
6
8
|
* Field-level hook argument types (exported for user annotations)
|
|
@@ -13,7 +15,7 @@ export type FieldResolveInputHookArgs<TTypeInfo extends TypeInfo, TFieldKey exte
|
|
|
13
15
|
inputData: TTypeInfo['inputs']['create'];
|
|
14
16
|
item: undefined;
|
|
15
17
|
resolvedData: TTypeInfo['inputs']['create'];
|
|
16
|
-
context: import('../
|
|
18
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
17
19
|
} | {
|
|
18
20
|
listKey: string;
|
|
19
21
|
fieldKey: TFieldKey;
|
|
@@ -21,7 +23,7 @@ export type FieldResolveInputHookArgs<TTypeInfo extends TypeInfo, TFieldKey exte
|
|
|
21
23
|
inputData: TTypeInfo['inputs']['update'];
|
|
22
24
|
item: TTypeInfo['item'];
|
|
23
25
|
resolvedData: TTypeInfo['inputs']['update'];
|
|
24
|
-
context: import('../
|
|
26
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
25
27
|
};
|
|
26
28
|
/** Arguments for {@link FieldHooks.validate} (and its deprecated `validateInput` alias). */
|
|
27
29
|
export type FieldValidateHookArgs<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = {
|
|
@@ -31,7 +33,7 @@ export type FieldValidateHookArgs<TTypeInfo extends TypeInfo, TFieldKey extends
|
|
|
31
33
|
inputData: TTypeInfo['inputs']['create'];
|
|
32
34
|
item: undefined;
|
|
33
35
|
resolvedData: TTypeInfo['inputs']['create'];
|
|
34
|
-
context: import('../
|
|
36
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
35
37
|
addValidationError: (msg: string) => void;
|
|
36
38
|
} | {
|
|
37
39
|
listKey: string;
|
|
@@ -40,14 +42,14 @@ export type FieldValidateHookArgs<TTypeInfo extends TypeInfo, TFieldKey extends
|
|
|
40
42
|
inputData: TTypeInfo['inputs']['update'];
|
|
41
43
|
item: TTypeInfo['item'];
|
|
42
44
|
resolvedData: TTypeInfo['inputs']['update'];
|
|
43
|
-
context: import('../
|
|
45
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
44
46
|
addValidationError: (msg: string) => void;
|
|
45
47
|
} | {
|
|
46
48
|
listKey: string;
|
|
47
49
|
fieldKey: TFieldKey;
|
|
48
50
|
operation: 'delete';
|
|
49
51
|
item: TTypeInfo['item'];
|
|
50
|
-
context: import('../
|
|
52
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
51
53
|
addValidationError: (msg: string) => void;
|
|
52
54
|
};
|
|
53
55
|
/** Arguments for {@link FieldHooks.beforeOperation}. */
|
|
@@ -57,7 +59,7 @@ export type FieldBeforeOperationHookArgs<TTypeInfo extends TypeInfo, TFieldKey e
|
|
|
57
59
|
operation: 'create';
|
|
58
60
|
inputData: TTypeInfo['inputs']['create'];
|
|
59
61
|
resolvedData: TTypeInfo['inputs']['create'];
|
|
60
|
-
context: import('../
|
|
62
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
61
63
|
} | {
|
|
62
64
|
listKey: string;
|
|
63
65
|
fieldKey: TFieldKey;
|
|
@@ -65,13 +67,13 @@ export type FieldBeforeOperationHookArgs<TTypeInfo extends TypeInfo, TFieldKey e
|
|
|
65
67
|
inputData: TTypeInfo['inputs']['update'];
|
|
66
68
|
item: TTypeInfo['item'];
|
|
67
69
|
resolvedData: TTypeInfo['inputs']['update'];
|
|
68
|
-
context: import('../
|
|
70
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
69
71
|
} | {
|
|
70
72
|
listKey: string;
|
|
71
73
|
fieldKey: TFieldKey;
|
|
72
74
|
operation: 'delete';
|
|
73
75
|
item: TTypeInfo['item'];
|
|
74
|
-
context: import('../
|
|
76
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
75
77
|
};
|
|
76
78
|
/** Arguments for {@link FieldHooks.afterOperation}. */
|
|
77
79
|
export type FieldAfterOperationHookArgs<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = {
|
|
@@ -81,7 +83,7 @@ export type FieldAfterOperationHookArgs<TTypeInfo extends TypeInfo, TFieldKey ex
|
|
|
81
83
|
inputData: TTypeInfo['inputs']['create'];
|
|
82
84
|
item: TTypeInfo['item'];
|
|
83
85
|
resolvedData: TTypeInfo['inputs']['create'];
|
|
84
|
-
context: import('../
|
|
86
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
85
87
|
} | {
|
|
86
88
|
listKey: string;
|
|
87
89
|
fieldKey: TFieldKey;
|
|
@@ -90,13 +92,13 @@ export type FieldAfterOperationHookArgs<TTypeInfo extends TypeInfo, TFieldKey ex
|
|
|
90
92
|
originalItem: TTypeInfo['item'];
|
|
91
93
|
item: TTypeInfo['item'];
|
|
92
94
|
resolvedData: TTypeInfo['inputs']['update'];
|
|
93
|
-
context: import('../
|
|
95
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
94
96
|
} | {
|
|
95
97
|
listKey: string;
|
|
96
98
|
fieldKey: TFieldKey;
|
|
97
99
|
operation: 'delete';
|
|
98
100
|
originalItem: TTypeInfo['item'];
|
|
99
|
-
context: import('../
|
|
101
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
100
102
|
};
|
|
101
103
|
/**
|
|
102
104
|
* Arguments for field-level beforeTransaction hook (#590 / ADR-0010).
|
|
@@ -115,20 +117,20 @@ export type FieldBeforeTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
115
117
|
fieldKey: TFieldKey;
|
|
116
118
|
operation: 'create';
|
|
117
119
|
inputData: TTypeInfo['inputs']['create'];
|
|
118
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
120
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
119
121
|
} | {
|
|
120
122
|
listKey: string;
|
|
121
123
|
fieldKey: TFieldKey;
|
|
122
124
|
operation: 'update';
|
|
123
125
|
inputData: TTypeInfo['inputs']['update'];
|
|
124
126
|
item: TTypeInfo['item'] | undefined;
|
|
125
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
127
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
126
128
|
} | {
|
|
127
129
|
listKey: string;
|
|
128
130
|
fieldKey: TFieldKey;
|
|
129
131
|
operation: 'delete';
|
|
130
132
|
item: TTypeInfo['item'] | undefined;
|
|
131
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
133
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
132
134
|
};
|
|
133
135
|
/**
|
|
134
136
|
* Arguments for field-level afterTransaction hook (#590 / ADR-0010).
|
|
@@ -142,6 +144,11 @@ export type FieldBeforeTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
142
144
|
* transaction, and these hooks fire at per-(list, operation) granularity, not
|
|
143
145
|
* per record. For per-record nested compensation use the in-transaction
|
|
144
146
|
* `afterOperation` (which receives the correct nested `item`).
|
|
147
|
+
* - An update whose resolved payload is empty still reports `committed`, with
|
|
148
|
+
* `item` equal to `originalItem`; compare the two to skip a no-op.
|
|
149
|
+
* - `item` is the raw persisted row, the same one `afterOperation` receives —
|
|
150
|
+
* not the session's Field Visibility projection: columns the session cannot
|
|
151
|
+
* read are present and `resolveOutput` transforms are not applied.
|
|
145
152
|
* - `rolled-back`: NO persisted `item`; the hook gets `inputData` and the
|
|
146
153
|
* `error` that caused the rollback so it can compensate for whatever
|
|
147
154
|
* `beforeTransaction` did externally.
|
|
@@ -154,7 +161,7 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
154
161
|
inputData: TTypeInfo['inputs']['create'];
|
|
155
162
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
156
163
|
item: TTypeInfo['item'] | undefined;
|
|
157
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
164
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
158
165
|
} | {
|
|
159
166
|
listKey: string;
|
|
160
167
|
fieldKey: TFieldKey;
|
|
@@ -162,7 +169,7 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
162
169
|
status: 'rolled-back';
|
|
163
170
|
inputData: TTypeInfo['inputs']['create'];
|
|
164
171
|
error: unknown;
|
|
165
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
172
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
166
173
|
} | {
|
|
167
174
|
listKey: string;
|
|
168
175
|
fieldKey: TFieldKey;
|
|
@@ -173,7 +180,7 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
173
180
|
originalItem: TTypeInfo['item'] | undefined;
|
|
174
181
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
175
182
|
item: TTypeInfo['item'] | undefined;
|
|
176
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
183
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
177
184
|
} | {
|
|
178
185
|
listKey: string;
|
|
179
186
|
fieldKey: TFieldKey;
|
|
@@ -182,7 +189,7 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
182
189
|
inputData: TTypeInfo['inputs']['update'];
|
|
183
190
|
originalItem: TTypeInfo['item'] | undefined;
|
|
184
191
|
error: unknown;
|
|
185
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
192
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
186
193
|
} | {
|
|
187
194
|
listKey: string;
|
|
188
195
|
fieldKey: TFieldKey;
|
|
@@ -190,7 +197,7 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
190
197
|
status: 'committed';
|
|
191
198
|
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
192
199
|
originalItem: TTypeInfo['item'] | undefined;
|
|
193
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
200
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
194
201
|
} | {
|
|
195
202
|
listKey: string;
|
|
196
203
|
fieldKey: TFieldKey;
|
|
@@ -198,16 +205,21 @@ export type FieldAfterTransactionHookArgs<TTypeInfo extends TypeInfo, TFieldKey
|
|
|
198
205
|
status: 'rolled-back';
|
|
199
206
|
originalItem: TTypeInfo['item'] | undefined;
|
|
200
207
|
error: unknown;
|
|
201
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
208
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
202
209
|
};
|
|
203
210
|
/** Arguments for {@link FieldHooks.resolveOutput}. */
|
|
204
211
|
export type FieldResolveOutputHookArgs<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = {
|
|
205
212
|
operation: 'query';
|
|
206
|
-
value: GetFieldValueType<TTypeInfo
|
|
207
|
-
|
|
213
|
+
value: GetFieldValueType<TTypeInfo, TFieldKey>;
|
|
214
|
+
/**
|
|
215
|
+
* Exactly the field's declared dependency set plus the list's system
|
|
216
|
+
* fields — what the runtime fetches for it (ADR-0051). Reading a column
|
|
217
|
+
* this field did not declare in `needs` is a compile error.
|
|
218
|
+
*/
|
|
219
|
+
item: FieldNeedsItem<TTypeInfo, TFieldKey>;
|
|
208
220
|
listKey: string;
|
|
209
221
|
fieldName: TFieldKey;
|
|
210
|
-
context: import('../access/types.js').AccessContext<TTypeInfo
|
|
222
|
+
context: import('../access/types.js').AccessContext<HookDb<TTypeInfo>>;
|
|
211
223
|
};
|
|
212
224
|
/**
|
|
213
225
|
* Field-level hooks for data transformation and side effects
|
|
@@ -246,7 +258,7 @@ export type FieldHooks<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<T
|
|
|
246
258
|
* }
|
|
247
259
|
* ```
|
|
248
260
|
*/
|
|
249
|
-
resolveInput?: (args: FieldResolveInputHookArgs<TTypeInfo, TFieldKey>) => Promise<GetFieldValueType<TTypeInfo
|
|
261
|
+
resolveInput?: (args: FieldResolveInputHookArgs<TTypeInfo, TFieldKey>) => Promise<GetFieldValueType<TTypeInfo, TFieldKey> | undefined> | GetFieldValueType<TTypeInfo, TFieldKey> | undefined;
|
|
250
262
|
/**
|
|
251
263
|
* Validate field value after resolveInput
|
|
252
264
|
* Called during create/update operations after resolveInput hooks but before database write
|
|
@@ -345,6 +357,8 @@ export type FieldHooks<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<T
|
|
|
345
357
|
* }
|
|
346
358
|
* }
|
|
347
359
|
* ```
|
|
360
|
+
*
|
|
361
|
+
* A throw is reported to `onAfterTransactionError`, never propagated.
|
|
348
362
|
*/
|
|
349
363
|
afterTransaction?: (args: FieldAfterTransactionHookArgs<TTypeInfo, TFieldKey>) => Promise<void> | void;
|
|
350
364
|
/**
|
|
@@ -365,70 +379,42 @@ export type FieldHooks<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<T
|
|
|
365
379
|
* return value
|
|
366
380
|
* }
|
|
367
381
|
*
|
|
368
|
-
* // Async example (e.g., for virtual fields that query the database)
|
|
382
|
+
* // Async example (e.g., for virtual fields that query the database).
|
|
383
|
+
* // `item.relatedId` requires the field to declare `needs: ['relatedId']` —
|
|
384
|
+
* // a hook's `item` carries only its own declared dependency set.
|
|
369
385
|
* resolveOutput: async ({ item, context }) => {
|
|
370
|
-
* const related = await context.db.
|
|
386
|
+
* const related = await context.db.OtherList.where({ id: item.relatedId }).first()
|
|
371
387
|
* return related?.name
|
|
372
388
|
* }
|
|
373
389
|
* ```
|
|
374
390
|
*/
|
|
375
|
-
resolveOutput?: (args: FieldResolveOutputHookArgs<TTypeInfo, TFieldKey>) => GetFieldValueType<TTypeInfo
|
|
391
|
+
resolveOutput?: (args: FieldResolveOutputHookArgs<TTypeInfo, TFieldKey>) => GetFieldValueType<TTypeInfo, TFieldKey> | undefined | Promise<GetFieldValueType<TTypeInfo, TFieldKey> | undefined>;
|
|
376
392
|
};
|
|
377
|
-
|
|
378
|
-
* Configuration for Prisma result extensions
|
|
379
|
-
* Allows fields to transform their runtime values and types in query results
|
|
380
|
-
*
|
|
381
|
-
* Runtime transformation is delegated to the field's resolveOutput hook.
|
|
382
|
-
* This config only specifies the TypeScript output type for generated types.
|
|
383
|
-
*/
|
|
384
|
-
export type ResultExtensionConfig = {
|
|
385
|
-
/**
|
|
386
|
-
* The TypeScript type to use in query result types
|
|
387
|
-
* This is a type expression like: "import('@opensaas/stack-core').HashedPassword"
|
|
388
|
-
*
|
|
389
|
-
* The actual runtime transformation is performed by the field's resolveOutput hook.
|
|
390
|
-
* The Prisma extension will automatically call the hook if it exists.
|
|
391
|
-
*
|
|
392
|
-
* @example "import('@opensaas/stack-core').HashedPassword"
|
|
393
|
-
* @example "import('./types').MyCustomType"
|
|
394
|
-
*/
|
|
395
|
-
outputType: string;
|
|
396
|
-
/**
|
|
397
|
-
* @deprecated No longer used. Runtime transformations are handled by resolveOutput hooks.
|
|
398
|
-
* This field is kept for backwards compatibility but should not be used in new code.
|
|
399
|
-
*/
|
|
400
|
-
compute?: string;
|
|
401
|
-
};
|
|
402
|
-
export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
393
|
+
export type BaseFieldConfig<TTypeInfo extends TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = {
|
|
403
394
|
type: string;
|
|
404
395
|
access?: FieldAccess<TTypeInfo['item'], TTypeInfo['inputs']['create'], TTypeInfo['inputs']['update']>;
|
|
405
396
|
defaultValue?: unknown;
|
|
406
|
-
hooks?: FieldHooks<TTypeInfo>;
|
|
397
|
+
hooks?: FieldHooks<TTypeInfo, TKey>;
|
|
407
398
|
/**
|
|
408
399
|
* Marks this field as virtual — not stored in database, computed via
|
|
409
|
-
* `resolveInput`/`resolveOutput` hooks, and excluded from the
|
|
410
|
-
*
|
|
400
|
+
* `resolveInput`/`resolveOutput` hooks, and excluded from the contract
|
|
401
|
+
* and input types. Computed whenever the read is going to return
|
|
411
402
|
* it (ADR-0027) — not gated behind an explicit `include`/selection.
|
|
412
403
|
*/
|
|
413
404
|
virtual?: boolean;
|
|
414
|
-
/**
|
|
415
|
-
* Prisma result extension configuration
|
|
416
|
-
* Transforms field values and types in query results using Prisma's native extension system
|
|
417
|
-
*/
|
|
418
|
-
resultExtension?: ResultExtensionConfig;
|
|
419
405
|
/**
|
|
420
406
|
* Database configuration
|
|
421
407
|
*/
|
|
422
408
|
db?: {
|
|
423
409
|
/**
|
|
424
|
-
* Custom database column name
|
|
425
|
-
*
|
|
410
|
+
* Custom database column name. Carried on the contract column as `map`,
|
|
411
|
+
* when it differs from the field's own name.
|
|
426
412
|
* @example
|
|
427
413
|
* ```typescript
|
|
428
414
|
* fields: {
|
|
429
415
|
* firstName: text({ db: { map: 'first_name' } })
|
|
430
416
|
* }
|
|
431
|
-
* //
|
|
417
|
+
* // Contract: the firstName column maps to 'first_name'
|
|
432
418
|
* ```
|
|
433
419
|
*/
|
|
434
420
|
map?: string;
|
|
@@ -448,32 +434,33 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
448
434
|
* phoneNumber: text({
|
|
449
435
|
* db: { isNullable: false }
|
|
450
436
|
* })
|
|
451
|
-
* //
|
|
437
|
+
* // Contract: the phoneNumber column is non-nullable
|
|
452
438
|
*
|
|
453
439
|
* // DB nullable (explicit), regardless of validation
|
|
454
440
|
* lastMessagePreview: text({
|
|
455
441
|
* db: { isNullable: true }
|
|
456
442
|
* })
|
|
457
|
-
* //
|
|
443
|
+
* // Contract: the lastMessagePreview column is nullable
|
|
458
444
|
* }
|
|
459
445
|
* ```
|
|
460
446
|
*/
|
|
461
447
|
isNullable?: boolean;
|
|
462
448
|
/**
|
|
463
|
-
* Override the native database type for the column.
|
|
464
|
-
*
|
|
465
|
-
*
|
|
449
|
+
* Override the native database type for the column. Folded into the
|
|
450
|
+
* contract column's own type constructor (`ColumnTypeDescriptor`), so the
|
|
451
|
+
* column is typed by `nativeType` directly rather than the field's
|
|
452
|
+
* default. The available types depend on your database provider.
|
|
466
453
|
*
|
|
467
454
|
* @example
|
|
468
455
|
* ```typescript
|
|
469
456
|
* // PostgreSQL: use TEXT instead of VARCHAR
|
|
470
457
|
* fields: {
|
|
471
458
|
* description: text({ db: { nativeType: 'Text' } })
|
|
472
|
-
* //
|
|
459
|
+
* // Contract: description is a Text column
|
|
473
460
|
*
|
|
474
461
|
* // PostgreSQL: use SMALLINT instead of INT
|
|
475
462
|
* count: integer({ db: { nativeType: 'SmallInt' } })
|
|
476
|
-
* //
|
|
463
|
+
* // Contract: count is a SmallInt column
|
|
477
464
|
* }
|
|
478
465
|
* ```
|
|
479
466
|
*/
|
|
@@ -557,54 +544,6 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
557
544
|
* @param operation - Whether this is a create or update operation
|
|
558
545
|
*/
|
|
559
546
|
getZodSchema?: (fieldName: string, operation: 'create' | 'update') => z.ZodTypeAny;
|
|
560
|
-
/**
|
|
561
|
-
* Get Prisma type and modifiers for schema generation
|
|
562
|
-
* @param fieldName - The name of the field (for generating modifiers)
|
|
563
|
-
* @param provider - Optional database provider ('sqlite', 'postgresql', 'mysql', etc.)
|
|
564
|
-
* @param listName - Optional list name (used for generating enum type names)
|
|
565
|
-
* @param keystoneCompat - Whether Keystone-compat mode is enabled (db.keystoneCompat).
|
|
566
|
-
* When true, non-null text columns without an explicit defaultValue emit
|
|
567
|
-
* `@default("")` to match Keystone 6's implicit empty-string text default.
|
|
568
|
-
* @returns Prisma type string, optional modifiers, optional enum values, and
|
|
569
|
-
* an optional block-level index request
|
|
570
|
-
*/
|
|
571
|
-
getPrismaType?: (fieldName: string, provider?: string, listName?: string, keystoneCompat?: boolean) => {
|
|
572
|
-
type: string;
|
|
573
|
-
modifiers?: string;
|
|
574
|
-
/**
|
|
575
|
-
* If set, this field requires a Prisma enum definition with these values.
|
|
576
|
-
* The enum name is the value of `type`.
|
|
577
|
-
*/
|
|
578
|
-
enumValues?: string[];
|
|
579
|
-
/**
|
|
580
|
-
* If set, this field requires a block-level index on the owning model:
|
|
581
|
-
* `@@index([fieldName])` for `true`, `@@unique([fieldName])` for
|
|
582
|
-
* `'unique'`. `false` and `undefined` both mean "no index".
|
|
583
|
-
*
|
|
584
|
-
* Prisma has no field-level `@index` attribute — a non-unique index can
|
|
585
|
-
* ONLY be expressed as the model-level `@@index([...])` — so a field that
|
|
586
|
-
* wants one has to ask for it out-of-line rather than appending to
|
|
587
|
-
* {@link modifiers}. (A unique index has both forms available; the
|
|
588
|
-
* built-in scalars keep emitting the inline `@unique` modifier for that
|
|
589
|
-
* case, so this channel carries only what cannot be written inline.)
|
|
590
|
-
*
|
|
591
|
-
* Same shape as {@link PrismaRelationResult.foreignKeyIndex}, which is how
|
|
592
|
-
* relationship fields have always emitted their foreign-key indexes. The
|
|
593
|
-
* generator handles both through one emit pass, so the field stays the
|
|
594
|
-
* authority on whether it can be indexed by name at all — a multi-column
|
|
595
|
-
* field (see {@link getPrismaColumns}) has no single column matching its
|
|
596
|
-
* field name and can decline, or name a real column of its own.
|
|
597
|
-
*/
|
|
598
|
-
index?: boolean | 'unique';
|
|
599
|
-
};
|
|
600
|
-
/**
|
|
601
|
-
* Get TypeScript type information for type generation
|
|
602
|
-
* @returns TypeScript type string and optionality
|
|
603
|
-
*/
|
|
604
|
-
getTypeScriptType?: () => {
|
|
605
|
-
type: string;
|
|
606
|
-
optional: boolean;
|
|
607
|
-
};
|
|
608
547
|
/**
|
|
609
548
|
* Declare this field's filtering capability — its {@link FilterSpec} — for the
|
|
610
549
|
* admin UI's Filter builder (ADR-0017). Optional and additive: a field that
|
|
@@ -612,8 +551,8 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
612
551
|
* hasn't adopted filtering) is simply not filterable and never suggested, so
|
|
613
552
|
* absence degrades gracefully everywhere.
|
|
614
553
|
*
|
|
615
|
-
* Self-contained, like {@link
|
|
616
|
-
* delegates to each field's spec rather than switching on field type. The
|
|
554
|
+
* Self-contained, like {@link getContractField} and friends — the filter
|
|
555
|
+
* engine delegates to each field's spec rather than switching on field type. The
|
|
617
556
|
* returned `toCondition` mapper must stay pure (no DB/Prisma imports); its
|
|
618
557
|
* output is ANDed with the access filter through the secured context.
|
|
619
558
|
*
|
|
@@ -625,49 +564,11 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
625
564
|
*/
|
|
626
565
|
getFilterSpec?: (fieldName: string, listKey: string, config: OpenSaasConfig) => FilterSpec | undefined;
|
|
627
566
|
/**
|
|
628
|
-
*
|
|
629
|
-
* @
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
* The type/value names to import
|
|
634
|
-
* e.g., ['StoredEmbedding', 'EmbeddingMetadata']
|
|
635
|
-
*/
|
|
636
|
-
names: string[];
|
|
637
|
-
/**
|
|
638
|
-
* The module to import from
|
|
639
|
-
* e.g., '@opensaas/stack-rag'
|
|
640
|
-
*/
|
|
641
|
-
from: string;
|
|
642
|
-
/**
|
|
643
|
-
* Whether this is a type-only import
|
|
644
|
-
* @default true
|
|
645
|
-
*/
|
|
646
|
-
typeOnly?: boolean;
|
|
647
|
-
}>;
|
|
648
|
-
/**
|
|
649
|
-
* Multi-column Prisma emission.
|
|
650
|
-
*
|
|
651
|
-
* Most scalar fields back a single Prisma column via {@link getPrismaType}.
|
|
652
|
-
* A field that maps onto SEVERAL physical columns (e.g. the storage
|
|
653
|
-
* `image()`/`file()` fields in multi-column / Keystone-parity mode — see
|
|
654
|
-
* ADR-0006) implements this instead: it returns one descriptor per column,
|
|
655
|
-
* each becoming its own line in the generated model. When present, the
|
|
656
|
-
* generator emits these lines and skips the single-column `getPrismaType`
|
|
657
|
-
* path. The field itself owns the column layout — the generator stays a
|
|
658
|
-
* neutral coordinator (no field-type switches), mirroring how relationship
|
|
659
|
-
* fields emit FK + relation lines through `getPrismaRelation`.
|
|
660
|
-
*
|
|
661
|
-
* @param fieldName - The field's config key (used to derive default column names)
|
|
662
|
-
* @returns One descriptor per physical column, or `undefined` to fall back to
|
|
663
|
-
* the single-column `getPrismaType` path.
|
|
664
|
-
*/
|
|
665
|
-
getPrismaColumns?: (fieldName: string) => MultiColumnPrismaResult[] | undefined;
|
|
666
|
-
/**
|
|
667
|
-
* The physical Prisma column names this field owns when it spans multiple
|
|
668
|
-
* columns (see {@link getPrismaColumns}). The read path uses this to strip the
|
|
669
|
-
* raw per-part columns from query results so only the assembled logical value
|
|
670
|
-
* (produced by {@link assembleColumns}) is exposed.
|
|
567
|
+
* The physical column names this field owns when its
|
|
568
|
+
* {@link getContractField} descriptor is a multi-column one (`kind:
|
|
569
|
+
* 'columns'`). The read path uses this to strip the raw per-part columns
|
|
570
|
+
* from query results so only the assembled logical value (produced by
|
|
571
|
+
* {@link assembleColumns}) is exposed.
|
|
671
572
|
*
|
|
672
573
|
* @param fieldName - The field's config key
|
|
673
574
|
*/
|
|
@@ -693,34 +594,99 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
693
594
|
*/
|
|
694
595
|
splitColumns?: (fieldName: string, value: unknown) => Record<string, unknown>;
|
|
695
596
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
597
|
+
* Describe what this field contributes to the contract (ADR-0040,
|
|
598
|
+
* ADR-0049): its stored column(s) as a pack-qualified type constructor with
|
|
599
|
+
* native type, nullability and column mapping; for a relationship, the
|
|
600
|
+
* relation and the foreign-key column this side owns; for a virtual field,
|
|
601
|
+
* nothing.
|
|
602
|
+
*
|
|
603
|
+
* @param fieldName - The field's config key
|
|
604
|
+
* @param listKey - The owning list's key
|
|
605
|
+
* @param config - The full config (a relationship resolves its target and
|
|
606
|
+
* foreign-key ownership from it)
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* getContractField: (fieldName) => ({
|
|
611
|
+
* kind: 'column',
|
|
612
|
+
* name: fieldName,
|
|
613
|
+
* type: { pack: 'pgvector', type: 'Vector', args: [1536] },
|
|
614
|
+
* nullable: true,
|
|
615
|
+
* })
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
getContractField?: (fieldName: string, listKey: string, config: OpenSaasConfig) => ContractFieldDescriptor;
|
|
619
|
+
/**
|
|
620
|
+
* Describe this field's stored vector column, when it has one: the column
|
|
621
|
+
* `nearest()` measures against and the distance function that measurement
|
|
622
|
+
* is made with (ADR-0045). A field that does not answer this is not
|
|
623
|
+
* searchable, which is what makes `nearest('title', …)` a refusal rather
|
|
624
|
+
* than a query the database rejects.
|
|
625
|
+
*
|
|
626
|
+
* @param fieldName - The field's config key
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* ```typescript
|
|
630
|
+
* getVectorColumn: (fieldName) => ({
|
|
631
|
+
* column: fieldName,
|
|
632
|
+
* dimensions: 1536,
|
|
633
|
+
* distanceFunction: 'cosine',
|
|
634
|
+
* })
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
getVectorColumn?: (fieldName: string) => VectorColumnDescriptor;
|
|
638
|
+
/**
|
|
639
|
+
* Set to `false` to keep this field out of the predicate, order and distinct
|
|
640
|
+
* vocabulary: a `where`, `orderBy`, `distinct` or `distinctOn` naming it is
|
|
641
|
+
* refused exactly as an undeclared column is. The field is still readable
|
|
642
|
+
* and writable under its own access rules. `password()` sets this so a hash
|
|
643
|
+
* cannot be extracted byte-by-byte with `contains`/`startsWith`/`gt`.
|
|
644
|
+
*/
|
|
645
|
+
isFilterable?: boolean;
|
|
646
|
+
/**
|
|
647
|
+
* The TypeScript type a read returns for this field, when it differs from
|
|
648
|
+
* the column's codec type (ADR-0052). Required on a virtual field, where it
|
|
649
|
+
* is the contract remainder's computed entry; on a stored field it is an
|
|
650
|
+
* override — `password` reads as `HashedPassword` over a text column —
|
|
651
|
+
* and absence means the codec's own type.
|
|
652
|
+
*
|
|
653
|
+
* @example "import('@opensaas/stack-core/internal').HashedPassword"
|
|
654
|
+
* @example { value: Decimal, from: 'decimal.js' }
|
|
655
|
+
*/
|
|
656
|
+
outputType?: TypeDescriptor;
|
|
657
|
+
/**
|
|
658
|
+
* The TypeScript type a write accepts for this field, when it differs from
|
|
659
|
+
* the column's codec input type (ADR-0052) — `calendarDay` accepts a
|
|
660
|
+
* `YYYY-MM-DD` string where the codec would take more. Absence means the
|
|
661
|
+
* codec's own input type.
|
|
662
|
+
*/
|
|
663
|
+
inputType?: TypeDescriptor;
|
|
664
|
+
/**
|
|
665
|
+
* Declares the immediate sibling columns and relations this field's
|
|
666
|
+
* `resolveOutput` hook cannot compute without (ADR-0025, widened to columns
|
|
667
|
+
* by ADR-0051 — the "Declared dependency" glossary entry in `CONTEXT.md`).
|
|
668
|
+
* The read fetches each declared dependency wherever this field is
|
|
669
|
+
* computed — at the root of a read and at every nested level alike — and
|
|
670
|
+
* scopes a relation through the Access Filter exactly like a caller-named
|
|
671
|
+
* one: a dependency a session cannot query is not fetched, and the hook
|
|
672
|
+
* sees nothing in its place.
|
|
703
673
|
*
|
|
704
674
|
* A declared dependency is private plumbing, not an implicit `include`: it
|
|
705
675
|
* is stripped from the result unless the caller named it too, so declaring
|
|
706
676
|
* or removing one changes this field's implementation, never the shape of
|
|
707
677
|
* every read of the list.
|
|
708
678
|
*
|
|
709
|
-
* Names immediate relations
|
|
710
|
-
*
|
|
711
|
-
*
|
|
679
|
+
* Names stored columns and immediate relations on the same list only — no
|
|
680
|
+
* dotted paths, and never a computed field. A declaration on a field with
|
|
681
|
+
* no `resolveOutput` hook is dead config and fails `pnpm generate`.
|
|
712
682
|
*
|
|
713
683
|
* Typed as a plain `string[]`, not narrowed to this list's own relation
|
|
714
|
-
* keys
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
* breaking assignability for every such field regardless of whether it
|
|
721
|
-
* uses `needs` at all. A misspelled or non-relation entry is instead
|
|
722
|
-
* caught by `pnpm generate` (`validateNeedsDeclarations`), which has no
|
|
723
|
-
* such constraint.
|
|
684
|
+
* keys, unlike {@link BaseFieldConfig}'s own `TKey` (issue #1306): a
|
|
685
|
+
* `needs` entry names a DIFFERENT field on the SAME list, so narrowing it
|
|
686
|
+
* would require threading that field's key too, for no reader-facing
|
|
687
|
+
* benefit `pnpm generate` (`validateNeedsDeclarations`) doesn't already
|
|
688
|
+
* provide by rejecting a misspelled or non-relation entry at generate
|
|
689
|
+
* time.
|
|
724
690
|
*
|
|
725
691
|
* @example
|
|
726
692
|
* ```typescript
|
|
@@ -737,24 +703,165 @@ export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
|
737
703
|
needs?: string[];
|
|
738
704
|
};
|
|
739
705
|
/**
|
|
740
|
-
* A
|
|
741
|
-
*
|
|
706
|
+
* A JSON-serialisable literal. What a column default can hold, and the
|
|
707
|
+
* argument vocabulary of a {@link ColumnTypeDescriptor} — the Contract module
|
|
708
|
+
* is fully literal (ADR-0040), so nothing that cannot be re-emitted as source
|
|
709
|
+
* belongs here.
|
|
742
710
|
*/
|
|
743
|
-
export type
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
711
|
+
export type ContractLiteral = string | number | boolean | null | ContractLiteral[] | {
|
|
712
|
+
[key: string]: ContractLiteral;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* A column's type as a pack-qualified type constructor —
|
|
716
|
+
* `type.<pack>.<type>(...args)` in the Contract module (ADR-0049). Core's
|
|
717
|
+
* scalars live in the `pg` pack (`{ pack: 'pg', type: 'text' }`,
|
|
718
|
+
* `{ pack: 'pg', type: 'decimal', args: [18, 4] }`); a field over an extension
|
|
719
|
+
* pack names it (`{ pack: 'pgvector', type: 'Vector', args: [1536] }`), and the
|
|
720
|
+
* generator refuses a config that uses a pack `db.extensions` does not declare.
|
|
721
|
+
*/
|
|
722
|
+
export type ColumnTypeDescriptor = {
|
|
723
|
+
/** The pack that owns the type constructor — `'pg'` for core's scalars, else an extension pack's `name`. */
|
|
724
|
+
pack: string;
|
|
725
|
+
/** The type constructor's name within the pack. */
|
|
747
726
|
type: string;
|
|
727
|
+
/** Positional arguments to the constructor (a length, a precision/scale pair, a dimension). */
|
|
728
|
+
args?: ContractLiteral[];
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* A column's default. `'literal'` carries a value the Contract module emits as
|
|
732
|
+
* source; `'now'` is the database clock at insert; `'sql'` is a database-side
|
|
733
|
+
* expression, for a column whose live default the verifier only recognises in
|
|
734
|
+
* its normalised SQL form. A `bigint` column's default
|
|
735
|
+
* is carried as its decimal string — `42n`, `42` and `'42'` all become `'42'`,
|
|
736
|
+
* the form the generator writes into `@default`. A default that is not a
|
|
737
|
+
* JSON literal (a `Date`, a `Decimal`, a `Map`) is refused by the builder.
|
|
738
|
+
*/
|
|
739
|
+
export type ColumnDefaultDescriptor = {
|
|
740
|
+
kind: 'literal';
|
|
741
|
+
value: ContractLiteral;
|
|
742
|
+
} | {
|
|
743
|
+
kind: 'now';
|
|
744
|
+
} | {
|
|
745
|
+
kind: 'sql';
|
|
746
|
+
expression: string;
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* One stored column a field contributes to the contract.
|
|
750
|
+
*/
|
|
751
|
+
export type ContractColumnDescriptor = {
|
|
752
|
+
/** The model field name — the property the column is declared as. Equals the field key for a single-column field. */
|
|
753
|
+
name: string;
|
|
754
|
+
/** The column's type constructor. */
|
|
755
|
+
type: ColumnTypeDescriptor;
|
|
756
|
+
/** A native-type override for the column (`db.nativeType`), when the constructor's default is not wanted. */
|
|
757
|
+
nativeType?: string;
|
|
758
|
+
/** Whether the column accepts NULL. */
|
|
759
|
+
nullable: boolean;
|
|
760
|
+
/** The physical column name, when it differs from {@link name} (`db.map`). */
|
|
761
|
+
map?: string;
|
|
762
|
+
/** Whether the column carries a unique constraint (`isIndexed: 'unique'`). */
|
|
763
|
+
unique?: boolean;
|
|
764
|
+
/** Whether the column carries a non-unique index (`isIndexed: true`). */
|
|
765
|
+
index?: boolean;
|
|
766
|
+
/** The column's default, when it has one. */
|
|
767
|
+
default?: ColumnDefaultDescriptor;
|
|
768
|
+
/**
|
|
769
|
+
* The native enum this column is typed by, when {@link type} is an enum
|
|
770
|
+
* constructor — the contract declares the enum entity once and the column
|
|
771
|
+
* references it.
|
|
772
|
+
*/
|
|
773
|
+
enum?: {
|
|
774
|
+
name: string;
|
|
775
|
+
values: string[];
|
|
776
|
+
};
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* The foreign-key column a relationship's owning side contributes. The
|
|
780
|
+
* column's type is the referenced list's id type, resolved from that list's
|
|
781
|
+
* `db.idField`.
|
|
782
|
+
*/
|
|
783
|
+
export type ContractForeignKeyDescriptor = {
|
|
784
|
+
/** The model field name of the foreign-key column (`<field>Id`). */
|
|
785
|
+
name: string;
|
|
786
|
+
/** The physical column name, when it differs from {@link name}. */
|
|
787
|
+
map?: string;
|
|
788
|
+
/** Whether the column accepts NULL (`db.isNullable`, default `true`). */
|
|
789
|
+
nullable: boolean;
|
|
790
|
+
/** Whether the column carries a unique constraint — the owning side of a one-to-one. */
|
|
791
|
+
unique: boolean;
|
|
792
|
+
/** Whether the column carries a non-unique index (`isIndexed`, default `true`). */
|
|
793
|
+
index: boolean;
|
|
794
|
+
/** The list and field the column references. */
|
|
795
|
+
references: {
|
|
796
|
+
list: string;
|
|
797
|
+
field: 'id';
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* A relationship field's contract contribution: the relation itself and, on
|
|
802
|
+
* the owning side of a to-one, its foreign-key column.
|
|
803
|
+
*/
|
|
804
|
+
export type ContractRelationDescriptor = {
|
|
805
|
+
kind: 'relation';
|
|
806
|
+
/** The list this field points at. */
|
|
807
|
+
target: string;
|
|
748
808
|
/**
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
809
|
+
* The field on {@link target} that is this relation's other side. Declared
|
|
810
|
+
* (`ref: 'List.field'`) or, for a list-only `ref: 'List'`, synthesised as
|
|
811
|
+
* `from_<List>_<field>` on the target.
|
|
752
812
|
*/
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
813
|
+
inverse: {
|
|
814
|
+
field: string;
|
|
815
|
+
synthetic: boolean;
|
|
816
|
+
};
|
|
817
|
+
/** Whether this side holds many rows. */
|
|
818
|
+
many: boolean;
|
|
819
|
+
/**
|
|
820
|
+
* The foreign-key column this side owns. Absent on a to-many side and on
|
|
821
|
+
* the non-owning side of a one-to-one, which have no column.
|
|
822
|
+
*/
|
|
823
|
+
foreignKey?: ContractForeignKeyDescriptor;
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* What a field contributes to the contract (ADR-0040, ADR-0049):
|
|
827
|
+
*
|
|
828
|
+
* - `'column'` — one stored column; the common scalar case.
|
|
829
|
+
* - `'columns'` — several stored columns owned by one field (the multi-column
|
|
830
|
+
* path ADR-0006 gave storage fields; each entry is its own column).
|
|
831
|
+
* - `'relation'` — a relation and, when this side owns it, a foreign key.
|
|
832
|
+
* - `'computed'` — no storage at all; a virtual field. Its TypeScript face is
|
|
833
|
+
* {@link BaseFieldConfig.outputType}, the contract remainder's computed entry.
|
|
834
|
+
*/
|
|
835
|
+
export type ContractFieldDescriptor = ({
|
|
836
|
+
kind: 'column';
|
|
837
|
+
} & ContractColumnDescriptor) | {
|
|
838
|
+
kind: 'columns';
|
|
839
|
+
columns: ContractColumnDescriptor[];
|
|
840
|
+
} | ContractRelationDescriptor | {
|
|
841
|
+
kind: 'computed';
|
|
756
842
|
};
|
|
757
|
-
|
|
843
|
+
/**
|
|
844
|
+
* How similarity is measured over a vector column. The three pgvector
|
|
845
|
+
* supports, in the spelling the RAG field builder already used: `cosine`
|
|
846
|
+
* (`<=>`), `l2` (`<->`) and `inner_product` (`<#>`, which yields the
|
|
847
|
+
* *negative* inner product — the direction `distanceToScore` hides).
|
|
848
|
+
*/
|
|
849
|
+
export type VectorDistanceFunction = 'cosine' | 'l2' | 'inner_product';
|
|
850
|
+
/**
|
|
851
|
+
* A field's stored vector column, as `nearest()` needs to see it
|
|
852
|
+
* (ADR-0045). The field owns the column, its dimension and the distance
|
|
853
|
+
* function together, because the index's operator class must agree with all
|
|
854
|
+
* three.
|
|
855
|
+
*/
|
|
856
|
+
export type VectorColumnDescriptor = {
|
|
857
|
+
/** The model field name of the vector column. */
|
|
858
|
+
column: string;
|
|
859
|
+
/** The column's declared dimension. A query vector of another length is refused. */
|
|
860
|
+
dimensions: number;
|
|
861
|
+
/** How a distance over this column is measured. */
|
|
862
|
+
distanceFunction: VectorDistanceFunction;
|
|
863
|
+
};
|
|
864
|
+
export type TextField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
758
865
|
type: 'text';
|
|
759
866
|
validation?: {
|
|
760
867
|
isRequired?: boolean;
|
|
@@ -768,7 +875,7 @@ export type TextField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<T
|
|
|
768
875
|
displayMode?: 'input' | 'textarea';
|
|
769
876
|
};
|
|
770
877
|
};
|
|
771
|
-
export type IntegerField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
878
|
+
export type IntegerField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
772
879
|
type: 'integer';
|
|
773
880
|
validation?: {
|
|
774
881
|
isRequired?: boolean;
|
|
@@ -777,7 +884,7 @@ export type IntegerField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfi
|
|
|
777
884
|
};
|
|
778
885
|
isIndexed?: boolean | 'unique';
|
|
779
886
|
};
|
|
780
|
-
export type DecimalField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
887
|
+
export type DecimalField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
781
888
|
type: 'decimal';
|
|
782
889
|
defaultValue?: string;
|
|
783
890
|
precision?: number;
|
|
@@ -797,7 +904,7 @@ export type DecimalField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfi
|
|
|
797
904
|
* string over MCP — `bigint` is not JSON-serialisable, so the MCP handler
|
|
798
905
|
* renders it as a string rather than throwing.
|
|
799
906
|
*/
|
|
800
|
-
export type BigIntField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
907
|
+
export type BigIntField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
801
908
|
type: 'bigInt';
|
|
802
909
|
defaultValue?: bigint | number | string;
|
|
803
910
|
validation?: {
|
|
@@ -807,17 +914,19 @@ export type BigIntField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig
|
|
|
807
914
|
};
|
|
808
915
|
isIndexed?: boolean | 'unique';
|
|
809
916
|
};
|
|
810
|
-
export type CheckboxField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
917
|
+
export type CheckboxField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
811
918
|
type: 'checkbox';
|
|
919
|
+
/** Value filled when the field is omitted on create. Defaults to `false`. */
|
|
920
|
+
defaultValue?: boolean;
|
|
812
921
|
};
|
|
813
|
-
export type TimestampField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
922
|
+
export type TimestampField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
814
923
|
type: 'timestamp';
|
|
815
924
|
defaultValue?: {
|
|
816
925
|
kind: 'now';
|
|
817
926
|
} | Date;
|
|
818
927
|
isIndexed?: boolean | 'unique';
|
|
819
928
|
};
|
|
820
|
-
export type CalendarDayField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
929
|
+
export type CalendarDayField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
821
930
|
type: 'calendarDay';
|
|
822
931
|
defaultValue?: string;
|
|
823
932
|
validation?: {
|
|
@@ -825,7 +934,7 @@ export type CalendarDayField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldC
|
|
|
825
934
|
};
|
|
826
935
|
isIndexed?: boolean | 'unique';
|
|
827
936
|
};
|
|
828
|
-
export type PasswordField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
937
|
+
export type PasswordField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
829
938
|
type: 'password';
|
|
830
939
|
validation?: {
|
|
831
940
|
isRequired?: boolean;
|
|
@@ -853,7 +962,7 @@ export type SelectOption = {
|
|
|
853
962
|
variant?: SelectOptionVariant;
|
|
854
963
|
};
|
|
855
964
|
};
|
|
856
|
-
export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
965
|
+
export type SelectField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
857
966
|
type: 'select';
|
|
858
967
|
options: Array<SelectOption>;
|
|
859
968
|
defaultValue?: string;
|
|
@@ -861,9 +970,10 @@ export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig
|
|
|
861
970
|
/**
|
|
862
971
|
* Whether to store as a native database enum type.
|
|
863
972
|
* - 'string' (default): stores as a plain string/varchar column
|
|
864
|
-
* - 'enum': stores as a
|
|
973
|
+
* - 'enum': stores as a native enum column, declared once in the contract's
|
|
974
|
+
* `enums` and referenced by this column's type
|
|
865
975
|
*
|
|
866
|
-
* Note: enum values must be valid
|
|
976
|
+
* Note: enum values must be valid identifiers (letters, numbers, underscores,
|
|
867
977
|
* starting with a letter) when using 'enum' type.
|
|
868
978
|
*
|
|
869
979
|
* @default 'string'
|
|
@@ -871,11 +981,11 @@ export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig
|
|
|
871
981
|
type?: 'string' | 'enum';
|
|
872
982
|
map?: string;
|
|
873
983
|
/**
|
|
874
|
-
* Force the
|
|
875
|
-
*
|
|
984
|
+
* Force the column to be nullable even when a `defaultValue` is present.
|
|
985
|
+
* By default a select with a `defaultValue` produces a NOT NULL column;
|
|
876
986
|
* set this to `true` for an explicit opt-in to a nullable column with a
|
|
877
|
-
* default
|
|
878
|
-
*
|
|
987
|
+
* default, so that a live column containing NULLs migrates without a NOT
|
|
988
|
+
* NULL failure.
|
|
879
989
|
*
|
|
880
990
|
* @default undefined (NOT NULL when a default is present — unchanged behaviour)
|
|
881
991
|
*
|
|
@@ -887,18 +997,18 @@ export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig
|
|
|
887
997
|
* defaultValue: 'draft',
|
|
888
998
|
* db: { isNullable: true },
|
|
889
999
|
* })
|
|
890
|
-
* //
|
|
1000
|
+
* // Contract: a nullable column with a default of 'draft'
|
|
891
1001
|
* ```
|
|
892
1002
|
*/
|
|
893
1003
|
isNullable?: boolean;
|
|
894
1004
|
/**
|
|
895
|
-
* Override the
|
|
896
|
-
*
|
|
1005
|
+
* Override the native enum type name for native-enum selects (only
|
|
1006
|
+
* applies when `type: 'enum'`). By default the enum is named
|
|
897
1007
|
* `<List><Field>` (e.g. `AccountNoteStatus`); set this to match a live DB
|
|
898
1008
|
* enum type whose name differs (e.g. Keystone's `…Type` suffix).
|
|
899
1009
|
*
|
|
900
|
-
* The custom name is
|
|
901
|
-
*
|
|
1010
|
+
* The custom name is carried on the contract's declared `enums` entry and
|
|
1011
|
+
* every column referencing it.
|
|
902
1012
|
*
|
|
903
1013
|
* @example
|
|
904
1014
|
* ```typescript
|
|
@@ -906,7 +1016,7 @@ export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig
|
|
|
906
1016
|
* options: [{ label: 'Open', value: 'open' }],
|
|
907
1017
|
* db: { type: 'enum', enumName: 'AccountNoteStatusType' },
|
|
908
1018
|
* })
|
|
909
|
-
* //
|
|
1019
|
+
* // Contract: declares enum AccountNoteStatusType and the column references it
|
|
910
1020
|
* ```
|
|
911
1021
|
*/
|
|
912
1022
|
enumName?: string;
|
|
@@ -1007,14 +1117,15 @@ export type RelationshipItemViewConfig = {
|
|
|
1007
1117
|
*/
|
|
1008
1118
|
removeAction?: 'disconnect' | 'delete' | 'none';
|
|
1009
1119
|
};
|
|
1010
|
-
export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
1120
|
+
export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
1011
1121
|
type: 'relationship';
|
|
1012
1122
|
ref: string;
|
|
1013
1123
|
many?: boolean;
|
|
1014
1124
|
/**
|
|
1015
|
-
* Controls whether
|
|
1016
|
-
* Defaults to true for all foreign key fields
|
|
1017
|
-
* Can be set to 'unique' for unique
|
|
1125
|
+
* Controls whether the foreign key column carries a contract-level index
|
|
1126
|
+
* or unique constraint. Defaults to true for all foreign key fields
|
|
1127
|
+
* (matching Keystone behavior). Can be set to 'unique' for a unique
|
|
1128
|
+
* constraint or false to leave the column unindexed.
|
|
1018
1129
|
*
|
|
1019
1130
|
* @default true (for foreign key fields)
|
|
1020
1131
|
*
|
|
@@ -1022,15 +1133,15 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1022
1133
|
* ```typescript
|
|
1023
1134
|
* // Standard indexed foreign key (default)
|
|
1024
1135
|
* author: relationship({ ref: 'User.posts' })
|
|
1025
|
-
* //
|
|
1136
|
+
* // Contract: an index on the authorId column
|
|
1026
1137
|
*
|
|
1027
1138
|
* // Unique foreign key (one-to-one)
|
|
1028
1139
|
* author: relationship({ ref: 'User.posts', isIndexed: 'unique' })
|
|
1029
|
-
* //
|
|
1140
|
+
* // Contract: a unique constraint on the authorId column
|
|
1030
1141
|
*
|
|
1031
1142
|
* // Disable indexing (not recommended, may cause performance issues)
|
|
1032
1143
|
* author: relationship({ ref: 'User.posts', isIndexed: false })
|
|
1033
|
-
* // No index
|
|
1144
|
+
* // No index or constraint on the column
|
|
1034
1145
|
* ```
|
|
1035
1146
|
*/
|
|
1036
1147
|
isIndexed?: boolean | 'unique';
|
|
@@ -1052,8 +1163,8 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1052
1163
|
* ref: 'User.sessions',
|
|
1053
1164
|
* db: { isNullable: false },
|
|
1054
1165
|
* })
|
|
1055
|
-
* //
|
|
1056
|
-
* //
|
|
1166
|
+
* // Contract: the userId column and the user relation are both
|
|
1167
|
+
* // non-nullable (were nullable by default)
|
|
1057
1168
|
* ```
|
|
1058
1169
|
*/
|
|
1059
1170
|
isNullable?: boolean;
|
|
@@ -1079,7 +1190,7 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1079
1190
|
* User: list({
|
|
1080
1191
|
* fields: {
|
|
1081
1192
|
* account: relationship({ ref: 'Account.user', db: { foreignKey: true } })
|
|
1082
|
-
* //
|
|
1193
|
+
* // Contract: a unique accountId column
|
|
1083
1194
|
* }
|
|
1084
1195
|
* })
|
|
1085
1196
|
*
|
|
@@ -1087,7 +1198,7 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1087
1198
|
* User: list({
|
|
1088
1199
|
* fields: {
|
|
1089
1200
|
* account: relationship({ ref: 'Account.user', db: { foreignKey: { map: 'account_id' } } })
|
|
1090
|
-
* //
|
|
1201
|
+
* // Contract: a unique accountId column mapped to 'account_id'
|
|
1091
1202
|
* }
|
|
1092
1203
|
* })
|
|
1093
1204
|
*
|
|
@@ -1101,7 +1212,7 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1101
1212
|
* Post: list({
|
|
1102
1213
|
* fields: {
|
|
1103
1214
|
* category: relationship({ ref: 'Category', db: { foreignKey: { map: 'category_id' } } })
|
|
1104
|
-
* //
|
|
1215
|
+
* // Contract: the categoryId column mapped to 'category_id'
|
|
1105
1216
|
* }
|
|
1106
1217
|
* })
|
|
1107
1218
|
* ```
|
|
@@ -1110,64 +1221,23 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1110
1221
|
map?: string;
|
|
1111
1222
|
};
|
|
1112
1223
|
/**
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
* Prisma will create an implicit join table named _relationName
|
|
1116
|
-
* Only needs to be set on one side of a bidirectional relationship
|
|
1117
|
-
*
|
|
1118
|
-
* @example KeystoneJS-style naming for migration
|
|
1119
|
-
* ```typescript
|
|
1120
|
-
* Lesson: list({
|
|
1121
|
-
* fields: {
|
|
1122
|
-
* teachers: relationship({
|
|
1123
|
-
* ref: 'Teacher.lessons',
|
|
1124
|
-
* many: true,
|
|
1125
|
-
* db: { relationName: 'Lesson_teachers' }
|
|
1126
|
-
* // Prisma creates join table _Lesson_teachers
|
|
1127
|
-
* })
|
|
1128
|
-
* }
|
|
1129
|
-
* })
|
|
1130
|
-
*
|
|
1131
|
-
* Teacher: list({
|
|
1132
|
-
* fields: {
|
|
1133
|
-
* lessons: relationship({ ref: 'Lesson.teachers', many: true })
|
|
1134
|
-
* // Automatically uses same relationName from other side
|
|
1135
|
-
* }
|
|
1136
|
-
* })
|
|
1137
|
-
* ```
|
|
1138
|
-
*/
|
|
1139
|
-
relationName?: string;
|
|
1140
|
-
/**
|
|
1141
|
-
* Extend or modify the generated Prisma schema lines for this relationship field
|
|
1142
|
-
* Receives the generated FK line (if applicable) and relation line
|
|
1143
|
-
* Returns the modified lines
|
|
1224
|
+
* What the database does to this row when the referenced row is
|
|
1225
|
+
* deleted. Only meaningful on the foreign-key-owning side.
|
|
1144
1226
|
*
|
|
1145
|
-
* @example
|
|
1227
|
+
* @example Detach children when a parent category goes
|
|
1146
1228
|
* ```typescript
|
|
1147
1229
|
* parent: relationship({
|
|
1148
1230
|
* ref: 'Category.children',
|
|
1149
|
-
* db: {
|
|
1150
|
-
* foreignKey: true,
|
|
1151
|
-
* extendPrismaSchema: ({ fkLine, relationLine }) => ({
|
|
1152
|
-
* fkLine,
|
|
1153
|
-
* relationLine: relationLine.replace(
|
|
1154
|
-
* '@relation(',
|
|
1155
|
-
* '@relation(onDelete: SetNull, '
|
|
1156
|
-
* )
|
|
1157
|
-
* })
|
|
1158
|
-
* }
|
|
1231
|
+
* db: { foreignKey: true, onDelete: 'setNull' },
|
|
1159
1232
|
* })
|
|
1160
1233
|
* ```
|
|
1161
1234
|
*/
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
fkLine?: string;
|
|
1169
|
-
relationLine: string;
|
|
1170
|
-
};
|
|
1235
|
+
onDelete?: ReferentialAction;
|
|
1236
|
+
/**
|
|
1237
|
+
* What the database does to this row's foreign key when the referenced
|
|
1238
|
+
* row's id changes. Only meaningful on the foreign-key-owning side.
|
|
1239
|
+
*/
|
|
1240
|
+
onUpdate?: ReferentialAction;
|
|
1171
1241
|
};
|
|
1172
1242
|
ui?: {
|
|
1173
1243
|
displayMode?: 'select' | 'cards';
|
|
@@ -1179,61 +1249,8 @@ export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> = BaseField
|
|
|
1179
1249
|
*/
|
|
1180
1250
|
itemView?: RelationshipItemViewConfig;
|
|
1181
1251
|
};
|
|
1182
|
-
/**
|
|
1183
|
-
* Get the complete Prisma schema contribution for this relationship field.
|
|
1184
|
-
*
|
|
1185
|
-
* Relationships are special: unlike scalar fields (which return a single
|
|
1186
|
-
* type via `getPrismaType`), a relationship can contribute a foreign key
|
|
1187
|
-
* line, a relation line on the owning model, and a synthetic back-relation
|
|
1188
|
-
* line on the target model. This method encapsulates all of that logic so
|
|
1189
|
-
* the generator can remain a neutral coordinator.
|
|
1190
|
-
*
|
|
1191
|
-
* @param fieldName - The name of this relationship field
|
|
1192
|
-
* @param allFields - All fields on the list this relationship belongs to
|
|
1193
|
-
* @param listKey - The name of the list this relationship belongs to
|
|
1194
|
-
* @param config - The full OpenSaas config (used to resolve the target list/field)
|
|
1195
|
-
*/
|
|
1196
|
-
getPrismaRelation?: (fieldName: string, allFields: Record<string, FieldConfig>, listKey: string, config: OpenSaasConfig) => PrismaRelationResult;
|
|
1197
|
-
};
|
|
1198
|
-
/**
|
|
1199
|
-
* The complete Prisma schema contribution of a relationship field.
|
|
1200
|
-
*/
|
|
1201
|
-
export type PrismaRelationResult = {
|
|
1202
|
-
/**
|
|
1203
|
-
* Lines to add to the owning model.
|
|
1204
|
-
* For an FK-owning single relationship this is `[fkLine, relationLine]`;
|
|
1205
|
-
* for the many side or the non-FK side it is `[relationLine]`.
|
|
1206
|
-
*/
|
|
1207
|
-
modelLines: string[];
|
|
1208
|
-
/**
|
|
1209
|
-
* The Prisma-level foreign key field name this side owns (e.g. `authorId`),
|
|
1210
|
-
* regardless of whether it is indexed. `undefined` when this side doesn't
|
|
1211
|
-
* own a foreign key column at all (the many side, or the non-FK side of a
|
|
1212
|
-
* one-to-one). Lets other generator passes resolve a relationship field
|
|
1213
|
-
* name to its physical column — e.g. a model-level composite index
|
|
1214
|
-
* ({@link ListIndex}) naming a relationship field — without duplicating
|
|
1215
|
-
* {@link foreignKeyIndex}'s narrower, indexing-conditional presence.
|
|
1216
|
-
*/
|
|
1217
|
-
foreignKeyField?: string;
|
|
1218
|
-
/**
|
|
1219
|
-
* Foreign key index to add to the owning model, if this side owns an
|
|
1220
|
-
* indexed foreign key.
|
|
1221
|
-
*/
|
|
1222
|
-
foreignKeyIndex?: {
|
|
1223
|
-
foreignKeyField: string;
|
|
1224
|
-
indexType: boolean | 'unique';
|
|
1225
|
-
};
|
|
1226
|
-
/**
|
|
1227
|
-
* Synthetic back-relation field to add to the target model. Only present
|
|
1228
|
-
* for list-only refs (e.g., `ref: 'Category'`), where the target model
|
|
1229
|
-
* needs an opposite relation field for Prisma to validate the relation.
|
|
1230
|
-
*/
|
|
1231
|
-
backRelation?: {
|
|
1232
|
-
targetList: string;
|
|
1233
|
-
line: string;
|
|
1234
|
-
};
|
|
1235
1252
|
};
|
|
1236
|
-
export type JsonField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
1253
|
+
export type JsonField<TTypeInfo extends TypeInfo = TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
1237
1254
|
type: 'json';
|
|
1238
1255
|
validation?: {
|
|
1239
1256
|
isRequired?: boolean;
|
|
@@ -1271,14 +1288,9 @@ export type TypeDescriptor = string | {
|
|
|
1271
1288
|
*/
|
|
1272
1289
|
name?: string;
|
|
1273
1290
|
};
|
|
1274
|
-
export type VirtualField<TTypeInfo extends TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
1291
|
+
export type VirtualField<TTypeInfo extends TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey> & {
|
|
1275
1292
|
type: 'virtual';
|
|
1276
1293
|
virtual: true;
|
|
1277
|
-
/**
|
|
1278
|
-
* TypeScript type string for the virtual field output
|
|
1279
|
-
* e.g., 'string', 'number', 'boolean', 'string[]', etc.
|
|
1280
|
-
*/
|
|
1281
|
-
outputType: string;
|
|
1282
1294
|
};
|
|
1283
1295
|
/**
|
|
1284
1296
|
* Generic field configuration type
|
|
@@ -1287,9 +1299,37 @@ export type VirtualField<TTypeInfo extends TypeInfo> = BaseFieldConfig<TTypeInfo
|
|
|
1287
1299
|
* but at the config level we treat all fields uniformly
|
|
1288
1300
|
*/
|
|
1289
1301
|
export type FieldConfig = BaseFieldConfig<TypeInfo>;
|
|
1290
|
-
type WithTypeInfo<TTypeInfo extends TypeInfo> = BaseFieldConfig<TTypeInfo>;
|
|
1291
|
-
|
|
1302
|
+
type WithTypeInfo<TTypeInfo extends TypeInfo, TKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>> = BaseFieldConfig<TTypeInfo, TKey>;
|
|
1303
|
+
/**
|
|
1304
|
+
* The type every entry of `list()`'s `fields` object is checked against.
|
|
1305
|
+
*
|
|
1306
|
+
* Gated on `TTypeInfo['item']` being concrete (issue #1306): once a real,
|
|
1307
|
+
* generated `TypeInfo` is in hand (`list<Lists.Post.TypeInfo>({...})`), each
|
|
1308
|
+
* entry is checked against {@link WithTypeInfo} pinned to ITS OWN key, so a
|
|
1309
|
+
* field builder written the same way as every field in this repo — generic
|
|
1310
|
+
* over `TTypeInfo` — has that key flow all the way into its `hooks`, and
|
|
1311
|
+
* `GetFieldValueType` resolves precisely rather than falling back to
|
|
1312
|
+
* `unknown`.
|
|
1313
|
+
*
|
|
1314
|
+
* The pre-generation flow (`list({ fields: {...} })`, no explicit
|
|
1315
|
+
* `TTypeInfo`) has no per-field key to pin — `TTypeInfo` defaults to the
|
|
1316
|
+
* bare, unbound `TypeInfo`. The conditional keeps that flow on the untouched,
|
|
1317
|
+
* unkeyed index signature: a naked conditional type blocks TypeScript's
|
|
1318
|
+
* reverse-mapped-type inference from firing while `TTypeInfo` is itself
|
|
1319
|
+
* still being inferred, so this flow types exactly as it did before
|
|
1320
|
+
* `BaseFieldConfig` gained a key parameter at all.
|
|
1321
|
+
*
|
|
1322
|
+
* Each entry stays OPTIONAL, exactly as the index signature it replaces never
|
|
1323
|
+
* required any key at all: `list<Lists.X.TypeInfo>({...})` is additive type
|
|
1324
|
+
* safety over an already-generated config, not a completeness check, and a
|
|
1325
|
+
* type-level fixture testing one field's hook in isolation is a legitimate
|
|
1326
|
+
* partial `fields` object. A key outside `TTypeInfo['fields']` is still
|
|
1327
|
+
* refused — the mapped type has no index signature of its own.
|
|
1328
|
+
*/
|
|
1329
|
+
export type FieldsWithTypeInfo<TTypeInfo extends TypeInfo> = IsAny<TTypeInfo['item']> extends true ? {
|
|
1292
1330
|
[key: string]: WithTypeInfo<TTypeInfo>;
|
|
1331
|
+
} : {
|
|
1332
|
+
[K in FieldKeys<TTypeInfo['fields']>]?: WithTypeInfo<TTypeInfo, K>;
|
|
1293
1333
|
};
|
|
1294
1334
|
/**
|
|
1295
1335
|
* Parse TypeScript type string to actual type
|
|
@@ -1302,26 +1342,6 @@ export type FieldsWithTypeInfo<TTypeInfo extends TypeInfo> = {
|
|
|
1302
1342
|
* ParseTypeString<"import('@opensaas/stack-core').HashedPassword"> => any (fallback for imports)
|
|
1303
1343
|
*/
|
|
1304
1344
|
type ParseTypeString<T extends string> = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'Date' ? Date : T extends 'unknown' ? unknown : T extends `'${infer U}'` ? U : T extends `${infer U} | ${infer V}` ? ParseTypeString<U> | ParseTypeString<V> : T extends `import(${string}).${string}` ? any : unknown;
|
|
1305
|
-
/**
|
|
1306
|
-
* Extract field value type from a field config
|
|
1307
|
-
* Uses the field's getTypeScriptType() method result
|
|
1308
|
-
* If resultExtension is present, uses its outputType instead
|
|
1309
|
-
*
|
|
1310
|
-
* @example
|
|
1311
|
-
* ExtractFieldValueType<TextField> => string | null | undefined (if optional)
|
|
1312
|
-
* ExtractFieldValueType<IntegerField> => number
|
|
1313
|
-
* ExtractFieldValueType<PasswordField> => HashedPassword (from resultExtension)
|
|
1314
|
-
*/
|
|
1315
|
-
type ExtractFieldValueType<TField extends BaseFieldConfig<any>> = TField extends {
|
|
1316
|
-
resultExtension: {
|
|
1317
|
-
outputType: infer O;
|
|
1318
|
-
};
|
|
1319
|
-
} ? ParseTypeString<O & string> : TField extends {
|
|
1320
|
-
getTypeScriptType(): {
|
|
1321
|
-
type: infer T;
|
|
1322
|
-
optional: infer Opt;
|
|
1323
|
-
};
|
|
1324
|
-
} ? Opt extends true ? ParseTypeString<T & string> | null | undefined : ParseTypeString<T & string> : unknown;
|
|
1325
1345
|
/**
|
|
1326
1346
|
* Extract field names as union of string literals
|
|
1327
1347
|
*
|
|
@@ -1338,14 +1358,57 @@ export type FieldKeys<TFields extends Record<string, any>> = keyof TFields & str
|
|
|
1338
1358
|
*/
|
|
1339
1359
|
export type GetFieldConfig<TFields extends Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic utility type needs to accept any field record
|
|
1340
1360
|
TFieldKey extends FieldKeys<TFields>> = TFields[TFieldKey];
|
|
1361
|
+
/** Whether `T` is `any`, which `keyof` would otherwise widen a lookup through. */
|
|
1362
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
1341
1363
|
/**
|
|
1342
|
-
*
|
|
1364
|
+
* A stored field's value type: the property the generated `Lists.<List>.Item`
|
|
1365
|
+
* carries for it (ADR-0052 — the contract column types the field, and `item`
|
|
1366
|
+
* is where that lands). `unknown` only for a hand-authored `TypeInfo`, whose
|
|
1367
|
+
* `item` carries no per-field facts to read.
|
|
1368
|
+
*/
|
|
1369
|
+
type StoredFieldValueType<TTypeInfo extends TypeInfo, TFieldKey extends PropertyKey> = IsAny<TTypeInfo['item']> extends true ? unknown : TFieldKey extends keyof TTypeInfo['item'] ? TTypeInfo['item'][TFieldKey] : unknown;
|
|
1370
|
+
/**
|
|
1371
|
+
* Whether `TKey` names more than one field. Every branch below is written
|
|
1372
|
+
* non-distributively over a single key, so a union has to be turned away
|
|
1373
|
+
* before it reaches them.
|
|
1374
|
+
*/
|
|
1375
|
+
type IsSeveralKeys<TKey, TAll = TKey> = TKey extends unknown ? [TAll] extends [TKey] ? false : true : never;
|
|
1376
|
+
/**
|
|
1377
|
+
* One field's value type: its declared `outputType` when its static type
|
|
1378
|
+
* declares one, and otherwise the stored row's property — so a stored field is
|
|
1379
|
+
* typed by its contract column rather than left open.
|
|
1380
|
+
*
|
|
1381
|
+
* `unknown` when `TFieldKey` names several fields — the fallback for a
|
|
1382
|
+
* `FieldHooks<TTypeInfo>` instantiated with no key of its own (a third-party
|
|
1383
|
+
* field that doesn't thread {@link BaseFieldConfig}'s `TKey` through, or a
|
|
1384
|
+
* hand-authored `TypeInfo` used generically). Resolving a genuine union would
|
|
1385
|
+
* type each field's hook by the whole row: a `text()` hook would accept a
|
|
1386
|
+
* `Date` and reject its own `string`. At the real, generated-`TypeInfo`
|
|
1387
|
+
* instantiation (`list<Lists.Post.TypeInfo>({ fields: { title: text(...) } })`)
|
|
1388
|
+
* {@link FieldsWithTypeInfo} pins each field's own key before it ever reaches
|
|
1389
|
+
* here, so this guard is a fallback, not the common case (issue #1306).
|
|
1343
1390
|
*
|
|
1344
1391
|
* @example
|
|
1345
|
-
* GetFieldValueType<
|
|
1392
|
+
* GetFieldValueType<Lists.Post.TypeInfo, 'title'> => string
|
|
1346
1393
|
*/
|
|
1347
|
-
export type GetFieldValueType<
|
|
1348
|
-
|
|
1394
|
+
export type GetFieldValueType<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<TTypeInfo['fields']>> = IsSeveralKeys<TFieldKey> extends false ? DeclaredOrStoredValueType<TTypeInfo, TFieldKey> : unknown;
|
|
1395
|
+
/**
|
|
1396
|
+
* The resolution for a single field key: `outputType` in either spelling,
|
|
1397
|
+
* falling through to the stored row. Written as tuple comparisons so nothing
|
|
1398
|
+
* distributes and no marker type is needed to spell "declared none" — a
|
|
1399
|
+
* sentinel here would surface verbatim in a consumer's error message.
|
|
1400
|
+
*/
|
|
1401
|
+
type DeclaredOrStoredValueType<TTypeInfo extends TypeInfo, TFieldKey extends FieldKeys<TTypeInfo['fields']>> = [GetFieldConfig<TTypeInfo['fields'], TFieldKey>] extends [
|
|
1402
|
+
{
|
|
1403
|
+
outputType: infer O extends string;
|
|
1404
|
+
}
|
|
1405
|
+
] ? ParseTypeString<O> : [GetFieldConfig<TTypeInfo['fields'], TFieldKey>] extends [
|
|
1406
|
+
{
|
|
1407
|
+
outputType: {
|
|
1408
|
+
value: new (...args: any[]) => infer I;
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
] ? I : StoredFieldValueType<TTypeInfo, TFieldKey>;
|
|
1349
1412
|
/**
|
|
1350
1413
|
* TypeInfo interface for list type information
|
|
1351
1414
|
* Provides a structured way to pass all type information for a list
|
|
@@ -1353,17 +1416,18 @@ TFieldKey extends FieldKeys<TFields>> = ExtractFieldValueType<GetFieldConfig<TFi
|
|
|
1353
1416
|
*
|
|
1354
1417
|
* @template TKey - The list key/name (e.g., 'Post', 'User')
|
|
1355
1418
|
* @template TFields - The fields configuration for the list
|
|
1356
|
-
* @template
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1419
|
+
* @template TDb - The app's generated `db` surface (ADR-0052's `DB`, the same
|
|
1420
|
+
* type the generated `Context`/`BaseContext` instantiate). Defaults to
|
|
1421
|
+
* `unknown`, never {@link AccessControlledDB} directly: the generated `DB`
|
|
1422
|
+
* is an `interface` with no index signature (ADR-0032), so pinning the
|
|
1423
|
+
* default there would make `TypeInfo` (bare, as every field builder bounds
|
|
1424
|
+
* its own `TTypeInfo extends TypeInfo`) demand one from every list's real
|
|
1425
|
+
* `db` and reject it as "index signature is missing" on every field. A
|
|
1426
|
+
* `TypeInfo` written (or defaulted) without `TDb` keeps today's behaviour —
|
|
1427
|
+
* `HookDb` resolves the hook's `context.db` to {@link AccessControlledDB}.
|
|
1360
1428
|
* @template TItem - The output type (Prisma model type)
|
|
1361
1429
|
* @template TCreateInput - The Prisma create input type
|
|
1362
1430
|
* @template TUpdateInput - The Prisma update input type
|
|
1363
|
-
* @template TDb - The app's own generated `db` surface (the CLI's `CustomDB`),
|
|
1364
|
-
* with virtual and transformed fields folded into every list's payload.
|
|
1365
|
-
* Defaults to `AccessControlledDB<TPrisma>` — the plain Prisma-shaped view —
|
|
1366
|
-
* so a `TypeInfo` written (or defaulted) without it keeps today's behaviour.
|
|
1367
1431
|
*
|
|
1368
1432
|
* @example
|
|
1369
1433
|
* ```typescript
|
|
@@ -1375,13 +1439,12 @@ TFieldKey extends FieldKeys<TFields>> = ExtractFieldValueType<GetFieldConfig<TFi
|
|
|
1375
1439
|
* create: Prisma.PostCreateInput
|
|
1376
1440
|
* update: Prisma.PostUpdateInput
|
|
1377
1441
|
* }
|
|
1378
|
-
*
|
|
1379
|
-
* db: CustomDB
|
|
1442
|
+
* db: DB
|
|
1380
1443
|
* }
|
|
1381
1444
|
* ```
|
|
1382
1445
|
*/
|
|
1383
1446
|
export interface TypeInfo<TKey extends string = string, TFields extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- TypeInfo must accept any field record
|
|
1384
|
-
|
|
1447
|
+
TDb = unknown> {
|
|
1385
1448
|
key: TKey;
|
|
1386
1449
|
fields: TFields;
|
|
1387
1450
|
item: any;
|
|
@@ -1390,18 +1453,71 @@ TPrisma extends PrismaClientLike = PrismaClientLike, TDb = AccessControlledDB<TP
|
|
|
1390
1453
|
update: any;
|
|
1391
1454
|
};
|
|
1392
1455
|
/**
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1456
|
+
* What a caller receives from a read of this list — the stored row plus its
|
|
1457
|
+
* computed fields. `item` is the narrower stored row a hook sees, which
|
|
1458
|
+
* never carries a computed value (ADR-0027).
|
|
1396
1459
|
*/
|
|
1397
|
-
|
|
1460
|
+
output?: unknown;
|
|
1398
1461
|
/**
|
|
1399
|
-
*
|
|
1400
|
-
* `
|
|
1401
|
-
*
|
|
1462
|
+
* Per-field declared-dependency facts (ADR-0051). `needs` is the field's
|
|
1463
|
+
* declared set as a union of column and relation keys; `item` is that set
|
|
1464
|
+
* resolved against the contract — exactly what the runtime hands the
|
|
1465
|
+
* field's `resolveOutput` hook, which is what makes reading an undeclared
|
|
1466
|
+
* column a compile error.
|
|
1467
|
+
*
|
|
1468
|
+
* Written by `pnpm generate`; absent on a hand-authored `TypeInfo`, where
|
|
1469
|
+
* a hook's `item` falls back to the whole stored row.
|
|
1402
1470
|
*/
|
|
1403
|
-
|
|
1471
|
+
needs?: Record<string, {
|
|
1472
|
+
needs?: string;
|
|
1473
|
+
item?: unknown;
|
|
1474
|
+
}>;
|
|
1475
|
+
/**
|
|
1476
|
+
* The app's generated `db` surface — the same `DB` the generated `Context`
|
|
1477
|
+
* and `BaseContext` instantiate. A hook's `context` is keyed off it, so
|
|
1478
|
+
* `context.db.<misspelled list>` is a compile error and `context.db.<real
|
|
1479
|
+
* list>` is that list's own `SecuredList` (ADR-0052's amendment for
|
|
1480
|
+
* #1211/#1213).
|
|
1481
|
+
*
|
|
1482
|
+
* Written by `pnpm generate`; absent (or `unknown`) on a hand-authored
|
|
1483
|
+
* `TypeInfo`, where {@link HookDb} falls back to {@link AccessControlledDB}.
|
|
1484
|
+
*/
|
|
1485
|
+
db?: TDb;
|
|
1404
1486
|
}
|
|
1487
|
+
/**
|
|
1488
|
+
* The `db` surface a hook's `context` is keyed to: {@link TypeInfo.db} when
|
|
1489
|
+
* the `TypeInfo` carries a real one, else {@link AccessControlledDB} —
|
|
1490
|
+
* applied both where a hand-authored `TypeInfo` omits the member entirely
|
|
1491
|
+
* (mirrors {@link FieldNeedsItem}'s `NonNullable<TTypeInfo['needs']>` pattern
|
|
1492
|
+
* for the same reason) and where `TypeInfo`'s own `TDb` default (`unknown`)
|
|
1493
|
+
* is standing in for it.
|
|
1494
|
+
*
|
|
1495
|
+
* Also falls back for `TTypeInfo = any` — the untyped `list()` shape
|
|
1496
|
+
* (`OpenSaasConfig['lists']` is `Record<string, ListConfig<any>>`) — where
|
|
1497
|
+
* `TTypeInfo['db']` would otherwise resolve to bare `any` and poison every
|
|
1498
|
+
* `context.db.<list>` chain in the hook to `any`, turning a genuine
|
|
1499
|
+
* `noImplicitAny` violation on the caller's own code into a silent pass.
|
|
1500
|
+
*
|
|
1501
|
+
* A hand-authored `TypeInfo.db` (the third-party-field pattern) is trusted
|
|
1502
|
+
* as given, unlike `StackContext`/`StackBaseContext`'s `DB extends
|
|
1503
|
+
* StackDb<DB>` (`types/context.ts`): that self-referential constraint can't
|
|
1504
|
+
* be re-verified through this indexed-access alias applied to an
|
|
1505
|
+
* as-yet-unresolved `TTypeInfo` without rejecting every real, generated `DB`
|
|
1506
|
+
* as "index signature is missing" (see the constraint dropped from
|
|
1507
|
+
* `AccessContext` in `access/types.ts`, and from `TypeInfo`'s own `TDb`
|
|
1508
|
+
* above). So a `TypeInfo.db` naming a raw ORM client, rather than a `DB`
|
|
1509
|
+
* surface, is not caught here the way it would be on `StackContext`.
|
|
1510
|
+
*/
|
|
1511
|
+
export type HookDb<TTypeInfo extends TypeInfo> = IsAny<TTypeInfo> extends true ? AccessControlledDB : unknown extends TTypeInfo['db'] ? AccessControlledDB : NonNullable<TTypeInfo['db']>;
|
|
1512
|
+
/**
|
|
1513
|
+
* The `item` a field's `resolveOutput` hook is handed: its declared
|
|
1514
|
+
* dependency set plus the list's system fields, resolved by `pnpm generate`
|
|
1515
|
+
* and read back off {@link TypeInfo.needs}. Falls back to the whole stored
|
|
1516
|
+
* row for a `TypeInfo` that carries no declared-dependency facts.
|
|
1517
|
+
*/
|
|
1518
|
+
export type FieldNeedsItem<TTypeInfo extends TypeInfo, TFieldKey extends PropertyKey> = NonNullable<TTypeInfo['needs']> extends infer TNeeds ? TFieldKey extends keyof TNeeds ? TNeeds[TFieldKey] extends {
|
|
1519
|
+
item: infer TItem;
|
|
1520
|
+
} ? TItem : TTypeInfo['item'] : TTypeInfo['item'] : TTypeInfo['item'];
|
|
1405
1521
|
export type OperationAccess<T = any> = {
|
|
1406
1522
|
query?: AccessControl<T>;
|
|
1407
1523
|
/**
|
|
@@ -1409,7 +1525,7 @@ export type OperationAccess<T = any> = {
|
|
|
1409
1525
|
* but at runtime `create` accepts a `boolean` result only. There is no
|
|
1410
1526
|
* existing row to scope with a filter, and — unlike `update`/`delete`,
|
|
1411
1527
|
* which re-check a returned filter against the target row via
|
|
1412
|
-
*
|
|
1528
|
+
* a read of the target — no equivalent re-check exists for a row that doesn't exist
|
|
1413
1529
|
* in the database yet. A rule that returns a filter (or any other
|
|
1414
1530
|
* non-boolean) throws `InvalidCreateAccessResultError` rather than being
|
|
1415
1531
|
* treated as an allow (see #1009, ADR-0022, ADR-0030). To scope create by
|
|
@@ -1463,20 +1579,20 @@ export type ListAccessControl<T = any> = AccessControl<T> | {
|
|
|
1463
1579
|
* - create: resolvedData is CreateInput, item is undefined
|
|
1464
1580
|
* - update: resolvedData is UpdateInput, item is the existing record
|
|
1465
1581
|
*/
|
|
1466
|
-
export type ResolveInputHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1582
|
+
export type ResolveInputHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1467
1583
|
listKey: string;
|
|
1468
1584
|
operation: 'create';
|
|
1469
1585
|
inputData: TCreateInput;
|
|
1470
1586
|
resolvedData: TCreateInput;
|
|
1471
1587
|
item: undefined;
|
|
1472
|
-
context: import('../
|
|
1588
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1473
1589
|
} | {
|
|
1474
1590
|
listKey: string;
|
|
1475
1591
|
operation: 'update';
|
|
1476
1592
|
inputData: TUpdateInput;
|
|
1477
1593
|
resolvedData: TUpdateInput;
|
|
1478
1594
|
item: TOutput;
|
|
1479
|
-
context: import('../
|
|
1595
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1480
1596
|
};
|
|
1481
1597
|
/**
|
|
1482
1598
|
* Hook arguments for the list-level `validate` hook (renamed from `validateInput` for Keystone compatibility).
|
|
@@ -1484,13 +1600,13 @@ export type ResolveInputHookArgs<TOutput = Record<string, unknown>, TCreateInput
|
|
|
1484
1600
|
* - update: resolvedData is UpdateInput, item is the existing record
|
|
1485
1601
|
* - delete: item is the item being deleted
|
|
1486
1602
|
*/
|
|
1487
|
-
export type ValidateHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1603
|
+
export type ValidateHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1488
1604
|
listKey: string;
|
|
1489
1605
|
operation: 'create';
|
|
1490
1606
|
inputData: TCreateInput;
|
|
1491
1607
|
resolvedData: TCreateInput;
|
|
1492
1608
|
item: undefined;
|
|
1493
|
-
context: import('../
|
|
1609
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1494
1610
|
addValidationError: (msg: string) => void;
|
|
1495
1611
|
} | {
|
|
1496
1612
|
listKey: string;
|
|
@@ -1498,13 +1614,13 @@ export type ValidateHookArgs<TOutput = Record<string, unknown>, TCreateInput = R
|
|
|
1498
1614
|
inputData: TUpdateInput;
|
|
1499
1615
|
resolvedData: TUpdateInput;
|
|
1500
1616
|
item: TOutput;
|
|
1501
|
-
context: import('../
|
|
1617
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1502
1618
|
addValidationError: (msg: string) => void;
|
|
1503
1619
|
} | {
|
|
1504
1620
|
listKey: string;
|
|
1505
1621
|
operation: 'delete';
|
|
1506
1622
|
item: TOutput;
|
|
1507
|
-
context: import('../
|
|
1623
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1508
1624
|
addValidationError: (msg: string) => void;
|
|
1509
1625
|
};
|
|
1510
1626
|
/**
|
|
@@ -1513,38 +1629,42 @@ export type ValidateHookArgs<TOutput = Record<string, unknown>, TCreateInput = R
|
|
|
1513
1629
|
* - update: has inputData, resolvedData, and item
|
|
1514
1630
|
* - delete: has item only
|
|
1515
1631
|
*/
|
|
1516
|
-
export type BeforeOperationHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1632
|
+
export type BeforeOperationHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1517
1633
|
listKey: string;
|
|
1518
1634
|
operation: 'create';
|
|
1519
1635
|
inputData: TCreateInput;
|
|
1520
1636
|
resolvedData: TCreateInput;
|
|
1521
|
-
context: import('../
|
|
1637
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1522
1638
|
} | {
|
|
1523
1639
|
listKey: string;
|
|
1524
1640
|
operation: 'update';
|
|
1525
1641
|
inputData: TUpdateInput;
|
|
1526
1642
|
item: TOutput;
|
|
1527
1643
|
resolvedData: TUpdateInput;
|
|
1528
|
-
context: import('../
|
|
1644
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1529
1645
|
} | {
|
|
1530
1646
|
listKey: string;
|
|
1531
1647
|
operation: 'delete';
|
|
1532
1648
|
item: TOutput;
|
|
1533
|
-
context: import('../
|
|
1649
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1534
1650
|
};
|
|
1535
1651
|
/**
|
|
1536
1652
|
* Hook arguments for the list-level `afterOperation` hook.
|
|
1537
1653
|
* - create: has item, inputData, and resolvedData, no originalItem
|
|
1538
1654
|
* - update: has item, originalItem, inputData, and resolvedData
|
|
1539
1655
|
* - delete: has originalItem only
|
|
1656
|
+
*
|
|
1657
|
+
* An update whose resolved payload is empty writes nothing (and does not move
|
|
1658
|
+
* `updatedAt`) but still runs `afterOperation`, with `item` equal to
|
|
1659
|
+
* `originalItem`. A hook that must skip no-ops compares the two.
|
|
1540
1660
|
*/
|
|
1541
|
-
export type AfterOperationHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1661
|
+
export type AfterOperationHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1542
1662
|
listKey: string;
|
|
1543
1663
|
operation: 'create';
|
|
1544
1664
|
inputData: TCreateInput;
|
|
1545
1665
|
item: TOutput;
|
|
1546
1666
|
resolvedData: TCreateInput;
|
|
1547
|
-
context: import('../
|
|
1667
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1548
1668
|
} | {
|
|
1549
1669
|
listKey: string;
|
|
1550
1670
|
operation: 'update';
|
|
@@ -1552,12 +1672,12 @@ export type AfterOperationHookArgs<TOutput = Record<string, unknown>, TCreateInp
|
|
|
1552
1672
|
originalItem: TOutput;
|
|
1553
1673
|
item: TOutput;
|
|
1554
1674
|
resolvedData: TUpdateInput;
|
|
1555
|
-
context: import('../
|
|
1675
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1556
1676
|
} | {
|
|
1557
1677
|
listKey: string;
|
|
1558
1678
|
operation: 'delete';
|
|
1559
1679
|
originalItem: TOutput;
|
|
1560
|
-
context: import('../
|
|
1680
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1561
1681
|
};
|
|
1562
1682
|
/**
|
|
1563
1683
|
* Hook arguments for the list-level beforeTransaction hook (#590 / ADR-0010).
|
|
@@ -1568,22 +1688,22 @@ export type AfterOperationHookArgs<TOutput = Record<string, unknown>, TCreateInp
|
|
|
1568
1688
|
* `undefined` for nested targets. For non-transactional side effects whose
|
|
1569
1689
|
* compensation pairs with `afterTransaction`.
|
|
1570
1690
|
*/
|
|
1571
|
-
export type BeforeTransactionHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1691
|
+
export type BeforeTransactionHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1572
1692
|
listKey: string;
|
|
1573
1693
|
operation: 'create';
|
|
1574
1694
|
inputData: TCreateInput;
|
|
1575
|
-
context: import('../access/types.js').AccessContext<
|
|
1695
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1576
1696
|
} | {
|
|
1577
1697
|
listKey: string;
|
|
1578
1698
|
operation: 'update';
|
|
1579
1699
|
inputData: TUpdateInput;
|
|
1580
1700
|
item: TOutput | undefined;
|
|
1581
|
-
context: import('../access/types.js').AccessContext<
|
|
1701
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1582
1702
|
} | {
|
|
1583
1703
|
listKey: string;
|
|
1584
1704
|
operation: 'delete';
|
|
1585
1705
|
item: TOutput | undefined;
|
|
1586
|
-
context: import('../access/types.js').AccessContext<
|
|
1706
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1587
1707
|
};
|
|
1588
1708
|
/**
|
|
1589
1709
|
* Hook arguments for the list-level afterTransaction hook (#590 / ADR-0010).
|
|
@@ -1600,24 +1720,27 @@ export type BeforeTransactionHookArgs<TOutput = Record<string, unknown>, TCreate
|
|
|
1600
1720
|
* `afterOperation` (which receives the correct nested `item`);
|
|
1601
1721
|
* transaction-boundary hooks are for external-call compensation keyed off
|
|
1602
1722
|
* `status`/`inputData`.
|
|
1723
|
+
* - `item` is the raw persisted row, the same one `afterOperation` receives —
|
|
1724
|
+
* not the session's Field Visibility projection: columns the session cannot
|
|
1725
|
+
* read are present and `resolveOutput` transforms are not applied.
|
|
1603
1726
|
* - `rolled-back`: NO persisted `item`; the hook gets `inputData` and the
|
|
1604
1727
|
* `error` that caused the rollback so it can compensate.
|
|
1605
1728
|
*/
|
|
1606
|
-
export type AfterTransactionHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1729
|
+
export type AfterTransactionHookArgs<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1607
1730
|
listKey: string;
|
|
1608
1731
|
operation: 'create';
|
|
1609
1732
|
status: 'committed';
|
|
1610
1733
|
inputData: TCreateInput;
|
|
1611
1734
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1612
1735
|
item: TOutput | undefined;
|
|
1613
|
-
context: import('../access/types.js').AccessContext<
|
|
1736
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1614
1737
|
} | {
|
|
1615
1738
|
listKey: string;
|
|
1616
1739
|
operation: 'create';
|
|
1617
1740
|
status: 'rolled-back';
|
|
1618
1741
|
inputData: TCreateInput;
|
|
1619
1742
|
error: unknown;
|
|
1620
|
-
context: import('../access/types.js').AccessContext<
|
|
1743
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1621
1744
|
} | {
|
|
1622
1745
|
listKey: string;
|
|
1623
1746
|
operation: 'update';
|
|
@@ -1627,7 +1750,7 @@ export type AfterTransactionHookArgs<TOutput = Record<string, unknown>, TCreateI
|
|
|
1627
1750
|
originalItem: TOutput | undefined;
|
|
1628
1751
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1629
1752
|
item: TOutput | undefined;
|
|
1630
|
-
context: import('../access/types.js').AccessContext<
|
|
1753
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1631
1754
|
} | {
|
|
1632
1755
|
listKey: string;
|
|
1633
1756
|
operation: 'update';
|
|
@@ -1635,34 +1758,34 @@ export type AfterTransactionHookArgs<TOutput = Record<string, unknown>, TCreateI
|
|
|
1635
1758
|
inputData: TUpdateInput;
|
|
1636
1759
|
originalItem: TOutput | undefined;
|
|
1637
1760
|
error: unknown;
|
|
1638
|
-
context: import('../access/types.js').AccessContext<
|
|
1761
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1639
1762
|
} | {
|
|
1640
1763
|
listKey: string;
|
|
1641
1764
|
operation: 'delete';
|
|
1642
1765
|
status: 'committed';
|
|
1643
1766
|
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1644
1767
|
originalItem: TOutput | undefined;
|
|
1645
|
-
context: import('../access/types.js').AccessContext<
|
|
1768
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1646
1769
|
} | {
|
|
1647
1770
|
listKey: string;
|
|
1648
1771
|
operation: 'delete';
|
|
1649
1772
|
status: 'rolled-back';
|
|
1650
1773
|
originalItem: TOutput | undefined;
|
|
1651
1774
|
error: unknown;
|
|
1652
|
-
context: import('../access/types.js').AccessContext<
|
|
1775
|
+
context: import('../access/types.js').AccessContext<TDb>;
|
|
1653
1776
|
};
|
|
1654
|
-
export type Hooks<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>,
|
|
1655
|
-
resolveInput?: (args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1656
|
-
validate?: (args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1657
|
-
beforeOperation?: (args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1658
|
-
afterOperation?: (args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1777
|
+
export type Hooks<TOutput = Record<string, unknown>, TCreateInput = Record<string, unknown>, TUpdateInput = Record<string, unknown>, TDb = AccessControlledDB> = {
|
|
1778
|
+
resolveInput?: (args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<TCreateInput | TUpdateInput>;
|
|
1779
|
+
validate?: (args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void>;
|
|
1780
|
+
beforeOperation?: (args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void>;
|
|
1781
|
+
afterOperation?: (args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void>;
|
|
1659
1782
|
/**
|
|
1660
1783
|
* Side effect BEFORE the write's transaction opens (#590 / ADR-0010).
|
|
1661
1784
|
* Runs OUTSIDE the transaction — for non-transactional work (external API
|
|
1662
1785
|
* calls). Throwing aborts the write; the paired `afterTransaction` then fires
|
|
1663
1786
|
* with `status: 'rolled-back'`. See {@link BeforeTransactionHookArgs}.
|
|
1664
1787
|
*/
|
|
1665
|
-
beforeTransaction?: (args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1788
|
+
beforeTransaction?: (args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void> | void;
|
|
1666
1789
|
/**
|
|
1667
1790
|
* Side effect AFTER the write's transaction settles (#590 / ADR-0010).
|
|
1668
1791
|
* ALWAYS runs when `beforeTransaction` ran; receives `committed | rolled-back`
|
|
@@ -1670,27 +1793,34 @@ export type Hooks<TOutput = Record<string, unknown>, TCreateInput = Record<strin
|
|
|
1670
1793
|
* AND only for the top-level record (`undefined` for nested lists). The
|
|
1671
1794
|
* compensation half of the transaction-boundary bracket. See
|
|
1672
1795
|
* {@link AfterTransactionHookArgs}.
|
|
1796
|
+
*
|
|
1797
|
+
* A throw is reported to `onAfterTransactionError`, never propagated: the
|
|
1798
|
+
* write's result is unchanged and every other compensator still runs.
|
|
1673
1799
|
*/
|
|
1674
|
-
afterTransaction?: (args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1800
|
+
afterTransaction?: (args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void> | void;
|
|
1675
1801
|
/**
|
|
1676
1802
|
* @deprecated Use 'validate' instead. This alias is provided for backwards compatibility.
|
|
1677
1803
|
*/
|
|
1678
|
-
validateInput?: (args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput,
|
|
1804
|
+
validateInput?: (args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TDb>) => Promise<void>;
|
|
1679
1805
|
};
|
|
1680
1806
|
/**
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1683
|
-
|
|
1807
|
+
* The five referential actions a foreign key can carry, in the ORM's own
|
|
1808
|
+
* spelling so the generated contract re-emits the value verbatim.
|
|
1809
|
+
*/
|
|
1810
|
+
export type ReferentialAction = 'cascade' | 'restrict' | 'noAction' | 'setNull' | 'setDefault';
|
|
1811
|
+
/**
|
|
1812
|
+
* A single field reference within a model-level {@link ListIndex}: the
|
|
1813
|
+
* OpenSaaS field name, bare or wrapped. An index column carries no sort
|
|
1814
|
+
* direction (ADR-0040); a `sort` key on the wrapped form is refused at
|
|
1815
|
+
* generation.
|
|
1684
1816
|
*/
|
|
1685
1817
|
export type ListIndexFieldRef = string | {
|
|
1686
1818
|
field: string;
|
|
1687
|
-
/** Sort direction for this column within the index/constraint. */
|
|
1688
|
-
sort?: 'asc' | 'desc';
|
|
1689
1819
|
};
|
|
1690
1820
|
/**
|
|
1691
|
-
* A model-level
|
|
1692
|
-
*
|
|
1693
|
-
*
|
|
1821
|
+
* A model-level unique constraint or index spanning one or more of a list's
|
|
1822
|
+
* own fields. See {@link ListConfig.db}'s `indexes` for the full explanation
|
|
1823
|
+
* and examples (#864, #918).
|
|
1694
1824
|
*/
|
|
1695
1825
|
export type ListIndex = {
|
|
1696
1826
|
/**
|
|
@@ -1698,23 +1828,29 @@ export type ListIndex = {
|
|
|
1698
1828
|
* OpenSaaS field names, not raw database column names.
|
|
1699
1829
|
*
|
|
1700
1830
|
* One or more fields — a named single-column constraint is as legitimate
|
|
1701
|
-
* as a composite one
|
|
1702
|
-
*
|
|
1703
|
-
* `isIndexed` remains the sugar for the unnamed single-column case; this
|
|
1704
|
-
* is the full form when a name or a sort direction is needed.
|
|
1831
|
+
* as a composite one. Field-level `isIndexed` remains the sugar for the
|
|
1832
|
+
* unnamed single-column case; this is the full form when a name is needed.
|
|
1705
1833
|
*/
|
|
1706
1834
|
fields: ListIndexFieldRef[];
|
|
1707
1835
|
/**
|
|
1708
|
-
* Emit
|
|
1836
|
+
* Emit a unique constraint instead of an index.
|
|
1709
1837
|
* @default false
|
|
1710
1838
|
*/
|
|
1711
1839
|
unique?: boolean;
|
|
1712
1840
|
/**
|
|
1713
|
-
*
|
|
1714
|
-
* existing live constraint be adopted under its current name rather than
|
|
1715
|
-
* renamed.
|
|
1841
|
+
* The constraint/index's wire name, emitted as the contract's `name:`.
|
|
1716
1842
|
*/
|
|
1717
1843
|
name?: string;
|
|
1844
|
+
/**
|
|
1845
|
+
* A partial index's predicate: raw SQL, the body of a `WHERE` clause without
|
|
1846
|
+
* the keyword. Written in database column names. A unique entry with `where`
|
|
1847
|
+
* is a partial unique index rather than a unique constraint. It must also carry a `name`, which is adopted as the index's exact name.
|
|
1848
|
+
*
|
|
1849
|
+
* Drift detection compares this text byte-for-byte with how PostgreSQL
|
|
1850
|
+
* prints the predicate back, so write it in that form — copy it from the
|
|
1851
|
+
* `WHERE` clause of `pg_indexes.indexdef` (`("twilioSid" <> ''::text)`).
|
|
1852
|
+
*/
|
|
1853
|
+
where?: string;
|
|
1718
1854
|
};
|
|
1719
1855
|
/**
|
|
1720
1856
|
* Internal list configuration type (after normalization by list() function)
|
|
@@ -1730,33 +1866,33 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1730
1866
|
access?: {
|
|
1731
1867
|
operation?: OperationAccess<TTypeInfo['item']>;
|
|
1732
1868
|
};
|
|
1733
|
-
hooks?: Hooks<TTypeInfo['item'], TTypeInfo['inputs']['create'], TTypeInfo['inputs']['update'], TTypeInfo
|
|
1869
|
+
hooks?: Hooks<TTypeInfo['item'], TTypeInfo['inputs']['create'], TTypeInfo['inputs']['update'], HookDb<TTypeInfo>>;
|
|
1734
1870
|
/**
|
|
1735
1871
|
* Database configuration for this list (model level)
|
|
1736
1872
|
*/
|
|
1737
1873
|
db?: {
|
|
1738
1874
|
/**
|
|
1739
|
-
* Custom database table name.
|
|
1740
|
-
*
|
|
1875
|
+
* Custom database table name. Carried on the contract model as `table`,
|
|
1876
|
+
* so the model name (the list key) can differ from the physical table.
|
|
1741
1877
|
*
|
|
1742
|
-
* Useful when the
|
|
1878
|
+
* Useful when the model name (the list key) must differ from the
|
|
1743
1879
|
* physical table name — e.g. adopting an existing better-auth installation
|
|
1744
1880
|
* whose tables were created under a different name.
|
|
1745
1881
|
*
|
|
1746
1882
|
* @example
|
|
1747
1883
|
* ```typescript
|
|
1748
1884
|
* AuthUser: list({ fields: { ... }, db: { map: 'user' } })
|
|
1749
|
-
* //
|
|
1885
|
+
* // Contract: model AuthUser has table 'user'
|
|
1750
1886
|
* ```
|
|
1751
1887
|
*/
|
|
1752
1888
|
map?: string;
|
|
1753
1889
|
/**
|
|
1754
|
-
* Database schema for this model (Postgres multi-schema).
|
|
1755
|
-
*
|
|
1890
|
+
* Database schema for this model (Postgres multi-schema). Carried on the
|
|
1891
|
+
* contract model as its `namespace`.
|
|
1756
1892
|
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1893
|
+
* The schema must also appear in {@link DatabaseConfig.schemas}, which the
|
|
1894
|
+
* contract collects into its own `namespaces` list — Prisma resolves a
|
|
1895
|
+
* model's `namespace` against that list.
|
|
1760
1896
|
*
|
|
1761
1897
|
* Useful when adopting an existing installation whose tables live in a
|
|
1762
1898
|
* non-`public` schema — e.g. a separate-schema better-auth layout.
|
|
@@ -1764,7 +1900,7 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1764
1900
|
* @example
|
|
1765
1901
|
* ```typescript
|
|
1766
1902
|
* AuthUser: list({ fields: { ... }, db: { schema: 'auth' } })
|
|
1767
|
-
* //
|
|
1903
|
+
* // Contract: model AuthUser has namespace 'auth'
|
|
1768
1904
|
* ```
|
|
1769
1905
|
*/
|
|
1770
1906
|
schema?: string;
|
|
@@ -1778,7 +1914,7 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1778
1914
|
*
|
|
1779
1915
|
* When timestamps resolve to on but the list already declares its own `createdAt`/
|
|
1780
1916
|
* `updatedAt` field, the auto column is skipped for the declared field(s) so Prisma
|
|
1781
|
-
* never sees a duplicate
|
|
1917
|
+
* never sees a duplicate column.
|
|
1782
1918
|
*
|
|
1783
1919
|
* @example Opt a single list out of timestamps even when enabled globally
|
|
1784
1920
|
* ```typescript
|
|
@@ -1790,21 +1926,40 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1790
1926
|
*/
|
|
1791
1927
|
timestamps?: boolean;
|
|
1792
1928
|
/**
|
|
1793
|
-
*
|
|
1929
|
+
* How this list's `id` is minted, overriding the config-level
|
|
1930
|
+
* `db.idField` default (ADR-0048). A plugin pins this on every list it
|
|
1931
|
+
* injects so an app-level default cannot reach a table it owns.
|
|
1932
|
+
*
|
|
1933
|
+
* Refused on a singleton list: a singleton's id is derived from
|
|
1934
|
+
* `isSingleton`, and that is the one knob.
|
|
1935
|
+
*
|
|
1936
|
+
* @example A list with a serial integer key
|
|
1937
|
+
* ```typescript
|
|
1938
|
+
* Invoice: list({
|
|
1939
|
+
* fields: { total: integer() },
|
|
1940
|
+
* db: { idField: 'int autoincrement' },
|
|
1941
|
+
* })
|
|
1942
|
+
* ```
|
|
1943
|
+
*/
|
|
1944
|
+
idField?: IdFieldStrategy;
|
|
1945
|
+
/**
|
|
1946
|
+
* Model-level unique constraints and indexes spanning one or more of
|
|
1794
1947
|
* this list's own fields (#864, #918). See the [reference
|
|
1795
1948
|
* docs](https://stack.opensaas.au/docs/reference/config-api#dbindexes)
|
|
1796
1949
|
* for the full explanation, arity, and error conditions.
|
|
1797
1950
|
*
|
|
1798
1951
|
* Field-level `isIndexed` (on a scalar or relationship field) is the
|
|
1799
1952
|
* sugar for the unnamed single-column case. `db.indexes` is the full
|
|
1800
|
-
* form — reach for it when a constraint needs a `name`
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1807
|
-
*
|
|
1953
|
+
* form — reach for it when a constraint needs a `name` or spans more
|
|
1954
|
+
* than one column. Arity is incidental: each entry names one or more of
|
|
1955
|
+
* the list's own OpenSaaS field names, not raw database column names.
|
|
1956
|
+
* The generator resolves each to its underlying column — a scalar
|
|
1957
|
+
* field's own name (unaffected by `db.map`), or a relationship field's
|
|
1958
|
+
* foreign key column (`<field>Id`) when this side owns it.
|
|
1959
|
+
*
|
|
1960
|
+
* An index column carries no sort direction (ADR-0040): a `sort` key on
|
|
1961
|
+
* an entry's field reference fails `pnpm generate` naming the list and
|
|
1962
|
+
* the entry.
|
|
1808
1963
|
*
|
|
1809
1964
|
* A **unique** entry is the load-bearing case: it's the database-level
|
|
1810
1965
|
* backstop for a business rule concurrent writes could otherwise both
|
|
@@ -1842,10 +1997,10 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1842
1997
|
* indexes: [{ fields: ['student', 'production'], unique: true }],
|
|
1843
1998
|
* },
|
|
1844
1999
|
* })
|
|
1845
|
-
* //
|
|
2000
|
+
* // Contract: a unique constraint on [studentId, productionId]
|
|
1846
2001
|
* ```
|
|
1847
2002
|
*
|
|
1848
|
-
* @example Hot lookup path (composite index) with a
|
|
2003
|
+
* @example Hot lookup path (composite index) with a name
|
|
1849
2004
|
* ```typescript
|
|
1850
2005
|
* AuthVerification: list({
|
|
1851
2006
|
* fields: {
|
|
@@ -1855,16 +2010,15 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1855
2010
|
* db: {
|
|
1856
2011
|
* indexes: [
|
|
1857
2012
|
* {
|
|
1858
|
-
* fields: ['identifier',
|
|
2013
|
+
* fields: ['identifier', 'createdAt'],
|
|
1859
2014
|
* name: 'AuthVerification_identifier_createdAt_idx',
|
|
1860
2015
|
* },
|
|
1861
2016
|
* ],
|
|
1862
2017
|
* },
|
|
1863
2018
|
* })
|
|
1864
|
-
* // Generates: @@index([identifier, createdAt(sort: Desc)], map: "AuthVerification_identifier_createdAt_idx")
|
|
1865
2019
|
* ```
|
|
1866
2020
|
*
|
|
1867
|
-
* @example Naming a single-column unique constraint
|
|
2021
|
+
* @example Naming a single-column unique constraint
|
|
1868
2022
|
* ```typescript
|
|
1869
2023
|
* RateLimit: list({
|
|
1870
2024
|
* fields: { key: text() }, // no isIndexed here — db.indexes owns this column instead
|
|
@@ -1872,7 +2026,6 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1872
2026
|
* indexes: [{ fields: ['key'], unique: true, name: 'RateLimit_key_key' }],
|
|
1873
2027
|
* },
|
|
1874
2028
|
* })
|
|
1875
|
-
* // Generates: @@unique([key], map: "RateLimit_key_key")
|
|
1876
2029
|
* // Setting key's own isIndexed too would duplicate this constraint and
|
|
1877
2030
|
* // fail generation — one of the two must own the column.
|
|
1878
2031
|
* ```
|
|
@@ -1884,9 +2037,10 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1884
2037
|
* Restricts this list to a single record (singleton pattern)
|
|
1885
2038
|
* When true:
|
|
1886
2039
|
* - Prevents creating multiple records
|
|
1887
|
-
* - Auto-creates the single record on first access (if autoCreate: true, which is the default
|
|
2040
|
+
* - Auto-creates the single record on first access (if autoCreate: true, which is the default,
|
|
2041
|
+
* and the list's `query` access rule answers a strict `true`, or the context is `sudo`)
|
|
1888
2042
|
* - Provides a get() method for easy access to the singleton
|
|
1889
|
-
* - Blocks delete and
|
|
2043
|
+
* - Blocks delete and the many-row read surface
|
|
1890
2044
|
* - Changes UI to show edit form instead of list view
|
|
1891
2045
|
*
|
|
1892
2046
|
* @example Simple boolean (auto-create enabled)
|
|
@@ -1903,7 +2057,13 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1903
2057
|
*/
|
|
1904
2058
|
isSingleton?: boolean | {
|
|
1905
2059
|
/**
|
|
1906
|
-
* Auto-create the singleton record on first access using field defaults
|
|
2060
|
+
* Auto-create the singleton record on first access using field defaults.
|
|
2061
|
+
*
|
|
2062
|
+
* Fires only for a `query` access rule that answers a strict `true`, or
|
|
2063
|
+
* under `sudo`. A rule that answers a filter, answers `false`, or is
|
|
2064
|
+
* absent makes `get()` answer `null` and write nothing — a filter-scoped
|
|
2065
|
+
* singleton needs `query: () => true` with the scoping moved onto the
|
|
2066
|
+
* fields if the row is to be auto-created.
|
|
1907
2067
|
* @default true
|
|
1908
2068
|
*/
|
|
1909
2069
|
autoCreate?: boolean;
|
|
@@ -1978,7 +2138,40 @@ export type ListUIConfig = {
|
|
|
1978
2138
|
* ```
|
|
1979
2139
|
*/
|
|
1980
2140
|
avatar?: boolean;
|
|
2141
|
+
/**
|
|
2142
|
+
* Hide every Create affordance for this list in the admin UI — the list
|
|
2143
|
+
* header, the empty state, the dashboard quick actions and a relationship
|
|
2144
|
+
* table's create drawer — and render the `/create` route as not-found.
|
|
2145
|
+
* Takes a boolean, or a function of the session resolved on the server. Only
|
|
2146
|
+
* what the UI offers changes; access control, hooks and server actions are
|
|
2147
|
+
* untouched, so a write that bypasses the UI behaves exactly as before.
|
|
2148
|
+
*
|
|
2149
|
+
* @example
|
|
2150
|
+
* ```typescript
|
|
2151
|
+
* ui: { hideCreate: ({ session }) => session?.role !== 'SUPPORT' }
|
|
2152
|
+
* ```
|
|
2153
|
+
*/
|
|
2154
|
+
hideCreate?: ListUIOption<boolean>;
|
|
2155
|
+
/**
|
|
2156
|
+
* Hide every Delete affordance for this list in the admin UI — the list view
|
|
2157
|
+
* (row and bulk) and the item view. Same shape and guarantees as
|
|
2158
|
+
* {@link ListUIConfig.hideCreate}.
|
|
2159
|
+
*
|
|
2160
|
+
* @example
|
|
2161
|
+
* ```typescript
|
|
2162
|
+
* ui: { hideDelete: true }
|
|
2163
|
+
* ```
|
|
2164
|
+
*/
|
|
2165
|
+
hideDelete?: ListUIOption<boolean>;
|
|
1981
2166
|
};
|
|
2167
|
+
/**
|
|
2168
|
+
* A list-level UI option: a literal, or a function of the live session
|
|
2169
|
+
* resolved on the server. The function never crosses to the client.
|
|
2170
|
+
*/
|
|
2171
|
+
export type ListUIOption<TValue> = TValue | ((args: {
|
|
2172
|
+
session: import('../access/types.js').AccessContext['session'];
|
|
2173
|
+
context: import('../access/types.js').AccessContext;
|
|
2174
|
+
}) => TValue | Promise<TValue>);
|
|
1982
2175
|
/**
|
|
1983
2176
|
* Item-view (record edit page) configuration, mirroring the `ui.listView`
|
|
1984
2177
|
* shape but for the shape-derived item layout (issue #734).
|
|
@@ -2001,6 +2194,18 @@ export type ItemViewUIConfig = {
|
|
|
2001
2194
|
* ```
|
|
2002
2195
|
*/
|
|
2003
2196
|
order?: string[];
|
|
2197
|
+
/**
|
|
2198
|
+
* The mode the item view renders its fields in. `'read'` renders every field
|
|
2199
|
+
* read-only with no Save action; relationship sections still render. Takes a
|
|
2200
|
+
* value, or a function of the session resolved on the server. Defaults to
|
|
2201
|
+
* `'edit'`. UI-only: access control and server actions are unchanged.
|
|
2202
|
+
*
|
|
2203
|
+
* @example
|
|
2204
|
+
* ```typescript
|
|
2205
|
+
* ui: { itemView: { defaultFieldMode: 'read' } }
|
|
2206
|
+
* ```
|
|
2207
|
+
*/
|
|
2208
|
+
defaultFieldMode?: ListUIOption<'edit' | 'read'>;
|
|
2004
2209
|
};
|
|
2005
2210
|
/**
|
|
2006
2211
|
* A button variant for a custom Bulk action, matching the admin UI's Button
|
|
@@ -2138,7 +2343,7 @@ export type ListViewUIConfig = {
|
|
|
2138
2343
|
* handler: async ({ ids, context }) => {
|
|
2139
2344
|
* let n = 0
|
|
2140
2345
|
* for (const id of ids) {
|
|
2141
|
-
* const r = await context.db.
|
|
2346
|
+
* const r = await context.db.Post.update({
|
|
2142
2347
|
* where: { id },
|
|
2143
2348
|
* data: { status: 'published' },
|
|
2144
2349
|
* })
|
|
@@ -2175,84 +2380,131 @@ export type ListConfigInput<TTypeInfo extends TypeInfo> = Omit<ListConfig<TTypeI
|
|
|
2175
2380
|
*/
|
|
2176
2381
|
access?: ListAccessControl<TTypeInfo['item']>;
|
|
2177
2382
|
};
|
|
2178
|
-
|
|
2179
|
-
|
|
2383
|
+
/**
|
|
2384
|
+
* How a list's `id` column is minted (ADR-0048). Every list carries a single
|
|
2385
|
+
* `id` column; this picks its shape.
|
|
2386
|
+
*
|
|
2387
|
+
* - `'uuid7'` — time-sortable UUID, minted by the ORM. The default.
|
|
2388
|
+
* - `'cuid2'` — CUID, minted by the ORM.
|
|
2389
|
+
* - `'cuid'` — a `text` column minted as cuid2. Use it to adopt a database whose
|
|
2390
|
+
* ids are `text` holding cuid v1 values; existing values are left alone.
|
|
2391
|
+
* - `'int autoincrement'` — a serial integer key.
|
|
2392
|
+
*
|
|
2393
|
+
* A singleton list derives its id from `isSingleton` and refuses this option.
|
|
2394
|
+
*/
|
|
2395
|
+
export type IdFieldStrategy = 'uuid7' | 'cuid2' | 'cuid' | 'int autoincrement';
|
|
2396
|
+
/**
|
|
2397
|
+
* A Prisma extension pack the contract declares (ADR-0049, ADR-0065). An
|
|
2398
|
+
* import descriptor rather than a pack value: the generated contract module is
|
|
2399
|
+
* standalone and fully literal, so it re-emits `from` as an import instead of
|
|
2400
|
+
* serialising an object out of the config.
|
|
2401
|
+
*/
|
|
2402
|
+
export type ExtensionDescriptor = {
|
|
2180
2403
|
/**
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
2183
|
-
*
|
|
2184
|
-
|
|
2404
|
+
* The pack's binding name — the key that spells its types on a field
|
|
2405
|
+
* (`type.pgvector.Vector(n)`), and the identity two declarations are merged
|
|
2406
|
+
* on. The same `name` declared twice with a different `from` is refused.
|
|
2407
|
+
*/
|
|
2408
|
+
name: string;
|
|
2409
|
+
/**
|
|
2410
|
+
* The pack's package name (e.g. `'@prisma/orm-extension-pgvector'`). The
|
|
2411
|
+
* generator derives the `/pack`, `/control` and `/runtime` subpaths per
|
|
2412
|
+
* emission.
|
|
2413
|
+
*/
|
|
2414
|
+
from: string;
|
|
2415
|
+
};
|
|
2416
|
+
type PostgresBindingOptions = PostgresOptions<never>;
|
|
2417
|
+
/**
|
|
2418
|
+
* Per-deployment pool binding for the generated runtime client (ADR-0049,
|
|
2419
|
+
* ADR-0054). Nothing here reaches the contract; it is read only by the
|
|
2420
|
+
* generated `.opensaas/context.ts` when it constructs the client.
|
|
2421
|
+
*/
|
|
2422
|
+
export type DatabaseClientConfig = {
|
|
2423
|
+
/**
|
|
2424
|
+
* Pool options handed to the ORM client as-is when no `pg` factory is
|
|
2425
|
+
* given.
|
|
2426
|
+
*/
|
|
2427
|
+
poolOptions?: PostgresOptionsBase['poolOptions'];
|
|
2428
|
+
/**
|
|
2429
|
+
* A lazy factory for the `pg` pool or client the runtime should bind to.
|
|
2430
|
+
* A factory, not an instance: the config is loaded by the CLI and by tooling
|
|
2431
|
+
* that never issues a query, and none of it should open a connection. Called
|
|
2432
|
+
* at most once, after the config promise resolves, under the runtime's
|
|
2433
|
+
* client singleton.
|
|
2185
2434
|
*
|
|
2186
|
-
* @example
|
|
2435
|
+
* @example Serverless Postgres over a WebSocket pool
|
|
2187
2436
|
* ```typescript
|
|
2188
|
-
* import {
|
|
2437
|
+
* import { Pool, neonConfig } from '@neondatabase/serverless'
|
|
2438
|
+
* import ws from 'ws'
|
|
2189
2439
|
*
|
|
2190
|
-
*
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2440
|
+
* db: {
|
|
2441
|
+
* provider: 'postgresql',
|
|
2442
|
+
* client: {
|
|
2443
|
+
* pg: () => {
|
|
2444
|
+
* neonConfig.webSocketConstructor = ws
|
|
2445
|
+
* return new Pool({ connectionString: process.env.DATABASE_URL })
|
|
2446
|
+
* },
|
|
2447
|
+
* },
|
|
2193
2448
|
* }
|
|
2194
2449
|
* ```
|
|
2450
|
+
*/
|
|
2451
|
+
pg?: () => NonNullable<PostgresBindingOptions['pg']>;
|
|
2452
|
+
};
|
|
2453
|
+
export type DatabaseConfig = {
|
|
2454
|
+
/**
|
|
2455
|
+
* The database the stack targets. Postgres only.
|
|
2456
|
+
*/
|
|
2457
|
+
provider: 'postgresql';
|
|
2458
|
+
/**
|
|
2459
|
+
* The id strategy every list gets unless it declares its own
|
|
2460
|
+
* `db.idField` (ADR-0048).
|
|
2195
2461
|
*
|
|
2196
|
-
* @
|
|
2197
|
-
* ```typescript
|
|
2198
|
-
* import { PrismaPg } from '@prisma/adapter-pg'
|
|
2199
|
-
* import pg from 'pg'
|
|
2200
|
-
*
|
|
2201
|
-
* prismaClientConstructor: (PrismaClient) => {
|
|
2202
|
-
* const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
|
2203
|
-
* const adapter = new PrismaPg(pool)
|
|
2204
|
-
* return new PrismaClient({ adapter })
|
|
2205
|
-
* }
|
|
2206
|
-
* ```
|
|
2462
|
+
* @default 'uuid7'
|
|
2207
2463
|
*
|
|
2208
|
-
* @example
|
|
2464
|
+
* @example Small integer keys across the whole app
|
|
2209
2465
|
* ```typescript
|
|
2210
|
-
*
|
|
2211
|
-
*
|
|
2212
|
-
*
|
|
2213
|
-
*
|
|
2214
|
-
* prismaClientConstructor: (PrismaClient) => {
|
|
2215
|
-
* neonConfig.webSocketConstructor = ws
|
|
2216
|
-
* const adapter = new PrismaNeon({
|
|
2217
|
-
* connectionString: process.env.DATABASE_URL
|
|
2218
|
-
* })
|
|
2219
|
-
* return new PrismaClient({ adapter })
|
|
2466
|
+
* db: {
|
|
2467
|
+
* provider: 'postgresql',
|
|
2468
|
+
* idField: 'int autoincrement',
|
|
2220
2469
|
* }
|
|
2221
2470
|
* ```
|
|
2222
2471
|
*/
|
|
2223
|
-
|
|
2472
|
+
idField?: IdFieldStrategy;
|
|
2224
2473
|
/**
|
|
2225
|
-
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
2229
|
-
*
|
|
2474
|
+
* Extension packs the contract declares (ADR-0049). Each descriptor names a
|
|
2475
|
+
* package; one declaration drives the contract module, `prisma.config.ts`,
|
|
2476
|
+
* the runtime client and the pack's extension contract space under
|
|
2477
|
+
* `migrations/`. A plugin adds its own through
|
|
2478
|
+
* {@link PluginContext.addExtension}.
|
|
2230
2479
|
*
|
|
2231
|
-
*
|
|
2232
|
-
*
|
|
2233
|
-
* and avoid data loss. Keystone names join tables as `_Model_fieldName` based on where the
|
|
2234
|
-
* relationship is defined in the schema.
|
|
2480
|
+
* Two entries with the same `name` are one declaration when their `from`
|
|
2481
|
+
* agrees and a config error when it does not.
|
|
2235
2482
|
*
|
|
2236
|
-
* @example
|
|
2483
|
+
* @example Declare pgvector for a native vector column
|
|
2237
2484
|
* ```typescript
|
|
2238
2485
|
* db: {
|
|
2239
2486
|
* provider: 'postgresql',
|
|
2240
|
-
*
|
|
2241
|
-
* // ... rest of config
|
|
2487
|
+
* extensions: [{ name: 'pgvector', from: '@prisma/orm-extension-pgvector' }],
|
|
2242
2488
|
* }
|
|
2243
2489
|
* ```
|
|
2244
2490
|
*/
|
|
2245
|
-
|
|
2491
|
+
extensions?: ExtensionDescriptor[];
|
|
2492
|
+
/**
|
|
2493
|
+
* Pool binding for the generated runtime client — see
|
|
2494
|
+
* {@link DatabaseClientConfig}. Omit it to let the runtime open its own pool
|
|
2495
|
+
* from the resolved database URL.
|
|
2496
|
+
*/
|
|
2497
|
+
client?: DatabaseClientConfig;
|
|
2246
2498
|
/**
|
|
2247
2499
|
* Postgres multi-schema support.
|
|
2248
2500
|
*
|
|
2249
|
-
* When set, the
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2252
|
-
* schema
|
|
2501
|
+
* When set, the contract's `namespaces` collects these schemas (unioned
|
|
2502
|
+
* with every `db.schema` a list uses — see {@link ListConfig}) and Prisma
|
|
2503
|
+
* resolves each model's `namespace` against that list. Combine with a
|
|
2504
|
+
* per-list `db.schema` to place a model in a specific schema.
|
|
2253
2505
|
*
|
|
2254
|
-
* Only applies to the `postgresql` provider. When unset,
|
|
2255
|
-
*
|
|
2506
|
+
* Only applies to the `postgresql` provider. When unset, every model stays
|
|
2507
|
+
* in the default `public` schema.
|
|
2256
2508
|
*
|
|
2257
2509
|
* @example Separate `auth` schema alongside the default `public`
|
|
2258
2510
|
* ```typescript
|
|
@@ -2272,16 +2524,14 @@ export type DatabaseConfig = {
|
|
|
2272
2524
|
* Keystone 6, which never adds timestamps automatically, and keeps Keystone → stack
|
|
2273
2525
|
* migrations non-destructive (Schema parity). See ADR-0004.
|
|
2274
2526
|
*
|
|
2275
|
-
* When `true`, every list receives
|
|
2276
|
-
*
|
|
2277
|
-
*
|
|
2278
|
-
* updatedAt DateTime @default(now()) @updatedAt
|
|
2279
|
-
* ```
|
|
2527
|
+
* When `true`, every list receives a `createdAt` column (a database `now()`
|
|
2528
|
+
* default) and an `updatedAt` column, maintained application-side with no
|
|
2529
|
+
* database backstop (ADR-0048).
|
|
2280
2530
|
*
|
|
2281
2531
|
* A per-list `db.timestamps` override takes precedence over this global setting. When
|
|
2282
2532
|
* timestamps are enabled but a list already declares its own `createdAt`/`updatedAt`
|
|
2283
|
-
* field, the auto column is skipped for the declared field(s) so
|
|
2284
|
-
* duplicate
|
|
2533
|
+
* field, the auto column is skipped for the declared field(s) so the contract never
|
|
2534
|
+
* carries a duplicate column.
|
|
2285
2535
|
*
|
|
2286
2536
|
* @default false
|
|
2287
2537
|
*
|
|
@@ -2295,27 +2545,61 @@ export type DatabaseConfig = {
|
|
|
2295
2545
|
* ```
|
|
2296
2546
|
*/
|
|
2297
2547
|
timestamps?: boolean;
|
|
2548
|
+
/**
|
|
2549
|
+
* Name every derived index, unique constraint and foreign key the way Prisma 7
|
|
2550
|
+
* did (`<Table>_<cols>_idx`, `_key`, `_fkey`, truncated to 63 bytes), so a plan
|
|
2551
|
+
* against a database Prisma 7 created shows no renames. Turning this on for a database
|
|
2552
|
+
* already migrated under Prisma 8's default names renames every index and foreign key.
|
|
2553
|
+
* Primary-key names are not affected. An explicit `name` on a
|
|
2554
|
+
* `db.indexes` entry still wins. Unset, Prisma 8's own derived names apply.
|
|
2555
|
+
*
|
|
2556
|
+
* @example
|
|
2557
|
+
* ```typescript
|
|
2558
|
+
* db: { provider: 'postgresql', indexNaming: 'prisma7' }
|
|
2559
|
+
* ```
|
|
2560
|
+
*/
|
|
2561
|
+
indexNaming?: 'prisma7';
|
|
2298
2562
|
/**
|
|
2299
2563
|
* Opt into Keystone-compat mode for generated schema defaults.
|
|
2300
2564
|
*
|
|
2301
2565
|
* Keystone 6 gives every non-null text column an implicit empty-string
|
|
2302
|
-
* default. With `keystoneCompat: true`, the
|
|
2303
|
-
* non-null `text()` column that has no explicit `defaultValue`
|
|
2304
|
-
*
|
|
2305
|
-
*
|
|
2566
|
+
* default. With `keystoneCompat: true`, the contract mirrors that: a
|
|
2567
|
+
* non-null `text()` column that has no explicit `defaultValue` carries `''`,
|
|
2568
|
+
* so a migrating project reaches schema parity without hand-setting
|
|
2569
|
+
* `defaultValue: ''` on dozens of columns.
|
|
2306
2570
|
*
|
|
2307
2571
|
* Stays opt-in (default `false`) because a greenfield project would not want
|
|
2308
2572
|
* implicit empty-string text defaults cluttering its schema. The flag never
|
|
2309
2573
|
* affects nullable text, fields with an explicit `defaultValue`, or any
|
|
2310
2574
|
* non-text field — an explicit `text({ defaultValue: 'x' })` always wins.
|
|
2311
2575
|
*
|
|
2576
|
+
* A column default also makes the column optional on the generated create
|
|
2577
|
+
* input, so the compat default is carried only where the field's own create
|
|
2578
|
+
* validator accepts both the omission it fills and `''` itself — the same
|
|
2579
|
+
* verdict an explicit `defaultValue: ''` reaches through
|
|
2580
|
+
* `applyCreateDefaults`.
|
|
2581
|
+
*
|
|
2582
|
+
* **Known limit — the flag is inert for `validation: { isRequired: true }`
|
|
2583
|
+
* and for `validation: { length: { min: N } }` with `N > 0`, and
|
|
2584
|
+
* `isRequired` is Keystone's commonest text column.** Keystone 6 renders
|
|
2585
|
+
* both as `NOT NULL DEFAULT ''`, but here `''` is a value the field's own
|
|
2586
|
+
* validator refuses (and `isRequired` refuses the omission besides), so
|
|
2587
|
+
* carrying the default would write a row the config forbids. Full parity
|
|
2588
|
+
* would need the flag to relax the create validator too, which
|
|
2589
|
+
* `getZodSchema` has no config to read. Until then a migrating project sees
|
|
2590
|
+
* `DROP DEFAULT` in `prisma db update --dry-run` for those columns and must set
|
|
2591
|
+
* `defaultValue: ''` on them by hand — which is refused at runtime for the
|
|
2592
|
+
* same reason, so the validation has to be relaxed alongside it. A column
|
|
2593
|
+
* made non-null through `db: { isNullable: false }` alone still gets the
|
|
2594
|
+
* default, as does one declaring `length: { min: 0 }` or a `length.max`.
|
|
2595
|
+
*
|
|
2312
2596
|
* @default false
|
|
2313
2597
|
*
|
|
2314
|
-
* @example Reach
|
|
2598
|
+
* @example Reach schema parity when migrating from Keystone
|
|
2315
2599
|
* ```typescript
|
|
2316
2600
|
* db: {
|
|
2317
2601
|
* provider: 'postgresql',
|
|
2318
|
-
* keystoneCompat: true, // non-null text without a default →
|
|
2602
|
+
* keystoneCompat: true, // non-null text without a default → default ''
|
|
2319
2603
|
* // ... rest of config
|
|
2320
2604
|
* }
|
|
2321
2605
|
* ```
|
|
@@ -2323,37 +2607,6 @@ export type DatabaseConfig = {
|
|
|
2323
2607
|
* @see ADR-0004 (Keystone-compatible generator defaults)
|
|
2324
2608
|
*/
|
|
2325
2609
|
keystoneCompat?: boolean;
|
|
2326
|
-
/**
|
|
2327
|
-
* Optional function to extend or modify the generated Prisma schema
|
|
2328
|
-
* Receives the generated schema as a string and should return the modified schema
|
|
2329
|
-
* Useful for advanced Prisma features not directly supported by the config API
|
|
2330
|
-
*
|
|
2331
|
-
* @example Add multi-schema support for PostgreSQL
|
|
2332
|
-
* ```typescript
|
|
2333
|
-
* extendPrismaSchema: (schema) => {
|
|
2334
|
-
* // Add schemas array to datasource
|
|
2335
|
-
* let modifiedSchema = schema
|
|
2336
|
-
* .replace(
|
|
2337
|
-
* /(datasource db \{[^}]+provider\s*=\s*"postgresql")/,
|
|
2338
|
-
* '$1\n schemas = ["public", "auth"]'
|
|
2339
|
-
* )
|
|
2340
|
-
*
|
|
2341
|
-
* // Add @@schema("public") to all models
|
|
2342
|
-
* modifiedSchema = modifiedSchema.replace(
|
|
2343
|
-
* /^(model \w+\s*\{[\s\S]*?)(^}$)/gm,
|
|
2344
|
-
* (match, modelContent) => {
|
|
2345
|
-
* if (!modelContent.includes('@@schema')) {
|
|
2346
|
-
* return `${modelContent}\n @@schema("public")\n}`
|
|
2347
|
-
* }
|
|
2348
|
-
* return match
|
|
2349
|
-
* }
|
|
2350
|
-
* )
|
|
2351
|
-
*
|
|
2352
|
-
* return modifiedSchema
|
|
2353
|
-
* }
|
|
2354
|
-
* ```
|
|
2355
|
-
*/
|
|
2356
|
-
extendPrismaSchema?: (schema: string) => string;
|
|
2357
2610
|
/**
|
|
2358
2611
|
* Override the Prisma `generator client { ... }` options the CLI emits for the
|
|
2359
2612
|
* `.opensaas` prisma-client subtree.
|
|
@@ -2482,9 +2735,35 @@ export type ThemeConfig = {
|
|
|
2482
2735
|
*/
|
|
2483
2736
|
shadows?: ThemeShadows;
|
|
2484
2737
|
};
|
|
2738
|
+
export type ActionErrorClassification = {
|
|
2739
|
+
code: string;
|
|
2740
|
+
message: string;
|
|
2741
|
+
};
|
|
2485
2742
|
export type UIConfig = {
|
|
2486
2743
|
basePath?: string;
|
|
2487
2744
|
theme?: ThemeConfig;
|
|
2745
|
+
/**
|
|
2746
|
+
* Maps an error thrown during a server action to a typed failure, applied
|
|
2747
|
+
* before the stack's default mapping. When it returns a value, the action
|
|
2748
|
+
* resolves `{ success: false, error: message, code }`. Returning `undefined`,
|
|
2749
|
+
* or throwing (the throw is logged, never surfaced), falls through to the
|
|
2750
|
+
* default mapping.
|
|
2751
|
+
*
|
|
2752
|
+
* @example
|
|
2753
|
+
* ```typescript
|
|
2754
|
+
* config({
|
|
2755
|
+
* db: { provider: 'postgresql' },
|
|
2756
|
+
* lists: {},
|
|
2757
|
+
* ui: {
|
|
2758
|
+
* classifyActionError: (error) =>
|
|
2759
|
+
* error instanceof ClaimConflict
|
|
2760
|
+
* ? { code: 'CLAIM_CONFLICT', message: 'Reload and try again.' }
|
|
2761
|
+
* : undefined,
|
|
2762
|
+
* },
|
|
2763
|
+
* })
|
|
2764
|
+
* ```
|
|
2765
|
+
*/
|
|
2766
|
+
classifyActionError?: (error: unknown) => ActionErrorClassification | undefined;
|
|
2488
2767
|
};
|
|
2489
2768
|
/**
|
|
2490
2769
|
* MCP (Model Context Protocol) configuration
|
|
@@ -2524,6 +2803,17 @@ export type McpCustomTool = {
|
|
|
2524
2803
|
*/
|
|
2525
2804
|
name: string;
|
|
2526
2805
|
description: string;
|
|
2806
|
+
/**
|
|
2807
|
+
* OAuth scopes the session's token must carry to see or call this tool.
|
|
2808
|
+
* A token missing any of them gets a tool error naming them, and the tool is
|
|
2809
|
+
* left out of `tools/list`.
|
|
2810
|
+
*
|
|
2811
|
+
* On a list custom tool, omitting this requires the configured write scope
|
|
2812
|
+
* (`mcp.scopes.write`, or the list's own override) when scopes are
|
|
2813
|
+
* configured, and nothing otherwise. Pass `[]` to opt out explicitly.
|
|
2814
|
+
* A plugin-registered tool with no scopes requires nothing.
|
|
2815
|
+
*/
|
|
2816
|
+
scopes?: string[];
|
|
2527
2817
|
/**
|
|
2528
2818
|
* Input schema (Zod schema)
|
|
2529
2819
|
*/
|
|
@@ -2533,12 +2823,32 @@ export type McpCustomTool = {
|
|
|
2533
2823
|
context: import('../access/types.js').AccessContext;
|
|
2534
2824
|
}) => Promise<unknown>;
|
|
2535
2825
|
};
|
|
2826
|
+
/**
|
|
2827
|
+
* OAuth scopes gating the CRUD tools. `read` gates `query`; `write` gates
|
|
2828
|
+
* `create`, `update` and `delete`. Scopes are only enforced where configured.
|
|
2829
|
+
*
|
|
2830
|
+
* @example
|
|
2831
|
+
* ```typescript
|
|
2832
|
+
* mcp: { enabled: true, scopes: { read: 'mcp:read', write: ['mcp:write'] } }
|
|
2833
|
+
* ```
|
|
2834
|
+
*/
|
|
2835
|
+
export type McpScopesConfig = {
|
|
2836
|
+
/** Scope(s) a token must carry to call `query` tools */
|
|
2837
|
+
read?: string | string[];
|
|
2838
|
+
/** Scope(s) a token must carry to call `create`, `update` and `delete` tools */
|
|
2839
|
+
write?: string | string[];
|
|
2840
|
+
};
|
|
2536
2841
|
export type ListMcpConfig = {
|
|
2537
2842
|
/**
|
|
2538
2843
|
* Enable MCP tools for this list
|
|
2539
2844
|
* @default true
|
|
2540
2845
|
*/
|
|
2541
2846
|
enabled?: boolean;
|
|
2847
|
+
/**
|
|
2848
|
+
* Scopes required by this list's CRUD tools. Each of `read` and `write`
|
|
2849
|
+
* set here takes precedence over the config-level `mcp.scopes`.
|
|
2850
|
+
*/
|
|
2851
|
+
scopes?: McpScopesConfig;
|
|
2542
2852
|
/**
|
|
2543
2853
|
* Configure which CRUD tools to enable
|
|
2544
2854
|
*/
|
|
@@ -2626,6 +2936,11 @@ export type McpConfig = {
|
|
|
2626
2936
|
* Can be overridden per-list
|
|
2627
2937
|
*/
|
|
2628
2938
|
defaultTools?: McpToolsConfig;
|
|
2939
|
+
/**
|
|
2940
|
+
* OAuth scopes the session's token must carry for CRUD tools. Not enforced
|
|
2941
|
+
* unless configured. Overridable per list with `list.mcp.scopes`.
|
|
2942
|
+
*/
|
|
2943
|
+
scopes?: McpScopesConfig;
|
|
2629
2944
|
/**
|
|
2630
2945
|
* Resource identifier for OAuth protected resource metadata
|
|
2631
2946
|
* @default "https://yourdomain.com"
|
|
@@ -2690,6 +3005,15 @@ export interface ImageTransformationResult {
|
|
|
2690
3005
|
height: number;
|
|
2691
3006
|
/** File size in bytes */
|
|
2692
3007
|
size: number;
|
|
3008
|
+
/**
|
|
3009
|
+
* The storage key the provider's own `upload()` returned for this
|
|
3010
|
+
* transformation. Cleanup deletes by this key, never by parsing `url` —
|
|
3011
|
+
* a stored `url` is not a trustworthy source of a storage key (issue
|
|
3012
|
+
* #1619). Optional so a value written before this field existed still
|
|
3013
|
+
* type-checks; such a row's transformations are left undeleted by cleanup
|
|
3014
|
+
* rather than deleted by a parsed guess.
|
|
3015
|
+
*/
|
|
3016
|
+
filename?: string;
|
|
2693
3017
|
}
|
|
2694
3018
|
export type StorageConfig = Record<string, {
|
|
2695
3019
|
type: string;
|
|
@@ -2703,7 +3027,7 @@ export type StorageConfig = Record<string, {
|
|
|
2703
3027
|
* Plugins can modify these during afterGenerate hooks
|
|
2704
3028
|
*/
|
|
2705
3029
|
export type GeneratedFiles = {
|
|
2706
|
-
|
|
3030
|
+
contractModule: string;
|
|
2707
3031
|
types: string;
|
|
2708
3032
|
context: string;
|
|
2709
3033
|
[key: string]: string;
|
|
@@ -2748,6 +3072,20 @@ export type PluginContext = {
|
|
|
2748
3072
|
* Tools are added to the global MCP server
|
|
2749
3073
|
*/
|
|
2750
3074
|
registerMcpTool?: (tool: McpCustomTool) => void;
|
|
3075
|
+
/**
|
|
3076
|
+
* Declare an extension pack the plugin's field types need (ADR-0049), as
|
|
3077
|
+
* if the app had listed it under `db.extensions`. Idempotent when the
|
|
3078
|
+
* config already declares the same `name` from the same package; throws
|
|
3079
|
+
* when it declares that `name` from a different one.
|
|
3080
|
+
*
|
|
3081
|
+
* @example
|
|
3082
|
+
* ```typescript
|
|
3083
|
+
* init: async (context) => {
|
|
3084
|
+
* context.addExtension({ name: 'pgvector', from: '@prisma/orm-extension-pgvector' })
|
|
3085
|
+
* }
|
|
3086
|
+
* ```
|
|
3087
|
+
*/
|
|
3088
|
+
addExtension: (descriptor: ExtensionDescriptor) => void;
|
|
2751
3089
|
/**
|
|
2752
3090
|
* Store plugin-specific data in config for runtime access
|
|
2753
3091
|
* Prefixed with plugin name to avoid conflicts
|
|
@@ -2778,13 +3116,19 @@ export type Plugin = {
|
|
|
2778
3116
|
*/
|
|
2779
3117
|
init: (context: PluginContext) => void | Promise<void>;
|
|
2780
3118
|
/**
|
|
2781
|
-
* Optional: Modify config before
|
|
3119
|
+
* Optional: Modify config before contract generation
|
|
2782
3120
|
* Useful for programmatic config transformations
|
|
2783
3121
|
*/
|
|
2784
3122
|
beforeGenerate?: (config: OpenSaasConfig) => OpenSaasConfig | Promise<OpenSaasConfig>;
|
|
2785
3123
|
/**
|
|
2786
3124
|
* Optional: Post-process generated files
|
|
2787
|
-
* Allows plugins to modify
|
|
3125
|
+
* Allows plugins to modify the Contract module, types, or add custom generated files
|
|
3126
|
+
*
|
|
3127
|
+
* Runs before `prisma contract emit`, so a rewritten `contractModule` is the
|
|
3128
|
+
* one the emitted `contract.json` / `contract.d.ts` describe and the one the
|
|
3129
|
+
* relation-graph agreement gate checks. A rewrite that the contract toolchain
|
|
3130
|
+
* rejects therefore fails `opensaas generate` rather than landing on disk
|
|
3131
|
+
* unemitted.
|
|
2788
3132
|
*/
|
|
2789
3133
|
afterGenerate?: (files: GeneratedFiles) => GeneratedFiles | Promise<GeneratedFiles>;
|
|
2790
3134
|
/**
|
|
@@ -2792,7 +3136,7 @@ export type Plugin = {
|
|
|
2792
3136
|
* Called when creating context to provide plugin-specific services
|
|
2793
3137
|
* Return value is stored in context.plugins[pluginName]
|
|
2794
3138
|
*
|
|
2795
|
-
* `sudo` returns an access-bypassing (but still hook-firing) `
|
|
3139
|
+
* `sudo` returns an access-bypassing (but still hook-firing) `StackContext`
|
|
2796
3140
|
* for the same request — use `sudo().db` for reads/writes that must not
|
|
2797
3141
|
* depend on the caller's own list access policy (e.g. an identity lookup
|
|
2798
3142
|
* like "who is this session"). Deliberately NOT a method on `AccessContext`
|
|
@@ -2801,8 +3145,14 @@ export type Plugin = {
|
|
|
2801
3145
|
* of unrelated generated Prisma types elsewhere (nullable JSON `CreateInput`
|
|
2802
3146
|
* fields) in a downstream app; passing it as a plain second argument avoids
|
|
2803
3147
|
* that recursion entirely.
|
|
3148
|
+
*
|
|
3149
|
+
* It is a `StackContext`, not the `AccessContext` of the first argument:
|
|
3150
|
+
* the two differ, and the difference bites. `StackContext` omits
|
|
3151
|
+
* `ormHandle`, `_isSudo`'s internal companions and `_config`, so a core
|
|
3152
|
+
* surface that needs the engine's own plumbing — `writePluginOwnedField`,
|
|
3153
|
+
* say — takes the first argument, never this one (ADR-0068).
|
|
2804
3154
|
*/
|
|
2805
|
-
runtime?: (context: import('../access/types.js').AccessContext, sudo: () => import('../
|
|
3155
|
+
runtime?: (context: import('../access/types.js').AccessContext, sudo: () => import('../types/context.js').StackContext) => unknown;
|
|
2806
3156
|
/**
|
|
2807
3157
|
* Optional: Type metadata for runtime services
|
|
2808
3158
|
* Enables type-safe code generation for context.plugins
|
|
@@ -2831,62 +3181,37 @@ export type Plugin = {
|
|
|
2831
3181
|
/**
|
|
2832
3182
|
* Configurable generator output locations.
|
|
2833
3183
|
*
|
|
2834
|
-
* Lets a project relocate the generated
|
|
3184
|
+
* Lets a project relocate the generated Contract module and the `.opensaas`
|
|
2835
3185
|
* bundle directory. Paths are interpreted relative to the project root.
|
|
2836
3186
|
*
|
|
2837
3187
|
* @example
|
|
2838
3188
|
* ```typescript
|
|
2839
3189
|
* output: {
|
|
2840
|
-
*
|
|
3190
|
+
* contractModule: 'prisma-opensaas/contract.ts',
|
|
2841
3191
|
* opensaasDir: '.opensaas',
|
|
2842
3192
|
* }
|
|
2843
3193
|
* ```
|
|
2844
3194
|
*/
|
|
2845
3195
|
export interface OutputConfig {
|
|
2846
3196
|
/**
|
|
2847
|
-
* Path to the generated
|
|
2848
|
-
*
|
|
3197
|
+
* Path to the generated Contract module. `contract.json` and `contract.d.ts`
|
|
3198
|
+
* are emitted into its directory, and `prisma.config.ts` points at it.
|
|
3199
|
+
* @default "prisma/contract.ts"
|
|
2849
3200
|
*/
|
|
2850
|
-
|
|
3201
|
+
contractModule?: string;
|
|
2851
3202
|
/**
|
|
2852
|
-
* Directory for the generated `.opensaas` bundle (types, lists, context
|
|
2853
|
-
* plugin
|
|
3203
|
+
* Directory for the generated `.opensaas` bundle (types, lists, context and
|
|
3204
|
+
* plugin types).
|
|
2854
3205
|
* @default ".opensaas"
|
|
2855
3206
|
*/
|
|
2856
3207
|
opensaasDir?: string;
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
* runtime (e.g. better-auth's Prisma adapter, imported by the Next server AND
|
|
2865
|
-
* by a Playwright e2e helper or a build-time script) has no Node-loadable
|
|
2866
|
-
* entry to point at.
|
|
2867
|
-
*
|
|
2868
|
-
* Setting `buildTarget: 'node'` additionally compiles the bundle to a
|
|
2869
|
-
* plain-Node-loadable ESM form under `<opensaasDir>/dist/` (`.js` + `.d.ts`,
|
|
2870
|
-
* with a `{"type":"module"}` marker). The compiled entry is
|
|
2871
|
-
* `<opensaasDir>/dist/context.js`; a portable module imports it directly so
|
|
2872
|
-
* the bundler traces it AND plain Node executes it (one specifier, both
|
|
2873
|
-
* runtimes — see ADR-0011). The default `.ts` form is unchanged and still
|
|
2874
|
-
* emitted; the Node build is purely additive.
|
|
2875
|
-
*
|
|
2876
|
-
* `'node'` is the only target today. The field is a string-literal union so
|
|
2877
|
-
* future compiled targets can be added without a breaking change.
|
|
2878
|
-
*
|
|
2879
|
-
* @example
|
|
2880
|
-
* ```typescript
|
|
2881
|
-
* export default config({
|
|
2882
|
-
* output: { buildTarget: 'node' },
|
|
2883
|
-
* // ...
|
|
2884
|
-
* })
|
|
2885
|
-
* // Then import the compiled entry from a plain-Node consumer:
|
|
2886
|
-
* // const { rawOpensaasContext } = await import('./.opensaas/dist/context.js')
|
|
2887
|
-
* ```
|
|
2888
|
-
*/
|
|
2889
|
-
buildTarget?: 'node';
|
|
3208
|
+
}
|
|
3209
|
+
/** What {@link OpenSaasConfig.onAfterTransactionError} receives for one failed `afterTransaction` hook. */
|
|
3210
|
+
export interface AfterTransactionErrorReport {
|
|
3211
|
+
error: unknown;
|
|
3212
|
+
status: 'committed' | 'rolled-back';
|
|
3213
|
+
listKey: string;
|
|
3214
|
+
operation: 'create' | 'update' | 'delete';
|
|
2890
3215
|
}
|
|
2891
3216
|
/**
|
|
2892
3217
|
* Main configuration type.
|
|
@@ -2894,6 +3219,25 @@ export interface OutputConfig {
|
|
|
2894
3219
|
*/
|
|
2895
3220
|
export interface OpenSaasConfig {
|
|
2896
3221
|
db: DatabaseConfig;
|
|
3222
|
+
/**
|
|
3223
|
+
* Receives every error an `afterTransaction` hook throws. Such an error never
|
|
3224
|
+
* changes the write's or transaction's result: a committed write resolves and
|
|
3225
|
+
* a rolled-back one still rejects with its own error. Called once per failed
|
|
3226
|
+
* hook. When unset, or when this callback itself throws, the error is written
|
|
3227
|
+
* to `console.error`.
|
|
3228
|
+
*
|
|
3229
|
+
* @example
|
|
3230
|
+
* ```typescript
|
|
3231
|
+
* config({
|
|
3232
|
+
* db: { provider: 'postgresql' },
|
|
3233
|
+
* lists: {},
|
|
3234
|
+
* onAfterTransactionError: ({ error, status, listKey, operation }) => {
|
|
3235
|
+
* logger.error({ error, status, listKey, operation }, 'afterTransaction failed')
|
|
3236
|
+
* },
|
|
3237
|
+
* })
|
|
3238
|
+
* ```
|
|
3239
|
+
*/
|
|
3240
|
+
onAfterTransactionError?: (report: AfterTransactionErrorReport) => void | Promise<void>;
|
|
2897
3241
|
lists: Record<string, ListConfig<any>>;
|
|
2898
3242
|
session?: SessionConfig;
|
|
2899
3243
|
ui?: UIConfig;
|
|
@@ -2916,13 +3260,13 @@ export interface OpenSaasConfig {
|
|
|
2916
3260
|
* existing `prisma/` directory (e.g. during a Keystone → stack migration).
|
|
2917
3261
|
*
|
|
2918
3262
|
* Both fields are resolved relative to the project root (the directory the
|
|
2919
|
-
* CLI runs in). When omitted, defaults are unchanged: the
|
|
2920
|
-
* `prisma/
|
|
3263
|
+
* CLI runs in). When omitted, defaults are unchanged: the Contract module is
|
|
3264
|
+
* written to `prisma/contract.ts` and the `.opensaas` bundle to `.opensaas/`.
|
|
2921
3265
|
*
|
|
2922
3266
|
* The generated files' cross-references follow these locations — `context.ts`
|
|
2923
3267
|
* imports the generated types/lists from the resolved `.opensaas` dir, and the
|
|
2924
|
-
* top-level `prisma.config.ts` points at the configured
|
|
2925
|
-
* `prisma` CLI keeps working.
|
|
3268
|
+
* top-level `prisma.config.ts` points at the configured Contract module path
|
|
3269
|
+
* so the `prisma` CLI keeps working.
|
|
2926
3270
|
*/
|
|
2927
3271
|
output?: OutputConfig;
|
|
2928
3272
|
/**
|
|
@@ -2942,6 +3286,14 @@ export interface OpenSaasConfig {
|
|
|
2942
3286
|
* @internal
|
|
2943
3287
|
*/
|
|
2944
3288
|
_plugins?: Plugin[];
|
|
3289
|
+
/**
|
|
3290
|
+
* The dependency-set table and unique-constraint map `pnpm generate`
|
|
3291
|
+
* emitted (ADR-0051, ADR-0042), supplied by the generated context. Absent
|
|
3292
|
+
* for a config reached without generation, in which case the engine derives
|
|
3293
|
+
* the dependency table from this config through the same computation.
|
|
3294
|
+
* @internal
|
|
3295
|
+
*/
|
|
3296
|
+
_tables?: GeneratedTables;
|
|
2945
3297
|
}
|
|
2946
3298
|
export {};
|
|
2947
3299
|
//# sourceMappingURL=types.d.ts.map
|