@opensaas/stack-core 0.43.0 → 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 +2720 -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 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -51
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +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 -74
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -847
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1470
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -192
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3146
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -317
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
package/src/query/index.ts
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { getDbKey } from '../lib/case-utils.js'
|
|
2
|
-
|
|
3
|
-
// ─────────────────────────────────────────────────────────────
|
|
4
|
-
// Internal helpers
|
|
5
|
-
// ─────────────────────────────────────────────────────────────
|
|
6
|
-
|
|
7
|
-
type UnwrapItem<T> = NonNullable<T> extends Array<infer U> ? NonNullable<U> : NonNullable<T>
|
|
8
|
-
|
|
9
|
-
// ─────────────────────────────────────────────────────────────
|
|
10
|
-
// Core types
|
|
11
|
-
// ─────────────────────────────────────────────────────────────
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A selector for a relationship field: either a {@link Fragment} directly
|
|
15
|
-
* (shorthand), or `{ query, where?, orderBy?, take?, skip? }` to combine a
|
|
16
|
-
* fragment with Prisma filter/ordering/pagination on the nested relationship.
|
|
17
|
-
*/
|
|
18
|
-
export type RelationSelector<TRelated extends Record<string, unknown>> =
|
|
19
|
-
| Fragment<TRelated, FieldSelection<TRelated>>
|
|
20
|
-
| {
|
|
21
|
-
readonly query: Fragment<TRelated, FieldSelection<TRelated>>
|
|
22
|
-
readonly where?: Record<string, unknown>
|
|
23
|
-
readonly orderBy?: Record<string, 'asc' | 'desc'> | Array<Record<string, 'asc' | 'desc'>>
|
|
24
|
-
readonly take?: number
|
|
25
|
-
readonly skip?: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A field selection for model type `TItem`. Passing `true` for a
|
|
30
|
-
* relationship field returns the raw Prisma value and loses type narrowing —
|
|
31
|
-
* use a {@link Fragment} or {@link RelationSelector} to keep it typed.
|
|
32
|
-
*/
|
|
33
|
-
export type FieldSelection<T> = {
|
|
34
|
-
readonly [K in keyof T]?: UnwrapItem<T[K]> extends Record<string, unknown>
|
|
35
|
-
? RelationSelector<UnwrapItem<T[K]>> | true
|
|
36
|
-
: true
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A reusable, composable field-selection descriptor for model type `TItem`.
|
|
41
|
-
* Create with {@link defineFragment}.
|
|
42
|
-
*/
|
|
43
|
-
export type Fragment<TItem, TFields extends FieldSelection<TItem> = FieldSelection<TItem>> = {
|
|
44
|
-
readonly _type: 'fragment'
|
|
45
|
-
readonly _fields: TFields
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ─────────────────────────────────────────────────────────────
|
|
49
|
-
// Internal type helpers
|
|
50
|
-
// ─────────────────────────────────────────────────────────────
|
|
51
|
-
|
|
52
|
-
/** @internal Returns `never` for scalar `true` selections, so they fall to the scalar branch in {@link SelectedFields}. */
|
|
53
|
-
type ExtractFragment<TSelector> =
|
|
54
|
-
TSelector extends Fragment<infer TItem, infer TFields>
|
|
55
|
-
? Fragment<TItem, TFields>
|
|
56
|
-
: TSelector extends { readonly query: Fragment<infer TItem, infer TFields> }
|
|
57
|
-
? Fragment<TItem, TFields>
|
|
58
|
-
: never
|
|
59
|
-
|
|
60
|
-
/** @internal */
|
|
61
|
-
type SelectedFields<TItem, TFields extends FieldSelection<TItem>> = {
|
|
62
|
-
[K in keyof TFields & keyof TItem]: [ExtractFragment<TFields[K]>] extends [never]
|
|
63
|
-
? // tuple wrapping avoids the vacuous `never extends T` pitfall
|
|
64
|
-
TItem[K]
|
|
65
|
-
: TItem[K] extends Array<unknown>
|
|
66
|
-
? ResultOf<ExtractFragment<TFields[K]>>[]
|
|
67
|
-
: null extends TItem[K]
|
|
68
|
-
? ResultOf<ExtractFragment<TFields[K]>> | null
|
|
69
|
-
: undefined extends TItem[K]
|
|
70
|
-
? ResultOf<ExtractFragment<TFields[K]>> | undefined
|
|
71
|
-
: ResultOf<ExtractFragment<TFields[K]>>
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ─────────────────────────────────────────────────────────────
|
|
75
|
-
// Public type utilities
|
|
76
|
-
// ─────────────────────────────────────────────────────────────
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Infer the TypeScript result type from a {@link Fragment} — the shape
|
|
80
|
-
* `runQuery`/`runQueryOne` return at runtime for that fragment.
|
|
81
|
-
*/
|
|
82
|
-
export type ResultOf<F> =
|
|
83
|
-
F extends Fragment<infer TItem, infer TFields> ? SelectedFields<TItem, TFields> : never
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Arguments accepted by {@link runQuery}.
|
|
87
|
-
*/
|
|
88
|
-
export type QueryArgs = {
|
|
89
|
-
/** Prisma where filter — the access control layer additionally scopes results. */
|
|
90
|
-
where?: Record<string, unknown>
|
|
91
|
-
orderBy?: Record<string, 'asc' | 'desc'> | Array<Record<string, 'asc' | 'desc'>>
|
|
92
|
-
take?: number
|
|
93
|
-
skip?: number
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Compatible with the full `AccessContext` produced by `getContext()`. */
|
|
97
|
-
export interface QueryRunnerContext {
|
|
98
|
-
db: {
|
|
99
|
-
[key: string]: {
|
|
100
|
-
findMany: (args?: unknown) => Promise<unknown[]>
|
|
101
|
-
findFirst: (args?: unknown) => Promise<unknown>
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ─────────────────────────────────────────────────────────────
|
|
107
|
-
// Fragment factory
|
|
108
|
-
// ─────────────────────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Create a type-safe, reusable fragment for a given model type. Curried so
|
|
112
|
-
* TypeScript can infer the model type from the explicit type parameter and
|
|
113
|
-
* the field selection from the argument.
|
|
114
|
-
*/
|
|
115
|
-
export function defineFragment<TItem>() {
|
|
116
|
-
return function <TFields extends FieldSelection<TItem>>(
|
|
117
|
-
fields: TFields,
|
|
118
|
-
): Fragment<TItem, TFields> {
|
|
119
|
-
return { _type: 'fragment', _fields: fields }
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ─────────────────────────────────────────────────────────────
|
|
124
|
-
// Runtime helpers
|
|
125
|
-
// ─────────────────────────────────────────────────────────────
|
|
126
|
-
|
|
127
|
-
/** @internal */
|
|
128
|
-
export function isFragment(value: unknown): value is Fragment<unknown, FieldSelection<unknown>> {
|
|
129
|
-
return (
|
|
130
|
-
value !== null &&
|
|
131
|
-
typeof value === 'object' &&
|
|
132
|
-
'_type' in value &&
|
|
133
|
-
(value as { _type: unknown })._type === 'fragment'
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Build the Prisma `include` map for a field selection's nested fragments.
|
|
139
|
-
* Scalar fields (`true`) need no include entry — Prisma returns all scalar
|
|
140
|
-
* columns by default; only relationship fields backed by a Fragment or
|
|
141
|
-
* RelationSelector generate one (recursively).
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
export function buildInclude(fields: FieldSelection<unknown>): Record<string, unknown> | undefined {
|
|
145
|
-
const include: Record<string, unknown> = {}
|
|
146
|
-
let hasIncludes = false
|
|
147
|
-
|
|
148
|
-
for (const [key, value] of Object.entries(fields as Record<string, unknown>)) {
|
|
149
|
-
if (value === null || value === true || typeof value !== 'object') continue
|
|
150
|
-
|
|
151
|
-
const val = value as Record<string, unknown>
|
|
152
|
-
|
|
153
|
-
if (isFragment(val)) {
|
|
154
|
-
hasIncludes = true
|
|
155
|
-
const nestedInclude = buildInclude(val._fields as FieldSelection<unknown>)
|
|
156
|
-
include[key] = nestedInclude ? { include: nestedInclude } : true
|
|
157
|
-
continue
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if ('query' in val && isFragment(val.query)) {
|
|
161
|
-
hasIncludes = true
|
|
162
|
-
const selector = val as {
|
|
163
|
-
query: Fragment<unknown, FieldSelection<unknown>>
|
|
164
|
-
where?: Record<string, unknown>
|
|
165
|
-
orderBy?: unknown
|
|
166
|
-
take?: number
|
|
167
|
-
skip?: number
|
|
168
|
-
}
|
|
169
|
-
const nestedInclude = buildInclude(selector.query._fields as FieldSelection<unknown>)
|
|
170
|
-
const includeEntry: Record<string, unknown> = {}
|
|
171
|
-
if (selector.where !== undefined) includeEntry.where = selector.where
|
|
172
|
-
if (selector.orderBy !== undefined) includeEntry.orderBy = selector.orderBy
|
|
173
|
-
if (selector.take !== undefined) includeEntry.take = selector.take
|
|
174
|
-
if (selector.skip !== undefined) includeEntry.skip = selector.skip
|
|
175
|
-
if (nestedInclude) includeEntry.include = nestedInclude
|
|
176
|
-
include[key] = Object.keys(includeEntry).length > 0 ? includeEntry : true
|
|
177
|
-
continue
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return hasIncludes ? include : undefined
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* A snapshot of which field names a fragment selects at one nesting level,
|
|
186
|
-
* plus the same tree one level down for every relation selected via a nested
|
|
187
|
-
* Fragment/RelationSelector. `fields: undefined` means "unrestricted" — every
|
|
188
|
-
* field at this level is going to be returned, which is what a bare or
|
|
189
|
-
* `include`-based read means for the whole tree (only a `query` fragment ever
|
|
190
|
-
* produces a restricted scope, and only as deep as it names).
|
|
191
|
-
*
|
|
192
|
-
* Used to make computed-field evaluation (`filterReadableFields`) and
|
|
193
|
-
* declared-dependency folding (`foldDeclaredDependencies`) projection-aware
|
|
194
|
-
* (ADR-0027): a field not named by the scope at its level is never computed
|
|
195
|
-
* and its `needs` are never folded, because the read is never going to
|
|
196
|
-
* return it.
|
|
197
|
-
* @internal
|
|
198
|
-
*/
|
|
199
|
-
export type FieldSelectionScope = {
|
|
200
|
-
readonly fields: ReadonlySet<string> | undefined
|
|
201
|
-
readonly nested: Readonly<Record<string, FieldSelectionScope>>
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Build the `FieldSelectionScope` for one fragment's field selection,
|
|
206
|
-
* recursing into nested Fragment/RelationSelector entries the same way
|
|
207
|
-
* `buildInclude` does. A relation named with the bare `true` shorthand (no
|
|
208
|
-
* narrower nested Fragment) gets no entry in `nested`, so a level reached
|
|
209
|
-
* through it is treated as unrestricted — the caller asked for "everything"
|
|
210
|
-
* there and gave no narrower shape to restrict it with.
|
|
211
|
-
* @internal
|
|
212
|
-
*/
|
|
213
|
-
export function buildFieldSelectionScope(fields: FieldSelection<unknown>): FieldSelectionScope {
|
|
214
|
-
const fieldNames = new Set(Object.keys(fields as Record<string, unknown>))
|
|
215
|
-
const nested: Record<string, FieldSelectionScope> = {}
|
|
216
|
-
|
|
217
|
-
for (const [key, value] of Object.entries(fields as Record<string, unknown>)) {
|
|
218
|
-
if (value === null || value === true || typeof value !== 'object') continue
|
|
219
|
-
const val = value as Record<string, unknown>
|
|
220
|
-
|
|
221
|
-
if (isFragment(val)) {
|
|
222
|
-
nested[key] = buildFieldSelectionScope(val._fields as FieldSelection<unknown>)
|
|
223
|
-
continue
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if ('query' in val && isFragment(val.query)) {
|
|
227
|
-
nested[key] = buildFieldSelectionScope(
|
|
228
|
-
(val.query as Fragment<unknown, FieldSelection<unknown>>)
|
|
229
|
-
._fields as FieldSelection<unknown>,
|
|
230
|
-
)
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return { fields: fieldNames, nested }
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Recursively pick only the fields requested by a fragment from a raw Prisma
|
|
239
|
-
* result object, so the runtime shape matches `ResultOf<F>`.
|
|
240
|
-
* @internal
|
|
241
|
-
*/
|
|
242
|
-
export function pickFields<TItem, TFields extends FieldSelection<TItem>>(
|
|
243
|
-
item: TItem,
|
|
244
|
-
fields: TFields,
|
|
245
|
-
): SelectedFields<TItem, TFields> {
|
|
246
|
-
const result: Record<string, unknown> = {}
|
|
247
|
-
|
|
248
|
-
for (const [key, value] of Object.entries(fields as Record<string, unknown>)) {
|
|
249
|
-
const fieldValue = (item as Record<string, unknown>)[key]
|
|
250
|
-
|
|
251
|
-
if (value === true) {
|
|
252
|
-
result[key] = fieldValue
|
|
253
|
-
continue
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (value === null || typeof value !== 'object') continue
|
|
257
|
-
|
|
258
|
-
const val = value as Record<string, unknown>
|
|
259
|
-
|
|
260
|
-
if (isFragment(val)) {
|
|
261
|
-
if (Array.isArray(fieldValue)) {
|
|
262
|
-
result[key] = fieldValue.map((elem) =>
|
|
263
|
-
pickFields(elem as unknown, val._fields as FieldSelection<unknown>),
|
|
264
|
-
)
|
|
265
|
-
} else if (fieldValue === null || fieldValue === undefined) {
|
|
266
|
-
result[key] = fieldValue
|
|
267
|
-
} else {
|
|
268
|
-
result[key] = pickFields(fieldValue as unknown, val._fields as FieldSelection<unknown>)
|
|
269
|
-
}
|
|
270
|
-
continue
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if ('query' in val && isFragment(val.query)) {
|
|
274
|
-
const nestedFrag = val.query as Fragment<unknown, FieldSelection<unknown>>
|
|
275
|
-
if (Array.isArray(fieldValue)) {
|
|
276
|
-
result[key] = fieldValue.map((elem) =>
|
|
277
|
-
pickFields(elem as unknown, nestedFrag._fields as FieldSelection<unknown>),
|
|
278
|
-
)
|
|
279
|
-
} else if (fieldValue === null || fieldValue === undefined) {
|
|
280
|
-
result[key] = fieldValue
|
|
281
|
-
} else {
|
|
282
|
-
result[key] = pickFields(
|
|
283
|
-
fieldValue as unknown,
|
|
284
|
-
nestedFrag._fields as FieldSelection<unknown>,
|
|
285
|
-
)
|
|
286
|
-
}
|
|
287
|
-
continue
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return result as SelectedFields<TItem, TFields>
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// ─────────────────────────────────────────────────────────────
|
|
295
|
-
// Standalone query runners
|
|
296
|
-
// ─────────────────────────────────────────────────────────────
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Execute a fragment-based query against a list, returning all matching
|
|
300
|
-
* records shaped to the fragment's field selection. Calls
|
|
301
|
-
* `context.db[listKey].findMany()` under the hood, so access control still
|
|
302
|
-
* applies.
|
|
303
|
-
*/
|
|
304
|
-
export async function runQuery<TItem, TFields extends FieldSelection<TItem>>(
|
|
305
|
-
context: QueryRunnerContext,
|
|
306
|
-
listKey: string,
|
|
307
|
-
fragment: Fragment<TItem, TFields>,
|
|
308
|
-
args?: QueryArgs,
|
|
309
|
-
): Promise<SelectedFields<TItem, TFields>[]> {
|
|
310
|
-
const dbKey = getDbKey(listKey)
|
|
311
|
-
const include = buildInclude(fragment._fields as FieldSelection<unknown>)
|
|
312
|
-
|
|
313
|
-
const findManyArgs: Record<string, unknown> = {}
|
|
314
|
-
if (args?.where !== undefined) findManyArgs.where = args.where
|
|
315
|
-
if (args?.orderBy !== undefined) findManyArgs.orderBy = args.orderBy
|
|
316
|
-
if (args?.take !== undefined) findManyArgs.take = args.take
|
|
317
|
-
if (args?.skip !== undefined) findManyArgs.skip = args.skip
|
|
318
|
-
if (include) findManyArgs.include = include
|
|
319
|
-
|
|
320
|
-
const results = await context.db[dbKey].findMany(
|
|
321
|
-
Object.keys(findManyArgs).length > 0 ? findManyArgs : undefined,
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
return results.map((item) => pickFields(item as TItem, fragment._fields)) as SelectedFields<
|
|
325
|
-
TItem,
|
|
326
|
-
TFields
|
|
327
|
-
>[]
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Execute a fragment-based query that returns a single record (or `null`).
|
|
332
|
-
* Calls `context.db[listKey].findFirst()` under the hood, so access control
|
|
333
|
-
* still applies.
|
|
334
|
-
*/
|
|
335
|
-
export async function runQueryOne<TItem, TFields extends FieldSelection<TItem>>(
|
|
336
|
-
context: QueryRunnerContext,
|
|
337
|
-
listKey: string,
|
|
338
|
-
fragment: Fragment<TItem, TFields>,
|
|
339
|
-
where: Record<string, unknown>,
|
|
340
|
-
): Promise<SelectedFields<TItem, TFields> | null> {
|
|
341
|
-
const dbKey = getDbKey(listKey)
|
|
342
|
-
const include = buildInclude(fragment._fields as FieldSelection<unknown>)
|
|
343
|
-
|
|
344
|
-
const findFirstArgs: Record<string, unknown> = { where }
|
|
345
|
-
if (include) findFirstArgs.include = include
|
|
346
|
-
|
|
347
|
-
const item = await context.db[dbKey].findFirst(findFirstArgs)
|
|
348
|
-
|
|
349
|
-
if (item === null || item === undefined) return null
|
|
350
|
-
|
|
351
|
-
return pickFields(item as TItem, fragment._fields) as SelectedFields<TItem, TFields>
|
|
352
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { getRelationshipOptions } from './relationship-options.js'
|
|
3
|
-
import type { QueryRunnerContext } from './index.js'
|
|
4
|
-
import type { OpenSaasConfig } from '../config/types.js'
|
|
5
|
-
|
|
6
|
-
function makeDelegate(rows: Array<Record<string, unknown>>) {
|
|
7
|
-
return {
|
|
8
|
-
findMany: vi.fn(async (_args?: unknown) => rows),
|
|
9
|
-
findFirst: vi.fn(async (_args?: unknown) => rows[0] ?? null),
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function makeContext(
|
|
14
|
-
delegates: Record<string, ReturnType<typeof makeDelegate>>,
|
|
15
|
-
): QueryRunnerContext {
|
|
16
|
-
return { db: delegates }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const authors = [
|
|
20
|
-
{ id: 'a1', name: 'Ada Lovelace' },
|
|
21
|
-
{ id: 'a2', name: 'Alan Turing' },
|
|
22
|
-
{ id: 'a3', name: 'Grace Hopper' },
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
function makeConfig(): OpenSaasConfig {
|
|
26
|
-
return {
|
|
27
|
-
db: { provider: 'sqlite', url: 'file:./test.db' },
|
|
28
|
-
lists: {
|
|
29
|
-
Author: {
|
|
30
|
-
fields: {
|
|
31
|
-
name: { type: 'text' },
|
|
32
|
-
},
|
|
33
|
-
access: { operation: { query: () => true } },
|
|
34
|
-
},
|
|
35
|
-
NumericLabel: {
|
|
36
|
-
fields: {
|
|
37
|
-
rank: { type: 'integer' },
|
|
38
|
-
},
|
|
39
|
-
ui: { labelField: 'rank' },
|
|
40
|
-
access: { operation: { query: () => true } },
|
|
41
|
-
},
|
|
42
|
-
VirtualLabel: {
|
|
43
|
-
fields: {
|
|
44
|
-
displayName: { type: 'virtual', virtual: true },
|
|
45
|
-
},
|
|
46
|
-
ui: { labelField: 'displayName' },
|
|
47
|
-
access: { operation: { query: () => true } },
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
} as unknown as OpenSaasConfig
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
describe('getRelationshipOptions', () => {
|
|
54
|
-
it('returns { id, label }[] via a scalar-only fragment with no nested include', async () => {
|
|
55
|
-
const delegate = makeDelegate(authors)
|
|
56
|
-
const context = makeContext({ author: delegate })
|
|
57
|
-
const config = makeConfig()
|
|
58
|
-
|
|
59
|
-
const result = await getRelationshipOptions(context, config, 'Author', {})
|
|
60
|
-
|
|
61
|
-
expect(result).toEqual([
|
|
62
|
-
{ id: 'a1', label: 'Ada Lovelace' },
|
|
63
|
-
{ id: 'a2', label: 'Alan Turing' },
|
|
64
|
-
{ id: 'a3', label: 'Grace Hopper' },
|
|
65
|
-
])
|
|
66
|
-
|
|
67
|
-
const call = delegate.findMany.mock.calls[0][0] as Record<string, unknown>
|
|
68
|
-
expect(call.include).toBeUndefined()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('bounds the result by take', async () => {
|
|
72
|
-
const delegate = makeDelegate(authors.slice(0, 2))
|
|
73
|
-
const context = makeContext({ author: delegate })
|
|
74
|
-
const config = makeConfig()
|
|
75
|
-
|
|
76
|
-
await getRelationshipOptions(context, config, 'Author', { take: 2 })
|
|
77
|
-
|
|
78
|
-
expect(delegate.findMany).toHaveBeenCalledWith(expect.objectContaining({ take: 2 }))
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('orders by the label field ascending and filters via contains on a text label field', async () => {
|
|
82
|
-
const delegate = makeDelegate([authors[0]])
|
|
83
|
-
const context = makeContext({ author: delegate })
|
|
84
|
-
const config = makeConfig()
|
|
85
|
-
|
|
86
|
-
await getRelationshipOptions(context, config, 'Author', { search: 'Ada' })
|
|
87
|
-
|
|
88
|
-
expect(delegate.findMany).toHaveBeenCalledWith(
|
|
89
|
-
expect.objectContaining({
|
|
90
|
-
where: { name: { contains: 'Ada' } },
|
|
91
|
-
orderBy: { name: 'asc' },
|
|
92
|
-
}),
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('does not filter (first-N) when the label field is not a text field', async () => {
|
|
97
|
-
const rows = [{ id: 'n1', rank: 1 }]
|
|
98
|
-
const delegate = makeDelegate(rows)
|
|
99
|
-
const context = makeContext({ numericLabel: delegate })
|
|
100
|
-
const config = makeConfig()
|
|
101
|
-
|
|
102
|
-
await getRelationshipOptions(context, config, 'NumericLabel', { search: '1' })
|
|
103
|
-
|
|
104
|
-
const call = delegate.findMany.mock.calls[0][0] as Record<string, unknown>
|
|
105
|
-
expect(call.where).toBeUndefined()
|
|
106
|
-
expect(call.orderBy).toEqual({ rank: 'asc' })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('falls back to ordering by id when the label field is virtual (no backing column)', async () => {
|
|
110
|
-
const rows = [{ id: 'v1', displayName: 'Computed One' }]
|
|
111
|
-
const delegate = makeDelegate(rows)
|
|
112
|
-
const context = makeContext({ virtualLabel: delegate })
|
|
113
|
-
const config = makeConfig()
|
|
114
|
-
|
|
115
|
-
const result = await getRelationshipOptions(context, config, 'VirtualLabel', { search: 'One' })
|
|
116
|
-
|
|
117
|
-
const call = delegate.findMany.mock.calls[0][0] as Record<string, unknown>
|
|
118
|
-
// Virtual label fields have no backing column, so ordering by them would
|
|
119
|
-
// 500 in Prisma — order by id instead, and skip the text `contains` filter.
|
|
120
|
-
expect(call.orderBy).toEqual({ id: 'asc' })
|
|
121
|
-
expect(call.where).toBeUndefined()
|
|
122
|
-
expect(result).toEqual([{ id: 'v1', label: 'Computed One' }])
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it('treats a field flagged virtual via type alone as non-orderable (orders by id)', async () => {
|
|
126
|
-
const config = makeConfig()
|
|
127
|
-
// Only `type: 'virtual'` is set here (no `virtual: true`) to lock in the
|
|
128
|
-
// discriminator against future refactors.
|
|
129
|
-
;(config.lists.VirtualLabel.fields.displayName as { virtual?: boolean }).virtual = undefined
|
|
130
|
-
const delegate = makeDelegate([{ id: 'v1', displayName: 'Computed One' }])
|
|
131
|
-
const context = makeContext({ virtualLabel: delegate })
|
|
132
|
-
|
|
133
|
-
await getRelationshipOptions(context, config, 'VirtualLabel', { search: 'One' })
|
|
134
|
-
|
|
135
|
-
const call = delegate.findMany.mock.calls[0][0] as Record<string, unknown>
|
|
136
|
-
expect(call.orderBy).toEqual({ id: 'asc' })
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
it('unions currently-selected ids even when beyond take / not matching search', async () => {
|
|
140
|
-
// The bounded/search-scoped query only returns a1 (mimicking take:1 + search).
|
|
141
|
-
const primaryDelegate = makeDelegate([authors[0]])
|
|
142
|
-
const context = makeContext({ author: primaryDelegate })
|
|
143
|
-
const config = makeConfig()
|
|
144
|
-
|
|
145
|
-
// The selected-ids query (a separate findMany call) resolves a3, which fell
|
|
146
|
-
// outside the primary window.
|
|
147
|
-
primaryDelegate.findMany.mockImplementationOnce(async () => [authors[0]])
|
|
148
|
-
primaryDelegate.findMany.mockImplementationOnce(async () => [authors[2]])
|
|
149
|
-
|
|
150
|
-
const result = await getRelationshipOptions(context, config, 'Author', {
|
|
151
|
-
take: 1,
|
|
152
|
-
selectedIds: ['a3'],
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
expect(result).toEqual([
|
|
156
|
-
{ id: 'a1', label: 'Ada Lovelace' },
|
|
157
|
-
{ id: 'a3', label: 'Grace Hopper' },
|
|
158
|
-
])
|
|
159
|
-
|
|
160
|
-
const selectedCall = primaryDelegate.findMany.mock.calls[1][0] as Record<string, unknown>
|
|
161
|
-
expect(selectedCall.where).toEqual({ id: { in: ['a3'] } })
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('does not re-query when the selected id is already within the primary window', async () => {
|
|
165
|
-
const delegate = makeDelegate([authors[0]])
|
|
166
|
-
const context = makeContext({ author: delegate })
|
|
167
|
-
const config = makeConfig()
|
|
168
|
-
|
|
169
|
-
await getRelationshipOptions(context, config, 'Author', { selectedIds: ['a1'] })
|
|
170
|
-
|
|
171
|
-
expect(delegate.findMany).toHaveBeenCalledTimes(1)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('returns [] when the related list query access is denied (findMany returns [])', async () => {
|
|
175
|
-
const delegate = makeDelegate([])
|
|
176
|
-
const context = makeContext({ author: delegate })
|
|
177
|
-
const config = makeConfig()
|
|
178
|
-
|
|
179
|
-
const result = await getRelationshipOptions(context, config, 'Author', {
|
|
180
|
-
selectedIds: ['a1'],
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
expect(result).toEqual([])
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('returns [] when the related list does not exist in config', async () => {
|
|
187
|
-
const context = makeContext({})
|
|
188
|
-
const config = makeConfig()
|
|
189
|
-
|
|
190
|
-
const result = await getRelationshipOptions(context, config, 'Missing', {})
|
|
191
|
-
|
|
192
|
-
expect(result).toEqual([])
|
|
193
|
-
})
|
|
194
|
-
})
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { OpenSaasConfig } from '../config/types.js'
|
|
2
|
-
import { getLabelFieldName, getItemLabel } from '../config/label.js'
|
|
3
|
-
import { defineFragment, runQuery, type QueryRunnerContext } from './index.js'
|
|
4
|
-
|
|
5
|
-
const DEFAULT_TAKE = 50
|
|
6
|
-
|
|
7
|
-
export interface RelationshipOption {
|
|
8
|
-
id: string
|
|
9
|
-
label: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface RelationshipOptionsArgs {
|
|
13
|
-
/** Filters the label field via `contains` when it is a text field. */
|
|
14
|
-
search?: string
|
|
15
|
-
/** Bounds the primary (search-scoped) window. @default 50 */
|
|
16
|
-
take?: number
|
|
17
|
-
/** Always unioned into the result, even outside the search/take window. */
|
|
18
|
-
selectedIds?: string[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Bounded, projected fetch of `{ id, label }` options for a relationship
|
|
23
|
-
* editor — the read primitive behind the `relationshipOptions` serverAction
|
|
24
|
-
* op. Selects only `id` and the resolved label field (via
|
|
25
|
-
* {@link getLabelFieldName}), so the fragment carries no relation keys and
|
|
26
|
-
* `buildAccessScopedInclude` never has anything to scope.
|
|
27
|
-
*
|
|
28
|
-
* Operation-level `query` access on `relatedListKey` still applies — a denied
|
|
29
|
-
* list resolves to `[]` (via the underlying access-controlled `findMany`).
|
|
30
|
-
*/
|
|
31
|
-
export async function getRelationshipOptions(
|
|
32
|
-
context: QueryRunnerContext,
|
|
33
|
-
config: OpenSaasConfig,
|
|
34
|
-
relatedListKey: string,
|
|
35
|
-
args: RelationshipOptionsArgs = {},
|
|
36
|
-
): Promise<RelationshipOption[]> {
|
|
37
|
-
const relatedListConfig = config.lists[relatedListKey]
|
|
38
|
-
if (!relatedListConfig) return []
|
|
39
|
-
|
|
40
|
-
const labelField = getLabelFieldName(relatedListConfig)
|
|
41
|
-
const fragment = defineFragment<Record<string, unknown>>()({
|
|
42
|
-
id: true,
|
|
43
|
-
[labelField]: true,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const { search, take = DEFAULT_TAKE, selectedIds = [] } = args
|
|
47
|
-
const labelFieldConfig = relatedListConfig.fields[labelField] as
|
|
48
|
-
{ type?: string; virtual?: boolean } | undefined
|
|
49
|
-
const where =
|
|
50
|
-
search && labelFieldConfig?.type === 'text' ? { [labelField]: { contains: search } } : undefined
|
|
51
|
-
|
|
52
|
-
// Virtual/computed label fields (resolved at read time via `resolveOutput`)
|
|
53
|
-
// have no backing database column, so passing them into `orderBy` fails
|
|
54
|
-
// Prisma validation and 500s the request. Fall back to ordering by `id` —
|
|
55
|
-
// always a real, orderable column — whenever the label field is virtual.
|
|
56
|
-
const isVirtualLabel = labelFieldConfig?.type === 'virtual' || labelFieldConfig?.virtual === true
|
|
57
|
-
const orderBy: Record<string, 'asc'> = isVirtualLabel ? { id: 'asc' } : { [labelField]: 'asc' }
|
|
58
|
-
|
|
59
|
-
const primary = await runQuery(context, relatedListKey, fragment, {
|
|
60
|
-
where,
|
|
61
|
-
orderBy,
|
|
62
|
-
take,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const seenIds = new Set(primary.map((item) => (item as { id: string }).id))
|
|
66
|
-
const missingSelectedIds = selectedIds.filter((id) => !seenIds.has(id))
|
|
67
|
-
|
|
68
|
-
const selected = missingSelectedIds.length
|
|
69
|
-
? await runQuery(context, relatedListKey, fragment, {
|
|
70
|
-
where: { id: { in: missingSelectedIds } },
|
|
71
|
-
})
|
|
72
|
-
: []
|
|
73
|
-
|
|
74
|
-
return [...primary, ...selected].map((item) => ({
|
|
75
|
-
id: (item as { id: string }).id,
|
|
76
|
-
label: getItemLabel(relatedListConfig, item as Record<string, unknown>),
|
|
77
|
-
}))
|
|
78
|
-
}
|