@opensaas/stack-core 0.43.0 → 0.44.0-alpha.2
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 +2753 -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 +1035 -611
- 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 +629 -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 +294 -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 +153 -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 +462 -678
- 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 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -51
- 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 +237 -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 -74
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -847
- 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 -1470
- 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 -192
- 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 -3146
- 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 -317
- 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/src/config/types.ts
DELETED
|
@@ -1,3270 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccessControl,
|
|
3
|
-
AccessControlledDB,
|
|
4
|
-
FieldAccess,
|
|
5
|
-
PrismaClientLike,
|
|
6
|
-
} from '../access/types.js'
|
|
7
|
-
import type { FilterSpec } from '../filter/types.js'
|
|
8
|
-
import type { z } from 'zod'
|
|
9
|
-
|
|
10
|
-
export type FieldType =
|
|
11
|
-
'text' | 'integer' | 'checkbox' | 'timestamp' | 'password' | 'select' | 'relationship' | string // Allow custom field types from third-party packages
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Field-level hook argument types (exported for user annotations)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/** Arguments for {@link FieldHooks.resolveInput}. */
|
|
18
|
-
export type FieldResolveInputHookArgs<
|
|
19
|
-
TTypeInfo extends TypeInfo,
|
|
20
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
21
|
-
> =
|
|
22
|
-
| {
|
|
23
|
-
listKey: string
|
|
24
|
-
fieldKey: TFieldKey
|
|
25
|
-
operation: 'create'
|
|
26
|
-
inputData: TTypeInfo['inputs']['create']
|
|
27
|
-
item: undefined
|
|
28
|
-
resolvedData: TTypeInfo['inputs']['create']
|
|
29
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
listKey: string
|
|
33
|
-
fieldKey: TFieldKey
|
|
34
|
-
operation: 'update'
|
|
35
|
-
inputData: TTypeInfo['inputs']['update']
|
|
36
|
-
item: TTypeInfo['item']
|
|
37
|
-
resolvedData: TTypeInfo['inputs']['update']
|
|
38
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Arguments for {@link FieldHooks.validate} (and its deprecated `validateInput` alias). */
|
|
42
|
-
export type FieldValidateHookArgs<
|
|
43
|
-
TTypeInfo extends TypeInfo,
|
|
44
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
45
|
-
> =
|
|
46
|
-
| {
|
|
47
|
-
listKey: string
|
|
48
|
-
fieldKey: TFieldKey
|
|
49
|
-
operation: 'create'
|
|
50
|
-
inputData: TTypeInfo['inputs']['create']
|
|
51
|
-
item: undefined
|
|
52
|
-
resolvedData: TTypeInfo['inputs']['create']
|
|
53
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
54
|
-
addValidationError: (msg: string) => void
|
|
55
|
-
}
|
|
56
|
-
| {
|
|
57
|
-
listKey: string
|
|
58
|
-
fieldKey: TFieldKey
|
|
59
|
-
operation: 'update'
|
|
60
|
-
inputData: TTypeInfo['inputs']['update']
|
|
61
|
-
item: TTypeInfo['item']
|
|
62
|
-
resolvedData: TTypeInfo['inputs']['update']
|
|
63
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
64
|
-
addValidationError: (msg: string) => void
|
|
65
|
-
}
|
|
66
|
-
| {
|
|
67
|
-
listKey: string
|
|
68
|
-
fieldKey: TFieldKey
|
|
69
|
-
operation: 'delete'
|
|
70
|
-
item: TTypeInfo['item']
|
|
71
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
72
|
-
addValidationError: (msg: string) => void
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Arguments for {@link FieldHooks.beforeOperation}. */
|
|
76
|
-
export type FieldBeforeOperationHookArgs<
|
|
77
|
-
TTypeInfo extends TypeInfo,
|
|
78
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
79
|
-
> =
|
|
80
|
-
| {
|
|
81
|
-
listKey: string
|
|
82
|
-
fieldKey: TFieldKey
|
|
83
|
-
operation: 'create'
|
|
84
|
-
inputData: TTypeInfo['inputs']['create']
|
|
85
|
-
resolvedData: TTypeInfo['inputs']['create']
|
|
86
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
87
|
-
}
|
|
88
|
-
| {
|
|
89
|
-
listKey: string
|
|
90
|
-
fieldKey: TFieldKey
|
|
91
|
-
operation: 'update'
|
|
92
|
-
inputData: TTypeInfo['inputs']['update']
|
|
93
|
-
item: TTypeInfo['item']
|
|
94
|
-
resolvedData: TTypeInfo['inputs']['update']
|
|
95
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
96
|
-
}
|
|
97
|
-
| {
|
|
98
|
-
listKey: string
|
|
99
|
-
fieldKey: TFieldKey
|
|
100
|
-
operation: 'delete'
|
|
101
|
-
item: TTypeInfo['item']
|
|
102
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Arguments for {@link FieldHooks.afterOperation}. */
|
|
106
|
-
export type FieldAfterOperationHookArgs<
|
|
107
|
-
TTypeInfo extends TypeInfo,
|
|
108
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
109
|
-
> =
|
|
110
|
-
| {
|
|
111
|
-
listKey: string
|
|
112
|
-
fieldKey: TFieldKey
|
|
113
|
-
operation: 'create'
|
|
114
|
-
inputData: TTypeInfo['inputs']['create']
|
|
115
|
-
item: TTypeInfo['item']
|
|
116
|
-
resolvedData: TTypeInfo['inputs']['create']
|
|
117
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
118
|
-
}
|
|
119
|
-
| {
|
|
120
|
-
listKey: string
|
|
121
|
-
fieldKey: TFieldKey
|
|
122
|
-
operation: 'update'
|
|
123
|
-
inputData: TTypeInfo['inputs']['update']
|
|
124
|
-
originalItem: TTypeInfo['item']
|
|
125
|
-
item: TTypeInfo['item']
|
|
126
|
-
resolvedData: TTypeInfo['inputs']['update']
|
|
127
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
128
|
-
}
|
|
129
|
-
| {
|
|
130
|
-
listKey: string
|
|
131
|
-
fieldKey: TFieldKey
|
|
132
|
-
operation: 'delete'
|
|
133
|
-
originalItem: TTypeInfo['item']
|
|
134
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Arguments for field-level beforeTransaction hook (#590 / ADR-0010).
|
|
139
|
-
*
|
|
140
|
-
* Transaction-boundary hooks run OUTSIDE the write's database transaction.
|
|
141
|
-
* `beforeTransaction` runs before the transaction opens, so it has the input
|
|
142
|
-
* data but no persisted `item` yet (and, for create, no `item` to read). For
|
|
143
|
-
* update/delete the existing `item` is best-effort: present for the top-level
|
|
144
|
-
* target (which the pipeline resolves before opening the transaction) and
|
|
145
|
-
* `undefined` for nested targets (not resolved at the boundary to avoid
|
|
146
|
-
* pre-transaction reads). Use it for non-transactional side effects (e.g.
|
|
147
|
-
* external API calls) whose compensation pairs with `afterTransaction`.
|
|
148
|
-
*/
|
|
149
|
-
export type FieldBeforeTransactionHookArgs<
|
|
150
|
-
TTypeInfo extends TypeInfo,
|
|
151
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
152
|
-
> =
|
|
153
|
-
| {
|
|
154
|
-
listKey: string
|
|
155
|
-
fieldKey: TFieldKey
|
|
156
|
-
operation: 'create'
|
|
157
|
-
inputData: TTypeInfo['inputs']['create']
|
|
158
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
159
|
-
}
|
|
160
|
-
| {
|
|
161
|
-
listKey: string
|
|
162
|
-
fieldKey: TFieldKey
|
|
163
|
-
operation: 'update'
|
|
164
|
-
inputData: TTypeInfo['inputs']['update']
|
|
165
|
-
item: TTypeInfo['item'] | undefined
|
|
166
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
167
|
-
}
|
|
168
|
-
| {
|
|
169
|
-
listKey: string
|
|
170
|
-
fieldKey: TFieldKey
|
|
171
|
-
operation: 'delete'
|
|
172
|
-
item: TTypeInfo['item'] | undefined
|
|
173
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Arguments for field-level afterTransaction hook (#590 / ADR-0010).
|
|
178
|
-
*
|
|
179
|
-
* Runs AFTER the transaction settles and ALWAYS runs when its paired
|
|
180
|
-
* `beforeTransaction` ran (symmetric bracket). The `status` discriminant tells
|
|
181
|
-
* the hook whether the write committed or rolled back:
|
|
182
|
-
* - `committed`: the persisted `item`/`originalItem` are populated ONLY for the
|
|
183
|
-
* TOP-LEVEL record of the write. For NESTED lists they are `undefined` — the
|
|
184
|
-
* per-record persisted row is not reliably recoverable outside the
|
|
185
|
-
* transaction, and these hooks fire at per-(list, operation) granularity, not
|
|
186
|
-
* per record. For per-record nested compensation use the in-transaction
|
|
187
|
-
* `afterOperation` (which receives the correct nested `item`).
|
|
188
|
-
* - `rolled-back`: NO persisted `item`; the hook gets `inputData` and the
|
|
189
|
-
* `error` that caused the rollback so it can compensate for whatever
|
|
190
|
-
* `beforeTransaction` did externally.
|
|
191
|
-
*/
|
|
192
|
-
export type FieldAfterTransactionHookArgs<
|
|
193
|
-
TTypeInfo extends TypeInfo,
|
|
194
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
195
|
-
> =
|
|
196
|
-
| {
|
|
197
|
-
listKey: string
|
|
198
|
-
fieldKey: TFieldKey
|
|
199
|
-
operation: 'create'
|
|
200
|
-
status: 'committed'
|
|
201
|
-
inputData: TTypeInfo['inputs']['create']
|
|
202
|
-
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
203
|
-
item: TTypeInfo['item'] | undefined
|
|
204
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
205
|
-
}
|
|
206
|
-
| {
|
|
207
|
-
listKey: string
|
|
208
|
-
fieldKey: TFieldKey
|
|
209
|
-
operation: 'create'
|
|
210
|
-
status: 'rolled-back'
|
|
211
|
-
inputData: TTypeInfo['inputs']['create']
|
|
212
|
-
error: unknown
|
|
213
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
214
|
-
}
|
|
215
|
-
| {
|
|
216
|
-
listKey: string
|
|
217
|
-
fieldKey: TFieldKey
|
|
218
|
-
operation: 'update'
|
|
219
|
-
status: 'committed'
|
|
220
|
-
inputData: TTypeInfo['inputs']['update']
|
|
221
|
-
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
222
|
-
originalItem: TTypeInfo['item'] | undefined
|
|
223
|
-
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
224
|
-
item: TTypeInfo['item'] | undefined
|
|
225
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
226
|
-
}
|
|
227
|
-
| {
|
|
228
|
-
listKey: string
|
|
229
|
-
fieldKey: TFieldKey
|
|
230
|
-
operation: 'update'
|
|
231
|
-
status: 'rolled-back'
|
|
232
|
-
inputData: TTypeInfo['inputs']['update']
|
|
233
|
-
originalItem: TTypeInfo['item'] | undefined
|
|
234
|
-
error: unknown
|
|
235
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
236
|
-
}
|
|
237
|
-
| {
|
|
238
|
-
listKey: string
|
|
239
|
-
fieldKey: TFieldKey
|
|
240
|
-
operation: 'delete'
|
|
241
|
-
status: 'committed'
|
|
242
|
-
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
243
|
-
originalItem: TTypeInfo['item'] | undefined
|
|
244
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
245
|
-
}
|
|
246
|
-
| {
|
|
247
|
-
listKey: string
|
|
248
|
-
fieldKey: TFieldKey
|
|
249
|
-
operation: 'delete'
|
|
250
|
-
status: 'rolled-back'
|
|
251
|
-
originalItem: TTypeInfo['item'] | undefined
|
|
252
|
-
error: unknown
|
|
253
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Arguments for {@link FieldHooks.resolveOutput}. */
|
|
257
|
-
export type FieldResolveOutputHookArgs<
|
|
258
|
-
TTypeInfo extends TypeInfo,
|
|
259
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
260
|
-
> = {
|
|
261
|
-
operation: 'query'
|
|
262
|
-
value: GetFieldValueType<TTypeInfo['fields'], TFieldKey>
|
|
263
|
-
item: TTypeInfo['item']
|
|
264
|
-
listKey: string
|
|
265
|
-
fieldName: TFieldKey
|
|
266
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Field-level hooks for data transformation and side effects
|
|
271
|
-
* Allows field types to define custom behavior during operations
|
|
272
|
-
*
|
|
273
|
-
* @template TTypeInfo - List type information including item and input types
|
|
274
|
-
* @template TFieldKey - The specific field name (defaults to any field in the list)
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```typescript
|
|
278
|
-
* // For a 'title' field on Post list:
|
|
279
|
-
* FieldHooks<Lists.Post.TypeInfo, 'title'>
|
|
280
|
-
* // resolveOutput returns: string | undefined (field-specific)
|
|
281
|
-
*
|
|
282
|
-
* // Generic (for field builders):
|
|
283
|
-
* FieldHooks<TTypeInfo>
|
|
284
|
-
* // resolveOutput returns: union of all field types
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
export type FieldHooks<
|
|
288
|
-
TTypeInfo extends TypeInfo,
|
|
289
|
-
TFieldKey extends FieldKeys<TTypeInfo['fields']> = FieldKeys<TTypeInfo['fields']>,
|
|
290
|
-
> = {
|
|
291
|
-
/**
|
|
292
|
-
* Transform field value before database write
|
|
293
|
-
* Called during create/update operations after list-level resolveInput but before validation
|
|
294
|
-
* This is where you should transform input data (e.g., hash passwords, normalize values)
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```typescript
|
|
298
|
-
* resolveInput: async ({ listKey, fieldKey, operation, inputData, item, resolvedData, context }) => {
|
|
299
|
-
* // For create operations, item is undefined
|
|
300
|
-
* // For update operations, item is the existing record
|
|
301
|
-
* const fieldValue = resolvedData[fieldKey]
|
|
302
|
-
* if (typeof fieldValue === 'string' && !isHashedPassword(fieldValue)) {
|
|
303
|
-
* return await hashPassword(fieldValue)
|
|
304
|
-
* }
|
|
305
|
-
* return fieldValue
|
|
306
|
-
* }
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
resolveInput?: (
|
|
310
|
-
args: FieldResolveInputHookArgs<TTypeInfo, TFieldKey>,
|
|
311
|
-
) =>
|
|
312
|
-
| Promise<GetFieldValueType<TTypeInfo['fields'], TFieldKey> | undefined>
|
|
313
|
-
| GetFieldValueType<TTypeInfo['fields'], TFieldKey>
|
|
314
|
-
| undefined
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Validate field value after resolveInput
|
|
318
|
-
* Called during create/update operations after resolveInput hooks but before database write
|
|
319
|
-
* Use addValidationError to report validation failures
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* validate: async ({ listKey, fieldKey, operation, inputData, item, resolvedData, context, addValidationError }) => {
|
|
324
|
-
* if (operation === 'delete') return
|
|
325
|
-
* const fieldValue = resolvedData[fieldKey]
|
|
326
|
-
* if (typeof fieldValue === 'string' && fieldValue.includes('spam')) {
|
|
327
|
-
* addValidationError('Field cannot contain spam')
|
|
328
|
-
* }
|
|
329
|
-
* }
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
validate?: (args: FieldValidateHookArgs<TTypeInfo, TFieldKey>) => Promise<void> | void
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @deprecated Use 'validate' instead. This alias is provided for backwards compatibility.
|
|
336
|
-
*/
|
|
337
|
-
validateInput?: (args: FieldValidateHookArgs<TTypeInfo, TFieldKey>) => Promise<void> | void
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Perform side effects before database write
|
|
341
|
-
* Called during create/update/delete operations after validation and access control
|
|
342
|
-
* This should ONLY contain side effects (logging, notifications, etc.), not data transformation
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* beforeOperation: async ({ listKey, fieldKey, operation, inputData, item, resolvedData, context }) => {
|
|
347
|
-
* // For create operations, item is undefined
|
|
348
|
-
* // For update/delete operations, item is the existing record
|
|
349
|
-
* const fieldValue = resolvedData?.[fieldKey]
|
|
350
|
-
* if (operation === 'update' && item) {
|
|
351
|
-
* console.log(`Updating field from ${item[fieldKey]} to ${fieldValue}`)
|
|
352
|
-
* }
|
|
353
|
-
* await sendAuditLog({ operation, item })
|
|
354
|
-
* }
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
|
-
beforeOperation?: (
|
|
358
|
-
args: FieldBeforeOperationHookArgs<TTypeInfo, TFieldKey>,
|
|
359
|
-
) => Promise<void> | void
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Perform side effects after database operation
|
|
363
|
-
* Called after any database operation (create/update/delete)
|
|
364
|
-
* This should ONLY contain side effects (logging, cache invalidation, etc.), not data transformation
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* ```typescript
|
|
368
|
-
* afterOperation: async ({ listKey, fieldKey, operation, inputData, item, originalItem, resolvedData, context }) => {
|
|
369
|
-
* // For create operations, originalItem is undefined
|
|
370
|
-
* // For update/delete operations, originalItem is the item before the operation
|
|
371
|
-
* if (operation === 'update' && originalItem) {
|
|
372
|
-
* console.log('Changed from:', originalItem[fieldKey], 'to:', item[fieldKey])
|
|
373
|
-
* }
|
|
374
|
-
* await invalidateCache({ listKey, itemId: item.id })
|
|
375
|
-
* await sendWebhook({ operation, item })
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
afterOperation?: (args: FieldAfterOperationHookArgs<TTypeInfo, TFieldKey>) => Promise<void> | void
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Perform side effects BEFORE the write's database transaction opens
|
|
383
|
-
* (#590 / ADR-0010 transaction-boundary hook).
|
|
384
|
-
*
|
|
385
|
-
* Unlike `beforeOperation` (which runs INSIDE the transaction and rolls back
|
|
386
|
-
* with it), this runs OUTSIDE the transaction — use it for non-transactional
|
|
387
|
-
* side effects such as external API calls that must not hold a DB transaction
|
|
388
|
-
* open and cannot be rolled back. If this throws, the write is aborted (the
|
|
389
|
-
* transaction never opens) and the paired `afterTransaction` fires with
|
|
390
|
-
* `status: 'rolled-back'`.
|
|
391
|
-
*
|
|
392
|
-
* @example
|
|
393
|
-
* ```typescript
|
|
394
|
-
* beforeTransaction: async ({ operation, inputData }) => {
|
|
395
|
-
* await externalApi.reserve(inputData.externalId)
|
|
396
|
-
* }
|
|
397
|
-
* ```
|
|
398
|
-
*/
|
|
399
|
-
beforeTransaction?: (
|
|
400
|
-
args: FieldBeforeTransactionHookArgs<TTypeInfo, TFieldKey>,
|
|
401
|
-
) => Promise<void> | void
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Perform side effects AFTER the write's database transaction settles
|
|
405
|
-
* (#590 / ADR-0010 transaction-boundary hook).
|
|
406
|
-
*
|
|
407
|
-
* ALWAYS runs when the paired `beforeTransaction` ran (symmetric bracket),
|
|
408
|
-
* receiving `status: 'committed' | 'rolled-back'`. On `committed` it gets the
|
|
409
|
-
* persisted `item` ONLY for the top-level record (`undefined` for nested
|
|
410
|
-
* lists — use the in-transaction `afterOperation` for per-record nested
|
|
411
|
-
* compensation); on `rolled-back` it gets the `error` that caused the
|
|
412
|
-
* rollback and NO `item`, so it can compensate for whatever `beforeTransaction`
|
|
413
|
-
* did externally.
|
|
414
|
-
*
|
|
415
|
-
* @example
|
|
416
|
-
* ```typescript
|
|
417
|
-
* afterTransaction: async (args) => {
|
|
418
|
-
* if (args.status === 'rolled-back') {
|
|
419
|
-
* await externalApi.release(args.inputData.externalId)
|
|
420
|
-
* }
|
|
421
|
-
* }
|
|
422
|
-
* ```
|
|
423
|
-
*/
|
|
424
|
-
afterTransaction?: (
|
|
425
|
-
args: FieldAfterTransactionHookArgs<TTypeInfo, TFieldKey>,
|
|
426
|
-
) => Promise<void> | void
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Transform field value after database read
|
|
430
|
-
* Called when returning results from query operations
|
|
431
|
-
* This is where you should transform output data (e.g., wrap passwords, format values)
|
|
432
|
-
*
|
|
433
|
-
* Supports both sync and async implementations. When async, the hook will be
|
|
434
|
-
* properly awaited before returning results.
|
|
435
|
-
*
|
|
436
|
-
* @example
|
|
437
|
-
* ```typescript
|
|
438
|
-
* // Sync example
|
|
439
|
-
* resolveOutput: ({ value }) => {
|
|
440
|
-
* if (typeof value === 'string' && value.length > 0) {
|
|
441
|
-
* return new HashedPassword(value)
|
|
442
|
-
* }
|
|
443
|
-
* return value
|
|
444
|
-
* }
|
|
445
|
-
*
|
|
446
|
-
* // Async example (e.g., for virtual fields that query the database)
|
|
447
|
-
* resolveOutput: async ({ item, context }) => {
|
|
448
|
-
* const related = await context.db.otherList.findUnique({ where: { id: item.relatedId } })
|
|
449
|
-
* return related?.name
|
|
450
|
-
* }
|
|
451
|
-
* ```
|
|
452
|
-
*/
|
|
453
|
-
resolveOutput?: (
|
|
454
|
-
args: FieldResolveOutputHookArgs<TTypeInfo, TFieldKey>,
|
|
455
|
-
) =>
|
|
456
|
-
| GetFieldValueType<TTypeInfo['fields'], TFieldKey>
|
|
457
|
-
| undefined
|
|
458
|
-
| Promise<GetFieldValueType<TTypeInfo['fields'], TFieldKey> | undefined>
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Configuration for Prisma result extensions
|
|
463
|
-
* Allows fields to transform their runtime values and types in query results
|
|
464
|
-
*
|
|
465
|
-
* Runtime transformation is delegated to the field's resolveOutput hook.
|
|
466
|
-
* This config only specifies the TypeScript output type for generated types.
|
|
467
|
-
*/
|
|
468
|
-
export type ResultExtensionConfig = {
|
|
469
|
-
/**
|
|
470
|
-
* The TypeScript type to use in query result types
|
|
471
|
-
* This is a type expression like: "import('@opensaas/stack-core').HashedPassword"
|
|
472
|
-
*
|
|
473
|
-
* The actual runtime transformation is performed by the field's resolveOutput hook.
|
|
474
|
-
* The Prisma extension will automatically call the hook if it exists.
|
|
475
|
-
*
|
|
476
|
-
* @example "import('@opensaas/stack-core').HashedPassword"
|
|
477
|
-
* @example "import('./types').MyCustomType"
|
|
478
|
-
*/
|
|
479
|
-
outputType: string
|
|
480
|
-
/**
|
|
481
|
-
* @deprecated No longer used. Runtime transformations are handled by resolveOutput hooks.
|
|
482
|
-
* This field is kept for backwards compatibility but should not be used in new code.
|
|
483
|
-
*/
|
|
484
|
-
compute?: string
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export type BaseFieldConfig<TTypeInfo extends TypeInfo> = {
|
|
488
|
-
type: string
|
|
489
|
-
access?: FieldAccess<
|
|
490
|
-
TTypeInfo['item'],
|
|
491
|
-
TTypeInfo['inputs']['create'],
|
|
492
|
-
TTypeInfo['inputs']['update']
|
|
493
|
-
>
|
|
494
|
-
defaultValue?: unknown
|
|
495
|
-
hooks?: FieldHooks<TTypeInfo>
|
|
496
|
-
/**
|
|
497
|
-
* Marks this field as virtual — not stored in database, computed via
|
|
498
|
-
* `resolveInput`/`resolveOutput` hooks, and excluded from the Prisma
|
|
499
|
-
* schema and input types. Computed whenever the read is going to return
|
|
500
|
-
* it (ADR-0027) — not gated behind an explicit `include`/selection.
|
|
501
|
-
*/
|
|
502
|
-
virtual?: boolean
|
|
503
|
-
/**
|
|
504
|
-
* Prisma result extension configuration
|
|
505
|
-
* Transforms field values and types in query results using Prisma's native extension system
|
|
506
|
-
*/
|
|
507
|
-
resultExtension?: ResultExtensionConfig
|
|
508
|
-
/**
|
|
509
|
-
* Database configuration
|
|
510
|
-
*/
|
|
511
|
-
db?: {
|
|
512
|
-
/**
|
|
513
|
-
* Custom database column name
|
|
514
|
-
* Adds a @map attribute in Prisma schema
|
|
515
|
-
* @example
|
|
516
|
-
* ```typescript
|
|
517
|
-
* fields: {
|
|
518
|
-
* firstName: text({ db: { map: 'first_name' } })
|
|
519
|
-
* }
|
|
520
|
-
* // Generates: firstName String @map("first_name")
|
|
521
|
-
* ```
|
|
522
|
-
*/
|
|
523
|
-
map?: string
|
|
524
|
-
/**
|
|
525
|
-
* Controls DB-level nullability independently of validation.isRequired.
|
|
526
|
-
* When specified, overrides the default behavior where nullability is inferred
|
|
527
|
-
* from validation.isRequired (required = non-nullable, optional = nullable).
|
|
528
|
-
*
|
|
529
|
-
* This allows you to:
|
|
530
|
-
* - Make a field non-nullable at the DB level without making it API-required
|
|
531
|
-
* - Explicitly mark a field as nullable even when it has isRequired validation
|
|
532
|
-
*
|
|
533
|
-
* @example
|
|
534
|
-
* ```typescript
|
|
535
|
-
* // DB non-nullable, but API optional (relies on a default value or hook)
|
|
536
|
-
* fields: {
|
|
537
|
-
* phoneNumber: text({
|
|
538
|
-
* db: { isNullable: false }
|
|
539
|
-
* })
|
|
540
|
-
* // Generates: phoneNumber String (non-nullable)
|
|
541
|
-
*
|
|
542
|
-
* // DB nullable (explicit), regardless of validation
|
|
543
|
-
* lastMessagePreview: text({
|
|
544
|
-
* db: { isNullable: true }
|
|
545
|
-
* })
|
|
546
|
-
* // Generates: lastMessagePreview String? (nullable)
|
|
547
|
-
* }
|
|
548
|
-
* ```
|
|
549
|
-
*/
|
|
550
|
-
isNullable?: boolean
|
|
551
|
-
/**
|
|
552
|
-
* Override the native database type for the column.
|
|
553
|
-
* Generates a @db.<nativeType> attribute in the Prisma schema.
|
|
554
|
-
* The available types depend on your database provider.
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* ```typescript
|
|
558
|
-
* // PostgreSQL: use TEXT instead of VARCHAR
|
|
559
|
-
* fields: {
|
|
560
|
-
* description: text({ db: { nativeType: 'Text' } })
|
|
561
|
-
* // Generates: description String? @db.Text
|
|
562
|
-
*
|
|
563
|
-
* // PostgreSQL: use SMALLINT instead of INT
|
|
564
|
-
* count: integer({ db: { nativeType: 'SmallInt' } })
|
|
565
|
-
* // Generates: count Int? @db.SmallInt
|
|
566
|
-
* }
|
|
567
|
-
* ```
|
|
568
|
-
*/
|
|
569
|
-
nativeType?: string
|
|
570
|
-
}
|
|
571
|
-
ui?: {
|
|
572
|
-
/**
|
|
573
|
-
* Custom React component to render this field
|
|
574
|
-
* Overrides the default component for this field type
|
|
575
|
-
* Uses `any` to accept any React component type without overly complex generics
|
|
576
|
-
*/
|
|
577
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
578
|
-
component?: any
|
|
579
|
-
/**
|
|
580
|
-
* Custom field type name to use from the global registry
|
|
581
|
-
* e.g., "color" to use a globally registered ColorPickerField
|
|
582
|
-
*/
|
|
583
|
-
fieldType?: string
|
|
584
|
-
/**
|
|
585
|
-
* Help / description text rendered beneath the field control in the admin UI.
|
|
586
|
-
*
|
|
587
|
-
* `FieldRenderer` surfaces this to the rendered field component as its
|
|
588
|
-
* `helpText` prop, so it appears via the shared field-shell `FieldHelp`
|
|
589
|
-
* rhythm (data-slot="field-help") for admin-rendered fields.
|
|
590
|
-
*
|
|
591
|
-
* @example
|
|
592
|
-
* ```typescript
|
|
593
|
-
* fields: {
|
|
594
|
-
* slug: text({ ui: { description: 'URL-friendly identifier, lowercase only.' } })
|
|
595
|
-
* }
|
|
596
|
-
* ```
|
|
597
|
-
*/
|
|
598
|
-
description?: string
|
|
599
|
-
/**
|
|
600
|
-
* Whether this field belongs in a list/related-list table's DEFAULT
|
|
601
|
-
* column set (issue #1018) — the columns shown when nothing explicitly
|
|
602
|
-
* names them (`ui.listView.initialColumns` on the list, or a
|
|
603
|
-
* relationship's own `ui.itemView.columns`). Naming the field explicitly
|
|
604
|
-
* in either of those always shows it regardless of this flag; it governs
|
|
605
|
-
* only what appears absent an explicit column list.
|
|
606
|
-
*
|
|
607
|
-
* This is a PRESENTATION default, not an access control — a field can be
|
|
608
|
-
* read-denied and still default to `true` here (it simply renders empty
|
|
609
|
-
* for a viewer who can't read it), and setting this to `false` hides a
|
|
610
|
-
* column without restricting who can read the underlying value. The
|
|
611
|
-
* field-level `access.read` deny remains the only real boundary.
|
|
612
|
-
*
|
|
613
|
-
* @default true
|
|
614
|
-
*
|
|
615
|
-
* @example Hide an internal field from default table views without denying read access
|
|
616
|
-
* ```typescript
|
|
617
|
-
* fields: {
|
|
618
|
-
* internalScore: integer({ ui: { listView: { defaultColumn: false } } }),
|
|
619
|
-
* }
|
|
620
|
-
* ```
|
|
621
|
-
*/
|
|
622
|
-
listView?: {
|
|
623
|
-
defaultColumn?: boolean
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Transform field value before sending to client (browser)
|
|
627
|
-
* Useful for sensitive fields (e.g., passwords) or complex data structures
|
|
628
|
-
* that shouldn't be serialized in their raw form
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```typescript
|
|
632
|
-
* // Password field: send only whether it's set, not the hash
|
|
633
|
-
* valueForClientSerialization: ({ value }) => ({ isSet: !!value })
|
|
634
|
-
* ```
|
|
635
|
-
*/
|
|
636
|
-
valueForClientSerialization?: (args: { value: unknown }) => unknown
|
|
637
|
-
/**
|
|
638
|
-
* Additional UI-specific configuration
|
|
639
|
-
*/
|
|
640
|
-
[key: string]: unknown
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* Generate Zod schema for this field
|
|
644
|
-
* @param fieldName - The name of the field (for error messages)
|
|
645
|
-
* @param operation - Whether this is a create or update operation
|
|
646
|
-
*/
|
|
647
|
-
getZodSchema?: (fieldName: string, operation: 'create' | 'update') => z.ZodTypeAny
|
|
648
|
-
/**
|
|
649
|
-
* Get Prisma type and modifiers for schema generation
|
|
650
|
-
* @param fieldName - The name of the field (for generating modifiers)
|
|
651
|
-
* @param provider - Optional database provider ('sqlite', 'postgresql', 'mysql', etc.)
|
|
652
|
-
* @param listName - Optional list name (used for generating enum type names)
|
|
653
|
-
* @param keystoneCompat - Whether Keystone-compat mode is enabled (db.keystoneCompat).
|
|
654
|
-
* When true, non-null text columns without an explicit defaultValue emit
|
|
655
|
-
* `@default("")` to match Keystone 6's implicit empty-string text default.
|
|
656
|
-
* @returns Prisma type string, optional modifiers, optional enum values, and
|
|
657
|
-
* an optional block-level index request
|
|
658
|
-
*/
|
|
659
|
-
getPrismaType?: (
|
|
660
|
-
fieldName: string,
|
|
661
|
-
provider?: string,
|
|
662
|
-
listName?: string,
|
|
663
|
-
keystoneCompat?: boolean,
|
|
664
|
-
) => {
|
|
665
|
-
type: string
|
|
666
|
-
modifiers?: string
|
|
667
|
-
/**
|
|
668
|
-
* If set, this field requires a Prisma enum definition with these values.
|
|
669
|
-
* The enum name is the value of `type`.
|
|
670
|
-
*/
|
|
671
|
-
enumValues?: string[]
|
|
672
|
-
/**
|
|
673
|
-
* If set, this field requires a block-level index on the owning model:
|
|
674
|
-
* `@@index([fieldName])` for `true`, `@@unique([fieldName])` for
|
|
675
|
-
* `'unique'`. `false` and `undefined` both mean "no index".
|
|
676
|
-
*
|
|
677
|
-
* Prisma has no field-level `@index` attribute — a non-unique index can
|
|
678
|
-
* ONLY be expressed as the model-level `@@index([...])` — so a field that
|
|
679
|
-
* wants one has to ask for it out-of-line rather than appending to
|
|
680
|
-
* {@link modifiers}. (A unique index has both forms available; the
|
|
681
|
-
* built-in scalars keep emitting the inline `@unique` modifier for that
|
|
682
|
-
* case, so this channel carries only what cannot be written inline.)
|
|
683
|
-
*
|
|
684
|
-
* Same shape as {@link PrismaRelationResult.foreignKeyIndex}, which is how
|
|
685
|
-
* relationship fields have always emitted their foreign-key indexes. The
|
|
686
|
-
* generator handles both through one emit pass, so the field stays the
|
|
687
|
-
* authority on whether it can be indexed by name at all — a multi-column
|
|
688
|
-
* field (see {@link getPrismaColumns}) has no single column matching its
|
|
689
|
-
* field name and can decline, or name a real column of its own.
|
|
690
|
-
*/
|
|
691
|
-
index?: boolean | 'unique'
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Get TypeScript type information for type generation
|
|
695
|
-
* @returns TypeScript type string and optionality
|
|
696
|
-
*/
|
|
697
|
-
getTypeScriptType?: () => {
|
|
698
|
-
type: string
|
|
699
|
-
optional: boolean
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Declare this field's filtering capability — its {@link FilterSpec} — for the
|
|
703
|
-
* admin UI's Filter builder (ADR-0017). Optional and additive: a field that
|
|
704
|
-
* omits it (like `password`, `json`, `virtual`, or a third-party field that
|
|
705
|
-
* hasn't adopted filtering) is simply not filterable and never suggested, so
|
|
706
|
-
* absence degrades gracefully everywhere.
|
|
707
|
-
*
|
|
708
|
-
* Self-contained, like {@link getPrismaType} and friends — the filter engine
|
|
709
|
-
* delegates to each field's spec rather than switching on field type. The
|
|
710
|
-
* returned `toCondition` mapper must stay pure (no DB/Prisma imports); its
|
|
711
|
-
* output is ANDed with the access filter through the secured context.
|
|
712
|
-
*
|
|
713
|
-
* @param fieldName The field's config key (closed over by the mapper).
|
|
714
|
-
* @param listKey The owning list's key.
|
|
715
|
-
* @param config The full config (e.g. relationship specs resolve their
|
|
716
|
-
* target list's label field from it).
|
|
717
|
-
* @returns The field's Filter spec, or `undefined` when not filterable.
|
|
718
|
-
*/
|
|
719
|
-
getFilterSpec?: (
|
|
720
|
-
fieldName: string,
|
|
721
|
-
listKey: string,
|
|
722
|
-
config: OpenSaasConfig,
|
|
723
|
-
) => FilterSpec | undefined
|
|
724
|
-
/**
|
|
725
|
-
* Get TypeScript imports needed for this field's type
|
|
726
|
-
* @returns Array of import statements needed for the generated types file
|
|
727
|
-
*/
|
|
728
|
-
getTypeScriptImports?: () => Array<{
|
|
729
|
-
/**
|
|
730
|
-
* The type/value names to import
|
|
731
|
-
* e.g., ['StoredEmbedding', 'EmbeddingMetadata']
|
|
732
|
-
*/
|
|
733
|
-
names: string[]
|
|
734
|
-
/**
|
|
735
|
-
* The module to import from
|
|
736
|
-
* e.g., '@opensaas/stack-rag'
|
|
737
|
-
*/
|
|
738
|
-
from: string
|
|
739
|
-
/**
|
|
740
|
-
* Whether this is a type-only import
|
|
741
|
-
* @default true
|
|
742
|
-
*/
|
|
743
|
-
typeOnly?: boolean
|
|
744
|
-
}>
|
|
745
|
-
/**
|
|
746
|
-
* Multi-column Prisma emission.
|
|
747
|
-
*
|
|
748
|
-
* Most scalar fields back a single Prisma column via {@link getPrismaType}.
|
|
749
|
-
* A field that maps onto SEVERAL physical columns (e.g. the storage
|
|
750
|
-
* `image()`/`file()` fields in multi-column / Keystone-parity mode — see
|
|
751
|
-
* ADR-0006) implements this instead: it returns one descriptor per column,
|
|
752
|
-
* each becoming its own line in the generated model. When present, the
|
|
753
|
-
* generator emits these lines and skips the single-column `getPrismaType`
|
|
754
|
-
* path. The field itself owns the column layout — the generator stays a
|
|
755
|
-
* neutral coordinator (no field-type switches), mirroring how relationship
|
|
756
|
-
* fields emit FK + relation lines through `getPrismaRelation`.
|
|
757
|
-
*
|
|
758
|
-
* @param fieldName - The field's config key (used to derive default column names)
|
|
759
|
-
* @returns One descriptor per physical column, or `undefined` to fall back to
|
|
760
|
-
* the single-column `getPrismaType` path.
|
|
761
|
-
*/
|
|
762
|
-
getPrismaColumns?: (fieldName: string) => MultiColumnPrismaResult[] | undefined
|
|
763
|
-
/**
|
|
764
|
-
* The physical Prisma column names this field owns when it spans multiple
|
|
765
|
-
* columns (see {@link getPrismaColumns}). The read path uses this to strip the
|
|
766
|
-
* raw per-part columns from query results so only the assembled logical value
|
|
767
|
-
* (produced by {@link assembleColumns}) is exposed.
|
|
768
|
-
*
|
|
769
|
-
* @param fieldName - The field's config key
|
|
770
|
-
*/
|
|
771
|
-
getColumnNames?: (fieldName: string) => string[]
|
|
772
|
-
/**
|
|
773
|
-
* Assemble the field's logical value from a database row's per-part columns
|
|
774
|
-
* (the read direction of a multi-column field). Pure transform — called by the
|
|
775
|
-
* read pipeline before field visibility. Receives the full row so it can read
|
|
776
|
-
* its sibling columns by name.
|
|
777
|
-
*
|
|
778
|
-
* @param fieldName - The field's config key
|
|
779
|
-
* @param row - The raw database row (contains the per-part columns)
|
|
780
|
-
*/
|
|
781
|
-
assembleColumns?: (fieldName: string, row: Record<string, unknown>) => unknown
|
|
782
|
-
/**
|
|
783
|
-
* Split the field's logical value into per-part columns for writing (the write
|
|
784
|
-
* direction of a multi-column field). Pure transform — called by the write
|
|
785
|
-
* pipeline after `resolveInput`; the returned record is merged into the write
|
|
786
|
-
* payload in place of the single field key.
|
|
787
|
-
*
|
|
788
|
-
* @param fieldName - The field's config key
|
|
789
|
-
* @param value - The resolved logical value (metadata, or `null` to clear)
|
|
790
|
-
*/
|
|
791
|
-
splitColumns?: (fieldName: string, value: unknown) => Record<string, unknown>
|
|
792
|
-
/**
|
|
793
|
-
* Declares the immediate sibling relations this field's `resolveOutput`
|
|
794
|
-
* hook cannot compute without (ADR-0025 — the "Declared dependency" glossary
|
|
795
|
-
* entry in `CONTEXT.md`). The read fetches each declared relation wherever
|
|
796
|
-
* this field is computed — at the root of a read and at every nested level
|
|
797
|
-
* alike — and scopes it through the Access Filter exactly like a
|
|
798
|
-
* caller-named relation: a dependency a session cannot query is not
|
|
799
|
-
* fetched, and the hook sees nothing in its place.
|
|
800
|
-
*
|
|
801
|
-
* A declared dependency is private plumbing, not an implicit `include`: it
|
|
802
|
-
* is stripped from the result unless the caller named it too, so declaring
|
|
803
|
-
* or removing one changes this field's implementation, never the shape of
|
|
804
|
-
* every read of the list.
|
|
805
|
-
*
|
|
806
|
-
* Names immediate relations only — no dotted paths. Reach beyond one hop
|
|
807
|
-
* comes from the recursive fold: a dependency's own list declares its own
|
|
808
|
-
* dependencies.
|
|
809
|
-
*
|
|
810
|
-
* Typed as a plain `string[]`, not narrowed to this list's own relation
|
|
811
|
-
* keys: `BaseFieldConfig` is the contextual type EVERY field builder's
|
|
812
|
-
* return type is checked against, including non-generic third-party ones
|
|
813
|
-
* (`richText(): RichTextField`, with no `TTypeInfo` parameter of its own —
|
|
814
|
-
* the documented third-party field pattern). Narrowing `needs` per-list
|
|
815
|
-
* would make `needs`'s type on a fixed, unparameterized third-party field
|
|
816
|
-
* config disagree with the narrower type this list's own slot expects,
|
|
817
|
-
* breaking assignability for every such field regardless of whether it
|
|
818
|
-
* uses `needs` at all. A misspelled or non-relation entry is instead
|
|
819
|
-
* caught by `pnpm generate` (`validateNeedsDeclarations`), which has no
|
|
820
|
-
* such constraint.
|
|
821
|
-
*
|
|
822
|
-
* @example
|
|
823
|
-
* ```typescript
|
|
824
|
-
* lineItems: relationship({ ref: 'LineItem.order', many: true }),
|
|
825
|
-
* total: virtual({
|
|
826
|
-
* type: 'number',
|
|
827
|
-
* needs: ['lineItems'],
|
|
828
|
-
* hooks: {
|
|
829
|
-
* resolveOutput: ({ item }) => item.lineItems.reduce((sum, li) => sum + li.price, 0),
|
|
830
|
-
* },
|
|
831
|
-
* }),
|
|
832
|
-
* ```
|
|
833
|
-
*/
|
|
834
|
-
needs?: string[]
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* A single physical column contributed by a multi-column field
|
|
839
|
-
* (see {@link BaseFieldConfig.getPrismaColumns}).
|
|
840
|
-
*/
|
|
841
|
-
export type MultiColumnPrismaResult = {
|
|
842
|
-
/** The Prisma model field name (the property the column is declared as). */
|
|
843
|
-
name: string
|
|
844
|
-
/** The Prisma scalar type, e.g. `'String'` or `'Int'`. */
|
|
845
|
-
type: string
|
|
846
|
-
/**
|
|
847
|
-
* Field modifiers, e.g. `'?'` for nullable. A leading `'?'` attaches to the
|
|
848
|
-
* type; anything after it is treated as trailing attributes (matching the
|
|
849
|
-
* single-column `getPrismaType` modifier convention).
|
|
850
|
-
*/
|
|
851
|
-
modifiers?: string
|
|
852
|
-
/** Physical column name for the `@map` attribute, when it differs from `name`. */
|
|
853
|
-
map?: string
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
export type TextField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
857
|
-
type: 'text'
|
|
858
|
-
validation?: {
|
|
859
|
-
isRequired?: boolean
|
|
860
|
-
length?: {
|
|
861
|
-
min?: number
|
|
862
|
-
max?: number
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
isIndexed?: boolean | 'unique'
|
|
866
|
-
ui?: {
|
|
867
|
-
displayMode?: 'input' | 'textarea'
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
export type IntegerField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
872
|
-
type: 'integer'
|
|
873
|
-
validation?: {
|
|
874
|
-
isRequired?: boolean
|
|
875
|
-
min?: number
|
|
876
|
-
max?: number
|
|
877
|
-
}
|
|
878
|
-
isIndexed?: boolean | 'unique'
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
export type DecimalField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
882
|
-
type: 'decimal'
|
|
883
|
-
defaultValue?: string
|
|
884
|
-
precision?: number
|
|
885
|
-
scale?: number
|
|
886
|
-
validation?: {
|
|
887
|
-
isRequired?: boolean
|
|
888
|
-
min?: string
|
|
889
|
-
max?: string
|
|
890
|
-
}
|
|
891
|
-
isIndexed?: boolean | 'unique'
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
/**
|
|
895
|
-
* 64-bit integer field (Prisma `BigInt`, TypeScript `bigint`) — for values that
|
|
896
|
-
* overflow `integer()`'s 32-bit `Int` (e.g. a millisecond epoch).
|
|
897
|
-
*
|
|
898
|
-
* Wire representation (ADR-0029): `bigint` in application code, a decimal
|
|
899
|
-
* string over MCP — `bigint` is not JSON-serialisable, so the MCP handler
|
|
900
|
-
* renders it as a string rather than throwing.
|
|
901
|
-
*/
|
|
902
|
-
export type BigIntField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
903
|
-
type: 'bigInt'
|
|
904
|
-
defaultValue?: bigint | number | string
|
|
905
|
-
validation?: {
|
|
906
|
-
isRequired?: boolean
|
|
907
|
-
min?: bigint
|
|
908
|
-
max?: bigint
|
|
909
|
-
}
|
|
910
|
-
isIndexed?: boolean | 'unique'
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
export type CheckboxField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
914
|
-
type: 'checkbox'
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
export type TimestampField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
918
|
-
type: 'timestamp'
|
|
919
|
-
defaultValue?: { kind: 'now' } | Date
|
|
920
|
-
isIndexed?: boolean | 'unique'
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
export type CalendarDayField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
924
|
-
type: 'calendarDay'
|
|
925
|
-
defaultValue?: string
|
|
926
|
-
validation?: {
|
|
927
|
-
isRequired?: boolean
|
|
928
|
-
}
|
|
929
|
-
isIndexed?: boolean | 'unique'
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
export type PasswordField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
933
|
-
type: 'password'
|
|
934
|
-
validation?: {
|
|
935
|
-
isRequired?: boolean
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* Badge-variant vocabulary a select option can map its value to for status-Cell
|
|
941
|
-
* rendering in the admin UI (issue #729). Mirrors the admin UI Badge primitive's
|
|
942
|
-
* variants; `secondary` is the neutral fallback used for unmapped options.
|
|
943
|
-
*/
|
|
944
|
-
export type SelectOptionVariant =
|
|
945
|
-
'default' | 'secondary' | 'success' | 'warning' | 'destructive' | 'outline'
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* A single choice in a `select` field.
|
|
949
|
-
*
|
|
950
|
-
* `label`/`value` are the long-standing shape; `ui` is additive, optional
|
|
951
|
-
* metadata (issue #729). `ui.variant` lets a value render as a coloured status
|
|
952
|
-
* badge in list-table Cells — an option without it renders with the neutral
|
|
953
|
-
* badge, so existing options keep working unchanged.
|
|
954
|
-
*/
|
|
955
|
-
export type SelectOption = {
|
|
956
|
-
label: string
|
|
957
|
-
value: string
|
|
958
|
-
ui?: {
|
|
959
|
-
/** Badge variant used when this option's value renders as a status Cell. */
|
|
960
|
-
variant?: SelectOptionVariant
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
export type SelectField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
965
|
-
type: 'select'
|
|
966
|
-
options: Array<SelectOption>
|
|
967
|
-
defaultValue?: string
|
|
968
|
-
db?: {
|
|
969
|
-
/**
|
|
970
|
-
* Whether to store as a native database enum type.
|
|
971
|
-
* - 'string' (default): stores as a plain string/varchar column
|
|
972
|
-
* - 'enum': stores as a Prisma enum, generating a native enum type in the schema
|
|
973
|
-
*
|
|
974
|
-
* Note: enum values must be valid Prisma identifiers (letters, numbers, underscores,
|
|
975
|
-
* starting with a letter) when using 'enum' type.
|
|
976
|
-
*
|
|
977
|
-
* @default 'string'
|
|
978
|
-
*/
|
|
979
|
-
type?: 'string' | 'enum'
|
|
980
|
-
map?: string
|
|
981
|
-
/**
|
|
982
|
-
* Force the generated column to be nullable (`?`) even when a `defaultValue`
|
|
983
|
-
* is present. By default a select with a `defaultValue` generates NOT NULL;
|
|
984
|
-
* set this to `true` for an explicit opt-in to a nullable column with a
|
|
985
|
-
* default (e.g. `String? @default("X")` or `<Enum>? @default(X)`), so that
|
|
986
|
-
* a live column containing NULLs migrates without a NOT NULL failure.
|
|
987
|
-
*
|
|
988
|
-
* @default undefined (NOT NULL when a default is present — unchanged behaviour)
|
|
989
|
-
*
|
|
990
|
-
* @example
|
|
991
|
-
* ```typescript
|
|
992
|
-
* // Optional select with a default, but keep the column nullable
|
|
993
|
-
* status: select({
|
|
994
|
-
* options: [{ label: 'Draft', value: 'draft' }],
|
|
995
|
-
* defaultValue: 'draft',
|
|
996
|
-
* db: { isNullable: true },
|
|
997
|
-
* })
|
|
998
|
-
* // Generates: String? @default("draft")
|
|
999
|
-
* ```
|
|
1000
|
-
*/
|
|
1001
|
-
isNullable?: boolean
|
|
1002
|
-
/**
|
|
1003
|
-
* Override the generated Prisma enum type name for native-enum selects
|
|
1004
|
-
* (only applies when `type: 'enum'`). By default the enum is named
|
|
1005
|
-
* `<List><Field>` (e.g. `AccountNoteStatus`); set this to match a live DB
|
|
1006
|
-
* enum type whose name differs (e.g. Keystone's `…Type` suffix).
|
|
1007
|
-
*
|
|
1008
|
-
* The custom name is applied to both the generated `enum` block and every
|
|
1009
|
-
* reference to it in the owning model.
|
|
1010
|
-
*
|
|
1011
|
-
* @example
|
|
1012
|
-
* ```typescript
|
|
1013
|
-
* status: select({
|
|
1014
|
-
* options: [{ label: 'Open', value: 'open' }],
|
|
1015
|
-
* db: { type: 'enum', enumName: 'AccountNoteStatusType' },
|
|
1016
|
-
* })
|
|
1017
|
-
* // Generates: enum AccountNoteStatusType { ... } and the column references it
|
|
1018
|
-
* ```
|
|
1019
|
-
*/
|
|
1020
|
-
enumName?: string
|
|
1021
|
-
}
|
|
1022
|
-
validation?: {
|
|
1023
|
-
isRequired?: boolean
|
|
1024
|
-
}
|
|
1025
|
-
isIndexed?: boolean | 'unique'
|
|
1026
|
-
ui?: {
|
|
1027
|
-
displayMode?: 'select' | 'segmented-control' | 'radio'
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
/**
|
|
1032
|
-
* Item-view configuration for a single to-many relationship field — the
|
|
1033
|
-
* per-relationship overrides for the admin item view's Relationship table
|
|
1034
|
-
* (issue #734). All values are plain, serialisable data so they can cross the
|
|
1035
|
-
* server→client boundary via the existing field-config serialisation.
|
|
1036
|
-
*/
|
|
1037
|
-
export type RelationshipItemViewConfig = {
|
|
1038
|
-
/**
|
|
1039
|
-
* How this to-many relationship is presented on the owning record's item
|
|
1040
|
-
* view:
|
|
1041
|
-
* - `'table'` (default): a read-only Relationship table of related rows.
|
|
1042
|
-
* - `'picker'`: demote it back to the compact relationship picker inside the
|
|
1043
|
-
* details card (the pre-#734 behaviour).
|
|
1044
|
-
*
|
|
1045
|
-
* @default 'table'
|
|
1046
|
-
*/
|
|
1047
|
-
displayMode?: 'table' | 'picker'
|
|
1048
|
-
/**
|
|
1049
|
-
* The related list's fields to show as Relationship-table columns, in order.
|
|
1050
|
-
*
|
|
1051
|
-
* When omitted, the columns default to the related list's own column
|
|
1052
|
-
* curation (`ui.listView.initialColumns`, else every field whose own
|
|
1053
|
-
* `ui.listView.defaultColumn` declaration holds — see {@link
|
|
1054
|
-
* BaseFieldConfig.ui}) minus the back-reference field that points at the
|
|
1055
|
-
* parent record.
|
|
1056
|
-
*
|
|
1057
|
-
* @example
|
|
1058
|
-
* ```typescript
|
|
1059
|
-
* posts: relationship({
|
|
1060
|
-
* ref: 'Post.author',
|
|
1061
|
-
* many: true,
|
|
1062
|
-
* ui: { itemView: { columns: ['title', 'status'] } },
|
|
1063
|
-
* })
|
|
1064
|
-
* ```
|
|
1065
|
-
*/
|
|
1066
|
-
columns?: string[]
|
|
1067
|
-
/**
|
|
1068
|
-
* The maximum number of related rows to fetch and render in this
|
|
1069
|
-
* Relationship table (issue #752). The item view fetches related rows
|
|
1070
|
-
* through the secured context bounded by this `take`, so a record with many
|
|
1071
|
-
* related rows never loads/renders every one on edit-page open. The totals
|
|
1072
|
-
* footer still shows the full access-scoped total ("showing N of M").
|
|
1073
|
-
*
|
|
1074
|
-
* When omitted, a sensible default cap applies (the UI's
|
|
1075
|
-
* `DEFAULT_ITEM_VIEW_TAKE`). Must be a positive integer; non-positive or
|
|
1076
|
-
* non-integer values fall back to the default.
|
|
1077
|
-
*
|
|
1078
|
-
* @example
|
|
1079
|
-
* ```typescript
|
|
1080
|
-
* sessions: relationship({
|
|
1081
|
-
* ref: 'Session.user',
|
|
1082
|
-
* many: true,
|
|
1083
|
-
* ui: { itemView: { take: 5 } },
|
|
1084
|
-
* })
|
|
1085
|
-
* ```
|
|
1086
|
-
*/
|
|
1087
|
-
take?: number
|
|
1088
|
-
/**
|
|
1089
|
-
* The numeric columns whose values are summed in the Relationship table's
|
|
1090
|
-
* totals footer. The row count is always shown; sums appear only for the
|
|
1091
|
-
* columns listed here, each formatted by that column's Cell.
|
|
1092
|
-
*
|
|
1093
|
-
* @example
|
|
1094
|
-
* ```typescript
|
|
1095
|
-
* lineItems: relationship({
|
|
1096
|
-
* ref: 'LineItem.order',
|
|
1097
|
-
* many: true,
|
|
1098
|
-
* ui: { itemView: { sum: ['amount'] } },
|
|
1099
|
-
* })
|
|
1100
|
-
* ```
|
|
1101
|
-
*/
|
|
1102
|
-
sum?: string[]
|
|
1103
|
-
/**
|
|
1104
|
-
* How a row's ✕ control removes a related row from this table (ADR-0018).
|
|
1105
|
-
*
|
|
1106
|
-
* - `'disconnect'` (default): non-destructively unlinks the related row from
|
|
1107
|
-
* this record — the row itself is untouched and still appears on its own
|
|
1108
|
-
* list. Gated on the related list's update access. Hidden statically when
|
|
1109
|
-
* the schema makes disconnect impossible (a required foreign key on the
|
|
1110
|
-
* related side, i.e. the back-reference declares `db.isNullable: false`).
|
|
1111
|
-
* - `'delete'`: opts into truly deleting the related row, behind a
|
|
1112
|
-
* confirmation, gated on the related list's delete access.
|
|
1113
|
-
* - `'none'`: hides the removal control entirely.
|
|
1114
|
-
*
|
|
1115
|
-
* @default 'disconnect'
|
|
1116
|
-
*/
|
|
1117
|
-
removeAction?: 'disconnect' | 'delete' | 'none'
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
export type RelationshipField<TTypeInfo extends TypeInfo = TypeInfo> =
|
|
1121
|
-
BaseFieldConfig<TTypeInfo> & {
|
|
1122
|
-
type: 'relationship'
|
|
1123
|
-
ref: string // Format: 'ListName.fieldName' or 'ListName'
|
|
1124
|
-
many?: boolean
|
|
1125
|
-
/**
|
|
1126
|
-
* Controls whether to create an index on the foreign key field
|
|
1127
|
-
* Defaults to true for all foreign key fields (matching Keystone behavior)
|
|
1128
|
-
* Can be set to 'unique' for unique constraints or false to disable indexing
|
|
1129
|
-
*
|
|
1130
|
-
* @default true (for foreign key fields)
|
|
1131
|
-
*
|
|
1132
|
-
* @example
|
|
1133
|
-
* ```typescript
|
|
1134
|
-
* // Standard indexed foreign key (default)
|
|
1135
|
-
* author: relationship({ ref: 'User.posts' })
|
|
1136
|
-
* // Generates: @@index([authorId])
|
|
1137
|
-
*
|
|
1138
|
-
* // Unique foreign key (one-to-one)
|
|
1139
|
-
* author: relationship({ ref: 'User.posts', isIndexed: 'unique' })
|
|
1140
|
-
* // Generates: @@unique([authorId])
|
|
1141
|
-
*
|
|
1142
|
-
* // Disable indexing (not recommended, may cause performance issues)
|
|
1143
|
-
* author: relationship({ ref: 'User.posts', isIndexed: false })
|
|
1144
|
-
* // No index generated
|
|
1145
|
-
* ```
|
|
1146
|
-
*/
|
|
1147
|
-
isIndexed?: boolean | 'unique'
|
|
1148
|
-
db?: {
|
|
1149
|
-
/**
|
|
1150
|
-
* Controls DB-level nullability of the foreign key column (and its
|
|
1151
|
-
* relation field) independently of the many side's own shape. Only
|
|
1152
|
-
* meaningful on the FK-owning (single) side of a relationship — the
|
|
1153
|
-
* many side has no column of its own to make non-nullable and rejects
|
|
1154
|
-
* this option.
|
|
1155
|
-
*
|
|
1156
|
-
* @default true (nullable, matching every relationship generated before
|
|
1157
|
-
* this option existed)
|
|
1158
|
-
*
|
|
1159
|
-
* @example
|
|
1160
|
-
* ```typescript
|
|
1161
|
-
* // Every session genuinely belongs to a user — make the FK required
|
|
1162
|
-
* user: relationship({
|
|
1163
|
-
* ref: 'User.sessions',
|
|
1164
|
-
* db: { isNullable: false },
|
|
1165
|
-
* })
|
|
1166
|
-
* // Generates: userId String (was String?)
|
|
1167
|
-
* // user User @relation(...) (was User?)
|
|
1168
|
-
* ```
|
|
1169
|
-
*/
|
|
1170
|
-
isNullable?: boolean
|
|
1171
|
-
/**
|
|
1172
|
-
* Controls foreign key placement and column name.
|
|
1173
|
-
* Can be a boolean or an object with a map property.
|
|
1174
|
-
* Only valid on single (non-many) relationships.
|
|
1175
|
-
* Cannot be true on both sides of a one-to-one relationship.
|
|
1176
|
-
*
|
|
1177
|
-
* The boolean form (the "which side owns the foreign key" sense) is only
|
|
1178
|
-
* meaningful on a bidirectional ref (`ref: 'ListName.fieldName'`) — a
|
|
1179
|
-
* list-only ref (`ref: 'ListName'`) always owns the foreign key, so a
|
|
1180
|
-
* boolean here is rejected. The `{ map }` form (the column-name sense)
|
|
1181
|
-
* works on both: it renames the foreign key column without changing
|
|
1182
|
-
* ownership.
|
|
1183
|
-
*
|
|
1184
|
-
* When a boolean, defaults the foreign key column name to the field name.
|
|
1185
|
-
* When an object with map, uses the provided column name.
|
|
1186
|
-
*
|
|
1187
|
-
* @example
|
|
1188
|
-
* ```typescript
|
|
1189
|
-
* // One-to-one: User has one Account (default foreign key name)
|
|
1190
|
-
* User: list({
|
|
1191
|
-
* fields: {
|
|
1192
|
-
* account: relationship({ ref: 'Account.user', db: { foreignKey: true } })
|
|
1193
|
-
* // Generates: accountId String? @unique
|
|
1194
|
-
* }
|
|
1195
|
-
* })
|
|
1196
|
-
*
|
|
1197
|
-
* // One-to-one: User has one Account (custom foreign key name)
|
|
1198
|
-
* User: list({
|
|
1199
|
-
* fields: {
|
|
1200
|
-
* account: relationship({ ref: 'Account.user', db: { foreignKey: { map: 'account_id' } } })
|
|
1201
|
-
* // Generates: accountId String? @unique @map("account_id")
|
|
1202
|
-
* }
|
|
1203
|
-
* })
|
|
1204
|
-
*
|
|
1205
|
-
* Account: list({
|
|
1206
|
-
* fields: {
|
|
1207
|
-
* user: relationship({ ref: 'User.account' }) // No foreign key on this side
|
|
1208
|
-
* }
|
|
1209
|
-
* })
|
|
1210
|
-
*
|
|
1211
|
-
* // List-only ref: rename the foreign key column (ownership is implicit)
|
|
1212
|
-
* Post: list({
|
|
1213
|
-
* fields: {
|
|
1214
|
-
* category: relationship({ ref: 'Category', db: { foreignKey: { map: 'category_id' } } })
|
|
1215
|
-
* // Generates: categoryId String? @map("category_id")
|
|
1216
|
-
* }
|
|
1217
|
-
* })
|
|
1218
|
-
* ```
|
|
1219
|
-
*/
|
|
1220
|
-
foreignKey?: boolean | { map?: string }
|
|
1221
|
-
/**
|
|
1222
|
-
* Custom relation name for many-to-many relationships
|
|
1223
|
-
* Overrides the global joinTableNaming setting
|
|
1224
|
-
* Prisma will create an implicit join table named _relationName
|
|
1225
|
-
* Only needs to be set on one side of a bidirectional relationship
|
|
1226
|
-
*
|
|
1227
|
-
* @example KeystoneJS-style naming for migration
|
|
1228
|
-
* ```typescript
|
|
1229
|
-
* Lesson: list({
|
|
1230
|
-
* fields: {
|
|
1231
|
-
* teachers: relationship({
|
|
1232
|
-
* ref: 'Teacher.lessons',
|
|
1233
|
-
* many: true,
|
|
1234
|
-
* db: { relationName: 'Lesson_teachers' }
|
|
1235
|
-
* // Prisma creates join table _Lesson_teachers
|
|
1236
|
-
* })
|
|
1237
|
-
* }
|
|
1238
|
-
* })
|
|
1239
|
-
*
|
|
1240
|
-
* Teacher: list({
|
|
1241
|
-
* fields: {
|
|
1242
|
-
* lessons: relationship({ ref: 'Lesson.teachers', many: true })
|
|
1243
|
-
* // Automatically uses same relationName from other side
|
|
1244
|
-
* }
|
|
1245
|
-
* })
|
|
1246
|
-
* ```
|
|
1247
|
-
*/
|
|
1248
|
-
relationName?: string
|
|
1249
|
-
/**
|
|
1250
|
-
* Extend or modify the generated Prisma schema lines for this relationship field
|
|
1251
|
-
* Receives the generated FK line (if applicable) and relation line
|
|
1252
|
-
* Returns the modified lines
|
|
1253
|
-
*
|
|
1254
|
-
* @example Add onDelete cascade for self-referential relationship
|
|
1255
|
-
* ```typescript
|
|
1256
|
-
* parent: relationship({
|
|
1257
|
-
* ref: 'Category.children',
|
|
1258
|
-
* db: {
|
|
1259
|
-
* foreignKey: true,
|
|
1260
|
-
* extendPrismaSchema: ({ fkLine, relationLine }) => ({
|
|
1261
|
-
* fkLine,
|
|
1262
|
-
* relationLine: relationLine.replace(
|
|
1263
|
-
* '@relation(',
|
|
1264
|
-
* '@relation(onDelete: SetNull, '
|
|
1265
|
-
* )
|
|
1266
|
-
* })
|
|
1267
|
-
* }
|
|
1268
|
-
* })
|
|
1269
|
-
* ```
|
|
1270
|
-
*/
|
|
1271
|
-
extendPrismaSchema?: (lines: {
|
|
1272
|
-
/** The foreign key field line (e.g., "parentId String?"), only present for single relationships that own the FK */
|
|
1273
|
-
fkLine?: string
|
|
1274
|
-
/** The relation field line (e.g., "parent Category? @relation(...)") */
|
|
1275
|
-
relationLine: string
|
|
1276
|
-
}) => {
|
|
1277
|
-
fkLine?: string
|
|
1278
|
-
relationLine: string
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
ui?: {
|
|
1282
|
-
displayMode?: 'select' | 'cards'
|
|
1283
|
-
/**
|
|
1284
|
-
* Item-view (Relationship table) overrides for this to-many relationship
|
|
1285
|
-
* — columns, summed columns, and demotion to the compact picker (issue
|
|
1286
|
-
* #734). Ignored for single (`many: false`) relationships, which always
|
|
1287
|
-
* render inside the details card.
|
|
1288
|
-
*/
|
|
1289
|
-
itemView?: RelationshipItemViewConfig
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Get the complete Prisma schema contribution for this relationship field.
|
|
1293
|
-
*
|
|
1294
|
-
* Relationships are special: unlike scalar fields (which return a single
|
|
1295
|
-
* type via `getPrismaType`), a relationship can contribute a foreign key
|
|
1296
|
-
* line, a relation line on the owning model, and a synthetic back-relation
|
|
1297
|
-
* line on the target model. This method encapsulates all of that logic so
|
|
1298
|
-
* the generator can remain a neutral coordinator.
|
|
1299
|
-
*
|
|
1300
|
-
* @param fieldName - The name of this relationship field
|
|
1301
|
-
* @param allFields - All fields on the list this relationship belongs to
|
|
1302
|
-
* @param listKey - The name of the list this relationship belongs to
|
|
1303
|
-
* @param config - The full OpenSaas config (used to resolve the target list/field)
|
|
1304
|
-
*/
|
|
1305
|
-
getPrismaRelation?: (
|
|
1306
|
-
fieldName: string,
|
|
1307
|
-
allFields: Record<string, FieldConfig>,
|
|
1308
|
-
listKey: string,
|
|
1309
|
-
config: OpenSaasConfig,
|
|
1310
|
-
) => PrismaRelationResult
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
/**
|
|
1314
|
-
* The complete Prisma schema contribution of a relationship field.
|
|
1315
|
-
*/
|
|
1316
|
-
export type PrismaRelationResult = {
|
|
1317
|
-
/**
|
|
1318
|
-
* Lines to add to the owning model.
|
|
1319
|
-
* For an FK-owning single relationship this is `[fkLine, relationLine]`;
|
|
1320
|
-
* for the many side or the non-FK side it is `[relationLine]`.
|
|
1321
|
-
*/
|
|
1322
|
-
modelLines: string[]
|
|
1323
|
-
/**
|
|
1324
|
-
* The Prisma-level foreign key field name this side owns (e.g. `authorId`),
|
|
1325
|
-
* regardless of whether it is indexed. `undefined` when this side doesn't
|
|
1326
|
-
* own a foreign key column at all (the many side, or the non-FK side of a
|
|
1327
|
-
* one-to-one). Lets other generator passes resolve a relationship field
|
|
1328
|
-
* name to its physical column — e.g. a model-level composite index
|
|
1329
|
-
* ({@link ListIndex}) naming a relationship field — without duplicating
|
|
1330
|
-
* {@link foreignKeyIndex}'s narrower, indexing-conditional presence.
|
|
1331
|
-
*/
|
|
1332
|
-
foreignKeyField?: string
|
|
1333
|
-
/**
|
|
1334
|
-
* Foreign key index to add to the owning model, if this side owns an
|
|
1335
|
-
* indexed foreign key.
|
|
1336
|
-
*/
|
|
1337
|
-
foreignKeyIndex?: {
|
|
1338
|
-
foreignKeyField: string
|
|
1339
|
-
indexType: boolean | 'unique'
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Synthetic back-relation field to add to the target model. Only present
|
|
1343
|
-
* for list-only refs (e.g., `ref: 'Category'`), where the target model
|
|
1344
|
-
* needs an opposite relation field for Prisma to validate the relation.
|
|
1345
|
-
*/
|
|
1346
|
-
backRelation?: {
|
|
1347
|
-
targetList: string
|
|
1348
|
-
line: string
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
export type JsonField<TTypeInfo extends TypeInfo = TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
1353
|
-
type: 'json'
|
|
1354
|
-
validation?: {
|
|
1355
|
-
isRequired?: boolean
|
|
1356
|
-
}
|
|
1357
|
-
ui?: {
|
|
1358
|
-
placeholder?: string
|
|
1359
|
-
rows?: number
|
|
1360
|
-
formatted?: boolean
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
/**
|
|
1365
|
-
* Type descriptor for virtual fields
|
|
1366
|
-
* Supports three formats:
|
|
1367
|
-
* 1. Primitive string: 'string', 'number', 'boolean', 'Date', etc.
|
|
1368
|
-
* 2. Import string: "import('decimal.js').Decimal"
|
|
1369
|
-
* 3. Type object descriptor: { value: Decimal, from: 'decimal.js', name: 'Decimal' }
|
|
1370
|
-
*/
|
|
1371
|
-
export type TypeDescriptor =
|
|
1372
|
-
| string
|
|
1373
|
-
| {
|
|
1374
|
-
/**
|
|
1375
|
-
* The type constructor or class
|
|
1376
|
-
* @example Decimal (from decimal.js)
|
|
1377
|
-
* @example MyCustomClass
|
|
1378
|
-
*/
|
|
1379
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Constructor can have any signature
|
|
1380
|
-
value: new (...args: any[]) => any
|
|
1381
|
-
/**
|
|
1382
|
-
* The module to import from
|
|
1383
|
-
* @example 'decimal.js'
|
|
1384
|
-
* @example '@myorg/custom-types'
|
|
1385
|
-
*/
|
|
1386
|
-
from: string
|
|
1387
|
-
/**
|
|
1388
|
-
* Optional custom name (defaults to constructor.name)
|
|
1389
|
-
* Useful when constructor name doesn't match export name
|
|
1390
|
-
* @example 'Decimal' when constructor.name is different
|
|
1391
|
-
*/
|
|
1392
|
-
name?: string
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
export type VirtualField<TTypeInfo extends TypeInfo> = BaseFieldConfig<TTypeInfo> & {
|
|
1396
|
-
type: 'virtual'
|
|
1397
|
-
virtual: true
|
|
1398
|
-
/**
|
|
1399
|
-
* TypeScript type string for the virtual field output
|
|
1400
|
-
* e.g., 'string', 'number', 'boolean', 'string[]', etc.
|
|
1401
|
-
*/
|
|
1402
|
-
outputType: string
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* Generic field configuration type
|
|
1407
|
-
* Simplified to just BaseFieldConfig to reduce type complexity
|
|
1408
|
-
* Specific field types (TextField, IntegerField, etc.) are used by field builders
|
|
1409
|
-
* but at the config level we treat all fields uniformly
|
|
1410
|
-
*/
|
|
1411
|
-
export type FieldConfig = BaseFieldConfig<TypeInfo>
|
|
1412
|
-
|
|
1413
|
-
type WithTypeInfo<TTypeInfo extends TypeInfo> = BaseFieldConfig<TTypeInfo>
|
|
1414
|
-
|
|
1415
|
-
export type FieldsWithTypeInfo<TTypeInfo extends TypeInfo> = {
|
|
1416
|
-
[key: string]: WithTypeInfo<TTypeInfo>
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
/**
|
|
1420
|
-
* Parse TypeScript type string to actual type
|
|
1421
|
-
* Handles: 'string', 'number', 'boolean', 'Date', unions, string literals, imports
|
|
1422
|
-
*
|
|
1423
|
-
* @example
|
|
1424
|
-
* ParseTypeString<'string'> => string
|
|
1425
|
-
* ParseTypeString<'number'> => number
|
|
1426
|
-
* ParseTypeString<"'draft' | 'published'"> => 'draft' | 'published'
|
|
1427
|
-
* ParseTypeString<"import('@opensaas/stack-core').HashedPassword"> => any (fallback for imports)
|
|
1428
|
-
*/
|
|
1429
|
-
type ParseTypeString<T extends string> = T extends 'string'
|
|
1430
|
-
? string
|
|
1431
|
-
: T extends 'number'
|
|
1432
|
-
? number
|
|
1433
|
-
: T extends 'boolean'
|
|
1434
|
-
? boolean
|
|
1435
|
-
: T extends 'Date'
|
|
1436
|
-
? Date
|
|
1437
|
-
: T extends 'unknown'
|
|
1438
|
-
? unknown
|
|
1439
|
-
: T extends `'${infer U}'`
|
|
1440
|
-
? U // String literal
|
|
1441
|
-
: T extends `${infer U} | ${infer V}`
|
|
1442
|
-
? ParseTypeString<U> | ParseTypeString<V> // Union
|
|
1443
|
-
: T extends `import(${string}).${string}`
|
|
1444
|
-
? any // eslint-disable-line @typescript-eslint/no-explicit-any -- Import types can't be resolved at compile time
|
|
1445
|
-
: unknown // Fallback
|
|
1446
|
-
|
|
1447
|
-
/**
|
|
1448
|
-
* Extract field value type from a field config
|
|
1449
|
-
* Uses the field's getTypeScriptType() method result
|
|
1450
|
-
* If resultExtension is present, uses its outputType instead
|
|
1451
|
-
*
|
|
1452
|
-
* @example
|
|
1453
|
-
* ExtractFieldValueType<TextField> => string | null | undefined (if optional)
|
|
1454
|
-
* ExtractFieldValueType<IntegerField> => number
|
|
1455
|
-
* ExtractFieldValueType<PasswordField> => HashedPassword (from resultExtension)
|
|
1456
|
-
*/
|
|
1457
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic utility type needs to accept any BaseFieldConfig
|
|
1458
|
-
type ExtractFieldValueType<TField extends BaseFieldConfig<any>> = TField extends {
|
|
1459
|
-
resultExtension: { outputType: infer O }
|
|
1460
|
-
}
|
|
1461
|
-
? ParseTypeString<O & string>
|
|
1462
|
-
: TField extends { getTypeScriptType(): { type: infer T; optional: infer Opt } }
|
|
1463
|
-
? Opt extends true
|
|
1464
|
-
? ParseTypeString<T & string> | null | undefined
|
|
1465
|
-
: ParseTypeString<T & string>
|
|
1466
|
-
: unknown
|
|
1467
|
-
|
|
1468
|
-
/**
|
|
1469
|
-
* Extract field names as union of string literals
|
|
1470
|
-
*
|
|
1471
|
-
* @example
|
|
1472
|
-
* FieldKeys<{ title: TextField, content: TextField }> => 'title' | 'content'
|
|
1473
|
-
*/
|
|
1474
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic utility type needs to accept any field record
|
|
1475
|
-
export type FieldKeys<TFields extends Record<string, any>> = keyof TFields & string
|
|
1476
|
-
|
|
1477
|
-
/**
|
|
1478
|
-
* Get field config for a specific field name
|
|
1479
|
-
* Preserves the specific field type (TextField, PasswordField, etc.)
|
|
1480
|
-
*
|
|
1481
|
-
* @example
|
|
1482
|
-
* GetFieldConfig<{ title: TextField }, 'title'> => TextField
|
|
1483
|
-
*/
|
|
1484
|
-
export type GetFieldConfig<
|
|
1485
|
-
TFields extends Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic utility type needs to accept any field record
|
|
1486
|
-
TFieldKey extends FieldKeys<TFields>,
|
|
1487
|
-
> = TFields[TFieldKey]
|
|
1488
|
-
|
|
1489
|
-
/**
|
|
1490
|
-
* Get value type for a specific field
|
|
1491
|
-
*
|
|
1492
|
-
* @example
|
|
1493
|
-
* GetFieldValueType<{ title: TextField }, 'title'> => string
|
|
1494
|
-
*/
|
|
1495
|
-
export type GetFieldValueType<
|
|
1496
|
-
TFields extends Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic utility type needs to accept any field record
|
|
1497
|
-
TFieldKey extends FieldKeys<TFields>,
|
|
1498
|
-
> = ExtractFieldValueType<GetFieldConfig<TFields, TFieldKey>>
|
|
1499
|
-
|
|
1500
|
-
/**
|
|
1501
|
-
* TypeInfo interface for list type information
|
|
1502
|
-
* Provides a structured way to pass all type information for a list
|
|
1503
|
-
* Inspired by Keystone's TypeInfo pattern
|
|
1504
|
-
*
|
|
1505
|
-
* @template TKey - The list key/name (e.g., 'Post', 'User')
|
|
1506
|
-
* @template TFields - The fields configuration for the list
|
|
1507
|
-
* @template TPrisma - The consuming app's own Prisma client type. Defaults to
|
|
1508
|
-
* {@link PrismaClientLike} so a `TypeInfo` written (or defaulted) without it
|
|
1509
|
-
* keeps today's behaviour — a hook's `context` resolves to `StackContext`
|
|
1510
|
-
* over an unnamed client, same as before this member existed.
|
|
1511
|
-
* @template TItem - The output type (Prisma model type)
|
|
1512
|
-
* @template TCreateInput - The Prisma create input type
|
|
1513
|
-
* @template TUpdateInput - The Prisma update input type
|
|
1514
|
-
* @template TDb - The app's own generated `db` surface (the CLI's `CustomDB`),
|
|
1515
|
-
* with virtual and transformed fields folded into every list's payload.
|
|
1516
|
-
* Defaults to `AccessControlledDB<TPrisma>` — the plain Prisma-shaped view —
|
|
1517
|
-
* so a `TypeInfo` written (or defaulted) without it keeps today's behaviour.
|
|
1518
|
-
*
|
|
1519
|
-
* @example
|
|
1520
|
-
* ```typescript
|
|
1521
|
-
* type PostTypeInfo = {
|
|
1522
|
-
* key: 'Post'
|
|
1523
|
-
* fields: { title: TextField<...>, content: TextField<...> }
|
|
1524
|
-
* item: Post
|
|
1525
|
-
* inputs: {
|
|
1526
|
-
* create: Prisma.PostCreateInput
|
|
1527
|
-
* update: Prisma.PostUpdateInput
|
|
1528
|
-
* }
|
|
1529
|
-
* prisma: PrismaClient
|
|
1530
|
-
* db: CustomDB
|
|
1531
|
-
* }
|
|
1532
|
-
* ```
|
|
1533
|
-
*/
|
|
1534
|
-
export interface TypeInfo<
|
|
1535
|
-
TKey extends string = string,
|
|
1536
|
-
TFields extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- TypeInfo must accept any field record
|
|
1537
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1538
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1539
|
-
> {
|
|
1540
|
-
key: TKey
|
|
1541
|
-
fields: TFields
|
|
1542
|
-
item: any // eslint-disable-line @typescript-eslint/no-explicit-any -- Item type is provided by Prisma and varies per list
|
|
1543
|
-
inputs: {
|
|
1544
|
-
create: any // eslint-disable-line @typescript-eslint/no-explicit-any -- Prisma input types are generated and vary per list
|
|
1545
|
-
update: any // eslint-disable-line @typescript-eslint/no-explicit-any -- Prisma input types are generated and vary per list
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* The consuming app's own Prisma client type, so a hook's `context` can be
|
|
1549
|
-
* keyed as `StackContext<TPrisma>`/`AccessContext<TPrisma>` instead of
|
|
1550
|
-
* resolving through the unparameterised {@link PrismaClientLike} default.
|
|
1551
|
-
*/
|
|
1552
|
-
prisma: TPrisma
|
|
1553
|
-
/**
|
|
1554
|
-
* The app's own generated `db` surface (see {@link TDb}), so a hook's
|
|
1555
|
-
* `context.db` describes the same virtual/transformed-field-augmented rows
|
|
1556
|
-
* the app's own generated `db` surface produces for the same read (#1232).
|
|
1557
|
-
*/
|
|
1558
|
-
db: TDb
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
// Generic `any` default allows OperationAccess to work with any list item type
|
|
1562
|
-
// This is needed because the item type varies per list and is inferred from Prisma models
|
|
1563
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1564
|
-
export type OperationAccess<T = any> = {
|
|
1565
|
-
query?: AccessControl<T>
|
|
1566
|
-
/**
|
|
1567
|
-
* Shares `AccessControl`'s signature (so a filter still type-checks here),
|
|
1568
|
-
* but at runtime `create` accepts a `boolean` result only. There is no
|
|
1569
|
-
* existing row to scope with a filter, and — unlike `update`/`delete`,
|
|
1570
|
-
* which re-check a returned filter against the target row via
|
|
1571
|
-
* `findFirst` — no equivalent re-check exists for a row that doesn't exist
|
|
1572
|
-
* in the database yet. A rule that returns a filter (or any other
|
|
1573
|
-
* non-boolean) throws `InvalidCreateAccessResultError` rather than being
|
|
1574
|
-
* treated as an allow (see #1009, ADR-0022, ADR-0030). To scope create by
|
|
1575
|
-
* ownership, evaluate the condition in a `resolveInput`/`validate` hook,
|
|
1576
|
-
* where the input data is in scope.
|
|
1577
|
-
*/
|
|
1578
|
-
create?: AccessControl<T>
|
|
1579
|
-
update?: AccessControl<T>
|
|
1580
|
-
delete?: AccessControl<T>
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
/**
|
|
1584
|
-
* List-level access control configuration
|
|
1585
|
-
* Supports two patterns:
|
|
1586
|
-
*
|
|
1587
|
-
* 1. Function shorthand - applies to all CRUD operations:
|
|
1588
|
-
* `access: isAdmin`
|
|
1589
|
-
*
|
|
1590
|
-
* 2. Object form - configure operations individually:
|
|
1591
|
-
* `access: { operation: { query: () => true, create: isAdmin } }`
|
|
1592
|
-
*
|
|
1593
|
-
* @example Function shorthand
|
|
1594
|
-
* ```typescript
|
|
1595
|
-
* const isAdmin = ({ session }) => session?.role === 'admin'
|
|
1596
|
-
*
|
|
1597
|
-
* list({
|
|
1598
|
-
* access: isAdmin, // Applies to query, create, update, delete
|
|
1599
|
-
* fields: { ... }
|
|
1600
|
-
* })
|
|
1601
|
-
* ```
|
|
1602
|
-
*
|
|
1603
|
-
* @example Object form
|
|
1604
|
-
* ```typescript
|
|
1605
|
-
* list({
|
|
1606
|
-
* access: {
|
|
1607
|
-
* operation: {
|
|
1608
|
-
* query: () => true,
|
|
1609
|
-
* create: isAdmin,
|
|
1610
|
-
* update: isOwner,
|
|
1611
|
-
* delete: isAdmin,
|
|
1612
|
-
* }
|
|
1613
|
-
* },
|
|
1614
|
-
* fields: { ... }
|
|
1615
|
-
* })
|
|
1616
|
-
* ```
|
|
1617
|
-
*/
|
|
1618
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1619
|
-
export type ListAccessControl<T = any> =
|
|
1620
|
-
| AccessControl<T>
|
|
1621
|
-
| {
|
|
1622
|
-
operation?: OperationAccess<T>
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
/**
|
|
1626
|
-
* Hook arguments for the list-level `resolveInput` hook.
|
|
1627
|
-
* - create: resolvedData is CreateInput, item is undefined
|
|
1628
|
-
* - update: resolvedData is UpdateInput, item is the existing record
|
|
1629
|
-
*/
|
|
1630
|
-
export type ResolveInputHookArgs<
|
|
1631
|
-
TOutput = Record<string, unknown>,
|
|
1632
|
-
TCreateInput = Record<string, unknown>,
|
|
1633
|
-
TUpdateInput = Record<string, unknown>,
|
|
1634
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1635
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1636
|
-
> =
|
|
1637
|
-
| {
|
|
1638
|
-
listKey: string
|
|
1639
|
-
operation: 'create'
|
|
1640
|
-
inputData: TCreateInput
|
|
1641
|
-
resolvedData: TCreateInput
|
|
1642
|
-
item: undefined
|
|
1643
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1644
|
-
}
|
|
1645
|
-
| {
|
|
1646
|
-
listKey: string
|
|
1647
|
-
operation: 'update'
|
|
1648
|
-
inputData: TUpdateInput
|
|
1649
|
-
resolvedData: TUpdateInput
|
|
1650
|
-
item: TOutput
|
|
1651
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
/**
|
|
1655
|
-
* Hook arguments for the list-level `validate` hook (renamed from `validateInput` for Keystone compatibility).
|
|
1656
|
-
* - create: resolvedData is CreateInput, item is undefined
|
|
1657
|
-
* - update: resolvedData is UpdateInput, item is the existing record
|
|
1658
|
-
* - delete: item is the item being deleted
|
|
1659
|
-
*/
|
|
1660
|
-
export type ValidateHookArgs<
|
|
1661
|
-
TOutput = Record<string, unknown>,
|
|
1662
|
-
TCreateInput = Record<string, unknown>,
|
|
1663
|
-
TUpdateInput = Record<string, unknown>,
|
|
1664
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1665
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1666
|
-
> =
|
|
1667
|
-
| {
|
|
1668
|
-
listKey: string
|
|
1669
|
-
operation: 'create'
|
|
1670
|
-
inputData: TCreateInput
|
|
1671
|
-
resolvedData: TCreateInput
|
|
1672
|
-
item: undefined
|
|
1673
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1674
|
-
addValidationError: (msg: string) => void
|
|
1675
|
-
}
|
|
1676
|
-
| {
|
|
1677
|
-
listKey: string
|
|
1678
|
-
operation: 'update'
|
|
1679
|
-
inputData: TUpdateInput
|
|
1680
|
-
resolvedData: TUpdateInput
|
|
1681
|
-
item: TOutput
|
|
1682
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1683
|
-
addValidationError: (msg: string) => void
|
|
1684
|
-
}
|
|
1685
|
-
| {
|
|
1686
|
-
listKey: string
|
|
1687
|
-
operation: 'delete'
|
|
1688
|
-
item: TOutput
|
|
1689
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1690
|
-
addValidationError: (msg: string) => void
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
/**
|
|
1694
|
-
* Hook arguments for the list-level `beforeOperation` hook.
|
|
1695
|
-
* - create: has inputData and resolvedData, no item
|
|
1696
|
-
* - update: has inputData, resolvedData, and item
|
|
1697
|
-
* - delete: has item only
|
|
1698
|
-
*/
|
|
1699
|
-
export type BeforeOperationHookArgs<
|
|
1700
|
-
TOutput = Record<string, unknown>,
|
|
1701
|
-
TCreateInput = Record<string, unknown>,
|
|
1702
|
-
TUpdateInput = Record<string, unknown>,
|
|
1703
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1704
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1705
|
-
> =
|
|
1706
|
-
| {
|
|
1707
|
-
listKey: string
|
|
1708
|
-
operation: 'create'
|
|
1709
|
-
inputData: TCreateInput
|
|
1710
|
-
resolvedData: TCreateInput
|
|
1711
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1712
|
-
}
|
|
1713
|
-
| {
|
|
1714
|
-
listKey: string
|
|
1715
|
-
operation: 'update'
|
|
1716
|
-
inputData: TUpdateInput
|
|
1717
|
-
item: TOutput
|
|
1718
|
-
resolvedData: TUpdateInput
|
|
1719
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1720
|
-
}
|
|
1721
|
-
| {
|
|
1722
|
-
listKey: string
|
|
1723
|
-
operation: 'delete'
|
|
1724
|
-
item: TOutput
|
|
1725
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1726
|
-
}
|
|
1727
|
-
|
|
1728
|
-
/**
|
|
1729
|
-
* Hook arguments for the list-level `afterOperation` hook.
|
|
1730
|
-
* - create: has item, inputData, and resolvedData, no originalItem
|
|
1731
|
-
* - update: has item, originalItem, inputData, and resolvedData
|
|
1732
|
-
* - delete: has originalItem only
|
|
1733
|
-
*/
|
|
1734
|
-
export type AfterOperationHookArgs<
|
|
1735
|
-
TOutput = Record<string, unknown>,
|
|
1736
|
-
TCreateInput = Record<string, unknown>,
|
|
1737
|
-
TUpdateInput = Record<string, unknown>,
|
|
1738
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1739
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1740
|
-
> =
|
|
1741
|
-
| {
|
|
1742
|
-
listKey: string
|
|
1743
|
-
operation: 'create'
|
|
1744
|
-
inputData: TCreateInput
|
|
1745
|
-
item: TOutput
|
|
1746
|
-
resolvedData: TCreateInput
|
|
1747
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1748
|
-
}
|
|
1749
|
-
| {
|
|
1750
|
-
listKey: string
|
|
1751
|
-
operation: 'update'
|
|
1752
|
-
inputData: TUpdateInput
|
|
1753
|
-
originalItem: TOutput
|
|
1754
|
-
item: TOutput
|
|
1755
|
-
resolvedData: TUpdateInput
|
|
1756
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1757
|
-
}
|
|
1758
|
-
| {
|
|
1759
|
-
listKey: string
|
|
1760
|
-
operation: 'delete'
|
|
1761
|
-
originalItem: TOutput
|
|
1762
|
-
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
/**
|
|
1766
|
-
* Hook arguments for the list-level beforeTransaction hook (#590 / ADR-0010).
|
|
1767
|
-
*
|
|
1768
|
-
* Runs BEFORE the write's transaction opens (outside it). Has input data but no
|
|
1769
|
-
* persisted `item`. For update/delete the existing `item` is best-effort:
|
|
1770
|
-
* present for the top-level target (resolved before the transaction opens) and
|
|
1771
|
-
* `undefined` for nested targets. For non-transactional side effects whose
|
|
1772
|
-
* compensation pairs with `afterTransaction`.
|
|
1773
|
-
*/
|
|
1774
|
-
export type BeforeTransactionHookArgs<
|
|
1775
|
-
TOutput = Record<string, unknown>,
|
|
1776
|
-
TCreateInput = Record<string, unknown>,
|
|
1777
|
-
TUpdateInput = Record<string, unknown>,
|
|
1778
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1779
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1780
|
-
> =
|
|
1781
|
-
| {
|
|
1782
|
-
listKey: string
|
|
1783
|
-
operation: 'create'
|
|
1784
|
-
inputData: TCreateInput
|
|
1785
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1786
|
-
}
|
|
1787
|
-
| {
|
|
1788
|
-
listKey: string
|
|
1789
|
-
operation: 'update'
|
|
1790
|
-
inputData: TUpdateInput
|
|
1791
|
-
item: TOutput | undefined
|
|
1792
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1793
|
-
}
|
|
1794
|
-
| {
|
|
1795
|
-
listKey: string
|
|
1796
|
-
operation: 'delete'
|
|
1797
|
-
item: TOutput | undefined
|
|
1798
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
/**
|
|
1802
|
-
* Hook arguments for the list-level afterTransaction hook (#590 / ADR-0010).
|
|
1803
|
-
*
|
|
1804
|
-
* Runs AFTER the write's transaction settles and ALWAYS runs when the paired
|
|
1805
|
-
* `beforeTransaction` ran (symmetric bracket). The `status` discriminant tells
|
|
1806
|
-
* the hook whether the write committed or rolled back:
|
|
1807
|
-
* - `committed`: the persisted `item`/`originalItem` are populated ONLY for the
|
|
1808
|
-
* TOP-LEVEL record of the write. For NESTED lists they are `undefined` — the
|
|
1809
|
-
* per-record persisted row is not reliably recoverable outside the
|
|
1810
|
-
* transaction (recovering it would duplicate #569's in-transaction id-diff
|
|
1811
|
-
* machinery), and these hooks fire at per-(list, operation) granularity, not
|
|
1812
|
-
* per record. For per-record nested compensation use the in-transaction
|
|
1813
|
-
* `afterOperation` (which receives the correct nested `item`);
|
|
1814
|
-
* transaction-boundary hooks are for external-call compensation keyed off
|
|
1815
|
-
* `status`/`inputData`.
|
|
1816
|
-
* - `rolled-back`: NO persisted `item`; the hook gets `inputData` and the
|
|
1817
|
-
* `error` that caused the rollback so it can compensate.
|
|
1818
|
-
*/
|
|
1819
|
-
export type AfterTransactionHookArgs<
|
|
1820
|
-
TOutput = Record<string, unknown>,
|
|
1821
|
-
TCreateInput = Record<string, unknown>,
|
|
1822
|
-
TUpdateInput = Record<string, unknown>,
|
|
1823
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1824
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1825
|
-
> =
|
|
1826
|
-
| {
|
|
1827
|
-
listKey: string
|
|
1828
|
-
operation: 'create'
|
|
1829
|
-
status: 'committed'
|
|
1830
|
-
inputData: TCreateInput
|
|
1831
|
-
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1832
|
-
item: TOutput | undefined
|
|
1833
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1834
|
-
}
|
|
1835
|
-
| {
|
|
1836
|
-
listKey: string
|
|
1837
|
-
operation: 'create'
|
|
1838
|
-
status: 'rolled-back'
|
|
1839
|
-
inputData: TCreateInput
|
|
1840
|
-
error: unknown
|
|
1841
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1842
|
-
}
|
|
1843
|
-
| {
|
|
1844
|
-
listKey: string
|
|
1845
|
-
operation: 'update'
|
|
1846
|
-
status: 'committed'
|
|
1847
|
-
inputData: TUpdateInput
|
|
1848
|
-
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1849
|
-
originalItem: TOutput | undefined
|
|
1850
|
-
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1851
|
-
item: TOutput | undefined
|
|
1852
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1853
|
-
}
|
|
1854
|
-
| {
|
|
1855
|
-
listKey: string
|
|
1856
|
-
operation: 'update'
|
|
1857
|
-
status: 'rolled-back'
|
|
1858
|
-
inputData: TUpdateInput
|
|
1859
|
-
originalItem: TOutput | undefined
|
|
1860
|
-
error: unknown
|
|
1861
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1862
|
-
}
|
|
1863
|
-
| {
|
|
1864
|
-
listKey: string
|
|
1865
|
-
operation: 'delete'
|
|
1866
|
-
status: 'committed'
|
|
1867
|
-
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1868
|
-
originalItem: TOutput | undefined
|
|
1869
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1870
|
-
}
|
|
1871
|
-
| {
|
|
1872
|
-
listKey: string
|
|
1873
|
-
operation: 'delete'
|
|
1874
|
-
status: 'rolled-back'
|
|
1875
|
-
originalItem: TOutput | undefined
|
|
1876
|
-
error: unknown
|
|
1877
|
-
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
export type Hooks<
|
|
1881
|
-
TOutput = Record<string, unknown>,
|
|
1882
|
-
TCreateInput = Record<string, unknown>,
|
|
1883
|
-
TUpdateInput = Record<string, unknown>,
|
|
1884
|
-
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1885
|
-
TDb = AccessControlledDB<TPrisma>,
|
|
1886
|
-
> = {
|
|
1887
|
-
resolveInput?: (
|
|
1888
|
-
args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1889
|
-
) => Promise<TCreateInput | TUpdateInput>
|
|
1890
|
-
validate?: (
|
|
1891
|
-
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1892
|
-
) => Promise<void>
|
|
1893
|
-
beforeOperation?: (
|
|
1894
|
-
args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1895
|
-
) => Promise<void>
|
|
1896
|
-
afterOperation?: (
|
|
1897
|
-
args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1898
|
-
) => Promise<void>
|
|
1899
|
-
/**
|
|
1900
|
-
* Side effect BEFORE the write's transaction opens (#590 / ADR-0010).
|
|
1901
|
-
* Runs OUTSIDE the transaction — for non-transactional work (external API
|
|
1902
|
-
* calls). Throwing aborts the write; the paired `afterTransaction` then fires
|
|
1903
|
-
* with `status: 'rolled-back'`. See {@link BeforeTransactionHookArgs}.
|
|
1904
|
-
*/
|
|
1905
|
-
beforeTransaction?: (
|
|
1906
|
-
args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1907
|
-
) => Promise<void> | void
|
|
1908
|
-
/**
|
|
1909
|
-
* Side effect AFTER the write's transaction settles (#590 / ADR-0010).
|
|
1910
|
-
* ALWAYS runs when `beforeTransaction` ran; receives `committed | rolled-back`
|
|
1911
|
-
* + `error`. The persisted `item`/`originalItem` are present only on commit
|
|
1912
|
-
* AND only for the top-level record (`undefined` for nested lists). The
|
|
1913
|
-
* compensation half of the transaction-boundary bracket. See
|
|
1914
|
-
* {@link AfterTransactionHookArgs}.
|
|
1915
|
-
*/
|
|
1916
|
-
afterTransaction?: (
|
|
1917
|
-
args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1918
|
-
) => Promise<void> | void
|
|
1919
|
-
/**
|
|
1920
|
-
* @deprecated Use 'validate' instead. This alias is provided for backwards compatibility.
|
|
1921
|
-
*/
|
|
1922
|
-
validateInput?: (
|
|
1923
|
-
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1924
|
-
) => Promise<void>
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
/**
|
|
1928
|
-
* A single field reference within a model-level {@link ListIndex}. Either
|
|
1929
|
-
* just the OpenSaaS field name, or an object naming it alongside a sort
|
|
1930
|
-
* direction.
|
|
1931
|
-
*/
|
|
1932
|
-
export type ListIndexFieldRef =
|
|
1933
|
-
| string
|
|
1934
|
-
| {
|
|
1935
|
-
field: string
|
|
1936
|
-
/** Sort direction for this column within the index/constraint. */
|
|
1937
|
-
sort?: 'asc' | 'desc'
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
/**
|
|
1941
|
-
* A model-level `@@unique`/`@@index` constraint spanning one or more of a
|
|
1942
|
-
* list's own fields. See {@link ListConfig.db}'s `indexes` for the full
|
|
1943
|
-
* explanation and examples (#864, #918).
|
|
1944
|
-
*/
|
|
1945
|
-
export type ListIndex = {
|
|
1946
|
-
/**
|
|
1947
|
-
* The fields participating in this index/constraint, in declaration order.
|
|
1948
|
-
* OpenSaaS field names, not raw database column names.
|
|
1949
|
-
*
|
|
1950
|
-
* One or more fields — a named single-column constraint is as legitimate
|
|
1951
|
-
* as a composite one, and is the form to reach for when a live table's
|
|
1952
|
-
* constraint carries a name Prisma wouldn't derive on its own. Field-level
|
|
1953
|
-
* `isIndexed` remains the sugar for the unnamed single-column case; this
|
|
1954
|
-
* is the full form when a name or a sort direction is needed.
|
|
1955
|
-
*/
|
|
1956
|
-
fields: ListIndexFieldRef[]
|
|
1957
|
-
/**
|
|
1958
|
-
* Emit `@@unique([...])` instead of `@@index([...])`.
|
|
1959
|
-
* @default false
|
|
1960
|
-
*/
|
|
1961
|
-
unique?: boolean
|
|
1962
|
-
/**
|
|
1963
|
-
* Constraint/index name, emitted as Prisma's `map:` argument — lets an
|
|
1964
|
-
* existing live constraint be adopted under its current name rather than
|
|
1965
|
-
* renamed.
|
|
1966
|
-
*/
|
|
1967
|
-
name?: string
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
// Generic `any` default allows ListConfig to work with any list item type
|
|
1971
|
-
// This is needed because the item type varies per list and is inferred from Prisma models
|
|
1972
|
-
/**
|
|
1973
|
-
* Internal list configuration type (after normalization by list() function)
|
|
1974
|
-
* Access control is always in object form internally.
|
|
1975
|
-
* Use list() function which accepts both function shorthand and object form.
|
|
1976
|
-
*/
|
|
1977
|
-
export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
1978
|
-
// Field configs are automatically transformed to inject the full TypeInfo
|
|
1979
|
-
// This enables proper typing in field hooks where item, create input, and update input are all typed
|
|
1980
|
-
fields: FieldsWithTypeInfo<TTypeInfo>
|
|
1981
|
-
/**
|
|
1982
|
-
* Access control configuration for this list (normalized object form).
|
|
1983
|
-
* The list() function normalizes function shorthand to this object form.
|
|
1984
|
-
*/
|
|
1985
|
-
access?: {
|
|
1986
|
-
operation?: OperationAccess<TTypeInfo['item']>
|
|
1987
|
-
}
|
|
1988
|
-
hooks?: Hooks<
|
|
1989
|
-
TTypeInfo['item'],
|
|
1990
|
-
TTypeInfo['inputs']['create'],
|
|
1991
|
-
TTypeInfo['inputs']['update'],
|
|
1992
|
-
TTypeInfo['prisma'],
|
|
1993
|
-
TTypeInfo['db']
|
|
1994
|
-
>
|
|
1995
|
-
/**
|
|
1996
|
-
* Database configuration for this list (model level)
|
|
1997
|
-
*/
|
|
1998
|
-
db?: {
|
|
1999
|
-
/**
|
|
2000
|
-
* Custom database table name.
|
|
2001
|
-
* Adds a `@@map` attribute to the generated Prisma model.
|
|
2002
|
-
*
|
|
2003
|
-
* Useful when the Prisma model name (the list key) must differ from the
|
|
2004
|
-
* physical table name — e.g. adopting an existing better-auth installation
|
|
2005
|
-
* whose tables were created under a different name.
|
|
2006
|
-
*
|
|
2007
|
-
* @example
|
|
2008
|
-
* ```typescript
|
|
2009
|
-
* AuthUser: list({ fields: { ... }, db: { map: 'user' } })
|
|
2010
|
-
* // Generates: model AuthUser { ... @@map("user") }
|
|
2011
|
-
* ```
|
|
2012
|
-
*/
|
|
2013
|
-
map?: string
|
|
2014
|
-
/**
|
|
2015
|
-
* Database schema for this model (Postgres multi-schema).
|
|
2016
|
-
* Adds a `@@schema` attribute to the generated Prisma model.
|
|
2017
|
-
*
|
|
2018
|
-
* Requires the schema to be listed in the datasource `schemas` array (see
|
|
2019
|
-
* {@link DatabaseConfig.schemas}) and the `multiSchema` preview feature,
|
|
2020
|
-
* both of which the generator emits automatically when `db.schemas` is set.
|
|
2021
|
-
*
|
|
2022
|
-
* Useful when adopting an existing installation whose tables live in a
|
|
2023
|
-
* non-`public` schema — e.g. a separate-schema better-auth layout.
|
|
2024
|
-
*
|
|
2025
|
-
* @example
|
|
2026
|
-
* ```typescript
|
|
2027
|
-
* AuthUser: list({ fields: { ... }, db: { schema: 'auth' } })
|
|
2028
|
-
* // Generates: model AuthUser { ... @@schema("auth") }
|
|
2029
|
-
* ```
|
|
2030
|
-
*/
|
|
2031
|
-
schema?: string
|
|
2032
|
-
/**
|
|
2033
|
-
* Per-list override for auto-injected `createdAt`/`updatedAt` timestamp columns.
|
|
2034
|
-
*
|
|
2035
|
-
* Takes precedence over the global `db.timestamps` setting:
|
|
2036
|
-
* - `true` forces auto-timestamps on for this list, even when the global default is off.
|
|
2037
|
-
* - `false` forces them off for this list, even when enabled globally.
|
|
2038
|
-
* - `undefined` (the default) falls back to the global `db.timestamps` setting.
|
|
2039
|
-
*
|
|
2040
|
-
* When timestamps resolve to on but the list already declares its own `createdAt`/
|
|
2041
|
-
* `updatedAt` field, the auto column is skipped for the declared field(s) so Prisma
|
|
2042
|
-
* never sees a duplicate (`P1012`).
|
|
2043
|
-
*
|
|
2044
|
-
* @example Opt a single list out of timestamps even when enabled globally
|
|
2045
|
-
* ```typescript
|
|
2046
|
-
* Production: list({
|
|
2047
|
-
* fields: { name: text() },
|
|
2048
|
-
* db: { timestamps: false },
|
|
2049
|
-
* })
|
|
2050
|
-
* ```
|
|
2051
|
-
*/
|
|
2052
|
-
timestamps?: boolean
|
|
2053
|
-
/**
|
|
2054
|
-
* Model-level `@@unique`/`@@index` constraints spanning one or more of
|
|
2055
|
-
* this list's own fields (#864, #918). See the [reference
|
|
2056
|
-
* docs](https://stack.opensaas.au/docs/reference/config-api#dbindexes)
|
|
2057
|
-
* for the full explanation, arity, and error conditions.
|
|
2058
|
-
*
|
|
2059
|
-
* Field-level `isIndexed` (on a scalar or relationship field) is the
|
|
2060
|
-
* sugar for the unnamed single-column case. `db.indexes` is the full
|
|
2061
|
-
* form — reach for it when a constraint needs a `name` (Prisma's `map:`,
|
|
2062
|
-
* for adopting an existing live constraint), a `sort` direction, or spans
|
|
2063
|
-
* more than one column. Arity is incidental: each entry names one or
|
|
2064
|
-
* more of the list's own OpenSaaS field names, not raw database column
|
|
2065
|
-
* names. The generator resolves each to its underlying Prisma column — a
|
|
2066
|
-
* scalar field's own name (its Prisma field name is unaffected by
|
|
2067
|
-
* `db.map`), or a relationship field's foreign key column (`<field>Id`)
|
|
2068
|
-
* when this side owns it.
|
|
2069
|
-
*
|
|
2070
|
-
* A **unique** entry is the load-bearing case: it's the database-level
|
|
2071
|
-
* backstop for a business rule concurrent writes could otherwise both
|
|
2072
|
-
* slip past (e.g. "one booking per student per production", or a
|
|
2073
|
-
* single-column unique a live table already enforces under a name Prisma
|
|
2074
|
-
* wouldn't derive) — something a hook's existence check cannot close on
|
|
2075
|
-
* its own, and can't be retrofitted once duplicate rows exist. An
|
|
2076
|
-
* **index** (non-unique) entry is the equivalent performance-only case
|
|
2077
|
-
* (a hot lookup path).
|
|
2078
|
-
*
|
|
2079
|
-
* Two conditions fail `pnpm generate` with an error naming the list and
|
|
2080
|
-
* the entry: an empty `fields` array, and a single-field entry that
|
|
2081
|
-
* indexes the exact column a field-level `isIndexed` on the same list
|
|
2082
|
-
* already indexes (the error also names that field and its `isIndexed`
|
|
2083
|
-
* value — one of the two should be removed). An entry naming a field the
|
|
2084
|
-
* list doesn't have, a virtual field, a to-many relationship, or the
|
|
2085
|
-
* non-FK side of a one-to-one relationship fails the same way, naming
|
|
2086
|
-
* the bad field too — no entry is ever silently dropped or emitted as
|
|
2087
|
-
* invalid Prisma.
|
|
2088
|
-
*
|
|
2089
|
-
* `createdAt`/`updatedAt` are a valid entry even when the list has no
|
|
2090
|
-
* matching declared field — an entry may name either as long as the
|
|
2091
|
-
* list's auto-timestamps (`db.timestamps`, global or per-list) are
|
|
2092
|
-
* enabled for that column, since the auto-injected column has no `@map`
|
|
2093
|
-
* of its own and its Prisma field name is exactly `createdAt`/`updatedAt`.
|
|
2094
|
-
*
|
|
2095
|
-
* @example One audition per student per production (composite unique)
|
|
2096
|
-
* ```typescript
|
|
2097
|
-
* Audition: list({
|
|
2098
|
-
* fields: {
|
|
2099
|
-
* student: relationship({ ref: 'Student.auditions' }),
|
|
2100
|
-
* production: relationship({ ref: 'Production.auditions' }),
|
|
2101
|
-
* },
|
|
2102
|
-
* db: {
|
|
2103
|
-
* indexes: [{ fields: ['student', 'production'], unique: true }],
|
|
2104
|
-
* },
|
|
2105
|
-
* })
|
|
2106
|
-
* // Generates: @@unique([studentId, productionId])
|
|
2107
|
-
* ```
|
|
2108
|
-
*
|
|
2109
|
-
* @example Hot lookup path (composite index) with a sort direction and an adopted constraint name
|
|
2110
|
-
* ```typescript
|
|
2111
|
-
* AuthVerification: list({
|
|
2112
|
-
* fields: {
|
|
2113
|
-
* identifier: text(),
|
|
2114
|
-
* createdAt: timestamp(),
|
|
2115
|
-
* },
|
|
2116
|
-
* db: {
|
|
2117
|
-
* indexes: [
|
|
2118
|
-
* {
|
|
2119
|
-
* fields: ['identifier', { field: 'createdAt', sort: 'desc' }],
|
|
2120
|
-
* name: 'AuthVerification_identifier_createdAt_idx',
|
|
2121
|
-
* },
|
|
2122
|
-
* ],
|
|
2123
|
-
* },
|
|
2124
|
-
* })
|
|
2125
|
-
* // Generates: @@index([identifier, createdAt(sort: Desc)], map: "AuthVerification_identifier_createdAt_idx")
|
|
2126
|
-
* ```
|
|
2127
|
-
*
|
|
2128
|
-
* @example Naming a single-column unique constraint (adopting a live table's existing name)
|
|
2129
|
-
* ```typescript
|
|
2130
|
-
* RateLimit: list({
|
|
2131
|
-
* fields: { key: text() }, // no isIndexed here — db.indexes owns this column instead
|
|
2132
|
-
* db: {
|
|
2133
|
-
* indexes: [{ fields: ['key'], unique: true, name: 'RateLimit_key_key' }],
|
|
2134
|
-
* },
|
|
2135
|
-
* })
|
|
2136
|
-
* // Generates: @@unique([key], map: "RateLimit_key_key")
|
|
2137
|
-
* // Setting key's own isIndexed too would duplicate this constraint and
|
|
2138
|
-
* // fail generation — one of the two must own the column.
|
|
2139
|
-
* ```
|
|
2140
|
-
*/
|
|
2141
|
-
indexes?: ListIndex[]
|
|
2142
|
-
}
|
|
2143
|
-
mcp?: ListMcpConfig
|
|
2144
|
-
/**
|
|
2145
|
-
* Restricts this list to a single record (singleton pattern)
|
|
2146
|
-
* When true:
|
|
2147
|
-
* - Prevents creating multiple records
|
|
2148
|
-
* - Auto-creates the single record on first access (if autoCreate: true, which is the default)
|
|
2149
|
-
* - Provides a get() method for easy access to the singleton
|
|
2150
|
-
* - Blocks delete and findMany operations
|
|
2151
|
-
* - Changes UI to show edit form instead of list view
|
|
2152
|
-
*
|
|
2153
|
-
* @example Simple boolean (auto-create enabled)
|
|
2154
|
-
* ```typescript
|
|
2155
|
-
* isSingleton: true
|
|
2156
|
-
* ```
|
|
2157
|
-
*
|
|
2158
|
-
* @example With options
|
|
2159
|
-
* ```typescript
|
|
2160
|
-
* isSingleton: {
|
|
2161
|
-
* autoCreate: false // Don't auto-create, must be created manually
|
|
2162
|
-
* }
|
|
2163
|
-
* ```
|
|
2164
|
-
*/
|
|
2165
|
-
isSingleton?:
|
|
2166
|
-
| boolean
|
|
2167
|
-
| {
|
|
2168
|
-
/**
|
|
2169
|
-
* Auto-create the singleton record on first access using field defaults
|
|
2170
|
-
* @default true
|
|
2171
|
-
*/
|
|
2172
|
-
autoCreate?: boolean
|
|
2173
|
-
}
|
|
2174
|
-
/**
|
|
2175
|
-
* UI configuration for this list (admin interface).
|
|
2176
|
-
*
|
|
2177
|
-
* Mirrors Keystone's list-level `ui` block. Currently only `listView`
|
|
2178
|
-
* defaults (columns + sort) are supported.
|
|
2179
|
-
*/
|
|
2180
|
-
ui?: ListUIConfig
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
/**
|
|
2184
|
-
* List-level UI configuration for the admin interface.
|
|
2185
|
-
*
|
|
2186
|
-
* Mirrors Keystone's `ui` block on a list. List-view defaults (column
|
|
2187
|
-
* selection/order and default sort) and the label field are supported
|
|
2188
|
-
* today; other Keystone concerns (`label`, `description`) are intentionally
|
|
2189
|
-
* deferred as they cover navigation text rather than list-view or
|
|
2190
|
-
* row-labelling defaults.
|
|
2191
|
-
*/
|
|
2192
|
-
export type ListUIConfig = {
|
|
2193
|
-
/**
|
|
2194
|
-
* Default list-view (table) configuration for this list, mirroring
|
|
2195
|
-
* Keystone's `ui.listView`.
|
|
2196
|
-
*/
|
|
2197
|
-
listView?: ListViewUIConfig
|
|
2198
|
-
/**
|
|
2199
|
-
* Item-view (record edit page) configuration for this list — controls the
|
|
2200
|
-
* placement/order of the shape-derived Relationship-table sections (issue
|
|
2201
|
-
* #734). When omitted, sections appear in field-declaration order and the
|
|
2202
|
-
* layout is derived purely from the number of to-many relationships.
|
|
2203
|
-
*/
|
|
2204
|
-
itemView?: ItemViewUIConfig
|
|
2205
|
-
/**
|
|
2206
|
-
* The field used to represent a row as a single label — in relationship
|
|
2207
|
-
* cells, dropdown options, and page headings. Must reference a declared,
|
|
2208
|
-
* non-relationship field on this list.
|
|
2209
|
-
*
|
|
2210
|
-
* When omitted, resolves via `getLabelFieldName`'s fallback order: `name`
|
|
2211
|
-
* → `title` → `id` (first field that exists on the list).
|
|
2212
|
-
*
|
|
2213
|
-
* @example
|
|
2214
|
-
* ```typescript
|
|
2215
|
-
* ui: { labelField: 'email' }
|
|
2216
|
-
* ```
|
|
2217
|
-
*/
|
|
2218
|
-
labelField?: string
|
|
2219
|
-
/**
|
|
2220
|
-
* Opt this list into an access-scoped record count next to its Admin chrome
|
|
2221
|
-
* nav item (issue #735). Default `false` — no count query runs for lists that
|
|
2222
|
-
* don't opt in. The count is fetched through the secured context, so it only
|
|
2223
|
-
* ever reflects what the current session may see; a list whose query access
|
|
2224
|
-
* is statically denied renders no count rather than a misleading zero.
|
|
2225
|
-
*
|
|
2226
|
-
* @example
|
|
2227
|
-
* ```typescript
|
|
2228
|
-
* ui: { navCount: true }
|
|
2229
|
-
* ```
|
|
2230
|
-
*/
|
|
2231
|
-
navCount?: boolean
|
|
2232
|
-
/**
|
|
2233
|
-
* Opt this list's label column into an initials-avatar Cell (issue #735) — an
|
|
2234
|
-
* initials bubble whose text and colour derive deterministically from the row,
|
|
2235
|
-
* rendered ahead of the emphasized {@link getItemLabel Item label}. Default
|
|
2236
|
-
* `false` (text-only label). A per-field cell override (`ui.cell`) on the
|
|
2237
|
-
* label field still wins.
|
|
2238
|
-
*
|
|
2239
|
-
* @example
|
|
2240
|
-
* ```typescript
|
|
2241
|
-
* ui: { avatar: true }
|
|
2242
|
-
* ```
|
|
2243
|
-
*/
|
|
2244
|
-
avatar?: boolean
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
/**
|
|
2248
|
-
* Item-view (record edit page) configuration, mirroring the `ui.listView`
|
|
2249
|
-
* shape but for the shape-derived item layout (issue #734).
|
|
2250
|
-
*
|
|
2251
|
-
* The layout itself — single card / two-column split / stacked — is derived
|
|
2252
|
-
* from the number of to-many relationships rendered as Relationship tables and
|
|
2253
|
-
* needs no configuration. This block only reorders those sections; the
|
|
2254
|
-
* per-relationship column/sum/picker overrides live on the relationship field
|
|
2255
|
-
* (`ui.itemView`, see {@link RelationshipItemViewConfig}).
|
|
2256
|
-
*/
|
|
2257
|
-
export type ItemViewUIConfig = {
|
|
2258
|
-
/**
|
|
2259
|
-
* The order of the Relationship-table sections, by their to-many
|
|
2260
|
-
* relationship field name. Listed fields come first in this order; any
|
|
2261
|
-
* to-many relationship not listed keeps its declaration order after them.
|
|
2262
|
-
*
|
|
2263
|
-
* @example
|
|
2264
|
-
* ```typescript
|
|
2265
|
-
* ui: { itemView: { order: ['orders', 'reviews'] } }
|
|
2266
|
-
* ```
|
|
2267
|
-
*/
|
|
2268
|
-
order?: string[]
|
|
2269
|
-
}
|
|
2270
|
-
|
|
2271
|
-
/**
|
|
2272
|
-
* A button variant for a custom Bulk action, matching the admin UI's Button
|
|
2273
|
-
* variants. Serializable — it crosses to the client selection bar as a plain
|
|
2274
|
-
* string.
|
|
2275
|
-
*/
|
|
2276
|
-
export type BulkActionVariant =
|
|
2277
|
-
'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link'
|
|
2278
|
-
|
|
2279
|
-
/**
|
|
2280
|
-
* Arguments passed to a custom Bulk action's server-side `handler` (issue #736).
|
|
2281
|
-
*
|
|
2282
|
-
* The handler runs entirely server-side — it is NEVER serialized to the client —
|
|
2283
|
-
* and must do all of its work through the SECURED `context` (never raw Prisma),
|
|
2284
|
-
* so per-row access control still applies and a denied row is a Silent failure.
|
|
2285
|
-
*/
|
|
2286
|
-
export interface BulkActionContext {
|
|
2287
|
-
/** The list the action was invoked on (PascalCase list key). */
|
|
2288
|
-
listKey: string
|
|
2289
|
-
/** The explicit set of selected row ids the admin chose. */
|
|
2290
|
-
ids: string[]
|
|
2291
|
-
/**
|
|
2292
|
-
* The access-scoped context. All database work MUST go through `context.db`
|
|
2293
|
-
* so the list's access control and hooks are enforced for every id.
|
|
2294
|
-
*/
|
|
2295
|
-
context: import('../access/types.js').AccessContext
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
/**
|
|
2299
|
-
* The outcome a Bulk action `handler` returns. The optional `message` is shown
|
|
2300
|
-
* in the selection bar's status line once the action completes; returning
|
|
2301
|
-
* nothing yields a generic completion message.
|
|
2302
|
-
*/
|
|
2303
|
-
export interface BulkActionResult {
|
|
2304
|
-
/** Human-readable outcome shown to the admin (e.g. "Published 3 of 5"). */
|
|
2305
|
-
message?: string
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
/**
|
|
2309
|
-
* A list-specific custom Bulk action declared in `ui.listView.bulkActions`
|
|
2310
|
-
* (issue #736). Rendered as a button in the list view's selection bar, in
|
|
2311
|
-
* declaration order, alongside the built-in Delete.
|
|
2312
|
-
*
|
|
2313
|
-
* SERIALISATION BOUNDARY: only `key`, `label`, `variant` and `destructive`
|
|
2314
|
-
* cross to the client (as plain data). `handler` and `hasAccess` are
|
|
2315
|
-
* server-side functions and never leave the server — the client sends `key`
|
|
2316
|
-
* back through the generic server action, which looks the handler up and runs
|
|
2317
|
-
* it with the freshly-rebuilt secured context.
|
|
2318
|
-
*/
|
|
2319
|
-
export interface BulkAction {
|
|
2320
|
-
/**
|
|
2321
|
-
* Stable identifier the client echoes back to dispatch this action
|
|
2322
|
-
* server-side. Must be unique within the list.
|
|
2323
|
-
*/
|
|
2324
|
-
key: string
|
|
2325
|
-
/** Button label shown in the selection bar. */
|
|
2326
|
-
label: string
|
|
2327
|
-
/** Button variant (defaults to `'outline'`). */
|
|
2328
|
-
variant?: BulkActionVariant
|
|
2329
|
-
/**
|
|
2330
|
-
* When true, the admin is asked to confirm before the action runs, reusing
|
|
2331
|
-
* the same confirmation affordance as the built-in Delete.
|
|
2332
|
-
*/
|
|
2333
|
-
destructive?: boolean
|
|
2334
|
-
/**
|
|
2335
|
-
* Optional visibility gate, evaluated server-side against the session before
|
|
2336
|
-
* the button is offered (user story 14 — "only see actions I may perform").
|
|
2337
|
-
* Returning `false` hides the button.
|
|
2338
|
-
*
|
|
2339
|
-
* This ONLY controls visibility; the `handler` always runs through the
|
|
2340
|
-
* secured context, so per-row access is enforced regardless. It is also
|
|
2341
|
-
* re-checked server-side on dispatch, so a hidden action cannot be invoked.
|
|
2342
|
-
*/
|
|
2343
|
-
hasAccess?: (args: {
|
|
2344
|
-
session: import('../access/types.js').Session | null
|
|
2345
|
-
context: import('../access/types.js').AccessContext
|
|
2346
|
-
listKey: string
|
|
2347
|
-
}) => boolean | Promise<boolean>
|
|
2348
|
-
/**
|
|
2349
|
-
* The server-side handler. Receives the selected ids and the secured
|
|
2350
|
-
* `context`; do all work through `context.db`. Returns an optional
|
|
2351
|
-
* `{ message }` shown in the selection bar when the action completes.
|
|
2352
|
-
*/
|
|
2353
|
-
handler: (args: BulkActionContext) => BulkActionResult | void | Promise<BulkActionResult | void>
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
/**
|
|
2357
|
-
* Default list-view (table) configuration for a list, mirroring Keystone's
|
|
2358
|
-
* `ui.listView`.
|
|
2359
|
-
*
|
|
2360
|
-
* When omitted, the admin UI falls back to its existing defaults: every
|
|
2361
|
-
* field whose own `ui.listView.defaultColumn` declaration holds is shown as
|
|
2362
|
-
* a column (see {@link BaseFieldConfig.ui}) and no default sort is applied.
|
|
2363
|
-
*/
|
|
2364
|
-
export type ListViewUIConfig = {
|
|
2365
|
-
/**
|
|
2366
|
-
* The fields to show as columns in the list table, in order.
|
|
2367
|
-
*
|
|
2368
|
-
* Drives both the column **selection** and their **order**. When omitted,
|
|
2369
|
-
* every field whose own `ui.listView.defaultColumn` declaration holds is
|
|
2370
|
-
* shown (current default behaviour).
|
|
2371
|
-
*
|
|
2372
|
-
* @example
|
|
2373
|
-
* ```typescript
|
|
2374
|
-
* ui: { listView: { initialColumns: ['title', 'status', 'author'] } }
|
|
2375
|
-
* ```
|
|
2376
|
-
*/
|
|
2377
|
-
initialColumns?: string[]
|
|
2378
|
-
/**
|
|
2379
|
-
* The default sort applied to the list table.
|
|
2380
|
-
*
|
|
2381
|
-
* When omitted, no default sort is applied (current default behaviour).
|
|
2382
|
-
*
|
|
2383
|
-
* @example
|
|
2384
|
-
* ```typescript
|
|
2385
|
-
* ui: { listView: { initialSort: { field: 'createdAt', direction: 'desc' } } }
|
|
2386
|
-
* ```
|
|
2387
|
-
*/
|
|
2388
|
-
initialSort?: {
|
|
2389
|
-
/** The field to sort by. Must be a field defined on the list. */
|
|
2390
|
-
field: string
|
|
2391
|
-
/** The sort direction. */
|
|
2392
|
-
direction: 'asc' | 'desc'
|
|
2393
|
-
}
|
|
2394
|
-
/**
|
|
2395
|
-
* Custom list-specific Bulk actions shown in the list view's selection bar,
|
|
2396
|
-
* in declaration order, alongside the built-in Delete (issue #736). Each
|
|
2397
|
-
* action's `handler` runs server-side over the selected ids through the
|
|
2398
|
-
* secured context; only serializable metadata (`key`/`label`/`variant`/
|
|
2399
|
-
* `destructive`) crosses to the client.
|
|
2400
|
-
*
|
|
2401
|
-
* @example
|
|
2402
|
-
* ```typescript
|
|
2403
|
-
* ui: {
|
|
2404
|
-
* listView: {
|
|
2405
|
-
* bulkActions: [
|
|
2406
|
-
* {
|
|
2407
|
-
* key: 'publish',
|
|
2408
|
-
* label: 'Publish',
|
|
2409
|
-
* handler: async ({ ids, context }) => {
|
|
2410
|
-
* let n = 0
|
|
2411
|
-
* for (const id of ids) {
|
|
2412
|
-
* const r = await context.db.post.update({
|
|
2413
|
-
* where: { id },
|
|
2414
|
-
* data: { status: 'published' },
|
|
2415
|
-
* })
|
|
2416
|
-
* if (r) n++
|
|
2417
|
-
* }
|
|
2418
|
-
* return { message: `Published ${n} of ${ids.length}` }
|
|
2419
|
-
* },
|
|
2420
|
-
* },
|
|
2421
|
-
* ],
|
|
2422
|
-
* },
|
|
2423
|
-
* }
|
|
2424
|
-
* ```
|
|
2425
|
-
*/
|
|
2426
|
-
bulkActions?: BulkAction[]
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
/**
|
|
2430
|
-
* Input type for the list() function
|
|
2431
|
-
* Accepts both function shorthand and object form for access control.
|
|
2432
|
-
*/
|
|
2433
|
-
export type ListConfigInput<TTypeInfo extends TypeInfo> = Omit<ListConfig<TTypeInfo>, 'access'> & {
|
|
2434
|
-
/**
|
|
2435
|
-
* Access control configuration for this list.
|
|
2436
|
-
* Supports both function shorthand and object form.
|
|
2437
|
-
*
|
|
2438
|
-
* @example Function shorthand (applies to all operations)
|
|
2439
|
-
* ```typescript
|
|
2440
|
-
* access: isAdmin
|
|
2441
|
-
* ```
|
|
2442
|
-
*
|
|
2443
|
-
* @example Object form (per-operation)
|
|
2444
|
-
* ```typescript
|
|
2445
|
-
* access: { operation: { query: () => true, create: isAdmin } }
|
|
2446
|
-
* ```
|
|
2447
|
-
*/
|
|
2448
|
-
access?: ListAccessControl<TTypeInfo['item']>
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
|
-
export type DatabaseConfig = {
|
|
2452
|
-
provider: 'postgresql' | 'mysql' | 'sqlite'
|
|
2453
|
-
/**
|
|
2454
|
-
* Factory function to create a Prisma client instance with a database adapter
|
|
2455
|
-
* Required in Prisma 7+ - receives the PrismaClient class and returns a configured instance
|
|
2456
|
-
*
|
|
2457
|
-
* The connection URL is passed directly to the adapter, not to the config.
|
|
2458
|
-
*
|
|
2459
|
-
* @example SQLite with better-sqlite3
|
|
2460
|
-
* ```typescript
|
|
2461
|
-
* import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
|
|
2462
|
-
*
|
|
2463
|
-
* prismaClientConstructor: (PrismaClient) => {
|
|
2464
|
-
* const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL || 'file:./dev.db' })
|
|
2465
|
-
* return new PrismaClient({ adapter })
|
|
2466
|
-
* }
|
|
2467
|
-
* ```
|
|
2468
|
-
*
|
|
2469
|
-
* @example PostgreSQL with pg
|
|
2470
|
-
* ```typescript
|
|
2471
|
-
* import { PrismaPg } from '@prisma/adapter-pg'
|
|
2472
|
-
* import pg from 'pg'
|
|
2473
|
-
*
|
|
2474
|
-
* prismaClientConstructor: (PrismaClient) => {
|
|
2475
|
-
* const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
|
2476
|
-
* const adapter = new PrismaPg(pool)
|
|
2477
|
-
* return new PrismaClient({ adapter })
|
|
2478
|
-
* }
|
|
2479
|
-
* ```
|
|
2480
|
-
*
|
|
2481
|
-
* @example Neon serverless (PostgreSQL)
|
|
2482
|
-
* ```typescript
|
|
2483
|
-
* import { PrismaNeon } from '@prisma/adapter-neon'
|
|
2484
|
-
* import { neonConfig } from '@neondatabase/serverless'
|
|
2485
|
-
* import ws from 'ws'
|
|
2486
|
-
*
|
|
2487
|
-
* prismaClientConstructor: (PrismaClient) => {
|
|
2488
|
-
* neonConfig.webSocketConstructor = ws
|
|
2489
|
-
* const adapter = new PrismaNeon({
|
|
2490
|
-
* connectionString: process.env.DATABASE_URL
|
|
2491
|
-
* })
|
|
2492
|
-
* return new PrismaClient({ adapter })
|
|
2493
|
-
* }
|
|
2494
|
-
* ```
|
|
2495
|
-
*/
|
|
2496
|
-
// Uses `any` for maximum flexibility with Prisma client constructors and adapters
|
|
2497
|
-
// Different database adapters have varying type signatures that are hard to unify
|
|
2498
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2499
|
-
prismaClientConstructor: (PrismaClientClass: any) => any
|
|
2500
|
-
/**
|
|
2501
|
-
* Join table naming strategy for many-to-many relationships
|
|
2502
|
-
* - 'prisma': Use Prisma's default alphabetically-sorted naming (e.g., `_LessonToTeacher`)
|
|
2503
|
-
* - 'keystone': Use KeystoneJS-compatible naming based on field location (e.g., `_Lesson_teachers`)
|
|
2504
|
-
*
|
|
2505
|
-
* Default: 'prisma'
|
|
2506
|
-
*
|
|
2507
|
-
* **Important for KeystoneJS migration:**
|
|
2508
|
-
* When migrating from KeystoneJS, set this to 'keystone' to preserve existing join table names
|
|
2509
|
-
* and avoid data loss. Keystone names join tables as `_Model_fieldName` based on where the
|
|
2510
|
-
* relationship is defined in the schema.
|
|
2511
|
-
*
|
|
2512
|
-
* @example Preserve Keystone join table names during migration
|
|
2513
|
-
* ```typescript
|
|
2514
|
-
* db: {
|
|
2515
|
-
* provider: 'postgresql',
|
|
2516
|
-
* joinTableNaming: 'keystone', // Use KeystoneJS naming convention
|
|
2517
|
-
* // ... rest of config
|
|
2518
|
-
* }
|
|
2519
|
-
* ```
|
|
2520
|
-
*/
|
|
2521
|
-
joinTableNaming?: 'prisma' | 'keystone'
|
|
2522
|
-
/**
|
|
2523
|
-
* Postgres multi-schema support.
|
|
2524
|
-
*
|
|
2525
|
-
* When set, the generator enables Prisma's `multiSchema` preview feature and
|
|
2526
|
-
* emits the `schemas = [...]` array on the datasource block. Combine with a
|
|
2527
|
-
* per-list `db.schema` (see {@link ListConfig}) to place models in a specific
|
|
2528
|
-
* schema via `@@schema(...)`.
|
|
2529
|
-
*
|
|
2530
|
-
* Only applies to the `postgresql` provider. When unset, the generated schema
|
|
2531
|
-
* is unchanged (single `public` schema, no `@@schema` attributes).
|
|
2532
|
-
*
|
|
2533
|
-
* @example Separate `auth` schema alongside the default `public`
|
|
2534
|
-
* ```typescript
|
|
2535
|
-
* db: {
|
|
2536
|
-
* provider: 'postgresql',
|
|
2537
|
-
* schemas: ['public', 'auth'],
|
|
2538
|
-
* // ...
|
|
2539
|
-
* }
|
|
2540
|
-
* ```
|
|
2541
|
-
*/
|
|
2542
|
-
schemas?: string[]
|
|
2543
|
-
/**
|
|
2544
|
-
* Auto-inject `createdAt`/`updatedAt` timestamp columns into every generated model.
|
|
2545
|
-
*
|
|
2546
|
-
* Default: `false`. The generator does NOT add timestamps automatically — a list
|
|
2547
|
-
* opts in either by declaring the fields itself or by enabling this flag. This matches
|
|
2548
|
-
* Keystone 6, which never adds timestamps automatically, and keeps Keystone → stack
|
|
2549
|
-
* migrations non-destructive (Schema parity). See ADR-0004.
|
|
2550
|
-
*
|
|
2551
|
-
* When `true`, every list receives:
|
|
2552
|
-
* ```prisma
|
|
2553
|
-
* createdAt DateTime @default(now())
|
|
2554
|
-
* updatedAt DateTime @default(now()) @updatedAt
|
|
2555
|
-
* ```
|
|
2556
|
-
*
|
|
2557
|
-
* A per-list `db.timestamps` override takes precedence over this global setting. When
|
|
2558
|
-
* timestamps are enabled but a list already declares its own `createdAt`/`updatedAt`
|
|
2559
|
-
* field, the auto column is skipped for the declared field(s) so Prisma never sees a
|
|
2560
|
-
* duplicate (`P1012`).
|
|
2561
|
-
*
|
|
2562
|
-
* @default false
|
|
2563
|
-
*
|
|
2564
|
-
* @example Re-enable auto-timestamps globally
|
|
2565
|
-
* ```typescript
|
|
2566
|
-
* db: {
|
|
2567
|
-
* provider: 'postgresql',
|
|
2568
|
-
* timestamps: true,
|
|
2569
|
-
* // ... rest of config
|
|
2570
|
-
* }
|
|
2571
|
-
* ```
|
|
2572
|
-
*/
|
|
2573
|
-
timestamps?: boolean
|
|
2574
|
-
/**
|
|
2575
|
-
* Opt into Keystone-compat mode for generated schema defaults.
|
|
2576
|
-
*
|
|
2577
|
-
* Keystone 6 gives every non-null text column an implicit empty-string
|
|
2578
|
-
* default. With `keystoneCompat: true`, the generator mirrors that: any
|
|
2579
|
-
* non-null `text()` column that has no explicit `defaultValue` emits
|
|
2580
|
-
* `@default("")`, so a migrating project reaches Schema parity without
|
|
2581
|
-
* hand-setting `defaultValue: ''` on dozens of columns.
|
|
2582
|
-
*
|
|
2583
|
-
* Stays opt-in (default `false`) because a greenfield project would not want
|
|
2584
|
-
* implicit empty-string text defaults cluttering its schema. The flag never
|
|
2585
|
-
* affects nullable text, fields with an explicit `defaultValue`, or any
|
|
2586
|
-
* non-text field — an explicit `text({ defaultValue: 'x' })` always wins.
|
|
2587
|
-
*
|
|
2588
|
-
* @default false
|
|
2589
|
-
*
|
|
2590
|
-
* @example Reach Schema parity when migrating from Keystone
|
|
2591
|
-
* ```typescript
|
|
2592
|
-
* db: {
|
|
2593
|
-
* provider: 'postgresql',
|
|
2594
|
-
* keystoneCompat: true, // non-null text without a default → @default("")
|
|
2595
|
-
* // ... rest of config
|
|
2596
|
-
* }
|
|
2597
|
-
* ```
|
|
2598
|
-
*
|
|
2599
|
-
* @see ADR-0004 (Keystone-compatible generator defaults)
|
|
2600
|
-
*/
|
|
2601
|
-
keystoneCompat?: boolean
|
|
2602
|
-
/**
|
|
2603
|
-
* Optional function to extend or modify the generated Prisma schema
|
|
2604
|
-
* Receives the generated schema as a string and should return the modified schema
|
|
2605
|
-
* Useful for advanced Prisma features not directly supported by the config API
|
|
2606
|
-
*
|
|
2607
|
-
* @example Add multi-schema support for PostgreSQL
|
|
2608
|
-
* ```typescript
|
|
2609
|
-
* extendPrismaSchema: (schema) => {
|
|
2610
|
-
* // Add schemas array to datasource
|
|
2611
|
-
* let modifiedSchema = schema
|
|
2612
|
-
* .replace(
|
|
2613
|
-
* /(datasource db \{[^}]+provider\s*=\s*"postgresql")/,
|
|
2614
|
-
* '$1\n schemas = ["public", "auth"]'
|
|
2615
|
-
* )
|
|
2616
|
-
*
|
|
2617
|
-
* // Add @@schema("public") to all models
|
|
2618
|
-
* modifiedSchema = modifiedSchema.replace(
|
|
2619
|
-
* /^(model \w+\s*\{[\s\S]*?)(^}$)/gm,
|
|
2620
|
-
* (match, modelContent) => {
|
|
2621
|
-
* if (!modelContent.includes('@@schema')) {
|
|
2622
|
-
* return `${modelContent}\n @@schema("public")\n}`
|
|
2623
|
-
* }
|
|
2624
|
-
* return match
|
|
2625
|
-
* }
|
|
2626
|
-
* )
|
|
2627
|
-
*
|
|
2628
|
-
* return modifiedSchema
|
|
2629
|
-
* }
|
|
2630
|
-
* ```
|
|
2631
|
-
*/
|
|
2632
|
-
extendPrismaSchema?: (schema: string) => string
|
|
2633
|
-
/**
|
|
2634
|
-
* Override the Prisma `generator client { ... }` options the CLI emits for the
|
|
2635
|
-
* `.opensaas` prisma-client subtree.
|
|
2636
|
-
*
|
|
2637
|
-
* By default the generator emits `importFileExtension = "ts"` and
|
|
2638
|
-
* `moduleFormat = "esm"` so the whole generated bundle is statically
|
|
2639
|
-
* resolvable and matches the explicit `.ts` import-extension style the rest of
|
|
2640
|
-
* the `.opensaas` bundle uses (see ADR-0008). Supply this option only when you
|
|
2641
|
-
* need a different module/extension story (e.g. emitting `.js` extensions for a
|
|
2642
|
-
* Node-only consumer). Any value you provide wins; omitted keys fall back to
|
|
2643
|
-
* the `ts`/`esm` defaults.
|
|
2644
|
-
*
|
|
2645
|
-
* @example Emit `.js` extensions and CommonJS for a plain-Node consumer
|
|
2646
|
-
* ```typescript
|
|
2647
|
-
* db: {
|
|
2648
|
-
* provider: 'postgresql',
|
|
2649
|
-
* prismaGeneratorOptions: {
|
|
2650
|
-
* importFileExtension: 'js',
|
|
2651
|
-
* moduleFormat: 'commonjs',
|
|
2652
|
-
* },
|
|
2653
|
-
* // ... rest of config
|
|
2654
|
-
* }
|
|
2655
|
-
* ```
|
|
2656
|
-
*/
|
|
2657
|
-
prismaGeneratorOptions?: {
|
|
2658
|
-
/**
|
|
2659
|
-
* Value for the generator's `importFileExtension` option. Defaults to `'ts'`.
|
|
2660
|
-
*/
|
|
2661
|
-
importFileExtension?: 'ts' | 'js'
|
|
2662
|
-
/**
|
|
2663
|
-
* Value for the generator's `moduleFormat` option. Defaults to `'esm'`.
|
|
2664
|
-
*/
|
|
2665
|
-
moduleFormat?: 'esm' | 'commonjs'
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
export type SessionConfig = {
|
|
2670
|
-
// Uses `any` return type because session structure is user-defined and varies per application
|
|
2671
|
-
// The stack doesn't enforce a specific session shape - users can use NextAuth, Clerk, etc.
|
|
2672
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2673
|
-
getSession: () => Promise<any>
|
|
2674
|
-
}
|
|
2675
|
-
|
|
2676
|
-
export type ThemePreset = 'modern' | 'classic' | 'neon'
|
|
2677
|
-
|
|
2678
|
-
/**
|
|
2679
|
-
* Custom theme colors.
|
|
2680
|
-
*
|
|
2681
|
-
* Each value is passed through verbatim to the corresponding CSS custom
|
|
2682
|
-
* property, so any valid CSS color string works: `oklch(…)`, `#hex`, `rgb(…)`,
|
|
2683
|
-
* or a wrapped `hsl(…)`. Bare HSL triplets (`"220 20% 97%"`) are a clean break —
|
|
2684
|
-
* they are no longer accepted and trigger a dev-mode warning. See
|
|
2685
|
-
* `specs/THEMING.md` and ADR-0015.
|
|
2686
|
-
*/
|
|
2687
|
-
export type ThemeColors = {
|
|
2688
|
-
background?: string
|
|
2689
|
-
foreground?: string
|
|
2690
|
-
card?: string
|
|
2691
|
-
cardForeground?: string
|
|
2692
|
-
popover?: string
|
|
2693
|
-
popoverForeground?: string
|
|
2694
|
-
primary?: string
|
|
2695
|
-
primaryForeground?: string
|
|
2696
|
-
secondary?: string
|
|
2697
|
-
secondaryForeground?: string
|
|
2698
|
-
muted?: string
|
|
2699
|
-
mutedForeground?: string
|
|
2700
|
-
accent?: string
|
|
2701
|
-
accentForeground?: string
|
|
2702
|
-
destructive?: string
|
|
2703
|
-
destructiveForeground?: string
|
|
2704
|
-
success?: string
|
|
2705
|
-
successForeground?: string
|
|
2706
|
-
warning?: string
|
|
2707
|
-
warningForeground?: string
|
|
2708
|
-
border?: string
|
|
2709
|
-
input?: string
|
|
2710
|
-
ring?: string
|
|
2711
|
-
gradientFrom?: string
|
|
2712
|
-
gradientTo?: string
|
|
2713
|
-
}
|
|
2714
|
-
|
|
2715
|
-
/**
|
|
2716
|
-
* Font family tokens. Each value is a CSS `font-family` string, designed to
|
|
2717
|
-
* compose with `next/font`: set the value to the font's CSS variable, e.g.
|
|
2718
|
-
* `sans: 'var(--font-inter), system-ui, sans-serif'`. `heading` defaults to the
|
|
2719
|
-
* `sans` value when omitted.
|
|
2720
|
-
*/
|
|
2721
|
-
export type ThemeFonts = {
|
|
2722
|
-
sans?: string
|
|
2723
|
-
mono?: string
|
|
2724
|
-
heading?: string
|
|
2725
|
-
}
|
|
2726
|
-
|
|
2727
|
-
/**
|
|
2728
|
-
* Elevation shadow tokens. Each value is a CSS `box-shadow` string. Set them to
|
|
2729
|
-
* `'none'` for a fully flat theme without forking components.
|
|
2730
|
-
*/
|
|
2731
|
-
export type ThemeShadows = {
|
|
2732
|
-
sm?: string
|
|
2733
|
-
md?: string
|
|
2734
|
-
lg?: string
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
|
-
/**
|
|
2738
|
-
* Theme configuration. Compiles to token overrides written onto the same CSS
|
|
2739
|
-
* custom properties the UI package stylesheet declares — the config layer and
|
|
2740
|
-
* the stylesheet write to one token set so they can never drift (ADR-0015).
|
|
2741
|
-
*/
|
|
2742
|
-
export type ThemeConfig = {
|
|
2743
|
-
/**
|
|
2744
|
-
* Preset theme to start from. Individual tokens can be overridden on top.
|
|
2745
|
-
* @default "modern"
|
|
2746
|
-
*/
|
|
2747
|
-
preset?: ThemePreset
|
|
2748
|
-
/**
|
|
2749
|
-
* Custom color overrides for light mode.
|
|
2750
|
-
*/
|
|
2751
|
-
colors?: ThemeColors
|
|
2752
|
-
/**
|
|
2753
|
-
* Custom color overrides for dark mode.
|
|
2754
|
-
*/
|
|
2755
|
-
darkColors?: ThemeColors
|
|
2756
|
-
/**
|
|
2757
|
-
* Font family overrides (`--font-sans`, `--font-mono`, `--font-heading`).
|
|
2758
|
-
*/
|
|
2759
|
-
fonts?: ThemeFonts
|
|
2760
|
-
/**
|
|
2761
|
-
* Base border radius in rem. Derived sm/md/lg radii are computed from it.
|
|
2762
|
-
* @default 0.625
|
|
2763
|
-
*/
|
|
2764
|
-
radius?: number
|
|
2765
|
-
/**
|
|
2766
|
-
* Elevation shadow overrides (`--shadow-sm`, `--shadow-md`, `--shadow-lg`).
|
|
2767
|
-
*/
|
|
2768
|
-
shadows?: ThemeShadows
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
export type UIConfig = {
|
|
2772
|
-
basePath?: string
|
|
2773
|
-
theme?: ThemeConfig
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
/**
|
|
2777
|
-
* MCP (Model Context Protocol) configuration
|
|
2778
|
-
*/
|
|
2779
|
-
|
|
2780
|
-
/**
|
|
2781
|
-
* Configuration for which CRUD tools to enable for a list
|
|
2782
|
-
*/
|
|
2783
|
-
export type McpToolsConfig = {
|
|
2784
|
-
/**
|
|
2785
|
-
* Enable read/query tool
|
|
2786
|
-
* @default true
|
|
2787
|
-
*/
|
|
2788
|
-
read?: boolean
|
|
2789
|
-
/**
|
|
2790
|
-
* Enable create tool
|
|
2791
|
-
* @default true
|
|
2792
|
-
*/
|
|
2793
|
-
create?: boolean
|
|
2794
|
-
/**
|
|
2795
|
-
* Enable update tool
|
|
2796
|
-
* @default true
|
|
2797
|
-
*/
|
|
2798
|
-
update?: boolean
|
|
2799
|
-
/**
|
|
2800
|
-
* Enable delete tool
|
|
2801
|
-
* @default true
|
|
2802
|
-
*/
|
|
2803
|
-
delete?: boolean
|
|
2804
|
-
}
|
|
2805
|
-
|
|
2806
|
-
/**
|
|
2807
|
-
* Custom MCP tool definition
|
|
2808
|
-
* Allows developers to add custom tools for specific lists
|
|
2809
|
-
*/
|
|
2810
|
-
export type McpCustomTool = {
|
|
2811
|
-
/**
|
|
2812
|
-
* Unique name for the tool
|
|
2813
|
-
*/
|
|
2814
|
-
name: string
|
|
2815
|
-
description: string
|
|
2816
|
-
/**
|
|
2817
|
-
* Input schema (Zod schema)
|
|
2818
|
-
*/
|
|
2819
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2820
|
-
inputSchema: any
|
|
2821
|
-
handler: (args: {
|
|
2822
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2823
|
-
input: any
|
|
2824
|
-
context: import('../access/types.js').AccessContext
|
|
2825
|
-
}) => Promise<unknown>
|
|
2826
|
-
}
|
|
2827
|
-
|
|
2828
|
-
export type ListMcpConfig = {
|
|
2829
|
-
/**
|
|
2830
|
-
* Enable MCP tools for this list
|
|
2831
|
-
* @default true
|
|
2832
|
-
*/
|
|
2833
|
-
enabled?: boolean
|
|
2834
|
-
/**
|
|
2835
|
-
* Configure which CRUD tools to enable
|
|
2836
|
-
*/
|
|
2837
|
-
tools?: McpToolsConfig
|
|
2838
|
-
/**
|
|
2839
|
-
* Custom tools specific to this list
|
|
2840
|
-
*/
|
|
2841
|
-
customTools?: McpCustomTool[]
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
/**
|
|
2845
|
-
* OAuth configuration for MCP authentication
|
|
2846
|
-
* Supports Better Auth and custom auth providers
|
|
2847
|
-
*/
|
|
2848
|
-
export type McpAuthConfig =
|
|
2849
|
-
| {
|
|
2850
|
-
/**
|
|
2851
|
-
* Authentication type - Better Auth integration
|
|
2852
|
-
*/
|
|
2853
|
-
type: 'better-auth'
|
|
2854
|
-
/**
|
|
2855
|
-
* Path to login page for OAuth flow
|
|
2856
|
-
*/
|
|
2857
|
-
loginPage: string
|
|
2858
|
-
/**
|
|
2859
|
-
* OAuth scopes to request
|
|
2860
|
-
* @default ["openid", "profile", "email"]
|
|
2861
|
-
*/
|
|
2862
|
-
scopes?: string[]
|
|
2863
|
-
/**
|
|
2864
|
-
* Optional OIDC configuration
|
|
2865
|
-
*/
|
|
2866
|
-
oidcConfig?: {
|
|
2867
|
-
/**
|
|
2868
|
-
* Code expiration time in seconds
|
|
2869
|
-
* @default 600
|
|
2870
|
-
*/
|
|
2871
|
-
codeExpiresIn?: number
|
|
2872
|
-
/**
|
|
2873
|
-
* Access token expiration time in seconds
|
|
2874
|
-
* @default 3600
|
|
2875
|
-
*/
|
|
2876
|
-
accessTokenExpiresIn?: number
|
|
2877
|
-
/**
|
|
2878
|
-
* Refresh token expiration time in seconds
|
|
2879
|
-
* @default 604800
|
|
2880
|
-
*/
|
|
2881
|
-
refreshTokenExpiresIn?: number
|
|
2882
|
-
/**
|
|
2883
|
-
* Default scope for OAuth requests
|
|
2884
|
-
* @default "openid"
|
|
2885
|
-
*/
|
|
2886
|
-
defaultScope?: string
|
|
2887
|
-
/**
|
|
2888
|
-
* Additional scopes to support
|
|
2889
|
-
*/
|
|
2890
|
-
scopes?: string[]
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
| {
|
|
2894
|
-
/**
|
|
2895
|
-
* Authentication type - custom auth provider
|
|
2896
|
-
*/
|
|
2897
|
-
type: string
|
|
2898
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Allows custom auth provider configuration
|
|
2899
|
-
[key: string]: any
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
/**
|
|
2903
|
-
* Global MCP server configuration
|
|
2904
|
-
*/
|
|
2905
|
-
export type McpConfig = {
|
|
2906
|
-
/**
|
|
2907
|
-
* Enable MCP server globally
|
|
2908
|
-
* @default false
|
|
2909
|
-
*/
|
|
2910
|
-
enabled?: boolean
|
|
2911
|
-
/**
|
|
2912
|
-
* Base path for MCP API routes
|
|
2913
|
-
* @default "/api/mcp"
|
|
2914
|
-
*/
|
|
2915
|
-
basePath?: string
|
|
2916
|
-
/**
|
|
2917
|
-
* Authentication configuration
|
|
2918
|
-
* Required when MCP is enabled
|
|
2919
|
-
*/
|
|
2920
|
-
auth?: McpAuthConfig
|
|
2921
|
-
/**
|
|
2922
|
-
* Default tool configuration for all lists
|
|
2923
|
-
* Can be overridden per-list
|
|
2924
|
-
*/
|
|
2925
|
-
defaultTools?: McpToolsConfig
|
|
2926
|
-
/**
|
|
2927
|
-
* Resource identifier for OAuth protected resource metadata
|
|
2928
|
-
* @default "https://yourdomain.com"
|
|
2929
|
-
*/
|
|
2930
|
-
resource?: string
|
|
2931
|
-
}
|
|
2932
|
-
|
|
2933
|
-
/**
|
|
2934
|
-
* Storage configuration for file uploads
|
|
2935
|
-
* Maps storage provider names to their configurations
|
|
2936
|
-
*
|
|
2937
|
-
* @example
|
|
2938
|
-
* ```typescript
|
|
2939
|
-
* storage: {
|
|
2940
|
-
* avatars: s3Storage({ bucket: 'my-avatars', region: 'us-east-1' }),
|
|
2941
|
-
* documents: localStorage({ uploadDir: './uploads', serveUrl: '/api/files' })
|
|
2942
|
-
* }
|
|
2943
|
-
* ```
|
|
2944
|
-
*/
|
|
2945
|
-
/**
|
|
2946
|
-
* File metadata stored in the database (as JSON)
|
|
2947
|
-
* Used by file upload fields to track uploaded files
|
|
2948
|
-
*/
|
|
2949
|
-
export interface FileMetadata {
|
|
2950
|
-
/** Generated filename in storage */
|
|
2951
|
-
filename: string
|
|
2952
|
-
/** Original filename from upload */
|
|
2953
|
-
originalFilename: string
|
|
2954
|
-
/** Public URL to access the file */
|
|
2955
|
-
url: string
|
|
2956
|
-
/** MIME type */
|
|
2957
|
-
mimeType: string
|
|
2958
|
-
/** File size in bytes */
|
|
2959
|
-
size: number
|
|
2960
|
-
/** Upload timestamp */
|
|
2961
|
-
uploadedAt: string
|
|
2962
|
-
/** Storage provider name */
|
|
2963
|
-
storageProvider: string
|
|
2964
|
-
/** Additional provider-specific metadata */
|
|
2965
|
-
metadata?: Record<string, unknown>
|
|
2966
|
-
}
|
|
2967
|
-
|
|
2968
|
-
/**
|
|
2969
|
-
* Image-specific metadata (extends FileMetadata)
|
|
2970
|
-
* Includes dimensions and optional transformations
|
|
2971
|
-
*/
|
|
2972
|
-
export interface ImageMetadata extends FileMetadata {
|
|
2973
|
-
/** Image width in pixels */
|
|
2974
|
-
width: number
|
|
2975
|
-
/** Image height in pixels */
|
|
2976
|
-
height: number
|
|
2977
|
-
/** Generated image transformations/variants */
|
|
2978
|
-
transformations?: Record<string, ImageTransformationResult>
|
|
2979
|
-
}
|
|
2980
|
-
|
|
2981
|
-
/**
|
|
2982
|
-
* Result of an image transformation
|
|
2983
|
-
*/
|
|
2984
|
-
export interface ImageTransformationResult {
|
|
2985
|
-
/** URL to the transformed image */
|
|
2986
|
-
url: string
|
|
2987
|
-
/** Width in pixels */
|
|
2988
|
-
width: number
|
|
2989
|
-
/** Height in pixels */
|
|
2990
|
-
height: number
|
|
2991
|
-
/** File size in bytes */
|
|
2992
|
-
size: number
|
|
2993
|
-
}
|
|
2994
|
-
|
|
2995
|
-
export type StorageConfig = Record<string, { type: string; [key: string]: unknown }>
|
|
2996
|
-
|
|
2997
|
-
/**
|
|
2998
|
-
* Plugin system types
|
|
2999
|
-
*/
|
|
3000
|
-
|
|
3001
|
-
/**
|
|
3002
|
-
* Files generated by the core generators
|
|
3003
|
-
* Plugins can modify these during afterGenerate hooks
|
|
3004
|
-
*/
|
|
3005
|
-
export type GeneratedFiles = {
|
|
3006
|
-
prismaSchema: string
|
|
3007
|
-
types: string
|
|
3008
|
-
context: string
|
|
3009
|
-
[key: string]: string // Allow plugins to add custom generated files
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
/**
|
|
3013
|
-
* Context provided to plugins during initialization
|
|
3014
|
-
* Provides helpers for safely modifying config
|
|
3015
|
-
*/
|
|
3016
|
-
export type PluginContext = {
|
|
3017
|
-
/**
|
|
3018
|
-
* Current config state (read-only)
|
|
3019
|
-
* Plugins should use helper methods to modify config, not mutate directly
|
|
3020
|
-
*/
|
|
3021
|
-
readonly config: OpenSaasConfig
|
|
3022
|
-
|
|
3023
|
-
/**
|
|
3024
|
-
* Add a new list to the config
|
|
3025
|
-
* Throws error if list already exists
|
|
3026
|
-
*/
|
|
3027
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Plugin API must accept any list config
|
|
3028
|
-
addList: (name: string, listConfig: ListConfig<any>) => void
|
|
3029
|
-
|
|
3030
|
-
/**
|
|
3031
|
-
* Extend an existing list with additional fields, hooks, or MCP config.
|
|
3032
|
-
* Merges fields, hooks, and MCP config. Throws if the list doesn't exist,
|
|
3033
|
-
* or if the extension sets operation-level `access` — access control
|
|
3034
|
-
* belongs to whoever created the list, never a plugin extending it
|
|
3035
|
-
* (ADR-0013).
|
|
3036
|
-
*/
|
|
3037
|
-
extendList: (
|
|
3038
|
-
name: string,
|
|
3039
|
-
extension: {
|
|
3040
|
-
fields?: Record<string, FieldConfig>
|
|
3041
|
-
hooks?: Hooks
|
|
3042
|
-
access?: {
|
|
3043
|
-
operation?: OperationAccess
|
|
3044
|
-
}
|
|
3045
|
-
mcp?: ListMcpConfig
|
|
3046
|
-
},
|
|
3047
|
-
) => void
|
|
3048
|
-
|
|
3049
|
-
/**
|
|
3050
|
-
* Register a field type globally
|
|
3051
|
-
* Useful for third-party field packages
|
|
3052
|
-
*/
|
|
3053
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Plugin API must accept any field config builder
|
|
3054
|
-
registerFieldType?: (type: string, builder: (options?: unknown) => BaseFieldConfig<any>) => void
|
|
3055
|
-
|
|
3056
|
-
/**
|
|
3057
|
-
* Register a custom MCP tool
|
|
3058
|
-
* Tools are added to the global MCP server
|
|
3059
|
-
*/
|
|
3060
|
-
registerMcpTool?: (tool: McpCustomTool) => void
|
|
3061
|
-
|
|
3062
|
-
/**
|
|
3063
|
-
* Store plugin-specific data in config for runtime access
|
|
3064
|
-
* Prefixed with plugin name to avoid conflicts
|
|
3065
|
-
*/
|
|
3066
|
-
setPluginData: <T>(pluginName: string, data: T) => void
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
/**
|
|
3070
|
-
* Plugin definition
|
|
3071
|
-
* Plugins can extend config, inject lists, add hooks, and participate in generation lifecycle
|
|
3072
|
-
*/
|
|
3073
|
-
export type Plugin = {
|
|
3074
|
-
/**
|
|
3075
|
-
* Unique plugin name (used for dependency resolution and data storage)
|
|
3076
|
-
*/
|
|
3077
|
-
name: string
|
|
3078
|
-
|
|
3079
|
-
/**
|
|
3080
|
-
* Plugin version (semantic versioning)
|
|
3081
|
-
*/
|
|
3082
|
-
version?: string
|
|
3083
|
-
|
|
3084
|
-
/**
|
|
3085
|
-
* Dependencies on other plugins (by name)
|
|
3086
|
-
* Ensures plugins execute in correct order
|
|
3087
|
-
*/
|
|
3088
|
-
dependencies?: string[]
|
|
3089
|
-
|
|
3090
|
-
/**
|
|
3091
|
-
* Main initialization hook
|
|
3092
|
-
* Called during config processing to extend or modify configuration
|
|
3093
|
-
*/
|
|
3094
|
-
init: (context: PluginContext) => void | Promise<void>
|
|
3095
|
-
|
|
3096
|
-
/**
|
|
3097
|
-
* Optional: Modify config before Prisma schema generation
|
|
3098
|
-
* Useful for programmatic config transformations
|
|
3099
|
-
*/
|
|
3100
|
-
beforeGenerate?: (config: OpenSaasConfig) => OpenSaasConfig | Promise<OpenSaasConfig>
|
|
3101
|
-
|
|
3102
|
-
/**
|
|
3103
|
-
* Optional: Post-process generated files
|
|
3104
|
-
* Allows plugins to modify Prisma schema, types, or add custom generated files
|
|
3105
|
-
*/
|
|
3106
|
-
afterGenerate?: (files: GeneratedFiles) => GeneratedFiles | Promise<GeneratedFiles>
|
|
3107
|
-
|
|
3108
|
-
/**
|
|
3109
|
-
* Optional: Provide runtime services
|
|
3110
|
-
* Called when creating context to provide plugin-specific services
|
|
3111
|
-
* Return value is stored in context.plugins[pluginName]
|
|
3112
|
-
*
|
|
3113
|
-
* `sudo` returns an access-bypassing (but still hook-firing) `AccessContext`
|
|
3114
|
-
* for the same request — use `sudo().db` for reads/writes that must not
|
|
3115
|
-
* depend on the caller's own list access policy (e.g. an identity lookup
|
|
3116
|
-
* like "who is this session"). Deliberately NOT a method on `AccessContext`
|
|
3117
|
-
* itself — a self-referential `sudo(): AccessContext` field on that shared,
|
|
3118
|
-
* widely-instantiated interface tripped up TypeScript's structural checking
|
|
3119
|
-
* of unrelated generated Prisma types elsewhere (nullable JSON `CreateInput`
|
|
3120
|
-
* fields) in a downstream app; passing it as a plain second argument avoids
|
|
3121
|
-
* that recursion entirely.
|
|
3122
|
-
*/
|
|
3123
|
-
runtime?: (
|
|
3124
|
-
context: import('../access/types.js').AccessContext,
|
|
3125
|
-
sudo: () => import('../access/types.js').AccessContext,
|
|
3126
|
-
) => unknown
|
|
3127
|
-
|
|
3128
|
-
/**
|
|
3129
|
-
* Optional: Type metadata for runtime services
|
|
3130
|
-
* Enables type-safe code generation for context.plugins
|
|
3131
|
-
*
|
|
3132
|
-
* @example
|
|
3133
|
-
* ```typescript
|
|
3134
|
-
* {
|
|
3135
|
-
* import: "import type { AuthRuntimeServices } from '@opensaas/stack-auth/runtime'",
|
|
3136
|
-
* typeName: "AuthRuntimeServices"
|
|
3137
|
-
* }
|
|
3138
|
-
* ```
|
|
3139
|
-
*/
|
|
3140
|
-
runtimeServiceTypes?: {
|
|
3141
|
-
/**
|
|
3142
|
-
* Import statement to include in generated types file
|
|
3143
|
-
* Must be a complete import statement with 'import type' and quotes
|
|
3144
|
-
*/
|
|
3145
|
-
import: string
|
|
3146
|
-
/**
|
|
3147
|
-
* TypeScript type name to use in PluginServices interface
|
|
3148
|
-
* Should match the exported type from the import
|
|
3149
|
-
*/
|
|
3150
|
-
typeName: string
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
/**
|
|
3155
|
-
* Configurable generator output locations.
|
|
3156
|
-
*
|
|
3157
|
-
* Lets a project relocate the generated Prisma schema and the `.opensaas`
|
|
3158
|
-
* bundle directory. Paths are interpreted relative to the project root.
|
|
3159
|
-
*
|
|
3160
|
-
* @example
|
|
3161
|
-
* ```typescript
|
|
3162
|
-
* output: {
|
|
3163
|
-
* prismaSchema: 'prisma-opensaas/schema.prisma',
|
|
3164
|
-
* opensaasDir: '.opensaas',
|
|
3165
|
-
* }
|
|
3166
|
-
* ```
|
|
3167
|
-
*/
|
|
3168
|
-
export interface OutputConfig {
|
|
3169
|
-
/**
|
|
3170
|
-
* Path to the generated Prisma schema file.
|
|
3171
|
-
* @default "prisma/schema.prisma"
|
|
3172
|
-
*/
|
|
3173
|
-
prismaSchema?: string
|
|
3174
|
-
/**
|
|
3175
|
-
* Directory for the generated `.opensaas` bundle (types, lists, context,
|
|
3176
|
-
* plugin-types, and the patched Prisma client).
|
|
3177
|
-
* @default ".opensaas"
|
|
3178
|
-
*/
|
|
3179
|
-
opensaasDir?: string
|
|
3180
|
-
/**
|
|
3181
|
-
* Opt in to an additional **Node build** of the Generated bundle.
|
|
3182
|
-
*
|
|
3183
|
-
* By default (omitted) the generator emits only the bundler-loadable `.ts`
|
|
3184
|
-
* form (ADR-0008): TypeScript with explicit `.ts` import extensions, traced
|
|
3185
|
-
* and transpiled by the host's bundler. That form cannot execute under plain
|
|
3186
|
-
* Node, so a live module that must run in BOTH a bundled and a bundler-less
|
|
3187
|
-
* runtime (e.g. better-auth's Prisma adapter, imported by the Next server AND
|
|
3188
|
-
* by a Playwright e2e helper or a build-time script) has no Node-loadable
|
|
3189
|
-
* entry to point at.
|
|
3190
|
-
*
|
|
3191
|
-
* Setting `buildTarget: 'node'` additionally compiles the bundle to a
|
|
3192
|
-
* plain-Node-loadable ESM form under `<opensaasDir>/dist/` (`.js` + `.d.ts`,
|
|
3193
|
-
* with a `{"type":"module"}` marker). The compiled entry is
|
|
3194
|
-
* `<opensaasDir>/dist/context.js`; a portable module imports it directly so
|
|
3195
|
-
* the bundler traces it AND plain Node executes it (one specifier, both
|
|
3196
|
-
* runtimes — see ADR-0011). The default `.ts` form is unchanged and still
|
|
3197
|
-
* emitted; the Node build is purely additive.
|
|
3198
|
-
*
|
|
3199
|
-
* `'node'` is the only target today. The field is a string-literal union so
|
|
3200
|
-
* future compiled targets can be added without a breaking change.
|
|
3201
|
-
*
|
|
3202
|
-
* @example
|
|
3203
|
-
* ```typescript
|
|
3204
|
-
* export default config({
|
|
3205
|
-
* output: { buildTarget: 'node' },
|
|
3206
|
-
* // ...
|
|
3207
|
-
* })
|
|
3208
|
-
* // Then import the compiled entry from a plain-Node consumer:
|
|
3209
|
-
* // const { rawOpensaasContext } = await import('./.opensaas/dist/context.js')
|
|
3210
|
-
* ```
|
|
3211
|
-
*/
|
|
3212
|
-
buildTarget?: 'node'
|
|
3213
|
-
}
|
|
3214
|
-
|
|
3215
|
-
/**
|
|
3216
|
-
* Main configuration type.
|
|
3217
|
-
* Uses an interface, not a type alias, so it can be extended via module augmentation.
|
|
3218
|
-
*/
|
|
3219
|
-
export interface OpenSaasConfig {
|
|
3220
|
-
db: DatabaseConfig
|
|
3221
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Config must accept any list configuration
|
|
3222
|
-
lists: Record<string, ListConfig<any>>
|
|
3223
|
-
session?: SessionConfig
|
|
3224
|
-
ui?: UIConfig
|
|
3225
|
-
/**
|
|
3226
|
-
* MCP (Model Context Protocol) server configuration
|
|
3227
|
-
*/
|
|
3228
|
-
mcp?: McpConfig
|
|
3229
|
-
/**
|
|
3230
|
-
* Storage configuration for file/image uploads
|
|
3231
|
-
* Maps named storage providers to their configurations
|
|
3232
|
-
*/
|
|
3233
|
-
storage?: StorageConfig
|
|
3234
|
-
/**
|
|
3235
|
-
* Path where OpenSaas generates files (context, types, patched Prisma client)
|
|
3236
|
-
* @default ".opensaas"
|
|
3237
|
-
*/
|
|
3238
|
-
opensaasPath?: string
|
|
3239
|
-
/**
|
|
3240
|
-
* Relocate the generator's output so `opensaas generate` can coexist with an
|
|
3241
|
-
* existing `prisma/` directory (e.g. during a Keystone → stack migration).
|
|
3242
|
-
*
|
|
3243
|
-
* Both fields are resolved relative to the project root (the directory the
|
|
3244
|
-
* CLI runs in). When omitted, defaults are unchanged: the schema is written to
|
|
3245
|
-
* `prisma/schema.prisma` and the `.opensaas` bundle to `.opensaas/`.
|
|
3246
|
-
*
|
|
3247
|
-
* The generated files' cross-references follow these locations — `context.ts`
|
|
3248
|
-
* imports the generated types/lists from the resolved `.opensaas` dir, and the
|
|
3249
|
-
* top-level `prisma.config.ts` points at the configured schema path so the
|
|
3250
|
-
* `prisma` CLI keeps working.
|
|
3251
|
-
*/
|
|
3252
|
-
output?: OutputConfig
|
|
3253
|
-
/**
|
|
3254
|
-
* Plugins to extend the stack
|
|
3255
|
-
* Executed in array order (or dependency order if dependencies specified)
|
|
3256
|
-
*/
|
|
3257
|
-
plugins?: Plugin[]
|
|
3258
|
-
/**
|
|
3259
|
-
* Plugin-specific data storage
|
|
3260
|
-
* Keyed by plugin name, used for runtime configuration
|
|
3261
|
-
* @internal
|
|
3262
|
-
*/
|
|
3263
|
-
_pluginData?: Record<string, unknown>
|
|
3264
|
-
/**
|
|
3265
|
-
* Sorted plugin instances (stored after plugin execution)
|
|
3266
|
-
* Used at runtime to call plugin.runtime() functions
|
|
3267
|
-
* @internal
|
|
3268
|
-
*/
|
|
3269
|
-
_plugins?: Plugin[]
|
|
3270
|
-
}
|