@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,692 +0,0 @@
|
|
|
1
|
-
import { checkAccess, getRelatedListConfig, resolveSyntheticReverseRelation, listSyntheticReverseRelationNames, } from './engine.js';
|
|
2
|
-
import { READ_INCLUDE_MAX_DEPTH } from './depth-limits.js';
|
|
3
|
-
import { AccessScopeDepthExceededError, RelationFilterAccessDeniedError, UndeclaredCountKeyError, UndeclaredIncludeKeyError, } from './errors.js';
|
|
4
|
-
import { LOGICAL_OPERATORS, RELATION_QUANTIFIERS, resolveQueryField, validateQueryFieldReadAccess, validateQueryKeys, walkWhereReadAccess, } from './query-validation.js';
|
|
5
|
-
import { isToManyRelationshipField, resolveCountAccessEntryForList } from './relationship-count.js';
|
|
6
|
-
import { getDbKey } from '../lib/case-utils.js';
|
|
7
|
-
/** A plain object — excludes `null` and arrays, which `typeof x === 'object'` alone would admit. */
|
|
8
|
-
function isPlainObject(value) {
|
|
9
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Narrow an unknown include value to the structured object form (vs bare `true`
|
|
13
|
-
* or any other primitive). Caller-supplied includes arrive untyped at the
|
|
14
|
-
* runtime boundary: narrow to a plain object first, then validate each field's
|
|
15
|
-
* own type before trusting it, rather than casting the whole value wholesale.
|
|
16
|
-
*
|
|
17
|
-
* A numeric `take` on a to-many relation include (a caller-supplied row bound,
|
|
18
|
-
* issue #752), and a caller-supplied `orderBy`/`skip` (#851), are carried
|
|
19
|
-
* through the same way: none of the three can ever widen the result past the
|
|
20
|
-
* access `where` — they only narrow or reorder rows the access filter already
|
|
21
|
-
* admits — so preserving them is access-neutral.
|
|
22
|
-
*/
|
|
23
|
-
function asEntryObject(value) {
|
|
24
|
-
if (!isPlainObject(value))
|
|
25
|
-
return null;
|
|
26
|
-
const { where, include, take, orderBy, skip } = value;
|
|
27
|
-
const entry = {};
|
|
28
|
-
if (isPlainObject(where))
|
|
29
|
-
entry.where = where;
|
|
30
|
-
if (isPlainObject(include))
|
|
31
|
-
entry.include = include;
|
|
32
|
-
if (typeof take === 'number')
|
|
33
|
-
entry.take = take;
|
|
34
|
-
if (isPlainObject(orderBy) || Array.isArray(orderBy)) {
|
|
35
|
-
entry.orderBy = orderBy;
|
|
36
|
-
}
|
|
37
|
-
if (typeof skip === 'number')
|
|
38
|
-
entry.skip = skip;
|
|
39
|
-
return entry;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* AND-combine an access `where` with a caller-supplied nested `where`.
|
|
43
|
-
*
|
|
44
|
-
* The access filter is authoritative: the caller's filter may only NARROW the
|
|
45
|
-
* result further, never widen past what access permits. We therefore wrap both
|
|
46
|
-
* in a Prisma `AND` so neither can override the other.
|
|
47
|
-
*/
|
|
48
|
-
function andWhere(accessWhere, callerWhere) {
|
|
49
|
-
if (accessWhere && callerWhere) {
|
|
50
|
-
return { AND: [accessWhere, callerWhere] };
|
|
51
|
-
}
|
|
52
|
-
return accessWhere ?? callerWhere;
|
|
53
|
-
}
|
|
54
|
-
export function emptyToOneAccessFilterTree() {
|
|
55
|
-
return { filters: {}, nested: {} };
|
|
56
|
-
}
|
|
57
|
-
function isToOneAccessFilterTreeEmpty(tree) {
|
|
58
|
-
return Object.keys(tree.filters).length === 0 && Object.keys(tree.nested).length === 0;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Whether a relationship field is to-one (at most one related row) rather
|
|
62
|
-
* than to-many. Exported so `field-visibility.ts` can pick the same `null`
|
|
63
|
-
* (to-one) vs `[]` (to-many) shape for a denied relation's forced value
|
|
64
|
-
* (issue #1103) that this module used to decide whether to record the
|
|
65
|
-
* denial in the first place — one source of truth for arity, not two.
|
|
66
|
-
*/
|
|
67
|
-
export function isToOneRelationship(fieldConfig) {
|
|
68
|
-
return !('many' in fieldConfig && fieldConfig.many === true);
|
|
69
|
-
}
|
|
70
|
-
export function emptyCountAccessDenialTree() {
|
|
71
|
-
return { keys: new Set(), nested: {} };
|
|
72
|
-
}
|
|
73
|
-
function isCountAccessDenialTreeEmpty(tree) {
|
|
74
|
-
return tree.keys.size === 0 && Object.keys(tree.nested).length === 0;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Normalize a caller's `_count` include value to the `_count.select` map it
|
|
78
|
-
* names. `true` (Prisma's "count every relation" shorthand) expands to every
|
|
79
|
-
* countable relation Prisma itself carries on this model — every DECLARED
|
|
80
|
-
* to-many relationship, plus every synthetic back-relation a list-only `ref`
|
|
81
|
-
* elsewhere in the config synthesizes onto it (issue #1082): Prisma's own
|
|
82
|
-
* `_count: true` has always counted both, and dropping the synthetic ones
|
|
83
|
-
* here would silently stop counting a relation the caller used to get a
|
|
84
|
-
* (previously unscoped) count for. Returns `null` for a shape that requests
|
|
85
|
-
* nothing countable (`false`, or an object with no usable `select`).
|
|
86
|
-
*/
|
|
87
|
-
function normalizeCountSelect(requestedValue, fieldConfigs, listKey, config) {
|
|
88
|
-
if (requestedValue === true) {
|
|
89
|
-
const expanded = {};
|
|
90
|
-
for (const [fieldName, fieldConfig] of Object.entries(fieldConfigs)) {
|
|
91
|
-
if (isToManyRelationshipField(fieldConfig))
|
|
92
|
-
expanded[fieldName] = true;
|
|
93
|
-
}
|
|
94
|
-
for (const syntheticName of listSyntheticReverseRelationNames(listKey, config)) {
|
|
95
|
-
expanded[syntheticName] = true;
|
|
96
|
-
}
|
|
97
|
-
return expanded;
|
|
98
|
-
}
|
|
99
|
-
if (isPlainObject(requestedValue) && isPlainObject(requestedValue.select)) {
|
|
100
|
-
return requestedValue.select;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Scope a caller-supplied `_count` include value by each named relation's own
|
|
106
|
-
* `query` access — the `_count` counterpart to the rest of this module's
|
|
107
|
-
* relation scoping (issue #1087, closing the one key `buildAccessScopedInclude`
|
|
108
|
-
* used to allowlist through unscoped, #1082's "Out of scope").
|
|
109
|
-
*
|
|
110
|
-
* For each key in the caller's `_count.select` (or, for bare `_count: true`,
|
|
111
|
-
* every declared to-many relation — see `normalizeCountSelect`):
|
|
112
|
-
* - Not a declared to-many relationship and not a synthetic back-relation
|
|
113
|
-
* (#1082 — always genuinely countable) → THROWN as
|
|
114
|
-
* `UndeclaredCountKeyError`, matching `buildAccessScopedInclude`'s own
|
|
115
|
-
* rejection for the ordinary walk. A declared to-many relationship whose
|
|
116
|
-
* `ref` cannot be resolved is skipped instead, matching that same walk's
|
|
117
|
-
* handling of a config-level dangling ref (not a caller error).
|
|
118
|
-
* - The counting list's OWN field-level `read` access on the relationship
|
|
119
|
-
* field being counted denies it, or the related list's `query` access
|
|
120
|
-
* denies it (`=== false`) → omitted from the select sent to Prisma and
|
|
121
|
-
* added to the returned `deniedKeys`, so `filterReadableFields` can inject
|
|
122
|
-
* `0` post-query (a count is session-relative; denial doesn't mean "no such
|
|
123
|
-
* relation"). The field-level check has nothing to evaluate for a synthetic
|
|
124
|
-
* back-relation (no field of its own on this list) and is skipped for it —
|
|
125
|
-
* `resolveCountAccessEntryForList` (issue #1111). Both checks run BEFORE
|
|
126
|
-
* any caller-supplied nested `where` is validated — validating first would
|
|
127
|
-
* let a caller who cannot read a single row of the related list learn its
|
|
128
|
-
* field names and field-level read rules from a thrown `ValidationError`
|
|
129
|
-
* alone, reopening the exact oracle #915/ADR-0031 closed for a top-level
|
|
130
|
-
* predicate.
|
|
131
|
-
* - Otherwise → the caller-supplied nested `where` at that key (if any) is
|
|
132
|
-
* key- and read-access-validated against the RELATED list via the same
|
|
133
|
-
* `validateQueryKeys`/`validateQueryFieldReadAccess` primitives
|
|
134
|
-
* `createFindMany` already runs on a top-level `where` (#912/#915), then
|
|
135
|
-
* run through `buildAccessScopedWhere` — the same fold `createFindMany`
|
|
136
|
-
* applies to a top-level `where` (#916) — so a relation filter nested
|
|
137
|
-
* inside IT (e.g. `_count.select.posts.where.comments.some`) is scoped by
|
|
138
|
-
* THAT further list's own `query` access too, not just the counted
|
|
139
|
-
* relation's. The result is AND-combined with the counted relation's own
|
|
140
|
-
* access filter (if any) — reusing `andWhere`, never replacing the
|
|
141
|
-
* caller's condition, mirroring `buildAccessScopedInclude` itself.
|
|
142
|
-
*/
|
|
143
|
-
async function buildAccessScopedCountSelect(requestedValue, fieldConfigs, args, config, listKey) {
|
|
144
|
-
const requestedSelect = normalizeCountSelect(requestedValue, fieldConfigs, listKey, config);
|
|
145
|
-
const deniedKeys = new Set();
|
|
146
|
-
if (!requestedSelect)
|
|
147
|
-
return { select: undefined, deniedKeys };
|
|
148
|
-
const select = {};
|
|
149
|
-
for (const [key, entryValue] of Object.entries(requestedSelect)) {
|
|
150
|
-
// A caller can explicitly exclude a key from the `true`-expanded set the
|
|
151
|
-
// same way Prisma's own `select` excludes a field.
|
|
152
|
-
if (entryValue === false)
|
|
153
|
-
continue;
|
|
154
|
-
const fieldConfig = fieldConfigs[key];
|
|
155
|
-
const isDeclaredToMany = isToManyRelationshipField(fieldConfig);
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
157
|
-
let relatedConfig = null;
|
|
158
|
-
if (isDeclaredToMany && fieldConfig && 'ref' in fieldConfig) {
|
|
159
|
-
relatedConfig = getRelatedListConfig(fieldConfig.ref, config);
|
|
160
|
-
}
|
|
161
|
-
if (!relatedConfig && !isDeclaredToMany) {
|
|
162
|
-
const synthetic = resolveSyntheticReverseRelation(key, listKey, config);
|
|
163
|
-
if (synthetic) {
|
|
164
|
-
relatedConfig = {
|
|
165
|
-
listName: synthetic.sourceListName,
|
|
166
|
-
listConfig: synthetic.sourceListConfig,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (!relatedConfig) {
|
|
171
|
-
// A declared to-many field whose `ref` didn't resolve is a config
|
|
172
|
-
// issue, not a caller error — skip it exactly like the ordinary
|
|
173
|
-
// include walk does for the same case.
|
|
174
|
-
if (isDeclaredToMany)
|
|
175
|
-
continue;
|
|
176
|
-
throw new UndeclaredCountKeyError(listKey, key);
|
|
177
|
-
}
|
|
178
|
-
// `fieldConfig` is undefined for a synthetic back-relation (#1082) — it has
|
|
179
|
-
// no field of its own on THIS list, so there is no field-level `read`
|
|
180
|
-
// access to fold in; `resolveCountAccessEntryForList` treats a missing
|
|
181
|
-
// `fieldAccess` as exempt, matching the ordinary include path's own lack
|
|
182
|
-
// of a field-level gate for a synthetic key (issue #1111).
|
|
183
|
-
const accessEntry = await resolveCountAccessEntryForList(relatedConfig.listConfig, args, fieldConfig?.access);
|
|
184
|
-
// Denial is checked BEFORE the caller's nested `where` is validated —
|
|
185
|
-
// mirroring `buildAccessScopedWhere`'s own ordering below. A fully denied
|
|
186
|
-
// relation counts `0` no matter what `where` the caller supplied, so
|
|
187
|
-
// validating it first would let a caller who cannot read a single row of
|
|
188
|
-
// the related list learn its field names and field-level read rules from
|
|
189
|
-
// a `ValidationError`'s message alone — the exact oracle #915/ADR-0031
|
|
190
|
-
// closed for a top-level predicate, reopened here if this ran first.
|
|
191
|
-
if (accessEntry.kind === 'denied') {
|
|
192
|
-
deniedKeys.add(key);
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
const requestedWhere = isPlainObject(entryValue) && isPlainObject(entryValue.where)
|
|
196
|
-
? entryValue.where
|
|
197
|
-
: undefined;
|
|
198
|
-
let scopedRequestedWhere;
|
|
199
|
-
if (requestedWhere) {
|
|
200
|
-
// Mirrors `buildAccessScopedInclude`'s own `resolveSyntheticRelation`
|
|
201
|
-
// closure (#1092/#916) — a synthetic back-relation (#1082) named inside
|
|
202
|
-
// this count entry's own `where` resolves against its source list
|
|
203
|
-
// rather than being rejected as undeclared, at every hop.
|
|
204
|
-
const resolveSyntheticRelation = (syntheticKey, fromListName) => {
|
|
205
|
-
const synthetic = resolveSyntheticReverseRelation(syntheticKey, fromListName, config);
|
|
206
|
-
return synthetic
|
|
207
|
-
? { listConfig: synthetic.sourceListConfig, listName: synthetic.sourceListName }
|
|
208
|
-
: null;
|
|
209
|
-
};
|
|
210
|
-
validateQueryKeys({
|
|
211
|
-
where: requestedWhere,
|
|
212
|
-
listConfig: relatedConfig.listConfig,
|
|
213
|
-
listName: relatedConfig.listName,
|
|
214
|
-
config,
|
|
215
|
-
isSudo: false,
|
|
216
|
-
resolveSyntheticRelation,
|
|
217
|
-
});
|
|
218
|
-
await validateQueryFieldReadAccess({
|
|
219
|
-
where: requestedWhere,
|
|
220
|
-
listConfig: relatedConfig.listConfig,
|
|
221
|
-
listName: relatedConfig.listName,
|
|
222
|
-
session: args.session,
|
|
223
|
-
context: args.context,
|
|
224
|
-
isSudo: false,
|
|
225
|
-
});
|
|
226
|
-
// A relation filter (`some`/`every`/`none`/`is`/`isNot`) nested inside
|
|
227
|
-
// the caller's own `where` names a THIRD list one hop further out —
|
|
228
|
-
// e.g. `_count.select.posts.where.comments.some`. Validation above only
|
|
229
|
-
// checked keys against the counted relation's OWN fields; without this,
|
|
230
|
-
// that nested relation would reach Prisma unscoped by ITS list's
|
|
231
|
-
// `query` access, letting the resulting count reveal whether
|
|
232
|
-
// inaccessible rows over there exist. `buildAccessScopedWhere` is the
|
|
233
|
-
// same fold `createFindMany` runs on an ordinary top-level `where`
|
|
234
|
-
// (#916) — reused here rather than re-derived.
|
|
235
|
-
scopedRequestedWhere = (await buildAccessScopedWhere(requestedWhere, relatedConfig.listConfig, relatedConfig.listName, config, args, resolveSyntheticRelation));
|
|
236
|
-
}
|
|
237
|
-
const scopedWhere = andWhere(accessEntry.kind === 'scoped' ? accessEntry.where : undefined, scopedRequestedWhere);
|
|
238
|
-
select[key] = scopedWhere ? { where: scopedWhere } : true;
|
|
239
|
-
}
|
|
240
|
-
return { select: Object.keys(select).length > 0 ? select : undefined, deniedKeys };
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Build the access-scoped `include` for exactly the relations a read
|
|
244
|
-
* requested, recursing only into branches `requestedInclude` itself names.
|
|
245
|
-
*
|
|
246
|
-
* For each key in `requestedInclude`:
|
|
247
|
-
* - A declared field that isn't a relationship (scalar, virtual, …) → access
|
|
248
|
-
* control does not govern it; passed through unchanged (a virtual key is
|
|
249
|
-
* stripped later by `stripVirtualFieldsFromInclude`, #628).
|
|
250
|
-
* - Not declared at all → resolved via `resolveSyntheticReverseRelation`
|
|
251
|
-
* (the synthetic-back-relation case above); `_count` is scoped by
|
|
252
|
-
* `buildAccessScopedCountSelect` (issue #1087 — each named relation's own
|
|
253
|
-
* `query` access, exactly like any other relation this walk scopes; a
|
|
254
|
-
* denied one is recorded for `filterReadableFields` to inject `0` for,
|
|
255
|
-
* post-query, since Prisma cannot be asked for a guaranteed `0`); anything
|
|
256
|
-
* else throws `UndeclaredIncludeKeyError` rather than reaching the
|
|
257
|
-
* database unscoped.
|
|
258
|
-
* - A declared relationship whose related list's `query` access denies it
|
|
259
|
-
* (`=== false`) → dropped entirely, no matter what the request asked for
|
|
260
|
-
* nested beneath it (#566): the caller chooses *which* relations, access
|
|
261
|
-
* control chooses *whether* and *with what filter*. This denial is also
|
|
262
|
-
* recorded in `toOneAccessFilters` (`kind: 'denied'`), for either arity, so
|
|
263
|
-
* `filterReadableFields` can still surface an explicit `null` (to-one,
|
|
264
|
-
* issue #974) or `[]` (to-many, issue #1103) for it rather than an absent
|
|
265
|
-
* key.
|
|
266
|
-
* - Otherwise, for a to-**many** relation → the access `where` is
|
|
267
|
-
* AND-combined with any caller-supplied nested `where` (never replaced —
|
|
268
|
-
* the other half of #566), and a caller-supplied `take` rides through
|
|
269
|
-
* unchanged (#752). For a to-**one** relation → the access filter (if any)
|
|
270
|
-
* is recorded in `toOneAccessFilters` instead of attached as `where`,
|
|
271
|
-
* because Prisma only accepts a nested `where` on a to-many include
|
|
272
|
-
* (issue #974) — the entry itself never carries a `where` for a to-one key.
|
|
273
|
-
* - Either way — the "One hop" rule (ADR-0026) — nested relations are scoped
|
|
274
|
-
* ONLY if `requestedInclude` itself named a nested `include` here. A bare
|
|
275
|
-
* relation (or one with no nested `include`) fetches its own columns and
|
|
276
|
-
* stops: no recursive call, no access evaluation on anything beneath it.
|
|
277
|
-
*
|
|
278
|
-
* **Depth is a cost limit, not a cycle guard (ADR-0026).** A `requestedInclude`
|
|
279
|
-
* is always a finite literal — the caller's own object, or
|
|
280
|
-
* `foldDeclaredDependencies`'s already-cycle-guarded fold — so this recursion
|
|
281
|
-
* cannot loop unboundedly on its own; nothing here walks the relationship
|
|
282
|
-
* graph unprompted. `READ_INCLUDE_MAX_DEPTH` still bounds how deep a request
|
|
283
|
-
* may reach, fail-closed per ADR-0022: a request naming anything at or past
|
|
284
|
-
* the cap throws `AccessScopeDepthExceededError` rather than silently
|
|
285
|
-
* returning less than what was asked for.
|
|
286
|
-
*/
|
|
287
|
-
export async function buildAccessScopedInclude(requestedInclude, fieldConfigs, args, config, listKey, depth = 0) {
|
|
288
|
-
const requestedKeys = Object.keys(requestedInclude);
|
|
289
|
-
if (depth >= READ_INCLUDE_MAX_DEPTH && requestedKeys.length > 0) {
|
|
290
|
-
throw new AccessScopeDepthExceededError(listKey, requestedKeys[0], depth);
|
|
291
|
-
}
|
|
292
|
-
const result = {};
|
|
293
|
-
const toOneAccessFilters = emptyToOneAccessFilterTree();
|
|
294
|
-
const countDenials = emptyCountAccessDenialTree();
|
|
295
|
-
for (const [relationName, requestedValue] of Object.entries(requestedInclude)) {
|
|
296
|
-
// A caller can explicitly opt a relation OUT of a Prisma include with
|
|
297
|
-
// `false` (its `Include` type allows a bare `boolean`), or end up with an
|
|
298
|
-
// `undefined` value from a conditionally-built object
|
|
299
|
-
// (`{ posts: cond ? true : undefined }`) — Prisma treats both the same as
|
|
300
|
-
// the key being absent. Treat them identically here too, before this key
|
|
301
|
-
// ever reaches access evaluation: an explicitly-disabled relation was
|
|
302
|
-
// never actually requested, so it must not be evaluated, dropped as
|
|
303
|
-
// "denied", or recorded as needing a post-query fixup (issue #1103 code
|
|
304
|
-
// review) — any of those would surface a value (`[]`/`null`) for a key
|
|
305
|
-
// the caller deliberately excluded.
|
|
306
|
-
if (requestedValue === false || requestedValue === undefined)
|
|
307
|
-
continue;
|
|
308
|
-
const fieldConfig = fieldConfigs[relationName];
|
|
309
|
-
const isDeclaredRelationship = fieldConfig?.type === 'relationship' && 'ref' in fieldConfig && !!fieldConfig.ref;
|
|
310
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
311
|
-
let relatedConfig;
|
|
312
|
-
let isToOne;
|
|
313
|
-
if (isDeclaredRelationship) {
|
|
314
|
-
relatedConfig = getRelatedListConfig(fieldConfig.ref, config);
|
|
315
|
-
if (!relatedConfig)
|
|
316
|
-
continue;
|
|
317
|
-
isToOne = isToOneRelationship(fieldConfig);
|
|
318
|
-
}
|
|
319
|
-
else if (fieldConfig) {
|
|
320
|
-
// A declared field that is not a relationship — access control does
|
|
321
|
-
// not govern it here; passed through unchanged.
|
|
322
|
-
result[relationName] = requestedValue;
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
else if (relationName === '_count') {
|
|
326
|
-
const { select, deniedKeys } = await buildAccessScopedCountSelect(requestedValue, fieldConfigs, args, config, listKey);
|
|
327
|
-
if (select)
|
|
328
|
-
result[relationName] = { select };
|
|
329
|
-
if (deniedKeys.size > 0)
|
|
330
|
-
countDenials.keys = deniedKeys;
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
const synthetic = resolveSyntheticReverseRelation(relationName, listKey, config);
|
|
335
|
-
if (!synthetic) {
|
|
336
|
-
throw new UndeclaredIncludeKeyError(listKey, relationName);
|
|
337
|
-
}
|
|
338
|
-
relatedConfig = { listName: synthetic.sourceListName, listConfig: synthetic.sourceListConfig };
|
|
339
|
-
// Always to-many — a list-only ref has one construction site and no
|
|
340
|
-
// arity branch, and one-to-one is structurally impossible for it.
|
|
341
|
-
isToOne = false;
|
|
342
|
-
}
|
|
343
|
-
const queryAccess = relatedConfig.listConfig.access?.operation?.query;
|
|
344
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
345
|
-
session: args.session,
|
|
346
|
-
context: args.context,
|
|
347
|
-
});
|
|
348
|
-
if (accessResult === false) {
|
|
349
|
-
// Recorded for either arity (issue #1103) — a to-many relation is
|
|
350
|
-
// dropped from `include` here exactly like a to-one one, and needs the
|
|
351
|
-
// same post-query fixup so its key comes back `[]`, not silently
|
|
352
|
-
// absent from the row.
|
|
353
|
-
toOneAccessFilters.filters[relationName] = { kind: 'denied' };
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
const accessWhere = typeof accessResult === 'object' ? accessResult : undefined;
|
|
357
|
-
const requestedEntry = asEntryObject(requestedValue);
|
|
358
|
-
// #1092 — a nested `where`/`orderBy` gets the same #912/#915 checks the
|
|
359
|
-
// top-level `where`/`orderBy` already gets, resolved against the RELATED
|
|
360
|
-
// list (`relatedConfig`) rather than the current one, and run only once
|
|
361
|
-
// the relation is known to be accessible at all (same ordering reason as
|
|
362
|
-
// the top-level checks: don't leak a field's name/read-gating status to a
|
|
363
|
-
// caller who has zero access to the relation to begin with).
|
|
364
|
-
const resolveSyntheticRelation = (key, fromListName) => {
|
|
365
|
-
const synthetic = resolveSyntheticReverseRelation(key, fromListName, config);
|
|
366
|
-
return synthetic
|
|
367
|
-
? { listConfig: synthetic.sourceListConfig, listName: synthetic.sourceListName }
|
|
368
|
-
: null;
|
|
369
|
-
};
|
|
370
|
-
validateQueryKeys({
|
|
371
|
-
where: requestedEntry?.where,
|
|
372
|
-
orderBy: requestedEntry?.orderBy,
|
|
373
|
-
listConfig: relatedConfig.listConfig,
|
|
374
|
-
listName: relatedConfig.listName,
|
|
375
|
-
config,
|
|
376
|
-
isSudo: false,
|
|
377
|
-
resolveSyntheticRelation,
|
|
378
|
-
});
|
|
379
|
-
await validateQueryFieldReadAccess({
|
|
380
|
-
where: requestedEntry?.where,
|
|
381
|
-
orderBy: requestedEntry?.orderBy,
|
|
382
|
-
listConfig: relatedConfig.listConfig,
|
|
383
|
-
listName: relatedConfig.listName,
|
|
384
|
-
session: args.session,
|
|
385
|
-
context: args.context,
|
|
386
|
-
isSudo: false,
|
|
387
|
-
});
|
|
388
|
-
// The two checks above only reach the entry's own top-level keys — a
|
|
389
|
-
// relation quantifier (`some`/`every`/`none`/`is`/`isNot`) nested inside
|
|
390
|
-
// this `where` names a DEEPER related list, which needs the same
|
|
391
|
-
// treatment the top-level `where` already gets from `buildAccessScopedWhere`
|
|
392
|
-
// (#916): scope it by that deeper list's own `query` access and check ITS
|
|
393
|
-
// fields' read access, recursing through every further hop. Only for
|
|
394
|
-
// to-many — a to-one entry never carries `requestedEntry.where` through to
|
|
395
|
-
// Prisma at all (see below), so there is nothing here to scope.
|
|
396
|
-
const scopedRequestedWhere = !isToOne && requestedEntry?.where !== undefined
|
|
397
|
-
? (await buildAccessScopedWhere(requestedEntry.where, relatedConfig.listConfig, relatedConfig.listName, config, args, resolveSyntheticRelation))
|
|
398
|
-
: requestedEntry?.where;
|
|
399
|
-
let nestedInclude;
|
|
400
|
-
let nestedToOneFilters;
|
|
401
|
-
let nestedCountDenials;
|
|
402
|
-
if (requestedEntry?.include) {
|
|
403
|
-
const nested = await buildAccessScopedInclude(requestedEntry.include, relatedConfig.listConfig.fields, args, config, relatedConfig.listName, depth + 1);
|
|
404
|
-
nestedInclude = nested.include;
|
|
405
|
-
nestedToOneFilters = nested.toOneAccessFilters;
|
|
406
|
-
nestedCountDenials = nested.countDenials;
|
|
407
|
-
}
|
|
408
|
-
const entry = {};
|
|
409
|
-
if (isToOne) {
|
|
410
|
-
if (accessWhere) {
|
|
411
|
-
toOneAccessFilters.filters[relationName] = {
|
|
412
|
-
kind: 'scoped',
|
|
413
|
-
relatedListName: relatedConfig.listName,
|
|
414
|
-
accessWhere,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
const mergedWhere = andWhere(accessWhere, scopedRequestedWhere);
|
|
420
|
-
if (mergedWhere)
|
|
421
|
-
entry.where = mergedWhere;
|
|
422
|
-
if (requestedEntry?.take !== undefined)
|
|
423
|
-
entry.take = requestedEntry.take;
|
|
424
|
-
if (requestedEntry?.orderBy !== undefined)
|
|
425
|
-
entry.orderBy = requestedEntry.orderBy;
|
|
426
|
-
if (requestedEntry?.skip !== undefined)
|
|
427
|
-
entry.skip = requestedEntry.skip;
|
|
428
|
-
}
|
|
429
|
-
if (nestedInclude && Object.keys(nestedInclude).length > 0)
|
|
430
|
-
entry.include = nestedInclude;
|
|
431
|
-
if (nestedToOneFilters && !isToOneAccessFilterTreeEmpty(nestedToOneFilters)) {
|
|
432
|
-
toOneAccessFilters.nested[relationName] = nestedToOneFilters;
|
|
433
|
-
}
|
|
434
|
-
if (nestedCountDenials && !isCountAccessDenialTreeEmpty(nestedCountDenials)) {
|
|
435
|
-
countDenials.nested[relationName] = nestedCountDenials;
|
|
436
|
-
}
|
|
437
|
-
result[relationName] = Object.keys(entry).length > 0 ? entry : true;
|
|
438
|
-
}
|
|
439
|
-
return { include: result, toOneAccessFilters, countDenials };
|
|
440
|
-
}
|
|
441
|
-
export function emptyToOneAccessVisibilityTree() {
|
|
442
|
-
return { filters: {}, nested: {} };
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Resolve a `ToOneAccessFilterTree` against the RAW rows Prisma already
|
|
446
|
-
* fetched (unscoped for the flagged to-one relations — see
|
|
447
|
-
* `buildAccessScopedInclude`) into the set of related ids the session may
|
|
448
|
-
* actually see, one batched `id IN (...)` existence check per (relation,
|
|
449
|
-
* nesting level) across every row in `items` — never once per row.
|
|
450
|
-
*
|
|
451
|
-
* For each `filters` entry at a level:
|
|
452
|
-
* - `kind: 'denied'` → carried straight through; no query, nothing to check.
|
|
453
|
-
* - `kind: 'scoped'` → every id present at this key across ALL of `items` is
|
|
454
|
-
* collected first (an empty set skips the query entirely — nothing to
|
|
455
|
-
* check), then ONE `findMany` through the RAW `prisma` client (not
|
|
456
|
-
* `context.db`, which would re-evaluate the same access-control function a
|
|
457
|
-
* second time) asks which of those ids also satisfy `accessWhere` — the
|
|
458
|
-
* exact `PrismaFilter` `checkAccess` already produced, handed to Prisma
|
|
459
|
-
* unmodified rather than interpreted by hand.
|
|
460
|
-
*
|
|
461
|
-
* Recurses into `nested` by flattening the related items reached through
|
|
462
|
-
* each key across every row in `items` (a to-many hop contributes every one
|
|
463
|
-
* of its rows; a to-one hop contributes its single row, if any) into the
|
|
464
|
-
* next level's own `items` array, so a to-one relation nested arbitrarily
|
|
465
|
-
* deep is still resolved with one batched query per node, not per parent row.
|
|
466
|
-
*/
|
|
467
|
-
export async function resolveToOneAccessVisibility(items, tree, args) {
|
|
468
|
-
const resolved = emptyToOneAccessVisibilityTree();
|
|
469
|
-
for (const [key, entry] of Object.entries(tree.filters)) {
|
|
470
|
-
if (entry.kind === 'denied') {
|
|
471
|
-
resolved.filters[key] = { kind: 'denied' };
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
const ids = new Set();
|
|
475
|
-
for (const item of items) {
|
|
476
|
-
if (!item || typeof item !== 'object')
|
|
477
|
-
continue;
|
|
478
|
-
const value = item[key];
|
|
479
|
-
if (value && typeof value === 'object' && 'id' in value) {
|
|
480
|
-
ids.add(String(value.id));
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
if (ids.size === 0) {
|
|
484
|
-
resolved.filters[key] = { kind: 'visible', ids: new Set() };
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic model access by list name, mirroring the rest of the read pipeline
|
|
488
|
-
const model = args.context.prisma[getDbKey(entry.relatedListName)];
|
|
489
|
-
const visibleRows = await model.findMany({
|
|
490
|
-
where: { AND: [entry.accessWhere, { id: { in: [...ids] } }] },
|
|
491
|
-
select: { id: true },
|
|
492
|
-
});
|
|
493
|
-
const visibleIds = new Set(Array.isArray(visibleRows) ? visibleRows.map((row) => String(row.id)) : []);
|
|
494
|
-
resolved.filters[key] = { kind: 'visible', ids: visibleIds };
|
|
495
|
-
}
|
|
496
|
-
for (const [key, nestedTree] of Object.entries(tree.nested)) {
|
|
497
|
-
const nestedItems = [];
|
|
498
|
-
for (const item of items) {
|
|
499
|
-
if (!item || typeof item !== 'object')
|
|
500
|
-
continue;
|
|
501
|
-
const value = item[key];
|
|
502
|
-
if (Array.isArray(value))
|
|
503
|
-
nestedItems.push(...value);
|
|
504
|
-
else if (value && typeof value === 'object')
|
|
505
|
-
nestedItems.push(value);
|
|
506
|
-
}
|
|
507
|
-
resolved.nested[key] = await resolveToOneAccessVisibility(nestedItems, nestedTree, args);
|
|
508
|
-
}
|
|
509
|
-
return resolved;
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Scope every relation filter (`some`/`every`/`none`/`is`/`isNot`) nested in a
|
|
513
|
-
* caller's `where` by the related list's own `query` access — the `where`
|
|
514
|
-
* counterpart to `buildAccessScopedInclude` above, closing #916 (the
|
|
515
|
-
* "unclosed half of ADR-0022"). `include` and `where` are fundamentally
|
|
516
|
-
* different requests (which relations come back, vs. which parent rows
|
|
517
|
-
* match), so this is a distinct function, but it shares every primitive that
|
|
518
|
-
* matters: `checkAccess`/`getRelatedListConfig` (the same access-evaluation
|
|
519
|
-
* calls `buildAccessScopedInclude` makes), `andWhere` (the same AND-fold), and
|
|
520
|
-
* `resolveQueryField`/`LOGICAL_OPERATORS`/`RELATION_QUANTIFIERS`/
|
|
521
|
-
* `walkWhereReadAccess` (the same shape-recognition and field-read check
|
|
522
|
-
* `query-validation.ts` already uses for #912/#915) — there is no second,
|
|
523
|
-
* parallel implementation of any of those decisions.
|
|
524
|
-
*
|
|
525
|
-
* For each relationship key found (at any depth — the walk recurses through
|
|
526
|
-
* `AND`/`OR`/`NOT` and through every hop of a chain):
|
|
527
|
-
* - Not a declared relationship, or the key #912 already rejected (this walk
|
|
528
|
-
* runs strictly after that check) → passed through unchanged.
|
|
529
|
-
* - The related list's `query` access denies it (`=== false`) → THROWS
|
|
530
|
-
* `RelationFilterAccessDeniedError`. Unlike `buildAccessScopedInclude`'s
|
|
531
|
-
* silent drop, this is a loud failure: a `where` predicate has no neutral
|
|
532
|
-
* "not requested" outcome the way a missing `include` key does, so a
|
|
533
|
-
* silently-empty match would itself be a distinguishable signal (ADR-0022).
|
|
534
|
-
* - Otherwise → the access filter (if any) is AND-combined into the relation
|
|
535
|
-
* quantifier's nested clause (never replacing the caller's own condition,
|
|
536
|
-
* mirroring `andWhere`'s include-side contract), keys inside that nested
|
|
537
|
-
* clause are checked against the RELATED list's field-level `read` access
|
|
538
|
-
* (`walkWhereReadAccess`, closing #915's stated gap for this path), and the
|
|
539
|
-
* walk recurses into the related list's own fields for a further hop.
|
|
540
|
-
*
|
|
541
|
-
* One quantifier is deliberately conservative rather than exactly precise:
|
|
542
|
-
* folding the access filter into `every`'s nested clause with a plain AND
|
|
543
|
-
* makes `every` require every related row to be BOTH access-visible AND
|
|
544
|
-
* matching, not "every access-visible row matches" (the latter needs a
|
|
545
|
-
* `NOT`/`OR` transform this does not attempt). The conservative version can
|
|
546
|
-
* only reject a query that the precise version would allow — it never
|
|
547
|
-
* widens what a caller can learn — so it is the safe direction to ship; a
|
|
548
|
-
* caller can observe that an inaccessible related row exists (an `every`
|
|
549
|
-
* that "should" pass instead fails), but never that row's field values,
|
|
550
|
-
* which is the property this ticket exists to close.
|
|
551
|
-
*
|
|
552
|
-
* A quantifier's value of literal `null` (`is: null`/`isNot: null`, a to-one
|
|
553
|
-
* relation's existence check) is passed through untouched rather than folded:
|
|
554
|
-
* it names no fields to read-check or scope, and AND-folding an access filter
|
|
555
|
-
* into it would silently invert the caller's own predicate (see the inline
|
|
556
|
-
* comment at that branch).
|
|
557
|
-
*
|
|
558
|
-
* `resolveSyntheticRelation` (#1092/#1108) extends this to a key that
|
|
559
|
-
* resolves to a synthetic back-relation (#1082) rather than a declared
|
|
560
|
-
* field, recursing against its SOURCE list. Only `buildAccessScopedInclude`
|
|
561
|
-
* passes it, for the include-nested `where` position; the top-level `where`
|
|
562
|
-
* this function was originally built for (`context/index.ts`) omits it, so
|
|
563
|
-
* a synthetic key there is unaffected — matching #1092's own scope, which
|
|
564
|
-
* deliberately left the top-level checks unchanged.
|
|
565
|
-
*/
|
|
566
|
-
export async function buildAccessScopedWhere(where,
|
|
567
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
568
|
-
listConfig, listName, config, args,
|
|
569
|
-
// #1092/#1108 — the include-nested position's own addition, exactly
|
|
570
|
-
// mirroring `validateQueryKeys`'s `resolveSyntheticRelation` (see that
|
|
571
|
-
// module's doc comment): every top-level `where` caller omits this, so
|
|
572
|
-
// top-level behavior is unchanged.
|
|
573
|
-
resolveSyntheticRelation) {
|
|
574
|
-
if (where === null || typeof where !== 'object')
|
|
575
|
-
return where;
|
|
576
|
-
if (Array.isArray(where)) {
|
|
577
|
-
return Promise.all(where.map((entry) => buildAccessScopedWhere(entry, listConfig, listName, config, args, resolveSyntheticRelation)));
|
|
578
|
-
}
|
|
579
|
-
const result = {};
|
|
580
|
-
for (const [key, value] of Object.entries(where)) {
|
|
581
|
-
if (LOGICAL_OPERATORS.has(key)) {
|
|
582
|
-
result[key] = await buildAccessScopedWhere(value, listConfig, listName, config, args, resolveSyntheticRelation);
|
|
583
|
-
continue;
|
|
584
|
-
}
|
|
585
|
-
const resolved = resolveQueryField(key, listConfig.fields);
|
|
586
|
-
// A synthetic back-relation (#1082) carries no `ref` of its own to
|
|
587
|
-
// follow — its "related" list for recursion is the SOURCE list it
|
|
588
|
-
// stands for, given directly by the resolver, not `getRelatedListConfig`.
|
|
589
|
-
const related = resolved?.isRelationship
|
|
590
|
-
? getRelatedListConfig(resolved.fieldConfig.ref, config)
|
|
591
|
-
: !resolved
|
|
592
|
-
? (() => {
|
|
593
|
-
const synthetic = resolveSyntheticRelation?.(key, listName);
|
|
594
|
-
return synthetic
|
|
595
|
-
? { listConfig: synthetic.listConfig, listName: synthetic.listName }
|
|
596
|
-
: null;
|
|
597
|
-
})()
|
|
598
|
-
: null;
|
|
599
|
-
if (!related || value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
600
|
-
result[key] = value;
|
|
601
|
-
continue;
|
|
602
|
-
}
|
|
603
|
-
const queryAccess = related.listConfig.access?.operation?.query;
|
|
604
|
-
const accessResult = await checkAccess(queryAccess, {
|
|
605
|
-
session: args.session,
|
|
606
|
-
context: args.context,
|
|
607
|
-
});
|
|
608
|
-
if (accessResult === false) {
|
|
609
|
-
throw new RelationFilterAccessDeniedError(listName, key, related.listName);
|
|
610
|
-
}
|
|
611
|
-
const accessWhere = typeof accessResult === 'object' ? accessResult : undefined;
|
|
612
|
-
const relationEntries = Object.entries(value);
|
|
613
|
-
const hasQuantifier = relationEntries.some(([k]) => RELATION_QUANTIFIERS.has(k));
|
|
614
|
-
if (hasQuantifier) {
|
|
615
|
-
const nestedEntry = {};
|
|
616
|
-
for (const [quantifier, quantifierValue] of relationEntries) {
|
|
617
|
-
if (!RELATION_QUANTIFIERS.has(quantifier)) {
|
|
618
|
-
nestedEntry[quantifier] = quantifierValue;
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
if (quantifierValue === null) {
|
|
622
|
-
// `is: null` / `isNot: null` tests EXISTENCE of a to-one relation,
|
|
623
|
-
// not its fields — there is nothing to read-check or scope, and
|
|
624
|
-
// AND-folding the access filter in here would silently invert the
|
|
625
|
-
// caller's predicate: `is: null` ("has no related row") would
|
|
626
|
-
// become `is: <accessWhere>` ("has a related row matching the
|
|
627
|
-
// filter"), the opposite of what was asked. Passed through as-is.
|
|
628
|
-
nestedEntry[quantifier] = null;
|
|
629
|
-
continue;
|
|
630
|
-
}
|
|
631
|
-
await walkWhereReadAccess(quantifierValue, related.listConfig, related.listName, args);
|
|
632
|
-
const scopedNested = await buildAccessScopedWhere(quantifierValue, related.listConfig, related.listName, config, args, resolveSyntheticRelation);
|
|
633
|
-
nestedEntry[quantifier] = accessWhere
|
|
634
|
-
? andWhere(accessWhere, scopedNested)
|
|
635
|
-
: scopedNested;
|
|
636
|
-
}
|
|
637
|
-
result[key] = nestedEntry;
|
|
638
|
-
}
|
|
639
|
-
else {
|
|
640
|
-
// Prisma's direct-nesting to-one form: the whole value IS the nested
|
|
641
|
-
// WHERE clause, with no `is` wrapper. Only wrap it in `is` when there is
|
|
642
|
-
// an access filter to fold in — an unwrapped value that needs no fold
|
|
643
|
-
// (fully-allowed related list) is returned exactly as the caller wrote
|
|
644
|
-
// it, so an already-permitted query is not perturbed by this pass.
|
|
645
|
-
await walkWhereReadAccess(value, related.listConfig, related.listName, args);
|
|
646
|
-
const scopedNested = await buildAccessScopedWhere(value, related.listConfig, related.listName, config, args, resolveSyntheticRelation);
|
|
647
|
-
result[key] = accessWhere
|
|
648
|
-
? { is: andWhere(accessWhere, scopedNested) }
|
|
649
|
-
: scopedNested;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
return result;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Remove keys that correspond to `virtual` fields from a Prisma `include`
|
|
656
|
-
* object, recursing into nested relationship includes using the related
|
|
657
|
-
* list's field configs.
|
|
658
|
-
*
|
|
659
|
-
* Virtual fields are computed in JavaScript (via `resolveOutput` in
|
|
660
|
-
* `field-visibility.ts`) and have no database column. Naming one in `include`
|
|
661
|
-
* type-checks — the generated `Include` type lists every field the config
|
|
662
|
-
* declares — but Prisma throws `Unknown field '<name>' for include statement`
|
|
663
|
-
* at runtime. This is applied as the final step on whatever `include` a read
|
|
664
|
-
* op ends up with (fragment-built, access-controlled merge, or sudo
|
|
665
|
-
* passthrough) so a virtual key never reaches the Prisma client, regardless
|
|
666
|
-
* of which path produced it. The virtual value is still computed
|
|
667
|
-
* unconditionally by `filterReadableFields`, so stripping the include key has
|
|
668
|
-
* no effect on whether the value appears in the result (#628).
|
|
669
|
-
*/
|
|
670
|
-
export function stripVirtualFieldsFromInclude(include, fieldConfigs, config) {
|
|
671
|
-
if (!include)
|
|
672
|
-
return include;
|
|
673
|
-
const result = {};
|
|
674
|
-
for (const [key, value] of Object.entries(include)) {
|
|
675
|
-
const fieldConfig = fieldConfigs[key];
|
|
676
|
-
if (fieldConfig?.virtual)
|
|
677
|
-
continue;
|
|
678
|
-
const isDeclaredRelationship = fieldConfig?.type === 'relationship' && 'ref' in fieldConfig && !!fieldConfig.ref;
|
|
679
|
-
const entry = asEntryObject(value);
|
|
680
|
-
if (isDeclaredRelationship && entry?.include) {
|
|
681
|
-
const relatedConfig = getRelatedListConfig(fieldConfig.ref, config);
|
|
682
|
-
if (relatedConfig) {
|
|
683
|
-
const nestedInclude = stripVirtualFieldsFromInclude(entry.include, relatedConfig.listConfig.fields, config);
|
|
684
|
-
result[key] = { ...value, include: nestedInclude };
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
result[key] = value;
|
|
689
|
-
}
|
|
690
|
-
return result;
|
|
691
|
-
}
|
|
692
|
-
//# sourceMappingURL=access-filter.js.map
|