@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,344 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { list } from '../config/index.js'
|
|
3
|
-
import { text, relationship, integer } from '../fields/index.js'
|
|
4
|
-
import type { OpenSaasConfig } from '../config/types.js'
|
|
5
|
-
import type { AccessContext } from './types.js'
|
|
6
|
-
import {
|
|
7
|
-
buildRelationshipCountSelect,
|
|
8
|
-
resolveRelationshipCountFilters,
|
|
9
|
-
isToManyRelationshipField,
|
|
10
|
-
} from './relationship-count.js'
|
|
11
|
-
import { RELATIONSHIP_COUNT_FILTER_KEY } from '../filter/types.js'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Access-scoped to-many relationship counts (issue #732). Verifies:
|
|
15
|
-
* • the filtered `_count` select folds in the related list's query access,
|
|
16
|
-
* • a denied related list is omitted (its count renders as 0, never a leak),
|
|
17
|
-
* • count-filter markers resolve to access-scoped `{ id: { in } }` via a single
|
|
18
|
-
* secured read (never a per-row query), including the fully-denied case.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// User (published-only for anon via a filter), plus a Widget list that is fully
|
|
22
|
-
// closed by default (no query access) to prove the denied path.
|
|
23
|
-
function makeConfig(): OpenSaasConfig {
|
|
24
|
-
return {
|
|
25
|
-
db: { provider: 'sqlite', prismaClientConstructor: () => null as never },
|
|
26
|
-
lists: {
|
|
27
|
-
User: list({
|
|
28
|
-
fields: {
|
|
29
|
-
name: text(),
|
|
30
|
-
posts: relationship({ ref: 'Post.author', many: true }),
|
|
31
|
-
widgets: relationship({ ref: 'Widget', many: true }),
|
|
32
|
-
manager: relationship({ ref: 'User' }), // to-one — never counted
|
|
33
|
-
},
|
|
34
|
-
access: { operation: { query: () => true } },
|
|
35
|
-
}),
|
|
36
|
-
Post: list({
|
|
37
|
-
fields: { title: text(), views: integer(), author: relationship({ ref: 'User.posts' }) },
|
|
38
|
-
// Only published posts are visible → the count must be access-scoped.
|
|
39
|
-
access: { operation: { query: () => ({ status: { equals: 'published' } }) } },
|
|
40
|
-
}),
|
|
41
|
-
// Widget ships closed (no access block) → query denied by default.
|
|
42
|
-
Widget: list({ fields: { name: text() } }),
|
|
43
|
-
},
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
|
|
45
|
-
} as any
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function makeContext(
|
|
49
|
-
findMany?: (args: unknown) => Promise<Array<Record<string, unknown>>>,
|
|
50
|
-
): AccessContext {
|
|
51
|
-
return {
|
|
52
|
-
session: null,
|
|
53
|
-
_isSudo: false,
|
|
54
|
-
_resolveOutputChain: [],
|
|
55
|
-
db: findMany ? { user: { findMany } } : {},
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal context for unit test
|
|
57
|
-
} as any
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
describe('isToManyRelationshipField', () => {
|
|
61
|
-
const config = makeConfig()
|
|
62
|
-
const userFields = config.lists.User.fields
|
|
63
|
-
it('is true only for a to-many relationship', () => {
|
|
64
|
-
expect(isToManyRelationshipField(userFields.posts)).toBe(true)
|
|
65
|
-
expect(isToManyRelationshipField(userFields.widgets)).toBe(true)
|
|
66
|
-
expect(isToManyRelationshipField(userFields.manager)).toBe(false)
|
|
67
|
-
expect(isToManyRelationshipField(userFields.name)).toBe(false)
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
describe('buildRelationshipCountSelect', () => {
|
|
72
|
-
it("folds the related list's query filter into each to-many count and omits denied/to-one", async () => {
|
|
73
|
-
const config = makeConfig()
|
|
74
|
-
const select = await buildRelationshipCountSelect(
|
|
75
|
-
config.lists.User,
|
|
76
|
-
{ session: null, context: makeContext() },
|
|
77
|
-
config,
|
|
78
|
-
)
|
|
79
|
-
// `posts` → access-scoped where; `widgets` → denied (omitted); `manager` →
|
|
80
|
-
// to-one (never counted).
|
|
81
|
-
expect(select).toEqual({ posts: { where: { status: { equals: 'published' } } } })
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('uses a bare `true` when the related list is fully readable', async () => {
|
|
85
|
-
const config: OpenSaasConfig = {
|
|
86
|
-
db: { provider: 'sqlite', prismaClientConstructor: () => null as never },
|
|
87
|
-
lists: {
|
|
88
|
-
Tag: list({ fields: { name: text() }, access: { operation: { query: () => true } } }),
|
|
89
|
-
Post: list({ fields: { title: text(), tags: relationship({ ref: 'Tag', many: true }) } }),
|
|
90
|
-
},
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
|
|
92
|
-
} as any
|
|
93
|
-
const select = await buildRelationshipCountSelect(
|
|
94
|
-
config.lists.Post,
|
|
95
|
-
{ session: null, context: makeContext() },
|
|
96
|
-
config,
|
|
97
|
-
)
|
|
98
|
-
expect(select).toEqual({ tags: true })
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('returns undefined when there are no countable to-many relationships', async () => {
|
|
102
|
-
const config: OpenSaasConfig = {
|
|
103
|
-
db: { provider: 'sqlite', prismaClientConstructor: () => null as never },
|
|
104
|
-
lists: { Post: list({ fields: { title: text() } }) },
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
|
|
106
|
-
} as any
|
|
107
|
-
const select = await buildRelationshipCountSelect(
|
|
108
|
-
config.lists.Post,
|
|
109
|
-
{ session: null, context: makeContext() },
|
|
110
|
-
config,
|
|
111
|
-
)
|
|
112
|
-
expect(select).toBeUndefined()
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
// Issue #1111: a relationship hidden via field-level `read` access must not
|
|
116
|
-
// leak its true count, even when the related list's rows are otherwise
|
|
117
|
-
// fully readable — the same denial an ordinary `include` of that field
|
|
118
|
-
// already gets from `filterReadableFields`'s `checkFieldAccess` call.
|
|
119
|
-
it('omits a relation whose field-level `read` access denies it, even though the related list is fully readable', async () => {
|
|
120
|
-
const config: OpenSaasConfig = {
|
|
121
|
-
db: { provider: 'sqlite', prismaClientConstructor: () => null as never },
|
|
122
|
-
lists: {
|
|
123
|
-
User: list({
|
|
124
|
-
fields: {
|
|
125
|
-
name: text(),
|
|
126
|
-
posts: relationship({
|
|
127
|
-
ref: 'Post.author',
|
|
128
|
-
many: true,
|
|
129
|
-
access: { read: () => false },
|
|
130
|
-
}),
|
|
131
|
-
},
|
|
132
|
-
access: { operation: { query: () => true } },
|
|
133
|
-
}),
|
|
134
|
-
Post: list({
|
|
135
|
-
fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
|
|
136
|
-
access: { operation: { query: () => true } },
|
|
137
|
-
}),
|
|
138
|
-
},
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
|
|
140
|
-
} as any
|
|
141
|
-
|
|
142
|
-
const select = await buildRelationshipCountSelect(
|
|
143
|
-
config.lists.User,
|
|
144
|
-
{ session: null, context: makeContext() },
|
|
145
|
-
config,
|
|
146
|
-
)
|
|
147
|
-
expect(select).toBeUndefined()
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
describe('resolveRelationshipCountFilters', () => {
|
|
152
|
-
const marker = (operator: string, value: number) => ({
|
|
153
|
-
posts: { [RELATIONSHIP_COUNT_FILTER_KEY]: { operator, value } },
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('returns the where unchanged when there are no count markers', async () => {
|
|
157
|
-
const config = makeConfig()
|
|
158
|
-
const where = { name: { contains: 'ada' } }
|
|
159
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
160
|
-
where,
|
|
161
|
-
config.lists.User,
|
|
162
|
-
'User',
|
|
163
|
-
{ session: null, context: makeContext() },
|
|
164
|
-
config,
|
|
165
|
-
)
|
|
166
|
-
expect(resolved).toBe(where)
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('resolves a count marker to an access-scoped { id: { in } } via a single secured read', async () => {
|
|
170
|
-
const config = makeConfig()
|
|
171
|
-
// Two users; the secured read returns each with its access-scoped `_count`.
|
|
172
|
-
const findMany = vi.fn(async () => [
|
|
173
|
-
{ id: 'u1', _count: { posts: 3 } },
|
|
174
|
-
{ id: 'u2', _count: { posts: 7 } },
|
|
175
|
-
])
|
|
176
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
177
|
-
marker('gt', 5),
|
|
178
|
-
config.lists.User,
|
|
179
|
-
'User',
|
|
180
|
-
{ session: null, context: makeContext(findMany) },
|
|
181
|
-
config,
|
|
182
|
-
)
|
|
183
|
-
// Only u2 (7 > 5) matches; the read was access-scoped (published-only count).
|
|
184
|
-
expect(resolved).toEqual({ id: { in: ['u2'] } })
|
|
185
|
-
expect(findMany).toHaveBeenCalledTimes(1)
|
|
186
|
-
expect(findMany).toHaveBeenCalledWith({
|
|
187
|
-
include: { _count: { select: { posts: { where: { status: { equals: 'published' } } } } } },
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
it('includes zero-count rows for comparisons that admit zero (no complement bug)', async () => {
|
|
192
|
-
const config = makeConfig()
|
|
193
|
-
const findMany = vi.fn(async () => [
|
|
194
|
-
{ id: 'u1', _count: { posts: 0 } },
|
|
195
|
-
{ id: 'u2', _count: { posts: 4 } },
|
|
196
|
-
])
|
|
197
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
198
|
-
marker('lt', 1), // count < 1 → only the zero-count user
|
|
199
|
-
config.lists.User,
|
|
200
|
-
'User',
|
|
201
|
-
{ session: null, context: makeContext(findMany) },
|
|
202
|
-
config,
|
|
203
|
-
)
|
|
204
|
-
expect(resolved).toEqual({ id: { in: ['u1'] } })
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
it('resolves a denied related list without any query: count is always 0', async () => {
|
|
208
|
-
const config = makeConfig()
|
|
209
|
-
const findMany = vi.fn(async () => [])
|
|
210
|
-
// `widgets`' related list (Widget) is fully denied → every count is 0.
|
|
211
|
-
const where = { widgets: { [RELATIONSHIP_COUNT_FILTER_KEY]: { operator: 'gt', value: 5 } } }
|
|
212
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
213
|
-
where,
|
|
214
|
-
config.lists.User,
|
|
215
|
-
'User',
|
|
216
|
-
{ session: null, context: makeContext(findMany) },
|
|
217
|
-
config,
|
|
218
|
-
)
|
|
219
|
-
// 0 is not > 5 → nothing matches, and no read was issued.
|
|
220
|
-
expect(resolved).toEqual({ id: { in: [] } })
|
|
221
|
-
expect(findMany).not.toHaveBeenCalled()
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
// Issue #1111: a relationship denied at the FIELD level (as opposed to the
|
|
225
|
-
// related list's operation-level `query` access, covered above) must also
|
|
226
|
-
// resolve to "always 0, no query needed" — the related list here (Post) is
|
|
227
|
-
// otherwise fully readable, so only the field-level check on `posts` itself
|
|
228
|
-
// can be what's denying it.
|
|
229
|
-
it('resolves a field-level-denied relationship without any query: count is always 0', async () => {
|
|
230
|
-
const config: OpenSaasConfig = {
|
|
231
|
-
db: { provider: 'sqlite', prismaClientConstructor: () => null as never },
|
|
232
|
-
lists: {
|
|
233
|
-
User: list({
|
|
234
|
-
fields: {
|
|
235
|
-
name: text(),
|
|
236
|
-
posts: relationship({
|
|
237
|
-
ref: 'Post.author',
|
|
238
|
-
many: true,
|
|
239
|
-
access: { read: () => false },
|
|
240
|
-
}),
|
|
241
|
-
},
|
|
242
|
-
access: { operation: { query: () => true } },
|
|
243
|
-
}),
|
|
244
|
-
Post: list({
|
|
245
|
-
fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
|
|
246
|
-
access: { operation: { query: () => true } },
|
|
247
|
-
}),
|
|
248
|
-
},
|
|
249
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
|
|
250
|
-
} as any
|
|
251
|
-
const findMany = vi.fn(async () => [])
|
|
252
|
-
const where = { posts: { [RELATIONSHIP_COUNT_FILTER_KEY]: { operator: 'gt', value: 0 } } }
|
|
253
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
254
|
-
where,
|
|
255
|
-
config.lists.User,
|
|
256
|
-
'User',
|
|
257
|
-
{ session: null, context: makeContext(findMany) },
|
|
258
|
-
config,
|
|
259
|
-
)
|
|
260
|
-
expect(resolved).toEqual({ id: { in: [] } })
|
|
261
|
-
expect(findMany).not.toHaveBeenCalled()
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
it('preserves sibling conditions, ANDing the resolved id constraint', async () => {
|
|
265
|
-
const config = makeConfig()
|
|
266
|
-
const findMany = vi.fn(async () => [{ id: 'u2', _count: { posts: 7 } }])
|
|
267
|
-
const where = { AND: [{ name: { contains: 'ada' } }, marker('gte', 1)] }
|
|
268
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
269
|
-
where,
|
|
270
|
-
config.lists.User,
|
|
271
|
-
'User',
|
|
272
|
-
{ session: null, context: makeContext(findMany) },
|
|
273
|
-
config,
|
|
274
|
-
)
|
|
275
|
-
expect(resolved).toEqual({ AND: [{ name: { contains: 'ada' } }, { id: { in: ['u2'] } }] })
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
it('reads with only the filtered `_count` include — no over-fetching `select` projection', async () => {
|
|
279
|
-
const config = makeConfig()
|
|
280
|
-
const findMany = vi.fn((_args: unknown) =>
|
|
281
|
-
Promise.resolve([{ id: 'u2', _count: { posts: 7 } }]),
|
|
282
|
-
)
|
|
283
|
-
await resolveRelationshipCountFilters(
|
|
284
|
-
marker('gt', 5),
|
|
285
|
-
config.lists.User,
|
|
286
|
-
'User',
|
|
287
|
-
{ session: null, context: makeContext(findMany) },
|
|
288
|
-
config,
|
|
289
|
-
)
|
|
290
|
-
// The secured read is issued with the access-scoped `_count` include and NO
|
|
291
|
-
// `select` — the secured findMany does not honour `select`, so forcing one
|
|
292
|
-
// would be an ignored no-op. Access-scoping lives entirely in `_count.where`.
|
|
293
|
-
expect(findMany).toHaveBeenCalledTimes(1)
|
|
294
|
-
const callArg = findMany.mock.calls[0][0]
|
|
295
|
-
expect(callArg).not.toHaveProperty('select')
|
|
296
|
-
expect(callArg).toEqual({
|
|
297
|
-
include: { _count: { select: { posts: { where: { status: { equals: 'published' } } } } } },
|
|
298
|
-
})
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
it('preserves a sibling condition co-present in the same member as the marker', async () => {
|
|
302
|
-
const config = makeConfig()
|
|
303
|
-
const findMany = vi.fn(async () => [{ id: 'u2', _count: { posts: 7 } }])
|
|
304
|
-
// A single AND-member carrying BOTH a scalar condition and the count marker.
|
|
305
|
-
// The marker resolution must keep the co-present sibling, not replace the
|
|
306
|
-
// member wholesale (guards against a future filter-engine change that merges
|
|
307
|
-
// conditions into one member).
|
|
308
|
-
const where = {
|
|
309
|
-
AND: [
|
|
310
|
-
{
|
|
311
|
-
name: { contains: 'ada' },
|
|
312
|
-
posts: { [RELATIONSHIP_COUNT_FILTER_KEY]: { operator: 'gt', value: 5 } },
|
|
313
|
-
},
|
|
314
|
-
],
|
|
315
|
-
}
|
|
316
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
317
|
-
where,
|
|
318
|
-
config.lists.User,
|
|
319
|
-
'User',
|
|
320
|
-
{ session: null, context: makeContext(findMany) },
|
|
321
|
-
config,
|
|
322
|
-
)
|
|
323
|
-
expect(resolved).toEqual({ name: { contains: 'ada' }, id: { in: ['u2'] } })
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
it('ANDs the resolved id constraint with a co-present sibling id condition (no silent drop)', async () => {
|
|
327
|
-
const config = makeConfig()
|
|
328
|
-
const findMany = vi.fn(async () => [{ id: 'u2', _count: { posts: 7 } }])
|
|
329
|
-
// Contrived: a member carrying its own `id` condition alongside the marker.
|
|
330
|
-
// Spreading would let one `id` overwrite the other; instead both are ANDed.
|
|
331
|
-
const where = {
|
|
332
|
-
id: { in: ['u1', 'u2'] },
|
|
333
|
-
posts: { [RELATIONSHIP_COUNT_FILTER_KEY]: { operator: 'gt', value: 5 } },
|
|
334
|
-
}
|
|
335
|
-
const resolved = await resolveRelationshipCountFilters(
|
|
336
|
-
where,
|
|
337
|
-
config.lists.User,
|
|
338
|
-
'User',
|
|
339
|
-
{ session: null, context: makeContext(findMany) },
|
|
340
|
-
config,
|
|
341
|
-
)
|
|
342
|
-
expect(resolved).toEqual({ AND: [{ id: { in: ['u1', 'u2'] } }, { id: { in: ['u2'] } }] })
|
|
343
|
-
})
|
|
344
|
-
})
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import type { Session, AccessContext, PrismaFilter, FieldAccess } from './types.js'
|
|
2
|
-
import type { OpenSaasConfig, ListConfig, FieldConfig } from '../config/types.js'
|
|
3
|
-
import type { FilterOperator, RelationshipCountFilterMarker } from '../filter/types.js'
|
|
4
|
-
import { RELATIONSHIP_COUNT_FILTER_KEY } from '../filter/types.js'
|
|
5
|
-
import { checkAccess, getRelatedListConfig } from './engine.js'
|
|
6
|
-
import { isFieldReadableForPredicate } from './field-access.js'
|
|
7
|
-
import { getDbKey } from '../lib/case-utils.js'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Access-scoped to-many relationship counts for the admin list view (issue
|
|
11
|
-
* #732).
|
|
12
|
-
*
|
|
13
|
-
* A to-many relationship column shows the count of the related rows the session
|
|
14
|
-
* may see — fetched in the SAME query as the row via Prisma's filtered
|
|
15
|
-
* `_count` (`_count: { select: { orders: { where: <access filter> } } }`), so no
|
|
16
|
-
* per-row query is issued and the count can never include rows the session
|
|
17
|
-
* cannot read. This module is the single place the related list's
|
|
18
|
-
* operation-level `query` access, AND the counting list's own field-level
|
|
19
|
-
* `read` access on the relationship field being counted (issue #1111), are
|
|
20
|
-
* folded into that `_count`, mirroring how `buildAccessScopedInclude` folds
|
|
21
|
-
* both into relation includes.
|
|
22
|
-
*
|
|
23
|
-
* It also resolves the count Filter spec's markers: Prisma cannot compare a
|
|
24
|
-
* relation count in a `where`, so a to-many relationship's Filter spec emits a
|
|
25
|
-
* {@link RELATIONSHIP_COUNT_FILTER_KEY} marker that
|
|
26
|
-
* {@link resolveRelationshipCountFilters} turns into an access-scoped
|
|
27
|
-
* `{ id: { in } }` before the query runs — never leaking counts of related rows
|
|
28
|
-
* the session cannot see.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
type CountArgs = {
|
|
32
|
-
session: Session | null
|
|
33
|
-
context: AccessContext
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Whether a field is a to-many relationship — the only field kind that carries a
|
|
38
|
-
* relationship count (a to-one relationship has at most one related row).
|
|
39
|
-
*/
|
|
40
|
-
export function isToManyRelationshipField(field: FieldConfig | undefined): boolean {
|
|
41
|
-
return (
|
|
42
|
-
field?.type === 'relationship' &&
|
|
43
|
-
'many' in field &&
|
|
44
|
-
field.many === true &&
|
|
45
|
-
'ref' in field &&
|
|
46
|
-
typeof field.ref === 'string' &&
|
|
47
|
-
field.ref.length > 0
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** The per-relation entry the count `_count.select` uses for one relationship. */
|
|
52
|
-
export type CountAccessEntry =
|
|
53
|
-
| { kind: 'all' } // related list fully readable → count every related row
|
|
54
|
-
| { kind: 'scoped'; where: PrismaFilter } // count only rows matching the access filter
|
|
55
|
-
| { kind: 'denied' } // related list not readable at all → count is always 0
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Resolve one related list's operation-level `query` access, and — when the
|
|
59
|
-
* counting list has a field of its own for the relationship being counted —
|
|
60
|
-
* that field's own field-level `read` access, into the entry its `_count`
|
|
61
|
-
* select needs. The shared decision both `relationshipCountAccessEntry` below
|
|
62
|
-
* (field → related list, for this module's own admin-list-view and
|
|
63
|
-
* count-filter callers) and `access-filter.ts`'s caller-`_count` scoping
|
|
64
|
-
* (issue #1087, which already has the related list resolved — including a
|
|
65
|
-
* synthetic back-relation's, which has no field of its own on the counting
|
|
66
|
-
* list) build on.
|
|
67
|
-
*
|
|
68
|
-
* `fieldAccess` is the COUNTING list's own relationship field access — not
|
|
69
|
-
* the related list's — mirroring the check `filterReadableFields`
|
|
70
|
-
* (`field-visibility.ts`) runs before returning an ordinary `include` of that
|
|
71
|
-
* same field (issue #1111: a `_count` used to leak the true count of a
|
|
72
|
-
* relationship whose field-level `read` access denied the relationship
|
|
73
|
-
* itself, even when the related list's own rows were otherwise fully
|
|
74
|
-
* readable). Evaluated via `isFieldReadableForPredicate` — the pre-query
|
|
75
|
-
* evaluator #915 already built for the identical problem on `where`/`orderBy`
|
|
76
|
-
* — since there is no fetched row yet at `_count`-select-build time; a rule
|
|
77
|
-
* that depends on one denies here, the same as it would there. Checked BEFORE
|
|
78
|
-
* the related list's `query` access so a field-level denial short-circuits
|
|
79
|
-
* without needing the related list's access rule at all. Omitted entirely
|
|
80
|
-
* (`undefined`) for a synthetic back-relation, which has no field of its own
|
|
81
|
-
* on the counting list to evaluate.
|
|
82
|
-
*/
|
|
83
|
-
export async function resolveCountAccessEntryForList(
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
85
|
-
relatedListConfig: ListConfig<any>,
|
|
86
|
-
args: CountArgs,
|
|
87
|
-
fieldAccess?: FieldAccess,
|
|
88
|
-
): Promise<CountAccessEntry> {
|
|
89
|
-
if (fieldAccess) {
|
|
90
|
-
const canReadField = await isFieldReadableForPredicate(fieldAccess, args)
|
|
91
|
-
if (!canReadField) return { kind: 'denied' }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const queryAccess = relatedListConfig.access?.operation?.query
|
|
95
|
-
const result = await checkAccess(queryAccess, { session: args.session, context: args.context })
|
|
96
|
-
|
|
97
|
-
if (result === false) return { kind: 'denied' }
|
|
98
|
-
if (typeof result === 'object') return { kind: 'scoped', where: result }
|
|
99
|
-
return { kind: 'all' }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Resolve the related list's operation-level `query` access for one to-many
|
|
104
|
-
* relationship into the entry its `_count` select needs. Returns `null` when the
|
|
105
|
-
* field is not a resolvable to-many relationship.
|
|
106
|
-
*/
|
|
107
|
-
async function relationshipCountAccessEntry(
|
|
108
|
-
field: FieldConfig | undefined,
|
|
109
|
-
args: CountArgs,
|
|
110
|
-
config: OpenSaasConfig,
|
|
111
|
-
): Promise<CountAccessEntry | null> {
|
|
112
|
-
if (!field || !isToManyRelationshipField(field) || !('ref' in field)) {
|
|
113
|
-
return null
|
|
114
|
-
}
|
|
115
|
-
const ref = field.ref
|
|
116
|
-
if (typeof ref !== 'string') return null
|
|
117
|
-
const related = getRelatedListConfig(ref, config)
|
|
118
|
-
if (!related) return null
|
|
119
|
-
|
|
120
|
-
return resolveCountAccessEntryForList(related.listConfig, args, field.access)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Build the object to place at `include._count.select` for a list's to-many
|
|
125
|
-
* relationships, with each related list's `query` access folded into the
|
|
126
|
-
* per-relation `where` so the returned counts are access-scoped. A relationship
|
|
127
|
-
* whose related list is fully denied is omitted (its count renders as 0). Returns
|
|
128
|
-
* `undefined` when the list has no countable to-many relationships.
|
|
129
|
-
*/
|
|
130
|
-
export async function buildRelationshipCountSelect(
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
132
|
-
listConfig: ListConfig<any>,
|
|
133
|
-
args: CountArgs,
|
|
134
|
-
config: OpenSaasConfig,
|
|
135
|
-
): Promise<Record<string, unknown> | undefined> {
|
|
136
|
-
const select: Record<string, unknown> = {}
|
|
137
|
-
for (const [fieldName, field] of Object.entries(listConfig.fields)) {
|
|
138
|
-
const entry = await relationshipCountAccessEntry(field, args, config)
|
|
139
|
-
if (entry === null || entry.kind === 'denied') continue
|
|
140
|
-
select[fieldName] = entry.kind === 'scoped' ? { where: entry.where } : true
|
|
141
|
-
}
|
|
142
|
-
return Object.keys(select).length > 0 ? select : undefined
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function readRelationshipCount(row: Record<string, unknown>, fieldName: string): number {
|
|
146
|
-
const counts = row._count
|
|
147
|
-
if (counts && typeof counts === 'object') {
|
|
148
|
-
const value = (counts as Record<string, unknown>)[fieldName]
|
|
149
|
-
if (typeof value === 'number') return value
|
|
150
|
-
}
|
|
151
|
-
return 0
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function matchesCount(count: number, operator: FilterOperator, value: number): boolean {
|
|
155
|
-
switch (operator) {
|
|
156
|
-
case 'eq':
|
|
157
|
-
return count === value
|
|
158
|
-
case 'gt':
|
|
159
|
-
return count > value
|
|
160
|
-
case 'gte':
|
|
161
|
-
return count >= value
|
|
162
|
-
case 'lt':
|
|
163
|
-
return count < value
|
|
164
|
-
case 'lte':
|
|
165
|
-
return count <= value
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Minimal shape the resolver needs off the secured `context.db` delegate. */
|
|
170
|
-
interface CountFindManyDelegate {
|
|
171
|
-
findMany: (args: { include: { _count: { select: Record<string, unknown> } } }) => Promise<unknown>
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function asCountDelegate(value: unknown): CountFindManyDelegate | null {
|
|
175
|
-
if (value && typeof value === 'object' && 'findMany' in value) {
|
|
176
|
-
const candidate = value as { findMany?: unknown }
|
|
177
|
-
if (typeof candidate.findMany === 'function') {
|
|
178
|
-
return value as CountFindManyDelegate
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return null
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function readCountMarker(value: unknown): RelationshipCountFilterMarker | null {
|
|
185
|
-
if (!value || typeof value !== 'object') return null
|
|
186
|
-
const marker = (value as Record<string, unknown>)[RELATIONSHIP_COUNT_FILTER_KEY]
|
|
187
|
-
if (!marker || typeof marker !== 'object') return null
|
|
188
|
-
const { operator, value: n } = marker as { operator?: unknown; value?: unknown }
|
|
189
|
-
if (
|
|
190
|
-
(operator === 'eq' ||
|
|
191
|
-
operator === 'gt' ||
|
|
192
|
-
operator === 'gte' ||
|
|
193
|
-
operator === 'lt' ||
|
|
194
|
-
operator === 'lte') &&
|
|
195
|
-
typeof n === 'number'
|
|
196
|
-
) {
|
|
197
|
-
return { operator, value: n }
|
|
198
|
-
}
|
|
199
|
-
return null
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Resolve one to-many relationship count-filter marker into a Prisma `where`
|
|
204
|
-
* fragment constraining the parent by id. Runs a single access-scoped read
|
|
205
|
-
* through the SECURED context — never a raw/unscoped query and never a per-row
|
|
206
|
-
* query — computing the access-visible count per parent and keeping the ids
|
|
207
|
-
* whose count satisfies the comparison. A fully-denied related list makes every
|
|
208
|
-
* count 0, resolved without any query.
|
|
209
|
-
*/
|
|
210
|
-
async function resolveOneCountFilter(
|
|
211
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
212
|
-
listConfig: ListConfig<any>,
|
|
213
|
-
listKey: string,
|
|
214
|
-
fieldName: string,
|
|
215
|
-
marker: RelationshipCountFilterMarker,
|
|
216
|
-
args: CountArgs,
|
|
217
|
-
config: OpenSaasConfig,
|
|
218
|
-
): Promise<PrismaFilter> {
|
|
219
|
-
const field = listConfig.fields[fieldName]
|
|
220
|
-
const entry = await relationshipCountAccessEntry(field, args, config)
|
|
221
|
-
|
|
222
|
-
// Not resolvable (shouldn't happen for a marker the spec emitted) → no-op.
|
|
223
|
-
if (entry === null) return {}
|
|
224
|
-
|
|
225
|
-
// Related list fully denied → every parent's access-visible count is 0.
|
|
226
|
-
if (entry.kind === 'denied') {
|
|
227
|
-
return matchesCount(0, marker.operator, marker.value) ? {} : { id: { in: [] } }
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const delegate = asCountDelegate(args.context.db[getDbKey(listKey)])
|
|
231
|
-
if (!delegate) return {}
|
|
232
|
-
|
|
233
|
-
const countSelect = entry.kind === 'scoped' ? { where: entry.where } : true
|
|
234
|
-
// This over-fetches the parent's scalar columns — it reads only `id` + `_count`
|
|
235
|
-
// per row yet materialises every scalar. It is left un-narrowed on purpose: the
|
|
236
|
-
// secured `context.db` `findMany` does NOT honour Prisma `select` (it
|
|
237
|
-
// warns-and-ignores it and returns the full access-filtered record — see
|
|
238
|
-
// `warnIfSelectIgnored` in context/index.ts and the "Narrowing Reads" note in
|
|
239
|
-
// packages/core/CLAUDE.md). The only supported narrowing is `include`/fragment
|
|
240
|
-
// `query`, neither of which can drop scalar columns. So adding
|
|
241
|
-
// `select: { id: true, _count: {...} }` here would be a silent no-op that also
|
|
242
|
-
// trips the ignore-warning, not a real projection. The count stays access-scoped
|
|
243
|
-
// via the filtered `_count` include below regardless; trimming the projection
|
|
244
|
-
// would first require the read pipeline to honour `select`.
|
|
245
|
-
const rows = await delegate.findMany({
|
|
246
|
-
include: { _count: { select: { [fieldName]: countSelect } } },
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
const matchingIds: string[] = []
|
|
250
|
-
if (Array.isArray(rows)) {
|
|
251
|
-
for (const row of rows) {
|
|
252
|
-
if (!row || typeof row !== 'object') continue
|
|
253
|
-
const record = row as Record<string, unknown>
|
|
254
|
-
if (matchesCount(readRelationshipCount(record, fieldName), marker.operator, marker.value)) {
|
|
255
|
-
matchingIds.push(String(record.id))
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return { id: { in: matchingIds } }
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Merge a filter-member's non-resolved sibling conditions with a resolved
|
|
264
|
-
* access-scoped fragment (e.g. a count marker's `{ id: { in } }`, or a to-one
|
|
265
|
-
* label filter's access-scoped `is`). With no siblings (the guaranteed case
|
|
266
|
-
* today) this is just the resolved fragment. When a sibling shares a key with
|
|
267
|
-
* the resolved fragment — a contrived case that cannot arise under the current
|
|
268
|
-
* one-condition-per-member invariant — both are ANDed so neither condition is
|
|
269
|
-
* silently lost. Shared by both relationship resolvers in this module and in
|
|
270
|
-
* `relationship-label-filter.ts`.
|
|
271
|
-
*/
|
|
272
|
-
export function mergeResolvedMember(
|
|
273
|
-
siblings: Record<string, unknown>,
|
|
274
|
-
resolved: Record<string, unknown>,
|
|
275
|
-
): Record<string, unknown> {
|
|
276
|
-
if (Object.keys(siblings).length === 0) return resolved
|
|
277
|
-
const collides = Object.keys(resolved).some((key) => key in siblings)
|
|
278
|
-
return collides ? { AND: [siblings, resolved] } : { ...siblings, ...resolved }
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Replace any to-many relationship count-filter markers in a filter `where` with
|
|
283
|
-
* access-scoped `{ id: { in } }` fragments. Markers only ever appear as
|
|
284
|
-
* top-level AND members (the pure filter engine pushes each field condition into
|
|
285
|
-
* the top-level AND, and never nests a marker inside the free-text OR), so this
|
|
286
|
-
* walks only the top level. Returns the `where` unchanged when it contains no
|
|
287
|
-
* markers, so lists without count filters pay nothing.
|
|
288
|
-
*/
|
|
289
|
-
export async function resolveRelationshipCountFilters(
|
|
290
|
-
where: Record<string, unknown> | undefined,
|
|
291
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
292
|
-
listConfig: ListConfig<any>,
|
|
293
|
-
listKey: string,
|
|
294
|
-
args: CountArgs,
|
|
295
|
-
config: OpenSaasConfig,
|
|
296
|
-
): Promise<Record<string, unknown> | undefined> {
|
|
297
|
-
if (!where) return where
|
|
298
|
-
|
|
299
|
-
const andValue = where.AND
|
|
300
|
-
const members: Array<Record<string, unknown>> = Array.isArray(andValue)
|
|
301
|
-
? (andValue as Array<Record<string, unknown>>)
|
|
302
|
-
: [where]
|
|
303
|
-
|
|
304
|
-
const findMarker = (
|
|
305
|
-
member: Record<string, unknown>,
|
|
306
|
-
): { field: string; marker: RelationshipCountFilterMarker } | null => {
|
|
307
|
-
for (const key of Object.keys(member)) {
|
|
308
|
-
if (!isToManyRelationshipField(listConfig.fields[key])) continue
|
|
309
|
-
const marker = readCountMarker(member[key])
|
|
310
|
-
if (marker) return { field: key, marker }
|
|
311
|
-
}
|
|
312
|
-
return null
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (!members.some((member) => findMarker(member) !== null)) {
|
|
316
|
-
return where
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const resolvedMembers: Array<Record<string, unknown>> = []
|
|
320
|
-
for (const member of members) {
|
|
321
|
-
const found = findMarker(member)
|
|
322
|
-
if (!found) {
|
|
323
|
-
resolvedMembers.push(member)
|
|
324
|
-
continue
|
|
325
|
-
}
|
|
326
|
-
const resolved = await resolveOneCountFilter(
|
|
327
|
-
listConfig,
|
|
328
|
-
listKey,
|
|
329
|
-
found.field,
|
|
330
|
-
found.marker,
|
|
331
|
-
args,
|
|
332
|
-
config,
|
|
333
|
-
)
|
|
334
|
-
// Preserve any sibling conditions rather than replacing the member
|
|
335
|
-
// wholesale — see `mergeResolvedMember` above for why.
|
|
336
|
-
const siblings: Record<string, unknown> = { ...member }
|
|
337
|
-
delete siblings[found.field]
|
|
338
|
-
resolvedMembers.push(mergeResolvedMember(siblings, resolved))
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// Drop no-op members (a fully-denied related list where 0 satisfies the
|
|
342
|
-
// comparison resolves to `{}` — matches everything, so it need not be ANDed).
|
|
343
|
-
const effective = resolvedMembers.filter((member) => Object.keys(member).length > 0)
|
|
344
|
-
if (effective.length === 0) return undefined
|
|
345
|
-
return effective.length === 1 ? effective[0] : { AND: effective }
|
|
346
|
-
}
|