@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,1325 +0,0 @@
|
|
|
1
|
-
import type { OpenSaasConfig, ListConfig, FieldConfig } from '../config/types.js'
|
|
2
|
-
import type { FieldAccess, PrismaFilter } from '../access/types.js'
|
|
3
|
-
import type { StackContext } from './index.js'
|
|
4
|
-
import {
|
|
5
|
-
checkAccess,
|
|
6
|
-
checkCreateAccess,
|
|
7
|
-
filterWritableFields,
|
|
8
|
-
getRelatedListConfig,
|
|
9
|
-
mergeFilters,
|
|
10
|
-
resolveSyntheticReverseRelation,
|
|
11
|
-
} from '../access/index.js'
|
|
12
|
-
import { checkFieldAccess } from '../access/field-access.js'
|
|
13
|
-
import {
|
|
14
|
-
executeResolveInput,
|
|
15
|
-
executeValidate,
|
|
16
|
-
executeFieldResolveInputHooks,
|
|
17
|
-
executeBeforeOperation,
|
|
18
|
-
executeAfterOperation,
|
|
19
|
-
executeFieldBeforeOperationHooks,
|
|
20
|
-
executeFieldAfterOperationHooks,
|
|
21
|
-
executeFieldValidateHooks,
|
|
22
|
-
validateFieldRules,
|
|
23
|
-
splitMultiColumnFields,
|
|
24
|
-
ValidationError,
|
|
25
|
-
} from '../hooks/index.js'
|
|
26
|
-
import { getDbKey } from '../lib/case-utils.js'
|
|
27
|
-
import { applyCreateDefaults } from './apply-defaults.js'
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Nested writes (#569 / ADR-0010): give nested `create`/`update`/`delete` the
|
|
31
|
-
* same before/afterOperation hooks as an equivalent top-level write, inside
|
|
32
|
-
* the one transaction the Write Pipeline opens. `processNestedOperations`
|
|
33
|
-
* transforms the payload and runs `beforeOperation`, returning deferred
|
|
34
|
-
* {@link AfterTask}s that {@link runAfterTasks} runs once the parent has
|
|
35
|
-
* persisted. See ADR-0010 for the full mechanism.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/** A deferred nested `afterOperation` task, run once the parent has persisted. */
|
|
39
|
-
export interface AfterTask {
|
|
40
|
-
/** Field name on the parent linking to the related list (for include lookup). */
|
|
41
|
-
fieldName: string
|
|
42
|
-
run(parentResult: Record<string, unknown>): Promise<void>
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Result of processing nested operations: the transformed write payload plus
|
|
47
|
-
* the deferred `afterOperation` tasks and the relation fields the parent write
|
|
48
|
-
* must `include` so those tasks can recover their persisted `item`.
|
|
49
|
-
*/
|
|
50
|
-
export interface NestedOpsResult {
|
|
51
|
-
/** The transformed write payload handed to Prisma. */
|
|
52
|
-
data: Record<string, unknown>
|
|
53
|
-
/** Deferred `afterOperation` tasks to run after the parent persist. */
|
|
54
|
-
afterTasks: AfterTask[]
|
|
55
|
-
/** Relationship field names to `include` in the parent write result. */
|
|
56
|
-
includeFields: Set<string>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isRelationshipField(fieldConfig: FieldConfig | undefined): boolean {
|
|
60
|
-
return fieldConfig?.type === 'relationship'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Resolve a list name by matching config object identity, not by name. */
|
|
64
|
-
function findListName(
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
66
|
-
relatedListConfig: ListConfig<any>,
|
|
67
|
-
config: OpenSaasConfig,
|
|
68
|
-
): string {
|
|
69
|
-
for (const [listKey, listCfg] of Object.entries(config.lists)) {
|
|
70
|
-
if (listCfg === relatedListConfig) {
|
|
71
|
-
return listKey
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return ''
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Read the rows of a parent's included relation as an array.
|
|
79
|
-
*
|
|
80
|
-
* A to-one relation comes back as a single row (or `null`); a to-many relation
|
|
81
|
-
* comes back as an array. Normalises both so callers can apply a uniform id-diff.
|
|
82
|
-
*/
|
|
83
|
-
function includedRows(
|
|
84
|
-
parentResult: Record<string, unknown>,
|
|
85
|
-
fieldName: string,
|
|
86
|
-
): Array<Record<string, unknown>> {
|
|
87
|
-
const included = parentResult[fieldName]
|
|
88
|
-
if (included == null) return []
|
|
89
|
-
if (Array.isArray(included)) return included as Array<Record<string, unknown>>
|
|
90
|
-
return [included as Record<string, unknown>]
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Recover an UPDATED nested row from the parent result by its known id.
|
|
95
|
-
*
|
|
96
|
-
* The updated row's id is known up front (it was fetched for access as
|
|
97
|
-
* `originalItem`), so the persisted row is the included row with that id.
|
|
98
|
-
*/
|
|
99
|
-
function recoverUpdatedRow(
|
|
100
|
-
parentResult: Record<string, unknown>,
|
|
101
|
-
fieldName: string,
|
|
102
|
-
knownId: string | undefined,
|
|
103
|
-
): Record<string, unknown> | undefined {
|
|
104
|
-
if (knownId === undefined) return undefined
|
|
105
|
-
return includedRows(parentResult, fieldName).find((r) => r.id === knownId)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Recover the CREATED nested rows from the parent result by id-diff: the
|
|
110
|
-
* included rows whose ids are NOT in `preExistingIds`. Returned in include
|
|
111
|
-
* order, which {@link CreatedRowRecovery} pairs to create-payload entries by
|
|
112
|
-
* position — reordering this would break that pairing.
|
|
113
|
-
*/
|
|
114
|
-
function recoverCreatedRows(
|
|
115
|
-
parentResult: Record<string, unknown>,
|
|
116
|
-
fieldName: string,
|
|
117
|
-
preExistingIds: Set<string>,
|
|
118
|
-
): Array<Record<string, unknown>> {
|
|
119
|
-
return includedRows(parentResult, fieldName).filter(
|
|
120
|
-
(r) => typeof r.id === 'string' && !preExistingIds.has(r.id as string),
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Shared, memoised recovery of the rows created for ONE nested `create` payload
|
|
126
|
-
* on ONE relation field, by id-diff against the parent's pre-persist related
|
|
127
|
-
* ids, paired to create-payload entries by position. See ADR-0010. The id-diff
|
|
128
|
-
* is cached per parent result so every entry's task shares it.
|
|
129
|
-
*
|
|
130
|
-
* `inputData`↔row pairing is positional and best-effort; `item` correctness
|
|
131
|
-
* (each task gets a genuinely-created, distinct row) is guaranteed — a
|
|
132
|
-
* pre-existing row can never be returned because the diff excludes it.
|
|
133
|
-
*/
|
|
134
|
-
interface CreatedRowRecovery {
|
|
135
|
-
/** Recover the created row for the create-payload entry at `index`. */
|
|
136
|
-
rowAt(parentResult: Record<string, unknown>, index: number): Record<string, unknown> | undefined
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function createCreatedRowRecovery(
|
|
140
|
-
fieldName: string,
|
|
141
|
-
preExistingIds: Set<string>,
|
|
142
|
-
): CreatedRowRecovery {
|
|
143
|
-
let cache: { source: Record<string, unknown>; rows: Array<Record<string, unknown>> } | undefined
|
|
144
|
-
return {
|
|
145
|
-
rowAt(parentResult, index) {
|
|
146
|
-
if (!cache || cache.source !== parentResult) {
|
|
147
|
-
cache = {
|
|
148
|
-
source: parentResult,
|
|
149
|
-
rows: recoverCreatedRows(parentResult, fieldName, preExistingIds),
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return cache.rows[index]
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Capture the ids of the rows currently linked to the parent via `fieldName`,
|
|
159
|
-
* BEFORE the parent persists, so created rows can later be identified by id-diff.
|
|
160
|
-
* Empty for a parent CREATE (no parent row exists yet to have related rows).
|
|
161
|
-
*
|
|
162
|
-
* `prisma` must be the transaction client — the read has to participate in the
|
|
163
|
-
* transaction to see a consistent snapshot.
|
|
164
|
-
*/
|
|
165
|
-
async function capturePreExistingIds(
|
|
166
|
-
parentListName: string,
|
|
167
|
-
parentOriginalItem: Record<string, unknown> | undefined,
|
|
168
|
-
fieldName: string,
|
|
169
|
-
prisma: unknown,
|
|
170
|
-
): Promise<Set<string>> {
|
|
171
|
-
const ids = new Set<string>()
|
|
172
|
-
const parentId = parentOriginalItem?.id
|
|
173
|
-
if (typeof parentId !== 'string') {
|
|
174
|
-
// Parent create (no existing row) — nothing pre-exists.
|
|
175
|
-
return ids
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
180
|
-
const parentModel = (prisma as any)[getDbKey(parentListName)]
|
|
181
|
-
if (!parentModel?.findUnique) return ids
|
|
182
|
-
|
|
183
|
-
const current = await parentModel.findUnique({
|
|
184
|
-
where: { id: parentId },
|
|
185
|
-
include: { [fieldName]: true },
|
|
186
|
-
})
|
|
187
|
-
for (const row of includedRows((current ?? {}) as Record<string, unknown>, fieldName)) {
|
|
188
|
-
if (typeof row.id === 'string') ids.add(row.id)
|
|
189
|
-
}
|
|
190
|
-
return ids
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Process nested create operations: run the target list's full input pipeline
|
|
195
|
-
* and `beforeOperation`, then register an `afterOperation` task keyed to the
|
|
196
|
-
* parent's included relation.
|
|
197
|
-
*/
|
|
198
|
-
async function processNestedCreate(
|
|
199
|
-
items: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
200
|
-
fieldName: string,
|
|
201
|
-
relatedListName: string,
|
|
202
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
203
|
-
relatedListConfig: ListConfig<any>,
|
|
204
|
-
context: StackContext,
|
|
205
|
-
config: OpenSaasConfig,
|
|
206
|
-
prisma: unknown,
|
|
207
|
-
afterTasks: AfterTask[],
|
|
208
|
-
recovery: CreatedRowRecovery,
|
|
209
|
-
): Promise<Record<string, unknown> | Array<Record<string, unknown>>> {
|
|
210
|
-
const itemsArray = Array.isArray(items) ? items : [items]
|
|
211
|
-
|
|
212
|
-
const processedItems = await Promise.all(
|
|
213
|
-
itemsArray.map(async (item, index) => {
|
|
214
|
-
if (!context._isSudo) {
|
|
215
|
-
const createAccess = relatedListConfig.access?.operation?.create
|
|
216
|
-
const allowed = await checkCreateAccess(relatedListName, createAccess, {
|
|
217
|
-
session: context.session,
|
|
218
|
-
context,
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
if (!allowed) {
|
|
222
|
-
throw new Error('Access denied: Cannot create related item')
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let resolvedData = await executeResolveInput(relatedListConfig.hooks, {
|
|
227
|
-
listKey: relatedListName,
|
|
228
|
-
operation: 'create',
|
|
229
|
-
inputData: item,
|
|
230
|
-
resolvedData: item,
|
|
231
|
-
item: undefined,
|
|
232
|
-
context,
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
resolvedData = await executeFieldResolveInputHooks(
|
|
236
|
-
item,
|
|
237
|
-
resolvedData,
|
|
238
|
-
relatedListConfig.fields,
|
|
239
|
-
'create',
|
|
240
|
-
context,
|
|
241
|
-
relatedListName,
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
// Apply field defaults to omitted inputs (resolve-then-validate, #615) so
|
|
245
|
-
// a nested required-with-default field resolves before `isRequired` runs,
|
|
246
|
-
// mirroring the top-level pipeline. Create-only.
|
|
247
|
-
resolvedData = applyCreateDefaults(resolvedData, relatedListConfig.fields)
|
|
248
|
-
|
|
249
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
250
|
-
listKey: relatedListName,
|
|
251
|
-
operation: 'create',
|
|
252
|
-
inputData: item,
|
|
253
|
-
resolvedData,
|
|
254
|
-
item: undefined,
|
|
255
|
-
context,
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
await executeFieldValidateHooks(
|
|
259
|
-
item,
|
|
260
|
-
resolvedData,
|
|
261
|
-
relatedListConfig.fields,
|
|
262
|
-
'create',
|
|
263
|
-
context,
|
|
264
|
-
relatedListName,
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
const validation = validateFieldRules(resolvedData, relatedListConfig.fields, 'create')
|
|
268
|
-
if (validation.errors.length > 0) {
|
|
269
|
-
throw new ValidationError(validation.errors, validation.fieldErrors)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Split multi-column fields into physical columns (#789) — must run after
|
|
273
|
-
// validation, which operates on the logical (pre-split) value.
|
|
274
|
-
resolvedData = await splitMultiColumnFields(
|
|
275
|
-
item,
|
|
276
|
-
resolvedData,
|
|
277
|
-
relatedListConfig.fields,
|
|
278
|
-
'create',
|
|
279
|
-
context,
|
|
280
|
-
)
|
|
281
|
-
|
|
282
|
-
const filtered = await filterWritableFields(
|
|
283
|
-
resolvedData,
|
|
284
|
-
relatedListConfig.fields,
|
|
285
|
-
'create',
|
|
286
|
-
{
|
|
287
|
-
session: context.session,
|
|
288
|
-
context,
|
|
289
|
-
inputData: item,
|
|
290
|
-
listName: relatedListName,
|
|
291
|
-
config,
|
|
292
|
-
},
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
// This nested row is itself being created, so it has no pre-existing
|
|
296
|
-
// related rows of its own (parent originalItem is undefined below).
|
|
297
|
-
const { data: nestedData, afterTasks: childAfterTasks } = await processNestedOperations(
|
|
298
|
-
filtered,
|
|
299
|
-
relatedListConfig.fields,
|
|
300
|
-
config,
|
|
301
|
-
{ ...context, prisma },
|
|
302
|
-
'create',
|
|
303
|
-
relatedListName,
|
|
304
|
-
undefined,
|
|
305
|
-
// Its own create payload is the enclosing inputData for the connect-site
|
|
306
|
-
// owning-field gate (#588).
|
|
307
|
-
item,
|
|
308
|
-
)
|
|
309
|
-
|
|
310
|
-
await executeFieldBeforeOperationHooks(
|
|
311
|
-
item,
|
|
312
|
-
resolvedData,
|
|
313
|
-
relatedListConfig.fields,
|
|
314
|
-
'create',
|
|
315
|
-
context,
|
|
316
|
-
relatedListName,
|
|
317
|
-
)
|
|
318
|
-
|
|
319
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
320
|
-
listKey: relatedListName,
|
|
321
|
-
operation: 'create',
|
|
322
|
-
inputData: item,
|
|
323
|
-
resolvedData,
|
|
324
|
-
context,
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
// Fires once the parent has persisted. The row is recovered by id-diff and
|
|
328
|
-
// paired to THIS entry by position (see CreatedRowRecovery), so a to-many
|
|
329
|
-
// `create: [{A},{B}]` fires once per row against its own distinct row.
|
|
330
|
-
afterTasks.push({
|
|
331
|
-
fieldName,
|
|
332
|
-
run: async (parentResult) => {
|
|
333
|
-
const createdItem = recovery.rowAt(parentResult, index)
|
|
334
|
-
if (!createdItem) {
|
|
335
|
-
// Could not identify the created row by id-diff — the parent write
|
|
336
|
-
// didn't echo this nested relation (e.g. a client/mock that doesn't
|
|
337
|
-
// honour `include`; real Prisma always does). Deliberately SKIP this
|
|
338
|
-
// record's `afterOperation` rather than fabricate an id-less item —
|
|
339
|
-
// `item` correctness is the must-have, so a missing row is never faked.
|
|
340
|
-
return
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
344
|
-
listKey: relatedListName,
|
|
345
|
-
operation: 'create',
|
|
346
|
-
inputData: item,
|
|
347
|
-
item: createdItem,
|
|
348
|
-
resolvedData,
|
|
349
|
-
context,
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
await executeFieldAfterOperationHooks(
|
|
353
|
-
createdItem,
|
|
354
|
-
item,
|
|
355
|
-
resolvedData,
|
|
356
|
-
relatedListConfig.fields,
|
|
357
|
-
'create',
|
|
358
|
-
context,
|
|
359
|
-
relatedListName,
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
await runAfterTasks(childAfterTasks, createdItem)
|
|
363
|
-
},
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
return nestedData
|
|
367
|
-
}),
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
return Array.isArray(items) ? processedItems : processedItems[0]
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Verify that a single connection target is reachable for the caller.
|
|
375
|
-
*
|
|
376
|
-
* Connecting references an existing row rather than modifying it, so — mirroring
|
|
377
|
-
* Keystone — it requires **read/query** access on the target (#578), not update.
|
|
378
|
-
* A filter-result query access is evaluated in the DATABASE via
|
|
379
|
-
* `findFirst({ where: { AND: [connection, accessFilter] } })` rather than in
|
|
380
|
-
* memory, so it correctly handles arbitrary nested-relation predicates and
|
|
381
|
-
* boolean combinators; a non-existent id is folded into the same check.
|
|
382
|
-
*
|
|
383
|
-
* In ADDITION, the OWNING relationship field's field-level access (e.g.
|
|
384
|
-
* `Post.author`'s `create`/`update` access) must permit the connect (#588) —
|
|
385
|
-
* the other half Keystone requires: read access on the target AND write access
|
|
386
|
-
* on the owning field. A deny here denies the connect even when the target row
|
|
387
|
-
* is readable/reachable.
|
|
388
|
-
*
|
|
389
|
-
* Sudo bypasses the entire check (handled by the caller).
|
|
390
|
-
*/
|
|
391
|
-
async function verifyConnectReachable(
|
|
392
|
-
connection: Record<string, unknown>,
|
|
393
|
-
relatedListName: string,
|
|
394
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
395
|
-
relatedListConfig: ListConfig<any>,
|
|
396
|
-
context: StackContext,
|
|
397
|
-
prisma: unknown,
|
|
398
|
-
owningFieldAccess: FieldAccess | undefined,
|
|
399
|
-
enclosingOperation: 'create' | 'update',
|
|
400
|
-
enclosingItem: Record<string, unknown> | undefined,
|
|
401
|
-
enclosingInputData: Record<string, unknown> | undefined,
|
|
402
|
-
): Promise<void> {
|
|
403
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
404
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
405
|
-
const model = (prisma as any)[getDbKey(relatedListName)]
|
|
406
|
-
|
|
407
|
-
// #588 owning-field gate (see docblock above). `item`/`inputData` are the
|
|
408
|
-
// ENCLOSING write's `originalItem`/`inputData` — the same values the canonical
|
|
409
|
-
// Phase-5 `filterWritableFields` call passes for this field — so an
|
|
410
|
-
// item-/inputData-dependent field-access rule can't diverge between the two gates.
|
|
411
|
-
const owningFieldAllowed = await checkFieldAccess(owningFieldAccess, enclosingOperation, {
|
|
412
|
-
session: context.session,
|
|
413
|
-
item: enclosingItem,
|
|
414
|
-
inputData: enclosingInputData,
|
|
415
|
-
context,
|
|
416
|
-
})
|
|
417
|
-
if (!owningFieldAllowed) {
|
|
418
|
-
throw new Error('Access denied: Cannot connect to this item')
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const queryAccess = relatedListConfig.access?.operation?.query
|
|
422
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
423
|
-
session: context.session,
|
|
424
|
-
context,
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
if (accessResult === false) {
|
|
428
|
-
throw new Error('Access denied: Cannot connect to this item')
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Full access still verifies the row exists, to keep "Item not found" behaviour.
|
|
432
|
-
if (accessResult === true) {
|
|
433
|
-
const item = await model.findUnique({ where: connection })
|
|
434
|
-
if (!item) {
|
|
435
|
-
throw new Error(`Cannot connect: Item not found`)
|
|
436
|
-
}
|
|
437
|
-
return
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Filter result: reachable iff AND-combining the connection with the filter
|
|
441
|
-
// returns a row (see docblock above).
|
|
442
|
-
const reachable = await model.findFirst({
|
|
443
|
-
where: { AND: [connection, accessResult] },
|
|
444
|
-
})
|
|
445
|
-
|
|
446
|
-
if (!reachable) {
|
|
447
|
-
throw new Error('Access denied: Cannot connect to this item')
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Process nested connect operations.
|
|
453
|
-
* Verifies read (query) access to the items being connected via DB reachability
|
|
454
|
-
* AND the owning relationship field's field-level access (#588).
|
|
455
|
-
*/
|
|
456
|
-
async function processNestedConnect(
|
|
457
|
-
connections: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
458
|
-
relatedListName: string,
|
|
459
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
460
|
-
relatedListConfig: ListConfig<any>,
|
|
461
|
-
context: StackContext,
|
|
462
|
-
prisma: unknown,
|
|
463
|
-
owningFieldAccess: FieldAccess | undefined,
|
|
464
|
-
enclosingOperation: 'create' | 'update',
|
|
465
|
-
enclosingItem: Record<string, unknown> | undefined,
|
|
466
|
-
enclosingInputData: Record<string, unknown> | undefined,
|
|
467
|
-
): Promise<Record<string, unknown> | Array<Record<string, unknown>>> {
|
|
468
|
-
const connectionsArray = Array.isArray(connections) ? connections : [connections]
|
|
469
|
-
|
|
470
|
-
if (!context._isSudo) {
|
|
471
|
-
for (const connection of connectionsArray) {
|
|
472
|
-
await verifyConnectReachable(
|
|
473
|
-
connection,
|
|
474
|
-
relatedListName,
|
|
475
|
-
relatedListConfig,
|
|
476
|
-
context,
|
|
477
|
-
prisma,
|
|
478
|
-
owningFieldAccess,
|
|
479
|
-
enclosingOperation,
|
|
480
|
-
enclosingItem,
|
|
481
|
-
enclosingInputData,
|
|
482
|
-
)
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
return connections
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Re-check a nested update/delete access result against the target row,
|
|
491
|
-
* mirroring the Write Pipeline's `resolveExistingTarget` (#1081): `false`
|
|
492
|
-
* denies, `true` allows outright (the row's existence is already established
|
|
493
|
-
* by the caller's own `findUnique`), and a returned PrismaFilter must
|
|
494
|
-
* additionally match the row, re-checked in the DATABASE via
|
|
495
|
-
* `findFirst(mergeFilters(where, accessResult))` rather than in memory — the
|
|
496
|
-
* same requirement `connect`'s reachability check already applies (#578), so
|
|
497
|
-
* nested-relation predicates and boolean combinators are honoured correctly.
|
|
498
|
-
*/
|
|
499
|
-
async function isExistingTargetAccessible(
|
|
500
|
-
model: { findFirst: (args: { where: Record<string, unknown> }) => Promise<unknown> },
|
|
501
|
-
where: Record<string, unknown>,
|
|
502
|
-
accessResult: boolean | PrismaFilter,
|
|
503
|
-
): Promise<boolean> {
|
|
504
|
-
if (accessResult === false) return false
|
|
505
|
-
if (accessResult === true) return true
|
|
506
|
-
|
|
507
|
-
const matchesFilter = await model.findFirst({ where: mergeFilters(where, accessResult) ?? {} })
|
|
508
|
-
return matchesFilter !== null
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Process nested update operations.
|
|
513
|
-
*
|
|
514
|
-
* Runs the target list's full update input pipeline AND its `beforeOperation`,
|
|
515
|
-
* then registers an `afterOperation` task receiving `originalItem` (the row
|
|
516
|
-
* fetched before the write) and the persisted updated `item`.
|
|
517
|
-
*/
|
|
518
|
-
async function processNestedUpdate(
|
|
519
|
-
updates: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
520
|
-
fieldName: string,
|
|
521
|
-
relatedListName: string,
|
|
522
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
523
|
-
relatedListConfig: ListConfig<any>,
|
|
524
|
-
context: StackContext,
|
|
525
|
-
config: OpenSaasConfig,
|
|
526
|
-
prisma: unknown,
|
|
527
|
-
afterTasks: AfterTask[],
|
|
528
|
-
): Promise<Record<string, unknown> | Array<Record<string, unknown>>> {
|
|
529
|
-
const updatesArray = Array.isArray(updates) ? updates : [updates]
|
|
530
|
-
|
|
531
|
-
const processedUpdates = await Promise.all(
|
|
532
|
-
updatesArray.map(async (update) => {
|
|
533
|
-
// Access Prisma model dynamically - required because model names are generated at runtime
|
|
534
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
535
|
-
const model = (prisma as any)[getDbKey(relatedListName)]
|
|
536
|
-
|
|
537
|
-
const where = (update as Record<string, unknown>).where as Record<string, unknown>
|
|
538
|
-
|
|
539
|
-
// Fetched here and reused as `originalItem` for afterOperation.
|
|
540
|
-
const originalItem = await model.findUnique({ where })
|
|
541
|
-
|
|
542
|
-
if (!originalItem) {
|
|
543
|
-
throw new Error('Cannot update: Item not found')
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const knownId = typeof originalItem.id === 'string' ? (originalItem.id as string) : undefined
|
|
547
|
-
|
|
548
|
-
if (!context._isSudo) {
|
|
549
|
-
const updateAccess = relatedListConfig.access?.operation?.update
|
|
550
|
-
const accessResult = await checkAccess(updateAccess, {
|
|
551
|
-
session: context.session,
|
|
552
|
-
item: originalItem,
|
|
553
|
-
context,
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
if (!(await isExistingTargetAccessible(model, where, accessResult))) {
|
|
557
|
-
throw new Error('Access denied: Cannot update related item')
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const updateData = (update as Record<string, unknown>).data as Record<string, unknown>
|
|
562
|
-
let resolvedData = await executeResolveInput(relatedListConfig.hooks, {
|
|
563
|
-
listKey: relatedListName,
|
|
564
|
-
operation: 'update',
|
|
565
|
-
inputData: updateData,
|
|
566
|
-
resolvedData: updateData,
|
|
567
|
-
item: originalItem,
|
|
568
|
-
context,
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
resolvedData = await executeFieldResolveInputHooks(
|
|
572
|
-
updateData,
|
|
573
|
-
resolvedData,
|
|
574
|
-
relatedListConfig.fields,
|
|
575
|
-
'update',
|
|
576
|
-
context,
|
|
577
|
-
relatedListName,
|
|
578
|
-
originalItem,
|
|
579
|
-
)
|
|
580
|
-
|
|
581
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
582
|
-
listKey: relatedListName,
|
|
583
|
-
operation: 'update',
|
|
584
|
-
inputData: updateData,
|
|
585
|
-
resolvedData,
|
|
586
|
-
item: originalItem,
|
|
587
|
-
context,
|
|
588
|
-
})
|
|
589
|
-
|
|
590
|
-
await executeFieldValidateHooks(
|
|
591
|
-
updateData,
|
|
592
|
-
resolvedData,
|
|
593
|
-
relatedListConfig.fields,
|
|
594
|
-
'update',
|
|
595
|
-
context,
|
|
596
|
-
relatedListName,
|
|
597
|
-
originalItem,
|
|
598
|
-
)
|
|
599
|
-
|
|
600
|
-
const validation = validateFieldRules(resolvedData, relatedListConfig.fields, 'update')
|
|
601
|
-
if (validation.errors.length > 0) {
|
|
602
|
-
throw new ValidationError(validation.errors, validation.fieldErrors)
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// Split multi-column fields into physical columns (#789) — must run after
|
|
606
|
-
// validation, which operates on the logical (pre-split) value.
|
|
607
|
-
resolvedData = await splitMultiColumnFields(
|
|
608
|
-
updateData,
|
|
609
|
-
resolvedData,
|
|
610
|
-
relatedListConfig.fields,
|
|
611
|
-
'update',
|
|
612
|
-
context,
|
|
613
|
-
originalItem,
|
|
614
|
-
)
|
|
615
|
-
|
|
616
|
-
const filtered = await filterWritableFields(
|
|
617
|
-
resolvedData,
|
|
618
|
-
relatedListConfig.fields,
|
|
619
|
-
'update',
|
|
620
|
-
{
|
|
621
|
-
session: context.session,
|
|
622
|
-
item: originalItem,
|
|
623
|
-
context,
|
|
624
|
-
inputData: updateData,
|
|
625
|
-
listName: relatedListName,
|
|
626
|
-
config,
|
|
627
|
-
},
|
|
628
|
-
)
|
|
629
|
-
|
|
630
|
-
// This nested row is being updated, so its own relations' pre-existing
|
|
631
|
-
// rows are captured from `originalItem` below.
|
|
632
|
-
const { data: nestedData, afterTasks: childAfterTasks } = await processNestedOperations(
|
|
633
|
-
filtered,
|
|
634
|
-
relatedListConfig.fields,
|
|
635
|
-
config,
|
|
636
|
-
{ ...context, prisma },
|
|
637
|
-
'update',
|
|
638
|
-
relatedListName,
|
|
639
|
-
originalItem,
|
|
640
|
-
// Its own update payload is the enclosing inputData for the connect-site
|
|
641
|
-
// owning-field gate (#588).
|
|
642
|
-
updateData,
|
|
643
|
-
)
|
|
644
|
-
|
|
645
|
-
await executeFieldBeforeOperationHooks(
|
|
646
|
-
updateData,
|
|
647
|
-
resolvedData,
|
|
648
|
-
relatedListConfig.fields,
|
|
649
|
-
'update',
|
|
650
|
-
context,
|
|
651
|
-
relatedListName,
|
|
652
|
-
originalItem,
|
|
653
|
-
)
|
|
654
|
-
|
|
655
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
656
|
-
listKey: relatedListName,
|
|
657
|
-
operation: 'update',
|
|
658
|
-
inputData: updateData,
|
|
659
|
-
item: originalItem,
|
|
660
|
-
resolvedData,
|
|
661
|
-
context,
|
|
662
|
-
})
|
|
663
|
-
|
|
664
|
-
// Fires after the parent persist; the row is recovered by its known id.
|
|
665
|
-
afterTasks.push({
|
|
666
|
-
fieldName,
|
|
667
|
-
run: async (parentResult) => {
|
|
668
|
-
const persisted = recoverUpdatedRow(parentResult, fieldName, knownId)
|
|
669
|
-
const updatedItem = persisted ?? originalItem
|
|
670
|
-
|
|
671
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
672
|
-
listKey: relatedListName,
|
|
673
|
-
operation: 'update',
|
|
674
|
-
inputData: updateData,
|
|
675
|
-
originalItem,
|
|
676
|
-
item: updatedItem,
|
|
677
|
-
resolvedData,
|
|
678
|
-
context,
|
|
679
|
-
})
|
|
680
|
-
|
|
681
|
-
await executeFieldAfterOperationHooks(
|
|
682
|
-
updatedItem,
|
|
683
|
-
updateData,
|
|
684
|
-
resolvedData,
|
|
685
|
-
relatedListConfig.fields,
|
|
686
|
-
'update',
|
|
687
|
-
context,
|
|
688
|
-
relatedListName,
|
|
689
|
-
originalItem,
|
|
690
|
-
)
|
|
691
|
-
|
|
692
|
-
await runAfterTasks(childAfterTasks, updatedItem)
|
|
693
|
-
},
|
|
694
|
-
})
|
|
695
|
-
|
|
696
|
-
return {
|
|
697
|
-
where,
|
|
698
|
-
data: nestedData,
|
|
699
|
-
}
|
|
700
|
-
}),
|
|
701
|
-
)
|
|
702
|
-
|
|
703
|
-
return Array.isArray(updates) ? processedUpdates : processedUpdates[0]
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Process nested delete operations.
|
|
708
|
-
*
|
|
709
|
-
* Runs the target list's delete pipeline (validate/field-validate +
|
|
710
|
-
* `beforeOperation`) before the parent persist, and registers an
|
|
711
|
-
* `afterOperation` task receiving the `originalItem` (the row before deletion).
|
|
712
|
-
* Persistence is performed by Prisma's nested write; the row no longer exists
|
|
713
|
-
* after, so `originalItem` is the authoritative record for after-hooks.
|
|
714
|
-
*/
|
|
715
|
-
async function processNestedDelete(
|
|
716
|
-
deletes: Record<string, unknown> | Array<Record<string, unknown>> | boolean,
|
|
717
|
-
relatedListName: string,
|
|
718
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
719
|
-
relatedListConfig: ListConfig<any>,
|
|
720
|
-
context: StackContext,
|
|
721
|
-
prisma: unknown,
|
|
722
|
-
afterTasks: AfterTask[],
|
|
723
|
-
): Promise<Record<string, unknown> | Array<Record<string, unknown>> | boolean> {
|
|
724
|
-
// A to-one relation delete can be a boolean (`{ delete: true }`); there is no
|
|
725
|
-
// identifying `where`, so we cannot run target-resolved hooks. Pass through.
|
|
726
|
-
if (typeof deletes === 'boolean') {
|
|
727
|
-
return deletes
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
const deletesArray = Array.isArray(deletes) ? deletes : [deletes]
|
|
731
|
-
|
|
732
|
-
await Promise.all(
|
|
733
|
-
deletesArray.map(async (del) => {
|
|
734
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
735
|
-
const model = (prisma as any)[getDbKey(relatedListName)]
|
|
736
|
-
|
|
737
|
-
// A nested delete entry is itself the unique `where` (e.g. `{ id }`).
|
|
738
|
-
const where = del as Record<string, unknown>
|
|
739
|
-
|
|
740
|
-
const originalItem = await model.findUnique({ where })
|
|
741
|
-
if (!originalItem) {
|
|
742
|
-
throw new Error('Cannot delete: Item not found')
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (!context._isSudo) {
|
|
746
|
-
const deleteAccess = relatedListConfig.access?.operation?.delete
|
|
747
|
-
const accessResult = await checkAccess(deleteAccess, {
|
|
748
|
-
session: context.session,
|
|
749
|
-
item: originalItem,
|
|
750
|
-
context,
|
|
751
|
-
})
|
|
752
|
-
|
|
753
|
-
if (!(await isExistingTargetAccessible(model, where, accessResult))) {
|
|
754
|
-
throw new Error('Access denied: Cannot delete related item')
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
await executeValidate(relatedListConfig.hooks, {
|
|
759
|
-
listKey: relatedListName,
|
|
760
|
-
operation: 'delete',
|
|
761
|
-
item: originalItem,
|
|
762
|
-
context,
|
|
763
|
-
})
|
|
764
|
-
|
|
765
|
-
await executeFieldValidateHooks(
|
|
766
|
-
undefined,
|
|
767
|
-
undefined,
|
|
768
|
-
relatedListConfig.fields,
|
|
769
|
-
'delete',
|
|
770
|
-
context,
|
|
771
|
-
relatedListName,
|
|
772
|
-
originalItem,
|
|
773
|
-
)
|
|
774
|
-
|
|
775
|
-
await executeFieldBeforeOperationHooks(
|
|
776
|
-
{},
|
|
777
|
-
{},
|
|
778
|
-
relatedListConfig.fields,
|
|
779
|
-
'delete',
|
|
780
|
-
context,
|
|
781
|
-
relatedListName,
|
|
782
|
-
originalItem,
|
|
783
|
-
)
|
|
784
|
-
|
|
785
|
-
await executeBeforeOperation(relatedListConfig.hooks, {
|
|
786
|
-
listKey: relatedListName,
|
|
787
|
-
operation: 'delete',
|
|
788
|
-
item: originalItem,
|
|
789
|
-
context,
|
|
790
|
-
})
|
|
791
|
-
|
|
792
|
-
// The row is gone after persist, so originalItem is the authoritative
|
|
793
|
-
// record passed to the after-hooks below.
|
|
794
|
-
afterTasks.push({
|
|
795
|
-
fieldName: '',
|
|
796
|
-
run: async () => {
|
|
797
|
-
await executeAfterOperation(relatedListConfig.hooks, {
|
|
798
|
-
listKey: relatedListName,
|
|
799
|
-
operation: 'delete',
|
|
800
|
-
originalItem,
|
|
801
|
-
context,
|
|
802
|
-
})
|
|
803
|
-
|
|
804
|
-
await executeFieldAfterOperationHooks(
|
|
805
|
-
originalItem,
|
|
806
|
-
undefined,
|
|
807
|
-
undefined,
|
|
808
|
-
relatedListConfig.fields,
|
|
809
|
-
'delete',
|
|
810
|
-
context,
|
|
811
|
-
relatedListName,
|
|
812
|
-
originalItem,
|
|
813
|
-
)
|
|
814
|
-
},
|
|
815
|
-
})
|
|
816
|
-
}),
|
|
817
|
-
)
|
|
818
|
-
|
|
819
|
-
return deletes
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
async function processNestedConnectOrCreate(
|
|
823
|
-
operations: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
824
|
-
fieldName: string,
|
|
825
|
-
relatedListName: string,
|
|
826
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
827
|
-
relatedListConfig: ListConfig<any>,
|
|
828
|
-
context: StackContext,
|
|
829
|
-
config: OpenSaasConfig,
|
|
830
|
-
prisma: unknown,
|
|
831
|
-
afterTasks: AfterTask[],
|
|
832
|
-
recovery: CreatedRowRecovery,
|
|
833
|
-
owningFieldAccess: FieldAccess | undefined,
|
|
834
|
-
enclosingOperation: 'create' | 'update',
|
|
835
|
-
enclosingItem: Record<string, unknown> | undefined,
|
|
836
|
-
enclosingInputData: Record<string, unknown> | undefined,
|
|
837
|
-
): Promise<Record<string, unknown> | Array<Record<string, unknown>>> {
|
|
838
|
-
const operationsArray = Array.isArray(operations) ? operations : [operations]
|
|
839
|
-
|
|
840
|
-
const processedOps = await Promise.all(
|
|
841
|
-
operationsArray.map(async (op) => {
|
|
842
|
-
const opRecord = op as Record<string, unknown>
|
|
843
|
-
|
|
844
|
-
// When the target row exists, connectOrCreate applies the same connect
|
|
845
|
-
// semantics as processNestedConnect (read access + #588 owning-field gate,
|
|
846
|
-
// both evaluated via DB reachability); otherwise it falls through to
|
|
847
|
-
// create. An access-denied error must NOT be swallowed into that fallback
|
|
848
|
-
// — only a genuine "row absent" may fall back to create.
|
|
849
|
-
let rowExists = false
|
|
850
|
-
if (!context._isSudo) {
|
|
851
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
852
|
-
const model = (prisma as any)[getDbKey(relatedListName)]
|
|
853
|
-
const where = opRecord.where as Record<string, unknown>
|
|
854
|
-
|
|
855
|
-
const existingItem = await model.findUnique({ where })
|
|
856
|
-
|
|
857
|
-
if (existingItem) {
|
|
858
|
-
rowExists = true
|
|
859
|
-
|
|
860
|
-
const owningFieldAllowed = await checkFieldAccess(owningFieldAccess, enclosingOperation, {
|
|
861
|
-
session: context.session,
|
|
862
|
-
item: enclosingItem,
|
|
863
|
-
inputData: enclosingInputData,
|
|
864
|
-
context,
|
|
865
|
-
})
|
|
866
|
-
if (!owningFieldAllowed) {
|
|
867
|
-
throw new Error('Access denied: Cannot connect to existing item')
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
const queryAccess = relatedListConfig.access?.operation?.query
|
|
871
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
872
|
-
session: context.session,
|
|
873
|
-
item: existingItem,
|
|
874
|
-
context,
|
|
875
|
-
})
|
|
876
|
-
|
|
877
|
-
if (accessResult === false) {
|
|
878
|
-
throw new Error('Access denied: Cannot connect to existing item')
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
if (accessResult !== true) {
|
|
882
|
-
const reachable = await model.findFirst({
|
|
883
|
-
where: { AND: [where, accessResult] },
|
|
884
|
-
})
|
|
885
|
-
|
|
886
|
-
if (!reachable) {
|
|
887
|
-
throw new Error('Access denied: Cannot connect to existing item')
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
// Only register an afterOperation task when the create branch will
|
|
894
|
-
// actually run (row absent), so a pure connect doesn't fire create hooks.
|
|
895
|
-
// Under sudo we can't tell statically, so the create pipeline always runs
|
|
896
|
-
// its hooks there (sudo bypasses access only, not hooks).
|
|
897
|
-
const runCreateHooks = context._isSudo || !rowExists
|
|
898
|
-
const createAfterTasks: AfterTask[] = runCreateHooks ? afterTasks : []
|
|
899
|
-
const processedCreate = await processNestedCreate(
|
|
900
|
-
opRecord.create as Record<string, unknown> | Array<Record<string, unknown>>,
|
|
901
|
-
fieldName,
|
|
902
|
-
relatedListName,
|
|
903
|
-
relatedListConfig,
|
|
904
|
-
context,
|
|
905
|
-
config,
|
|
906
|
-
prisma,
|
|
907
|
-
createAfterTasks,
|
|
908
|
-
recovery,
|
|
909
|
-
)
|
|
910
|
-
|
|
911
|
-
return {
|
|
912
|
-
where: opRecord.where,
|
|
913
|
-
create: processedCreate,
|
|
914
|
-
}
|
|
915
|
-
}),
|
|
916
|
-
)
|
|
917
|
-
|
|
918
|
-
return Array.isArray(operations) ? processedOps : processedOps[0]
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* Arguments passed to every nested-operation handler.
|
|
923
|
-
*/
|
|
924
|
-
interface NestedOpHandlerArgs {
|
|
925
|
-
/** Raw payload supplied for this nested-op kind (e.g. the value of `value.create`). */
|
|
926
|
-
value: unknown
|
|
927
|
-
/** The owning relationship field name on the parent (for include read-back). */
|
|
928
|
-
fieldName: string
|
|
929
|
-
/** The list name of the related model (e.g. `'User'`). */
|
|
930
|
-
relatedListName: string
|
|
931
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
932
|
-
relatedListConfig: ListConfig<any>
|
|
933
|
-
/**
|
|
934
|
-
* Field-level `access` of the OWNING relationship field (e.g. `Post.author`).
|
|
935
|
-
* Gates connect/connectOrCreate by the owning field's create/update access —
|
|
936
|
-
* see the #588 gate in {@link verifyConnectReachable}.
|
|
937
|
-
*/
|
|
938
|
-
owningFieldAccess: FieldAccess | undefined
|
|
939
|
-
/** The enclosing write's operation, used as the owning-field gate's field-access operation. */
|
|
940
|
-
enclosingOperation: 'create' | 'update'
|
|
941
|
-
/**
|
|
942
|
-
* The enclosing write's `originalItem` (`undefined` for an enclosing create).
|
|
943
|
-
* Passed to the owning-field gate so it matches the canonical Phase-5
|
|
944
|
-
* `filterWritableFields` call and the two can't diverge (#588).
|
|
945
|
-
*/
|
|
946
|
-
enclosingItem: Record<string, unknown> | undefined
|
|
947
|
-
/** The enclosing write's input data, passed to the owning-field gate for the same reason as `enclosingItem`. */
|
|
948
|
-
enclosingInputData: Record<string, unknown> | undefined
|
|
949
|
-
context: StackContext
|
|
950
|
-
config: OpenSaasConfig
|
|
951
|
-
/** Prisma client used for dynamic model access during access checks. */
|
|
952
|
-
prisma: unknown
|
|
953
|
-
/** Collector for deferred nested `afterOperation` tasks. */
|
|
954
|
-
afterTasks: AfterTask[]
|
|
955
|
-
/**
|
|
956
|
-
* Recovery of the rows created on THIS field by id-diff (created kinds only —
|
|
957
|
-
* `create` and `connectOrCreate`'s create branch). Identifies each created row
|
|
958
|
-
* by excluding the ids that existed before the persist, and pairs them to the
|
|
959
|
-
* create-payload entries by position. Created lazily because it requires a
|
|
960
|
-
* pre-persist DB read; `undefined` for kinds that never create.
|
|
961
|
-
*/
|
|
962
|
-
recovery: CreatedRowRecovery | undefined
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* Narrow the lazily-built {@link CreatedRowRecovery} to a present value for the
|
|
967
|
-
* created kinds (`create`, `connectOrCreate`). It is always provided for these
|
|
968
|
-
* kinds by {@link processFieldNestedOps}; the guard backstops a programming
|
|
969
|
-
* error rather than a user-facing path.
|
|
970
|
-
*/
|
|
971
|
-
function requireRecovery(
|
|
972
|
-
recovery: CreatedRowRecovery | undefined,
|
|
973
|
-
kind: string,
|
|
974
|
-
): CreatedRowRecovery {
|
|
975
|
-
if (!recovery) {
|
|
976
|
-
throw new Error(`Internal error: missing created-row recovery for nested "${kind}"`)
|
|
977
|
-
}
|
|
978
|
-
return recovery
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
/** Nested-op kinds that can create new rows and so need created-row recovery. */
|
|
982
|
-
const CREATING_KINDS = new Set(['create', 'connectOrCreate'])
|
|
983
|
-
|
|
984
|
-
/**
|
|
985
|
-
* A nested-operation handler describes how a single nested-op kind
|
|
986
|
-
* (`create`, `connect`, …) is processed before it reaches Prisma.
|
|
987
|
-
*/
|
|
988
|
-
interface NestedOpHandler {
|
|
989
|
-
/** Produce the processed payload for this nested-op kind. */
|
|
990
|
-
execute(args: NestedOpHandlerArgs): Promise<unknown>
|
|
991
|
-
/**
|
|
992
|
-
* Whether this kind needs the parent write to `include` the relation so its
|
|
993
|
-
* persisted row can be read back for `afterOperation` (`create`/`update`).
|
|
994
|
-
*/
|
|
995
|
-
needsInclude: boolean
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
/**
|
|
999
|
-
* Registry of nested-operation handlers keyed by nested-op kind.
|
|
1000
|
-
*
|
|
1001
|
-
* Kinds that run the full hook pipeline (`create`, `update`, `delete`, and the
|
|
1002
|
-
* create branch of `connectOrCreate`) run `beforeOperation` inline and register
|
|
1003
|
-
* deferred `afterOperation` tasks. `connect`/`connectOrCreate`'s connect branch
|
|
1004
|
-
* enforce access only. Remaining pass-through kinds (`disconnect`, `set`,
|
|
1005
|
-
* `updateMany`, `deleteMany`) return their value unchanged so Prisma's own
|
|
1006
|
-
* constraints apply — they are intentionally NOT in scope for #569.
|
|
1007
|
-
*/
|
|
1008
|
-
const nestedOpRegistry: Record<string, NestedOpHandler> = {
|
|
1009
|
-
create: {
|
|
1010
|
-
needsInclude: true,
|
|
1011
|
-
execute: ({
|
|
1012
|
-
value,
|
|
1013
|
-
fieldName,
|
|
1014
|
-
relatedListName,
|
|
1015
|
-
relatedListConfig,
|
|
1016
|
-
context,
|
|
1017
|
-
config,
|
|
1018
|
-
prisma,
|
|
1019
|
-
afterTasks,
|
|
1020
|
-
recovery,
|
|
1021
|
-
}) =>
|
|
1022
|
-
processNestedCreate(
|
|
1023
|
-
value as Record<string, unknown> | Array<Record<string, unknown>>,
|
|
1024
|
-
fieldName,
|
|
1025
|
-
relatedListName,
|
|
1026
|
-
relatedListConfig,
|
|
1027
|
-
context,
|
|
1028
|
-
config,
|
|
1029
|
-
prisma,
|
|
1030
|
-
afterTasks,
|
|
1031
|
-
requireRecovery(recovery, 'create'),
|
|
1032
|
-
),
|
|
1033
|
-
},
|
|
1034
|
-
connect: {
|
|
1035
|
-
needsInclude: false,
|
|
1036
|
-
execute: ({
|
|
1037
|
-
value,
|
|
1038
|
-
relatedListName,
|
|
1039
|
-
relatedListConfig,
|
|
1040
|
-
context,
|
|
1041
|
-
prisma,
|
|
1042
|
-
owningFieldAccess,
|
|
1043
|
-
enclosingOperation,
|
|
1044
|
-
enclosingItem,
|
|
1045
|
-
enclosingInputData,
|
|
1046
|
-
}) =>
|
|
1047
|
-
processNestedConnect(
|
|
1048
|
-
value as Record<string, unknown> | Array<Record<string, unknown>>,
|
|
1049
|
-
relatedListName,
|
|
1050
|
-
relatedListConfig,
|
|
1051
|
-
context,
|
|
1052
|
-
prisma,
|
|
1053
|
-
owningFieldAccess,
|
|
1054
|
-
enclosingOperation,
|
|
1055
|
-
enclosingItem,
|
|
1056
|
-
enclosingInputData,
|
|
1057
|
-
),
|
|
1058
|
-
},
|
|
1059
|
-
connectOrCreate: {
|
|
1060
|
-
needsInclude: true,
|
|
1061
|
-
execute: ({
|
|
1062
|
-
value,
|
|
1063
|
-
fieldName,
|
|
1064
|
-
relatedListName,
|
|
1065
|
-
relatedListConfig,
|
|
1066
|
-
context,
|
|
1067
|
-
config,
|
|
1068
|
-
prisma,
|
|
1069
|
-
afterTasks,
|
|
1070
|
-
recovery,
|
|
1071
|
-
owningFieldAccess,
|
|
1072
|
-
enclosingOperation,
|
|
1073
|
-
enclosingItem,
|
|
1074
|
-
enclosingInputData,
|
|
1075
|
-
}) =>
|
|
1076
|
-
processNestedConnectOrCreate(
|
|
1077
|
-
value as Record<string, unknown> | Array<Record<string, unknown>>,
|
|
1078
|
-
fieldName,
|
|
1079
|
-
relatedListName,
|
|
1080
|
-
relatedListConfig,
|
|
1081
|
-
context,
|
|
1082
|
-
config,
|
|
1083
|
-
prisma,
|
|
1084
|
-
afterTasks,
|
|
1085
|
-
requireRecovery(recovery, 'connectOrCreate'),
|
|
1086
|
-
owningFieldAccess,
|
|
1087
|
-
enclosingOperation,
|
|
1088
|
-
enclosingItem,
|
|
1089
|
-
enclosingInputData,
|
|
1090
|
-
),
|
|
1091
|
-
},
|
|
1092
|
-
update: {
|
|
1093
|
-
needsInclude: true,
|
|
1094
|
-
execute: ({
|
|
1095
|
-
value,
|
|
1096
|
-
fieldName,
|
|
1097
|
-
relatedListName,
|
|
1098
|
-
relatedListConfig,
|
|
1099
|
-
context,
|
|
1100
|
-
config,
|
|
1101
|
-
prisma,
|
|
1102
|
-
afterTasks,
|
|
1103
|
-
}) =>
|
|
1104
|
-
processNestedUpdate(
|
|
1105
|
-
value as Record<string, unknown> | Array<Record<string, unknown>>,
|
|
1106
|
-
fieldName,
|
|
1107
|
-
relatedListName,
|
|
1108
|
-
relatedListConfig,
|
|
1109
|
-
context,
|
|
1110
|
-
config,
|
|
1111
|
-
prisma,
|
|
1112
|
-
afterTasks,
|
|
1113
|
-
),
|
|
1114
|
-
},
|
|
1115
|
-
delete: {
|
|
1116
|
-
// The row no longer exists after the parent write, so no read-back include.
|
|
1117
|
-
needsInclude: false,
|
|
1118
|
-
execute: ({ value, relatedListName, relatedListConfig, context, prisma, afterTasks }) =>
|
|
1119
|
-
processNestedDelete(
|
|
1120
|
-
value as Record<string, unknown> | Array<Record<string, unknown>> | boolean,
|
|
1121
|
-
relatedListName,
|
|
1122
|
-
relatedListConfig,
|
|
1123
|
-
context,
|
|
1124
|
-
prisma,
|
|
1125
|
-
afterTasks,
|
|
1126
|
-
),
|
|
1127
|
-
},
|
|
1128
|
-
// Pass-through kinds: no hooks/access control, left to Prisma's own constraints.
|
|
1129
|
-
// (Out of scope for #569 — see the issue's "Out of scope" notes.)
|
|
1130
|
-
disconnect: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
1131
|
-
deleteMany: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
1132
|
-
set: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
1133
|
-
updateMany: { needsInclude: false, execute: ({ value }) => Promise.resolve(value) },
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* Order in which nested-op kinds are processed for a single relationship field.
|
|
1138
|
-
*/
|
|
1139
|
-
const nestedOpOrder = [
|
|
1140
|
-
'create',
|
|
1141
|
-
'connect',
|
|
1142
|
-
'connectOrCreate',
|
|
1143
|
-
'update',
|
|
1144
|
-
'disconnect',
|
|
1145
|
-
'delete',
|
|
1146
|
-
'deleteMany',
|
|
1147
|
-
'set',
|
|
1148
|
-
'updateMany',
|
|
1149
|
-
] as const
|
|
1150
|
-
|
|
1151
|
-
/**
|
|
1152
|
-
* Process the nested relationship operations supplied for a single
|
|
1153
|
-
* relationship field's value, dispatching each present nested-op kind through
|
|
1154
|
-
* the {@link nestedOpRegistry}.
|
|
1155
|
-
*/
|
|
1156
|
-
async function processFieldNestedOps(
|
|
1157
|
-
fieldName: string,
|
|
1158
|
-
valueRecord: Record<string, unknown>,
|
|
1159
|
-
args: Omit<NestedOpHandlerArgs, 'value' | 'fieldName' | 'recovery'>,
|
|
1160
|
-
includeFields: Set<string>,
|
|
1161
|
-
parentListName: string,
|
|
1162
|
-
parentOriginalItem: Record<string, unknown> | undefined,
|
|
1163
|
-
): Promise<Record<string, unknown>> {
|
|
1164
|
-
const nestedOp: Record<string, unknown> = {}
|
|
1165
|
-
|
|
1166
|
-
// Created-row recovery is only needed when this field has a creating kind
|
|
1167
|
-
// (`create`/`connectOrCreate`). When present it requires a pre-persist read of
|
|
1168
|
-
// the parent's current related ids, so build it once, lazily, and share it
|
|
1169
|
-
// across the creating kinds on this field.
|
|
1170
|
-
let recovery: CreatedRowRecovery | undefined
|
|
1171
|
-
const hasCreatingKind = nestedOpOrder.some(
|
|
1172
|
-
(kind) => CREATING_KINDS.has(kind) && valueRecord[kind] !== undefined,
|
|
1173
|
-
)
|
|
1174
|
-
if (hasCreatingKind) {
|
|
1175
|
-
const preExistingIds = await capturePreExistingIds(
|
|
1176
|
-
parentListName,
|
|
1177
|
-
parentOriginalItem,
|
|
1178
|
-
fieldName,
|
|
1179
|
-
args.prisma,
|
|
1180
|
-
)
|
|
1181
|
-
recovery = createCreatedRowRecovery(fieldName, preExistingIds)
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
for (const kind of nestedOpOrder) {
|
|
1185
|
-
const value = valueRecord[kind]
|
|
1186
|
-
if (value === undefined) {
|
|
1187
|
-
continue
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
const handler = nestedOpRegistry[kind]
|
|
1191
|
-
if (handler.needsInclude) {
|
|
1192
|
-
includeFields.add(fieldName)
|
|
1193
|
-
}
|
|
1194
|
-
nestedOp[kind] = await handler.execute({
|
|
1195
|
-
...args,
|
|
1196
|
-
value,
|
|
1197
|
-
fieldName,
|
|
1198
|
-
recovery,
|
|
1199
|
-
})
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
return nestedOp
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* Process all nested operations in a data payload.
|
|
1207
|
-
*
|
|
1208
|
-
* Recursively handles relationship fields with nested writes. In addition to
|
|
1209
|
-
* transforming the payload it runs each nested record's `beforeOperation` and
|
|
1210
|
-
* collects deferred `afterOperation` tasks (run by the Write Pipeline after the
|
|
1211
|
-
* parent persist via {@link runAfterTasks}). See ADR-0010.
|
|
1212
|
-
*/
|
|
1213
|
-
export async function processNestedOperations(
|
|
1214
|
-
data: Record<string, unknown>,
|
|
1215
|
-
fieldConfigs: Record<string, FieldConfig>,
|
|
1216
|
-
config: OpenSaasConfig,
|
|
1217
|
-
context: StackContext & { prisma: unknown },
|
|
1218
|
-
operation: 'create' | 'update',
|
|
1219
|
-
parentListName: string,
|
|
1220
|
-
parentOriginalItem: Record<string, unknown> | undefined,
|
|
1221
|
-
// The enclosing write's inputData, for the #588 owning-field gate (see
|
|
1222
|
-
// verifyConnectReachable). `undefined` is tolerated (defaults to `{}`).
|
|
1223
|
-
parentInputData: Record<string, unknown> | undefined = undefined,
|
|
1224
|
-
): Promise<NestedOpsResult> {
|
|
1225
|
-
const afterTasks: AfterTask[] = []
|
|
1226
|
-
const includeFields = new Set<string>()
|
|
1227
|
-
|
|
1228
|
-
const processed: Record<string, unknown> = {}
|
|
1229
|
-
|
|
1230
|
-
for (const [fieldName, value] of Object.entries(data)) {
|
|
1231
|
-
if (value === null || value === undefined) {
|
|
1232
|
-
processed[fieldName] = value
|
|
1233
|
-
continue
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
const fieldConfig = fieldConfigs[fieldName]
|
|
1237
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
1238
|
-
let relatedListConfig: ListConfig<any>
|
|
1239
|
-
let resolvedListName: string
|
|
1240
|
-
let owningFieldAccess: FieldAccess | undefined
|
|
1241
|
-
|
|
1242
|
-
if (isRelationshipField(fieldConfig)) {
|
|
1243
|
-
const relationshipField = fieldConfig as { type: 'relationship'; ref: string }
|
|
1244
|
-
const relatedConfig = getRelatedListConfig(relationshipField.ref, config)
|
|
1245
|
-
if (!relatedConfig) {
|
|
1246
|
-
processed[fieldName] = value
|
|
1247
|
-
continue
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
const { listName: relatedListName, listConfig } = relatedConfig
|
|
1251
|
-
resolvedListName = relatedListName || findListName(listConfig, config)
|
|
1252
|
-
relatedListConfig = listConfig
|
|
1253
|
-
// The owning relationship field's field-level access, for the #588 gate
|
|
1254
|
-
// in verifyConnectReachable.
|
|
1255
|
-
owningFieldAccess = fieldConfig.access
|
|
1256
|
-
} else if (!fieldConfig) {
|
|
1257
|
-
// Not a field the parent's config declares — check whether it names the
|
|
1258
|
-
// synthetic back-relation a list-only `ref` generates on this list
|
|
1259
|
-
// (`from_<List>_<field>`, #978). Resolved, it is processed exactly like a
|
|
1260
|
-
// nested write through the declared field that owns it; unresolved, it
|
|
1261
|
-
// is left untouched. This is NOT solely a sudo path: a multi-column
|
|
1262
|
-
// field's raw per-part columns (e.g. `m_url`/`m_size`, #789) are ALSO
|
|
1263
|
-
// undeclared from this list's `fieldConfigs` perspective and reach here
|
|
1264
|
-
// on every write, sudo or not — `filterWritableFields` already
|
|
1265
|
-
// recognises and gates those via its own `splitColumnOwners` map before
|
|
1266
|
-
// its undeclared-key branch, and this function has no such map to tell
|
|
1267
|
-
// them apart from a genuinely-unrecognised key, so it must not throw
|
|
1268
|
-
// here. A genuinely unrecognised key under sudo is refused instead by
|
|
1269
|
-
// `filterWritableFields`'s own resolution attempt, one level up.
|
|
1270
|
-
const synthetic = resolveSyntheticReverseRelation(fieldName, parentListName, config)
|
|
1271
|
-
if (!synthetic) {
|
|
1272
|
-
processed[fieldName] = value
|
|
1273
|
-
continue
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
resolvedListName = synthetic.sourceListName
|
|
1277
|
-
relatedListConfig = synthetic.sourceListConfig
|
|
1278
|
-
// There is no parent-side field here (unlike the declared-relationship
|
|
1279
|
-
// branch above) — the FK-owning field genuinely IS the one the source
|
|
1280
|
-
// list declares, so its access is the owning-field gate.
|
|
1281
|
-
owningFieldAccess = synthetic.sourceFieldConfig.access
|
|
1282
|
-
} else {
|
|
1283
|
-
processed[fieldName] = value
|
|
1284
|
-
continue
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
processed[fieldName] = await processFieldNestedOps(
|
|
1288
|
-
fieldName,
|
|
1289
|
-
value as Record<string, unknown>,
|
|
1290
|
-
{
|
|
1291
|
-
relatedListName: resolvedListName,
|
|
1292
|
-
relatedListConfig,
|
|
1293
|
-
owningFieldAccess,
|
|
1294
|
-
enclosingOperation: operation,
|
|
1295
|
-
// Same values Phase-5 `filterWritableFields` passes for this field, so
|
|
1296
|
-
// the #588 owning-field gate can't diverge from it.
|
|
1297
|
-
enclosingItem: parentOriginalItem,
|
|
1298
|
-
enclosingInputData: parentInputData ?? {},
|
|
1299
|
-
context,
|
|
1300
|
-
config,
|
|
1301
|
-
prisma: context.prisma,
|
|
1302
|
-
afterTasks,
|
|
1303
|
-
},
|
|
1304
|
-
includeFields,
|
|
1305
|
-
parentListName,
|
|
1306
|
-
parentOriginalItem,
|
|
1307
|
-
)
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
return { data: processed, afterTasks, includeFields }
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
/**
|
|
1314
|
-
* Run a set of deferred nested `afterOperation` tasks against a persisted parent
|
|
1315
|
-
* row. Tasks run sequentially so a throwing after-hook aborts the rest (and, run
|
|
1316
|
-
* inside the transaction by the Write Pipeline, rolls the whole write back).
|
|
1317
|
-
*/
|
|
1318
|
-
export async function runAfterTasks(
|
|
1319
|
-
afterTasks: AfterTask[],
|
|
1320
|
-
parentResult: Record<string, unknown>,
|
|
1321
|
-
): Promise<void> {
|
|
1322
|
-
for (const task of afterTasks) {
|
|
1323
|
-
await task.run(parentResult)
|
|
1324
|
-
}
|
|
1325
|
-
}
|