@opensaas/stack-core 0.42.3 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2745 -0
- package/README.md +182 -115
- package/dist/.build-hash +1 -0
- package/dist/access/declared-dependencies.d.ts +102 -88
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +83 -71
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +4 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +4 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +68 -20
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +151 -37
- package/dist/access/engine.js.map +1 -1
- package/dist/access/errors.d.ts +33 -48
- package/dist/access/errors.d.ts.map +1 -1
- package/dist/access/errors.js +73 -63
- package/dist/access/errors.js.map +1 -1
- package/dist/access/field-access.d.ts +76 -5
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +235 -61
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/field-visibility.d.ts +50 -4
- package/dist/access/field-visibility.d.ts.map +1 -1
- package/dist/access/field-visibility.js +143 -160
- package/dist/access/field-visibility.js.map +1 -1
- package/dist/access/index.d.ts +5 -12
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -19
- package/dist/access/index.js.map +1 -1
- package/dist/access/orm-client.d.ts +19 -0
- package/dist/access/orm-client.d.ts.map +1 -0
- package/dist/access/orm-client.js +37 -0
- package/dist/access/orm-client.js.map +1 -0
- package/dist/access/query-validation.d.ts +7 -129
- package/dist/access/query-validation.d.ts.map +1 -1
- package/dist/access/query-validation.js +12 -314
- package/dist/access/query-validation.js.map +1 -1
- package/dist/access/system-fields.d.ts +2 -0
- package/dist/access/system-fields.d.ts.map +1 -0
- package/dist/access/system-fields.js +7 -0
- package/dist/access/system-fields.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +25 -2
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +34 -17
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +217 -131
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/field-kind.d.ts +66 -0
- package/dist/config/field-kind.d.ts.map +1 -0
- package/dist/config/field-kind.js +63 -0
- package/dist/config/field-kind.js.map +1 -0
- package/dist/config/hook-only-fields.d.ts +3 -0
- package/dist/config/hook-only-fields.d.ts.map +1 -0
- package/dist/config/hook-only-fields.js +17 -0
- package/dist/config/hook-only-fields.js.map +1 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-tool-names.d.ts +3 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -0
- package/dist/config/mcp-tool-names.js +25 -0
- package/dist/config/mcp-tool-names.js.map +1 -0
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +4 -4
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts +8 -2
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +102 -38
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +966 -614
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/apply-defaults.d.ts +18 -1
- package/dist/context/apply-defaults.d.ts.map +1 -1
- package/dist/context/apply-defaults.js +30 -4
- package/dist/context/apply-defaults.js.map +1 -1
- package/dist/context/engine-context.d.ts +73 -0
- package/dist/context/engine-context.d.ts.map +1 -0
- package/dist/context/engine-context.js +67 -0
- package/dist/context/engine-context.js.map +1 -0
- package/dist/context/hook-pipeline.d.ts +9 -2
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +5 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +98 -89
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +917 -722
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +59 -0
- package/dist/context/junction.d.ts.map +1 -0
- package/dist/context/junction.js +126 -0
- package/dist/context/junction.js.map +1 -0
- package/dist/context/plugin-field-read.d.ts +33 -0
- package/dist/context/plugin-field-read.d.ts.map +1 -0
- package/dist/context/plugin-field-read.js +41 -0
- package/dist/context/plugin-field-read.js.map +1 -0
- package/dist/context/plugin-field-write.d.ts +104 -0
- package/dist/context/plugin-field-write.d.ts.map +1 -0
- package/dist/context/plugin-field-write.js +184 -0
- package/dist/context/plugin-field-write.js.map +1 -0
- package/dist/context/relationship-input.d.ts +146 -0
- package/dist/context/relationship-input.d.ts.map +1 -0
- package/dist/context/relationship-input.js +453 -0
- package/dist/context/relationship-input.js.map +1 -0
- package/dist/context/transaction-boundary.d.ts +54 -28
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +87 -169
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +33 -51
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +372 -185
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/contract/dependencies.d.ts +88 -0
- package/dist/contract/dependencies.d.ts.map +1 -0
- package/dist/contract/dependencies.js +237 -0
- package/dist/contract/dependencies.js.map +1 -0
- package/dist/contract/derive.d.ts +49 -0
- package/dist/contract/derive.d.ts.map +1 -0
- package/dist/contract/derive.js +540 -0
- package/dist/contract/derive.js.map +1 -0
- package/dist/contract/fixtures/contract-configs.d.ts +64 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
- package/dist/contract/fixtures/contract-configs.js +345 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -0
- package/dist/contract/id-boundary.d.ts +53 -0
- package/dist/contract/id-boundary.d.ts.map +1 -0
- package/dist/contract/id-boundary.js +76 -0
- package/dist/contract/id-boundary.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +11 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/prisma.d.ts +58 -0
- package/dist/contract/prisma.d.ts.map +1 -0
- package/dist/contract/prisma.js +282 -0
- package/dist/contract/prisma.js.map +1 -0
- package/dist/contract/relation-graph.d.ts +70 -0
- package/dist/contract/relation-graph.d.ts.map +1 -0
- package/dist/contract/relation-graph.js +113 -0
- package/dist/contract/relation-graph.js.map +1 -0
- package/dist/contract/types.d.ts +135 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/db/client.d.ts +55 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +73 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/dev-database.d.ts +124 -0
- package/dist/db/dev-database.d.ts.map +1 -0
- package/dist/db/dev-database.js +291 -0
- package/dist/db/dev-database.js.map +1 -0
- package/dist/db/password-front.d.ts +10 -0
- package/dist/db/password-front.d.ts.map +1 -0
- package/dist/db/password-front.js +147 -0
- package/dist/db/password-front.js.map +1 -0
- package/dist/db/process-identity.d.ts +36 -0
- package/dist/db/process-identity.d.ts.map +1 -0
- package/dist/db/process-identity.js +114 -0
- package/dist/db/process-identity.js.map +1 -0
- package/dist/db/state-file.d.ts +54 -0
- package/dist/db/state-file.d.ts.map +1 -0
- package/dist/db/state-file.js +91 -0
- package/dist/db/state-file.js.map +1 -0
- package/dist/db/url.d.ts +89 -0
- package/dist/db/url.d.ts.map +1 -0
- package/dist/db/url.js +118 -0
- package/dist/db/url.js.map +1 -0
- package/dist/extend.d.ts +13 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js +24 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +87 -42
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +457 -677
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +3 -4
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +2 -2
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -2
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +0 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +12 -5
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +47 -19
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/types.d.ts +10 -24
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +22 -31
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +33 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/transition-guard.d.ts +61 -0
- package/dist/hooks/transition-guard.d.ts.map +1 -0
- package/dist/hooks/transition-guard.js +93 -0
- package/dist/hooks/transition-guard.js.map +1 -0
- package/dist/index.d.ts +52 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -44
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +221 -0
- package/dist/validation/database-config.js.map +1 -0
- package/dist/validation/default-value.d.ts +21 -0
- package/dist/validation/default-value.d.ts.map +1 -0
- package/dist/validation/default-value.js +72 -0
- package/dist/validation/default-value.js.map +1 -0
- package/dist/validation/extension-packs.d.ts +11 -0
- package/dist/validation/extension-packs.d.ts.map +1 -0
- package/dist/validation/extension-packs.js +53 -0
- package/dist/validation/extension-packs.js.map +1 -0
- package/dist/validation/field-config.d.ts +35 -21
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +51 -41
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +15 -0
- package/dist/validation/field-names.d.ts.map +1 -0
- package/dist/validation/field-names.js +155 -0
- package/dist/validation/field-names.js.map +1 -0
- package/dist/validation/identifier-names.d.ts +4 -0
- package/dist/validation/identifier-names.d.ts.map +1 -0
- package/dist/validation/identifier-names.js +39 -0
- package/dist/validation/identifier-names.js.map +1 -0
- package/dist/validation/needs-closure.d.ts +20 -30
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +29 -105
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts +17 -0
- package/dist/validation/relations.d.ts.map +1 -0
- package/dist/validation/relations.js +268 -0
- package/dist/validation/relations.js.map +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +1 -3
- package/dist/validation/schema.js.map +1 -1
- package/dist/where/like.d.ts +32 -0
- package/dist/where/like.d.ts.map +1 -0
- package/dist/where/like.js +42 -0
- package/dist/where/like.js.map +1 -0
- package/package.json +70 -8
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -609
- package/dist/access/access-filter.d.ts +0 -241
- package/dist/access/access-filter.d.ts.map +0 -1
- package/dist/access/access-filter.js +0 -692
- package/dist/access/access-filter.js.map +0 -1
- package/dist/access/access-filter.test.d.ts +0 -2
- package/dist/access/access-filter.test.d.ts.map +0 -1
- package/dist/access/access-filter.test.js +0 -1256
- package/dist/access/access-filter.test.js.map +0 -1
- package/dist/access/declared-dependencies.test.d.ts +0 -2
- package/dist/access/declared-dependencies.test.d.ts.map +0 -1
- package/dist/access/declared-dependencies.test.js +0 -226
- package/dist/access/declared-dependencies.test.js.map +0 -1
- package/dist/access/denied-relation-visibility.test.d.ts +0 -2
- package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
- package/dist/access/denied-relation-visibility.test.js +0 -114
- package/dist/access/denied-relation-visibility.test.js.map +0 -1
- package/dist/access/engine.test.d.ts +0 -2
- package/dist/access/engine.test.d.ts.map +0 -1
- package/dist/access/engine.test.js +0 -56
- package/dist/access/engine.test.js.map +0 -1
- package/dist/access/field-access.test.d.ts +0 -2
- package/dist/access/field-access.test.d.ts.map +0 -1
- package/dist/access/field-access.test.js +0 -635
- package/dist/access/field-access.test.js.map +0 -1
- package/dist/access/multi-column-read-write.test.d.ts +0 -2
- package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
- package/dist/access/multi-column-read-write.test.js +0 -183
- package/dist/access/multi-column-read-write.test.js.map +0 -1
- package/dist/access/relationship-count.d.ts +0 -98
- package/dist/access/relationship-count.d.ts.map +0 -1
- package/dist/access/relationship-count.js +0 -262
- package/dist/access/relationship-count.js.map +0 -1
- package/dist/access/relationship-count.test.d.ts +0 -2
- package/dist/access/relationship-count.test.d.ts.map +0 -1
- package/dist/access/relationship-count.test.js +0 -247
- package/dist/access/relationship-count.test.js.map +0 -1
- package/dist/access/relationship-label-filter.d.ts +0 -45
- package/dist/access/relationship-label-filter.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.js +0 -22
- package/dist/access/relationship-label-filter.js.map +0 -1
- package/dist/access/relationship-label-filter.test.d.ts +0 -2
- package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.test.js +0 -89
- package/dist/access/relationship-label-filter.test.js.map +0 -1
- package/dist/access/synthetic-include-read.test.d.ts +0 -2
- package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
- package/dist/access/synthetic-include-read.test.js +0 -121
- package/dist/access/synthetic-include-read.test.js.map +0 -1
- package/dist/context/nested-operations.d.ts +0 -47
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -731
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1325
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -184
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3141
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -231
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
|
@@ -1,732 +0,0 @@
|
|
|
1
|
-
import type { OpenSaasConfig, ListConfig } from '../config/types.js'
|
|
2
|
-
import type { AccessContext, PrismaClientLike } from '../access/types.js'
|
|
3
|
-
import {
|
|
4
|
-
checkAccess,
|
|
5
|
-
checkCreateAccess,
|
|
6
|
-
mergeFilters,
|
|
7
|
-
filterReadableFields,
|
|
8
|
-
filterWritableFields,
|
|
9
|
-
} from '../access/index.js'
|
|
10
|
-
import {
|
|
11
|
-
executeValidate,
|
|
12
|
-
executeBeforeOperation,
|
|
13
|
-
executeAfterOperation,
|
|
14
|
-
executeFieldValidateHooks,
|
|
15
|
-
executeFieldBeforeOperationHooks,
|
|
16
|
-
executeFieldAfterOperationHooks,
|
|
17
|
-
ValidationError,
|
|
18
|
-
} from '../hooks/index.js'
|
|
19
|
-
import { hookPipeline } from './hook-pipeline.js'
|
|
20
|
-
import { processNestedOperations, runAfterTasks } from './nested-operations.js'
|
|
21
|
-
import type { AfterTask } from './nested-operations.js'
|
|
22
|
-
import { enumerateInvolvedLists, runWithTransactionBoundary } from './transaction-boundary.js'
|
|
23
|
-
import { TransactionRegistry } from '../access/transaction-registry.js'
|
|
24
|
-
import { getDbKey } from '../lib/case-utils.js'
|
|
25
|
-
// NOTE: `index.ts` imports from this module too — this is an intentional cyclic
|
|
26
|
-
// dependency. It is safe because `getContext` is only INVOKED at write time
|
|
27
|
-
// (never during module evaluation), so by the time it runs the export is fully
|
|
28
|
-
// initialised.
|
|
29
|
-
import { getContext } from './index.js'
|
|
30
|
-
import type { StackContext } from './index.js'
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Write Pipeline — runs the canonical, secured write sequence for one
|
|
34
|
-
* create/update/delete; see the "Write Pipeline" glossary entry in CONTEXT.md
|
|
35
|
-
* for the phase order and the hooks ordering in CLAUDE.md. Reads are out of
|
|
36
|
-
* scope (ADR-0001).
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export type WriteOperation = 'create' | 'update' | 'delete'
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Result of resolving a write target (axis 1). `denied` covers access denial,
|
|
43
|
-
* a missing target, or a filter non-match alike, and short-circuits to `null`
|
|
44
|
-
* before any hooks or the DB call.
|
|
45
|
-
*/
|
|
46
|
-
export type TargetResolution =
|
|
47
|
-
{ status: 'ok'; originalItem: Record<string, unknown> | undefined } | { status: 'denied' }
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Minimal dynamic Prisma model surface used by the write pipeline. Model names
|
|
51
|
-
* are generated at runtime, so the concrete client type is not known here.
|
|
52
|
-
*/
|
|
53
|
-
export interface PrismaModel {
|
|
54
|
-
findUnique: (args: { where: Record<string, unknown> }) => Promise<Record<string, unknown> | null>
|
|
55
|
-
findFirst: (args: { where: Record<string, unknown> }) => Promise<Record<string, unknown> | null>
|
|
56
|
-
count: () => Promise<number>
|
|
57
|
-
create: (args: {
|
|
58
|
-
data: Record<string, unknown>
|
|
59
|
-
include?: Record<string, unknown>
|
|
60
|
-
}) => Promise<Record<string, unknown>>
|
|
61
|
-
update: (args: {
|
|
62
|
-
where: Record<string, unknown>
|
|
63
|
-
data: Record<string, unknown>
|
|
64
|
-
include?: Record<string, unknown>
|
|
65
|
-
}) => Promise<Record<string, unknown>>
|
|
66
|
-
delete: (args: { where: Record<string, unknown> }) => Promise<Record<string, unknown>>
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Per-operation strategy. Supplies the three axes on which create/update/delete
|
|
71
|
-
* differ; the pipeline owns the shared phase order around them.
|
|
72
|
-
*/
|
|
73
|
-
export interface WriteStrategy {
|
|
74
|
-
operation: WriteOperation
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Axis 1: resolve the target row and check operation-level access.
|
|
78
|
-
* Implementations must honour `context._isSudo`.
|
|
79
|
-
*/
|
|
80
|
-
resolveTarget(model: PrismaModel): Promise<TargetResolution>
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Axis 2: whether to run the input-shaping phases (resolveInput → validate
|
|
84
|
-
* hooks → built-in field rules → filter-writable → nested ops). Delete runs
|
|
85
|
-
* only its `validate`/field-validate hooks and skips the rest.
|
|
86
|
-
*/
|
|
87
|
-
runInputPhases: boolean
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Axis 3: execute the database write and return the persisted/deleted row.
|
|
91
|
-
* `data` is the fully-resolved write payload (empty object for delete).
|
|
92
|
-
* `include` (create/update) asks the DB to return nested relations so nested
|
|
93
|
-
* `afterOperation` can recover its persisted `item`; delete ignores it.
|
|
94
|
-
*/
|
|
95
|
-
persist(
|
|
96
|
-
model: PrismaModel,
|
|
97
|
-
data: Record<string, unknown>,
|
|
98
|
-
include?: Record<string, unknown>,
|
|
99
|
-
): Promise<Record<string, unknown>>
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Resolve the dynamic Prisma model for a list. Model names are generated at
|
|
104
|
-
* runtime, so the cast is unavoidable — kept localized here (mirrors
|
|
105
|
-
* `context/index.ts`).
|
|
106
|
-
*/
|
|
107
|
-
function getModel<TPrisma extends PrismaClientLike>(
|
|
108
|
-
prisma: TPrisma,
|
|
109
|
-
listName: string,
|
|
110
|
-
): PrismaModel {
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- model names are generated at runtime
|
|
112
|
-
return (prisma as any)[getDbKey(listName)] as PrismaModel
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Minimal shape of a Prisma interactive-transaction-capable client. `tx` is
|
|
117
|
-
* dynamically typed like the model surface above (names generated at runtime).
|
|
118
|
-
*/
|
|
119
|
-
interface TransactionCapable {
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- $transaction callback receives a dynamically-typed tx client
|
|
121
|
-
$transaction?: (fn: (tx: any) => Promise<unknown>) => Promise<unknown>
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Run `fn` inside ONE interactive transaction, used as the persistence target
|
|
126
|
-
* for the parent and all nested writes (ADR-0010).
|
|
127
|
-
*
|
|
128
|
-
* Without `$transaction` (e.g. a test mock), `fn` runs directly against the
|
|
129
|
-
* client — hook ordering and arguments are identical, but only a real
|
|
130
|
-
* transaction provides the rollback guarantee.
|
|
131
|
-
*/
|
|
132
|
-
async function runInTransaction<TPrisma extends PrismaClientLike>(
|
|
133
|
-
prisma: TPrisma,
|
|
134
|
-
fn: (tx: TPrisma) => Promise<Record<string, unknown> | null>,
|
|
135
|
-
): Promise<Record<string, unknown> | null> {
|
|
136
|
-
const client = prisma as unknown as TransactionCapable
|
|
137
|
-
if (typeof client.$transaction === 'function') {
|
|
138
|
-
return (await client.$transaction(async (tx) => fn(tx as TPrisma))) as Record<
|
|
139
|
-
string,
|
|
140
|
-
unknown
|
|
141
|
-
> | null
|
|
142
|
-
}
|
|
143
|
-
return fn(prisma)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
147
|
-
function isSingletonList(listConfig: ListConfig<any>): boolean {
|
|
148
|
-
return !!listConfig.isSingleton
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface WritePipelineArgs<TPrisma extends PrismaClientLike> {
|
|
152
|
-
listName: string
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
154
|
-
listConfig: ListConfig<any>
|
|
155
|
-
prisma: TPrisma
|
|
156
|
-
context: AccessContext<TPrisma>
|
|
157
|
-
config: OpenSaasConfig
|
|
158
|
-
/** The original input data for the write (create/update). `undefined` for delete. */
|
|
159
|
-
inputData: Record<string, unknown> | undefined
|
|
160
|
-
/** The per-operation strategy (see {@link WriteStrategy}). */
|
|
161
|
-
strategy: WriteStrategy
|
|
162
|
-
/**
|
|
163
|
-
* The target resolution computed once before the transaction opens, and
|
|
164
|
-
* reused inside it rather than resolved a second time — see the
|
|
165
|
-
* pre-transaction gate in {@link runWritePipeline}.
|
|
166
|
-
*/
|
|
167
|
-
preResolvedTarget?: TargetResolution
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* {@link WritePipelineArgs} narrowed to the in-transaction phase: `context` is
|
|
172
|
-
* the full {@link StackContext} `bindContextToTransaction` rebuilds (issue
|
|
173
|
-
* #1176), not the plain {@link AccessContext} the pre-transaction gate and the
|
|
174
|
-
* transaction-boundary hooks use. `StackContext` is a structural superset of
|
|
175
|
-
* `AccessContext` (it carries `_resolveOutputChain`/`_transactionOwner` too),
|
|
176
|
-
* so nothing downstream of {@link runWriteInTransaction} that only needs
|
|
177
|
-
* `AccessContext` requires any change.
|
|
178
|
-
*/
|
|
179
|
-
type WriteInTransactionArgs<TPrisma extends PrismaClientLike> = Omit<
|
|
180
|
-
WritePipelineArgs<TPrisma>,
|
|
181
|
-
'context'
|
|
182
|
-
> & {
|
|
183
|
-
context: StackContext<TPrisma>
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Run the canonical secured write sequence once. Phase order matches the
|
|
188
|
-
* "Write Pipeline" glossary entry in CONTEXT.md.
|
|
189
|
-
*
|
|
190
|
-
* Contract preserved exactly:
|
|
191
|
-
* - missing target / access denied / filter non-match → `null` (silent),
|
|
192
|
-
* BEFORE the DB call and BEFORE `beforeOperation`.
|
|
193
|
-
* - validation failure → THROW `ValidationError` (never silent).
|
|
194
|
-
* - sudo mode skips access checks and writable-field filtering.
|
|
195
|
-
* - `afterOperation` receives `originalItem` for update/delete (undefined for
|
|
196
|
-
* create).
|
|
197
|
-
* - delete returns the deleted row as-is (no Field Visibility pass).
|
|
198
|
-
*/
|
|
199
|
-
export async function runWritePipeline<TPrisma extends PrismaClientLike>(
|
|
200
|
-
args: WritePipelineArgs<TPrisma>,
|
|
201
|
-
): Promise<Record<string, unknown> | null> {
|
|
202
|
-
const { prisma, listName, listConfig, context, config, inputData, strategy } = args
|
|
203
|
-
|
|
204
|
-
// ── Pre-transaction access gate (#590) ──────────────────────────────────────
|
|
205
|
-
// Resolves the top-level target + access OUTSIDE the transaction so a denied
|
|
206
|
-
// write short-circuits to `null` WITHOUT firing beforeTransaction/
|
|
207
|
-
// afterTransaction — a denied write takes no external action, so the
|
|
208
|
-
// boundary hooks must not run. The result feeds `preResolvedTarget` and is
|
|
209
|
-
// REUSED inside the transaction rather than re-resolved, keeping the target
|
|
210
|
-
// read exactly once (#569).
|
|
211
|
-
const gate = await strategy.resolveTarget(getModel(prisma, listName))
|
|
212
|
-
if (gate.status === 'denied') {
|
|
213
|
-
return null
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// ── Enumerate involved lists from the input tree (no DB reads) ──────────────
|
|
217
|
-
const involvedLists = enumerateInvolvedLists({
|
|
218
|
-
listName,
|
|
219
|
-
listConfig,
|
|
220
|
-
operation: strategy.operation,
|
|
221
|
-
inputData,
|
|
222
|
-
topLevelOriginalItem: gate.originalItem,
|
|
223
|
-
config,
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
// ── Transaction ownership for the transaction-boundary hooks (ADR-0028) ────
|
|
227
|
-
// A context carrying `_transactionOwner` is JOINING an enclosing transaction
|
|
228
|
-
// it did not open — defer to that owner even if `prisma` here still exposes
|
|
229
|
-
// `$transaction`. Otherwise this write becomes the owner: the registry every
|
|
230
|
-
// joined write below it enqueues into.
|
|
231
|
-
const existingOwner = context._transactionOwner
|
|
232
|
-
const opensOwnTransaction =
|
|
233
|
-
!existingOwner && typeof (prisma as TransactionCapable).$transaction === 'function'
|
|
234
|
-
const ownedRegistry = opensOwnTransaction ? new TransactionRegistry() : undefined
|
|
235
|
-
const transactionOwnerForBody = existingOwner ?? ownedRegistry
|
|
236
|
-
|
|
237
|
-
// ── Bracket the transaction with beforeTransaction/afterTransaction (#590) ──
|
|
238
|
-
// afterTransaction fires when the transaction settles, deferred to the owner
|
|
239
|
-
// for a joined write (ADR-0028, symmetric-bracket rule).
|
|
240
|
-
return runWithTransactionBoundary({
|
|
241
|
-
involvedLists,
|
|
242
|
-
context,
|
|
243
|
-
joinedOwner: existingOwner,
|
|
244
|
-
ownedRegistry,
|
|
245
|
-
runTransaction: () =>
|
|
246
|
-
// ADR-0010: parent + nested writes share `tx` as their persistence target.
|
|
247
|
-
runInTransaction(prisma, (tx) =>
|
|
248
|
-
runWriteInTransaction({
|
|
249
|
-
...args,
|
|
250
|
-
prisma: tx,
|
|
251
|
-
// Reuse the pre-transaction target resolution (#569 call-count semantics).
|
|
252
|
-
preResolvedTarget: gate,
|
|
253
|
-
// Rebind context.db/prisma to `tx` (ADR-0010 atomicity) and carry the
|
|
254
|
-
// transaction owner (ADR-0028) — see bindContextToTransaction below.
|
|
255
|
-
context: bindContextToTransaction(args, tx, transactionOwnerForBody),
|
|
256
|
-
}),
|
|
257
|
-
),
|
|
258
|
-
})
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Build the full {@link StackContext} a hook's `context` is (issue #1176):
|
|
263
|
-
* bound to the transaction client `tx`, so a `context.db` write a hook
|
|
264
|
-
* performs runs inside — and rolls back with — this write's transaction
|
|
265
|
-
* (ADR-0010), and carrying `sudo()`/`withSession()`/`transaction()` so a hook
|
|
266
|
-
* can reach an elevated or substituted read/write that stays on the SAME
|
|
267
|
-
* transaction client rather than escaping to the base one.
|
|
268
|
-
*
|
|
269
|
-
* Goes through the same {@link getContext} factory `context.transaction()`
|
|
270
|
-
* already rebuilds through (ADR-0012), rather than hand-assembling a plain
|
|
271
|
-
* object literal — reusing the request context's `session`, `storage`,
|
|
272
|
-
* `_isSudo`, `plugins` (as `_sharedPlugins`, so plugin `runtime()` is NOT
|
|
273
|
-
* re-executed on the rebind), and `_resolveOutputChain` (so a write issued
|
|
274
|
-
* from inside a `resolveOutput` hook keeps that hook's cycle-guard chain,
|
|
275
|
-
* ADR-0023) as-is.
|
|
276
|
-
*
|
|
277
|
-
* `transactionOwner` (ADR-0028) is carried onto the rebuilt context so a hook's
|
|
278
|
-
* own `context.db` write — and any write reached through its `sudo()`/
|
|
279
|
-
* `withSession()` — defers its transaction-boundary bracket to that owner
|
|
280
|
-
* instead of firing eagerly; `context.transaction()` called from a hook joins
|
|
281
|
-
* this same owner rather than opening a nested transaction, for the same
|
|
282
|
-
* reason.
|
|
283
|
-
*/
|
|
284
|
-
function bindContextToTransaction<TPrisma extends PrismaClientLike>(
|
|
285
|
-
args: WritePipelineArgs<TPrisma>,
|
|
286
|
-
tx: TPrisma,
|
|
287
|
-
transactionOwner: TransactionRegistry | undefined,
|
|
288
|
-
): StackContext<TPrisma> {
|
|
289
|
-
const { context, config } = args
|
|
290
|
-
return getContext(
|
|
291
|
-
config,
|
|
292
|
-
tx,
|
|
293
|
-
context.session,
|
|
294
|
-
context.storage,
|
|
295
|
-
context._isSudo,
|
|
296
|
-
context.plugins,
|
|
297
|
-
transactionOwner,
|
|
298
|
-
context._resolveOutputChain,
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* The body of one secured write, executed against the transaction client `tx`
|
|
304
|
-
* (passed in as `args.prisma`). Returns `null` for the silent-failure cases and
|
|
305
|
-
* the Field-Visibility-filtered row otherwise. Any throw here propagates out of
|
|
306
|
-
* `runInTransaction` and rolls the transaction back.
|
|
307
|
-
*/
|
|
308
|
-
async function runWriteInTransaction<TPrisma extends PrismaClientLike>(
|
|
309
|
-
args: WriteInTransactionArgs<TPrisma>,
|
|
310
|
-
): Promise<Record<string, unknown> | null> {
|
|
311
|
-
const { listName, listConfig, prisma: tx, context, config, inputData, strategy } = args
|
|
312
|
-
const { operation } = strategy
|
|
313
|
-
const model = getModel(tx, listName)
|
|
314
|
-
|
|
315
|
-
// ── Phase 1: resolve target + operation-level access ──────────────────────
|
|
316
|
-
// Reuses `preResolvedTarget` from the pre-transaction gate rather than
|
|
317
|
-
// reading the target twice; falls back to resolving here when invoked
|
|
318
|
-
// directly (e.g. a unit test) without that bracket.
|
|
319
|
-
const resolution = args.preResolvedTarget ?? (await strategy.resolveTarget(model))
|
|
320
|
-
if (resolution.status === 'denied') {
|
|
321
|
-
return null
|
|
322
|
-
}
|
|
323
|
-
const originalItem = resolution.originalItem
|
|
324
|
-
|
|
325
|
-
// ── Delete path: skip input phases, run only validate/field-validate ────────
|
|
326
|
-
if (!strategy.runInputPhases) {
|
|
327
|
-
return runDeletePath({ listName, listConfig, context, originalItem, model, strategy })
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Only create/update reach here (delete short-circuited above); narrow so
|
|
331
|
-
// field-hook helpers receive a 'create' | 'update' value.
|
|
332
|
-
const writeOp: 'create' | 'update' = operation === 'create' ? 'create' : 'update'
|
|
333
|
-
|
|
334
|
-
// `inputData` is always present here; `?? {}` is only a defensive fallback.
|
|
335
|
-
const input = inputData ?? {}
|
|
336
|
-
|
|
337
|
-
// ── Phases 2–4: transform + validate span (Hook Pipeline glossary, CONTEXT.md) ──
|
|
338
|
-
// THROWS `ValidationError` on any validation failure (never silent).
|
|
339
|
-
const { resolvedData } = await hookPipeline.run({
|
|
340
|
-
operation: writeOp,
|
|
341
|
-
listName,
|
|
342
|
-
listConfig,
|
|
343
|
-
inputData: input,
|
|
344
|
-
item: originalItem,
|
|
345
|
-
context,
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
// ── Phase 5: filter writable fields (field-level access, skip if sudo) ──────
|
|
349
|
-
const filteredData = await filterWritableFields(resolvedData, listConfig.fields, writeOp, {
|
|
350
|
-
session: context.session,
|
|
351
|
-
item: originalItem,
|
|
352
|
-
context: { ...context, _isSudo: context._isSudo },
|
|
353
|
-
inputData: input,
|
|
354
|
-
listName,
|
|
355
|
-
config,
|
|
356
|
-
})
|
|
357
|
-
|
|
358
|
-
// ── Phase 5.5: process nested relationship operations ───────────────────────
|
|
359
|
-
// Runs each nested record's resolveInput/validate/field-rules AND its
|
|
360
|
-
// `beforeOperation` inside this transaction, returning deferred
|
|
361
|
-
// `afterOperation` tasks plus the relation fields to `include` so those tasks
|
|
362
|
-
// can recover their persisted `item`.
|
|
363
|
-
const { data, afterTasks, includeFields } = await processNestedOperations(
|
|
364
|
-
filteredData,
|
|
365
|
-
listConfig.fields,
|
|
366
|
-
config,
|
|
367
|
-
{ ...context, prisma: tx },
|
|
368
|
-
writeOp,
|
|
369
|
-
listName,
|
|
370
|
-
originalItem,
|
|
371
|
-
// Same `inputData` Phase 5's filterWritableFields used, so the connect-site
|
|
372
|
-
// owning-field gate evaluates identically and can't diverge into a
|
|
373
|
-
// spurious connect denial (#588).
|
|
374
|
-
input,
|
|
375
|
-
)
|
|
376
|
-
|
|
377
|
-
// ── Phase 6: field-level beforeOperation (side effects only) ────────────────
|
|
378
|
-
await executeFieldBeforeOperationHooks(
|
|
379
|
-
input,
|
|
380
|
-
resolvedData,
|
|
381
|
-
listConfig.fields,
|
|
382
|
-
writeOp,
|
|
383
|
-
context,
|
|
384
|
-
listName,
|
|
385
|
-
originalItem,
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
// ── Phase 7: list-level beforeOperation ─────────────────────────────────────
|
|
389
|
-
await executeBeforeOperation(
|
|
390
|
-
listConfig.hooks,
|
|
391
|
-
operation === 'create'
|
|
392
|
-
? {
|
|
393
|
-
listKey: listName,
|
|
394
|
-
operation: 'create',
|
|
395
|
-
inputData: input,
|
|
396
|
-
resolvedData,
|
|
397
|
-
context,
|
|
398
|
-
}
|
|
399
|
-
: {
|
|
400
|
-
listKey: listName,
|
|
401
|
-
operation: 'update',
|
|
402
|
-
inputData: input,
|
|
403
|
-
item: originalItem,
|
|
404
|
-
resolvedData,
|
|
405
|
-
context,
|
|
406
|
-
},
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
// ── Phase 8: DB write ───────────────────────────────────────────────────────
|
|
410
|
-
// `include` returns the nested relations with deferred `afterOperation`
|
|
411
|
-
// tasks so they can recover their persisted `item`.
|
|
412
|
-
const include = buildIncludeFromFields(includeFields)
|
|
413
|
-
const item = await strategy.persist(model, data, include)
|
|
414
|
-
|
|
415
|
-
// ── Phase 9: list-level afterOperation ──────────────────────────────────────
|
|
416
|
-
await executeAfterOperation(
|
|
417
|
-
listConfig.hooks,
|
|
418
|
-
operation === 'create'
|
|
419
|
-
? {
|
|
420
|
-
listKey: listName,
|
|
421
|
-
operation: 'create',
|
|
422
|
-
inputData: input,
|
|
423
|
-
item,
|
|
424
|
-
resolvedData,
|
|
425
|
-
context,
|
|
426
|
-
}
|
|
427
|
-
: {
|
|
428
|
-
listKey: listName,
|
|
429
|
-
operation: 'update',
|
|
430
|
-
inputData: input,
|
|
431
|
-
// Non-null for update (fetched in Phase 1); cast narrows the type.
|
|
432
|
-
originalItem: originalItem as Record<string, unknown>,
|
|
433
|
-
item,
|
|
434
|
-
resolvedData,
|
|
435
|
-
context,
|
|
436
|
-
},
|
|
437
|
-
)
|
|
438
|
-
|
|
439
|
-
// ── Phase 10: field-level afterOperation (side effects only) ────────────────
|
|
440
|
-
await executeFieldAfterOperationHooks(
|
|
441
|
-
item,
|
|
442
|
-
input,
|
|
443
|
-
resolvedData,
|
|
444
|
-
listConfig.fields,
|
|
445
|
-
writeOp,
|
|
446
|
-
context,
|
|
447
|
-
listName,
|
|
448
|
-
originalItem, // undefined for create, original row for update
|
|
449
|
-
)
|
|
450
|
-
|
|
451
|
-
// ── Phase 10.5: nested afterOperation (deferred, in this transaction) ────────
|
|
452
|
-
// Each nested create/update/delete's `afterOperation` fires now, with the
|
|
453
|
-
// persisted nested row recovered from the parent's included relations. A throw
|
|
454
|
-
// here rolls the whole transaction back (parent write included).
|
|
455
|
-
await runNestedAfterTasks(afterTasks, item)
|
|
456
|
-
|
|
457
|
-
// ── Phase 11: Field Visibility (filter readable fields + resolveOutput) ─────
|
|
458
|
-
return filterReadableFields(
|
|
459
|
-
item,
|
|
460
|
-
listConfig.fields,
|
|
461
|
-
{
|
|
462
|
-
session: context.session,
|
|
463
|
-
context: { ...context, _isSudo: context._isSudo },
|
|
464
|
-
},
|
|
465
|
-
config,
|
|
466
|
-
0,
|
|
467
|
-
listName,
|
|
468
|
-
)
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* Build a Prisma `include` from the set of relation field names that have
|
|
473
|
-
* deferred nested `afterOperation` tasks, so the parent write returns those
|
|
474
|
-
* relations and the tasks can recover their persisted `item`.
|
|
475
|
-
*/
|
|
476
|
-
function buildIncludeFromFields(includeFields: Set<string>): Record<string, unknown> | undefined {
|
|
477
|
-
if (includeFields.size === 0) return undefined
|
|
478
|
-
const include: Record<string, unknown> = {}
|
|
479
|
-
for (const field of includeFields) {
|
|
480
|
-
include[field] = true
|
|
481
|
-
}
|
|
482
|
-
return include
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Run the deferred nested `afterOperation` tasks against the persisted parent
|
|
487
|
-
* row (`?? {}` is only a type-narrowing guard — parent is always a record
|
|
488
|
-
* here). Each task recovers its own nested row by id-diff/known id and THROWS
|
|
489
|
-
* if it can't, rather than firing with a fabricated item (ADR-0010).
|
|
490
|
-
*/
|
|
491
|
-
async function runNestedAfterTasks(
|
|
492
|
-
afterTasks: AfterTask[],
|
|
493
|
-
item: Record<string, unknown>,
|
|
494
|
-
): Promise<void> {
|
|
495
|
-
if (afterTasks.length === 0) return
|
|
496
|
-
await runAfterTasks(afterTasks, item ?? {})
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* The delete tail of the pipeline: skips the input-shaping phases and runs
|
|
501
|
-
* only validate/field-validate before the DB delete, then the after-hooks.
|
|
502
|
-
* Returns the deleted row as-is (no Field Visibility pass).
|
|
503
|
-
*/
|
|
504
|
-
async function runDeletePath(args: {
|
|
505
|
-
listName: string
|
|
506
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
507
|
-
listConfig: ListConfig<any>
|
|
508
|
-
context: StackContext
|
|
509
|
-
originalItem: Record<string, unknown> | undefined
|
|
510
|
-
model: PrismaModel
|
|
511
|
-
strategy: WriteStrategy
|
|
512
|
-
}): Promise<Record<string, unknown>> {
|
|
513
|
-
const { listName, listConfig, context, originalItem, model, strategy } = args
|
|
514
|
-
const item = originalItem as Record<string, unknown>
|
|
515
|
-
|
|
516
|
-
// ── Phase 3: list-level validate (delete) ──────────────────────────────────
|
|
517
|
-
await executeValidate(listConfig.hooks, {
|
|
518
|
-
listKey: listName,
|
|
519
|
-
operation: 'delete',
|
|
520
|
-
item,
|
|
521
|
-
context,
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
// ── Phase 3.5: field-level validate (delete) ────────────────────────────────
|
|
525
|
-
await executeFieldValidateHooks(
|
|
526
|
-
undefined,
|
|
527
|
-
undefined,
|
|
528
|
-
listConfig.fields,
|
|
529
|
-
'delete',
|
|
530
|
-
context,
|
|
531
|
-
listName,
|
|
532
|
-
item,
|
|
533
|
-
)
|
|
534
|
-
|
|
535
|
-
// ── Phase 6: field-level beforeOperation (delete) ───────────────────────────
|
|
536
|
-
await executeFieldBeforeOperationHooks(
|
|
537
|
-
{},
|
|
538
|
-
{},
|
|
539
|
-
listConfig.fields,
|
|
540
|
-
'delete',
|
|
541
|
-
context,
|
|
542
|
-
listName,
|
|
543
|
-
item,
|
|
544
|
-
)
|
|
545
|
-
|
|
546
|
-
// ── Phase 7: list-level beforeOperation (delete) ────────────────────────────
|
|
547
|
-
await executeBeforeOperation(listConfig.hooks, {
|
|
548
|
-
listKey: listName,
|
|
549
|
-
operation: 'delete',
|
|
550
|
-
item,
|
|
551
|
-
context,
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
// ── Phase 8: DB delete ──────────────────────────────────────────────────────
|
|
555
|
-
const deleted = await strategy.persist(model, {})
|
|
556
|
-
|
|
557
|
-
// ── Phase 9: list-level afterOperation (delete) ─────────────────────────────
|
|
558
|
-
await executeAfterOperation(listConfig.hooks, {
|
|
559
|
-
listKey: listName,
|
|
560
|
-
operation: 'delete',
|
|
561
|
-
originalItem: item,
|
|
562
|
-
context,
|
|
563
|
-
})
|
|
564
|
-
|
|
565
|
-
// ── Phase 10: field-level afterOperation (delete) ───────────────────────────
|
|
566
|
-
await executeFieldAfterOperationHooks(
|
|
567
|
-
deleted,
|
|
568
|
-
undefined,
|
|
569
|
-
undefined,
|
|
570
|
-
listConfig.fields,
|
|
571
|
-
'delete',
|
|
572
|
-
context,
|
|
573
|
-
listName,
|
|
574
|
-
item, // original row before deletion
|
|
575
|
-
)
|
|
576
|
-
|
|
577
|
-
return deleted
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// ── Per-operation strategies ──────────────────────────────────────────────────
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* Create strategy for {@link WriteStrategy}.
|
|
584
|
-
*
|
|
585
|
-
* Axis 1: checks `create` access with no existing row; a filter result
|
|
586
|
-
* throws `InvalidCreateAccessResultError` rather than proceeding unchecked —
|
|
587
|
-
* create has no row to re-check a filter against, unlike update/delete
|
|
588
|
-
* (#1009). Enforces the singleton-create constraint even under sudo.
|
|
589
|
-
* Axis 2: runs all input phases.
|
|
590
|
-
* Axis 3: `model.create({ data })`, prepending `id: 1` for singleton lists.
|
|
591
|
-
*/
|
|
592
|
-
export function createWriteStrategy(
|
|
593
|
-
listName: string,
|
|
594
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
595
|
-
listConfig: ListConfig<any>,
|
|
596
|
-
context: AccessContext,
|
|
597
|
-
): WriteStrategy {
|
|
598
|
-
const singleton = isSingletonList(listConfig)
|
|
599
|
-
return {
|
|
600
|
-
operation: 'create',
|
|
601
|
-
runInputPhases: true,
|
|
602
|
-
async resolveTarget(model) {
|
|
603
|
-
// Singleton constraint is enforced even under sudo.
|
|
604
|
-
if (singleton) {
|
|
605
|
-
const existingCount = await model.count()
|
|
606
|
-
if (existingCount > 0) {
|
|
607
|
-
throw new ValidationError(
|
|
608
|
-
[`Cannot create: ${listName} is a singleton list with an existing record`],
|
|
609
|
-
{},
|
|
610
|
-
)
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
if (!context._isSudo) {
|
|
615
|
-
const allowed = await checkCreateAccess(listName, listConfig.access?.operation?.create, {
|
|
616
|
-
session: context.session,
|
|
617
|
-
context,
|
|
618
|
-
})
|
|
619
|
-
if (!allowed) {
|
|
620
|
-
return { status: 'denied' }
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return { status: 'ok', originalItem: undefined }
|
|
625
|
-
},
|
|
626
|
-
async persist(model, data, include) {
|
|
627
|
-
// Singleton lists use Int @id with value always 1 (matching Keystone 6).
|
|
628
|
-
const createData = singleton ? { id: 1, ...data } : data
|
|
629
|
-
return model.create(include ? { data: createData, include } : { data: createData })
|
|
630
|
-
},
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Build the shared target resolution for update/delete: fetch the row (missing
|
|
636
|
-
* → denied), check operation-level access (false → denied), and if access
|
|
637
|
-
* returns a filter, re-check via `findFirst(mergeFilters(where, filter))`
|
|
638
|
-
* (no match → denied). An access result of `true` proceeds with no re-check.
|
|
639
|
-
*/
|
|
640
|
-
function resolveExistingTarget(
|
|
641
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
642
|
-
listConfig: ListConfig<any>,
|
|
643
|
-
context: AccessContext,
|
|
644
|
-
where: { id: string },
|
|
645
|
-
access: 'update' | 'delete',
|
|
646
|
-
): (model: PrismaModel) => Promise<TargetResolution> {
|
|
647
|
-
return async (model) => {
|
|
648
|
-
const item = await model.findUnique({ where })
|
|
649
|
-
if (!item) {
|
|
650
|
-
return { status: 'denied' }
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
if (!context._isSudo) {
|
|
654
|
-
const accessResult = await checkAccess(listConfig.access?.operation?.[access], {
|
|
655
|
-
session: context.session,
|
|
656
|
-
item,
|
|
657
|
-
context,
|
|
658
|
-
})
|
|
659
|
-
|
|
660
|
-
if (accessResult === false) {
|
|
661
|
-
return { status: 'denied' }
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// A filter result must additionally match the target row.
|
|
665
|
-
if (typeof accessResult === 'object') {
|
|
666
|
-
const matchesFilter = await model.findFirst({
|
|
667
|
-
where: mergeFilters(where, accessResult) ?? {},
|
|
668
|
-
})
|
|
669
|
-
if (!matchesFilter) {
|
|
670
|
-
return { status: 'denied' }
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
return { status: 'ok', originalItem: item }
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Update strategy for {@link WriteStrategy}.
|
|
681
|
-
*
|
|
682
|
-
* Axis 1: fetch row, check `update` access, re-check filter results.
|
|
683
|
-
* Axis 2: runs all input phases.
|
|
684
|
-
* Axis 3: `model.update({ where, data })`; afterOperation gets `originalItem`.
|
|
685
|
-
*/
|
|
686
|
-
export function updateWriteStrategy(
|
|
687
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
688
|
-
listConfig: ListConfig<any>,
|
|
689
|
-
context: AccessContext,
|
|
690
|
-
where: { id: string },
|
|
691
|
-
): WriteStrategy {
|
|
692
|
-
return {
|
|
693
|
-
operation: 'update',
|
|
694
|
-
runInputPhases: true,
|
|
695
|
-
resolveTarget: resolveExistingTarget(listConfig, context, where, 'update'),
|
|
696
|
-
async persist(model, data, include) {
|
|
697
|
-
return model.update(include ? { where, data, include } : { where, data })
|
|
698
|
-
},
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Delete strategy for {@link WriteStrategy}.
|
|
704
|
-
*
|
|
705
|
-
* Axis 1: enforce singleton constraint (even under sudo), fetch row, check
|
|
706
|
-
* `delete` access, re-check filter results.
|
|
707
|
-
* Axis 2: skips input phases (runs only validate/field-validate).
|
|
708
|
-
* Axis 3: `model.delete({ where })`; afterOperation gets `originalItem`.
|
|
709
|
-
*/
|
|
710
|
-
export function deleteWriteStrategy(
|
|
711
|
-
listName: string,
|
|
712
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
713
|
-
listConfig: ListConfig<any>,
|
|
714
|
-
context: AccessContext,
|
|
715
|
-
where: { id: string },
|
|
716
|
-
): WriteStrategy {
|
|
717
|
-
const resolveTarget = resolveExistingTarget(listConfig, context, where, 'delete')
|
|
718
|
-
return {
|
|
719
|
-
operation: 'delete',
|
|
720
|
-
runInputPhases: false,
|
|
721
|
-
async resolveTarget(model) {
|
|
722
|
-
// Singleton lists may not be deleted (enforced even under sudo).
|
|
723
|
-
if (isSingletonList(listConfig)) {
|
|
724
|
-
throw new ValidationError([`Cannot delete: ${listName} is a singleton list`], {})
|
|
725
|
-
}
|
|
726
|
-
return resolveTarget(model)
|
|
727
|
-
},
|
|
728
|
-
async persist(model) {
|
|
729
|
-
return model.delete({ where })
|
|
730
|
-
},
|
|
731
|
-
}
|
|
732
|
-
}
|