@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,485 +0,0 @@
|
|
|
1
|
-
import type { OpenSaasConfig, ListConfig, FieldConfig } from '../config/types.js'
|
|
2
|
-
import type { AccessContext, PrismaClientLike } from '../access/types.js'
|
|
3
|
-
import { getRelatedListConfig } from '../access/index.js'
|
|
4
|
-
import {
|
|
5
|
-
executeBeforeTransaction,
|
|
6
|
-
executeAfterTransaction,
|
|
7
|
-
executeFieldBeforeTransactionHooks,
|
|
8
|
-
executeFieldAfterTransactionHooks,
|
|
9
|
-
type TransactionOutcome,
|
|
10
|
-
} from '../hooks/index.js'
|
|
11
|
-
import type { WriteOperation } from './write-pipeline.js'
|
|
12
|
-
import type {
|
|
13
|
-
TransactionRegistry,
|
|
14
|
-
TransactionSettleOutcome,
|
|
15
|
-
} from '../access/transaction-registry.js'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Transaction-boundary hooks (#590 / ADR-0010): `beforeTransaction`/`afterTransaction`
|
|
19
|
-
* bracket a write's `$transaction` from the outside, for non-transactional side
|
|
20
|
-
* effects. See ADR-0010 for the bracket's design and ADR-0028 for how a joined
|
|
21
|
-
* write's `afterTransaction` defers to the transaction owner.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* One list involved in a write, enumerated purely from the input tree (no DB
|
|
26
|
-
* reads). `item`/`originalItem` are populated only for the top-level record
|
|
27
|
-
* (`isTopLevel`) — a nested list's persisted row isn't reliably recoverable
|
|
28
|
-
* outside the transaction, so handing it the top-level row instead would be
|
|
29
|
-
* silently wrong.
|
|
30
|
-
*/
|
|
31
|
-
export interface InvolvedList {
|
|
32
|
-
listKey: string
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
34
|
-
listConfig: ListConfig<any>
|
|
35
|
-
operation: WriteOperation
|
|
36
|
-
isTopLevel: boolean
|
|
37
|
-
/** `undefined` for delete, which has no input payload. */
|
|
38
|
-
inputData: Record<string, unknown> | undefined
|
|
39
|
-
originalItem: Record<string, unknown> | undefined
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const NESTED_OP_OPERATIONS: ReadonlyArray<{ kind: string; operation: WriteOperation }> = [
|
|
43
|
-
{ kind: 'create', operation: 'create' },
|
|
44
|
-
{ kind: 'update', operation: 'update' },
|
|
45
|
-
{ kind: 'delete', operation: 'delete' },
|
|
46
|
-
// connectOrCreate's create branch may create; treat as a possible create involvement.
|
|
47
|
-
{ kind: 'connectOrCreate', operation: 'create' },
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
const DISTINCT_OPERATION_COUNT = new Set(NESTED_OP_OPERATIONS.map((o) => o.operation)).size
|
|
51
|
-
|
|
52
|
-
function isRelationshipField(fieldConfig: FieldConfig | undefined): boolean {
|
|
53
|
-
return fieldConfig?.type === 'relationship'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Distinct (listKey, operation) pairs reachable from `startListName` via the
|
|
58
|
-
* CONFIG's relationship graph (not the payload) — the saturation bound
|
|
59
|
-
* `walkNested` stops at once it has recorded this many. Bounding by reachable
|
|
60
|
-
* pairs rather than a depth cap (#835) avoids losing hooks for payloads
|
|
61
|
-
* nested deeper than any fixed cap, while still terminating promptly on
|
|
62
|
-
* payloads that repeat the same few lists.
|
|
63
|
-
*/
|
|
64
|
-
function countReachableInvolvementPairs(
|
|
65
|
-
startListName: string,
|
|
66
|
-
startListConfig: ListConfig<any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
67
|
-
config: OpenSaasConfig,
|
|
68
|
-
): number {
|
|
69
|
-
const visited = new Set<string>([startListName])
|
|
70
|
-
const queue: Array<ListConfig<any>> = [startListConfig] // eslint-disable-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
71
|
-
|
|
72
|
-
while (queue.length > 0) {
|
|
73
|
-
const current = queue.shift()!
|
|
74
|
-
for (const fieldConfig of Object.values(current.fields)) {
|
|
75
|
-
if (!isRelationshipField(fieldConfig)) continue
|
|
76
|
-
const relationshipField = fieldConfig as { type: 'relationship'; ref: string }
|
|
77
|
-
const related = getRelatedListConfig(relationshipField.ref, config)
|
|
78
|
-
if (!related || visited.has(related.listName)) continue
|
|
79
|
-
visited.add(related.listName)
|
|
80
|
-
queue.push(related.listConfig)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return visited.size * DISTINCT_OPERATION_COUNT
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function asRecordArray(value: unknown): Array<Record<string, unknown>> {
|
|
88
|
-
if (value == null) return []
|
|
89
|
-
if (Array.isArray(value)) return value.filter((v) => v && typeof v === 'object')
|
|
90
|
-
if (typeof value === 'object') return [value as Record<string, unknown>]
|
|
91
|
-
return []
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Extract a nested-op entry's create/update payload so its `beforeTransaction` receives meaningful `inputData`. */
|
|
95
|
-
function nestedInputData(
|
|
96
|
-
kind: string,
|
|
97
|
-
entry: Record<string, unknown>,
|
|
98
|
-
): Record<string, unknown> | undefined {
|
|
99
|
-
if (kind === 'update') {
|
|
100
|
-
const data = entry.data
|
|
101
|
-
return data && typeof data === 'object' ? (data as Record<string, unknown>) : undefined
|
|
102
|
-
}
|
|
103
|
-
if (kind === 'connectOrCreate') {
|
|
104
|
-
const create = entry.create
|
|
105
|
-
return create && typeof create === 'object' ? (create as Record<string, unknown>) : undefined
|
|
106
|
-
}
|
|
107
|
-
if (kind === 'delete') return undefined
|
|
108
|
-
// create
|
|
109
|
-
return entry
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Recursively walk a write payload's relationship fields, appending one
|
|
114
|
-
* {@link InvolvedList} per nested create/update/delete involvement. De-dups
|
|
115
|
-
* by (listKey, operation): these hooks are a per-LIST compensation bracket,
|
|
116
|
-
* not per-record, so a list with many nested records of the same operation
|
|
117
|
-
* fires its bracket once.
|
|
118
|
-
*/
|
|
119
|
-
function walkNested(
|
|
120
|
-
data: Record<string, unknown> | undefined,
|
|
121
|
-
fieldConfigs: Record<string, FieldConfig>,
|
|
122
|
-
config: OpenSaasConfig,
|
|
123
|
-
out: InvolvedList[],
|
|
124
|
-
seen: Set<string>,
|
|
125
|
-
maxPairs: number,
|
|
126
|
-
): void {
|
|
127
|
-
// Saturated: no further pair can be new (see countReachableInvolvementPairs).
|
|
128
|
-
if (!data || seen.size >= maxPairs) return
|
|
129
|
-
|
|
130
|
-
for (const [fieldName, value] of Object.entries(data)) {
|
|
131
|
-
const fieldConfig = fieldConfigs[fieldName]
|
|
132
|
-
if (!isRelationshipField(fieldConfig) || value == null || typeof value !== 'object') continue
|
|
133
|
-
|
|
134
|
-
const relationshipField = fieldConfig as { type: 'relationship'; ref: string }
|
|
135
|
-
const related = getRelatedListConfig(relationshipField.ref, config)
|
|
136
|
-
if (!related) continue
|
|
137
|
-
const { listName: relatedListName, listConfig: relatedListConfig } = related
|
|
138
|
-
|
|
139
|
-
const valueRecord = value as Record<string, unknown>
|
|
140
|
-
for (const { kind, operation } of NESTED_OP_OPERATIONS) {
|
|
141
|
-
const opValue = valueRecord[kind]
|
|
142
|
-
if (opValue === undefined) continue
|
|
143
|
-
|
|
144
|
-
const entries = asRecordArray(opValue)
|
|
145
|
-
const dedupeKey = `${relatedListName}:${operation}`
|
|
146
|
-
if (!seen.has(dedupeKey)) {
|
|
147
|
-
seen.add(dedupeKey)
|
|
148
|
-
out.push({
|
|
149
|
-
listKey: relatedListName,
|
|
150
|
-
listConfig: relatedListConfig,
|
|
151
|
-
operation,
|
|
152
|
-
isTopLevel: false,
|
|
153
|
-
inputData: entries.length > 0 ? nestedInputData(kind, entries[0]) : undefined,
|
|
154
|
-
originalItem: undefined,
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (seen.size >= maxPairs) return
|
|
159
|
-
|
|
160
|
-
for (const entry of entries) {
|
|
161
|
-
const childData = nestedInputData(kind, entry)
|
|
162
|
-
walkNested(childData, relatedListConfig.fields, config, out, seen, maxPairs)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Enumerate the lists involved in a write — the top-level list plus every
|
|
170
|
-
* nested create/update/delete target — without DB reads. The top-level list
|
|
171
|
-
* is always first.
|
|
172
|
-
*/
|
|
173
|
-
export function enumerateInvolvedLists(args: {
|
|
174
|
-
listName: string
|
|
175
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
176
|
-
listConfig: ListConfig<any>
|
|
177
|
-
operation: WriteOperation
|
|
178
|
-
inputData: Record<string, unknown> | undefined
|
|
179
|
-
/** Top-level existing row (update/delete), resolved before the transaction by the caller. */
|
|
180
|
-
topLevelOriginalItem: Record<string, unknown> | undefined
|
|
181
|
-
config: OpenSaasConfig
|
|
182
|
-
}): InvolvedList[] {
|
|
183
|
-
const { listName, listConfig, operation, inputData, topLevelOriginalItem, config } = args
|
|
184
|
-
|
|
185
|
-
const out: InvolvedList[] = [
|
|
186
|
-
{
|
|
187
|
-
listKey: listName,
|
|
188
|
-
listConfig,
|
|
189
|
-
operation,
|
|
190
|
-
isTopLevel: true,
|
|
191
|
-
inputData,
|
|
192
|
-
originalItem: topLevelOriginalItem,
|
|
193
|
-
},
|
|
194
|
-
]
|
|
195
|
-
const seen = new Set<string>([`${listName}:${operation}`])
|
|
196
|
-
const maxPairs = countReachableInvolvementPairs(listName, listConfig, config)
|
|
197
|
-
|
|
198
|
-
walkNested(inputData, listConfig.fields, config, out, seen, maxPairs)
|
|
199
|
-
|
|
200
|
-
return out
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** Runs one involved list's `beforeTransaction` hooks. A throw propagates to the caller (which aborts the write). */
|
|
204
|
-
async function runBeforeTransactionForList<TPrisma extends PrismaClientLike>(
|
|
205
|
-
involved: InvolvedList,
|
|
206
|
-
context: AccessContext<TPrisma>,
|
|
207
|
-
): Promise<void> {
|
|
208
|
-
const { listKey, listConfig, operation, inputData, originalItem } = involved
|
|
209
|
-
|
|
210
|
-
if (operation === 'create') {
|
|
211
|
-
await executeBeforeTransaction(listConfig.hooks, {
|
|
212
|
-
listKey,
|
|
213
|
-
operation: 'create',
|
|
214
|
-
inputData: inputData ?? {},
|
|
215
|
-
context,
|
|
216
|
-
})
|
|
217
|
-
} else if (operation === 'update') {
|
|
218
|
-
await executeBeforeTransaction(listConfig.hooks, {
|
|
219
|
-
listKey,
|
|
220
|
-
operation: 'update',
|
|
221
|
-
inputData: inputData ?? {},
|
|
222
|
-
item: originalItem,
|
|
223
|
-
context,
|
|
224
|
-
})
|
|
225
|
-
} else {
|
|
226
|
-
await executeBeforeTransaction(listConfig.hooks, {
|
|
227
|
-
listKey,
|
|
228
|
-
operation: 'delete',
|
|
229
|
-
item: originalItem,
|
|
230
|
-
context,
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
await executeFieldBeforeTransactionHooks(
|
|
235
|
-
inputData,
|
|
236
|
-
listConfig.fields,
|
|
237
|
-
operation,
|
|
238
|
-
context,
|
|
239
|
-
listKey,
|
|
240
|
-
originalItem,
|
|
241
|
-
)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Runs one involved list's `afterTransaction` hooks against the settled
|
|
246
|
-
* {@link TransactionOutcome}, collecting rather than throwing errors so the
|
|
247
|
-
* caller can keep running the remaining lists' compensators. Exported for
|
|
248
|
-
* {@link TransactionRegistry} to reuse when draining a deferred, joined
|
|
249
|
-
* write's bracket (ADR-0028).
|
|
250
|
-
*/
|
|
251
|
-
export async function runAfterTransactionForList<TPrisma extends PrismaClientLike>(
|
|
252
|
-
involved: InvolvedList,
|
|
253
|
-
outcome: TransactionOutcome,
|
|
254
|
-
context: AccessContext<TPrisma>,
|
|
255
|
-
errors: unknown[],
|
|
256
|
-
): Promise<void> {
|
|
257
|
-
const { listKey, listConfig, operation, isTopLevel, inputData, originalItem } = involved
|
|
258
|
-
|
|
259
|
-
// The persisted row (`outcome.item`) is the TOP-LEVEL row only. Handing it to
|
|
260
|
-
// a nested list's hook would silently mis-type as that list's own item — for
|
|
261
|
-
// nested lists `item`/`originalItem` stay `undefined`; per-record nested
|
|
262
|
-
// compensation belongs in the in-transaction `afterOperation`, which gets the
|
|
263
|
-
// correct row.
|
|
264
|
-
try {
|
|
265
|
-
if (outcome.status === 'committed') {
|
|
266
|
-
const committedItem = isTopLevel ? outcome.item : undefined
|
|
267
|
-
if (operation === 'create') {
|
|
268
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
269
|
-
listKey,
|
|
270
|
-
operation: 'create',
|
|
271
|
-
status: 'committed',
|
|
272
|
-
inputData: inputData ?? {},
|
|
273
|
-
item: committedItem,
|
|
274
|
-
context,
|
|
275
|
-
})
|
|
276
|
-
} else if (operation === 'update') {
|
|
277
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
278
|
-
listKey,
|
|
279
|
-
operation: 'update',
|
|
280
|
-
status: 'committed',
|
|
281
|
-
inputData: inputData ?? {},
|
|
282
|
-
originalItem: isTopLevel ? originalItem : undefined,
|
|
283
|
-
item: committedItem,
|
|
284
|
-
context,
|
|
285
|
-
})
|
|
286
|
-
} else {
|
|
287
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
288
|
-
listKey,
|
|
289
|
-
operation: 'delete',
|
|
290
|
-
status: 'committed',
|
|
291
|
-
originalItem: isTopLevel ? originalItem : undefined,
|
|
292
|
-
context,
|
|
293
|
-
})
|
|
294
|
-
}
|
|
295
|
-
} else {
|
|
296
|
-
if (operation === 'create') {
|
|
297
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
298
|
-
listKey,
|
|
299
|
-
operation: 'create',
|
|
300
|
-
status: 'rolled-back',
|
|
301
|
-
inputData: inputData ?? {},
|
|
302
|
-
error: outcome.error,
|
|
303
|
-
context,
|
|
304
|
-
})
|
|
305
|
-
} else if (operation === 'update') {
|
|
306
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
307
|
-
listKey,
|
|
308
|
-
operation: 'update',
|
|
309
|
-
status: 'rolled-back',
|
|
310
|
-
inputData: inputData ?? {},
|
|
311
|
-
originalItem,
|
|
312
|
-
error: outcome.error,
|
|
313
|
-
context,
|
|
314
|
-
})
|
|
315
|
-
} else {
|
|
316
|
-
await executeAfterTransaction(listConfig.hooks, {
|
|
317
|
-
listKey,
|
|
318
|
-
operation: 'delete',
|
|
319
|
-
status: 'rolled-back',
|
|
320
|
-
originalItem,
|
|
321
|
-
error: outcome.error,
|
|
322
|
-
context,
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
} catch (err) {
|
|
327
|
-
// A throwing afterTransaction must NOT stop the remaining compensators.
|
|
328
|
-
errors.push(err)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
await executeFieldAfterTransactionHooks(
|
|
333
|
-
outcome,
|
|
334
|
-
inputData,
|
|
335
|
-
listConfig.fields,
|
|
336
|
-
operation,
|
|
337
|
-
context,
|
|
338
|
-
listKey,
|
|
339
|
-
isTopLevel,
|
|
340
|
-
originalItem,
|
|
341
|
-
)
|
|
342
|
-
} catch (err) {
|
|
343
|
-
errors.push(err)
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Aggregated error surfaced when one or more `afterTransaction` hooks throw.
|
|
349
|
-
* The DB state is already final; all compensators still ran.
|
|
350
|
-
*/
|
|
351
|
-
export class AfterTransactionError extends Error {
|
|
352
|
-
public errors: unknown[]
|
|
353
|
-
constructor(errors: unknown[]) {
|
|
354
|
-
super(
|
|
355
|
-
`afterTransaction hook(s) failed: ${errors
|
|
356
|
-
.map((e) => (e instanceof Error ? e.message : String(e)))
|
|
357
|
-
.join('; ')}`,
|
|
358
|
-
)
|
|
359
|
-
this.name = 'AfterTransactionError'
|
|
360
|
-
this.errors = errors
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Resolves a joined write's final outcome once the owner's settle is known
|
|
366
|
-
* (ADR-0028): the write's own error always wins; otherwise committed iff the
|
|
367
|
-
* owner's transaction also committed.
|
|
368
|
-
*/
|
|
369
|
-
function resolveDeferredOutcome(
|
|
370
|
-
writeOutcome: TransactionOutcome,
|
|
371
|
-
settle: TransactionSettleOutcome,
|
|
372
|
-
): TransactionOutcome {
|
|
373
|
-
if (writeOutcome.status === 'rolled-back') return writeOutcome
|
|
374
|
-
if (settle.status === 'committed') return writeOutcome
|
|
375
|
-
return { status: 'rolled-back', error: settle.error }
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Brackets a write's transaction with the transaction-boundary hooks (#590,
|
|
380
|
-
* ADR-0028 / #899): runs every involved list's `beforeTransaction` eagerly —
|
|
381
|
-
* a throw here aborts before `runTransaction` (#569) ever opens the write's
|
|
382
|
-
* transaction — then routes `afterTransaction` by ownership: deferred onto
|
|
383
|
-
* `args.joinedOwner`'s {@link TransactionRegistry} for a joined write, run
|
|
384
|
-
* eagerly (draining `args.ownedRegistry`) for the write that opened the
|
|
385
|
-
* transaction, or run eagerly with neither set. See ADR-0028 for why. A
|
|
386
|
-
* joined write's `afterTransaction` errors therefore surface as an
|
|
387
|
-
* {@link AfterTransactionError} from the OWNER's promise, not this write's.
|
|
388
|
-
*
|
|
389
|
-
* Sudo bypasses access control only — never these hooks.
|
|
390
|
-
*/
|
|
391
|
-
export async function runWithTransactionBoundary<TPrisma extends PrismaClientLike>(args: {
|
|
392
|
-
involvedLists: InvolvedList[]
|
|
393
|
-
context: AccessContext<TPrisma>
|
|
394
|
-
/** Set when this write is nested in a transaction it did not open (ADR-0028). */
|
|
395
|
-
joinedOwner?: TransactionRegistry
|
|
396
|
-
/** Set when this write just opened the transaction joined writes below it share. */
|
|
397
|
-
ownedRegistry?: TransactionRegistry
|
|
398
|
-
runTransaction: () => Promise<Record<string, unknown> | null>
|
|
399
|
-
}): Promise<Record<string, unknown> | null> {
|
|
400
|
-
const { involvedLists, context, joinedOwner, ownedRegistry, runTransaction } = args
|
|
401
|
-
|
|
402
|
-
// A list counts as "ran" the moment its beforeTransaction BEGINS (pushed
|
|
403
|
-
// before the try below), not on success — so a list whose beforeTransaction
|
|
404
|
-
// itself throws still gets its afterTransaction, in case it took a partial
|
|
405
|
-
// external action that needs compensating.
|
|
406
|
-
const ran: InvolvedList[] = []
|
|
407
|
-
|
|
408
|
-
let beforeError: unknown
|
|
409
|
-
for (const involved of involvedLists) {
|
|
410
|
-
ran.push(involved)
|
|
411
|
-
try {
|
|
412
|
-
await runBeforeTransactionForList(involved, context)
|
|
413
|
-
} catch (err) {
|
|
414
|
-
beforeError = err
|
|
415
|
-
break
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Abort path: never open the transaction; compensate the lists that ran,
|
|
420
|
-
// then rethrow the original error.
|
|
421
|
-
if (beforeError !== undefined) {
|
|
422
|
-
const outcome: TransactionOutcome = { status: 'rolled-back', error: beforeError }
|
|
423
|
-
if (joinedOwner) {
|
|
424
|
-
// Discards any afterTransaction errors on this path — only beforeError
|
|
425
|
-
// propagates, matching the eager branch below.
|
|
426
|
-
joinedOwner.enqueue(async (_settle, _errors) => {
|
|
427
|
-
const discarded: unknown[] = []
|
|
428
|
-
for (const involved of ran) {
|
|
429
|
-
await runAfterTransactionForList(involved, outcome, context, discarded)
|
|
430
|
-
}
|
|
431
|
-
})
|
|
432
|
-
} else {
|
|
433
|
-
const afterErrors: unknown[] = []
|
|
434
|
-
for (const involved of ran) {
|
|
435
|
-
await runAfterTransactionForList(involved, outcome, context, afterErrors)
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
throw beforeError
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// Open (or join) the transaction and capture this write's own settle outcome.
|
|
442
|
-
let outcome: TransactionOutcome
|
|
443
|
-
let result: Record<string, unknown> | null = null
|
|
444
|
-
let txError: unknown
|
|
445
|
-
try {
|
|
446
|
-
result = await runTransaction()
|
|
447
|
-
outcome = { status: 'committed', item: result ?? {} }
|
|
448
|
-
} catch (err) {
|
|
449
|
-
txError = err
|
|
450
|
-
outcome = { status: 'rolled-back', error: err }
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (joinedOwner) {
|
|
454
|
-
// Deferred (ADR-0028) — only afterTransaction waits; this write's own
|
|
455
|
-
// result/throw is returned/thrown normally below.
|
|
456
|
-
joinedOwner.enqueue(async (settle, errors) => {
|
|
457
|
-
const finalOutcome = resolveDeferredOutcome(outcome, settle)
|
|
458
|
-
for (const involved of ran) {
|
|
459
|
-
await runAfterTransactionForList(involved, finalOutcome, context, errors)
|
|
460
|
-
}
|
|
461
|
-
})
|
|
462
|
-
if (txError !== undefined) throw txError
|
|
463
|
-
return result
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// All compensators run even if one throws.
|
|
467
|
-
const afterErrors: unknown[] = []
|
|
468
|
-
for (const involved of ran) {
|
|
469
|
-
await runAfterTransactionForList(involved, outcome, context, afterErrors)
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Owner: drain joined writes' deferred brackets with this write's own settle
|
|
473
|
-
// outcome (ADR-0028).
|
|
474
|
-
if (ownedRegistry) {
|
|
475
|
-
const settle: TransactionSettleOutcome =
|
|
476
|
-
txError !== undefined ? { status: 'rolled-back', error: txError } : { status: 'committed' }
|
|
477
|
-
await ownedRegistry.drain(settle, afterErrors)
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Transaction error takes precedence over afterTransaction errors (ADR-0028).
|
|
481
|
-
if (txError !== undefined) throw txError
|
|
482
|
-
if (afterErrors.length > 0) throw new AfterTransactionError(afterErrors)
|
|
483
|
-
|
|
484
|
-
return result
|
|
485
|
-
}
|