@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
|
@@ -1,847 +0,0 @@
|
|
|
1
|
-
import { checkAccess, checkCreateAccess, filterWritableFields, getRelatedListConfig, mergeFilters, resolveSyntheticReverseRelation, } from '../access/index.js';
|
|
2
|
-
import { checkFieldAccess } from '../access/field-access.js';
|
|
3
|
-
import { executeResolveInput, executeValidate, executeFieldResolveInputHooks, executeBeforeOperation, executeAfterOperation, executeFieldBeforeOperationHooks, executeFieldAfterOperationHooks, executeFieldValidateHooks, validateFieldRules, splitMultiColumnFields, ValidationError, } from '../hooks/index.js';
|
|
4
|
-
import { getDbKey } from '../lib/case-utils.js';
|
|
5
|
-
import { applyCreateDefaults } from './apply-defaults.js';
|
|
6
|
-
/**
|
|
7
|
-
* Nested writes (#569 / ADR-0010): give nested `create`/`update`/`delete` the
|
|
8
|
-
* same before/afterOperation hooks as an equivalent top-level write, inside
|
|
9
|
-
* the one transaction the Write Pipeline opens. `processNestedOperations`
|
|
10
|
-
* transforms the payload and runs `beforeOperation`, returning deferred
|
|
11
|
-
* {@link AfterTask}s that {@link runAfterTasks} runs once the parent has
|
|
12
|
-
* persisted. See ADR-0010 for the full mechanism.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Thrown when a non-sudo write's payload carries a nested `set`, `updateMany`
|
|
16
|
-
* or `deleteMany` under a relationship key (#1384). These three kinds were
|
|
17
|
-
* historically a pass-through straight to Prisma: the target list's
|
|
18
|
-
* `operation.update`/`operation.delete` access was never consulted, no hooks
|
|
19
|
-
* ran, and an unscoped `updateMany`/`deleteMany` `where` reached rows well
|
|
20
|
-
* outside the parent's own subtree. ADR-0050 removes nested relation input
|
|
21
|
-
* from the secured write surface entirely on the `prisma-8` line, so building
|
|
22
|
-
* per-kind access machinery for these three kinds on `main` would be work
|
|
23
|
-
* that major deletes wholesale — this refuses them instead, an interim
|
|
24
|
-
* fail-closed fix mirroring ADR-0050's own refusal shape.
|
|
25
|
-
*
|
|
26
|
-
* The refusal fires before any part of the write executes, so a payload
|
|
27
|
-
* mixing a refused kind with a permitted one persists nothing. `sudo()`
|
|
28
|
-
* still accepts all three kinds unchanged — the same escape hatch every
|
|
29
|
-
* other access-control refusal in this module leans on.
|
|
30
|
-
*
|
|
31
|
-
* Replacement: author the writes against the target list directly, via
|
|
32
|
-
* `context.db.<targetList>`, wrapped in `context.transaction` when they must
|
|
33
|
-
* land atomically with this write.
|
|
34
|
-
*/
|
|
35
|
-
export class NestedRelationInputError extends Error {
|
|
36
|
-
listKey;
|
|
37
|
-
fieldKey;
|
|
38
|
-
kinds;
|
|
39
|
-
constructor(listKey, fieldKey, kinds) {
|
|
40
|
-
const kindList = kinds.map((kind) => `"${kind}"`).join(', ');
|
|
41
|
-
super(`Cannot write "${listKey}.${fieldKey}" — this payload carries a nested ${kindList} ` +
|
|
42
|
-
`operation, which non-sudo contexts no longer accept (#1384): the target list's access ` +
|
|
43
|
-
`rules were never consulted for these kinds. Author the writes against the target list ` +
|
|
44
|
-
`directly (\`context.db.<targetList>\`), wrapped in \`context.transaction\` when they must ` +
|
|
45
|
-
`land atomically with this write, or use \`context.sudo()\` if this write is trusted to ` +
|
|
46
|
-
`bypass the target list's access entirely.`);
|
|
47
|
-
this.name = 'NestedRelationInputError';
|
|
48
|
-
this.listKey = listKey;
|
|
49
|
-
this.fieldKey = fieldKey;
|
|
50
|
-
this.kinds = kinds;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/** Nested-op kinds refused outright for non-sudo contexts. See {@link NestedRelationInputError}. */
|
|
54
|
-
const REFUSED_KINDS = ['set', 'updateMany', 'deleteMany'];
|
|
55
|
-
function isRelationshipField(fieldConfig) {
|
|
56
|
-
return fieldConfig?.type === 'relationship';
|
|
57
|
-
}
|
|
58
|
-
/** Resolve a list name by matching config object identity, not by name. */
|
|
59
|
-
function findListName(
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
61
|
-
relatedListConfig, config) {
|
|
62
|
-
for (const [listKey, listCfg] of Object.entries(config.lists)) {
|
|
63
|
-
if (listCfg === relatedListConfig) {
|
|
64
|
-
return listKey;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return '';
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Read the rows of a parent's included relation as an array.
|
|
71
|
-
*
|
|
72
|
-
* A to-one relation comes back as a single row (or `null`); a to-many relation
|
|
73
|
-
* comes back as an array. Normalises both so callers can apply a uniform id-diff.
|
|
74
|
-
*/
|
|
75
|
-
function includedRows(parentResult, fieldName) {
|
|
76
|
-
const included = parentResult[fieldName];
|
|
77
|
-
if (included == null)
|
|
78
|
-
return [];
|
|
79
|
-
if (Array.isArray(included))
|
|
80
|
-
return included;
|
|
81
|
-
return [included];
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Recover an UPDATED nested row from the parent result by its known id.
|
|
85
|
-
*
|
|
86
|
-
* The updated row's id is known up front (it was fetched for access as
|
|
87
|
-
* `originalItem`), so the persisted row is the included row with that id.
|
|
88
|
-
*/
|
|
89
|
-
function recoverUpdatedRow(parentResult, fieldName, knownId) {
|
|
90
|
-
if (knownId === undefined)
|
|
91
|
-
return undefined;
|
|
92
|
-
return includedRows(parentResult, fieldName).find((r) => r.id === knownId);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Recover the CREATED nested rows from the parent result by id-diff: the
|
|
96
|
-
* included rows whose ids are NOT in `preExistingIds`. Returned in include
|
|
97
|
-
* order, which {@link CreatedRowRecovery} pairs to create-payload entries by
|
|
98
|
-
* position — reordering this would break that pairing.
|
|
99
|
-
*/
|
|
100
|
-
function recoverCreatedRows(parentResult, fieldName, preExistingIds) {
|
|
101
|
-
return includedRows(parentResult, fieldName).filter((r) => typeof r.id === 'string' && !preExistingIds.has(r.id));
|
|
102
|
-
}
|
|
103
|
-
function createCreatedRowRecovery(fieldName, preExistingIds) {
|
|
104
|
-
let cache;
|
|
105
|
-
return {
|
|
106
|
-
rowAt(parentResult, index) {
|
|
107
|
-
if (!cache || cache.source !== parentResult) {
|
|
108
|
-
cache = {
|
|
109
|
-
source: parentResult,
|
|
110
|
-
rows: recoverCreatedRows(parentResult, fieldName, preExistingIds),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return cache.rows[index];
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Capture the ids of the rows currently linked to the parent via `fieldName`,
|
|
119
|
-
* BEFORE the parent persists, so created rows can later be identified by id-diff.
|
|
120
|
-
* Empty for a parent CREATE (no parent row exists yet to have related rows).
|
|
121
|
-
*
|
|
122
|
-
* `prisma` must be the transaction client — the read has to participate in the
|
|
123
|
-
* transaction to see a consistent snapshot.
|
|
124
|
-
*/
|
|
125
|
-
async function capturePreExistingIds(parentListName, parentOriginalItem, fieldName, prisma) {
|
|
126
|
-
const ids = new Set();
|
|
127
|
-
const parentId = parentOriginalItem?.id;
|
|
128
|
-
if (typeof parentId !== 'string') {
|
|
129
|
-
// Parent create (no existing row) — nothing pre-exists.
|
|
130
|
-
return ids;
|
|
131
|
-
}
|
|
132
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
-
const parentModel = prisma[getDbKey(parentListName)];
|
|
135
|
-
if (!parentModel?.findUnique)
|
|
136
|
-
return ids;
|
|
137
|
-
const current = await parentModel.findUnique({
|
|
138
|
-
where: { id: parentId },
|
|
139
|
-
include: { [fieldName]: true },
|
|
140
|
-
});
|
|
141
|
-
for (const row of includedRows((current ?? {}), fieldName)) {
|
|
142
|
-
if (typeof row.id === 'string')
|
|
143
|
-
ids.add(row.id);
|
|
144
|
-
}
|
|
145
|
-
return ids;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Process nested create operations: run the target list's full input pipeline
|
|
149
|
-
* and `beforeOperation`, then register an `afterOperation` task keyed to the
|
|
150
|
-
* parent's included relation.
|
|
151
|
-
*/
|
|
152
|
-
async function processNestedCreate(items, fieldName, relatedListName,
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
154
|
-
relatedListConfig, context, config, prisma, afterTasks, recovery) {
|
|
155
|
-
const itemsArray = Array.isArray(items) ? items : [items];
|
|
156
|
-
const processedItems = await Promise.all(itemsArray.map(async (item, index) => {
|
|
157
|
-
if (!context._isSudo) {
|
|
158
|
-
const createAccess = relatedListConfig.access?.operation?.create;
|
|
159
|
-
const allowed = await checkCreateAccess(relatedListName, createAccess, {
|
|
160
|
-
session: context.session,
|
|
161
|
-
context,
|
|
162
|
-
});
|
|
163
|
-
if (!allowed) {
|
|
164
|
-
throw new Error('Access denied: Cannot create related item');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
let resolvedData = await executeResolveInput(relatedListConfig.hooks, {
|
|
168
|
-
listKey: relatedListName,
|
|
169
|
-
operation: 'create',
|
|
170
|
-
inputData: item,
|
|
171
|
-
resolvedData: item,
|
|
172
|
-
item: undefined,
|
|
173
|
-
context,
|
|
174
|
-
});
|
|
175
|
-
resolvedData = await executeFieldResolveInputHooks(item, resolvedData, relatedListConfig.fields, 'create', context, relatedListName);
|
|
176
|
-
// Apply field defaults to omitted inputs (resolve-then-validate, #615) so
|
|
177
|
-
// a nested required-with-default field resolves before `isRequired` runs,
|
|
178
|
-
// mirroring the top-level pipeline. Create-only.
|
|
179
|
-
resolvedData = applyCreateDefaults(resolvedData, relatedListConfig.fields);
|
|
180
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
181
|
-
listKey: relatedListName,
|
|
182
|
-
operation: 'create',
|
|
183
|
-
inputData: item,
|
|
184
|
-
resolvedData,
|
|
185
|
-
item: undefined,
|
|
186
|
-
context,
|
|
187
|
-
});
|
|
188
|
-
await executeFieldValidateHooks(item, resolvedData, relatedListConfig.fields, 'create', context, relatedListName);
|
|
189
|
-
const validation = validateFieldRules(resolvedData, relatedListConfig.fields, 'create');
|
|
190
|
-
if (validation.errors.length > 0) {
|
|
191
|
-
throw new ValidationError(validation.errors, validation.fieldErrors);
|
|
192
|
-
}
|
|
193
|
-
// Split multi-column fields into physical columns (#789) — must run after
|
|
194
|
-
// validation, which operates on the logical (pre-split) value.
|
|
195
|
-
resolvedData = await splitMultiColumnFields(item, resolvedData, relatedListConfig.fields, 'create', context);
|
|
196
|
-
const filtered = await filterWritableFields(resolvedData, relatedListConfig.fields, 'create', {
|
|
197
|
-
session: context.session,
|
|
198
|
-
context,
|
|
199
|
-
inputData: item,
|
|
200
|
-
listName: relatedListName,
|
|
201
|
-
config,
|
|
202
|
-
});
|
|
203
|
-
// This nested row is itself being created, so it has no pre-existing
|
|
204
|
-
// related rows of its own (parent originalItem is undefined below).
|
|
205
|
-
const { data: nestedData, afterTasks: childAfterTasks } = await processNestedOperations(filtered, relatedListConfig.fields, config, { ...context, prisma }, 'create', relatedListName, undefined,
|
|
206
|
-
// Its own create payload is the enclosing inputData for the connect-site
|
|
207
|
-
// owning-field gate (#588).
|
|
208
|
-
item);
|
|
209
|
-
await executeFieldBeforeOperationHooks(item, resolvedData, relatedListConfig.fields, 'create', context, relatedListName);
|
|
210
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
211
|
-
listKey: relatedListName,
|
|
212
|
-
operation: 'create',
|
|
213
|
-
inputData: item,
|
|
214
|
-
resolvedData,
|
|
215
|
-
context,
|
|
216
|
-
});
|
|
217
|
-
// Fires once the parent has persisted. The row is recovered by id-diff and
|
|
218
|
-
// paired to THIS entry by position (see CreatedRowRecovery), so a to-many
|
|
219
|
-
// `create: [{A},{B}]` fires once per row against its own distinct row.
|
|
220
|
-
afterTasks.push({
|
|
221
|
-
fieldName,
|
|
222
|
-
run: async (parentResult) => {
|
|
223
|
-
const createdItem = recovery.rowAt(parentResult, index);
|
|
224
|
-
if (!createdItem) {
|
|
225
|
-
// Could not identify the created row by id-diff — the parent write
|
|
226
|
-
// didn't echo this nested relation (e.g. a client/mock that doesn't
|
|
227
|
-
// honour `include`; real Prisma always does). Deliberately SKIP this
|
|
228
|
-
// record's `afterOperation` rather than fabricate an id-less item —
|
|
229
|
-
// `item` correctness is the must-have, so a missing row is never faked.
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
233
|
-
listKey: relatedListName,
|
|
234
|
-
operation: 'create',
|
|
235
|
-
inputData: item,
|
|
236
|
-
item: createdItem,
|
|
237
|
-
resolvedData,
|
|
238
|
-
context,
|
|
239
|
-
});
|
|
240
|
-
await executeFieldAfterOperationHooks(createdItem, item, resolvedData, relatedListConfig.fields, 'create', context, relatedListName);
|
|
241
|
-
await runAfterTasks(childAfterTasks, createdItem);
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
return nestedData;
|
|
245
|
-
}));
|
|
246
|
-
return Array.isArray(items) ? processedItems : processedItems[0];
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Verify that a single connection (or, for `disconnect`, disconnection)
|
|
250
|
-
* target is reachable for the caller.
|
|
251
|
-
*
|
|
252
|
-
* Both directions reference an existing row rather than modifying it, so —
|
|
253
|
-
* mirroring Keystone — they require **read/query** access on the target
|
|
254
|
-
* (#578/#1384), not update. A filter-result query access is evaluated in the
|
|
255
|
-
* DATABASE via `findFirst({ where: { AND: [connection, accessFilter] } })`
|
|
256
|
-
* rather than in memory, so it correctly handles arbitrary nested-relation
|
|
257
|
-
* predicates and boolean combinators; a non-existent id is folded into the
|
|
258
|
-
* same check.
|
|
259
|
-
*
|
|
260
|
-
* For `connect` (the default, `action: 'connect'`), the OWNING relationship
|
|
261
|
-
* field's field-level access (e.g. `Post.author`'s `create`/`update` access)
|
|
262
|
-
* must ADDITIONALLY permit the connect (#588) — the other half Keystone
|
|
263
|
-
* requires: read access on the target AND write access on the owning field. A
|
|
264
|
-
* deny here denies the connect even when the target row is readable/reachable.
|
|
265
|
-
*
|
|
266
|
-
* For `disconnect` (`action: 'disconnect'`), the caller passes
|
|
267
|
-
* `owningFieldAccess: undefined`, which makes this second gate a no-op
|
|
268
|
-
* (`checkFieldAccess` defaults an absent rule to allow) — deliberately: the
|
|
269
|
-
* owning field's write access is already enforced by Phase 5's
|
|
270
|
-
* `filterWritableFields` before nested-op processing ever sees this payload,
|
|
271
|
-
* so re-running it here would only duplicate that gate, not add one. See
|
|
272
|
-
* {@link processNestedDisconnect}.
|
|
273
|
-
*
|
|
274
|
-
* Sudo bypasses the entire check (handled by the caller).
|
|
275
|
-
*/
|
|
276
|
-
async function verifyConnectReachable(connection, relatedListName,
|
|
277
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
278
|
-
relatedListConfig, context, prisma, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData, action = 'connect') {
|
|
279
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
280
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
-
const model = prisma[getDbKey(relatedListName)];
|
|
282
|
-
const deniedMessage = action === 'connect'
|
|
283
|
-
? 'Access denied: Cannot connect to this item'
|
|
284
|
-
: 'Access denied: Cannot disconnect from this item';
|
|
285
|
-
// #588 owning-field gate (see docblock above). `item`/`inputData` are the
|
|
286
|
-
// ENCLOSING write's `originalItem`/`inputData` — the same values the canonical
|
|
287
|
-
// Phase-5 `filterWritableFields` call passes for this field — so an
|
|
288
|
-
// item-/inputData-dependent field-access rule can't diverge between the two gates.
|
|
289
|
-
const owningFieldAllowed = await checkFieldAccess(owningFieldAccess, enclosingOperation, {
|
|
290
|
-
session: context.session,
|
|
291
|
-
item: enclosingItem,
|
|
292
|
-
inputData: enclosingInputData,
|
|
293
|
-
context,
|
|
294
|
-
});
|
|
295
|
-
if (!owningFieldAllowed) {
|
|
296
|
-
throw new Error(deniedMessage);
|
|
297
|
-
}
|
|
298
|
-
const queryAccess = relatedListConfig.access?.operation?.query;
|
|
299
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
300
|
-
session: context.session,
|
|
301
|
-
context,
|
|
302
|
-
});
|
|
303
|
-
if (accessResult === false) {
|
|
304
|
-
throw new Error(deniedMessage);
|
|
305
|
-
}
|
|
306
|
-
// Full access still verifies the row exists, to keep "Item not found" behaviour.
|
|
307
|
-
if (accessResult === true) {
|
|
308
|
-
const item = await model.findUnique({ where: connection });
|
|
309
|
-
if (!item) {
|
|
310
|
-
throw new Error(`Cannot ${action}: Item not found`);
|
|
311
|
-
}
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
// Filter result: reachable iff AND-combining the connection with the filter
|
|
315
|
-
// returns a row (see docblock above).
|
|
316
|
-
const reachable = await model.findFirst({
|
|
317
|
-
where: { AND: [connection, accessResult] },
|
|
318
|
-
});
|
|
319
|
-
if (!reachable) {
|
|
320
|
-
throw new Error(deniedMessage);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Process nested connect operations.
|
|
325
|
-
* Verifies read (query) access to the items being connected via DB reachability
|
|
326
|
-
* AND the owning relationship field's field-level access (#588).
|
|
327
|
-
*/
|
|
328
|
-
async function processNestedConnect(connections, relatedListName,
|
|
329
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
330
|
-
relatedListConfig, context, prisma, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData) {
|
|
331
|
-
const connectionsArray = Array.isArray(connections) ? connections : [connections];
|
|
332
|
-
if (!context._isSudo) {
|
|
333
|
-
for (const connection of connectionsArray) {
|
|
334
|
-
await verifyConnectReachable(connection, relatedListName, relatedListConfig, context, prisma, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return connections;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Process a nested `disconnect` (#1384).
|
|
341
|
-
*
|
|
342
|
-
* `{ disconnect: true }` — the to-one boolean form — nulls the foreign key on
|
|
343
|
-
* the row already being updated; that row's own update access has already
|
|
344
|
-
* been checked (by the enclosing write), so it is left permitted, unchanged,
|
|
345
|
-
* with no target-list check. This is the form the admin UI's `removeRelated`
|
|
346
|
-
* action emits for a to-one back-reference (ADR-0018).
|
|
347
|
-
*
|
|
348
|
-
* `{ disconnect: { <criteria> } }` — or an array of criteria, for a to-many —
|
|
349
|
-
* names a target row on the OTHER list. This requires that target's
|
|
350
|
-
* `operation.query` access, Keystone's semantic, reusing `verifyConnectReachable`
|
|
351
|
-
* (see its docblock for why the owning-field gate is skipped here) rather than
|
|
352
|
-
* a second reachability check.
|
|
353
|
-
*/
|
|
354
|
-
async function processNestedDisconnect(value, relatedListName,
|
|
355
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
356
|
-
relatedListConfig, context, prisma, enclosingOperation) {
|
|
357
|
-
if (value === true || context._isSudo) {
|
|
358
|
-
return value;
|
|
359
|
-
}
|
|
360
|
-
const criteriaArray = Array.isArray(value)
|
|
361
|
-
? value
|
|
362
|
-
: [value];
|
|
363
|
-
for (const criteria of criteriaArray) {
|
|
364
|
-
await verifyConnectReachable(criteria, relatedListName, relatedListConfig, context, prisma, undefined, enclosingOperation, undefined, undefined, 'disconnect');
|
|
365
|
-
}
|
|
366
|
-
return value;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Re-check a nested update/delete access result against the target row,
|
|
370
|
-
* mirroring the Write Pipeline's `resolveExistingTarget` (#1081): `false`
|
|
371
|
-
* denies, `true` allows outright (the row's existence is already established
|
|
372
|
-
* by the caller's own `findUnique`), and a returned PrismaFilter must
|
|
373
|
-
* additionally match the row, re-checked in the DATABASE via
|
|
374
|
-
* `findFirst(mergeFilters(where, accessResult))` rather than in memory — the
|
|
375
|
-
* same requirement `connect`'s reachability check already applies (#578), so
|
|
376
|
-
* nested-relation predicates and boolean combinators are honoured correctly.
|
|
377
|
-
*/
|
|
378
|
-
async function isExistingTargetAccessible(model, where, accessResult) {
|
|
379
|
-
if (accessResult === false)
|
|
380
|
-
return false;
|
|
381
|
-
if (accessResult === true)
|
|
382
|
-
return true;
|
|
383
|
-
const matchesFilter = await model.findFirst({ where: mergeFilters(where, accessResult) ?? {} });
|
|
384
|
-
return matchesFilter !== null;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Process nested update operations.
|
|
388
|
-
*
|
|
389
|
-
* Runs the target list's full update input pipeline AND its `beforeOperation`,
|
|
390
|
-
* then registers an `afterOperation` task receiving `originalItem` (the row
|
|
391
|
-
* fetched before the write) and the persisted updated `item`.
|
|
392
|
-
*/
|
|
393
|
-
async function processNestedUpdate(updates, fieldName, relatedListName,
|
|
394
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
395
|
-
relatedListConfig, context, config, prisma, afterTasks) {
|
|
396
|
-
const updatesArray = Array.isArray(updates) ? updates : [updates];
|
|
397
|
-
const processedUpdates = await Promise.all(updatesArray.map(async (update) => {
|
|
398
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
399
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
400
|
-
const model = prisma[getDbKey(relatedListName)];
|
|
401
|
-
const where = update.where;
|
|
402
|
-
// Fetched here and reused as `originalItem` for afterOperation.
|
|
403
|
-
const originalItem = await model.findUnique({ where });
|
|
404
|
-
if (!originalItem) {
|
|
405
|
-
throw new Error('Cannot update: Item not found');
|
|
406
|
-
}
|
|
407
|
-
const knownId = typeof originalItem.id === 'string' ? originalItem.id : undefined;
|
|
408
|
-
if (!context._isSudo) {
|
|
409
|
-
const updateAccess = relatedListConfig.access?.operation?.update;
|
|
410
|
-
const accessResult = await checkAccess(updateAccess, {
|
|
411
|
-
session: context.session,
|
|
412
|
-
item: originalItem,
|
|
413
|
-
context,
|
|
414
|
-
});
|
|
415
|
-
if (!(await isExistingTargetAccessible(model, where, accessResult))) {
|
|
416
|
-
throw new Error('Access denied: Cannot update related item');
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
const updateData = update.data;
|
|
420
|
-
let resolvedData = await executeResolveInput(relatedListConfig.hooks, {
|
|
421
|
-
listKey: relatedListName,
|
|
422
|
-
operation: 'update',
|
|
423
|
-
inputData: updateData,
|
|
424
|
-
resolvedData: updateData,
|
|
425
|
-
item: originalItem,
|
|
426
|
-
context,
|
|
427
|
-
});
|
|
428
|
-
resolvedData = await executeFieldResolveInputHooks(updateData, resolvedData, relatedListConfig.fields, 'update', context, relatedListName, originalItem);
|
|
429
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
430
|
-
listKey: relatedListName,
|
|
431
|
-
operation: 'update',
|
|
432
|
-
inputData: updateData,
|
|
433
|
-
resolvedData,
|
|
434
|
-
item: originalItem,
|
|
435
|
-
context,
|
|
436
|
-
});
|
|
437
|
-
await executeFieldValidateHooks(updateData, resolvedData, relatedListConfig.fields, 'update', context, relatedListName, originalItem);
|
|
438
|
-
const validation = validateFieldRules(resolvedData, relatedListConfig.fields, 'update');
|
|
439
|
-
if (validation.errors.length > 0) {
|
|
440
|
-
throw new ValidationError(validation.errors, validation.fieldErrors);
|
|
441
|
-
}
|
|
442
|
-
// Split multi-column fields into physical columns (#789) — must run after
|
|
443
|
-
// validation, which operates on the logical (pre-split) value.
|
|
444
|
-
resolvedData = await splitMultiColumnFields(updateData, resolvedData, relatedListConfig.fields, 'update', context, originalItem);
|
|
445
|
-
const filtered = await filterWritableFields(resolvedData, relatedListConfig.fields, 'update', {
|
|
446
|
-
session: context.session,
|
|
447
|
-
item: originalItem,
|
|
448
|
-
context,
|
|
449
|
-
inputData: updateData,
|
|
450
|
-
listName: relatedListName,
|
|
451
|
-
config,
|
|
452
|
-
});
|
|
453
|
-
// This nested row is being updated, so its own relations' pre-existing
|
|
454
|
-
// rows are captured from `originalItem` below.
|
|
455
|
-
const { data: nestedData, afterTasks: childAfterTasks } = await processNestedOperations(filtered, relatedListConfig.fields, config, { ...context, prisma }, 'update', relatedListName, originalItem,
|
|
456
|
-
// Its own update payload is the enclosing inputData for the connect-site
|
|
457
|
-
// owning-field gate (#588).
|
|
458
|
-
updateData);
|
|
459
|
-
await executeFieldBeforeOperationHooks(updateData, resolvedData, relatedListConfig.fields, 'update', context, relatedListName, originalItem);
|
|
460
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
461
|
-
listKey: relatedListName,
|
|
462
|
-
operation: 'update',
|
|
463
|
-
inputData: updateData,
|
|
464
|
-
item: originalItem,
|
|
465
|
-
resolvedData,
|
|
466
|
-
context,
|
|
467
|
-
});
|
|
468
|
-
// Fires after the parent persist; the row is recovered by its known id.
|
|
469
|
-
afterTasks.push({
|
|
470
|
-
fieldName,
|
|
471
|
-
run: async (parentResult) => {
|
|
472
|
-
const persisted = recoverUpdatedRow(parentResult, fieldName, knownId);
|
|
473
|
-
const updatedItem = persisted ?? originalItem;
|
|
474
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
475
|
-
listKey: relatedListName,
|
|
476
|
-
operation: 'update',
|
|
477
|
-
inputData: updateData,
|
|
478
|
-
originalItem,
|
|
479
|
-
item: updatedItem,
|
|
480
|
-
resolvedData,
|
|
481
|
-
context,
|
|
482
|
-
});
|
|
483
|
-
await executeFieldAfterOperationHooks(updatedItem, updateData, resolvedData, relatedListConfig.fields, 'update', context, relatedListName, originalItem);
|
|
484
|
-
await runAfterTasks(childAfterTasks, updatedItem);
|
|
485
|
-
},
|
|
486
|
-
});
|
|
487
|
-
return {
|
|
488
|
-
where,
|
|
489
|
-
data: nestedData,
|
|
490
|
-
};
|
|
491
|
-
}));
|
|
492
|
-
return Array.isArray(updates) ? processedUpdates : processedUpdates[0];
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Process nested delete operations.
|
|
496
|
-
*
|
|
497
|
-
* Runs the target list's delete pipeline (validate/field-validate +
|
|
498
|
-
* `beforeOperation`) before the parent persist, and registers an
|
|
499
|
-
* `afterOperation` task receiving the `originalItem` (the row before deletion).
|
|
500
|
-
* Persistence is performed by Prisma's nested write; the row no longer exists
|
|
501
|
-
* after, so `originalItem` is the authoritative record for after-hooks.
|
|
502
|
-
*/
|
|
503
|
-
async function processNestedDelete(deletes, relatedListName,
|
|
504
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
505
|
-
relatedListConfig, context, prisma, afterTasks) {
|
|
506
|
-
// A to-one relation delete can be a boolean (`{ delete: true }`); there is no
|
|
507
|
-
// identifying `where`, so we cannot run target-resolved hooks. Pass through.
|
|
508
|
-
if (typeof deletes === 'boolean') {
|
|
509
|
-
return deletes;
|
|
510
|
-
}
|
|
511
|
-
const deletesArray = Array.isArray(deletes) ? deletes : [deletes];
|
|
512
|
-
await Promise.all(deletesArray.map(async (del) => {
|
|
513
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
514
|
-
const model = prisma[getDbKey(relatedListName)];
|
|
515
|
-
// A nested delete entry is itself the unique `where` (e.g. `{ id }`).
|
|
516
|
-
const where = del;
|
|
517
|
-
const originalItem = await model.findUnique({ where });
|
|
518
|
-
if (!originalItem) {
|
|
519
|
-
throw new Error('Cannot delete: Item not found');
|
|
520
|
-
}
|
|
521
|
-
if (!context._isSudo) {
|
|
522
|
-
const deleteAccess = relatedListConfig.access?.operation?.delete;
|
|
523
|
-
const accessResult = await checkAccess(deleteAccess, {
|
|
524
|
-
session: context.session,
|
|
525
|
-
item: originalItem,
|
|
526
|
-
context,
|
|
527
|
-
});
|
|
528
|
-
if (!(await isExistingTargetAccessible(model, where, accessResult))) {
|
|
529
|
-
throw new Error('Access denied: Cannot delete related item');
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
533
|
-
listKey: relatedListName,
|
|
534
|
-
operation: 'delete',
|
|
535
|
-
item: originalItem,
|
|
536
|
-
context,
|
|
537
|
-
});
|
|
538
|
-
await executeFieldValidateHooks(undefined, undefined, relatedListConfig.fields, 'delete', context, relatedListName, originalItem);
|
|
539
|
-
await executeFieldBeforeOperationHooks({}, {}, relatedListConfig.fields, 'delete', context, relatedListName, originalItem);
|
|
540
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
541
|
-
listKey: relatedListName,
|
|
542
|
-
operation: 'delete',
|
|
543
|
-
item: originalItem,
|
|
544
|
-
context,
|
|
545
|
-
});
|
|
546
|
-
// The row is gone after persist, so originalItem is the authoritative
|
|
547
|
-
// record passed to the after-hooks below.
|
|
548
|
-
afterTasks.push({
|
|
549
|
-
fieldName: '',
|
|
550
|
-
run: async () => {
|
|
551
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
552
|
-
listKey: relatedListName,
|
|
553
|
-
operation: 'delete',
|
|
554
|
-
originalItem,
|
|
555
|
-
context,
|
|
556
|
-
});
|
|
557
|
-
await executeFieldAfterOperationHooks(originalItem, undefined, undefined, relatedListConfig.fields, 'delete', context, relatedListName, originalItem);
|
|
558
|
-
},
|
|
559
|
-
});
|
|
560
|
-
}));
|
|
561
|
-
return deletes;
|
|
562
|
-
}
|
|
563
|
-
async function processNestedConnectOrCreate(operations, fieldName, relatedListName,
|
|
564
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
565
|
-
relatedListConfig, context, config, prisma, afterTasks, recovery, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData) {
|
|
566
|
-
const operationsArray = Array.isArray(operations) ? operations : [operations];
|
|
567
|
-
const processedOps = await Promise.all(operationsArray.map(async (op) => {
|
|
568
|
-
const opRecord = op;
|
|
569
|
-
// When the target row exists, connectOrCreate applies the same connect
|
|
570
|
-
// semantics as processNestedConnect (read access + #588 owning-field gate,
|
|
571
|
-
// both evaluated via DB reachability); otherwise it falls through to
|
|
572
|
-
// create. An access-denied error must NOT be swallowed into that fallback
|
|
573
|
-
// — only a genuine "row absent" may fall back to create.
|
|
574
|
-
let rowExists = false;
|
|
575
|
-
if (!context._isSudo) {
|
|
576
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
577
|
-
const model = prisma[getDbKey(relatedListName)];
|
|
578
|
-
const where = opRecord.where;
|
|
579
|
-
const existingItem = await model.findUnique({ where });
|
|
580
|
-
if (existingItem) {
|
|
581
|
-
rowExists = true;
|
|
582
|
-
const owningFieldAllowed = await checkFieldAccess(owningFieldAccess, enclosingOperation, {
|
|
583
|
-
session: context.session,
|
|
584
|
-
item: enclosingItem,
|
|
585
|
-
inputData: enclosingInputData,
|
|
586
|
-
context,
|
|
587
|
-
});
|
|
588
|
-
if (!owningFieldAllowed) {
|
|
589
|
-
throw new Error('Access denied: Cannot connect to existing item');
|
|
590
|
-
}
|
|
591
|
-
const queryAccess = relatedListConfig.access?.operation?.query;
|
|
592
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
593
|
-
session: context.session,
|
|
594
|
-
item: existingItem,
|
|
595
|
-
context,
|
|
596
|
-
});
|
|
597
|
-
if (accessResult === false) {
|
|
598
|
-
throw new Error('Access denied: Cannot connect to existing item');
|
|
599
|
-
}
|
|
600
|
-
if (accessResult !== true) {
|
|
601
|
-
const reachable = await model.findFirst({
|
|
602
|
-
where: { AND: [where, accessResult] },
|
|
603
|
-
});
|
|
604
|
-
if (!reachable) {
|
|
605
|
-
throw new Error('Access denied: Cannot connect to existing item');
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
// Only register an afterOperation task when the create branch will
|
|
611
|
-
// actually run (row absent), so a pure connect doesn't fire create hooks.
|
|
612
|
-
// Under sudo we can't tell statically, so the create pipeline always runs
|
|
613
|
-
// its hooks there (sudo bypasses access only, not hooks).
|
|
614
|
-
const runCreateHooks = context._isSudo || !rowExists;
|
|
615
|
-
const createAfterTasks = runCreateHooks ? afterTasks : [];
|
|
616
|
-
const processedCreate = await processNestedCreate(opRecord.create, fieldName, relatedListName, relatedListConfig, context, config, prisma, createAfterTasks, recovery);
|
|
617
|
-
return {
|
|
618
|
-
where: opRecord.where,
|
|
619
|
-
create: processedCreate,
|
|
620
|
-
};
|
|
621
|
-
}));
|
|
622
|
-
return Array.isArray(operations) ? processedOps : processedOps[0];
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Narrow the lazily-built {@link CreatedRowRecovery} to a present value for the
|
|
626
|
-
* created kinds (`create`, `connectOrCreate`). It is always provided for these
|
|
627
|
-
* kinds by {@link processFieldNestedOps}; the guard backstops a programming
|
|
628
|
-
* error rather than a user-facing path.
|
|
629
|
-
*/
|
|
630
|
-
function requireRecovery(recovery, kind) {
|
|
631
|
-
if (!recovery) {
|
|
632
|
-
throw new Error(`Internal error: missing created-row recovery for nested "${kind}"`);
|
|
633
|
-
}
|
|
634
|
-
return recovery;
|
|
635
|
-
}
|
|
636
|
-
/** Nested-op kinds that can create new rows and so need created-row recovery. */
|
|
637
|
-
const CREATING_KINDS = new Set(['create', 'connectOrCreate']);
|
|
638
|
-
/**
|
|
639
|
-
* Registry of nested-operation handlers keyed by nested-op kind.
|
|
640
|
-
*
|
|
641
|
-
* Kinds that run the full hook pipeline (`create`, `update`, `delete`, and the
|
|
642
|
-
* create branch of `connectOrCreate`) run `beforeOperation` inline and register
|
|
643
|
-
* deferred `afterOperation` tasks. `connect`/`connectOrCreate`'s connect branch,
|
|
644
|
-
* and `disconnect`'s target-row form, enforce access only — no hooks (#1384;
|
|
645
|
-
* this settles the `disconnect` half of #569's original scope note, which is
|
|
646
|
-
* now closed).
|
|
647
|
-
*
|
|
648
|
-
* `set`, `updateMany` and `deleteMany` are refused outright for non-sudo
|
|
649
|
-
* contexts before dispatch even reaches this registry (see `REFUSED_KINDS` /
|
|
650
|
-
* {@link NestedRelationInputError} near the top of this file) rather than
|
|
651
|
-
* given their own access machinery — ADR-0050 removes nested relation input
|
|
652
|
-
* from the secured write surface entirely on the `prisma-8` line, so that
|
|
653
|
-
* machinery would be built into a module the next major deletes wholesale.
|
|
654
|
-
* Their entries below therefore only ever run under `sudo()`, where they
|
|
655
|
-
* remain an unchecked, hook-free pass-through to Prisma, unchanged.
|
|
656
|
-
*/
|
|
657
|
-
const nestedOpRegistry = {
|
|
658
|
-
create: {
|
|
659
|
-
needsInclude: true,
|
|
660
|
-
execute: ({ value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks, recovery, }) => processNestedCreate(value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks, requireRecovery(recovery, 'create')),
|
|
661
|
-
},
|
|
662
|
-
connect: {
|
|
663
|
-
needsInclude: false,
|
|
664
|
-
execute: ({ value, relatedListName, relatedListConfig, context, prisma, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData, }) => processNestedConnect(value, relatedListName, relatedListConfig, context, prisma, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData),
|
|
665
|
-
},
|
|
666
|
-
connectOrCreate: {
|
|
667
|
-
needsInclude: true,
|
|
668
|
-
execute: ({ value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks, recovery, owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData, }) => processNestedConnectOrCreate(value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks, requireRecovery(recovery, 'connectOrCreate'), owningFieldAccess, enclosingOperation, enclosingItem, enclosingInputData),
|
|
669
|
-
},
|
|
670
|
-
update: {
|
|
671
|
-
needsInclude: true,
|
|
672
|
-
execute: ({ value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks, }) => processNestedUpdate(value, fieldName, relatedListName, relatedListConfig, context, config, prisma, afterTasks),
|
|
673
|
-
},
|
|
674
|
-
delete: {
|
|
675
|
-
// The row no longer exists after the parent write, so no read-back include.
|
|
676
|
-
needsInclude: false,
|
|
677
|
-
execute: ({ value, relatedListName, relatedListConfig, context, prisma, afterTasks }) => processNestedDelete(value, relatedListName, relatedListConfig, context, prisma, afterTasks),
|
|
678
|
-
},
|
|
679
|
-
// Gated pass-through: no hooks, but the target-row form requires the target
|
|
680
|
-
// list's operation.query access (#1384). See processNestedDisconnect.
|
|
681
|
-
disconnect: {
|
|
682
|
-
needsInclude: false,
|
|
683
|
-
execute: ({ value, relatedListName, relatedListConfig, context, prisma, enclosingOperation }) => processNestedDisconnect(value, relatedListName, relatedListConfig, context, prisma, enclosingOperation),
|
|
684
|
-
},
|
|
685
|
-
// Refused for non-sudo before dispatch reaches here (see REFUSED_KINDS) —
|
|
686
|
-
// these entries only ever run under sudo, as an unchecked pass-through.
|
|
687
|
-
deleteMany: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
688
|
-
set: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
689
|
-
updateMany: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
690
|
-
};
|
|
691
|
-
/**
|
|
692
|
-
* Order in which nested-op kinds are processed for a single relationship field.
|
|
693
|
-
*/
|
|
694
|
-
const nestedOpOrder = [
|
|
695
|
-
'create',
|
|
696
|
-
'connect',
|
|
697
|
-
'connectOrCreate',
|
|
698
|
-
'update',
|
|
699
|
-
'disconnect',
|
|
700
|
-
'delete',
|
|
701
|
-
'deleteMany',
|
|
702
|
-
'set',
|
|
703
|
-
'updateMany',
|
|
704
|
-
];
|
|
705
|
-
/**
|
|
706
|
-
* Process the nested relationship operations supplied for a single
|
|
707
|
-
* relationship field's value, dispatching each present nested-op kind through
|
|
708
|
-
* the {@link nestedOpRegistry}.
|
|
709
|
-
*/
|
|
710
|
-
async function processFieldNestedOps(fieldName, valueRecord, args, includeFields, parentListName, parentOriginalItem) {
|
|
711
|
-
// Refuse a non-sudo payload carrying a refused kind BEFORE any part of the
|
|
712
|
-
// write executes — including before another kind on this same field
|
|
713
|
-
// dispatches (see NestedRelationInputError's docblock). Collects every
|
|
714
|
-
// refused kind present so a payload mixing e.g. `set` and `updateMany`
|
|
715
|
-
// reports both in one error, not just the first found.
|
|
716
|
-
if (!args.context._isSudo) {
|
|
717
|
-
const refusedKinds = REFUSED_KINDS.filter((kind) => valueRecord[kind] !== undefined);
|
|
718
|
-
if (refusedKinds.length > 0) {
|
|
719
|
-
throw new NestedRelationInputError(parentListName, fieldName, refusedKinds);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
const nestedOp = {};
|
|
723
|
-
// Created-row recovery is only needed when this field has a creating kind
|
|
724
|
-
// (`create`/`connectOrCreate`). When present it requires a pre-persist read of
|
|
725
|
-
// the parent's current related ids, so build it once, lazily, and share it
|
|
726
|
-
// across the creating kinds on this field.
|
|
727
|
-
let recovery;
|
|
728
|
-
const hasCreatingKind = nestedOpOrder.some((kind) => CREATING_KINDS.has(kind) && valueRecord[kind] !== undefined);
|
|
729
|
-
if (hasCreatingKind) {
|
|
730
|
-
const preExistingIds = await capturePreExistingIds(parentListName, parentOriginalItem, fieldName, args.prisma);
|
|
731
|
-
recovery = createCreatedRowRecovery(fieldName, preExistingIds);
|
|
732
|
-
}
|
|
733
|
-
for (const kind of nestedOpOrder) {
|
|
734
|
-
const value = valueRecord[kind];
|
|
735
|
-
if (value === undefined) {
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
const handler = nestedOpRegistry[kind];
|
|
739
|
-
if (handler.needsInclude) {
|
|
740
|
-
includeFields.add(fieldName);
|
|
741
|
-
}
|
|
742
|
-
nestedOp[kind] = await handler.execute({
|
|
743
|
-
...args,
|
|
744
|
-
value,
|
|
745
|
-
fieldName,
|
|
746
|
-
recovery,
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
return nestedOp;
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Process all nested operations in a data payload.
|
|
753
|
-
*
|
|
754
|
-
* Recursively handles relationship fields with nested writes. In addition to
|
|
755
|
-
* transforming the payload it runs each nested record's `beforeOperation` and
|
|
756
|
-
* collects deferred `afterOperation` tasks (run by the Write Pipeline after the
|
|
757
|
-
* parent persist via {@link runAfterTasks}). See ADR-0010.
|
|
758
|
-
*/
|
|
759
|
-
export async function processNestedOperations(data, fieldConfigs, config, context, operation, parentListName, parentOriginalItem,
|
|
760
|
-
// The enclosing write's inputData, for the #588 owning-field gate (see
|
|
761
|
-
// verifyConnectReachable). `undefined` is tolerated (defaults to `{}`).
|
|
762
|
-
parentInputData = undefined) {
|
|
763
|
-
const afterTasks = [];
|
|
764
|
-
const includeFields = new Set();
|
|
765
|
-
const processed = {};
|
|
766
|
-
for (const [fieldName, value] of Object.entries(data)) {
|
|
767
|
-
if (value === null || value === undefined) {
|
|
768
|
-
processed[fieldName] = value;
|
|
769
|
-
continue;
|
|
770
|
-
}
|
|
771
|
-
const fieldConfig = fieldConfigs[fieldName];
|
|
772
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
773
|
-
let relatedListConfig;
|
|
774
|
-
let resolvedListName;
|
|
775
|
-
let owningFieldAccess;
|
|
776
|
-
if (isRelationshipField(fieldConfig)) {
|
|
777
|
-
const relationshipField = fieldConfig;
|
|
778
|
-
const relatedConfig = getRelatedListConfig(relationshipField.ref, config);
|
|
779
|
-
if (!relatedConfig) {
|
|
780
|
-
processed[fieldName] = value;
|
|
781
|
-
continue;
|
|
782
|
-
}
|
|
783
|
-
const { listName: relatedListName, listConfig } = relatedConfig;
|
|
784
|
-
resolvedListName = relatedListName || findListName(listConfig, config);
|
|
785
|
-
relatedListConfig = listConfig;
|
|
786
|
-
// The owning relationship field's field-level access, for the #588 gate
|
|
787
|
-
// in verifyConnectReachable.
|
|
788
|
-
owningFieldAccess = fieldConfig.access;
|
|
789
|
-
}
|
|
790
|
-
else if (!fieldConfig) {
|
|
791
|
-
// Not a field the parent's config declares — check whether it names the
|
|
792
|
-
// synthetic back-relation a list-only `ref` generates on this list
|
|
793
|
-
// (`from_<List>_<field>`, #978). Resolved, it is processed exactly like a
|
|
794
|
-
// nested write through the declared field that owns it; unresolved, it
|
|
795
|
-
// is left untouched. This is NOT solely a sudo path: a multi-column
|
|
796
|
-
// field's raw per-part columns (e.g. `m_url`/`m_size`, #789) are ALSO
|
|
797
|
-
// undeclared from this list's `fieldConfigs` perspective and reach here
|
|
798
|
-
// on every write, sudo or not — `filterWritableFields` already
|
|
799
|
-
// recognises and gates those via its own `splitColumnOwners` map before
|
|
800
|
-
// its undeclared-key branch, and this function has no such map to tell
|
|
801
|
-
// them apart from a genuinely-unrecognised key, so it must not throw
|
|
802
|
-
// here. A genuinely unrecognised key under sudo is refused instead by
|
|
803
|
-
// `filterWritableFields`'s own resolution attempt, one level up.
|
|
804
|
-
const synthetic = resolveSyntheticReverseRelation(fieldName, parentListName, config);
|
|
805
|
-
if (!synthetic) {
|
|
806
|
-
processed[fieldName] = value;
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
resolvedListName = synthetic.sourceListName;
|
|
810
|
-
relatedListConfig = synthetic.sourceListConfig;
|
|
811
|
-
// There is no parent-side field here (unlike the declared-relationship
|
|
812
|
-
// branch above) — the FK-owning field genuinely IS the one the source
|
|
813
|
-
// list declares, so its access is the owning-field gate.
|
|
814
|
-
owningFieldAccess = synthetic.sourceFieldConfig.access;
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
processed[fieldName] = value;
|
|
818
|
-
continue;
|
|
819
|
-
}
|
|
820
|
-
processed[fieldName] = await processFieldNestedOps(fieldName, value, {
|
|
821
|
-
relatedListName: resolvedListName,
|
|
822
|
-
relatedListConfig,
|
|
823
|
-
owningFieldAccess,
|
|
824
|
-
enclosingOperation: operation,
|
|
825
|
-
// Same values Phase-5 `filterWritableFields` passes for this field, so
|
|
826
|
-
// the #588 owning-field gate can't diverge from it.
|
|
827
|
-
enclosingItem: parentOriginalItem,
|
|
828
|
-
enclosingInputData: parentInputData ?? {},
|
|
829
|
-
context,
|
|
830
|
-
config,
|
|
831
|
-
prisma: context.prisma,
|
|
832
|
-
afterTasks,
|
|
833
|
-
}, includeFields, parentListName, parentOriginalItem);
|
|
834
|
-
}
|
|
835
|
-
return { data: processed, afterTasks, includeFields };
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Run a set of deferred nested `afterOperation` tasks against a persisted parent
|
|
839
|
-
* row. Tasks run sequentially so a throwing after-hook aborts the rest (and, run
|
|
840
|
-
* inside the transaction by the Write Pipeline, rolls the whole write back).
|
|
841
|
-
*/
|
|
842
|
-
export async function runAfterTasks(afterTasks, parentResult) {
|
|
843
|
-
for (const task of afterTasks) {
|
|
844
|
-
await task.run(parentResult);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
//# sourceMappingURL=nested-operations.js.map
|