@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/tests/sudo.test.ts
DELETED
|
@@ -1,676 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
2
|
-
import { getContext } from '../src/context/index.js'
|
|
3
|
-
import { config, list } from '../src/config/index.js'
|
|
4
|
-
import { text, integer, relationship } from '../src/fields/index.js'
|
|
5
|
-
import type { PrismaClient } from '@prisma/client'
|
|
6
|
-
import type { Plugin } from '../src/config/types.js'
|
|
7
|
-
import type { AccessContext } from '../src/access/types.js'
|
|
8
|
-
|
|
9
|
-
describe('Sudo Context', () => {
|
|
10
|
-
// Mock Prisma client
|
|
11
|
-
const mockPrisma = {
|
|
12
|
-
post: {
|
|
13
|
-
findFirst: vi.fn(),
|
|
14
|
-
findMany: vi.fn(),
|
|
15
|
-
findUnique: vi.fn(),
|
|
16
|
-
create: vi.fn(),
|
|
17
|
-
update: vi.fn(),
|
|
18
|
-
delete: vi.fn(),
|
|
19
|
-
count: vi.fn(),
|
|
20
|
-
},
|
|
21
|
-
} as unknown as PrismaClient
|
|
22
|
-
|
|
23
|
-
// Track hook execution
|
|
24
|
-
const hookExecutions: string[] = []
|
|
25
|
-
|
|
26
|
-
const testConfig = config({
|
|
27
|
-
db: {
|
|
28
|
-
provider: 'sqlite',
|
|
29
|
-
},
|
|
30
|
-
lists: {
|
|
31
|
-
Post: list({
|
|
32
|
-
fields: {
|
|
33
|
-
title: text({
|
|
34
|
-
validation: { isRequired: true },
|
|
35
|
-
hooks: {
|
|
36
|
-
resolveInput: async ({ resolvedData, fieldKey }) => {
|
|
37
|
-
hookExecutions.push('field-resolveInput')
|
|
38
|
-
return resolvedData[fieldKey]
|
|
39
|
-
},
|
|
40
|
-
beforeOperation: async () => {
|
|
41
|
-
hookExecutions.push('field-beforeOperation')
|
|
42
|
-
},
|
|
43
|
-
afterOperation: async () => {
|
|
44
|
-
hookExecutions.push('field-afterOperation')
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
}),
|
|
48
|
-
secretField: text({
|
|
49
|
-
access: {
|
|
50
|
-
read: async () => false,
|
|
51
|
-
create: async () => false,
|
|
52
|
-
update: async () => false,
|
|
53
|
-
},
|
|
54
|
-
}),
|
|
55
|
-
views: integer({ defaultValue: 0 }),
|
|
56
|
-
},
|
|
57
|
-
access: {
|
|
58
|
-
operation: {
|
|
59
|
-
query: async () => false,
|
|
60
|
-
create: async () => false,
|
|
61
|
-
update: async () => false,
|
|
62
|
-
delete: async () => false,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
hooks: {
|
|
66
|
-
resolveInput: async ({ resolvedData }) => {
|
|
67
|
-
hookExecutions.push('list-resolveInput')
|
|
68
|
-
return resolvedData
|
|
69
|
-
},
|
|
70
|
-
validateInput: async () => {
|
|
71
|
-
hookExecutions.push('list-validateInput')
|
|
72
|
-
},
|
|
73
|
-
beforeOperation: async () => {
|
|
74
|
-
hookExecutions.push('list-beforeOperation')
|
|
75
|
-
},
|
|
76
|
-
afterOperation: async () => {
|
|
77
|
-
hookExecutions.push('list-afterOperation')
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
}),
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
vi.clearAllMocks()
|
|
86
|
-
hookExecutions.length = 0
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
describe('Query Operations', () => {
|
|
90
|
-
it('should bypass operation-level access control with sudo()', async () => {
|
|
91
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
92
|
-
const sudoContext = context.sudo()
|
|
93
|
-
|
|
94
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Test Post' }])
|
|
95
|
-
|
|
96
|
-
// Regular context should return empty array (access denied)
|
|
97
|
-
const regularResult = await context.db.post.findMany()
|
|
98
|
-
expect(regularResult).toEqual([])
|
|
99
|
-
|
|
100
|
-
// Sudo context should return results
|
|
101
|
-
const sudoResult = await sudoContext.db.post.findMany()
|
|
102
|
-
expect(sudoResult).toHaveLength(1)
|
|
103
|
-
expect(sudoResult[0].title).toBe('Test Post')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should bypass field-level read access control with sudo()', async () => {
|
|
107
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
108
|
-
const sudoContext = context.sudo()
|
|
109
|
-
|
|
110
|
-
mockPrisma.post.findFirst.mockResolvedValue({
|
|
111
|
-
id: '1',
|
|
112
|
-
title: 'Test Post',
|
|
113
|
-
secretField: 'secret-value',
|
|
114
|
-
views: 10,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// Sudo context should return all fields including secretField
|
|
118
|
-
const sudoResult = await sudoContext.db.post.findUnique({ where: { id: '1' } })
|
|
119
|
-
expect(sudoResult?.secretField).toBe('secret-value')
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('Create Operations', () => {
|
|
124
|
-
it('should bypass operation-level access control with sudo()', async () => {
|
|
125
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
126
|
-
const sudoContext = context.sudo()
|
|
127
|
-
|
|
128
|
-
const mockPost = { id: '1', title: 'New Post', views: 0 }
|
|
129
|
-
mockPrisma.post.create.mockResolvedValue(mockPost)
|
|
130
|
-
|
|
131
|
-
// Regular context should return null (access denied)
|
|
132
|
-
const regularResult = await context.db.post.create({
|
|
133
|
-
data: { title: 'New Post' },
|
|
134
|
-
})
|
|
135
|
-
expect(regularResult).toBeNull()
|
|
136
|
-
|
|
137
|
-
// Sudo context should create successfully
|
|
138
|
-
hookExecutions.length = 0
|
|
139
|
-
const sudoResult = await sudoContext.db.post.create({
|
|
140
|
-
data: { title: 'New Post' },
|
|
141
|
-
})
|
|
142
|
-
expect(sudoResult).toMatchObject({ title: 'New Post' })
|
|
143
|
-
// `views` declares `defaultValue: 0`, so the omitted value is resolved to
|
|
144
|
-
// its default before persistence (#615 resolve-then-validate).
|
|
145
|
-
expect(mockPrisma.post.create).toHaveBeenCalledWith({
|
|
146
|
-
data: { title: 'New Post', views: 0 },
|
|
147
|
-
})
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('should bypass field-level write access control with sudo()', async () => {
|
|
151
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
152
|
-
const sudoContext = context.sudo()
|
|
153
|
-
|
|
154
|
-
const mockPost = { id: '1', title: 'New Post', secretField: 'secret', views: 0 }
|
|
155
|
-
mockPrisma.post.create.mockResolvedValue(mockPost)
|
|
156
|
-
|
|
157
|
-
// Sudo context should allow writing to secretField
|
|
158
|
-
await sudoContext.db.post.create({
|
|
159
|
-
data: { title: 'New Post', secretField: 'secret' },
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
// Verify that secretField was passed to Prisma. `views` declares
|
|
163
|
-
// `defaultValue: 0`, so the omitted value is resolved to its default
|
|
164
|
-
// before persistence (#615 resolve-then-validate).
|
|
165
|
-
expect(mockPrisma.post.create).toHaveBeenCalledWith({
|
|
166
|
-
data: { title: 'New Post', secretField: 'secret', views: 0 },
|
|
167
|
-
})
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('should execute all hooks with sudo()', async () => {
|
|
171
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
172
|
-
const sudoContext = context.sudo()
|
|
173
|
-
|
|
174
|
-
const mockPost = { id: '1', title: 'New Post', views: 0 }
|
|
175
|
-
mockPrisma.post.create.mockResolvedValue(mockPost)
|
|
176
|
-
|
|
177
|
-
await sudoContext.db.post.create({
|
|
178
|
-
data: { title: 'New Post' },
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
// Verify all hooks were executed
|
|
182
|
-
expect(hookExecutions).toContain('list-resolveInput')
|
|
183
|
-
expect(hookExecutions).toContain('field-resolveInput')
|
|
184
|
-
expect(hookExecutions).toContain('list-validateInput')
|
|
185
|
-
expect(hookExecutions).toContain('field-beforeOperation')
|
|
186
|
-
expect(hookExecutions).toContain('list-beforeOperation')
|
|
187
|
-
expect(hookExecutions).toContain('list-afterOperation')
|
|
188
|
-
expect(hookExecutions).toContain('field-afterOperation')
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
it('should still validate required fields with sudo()', async () => {
|
|
192
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
193
|
-
const sudoContext = context.sudo()
|
|
194
|
-
|
|
195
|
-
// Should throw validation error for missing required field
|
|
196
|
-
await expect(
|
|
197
|
-
sudoContext.db.post.create({
|
|
198
|
-
data: { views: 10 },
|
|
199
|
-
}),
|
|
200
|
-
).rejects.toThrow('Title must be text')
|
|
201
|
-
})
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
describe('Update Operations', () => {
|
|
205
|
-
it('should bypass operation-level access control with sudo()', async () => {
|
|
206
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
207
|
-
const sudoContext = context.sudo()
|
|
208
|
-
|
|
209
|
-
const existingPost = { id: '1', title: 'Old Title', views: 5 }
|
|
210
|
-
const updatedPost = { id: '1', title: 'New Title', views: 5 }
|
|
211
|
-
|
|
212
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
213
|
-
mockPrisma.post.findFirst.mockResolvedValue(null)
|
|
214
|
-
mockPrisma.post.update.mockResolvedValue(updatedPost)
|
|
215
|
-
|
|
216
|
-
// Regular context should return null (access denied)
|
|
217
|
-
const regularResult = await context.db.post.update({
|
|
218
|
-
where: { id: '1' },
|
|
219
|
-
data: { title: 'New Title' },
|
|
220
|
-
})
|
|
221
|
-
expect(regularResult).toBeNull()
|
|
222
|
-
|
|
223
|
-
// Reset mocks
|
|
224
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
225
|
-
hookExecutions.length = 0
|
|
226
|
-
|
|
227
|
-
// Sudo context should update successfully
|
|
228
|
-
const sudoResult = await sudoContext.db.post.update({
|
|
229
|
-
where: { id: '1' },
|
|
230
|
-
data: { title: 'New Title' },
|
|
231
|
-
})
|
|
232
|
-
expect(sudoResult).toMatchObject({ title: 'New Title' })
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('should bypass field-level write access control with sudo()', async () => {
|
|
236
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
237
|
-
const sudoContext = context.sudo()
|
|
238
|
-
|
|
239
|
-
const existingPost = { id: '1', title: 'Old Title', secretField: 'old-secret', views: 5 }
|
|
240
|
-
const updatedPost = { id: '1', title: 'Old Title', secretField: 'new-secret', views: 5 }
|
|
241
|
-
|
|
242
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
243
|
-
mockPrisma.post.update.mockResolvedValue(updatedPost)
|
|
244
|
-
|
|
245
|
-
// Sudo context should allow updating secretField
|
|
246
|
-
await sudoContext.db.post.update({
|
|
247
|
-
where: { id: '1' },
|
|
248
|
-
data: { secretField: 'new-secret' },
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
// Verify that secretField was passed to Prisma
|
|
252
|
-
expect(mockPrisma.post.update).toHaveBeenCalledWith({
|
|
253
|
-
where: { id: '1' },
|
|
254
|
-
data: { secretField: 'new-secret' },
|
|
255
|
-
})
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('should execute all hooks with sudo()', async () => {
|
|
259
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
260
|
-
const sudoContext = context.sudo()
|
|
261
|
-
|
|
262
|
-
const existingPost = { id: '1', title: 'Old Title', views: 5 }
|
|
263
|
-
const updatedPost = { id: '1', title: 'New Title', views: 5 }
|
|
264
|
-
|
|
265
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
266
|
-
mockPrisma.post.update.mockResolvedValue(updatedPost)
|
|
267
|
-
|
|
268
|
-
await sudoContext.db.post.update({
|
|
269
|
-
where: { id: '1' },
|
|
270
|
-
data: { title: 'New Title' },
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
// Verify all hooks were executed
|
|
274
|
-
expect(hookExecutions).toContain('list-resolveInput')
|
|
275
|
-
expect(hookExecutions).toContain('field-resolveInput')
|
|
276
|
-
expect(hookExecutions).toContain('list-validateInput')
|
|
277
|
-
expect(hookExecutions).toContain('field-beforeOperation')
|
|
278
|
-
expect(hookExecutions).toContain('list-beforeOperation')
|
|
279
|
-
expect(hookExecutions).toContain('list-afterOperation')
|
|
280
|
-
expect(hookExecutions).toContain('field-afterOperation')
|
|
281
|
-
})
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
describe('Delete Operations', () => {
|
|
285
|
-
it('should bypass operation-level access control with sudo()', async () => {
|
|
286
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
287
|
-
const sudoContext = context.sudo()
|
|
288
|
-
|
|
289
|
-
const existingPost = { id: '1', title: 'Post to Delete', views: 5 }
|
|
290
|
-
|
|
291
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
292
|
-
mockPrisma.post.findFirst.mockResolvedValue(null)
|
|
293
|
-
mockPrisma.post.delete.mockResolvedValue(existingPost)
|
|
294
|
-
|
|
295
|
-
// Regular context should return null (access denied)
|
|
296
|
-
const regularResult = await context.db.post.delete({
|
|
297
|
-
where: { id: '1' },
|
|
298
|
-
})
|
|
299
|
-
expect(regularResult).toBeNull()
|
|
300
|
-
|
|
301
|
-
// Reset mocks
|
|
302
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
303
|
-
hookExecutions.length = 0
|
|
304
|
-
|
|
305
|
-
// Sudo context should delete successfully
|
|
306
|
-
const sudoResult = await sudoContext.db.post.delete({
|
|
307
|
-
where: { id: '1' },
|
|
308
|
-
})
|
|
309
|
-
expect(sudoResult).toMatchObject({ title: 'Post to Delete' })
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
it('should execute all hooks with sudo()', async () => {
|
|
313
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
314
|
-
const sudoContext = context.sudo()
|
|
315
|
-
|
|
316
|
-
const existingPost = { id: '1', title: 'Post to Delete', views: 5 }
|
|
317
|
-
|
|
318
|
-
mockPrisma.post.findUnique.mockResolvedValue(existingPost)
|
|
319
|
-
mockPrisma.post.delete.mockResolvedValue(existingPost)
|
|
320
|
-
|
|
321
|
-
await sudoContext.db.post.delete({
|
|
322
|
-
where: { id: '1' },
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
// Verify hooks were executed
|
|
326
|
-
expect(hookExecutions).toContain('field-beforeOperation')
|
|
327
|
-
expect(hookExecutions).toContain('list-beforeOperation')
|
|
328
|
-
expect(hookExecutions).toContain('list-afterOperation')
|
|
329
|
-
expect(hookExecutions).toContain('field-afterOperation')
|
|
330
|
-
})
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
describe('Count Operations', () => {
|
|
334
|
-
it('should bypass operation-level access control with sudo()', async () => {
|
|
335
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
336
|
-
const sudoContext = context.sudo()
|
|
337
|
-
|
|
338
|
-
mockPrisma.post.count.mockResolvedValue(10)
|
|
339
|
-
|
|
340
|
-
// Regular context should return 0 (access denied)
|
|
341
|
-
const regularResult = await context.db.post.count()
|
|
342
|
-
expect(regularResult).toBe(0)
|
|
343
|
-
|
|
344
|
-
// Sudo context should return actual count
|
|
345
|
-
const sudoResult = await sudoContext.db.post.count()
|
|
346
|
-
expect(sudoResult).toBe(10)
|
|
347
|
-
})
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
describe('Sudo Context Properties', () => {
|
|
351
|
-
it('should maintain the same session object', async () => {
|
|
352
|
-
const session = { userId: 'user-123', role: 'admin' }
|
|
353
|
-
const context = getContext(testConfig, mockPrisma, session)
|
|
354
|
-
const sudoContext = context.sudo()
|
|
355
|
-
|
|
356
|
-
expect(sudoContext.session).toEqual(session)
|
|
357
|
-
expect(sudoContext.session).toBe(context.session)
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
it('should maintain the same prisma client', async () => {
|
|
361
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
362
|
-
const sudoContext = context.sudo()
|
|
363
|
-
|
|
364
|
-
expect(sudoContext.prisma).toBe(context.prisma)
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
it('should maintain the same storage utilities', async () => {
|
|
368
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
369
|
-
const sudoContext = context.sudo()
|
|
370
|
-
|
|
371
|
-
expect(sudoContext.storage).toBe(context.storage)
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('should allow chaining sudo() calls', async () => {
|
|
375
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
376
|
-
const sudoContext1 = context.sudo()
|
|
377
|
-
const sudoContext2 = sudoContext1.sudo()
|
|
378
|
-
|
|
379
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Test Post' }])
|
|
380
|
-
|
|
381
|
-
const result = await sudoContext2.db.post.findMany()
|
|
382
|
-
expect(result).toHaveLength(1)
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
it('should create independent contexts', async () => {
|
|
386
|
-
const context = getContext(testConfig, mockPrisma, null)
|
|
387
|
-
const sudoContext = context.sudo()
|
|
388
|
-
|
|
389
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Test Post' }])
|
|
390
|
-
|
|
391
|
-
// Regular context still denies access
|
|
392
|
-
const regularResult = await context.db.post.findMany()
|
|
393
|
-
expect(regularResult).toEqual([])
|
|
394
|
-
|
|
395
|
-
// Sudo context allows access
|
|
396
|
-
const sudoResult = await sudoContext.db.post.findMany()
|
|
397
|
-
expect(sudoResult).toHaveLength(1)
|
|
398
|
-
})
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
describe('Nested Operations with Sudo Mode', () => {
|
|
402
|
-
// Mock Prisma client with User and Post models for nested operations
|
|
403
|
-
const mockPrismaWithRelations = {
|
|
404
|
-
user: {
|
|
405
|
-
findUnique: vi.fn(),
|
|
406
|
-
findMany: vi.fn(),
|
|
407
|
-
create: vi.fn(),
|
|
408
|
-
update: vi.fn(),
|
|
409
|
-
},
|
|
410
|
-
post: {
|
|
411
|
-
findUnique: vi.fn(),
|
|
412
|
-
findMany: vi.fn(),
|
|
413
|
-
create: vi.fn(),
|
|
414
|
-
update: vi.fn(),
|
|
415
|
-
},
|
|
416
|
-
} as unknown as PrismaClient
|
|
417
|
-
|
|
418
|
-
const nestedTestConfig = config({
|
|
419
|
-
db: {
|
|
420
|
-
provider: 'sqlite',
|
|
421
|
-
},
|
|
422
|
-
lists: {
|
|
423
|
-
User: list({
|
|
424
|
-
fields: {
|
|
425
|
-
email: text({ validation: { isRequired: true } }),
|
|
426
|
-
name: text(),
|
|
427
|
-
posts: relationship({ ref: 'Post.author', many: true }),
|
|
428
|
-
},
|
|
429
|
-
access: {
|
|
430
|
-
operation: {
|
|
431
|
-
create: async () => false, // Block all creates
|
|
432
|
-
update: async () => false, // Block all updates
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
}),
|
|
436
|
-
Post: list({
|
|
437
|
-
fields: {
|
|
438
|
-
title: text({ validation: { isRequired: true } }),
|
|
439
|
-
content: text(),
|
|
440
|
-
author: relationship({ ref: 'User.posts' }),
|
|
441
|
-
},
|
|
442
|
-
access: {
|
|
443
|
-
operation: {
|
|
444
|
-
create: async () => true,
|
|
445
|
-
update: async () => true,
|
|
446
|
-
},
|
|
447
|
-
},
|
|
448
|
-
}),
|
|
449
|
-
},
|
|
450
|
-
})
|
|
451
|
-
|
|
452
|
-
beforeEach(() => {
|
|
453
|
-
vi.clearAllMocks()
|
|
454
|
-
})
|
|
455
|
-
|
|
456
|
-
it('should allow nested create in sudo mode when access control would deny', async () => {
|
|
457
|
-
const context = getContext(nestedTestConfig, mockPrismaWithRelations, null)
|
|
458
|
-
const sudoContext = context.sudo()
|
|
459
|
-
|
|
460
|
-
// Mock successful creation
|
|
461
|
-
mockPrismaWithRelations.post.create.mockResolvedValue({
|
|
462
|
-
id: '1',
|
|
463
|
-
title: 'Test Post',
|
|
464
|
-
content: 'Test Content',
|
|
465
|
-
authorId: 'user-1',
|
|
466
|
-
})
|
|
467
|
-
|
|
468
|
-
// In sudo mode, nested create should succeed despite User access control blocking creates
|
|
469
|
-
const result = await sudoContext.db.post.create({
|
|
470
|
-
data: {
|
|
471
|
-
title: 'Test Post',
|
|
472
|
-
content: 'Test Content',
|
|
473
|
-
author: {
|
|
474
|
-
create: {
|
|
475
|
-
email: 'test@example.com',
|
|
476
|
-
name: 'Test User',
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
},
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
expect(result).toBeDefined()
|
|
483
|
-
expect(mockPrismaWithRelations.post.create).toHaveBeenCalled()
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
it('should allow nested connect in sudo mode when access control would deny', async () => {
|
|
487
|
-
const context = getContext(nestedTestConfig, mockPrismaWithRelations, null)
|
|
488
|
-
const sudoContext = context.sudo()
|
|
489
|
-
|
|
490
|
-
// Mock existing user
|
|
491
|
-
mockPrismaWithRelations.user.findUnique.mockResolvedValue({
|
|
492
|
-
id: 'user-1',
|
|
493
|
-
email: 'existing@example.com',
|
|
494
|
-
name: 'Existing User',
|
|
495
|
-
})
|
|
496
|
-
|
|
497
|
-
// Mock successful creation
|
|
498
|
-
mockPrismaWithRelations.post.create.mockResolvedValue({
|
|
499
|
-
id: '1',
|
|
500
|
-
title: 'Test Post',
|
|
501
|
-
content: 'Test Content',
|
|
502
|
-
authorId: 'user-1',
|
|
503
|
-
})
|
|
504
|
-
|
|
505
|
-
// In sudo mode, nested connect should succeed despite User access control blocking updates
|
|
506
|
-
const result = await sudoContext.db.post.create({
|
|
507
|
-
data: {
|
|
508
|
-
title: 'Test Post',
|
|
509
|
-
content: 'Test Content',
|
|
510
|
-
author: {
|
|
511
|
-
connect: { id: 'user-1' },
|
|
512
|
-
},
|
|
513
|
-
},
|
|
514
|
-
})
|
|
515
|
-
|
|
516
|
-
expect(result).toBeDefined()
|
|
517
|
-
expect(mockPrismaWithRelations.post.create).toHaveBeenCalled()
|
|
518
|
-
})
|
|
519
|
-
|
|
520
|
-
it('should allow nested update in sudo mode when access control would deny', async () => {
|
|
521
|
-
const context = getContext(nestedTestConfig, mockPrismaWithRelations, null)
|
|
522
|
-
const sudoContext = context.sudo()
|
|
523
|
-
|
|
524
|
-
// Mock existing post (needed for access control check in main operation)
|
|
525
|
-
mockPrismaWithRelations.post.findUnique.mockResolvedValue({
|
|
526
|
-
id: '1',
|
|
527
|
-
title: 'Original Post',
|
|
528
|
-
content: 'Original Content',
|
|
529
|
-
authorId: 'user-1',
|
|
530
|
-
})
|
|
531
|
-
|
|
532
|
-
// Mock existing user (for nested update)
|
|
533
|
-
mockPrismaWithRelations.user.findUnique.mockResolvedValue({
|
|
534
|
-
id: 'user-1',
|
|
535
|
-
email: 'existing@example.com',
|
|
536
|
-
name: 'Existing User',
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
// Mock successful update
|
|
540
|
-
mockPrismaWithRelations.post.update.mockResolvedValue({
|
|
541
|
-
id: '1',
|
|
542
|
-
title: 'Updated Post',
|
|
543
|
-
content: 'Updated Content',
|
|
544
|
-
authorId: 'user-1',
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
// In sudo mode, nested update should succeed despite User access control blocking updates
|
|
548
|
-
const result = await sudoContext.db.post.update({
|
|
549
|
-
where: { id: '1' },
|
|
550
|
-
data: {
|
|
551
|
-
title: 'Updated Post',
|
|
552
|
-
author: {
|
|
553
|
-
update: {
|
|
554
|
-
where: { id: 'user-1' },
|
|
555
|
-
data: { name: 'Updated Name' },
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
},
|
|
559
|
-
})
|
|
560
|
-
|
|
561
|
-
expect(result).toBeDefined()
|
|
562
|
-
expect(mockPrismaWithRelations.post.update).toHaveBeenCalled()
|
|
563
|
-
})
|
|
564
|
-
|
|
565
|
-
it('should allow nested connectOrCreate in sudo mode when access control would deny', async () => {
|
|
566
|
-
const context = getContext(nestedTestConfig, mockPrismaWithRelations, null)
|
|
567
|
-
const sudoContext = context.sudo()
|
|
568
|
-
|
|
569
|
-
// Mock existing user check (will find existing user)
|
|
570
|
-
mockPrismaWithRelations.user.findUnique.mockResolvedValue({
|
|
571
|
-
id: 'user-1',
|
|
572
|
-
email: 'existing@example.com',
|
|
573
|
-
name: 'Existing User',
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
// Mock successful creation
|
|
577
|
-
mockPrismaWithRelations.post.create.mockResolvedValue({
|
|
578
|
-
id: '1',
|
|
579
|
-
title: 'Test Post',
|
|
580
|
-
content: 'Test Content',
|
|
581
|
-
authorId: 'user-1',
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
// In sudo mode, nested connectOrCreate should succeed despite access control
|
|
585
|
-
const result = await sudoContext.db.post.create({
|
|
586
|
-
data: {
|
|
587
|
-
title: 'Test Post',
|
|
588
|
-
content: 'Test Content',
|
|
589
|
-
author: {
|
|
590
|
-
connectOrCreate: {
|
|
591
|
-
where: { id: 'user-1' },
|
|
592
|
-
create: {
|
|
593
|
-
email: 'new@example.com',
|
|
594
|
-
name: 'New User',
|
|
595
|
-
},
|
|
596
|
-
},
|
|
597
|
-
},
|
|
598
|
-
},
|
|
599
|
-
})
|
|
600
|
-
|
|
601
|
-
expect(result).toBeDefined()
|
|
602
|
-
expect(mockPrismaWithRelations.post.create).toHaveBeenCalled()
|
|
603
|
-
})
|
|
604
|
-
|
|
605
|
-
it('should still enforce access control in nested operations without sudo mode', async () => {
|
|
606
|
-
const context = getContext(nestedTestConfig, mockPrismaWithRelations, null)
|
|
607
|
-
|
|
608
|
-
// Mock existing user
|
|
609
|
-
mockPrismaWithRelations.user.findUnique.mockResolvedValue({
|
|
610
|
-
id: 'user-1',
|
|
611
|
-
email: 'existing@example.com',
|
|
612
|
-
name: 'Existing User',
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
// Without sudo, nested connect should fail due to User update access control
|
|
616
|
-
await expect(
|
|
617
|
-
context.db.post.create({
|
|
618
|
-
data: {
|
|
619
|
-
title: 'Test Post',
|
|
620
|
-
content: 'Test Content',
|
|
621
|
-
author: {
|
|
622
|
-
connect: { id: 'user-1' },
|
|
623
|
-
},
|
|
624
|
-
},
|
|
625
|
-
}),
|
|
626
|
-
).rejects.toThrow('Access denied')
|
|
627
|
-
})
|
|
628
|
-
})
|
|
629
|
-
|
|
630
|
-
describe('Plugin runtime sudo access', () => {
|
|
631
|
-
// A plugin's `runtime(context, sudo)` factory receives a `sudo` helper as a
|
|
632
|
-
// plain second argument — NOT a method on `AccessContext` itself. A
|
|
633
|
-
// self-referential `sudo(): AccessContext` field on that shared, widely
|
|
634
|
-
// instantiated interface was found to break TypeScript's structural
|
|
635
|
-
// checking of unrelated generated Prisma types in a downstream app
|
|
636
|
-
// (nullable JSON `CreateInput` fields); passing it as a separate argument
|
|
637
|
-
// avoids that recursion while still giving plugins (e.g. the auth
|
|
638
|
-
// plugin's getUser/getCurrentUser, see ADR-0013) an access-bypassing
|
|
639
|
-
// identity-lookup path.
|
|
640
|
-
it('passes a working sudo() as the second argument to plugin.runtime()', async () => {
|
|
641
|
-
let capturedSudo: (() => AccessContext<typeof mockPrisma>) | undefined
|
|
642
|
-
|
|
643
|
-
const plugin: Plugin = {
|
|
644
|
-
name: 'test-plugin',
|
|
645
|
-
init: async () => {},
|
|
646
|
-
runtime: (_context, sudo) => {
|
|
647
|
-
capturedSudo = sudo as () => AccessContext<typeof mockPrisma>
|
|
648
|
-
return {}
|
|
649
|
-
},
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
const pluginConfig = await config({
|
|
653
|
-
db: { provider: 'sqlite' },
|
|
654
|
-
plugins: [plugin],
|
|
655
|
-
lists: {
|
|
656
|
-
Post: list({
|
|
657
|
-
fields: { title: text({ validation: { isRequired: true } }) },
|
|
658
|
-
// Closed list: only sudo() should be able to read from it.
|
|
659
|
-
access: { operation: { query: () => false } },
|
|
660
|
-
}),
|
|
661
|
-
},
|
|
662
|
-
})
|
|
663
|
-
|
|
664
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Test Post' }])
|
|
665
|
-
|
|
666
|
-
getContext(pluginConfig, mockPrisma, null)
|
|
667
|
-
|
|
668
|
-
expect(capturedSudo).toBeTypeOf('function')
|
|
669
|
-
|
|
670
|
-
const sudoContext = capturedSudo!()
|
|
671
|
-
const sudoResult = await sudoContext.db.post.findMany()
|
|
672
|
-
expect(sudoResult).toHaveLength(1)
|
|
673
|
-
expect(sudoResult[0].title).toBe('Test Post')
|
|
674
|
-
})
|
|
675
|
-
})
|
|
676
|
-
})
|