@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
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { getContext } from '../src/context/index.js'
|
|
3
|
-
import { config, list } from '../src/config/index.js'
|
|
4
|
-
import { text, relationship } from '../src/fields/index.js'
|
|
5
|
-
import { ValidationError } from '../src/hooks/index.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* #978: a nested write through a list-only ref's SYNTHETIC reverse relation
|
|
9
|
-
* (`from_<SourceList>_<sourceField>`, generated because Prisma requires an
|
|
10
|
-
* opposite field but the config never declares one) must run the target
|
|
11
|
-
* list's full write pipeline — the same resolveInput/validate/field-rules/
|
|
12
|
-
* beforeOperation/afterOperation a nested write through a DECLARED
|
|
13
|
-
* relationship field gets. Before this fix, the field went unrecognised by
|
|
14
|
-
* `processNestedOperations` and was handed to Prisma completely untransformed
|
|
15
|
-
* — no hooks, no validation, silently committing whatever the caller sent.
|
|
16
|
-
*
|
|
17
|
-
* `Account` declares no relationship field back to `ChargeRequest` — only
|
|
18
|
-
* `ChargeRequest.account: relationship({ ref: 'Account' })` (list-only), so
|
|
19
|
-
* the generator synthesizes `from_ChargeRequest_account` on Account. Reachable
|
|
20
|
-
* only under `sudo()`: the undeclared-key guard refuses it otherwise (pinned
|
|
21
|
-
* below too).
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const SYNTHETIC_FIELD = 'from_ChargeRequest_account'
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A transaction-aware in-memory Prisma mock for Account (one) / ChargeRequest
|
|
28
|
-
* (many), modeling the synthetic back-relation as a real field on the Account
|
|
29
|
-
* model — exactly as Prisma's generated client would, since the field is a
|
|
30
|
-
* genuine schema artefact even though it has no entry in the OpenSaaS config.
|
|
31
|
-
*/
|
|
32
|
-
function createAccountPrisma() {
|
|
33
|
-
const tables: Record<string, Map<string, Record<string, unknown>>> = {
|
|
34
|
-
account: new Map(),
|
|
35
|
-
chargeRequest: new Map(),
|
|
36
|
-
}
|
|
37
|
-
const chargeToAccount = new Map<string, string>()
|
|
38
|
-
let idCounter = 0
|
|
39
|
-
const nextId = () => `cr-${++idCounter}`
|
|
40
|
-
|
|
41
|
-
function linkedChargeRequests(accountId: string): Array<Record<string, unknown>> {
|
|
42
|
-
const rows: Array<Record<string, unknown>> = []
|
|
43
|
-
for (const [crId, owner] of chargeToAccount.entries()) {
|
|
44
|
-
if (owner === accountId) {
|
|
45
|
-
const row = tables.chargeRequest.get(crId)
|
|
46
|
-
if (row) rows.push(row)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return rows
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function applyChargeRequestOps(accountId: string, ops: Record<string, unknown>) {
|
|
53
|
-
if (ops.create) {
|
|
54
|
-
const creates = Array.isArray(ops.create) ? ops.create : [ops.create]
|
|
55
|
-
for (const data of creates as Array<Record<string, unknown>>) {
|
|
56
|
-
const id = (data.id as string) ?? nextId()
|
|
57
|
-
tables.chargeRequest.set(id, { id, ...data })
|
|
58
|
-
chargeToAccount.set(id, accountId)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (ops.update) {
|
|
62
|
-
const updates = Array.isArray(ops.update) ? ops.update : [ops.update]
|
|
63
|
-
for (const u of updates as Array<{ where: { id: string }; data: Record<string, unknown> }>) {
|
|
64
|
-
const existing = tables.chargeRequest.get(u.where.id) ?? { id: u.where.id }
|
|
65
|
-
tables.chargeRequest.set(u.where.id, { ...existing, ...u.data })
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (ops.delete) {
|
|
69
|
-
const deletes = Array.isArray(ops.delete) ? ops.delete : [ops.delete]
|
|
70
|
-
for (const d of deletes as Array<{ id: string }>) {
|
|
71
|
-
tables.chargeRequest.delete(d.id)
|
|
72
|
-
chargeToAccount.delete(d.id)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function buildAccountResult(
|
|
78
|
-
accountId: string,
|
|
79
|
-
include?: Record<string, unknown>,
|
|
80
|
-
): Record<string, unknown> {
|
|
81
|
-
const base = tables.account.get(accountId) ?? { id: accountId }
|
|
82
|
-
if (include?.[SYNTHETIC_FIELD]) {
|
|
83
|
-
return { ...base, [SYNTHETIC_FIELD]: linkedChargeRequests(accountId) }
|
|
84
|
-
}
|
|
85
|
-
return { ...base }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const accountModel = {
|
|
89
|
-
findUnique: vi.fn(
|
|
90
|
-
async ({ where, include }: { where: { id: string }; include?: Record<string, unknown> }) => {
|
|
91
|
-
if (!tables.account.has(where.id)) return null
|
|
92
|
-
return buildAccountResult(where.id, include)
|
|
93
|
-
},
|
|
94
|
-
),
|
|
95
|
-
findFirst: vi.fn(async ({ where }: { where?: { id?: string } }) => {
|
|
96
|
-
if (where?.id) return tables.account.get(where.id) ?? null
|
|
97
|
-
return tables.account.values().next().value ?? null
|
|
98
|
-
}),
|
|
99
|
-
findMany: vi.fn(async () => Array.from(tables.account.values())),
|
|
100
|
-
count: vi.fn(async () => tables.account.size),
|
|
101
|
-
create: vi.fn(
|
|
102
|
-
async ({
|
|
103
|
-
data,
|
|
104
|
-
include,
|
|
105
|
-
}: {
|
|
106
|
-
data: Record<string, unknown>
|
|
107
|
-
include?: Record<string, unknown>
|
|
108
|
-
}) => {
|
|
109
|
-
const id = (data.id as string) ?? `a-${++idCounter}`
|
|
110
|
-
const { [SYNTHETIC_FIELD]: nested, ...scalars } = data
|
|
111
|
-
tables.account.set(id, { id, ...scalars })
|
|
112
|
-
if (nested) applyChargeRequestOps(id, nested as Record<string, unknown>)
|
|
113
|
-
return buildAccountResult(id, include)
|
|
114
|
-
},
|
|
115
|
-
),
|
|
116
|
-
update: vi.fn(
|
|
117
|
-
async ({
|
|
118
|
-
where,
|
|
119
|
-
data,
|
|
120
|
-
include,
|
|
121
|
-
}: {
|
|
122
|
-
where: { id: string }
|
|
123
|
-
data: Record<string, unknown>
|
|
124
|
-
include?: Record<string, unknown>
|
|
125
|
-
}) => {
|
|
126
|
-
const existing = tables.account.get(where.id) ?? { id: where.id }
|
|
127
|
-
const { [SYNTHETIC_FIELD]: nested, ...scalars } = data
|
|
128
|
-
tables.account.set(where.id, { ...existing, ...scalars })
|
|
129
|
-
if (nested) applyChargeRequestOps(where.id, nested as Record<string, unknown>)
|
|
130
|
-
return buildAccountResult(where.id, include)
|
|
131
|
-
},
|
|
132
|
-
),
|
|
133
|
-
delete: vi.fn(async ({ where }: { where: { id: string } }) => {
|
|
134
|
-
const existing = tables.account.get(where.id) ?? { id: where.id }
|
|
135
|
-
tables.account.delete(where.id)
|
|
136
|
-
return existing
|
|
137
|
-
}),
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function makeChargeRequestModel() {
|
|
141
|
-
return {
|
|
142
|
-
findUnique: vi.fn(
|
|
143
|
-
async ({ where }: { where: { id: string } }) => tables.chargeRequest.get(where.id) ?? null,
|
|
144
|
-
),
|
|
145
|
-
findFirst: vi.fn(async () => tables.chargeRequest.values().next().value ?? null),
|
|
146
|
-
findMany: vi.fn(async () => Array.from(tables.chargeRequest.values())),
|
|
147
|
-
count: vi.fn(async () => tables.chargeRequest.size),
|
|
148
|
-
create: vi.fn(async ({ data }: { data: Record<string, unknown> }) => {
|
|
149
|
-
const id = (data.id as string) ?? nextId()
|
|
150
|
-
const row = { id, ...data }
|
|
151
|
-
tables.chargeRequest.set(id, row)
|
|
152
|
-
return row
|
|
153
|
-
}),
|
|
154
|
-
update: vi.fn(
|
|
155
|
-
async ({ where, data }: { where: { id: string }; data: Record<string, unknown> }) => {
|
|
156
|
-
const existing = tables.chargeRequest.get(where.id) ?? { id: where.id }
|
|
157
|
-
const updated = { ...existing, ...data }
|
|
158
|
-
tables.chargeRequest.set(where.id, updated)
|
|
159
|
-
return updated
|
|
160
|
-
},
|
|
161
|
-
),
|
|
162
|
-
delete: vi.fn(async ({ where }: { where: { id: string } }) => {
|
|
163
|
-
const existing = tables.chargeRequest.get(where.id) ?? { id: where.id }
|
|
164
|
-
tables.chargeRequest.delete(where.id)
|
|
165
|
-
chargeToAccount.delete(where.id)
|
|
166
|
-
return existing
|
|
167
|
-
}),
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const client: Record<string, unknown> = {
|
|
172
|
-
account: accountModel,
|
|
173
|
-
chargeRequest: makeChargeRequestModel(),
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
client.$transaction = async (fn: (tx: unknown) => Promise<unknown>) => {
|
|
177
|
-
const snapshot = {
|
|
178
|
-
account: new Map(tables.account),
|
|
179
|
-
chargeRequest: new Map(tables.chargeRequest),
|
|
180
|
-
links: new Map(chargeToAccount),
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
return await fn(client)
|
|
184
|
-
} catch (err) {
|
|
185
|
-
tables.account = snapshot.account
|
|
186
|
-
tables.chargeRequest = snapshot.chargeRequest
|
|
187
|
-
chargeToAccount.clear()
|
|
188
|
-
for (const [k, v] of snapshot.links) chargeToAccount.set(k, v)
|
|
189
|
-
throw err
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function seedChargeRequest(accountId: string, row: Record<string, unknown>) {
|
|
194
|
-
tables.chargeRequest.set(row.id as string, row)
|
|
195
|
-
chargeToAccount.set(row.id as string, accountId)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return { client, tables, seedChargeRequest, linkedChargeRequests }
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function buildConfig(hooks: Parameters<typeof list>[0]['hooks'] = {}) {
|
|
202
|
-
return config({
|
|
203
|
-
db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
|
|
204
|
-
lists: {
|
|
205
|
-
Account: list({
|
|
206
|
-
fields: { name: text() },
|
|
207
|
-
access: {
|
|
208
|
-
operation: {
|
|
209
|
-
query: () => true,
|
|
210
|
-
create: () => true,
|
|
211
|
-
update: () => true,
|
|
212
|
-
delete: () => true,
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
}),
|
|
216
|
-
// No `requests`/`chargeRequests` field on Account — this ref is
|
|
217
|
-
// list-only, so the generator synthesizes `from_ChargeRequest_account`.
|
|
218
|
-
ChargeRequest: list({
|
|
219
|
-
fields: {
|
|
220
|
-
kind: text(),
|
|
221
|
-
account: relationship({ ref: 'Account' }),
|
|
222
|
-
},
|
|
223
|
-
access: {
|
|
224
|
-
operation: {
|
|
225
|
-
query: () => true,
|
|
226
|
-
create: () => true,
|
|
227
|
-
update: () => true,
|
|
228
|
-
delete: () => true,
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
hooks,
|
|
232
|
-
}),
|
|
233
|
-
},
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
describe('#978 nested writes through a synthetic reverse relation', () => {
|
|
238
|
-
it('a non-sudo write through the synthetic key is still refused — unchanged', async () => {
|
|
239
|
-
const mock = createAccountPrisma()
|
|
240
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
241
|
-
const context = getContext(await buildConfig(), mock.client, { userId: '1' })
|
|
242
|
-
|
|
243
|
-
await expect(
|
|
244
|
-
context.db.account.update({
|
|
245
|
-
where: { id: 'a1' },
|
|
246
|
-
data: { [SYNTHETIC_FIELD]: { create: { kind: 'DEPOSIT' } } },
|
|
247
|
-
}),
|
|
248
|
-
).rejects.toThrow(/from_ChargeRequest_account/)
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
it('sudo nested create through the synthetic key runs the target list validate hook and refuses an invalid row', async () => {
|
|
252
|
-
const mock = createAccountPrisma()
|
|
253
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
254
|
-
|
|
255
|
-
const testConfig = buildConfig({
|
|
256
|
-
validate: ({ resolvedData, addValidationError }) => {
|
|
257
|
-
if (resolvedData.kind === 'INCOHERENT') {
|
|
258
|
-
addValidationError('kind must not be INCOHERENT')
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
})
|
|
262
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
263
|
-
|
|
264
|
-
await expect(
|
|
265
|
-
context.db.account.update({
|
|
266
|
-
where: { id: 'a1' },
|
|
267
|
-
data: { [SYNTHETIC_FIELD]: { create: { kind: 'INCOHERENT' } } },
|
|
268
|
-
}),
|
|
269
|
-
).rejects.toThrow(ValidationError)
|
|
270
|
-
|
|
271
|
-
// Refused before commit — nothing persisted, matching the atomic write
|
|
272
|
-
// pipeline's "throw rolls back the whole transaction" contract.
|
|
273
|
-
expect(mock.tables.chargeRequest.size).toBe(0)
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
it('sudo nested create through the synthetic key runs resolveInput, beforeOperation, and afterOperation', async () => {
|
|
277
|
-
const mock = createAccountPrisma()
|
|
278
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
279
|
-
|
|
280
|
-
const events: string[] = []
|
|
281
|
-
const testConfig = buildConfig({
|
|
282
|
-
resolveInput: ({ resolvedData }) => {
|
|
283
|
-
events.push('resolveInput')
|
|
284
|
-
return { ...resolvedData, kind: (resolvedData.kind as string).toUpperCase() }
|
|
285
|
-
},
|
|
286
|
-
beforeOperation: ({ operation }) => {
|
|
287
|
-
events.push(`beforeOperation:${operation}`)
|
|
288
|
-
},
|
|
289
|
-
afterOperation: ({ operation, item }) => {
|
|
290
|
-
events.push(`afterOperation:${operation}`)
|
|
291
|
-
expect(item).toBeDefined()
|
|
292
|
-
expect((item as Record<string, unknown>).id).toBeDefined()
|
|
293
|
-
},
|
|
294
|
-
})
|
|
295
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
296
|
-
|
|
297
|
-
await context.db.account.update({
|
|
298
|
-
where: { id: 'a1' },
|
|
299
|
-
data: { [SYNTHETIC_FIELD]: { create: { kind: 'deposit' } } },
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
expect(events).toEqual(['resolveInput', 'beforeOperation:create', 'afterOperation:create'])
|
|
303
|
-
const created = Array.from(mock.tables.chargeRequest.values())
|
|
304
|
-
expect(created).toHaveLength(1)
|
|
305
|
-
// resolveInput's transform actually landed in the persisted row.
|
|
306
|
-
expect(created[0].kind).toBe('DEPOSIT')
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
it('created-row recovery works for a synthetic-relation nested create, like the declared path', async () => {
|
|
310
|
-
const mock = createAccountPrisma()
|
|
311
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
312
|
-
mock.seedChargeRequest('a1', { id: 'pre-1', kind: 'PRE_EXISTING' })
|
|
313
|
-
|
|
314
|
-
const createdItems: Array<Record<string, unknown>> = []
|
|
315
|
-
const testConfig = buildConfig({
|
|
316
|
-
afterOperation: ({ operation, item }) => {
|
|
317
|
-
if (operation === 'create') createdItems.push(item as Record<string, unknown>)
|
|
318
|
-
},
|
|
319
|
-
})
|
|
320
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
321
|
-
|
|
322
|
-
await context.db.account.update({
|
|
323
|
-
where: { id: 'a1' },
|
|
324
|
-
data: { [SYNTHETIC_FIELD]: { create: [{ kind: 'DEPOSIT' }, { kind: 'WITHDRAW' }] } },
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
// Exactly the two NEW rows fired afterOperation, each with its own
|
|
328
|
-
// distinct persisted id — never the pre-existing row, never a shared id.
|
|
329
|
-
expect(createdItems).toHaveLength(2)
|
|
330
|
-
const ids = createdItems.map((c) => c.id)
|
|
331
|
-
expect(new Set(ids).size).toBe(2)
|
|
332
|
-
expect(ids).not.toContain('pre-1')
|
|
333
|
-
expect(createdItems.map((c) => c.kind).sort()).toEqual(['DEPOSIT', 'WITHDRAW'])
|
|
334
|
-
|
|
335
|
-
expect(
|
|
336
|
-
mock
|
|
337
|
-
.linkedChargeRequests('a1')
|
|
338
|
-
.map((c) => c.kind)
|
|
339
|
-
.sort(),
|
|
340
|
-
).toEqual(['DEPOSIT', 'PRE_EXISTING', 'WITHDRAW'])
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
it('sudo nested update through the synthetic key fires afterOperation with originalItem and the updated item', async () => {
|
|
344
|
-
const mock = createAccountPrisma()
|
|
345
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
346
|
-
mock.seedChargeRequest('a1', { id: 'cr-1', kind: 'DEPOSIT' })
|
|
347
|
-
|
|
348
|
-
const afterOp = vi.fn()
|
|
349
|
-
const testConfig = buildConfig({ afterOperation: afterOp })
|
|
350
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
351
|
-
|
|
352
|
-
await context.db.account.update({
|
|
353
|
-
where: { id: 'a1' },
|
|
354
|
-
data: {
|
|
355
|
-
[SYNTHETIC_FIELD]: { update: { where: { id: 'cr-1' }, data: { kind: 'WITHDRAW' } } },
|
|
356
|
-
},
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
expect(afterOp).toHaveBeenCalledWith(
|
|
360
|
-
expect.objectContaining({
|
|
361
|
-
operation: 'update',
|
|
362
|
-
originalItem: expect.objectContaining({ id: 'cr-1', kind: 'DEPOSIT' }),
|
|
363
|
-
item: expect.objectContaining({ id: 'cr-1', kind: 'WITHDRAW' }),
|
|
364
|
-
}),
|
|
365
|
-
)
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
it('sudo nested delete through the synthetic key fires before/afterOperation with originalItem', async () => {
|
|
369
|
-
const mock = createAccountPrisma()
|
|
370
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
371
|
-
mock.seedChargeRequest('a1', { id: 'cr-1', kind: 'DEPOSIT' })
|
|
372
|
-
|
|
373
|
-
const listBefore = vi.fn()
|
|
374
|
-
const listAfter = vi.fn()
|
|
375
|
-
const testConfig = buildConfig({ beforeOperation: listBefore, afterOperation: listAfter })
|
|
376
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
377
|
-
|
|
378
|
-
await context.db.account.update({
|
|
379
|
-
where: { id: 'a1' },
|
|
380
|
-
data: { [SYNTHETIC_FIELD]: { delete: { id: 'cr-1' } } },
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
expect(listBefore).toHaveBeenCalledWith(
|
|
384
|
-
expect.objectContaining({
|
|
385
|
-
operation: 'delete',
|
|
386
|
-
item: expect.objectContaining({ id: 'cr-1', kind: 'DEPOSIT' }),
|
|
387
|
-
}),
|
|
388
|
-
)
|
|
389
|
-
expect(listAfter).toHaveBeenCalledWith(
|
|
390
|
-
expect.objectContaining({
|
|
391
|
-
operation: 'delete',
|
|
392
|
-
originalItem: expect.objectContaining({ id: 'cr-1', kind: 'DEPOSIT' }),
|
|
393
|
-
}),
|
|
394
|
-
)
|
|
395
|
-
expect(mock.tables.chargeRequest.has('cr-1')).toBe(false)
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
it('a throwing nested afterOperation on the synthetic path rolls back the whole write (atomicity)', async () => {
|
|
399
|
-
const mock = createAccountPrisma()
|
|
400
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
401
|
-
|
|
402
|
-
const testConfig = buildConfig({
|
|
403
|
-
afterOperation: ({ operation }) => {
|
|
404
|
-
if (operation === 'create') throw new Error('synthetic afterOperation boom')
|
|
405
|
-
},
|
|
406
|
-
})
|
|
407
|
-
const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
|
|
408
|
-
|
|
409
|
-
await expect(
|
|
410
|
-
context.db.account.update({
|
|
411
|
-
where: { id: 'a1' },
|
|
412
|
-
data: {
|
|
413
|
-
name: 'Should NOT persist',
|
|
414
|
-
[SYNTHETIC_FIELD]: { create: { kind: 'DEPOSIT' } },
|
|
415
|
-
},
|
|
416
|
-
}),
|
|
417
|
-
).rejects.toThrow('synthetic afterOperation boom')
|
|
418
|
-
|
|
419
|
-
expect(mock.tables.account.get('a1')?.name).toBe('Acme')
|
|
420
|
-
expect(mock.tables.chargeRequest.size).toBe(0)
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
it('a genuinely unknown key (not a synthetic reverse relation) is refused even under sudo', async () => {
|
|
424
|
-
const mock = createAccountPrisma()
|
|
425
|
-
mock.tables.account.set('a1', { id: 'a1', name: 'Acme' })
|
|
426
|
-
const context = getContext(await buildConfig(), mock.client, { userId: '1' }).sudo()
|
|
427
|
-
|
|
428
|
-
await expect(
|
|
429
|
-
context.db.account.update({
|
|
430
|
-
where: { id: 'a1' },
|
|
431
|
-
data: { totallyBogusKey: { create: { kind: 'DEPOSIT' } } },
|
|
432
|
-
}),
|
|
433
|
-
).rejects.toThrow(/totallyBogusKey/)
|
|
434
|
-
|
|
435
|
-
expect(mock.tables.account.get('a1')?.name).toBe('Acme')
|
|
436
|
-
})
|
|
437
|
-
})
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { config, list, getContext } from '../src/index.js'
|
|
3
|
-
import { text, password, relationship } from '../src/fields/index.js'
|
|
4
|
-
import { PrismaClient } from '@prisma/client'
|
|
5
|
-
import type { HashedPassword } from '../src/utils/password.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Test to verify that password field transformation doesn't cause union type distribution
|
|
9
|
-
* This was the bug: all fields were becoming `string | HashedPassword` instead of just password field
|
|
10
|
-
*/
|
|
11
|
-
describe('Password Field Type Distribution Bug Fix', () => {
|
|
12
|
-
const mockPrismaClient = {
|
|
13
|
-
user: {
|
|
14
|
-
findUnique: async () => ({
|
|
15
|
-
id: '1',
|
|
16
|
-
name: 'John Doe',
|
|
17
|
-
email: 'john@example.com',
|
|
18
|
-
password: '$2a$10$hashedpassword',
|
|
19
|
-
}),
|
|
20
|
-
findMany: async () => [
|
|
21
|
-
{
|
|
22
|
-
id: '1',
|
|
23
|
-
name: 'John Doe',
|
|
24
|
-
email: 'john@example.com',
|
|
25
|
-
password: '$2a$10$hashedpassword',
|
|
26
|
-
posts: [
|
|
27
|
-
{
|
|
28
|
-
id: 'post1',
|
|
29
|
-
title: 'Test Post',
|
|
30
|
-
authorId: '1',
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
post: {
|
|
37
|
-
findMany: async () => [],
|
|
38
|
-
},
|
|
39
|
-
} as unknown as PrismaClient
|
|
40
|
-
|
|
41
|
-
const testConfig = config({
|
|
42
|
-
db: {
|
|
43
|
-
provider: 'sqlite',
|
|
44
|
-
},
|
|
45
|
-
lists: {
|
|
46
|
-
User: list({
|
|
47
|
-
fields: {
|
|
48
|
-
name: text({ validation: { isRequired: true } }),
|
|
49
|
-
email: text({ validation: { isRequired: true } }),
|
|
50
|
-
password: password({ validation: { isRequired: true } }),
|
|
51
|
-
posts: relationship({ ref: 'Post.author', many: true }),
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
Post: list({
|
|
55
|
-
fields: {
|
|
56
|
-
title: text({ validation: { isRequired: true } }),
|
|
57
|
-
author: relationship({ ref: 'User.posts' }),
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should NOT make all fields a union of string | HashedPassword', async () => {
|
|
64
|
-
const context = getContext(await testConfig, mockPrismaClient, null)
|
|
65
|
-
|
|
66
|
-
const user = await context.db.user.findUnique({ where: { id: '1' } })
|
|
67
|
-
|
|
68
|
-
if (user) {
|
|
69
|
-
// Type assertions that should compile correctly
|
|
70
|
-
// These would fail if the bug exists (type would be string | HashedPassword for all fields)
|
|
71
|
-
|
|
72
|
-
// name should be string, not string | HashedPassword
|
|
73
|
-
const name: string = user.name
|
|
74
|
-
expect(typeof name).toBe('string')
|
|
75
|
-
|
|
76
|
-
// email should be string, not string | HashedPassword
|
|
77
|
-
const email: string = user.email
|
|
78
|
-
expect(typeof email).toBe('string')
|
|
79
|
-
|
|
80
|
-
// id should be string, not string | HashedPassword
|
|
81
|
-
const id: string = user.id
|
|
82
|
-
expect(typeof id).toBe('string')
|
|
83
|
-
|
|
84
|
-
// password SHOULD be HashedPassword
|
|
85
|
-
const password: HashedPassword = user.password
|
|
86
|
-
expect(typeof password.compare).toBe('function')
|
|
87
|
-
|
|
88
|
-
// If the bug existed, this would be a type error because
|
|
89
|
-
// string | HashedPassword doesn't have .compare()
|
|
90
|
-
const canCompare: boolean = await password.compare('test')
|
|
91
|
-
expect(typeof canCompare).toBe('boolean')
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('should preserve types with included relationships', async () => {
|
|
96
|
-
const context = getContext(await testConfig, mockPrismaClient, null)
|
|
97
|
-
|
|
98
|
-
const users = await context.db.user.findMany({
|
|
99
|
-
include: {
|
|
100
|
-
posts: true,
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
if (users.length > 0) {
|
|
105
|
-
const user = users[0]
|
|
106
|
-
|
|
107
|
-
// Regular fields should have their original types
|
|
108
|
-
const name: string = user.name
|
|
109
|
-
const email: string = user.email
|
|
110
|
-
const id: string = user.id
|
|
111
|
-
|
|
112
|
-
// Password should be HashedPassword
|
|
113
|
-
const password: HashedPassword = user.password
|
|
114
|
-
|
|
115
|
-
// Posts should be included and typed
|
|
116
|
-
if (user.posts && user.posts.length > 0) {
|
|
117
|
-
const post = user.posts[0]
|
|
118
|
-
const title: string = post.title
|
|
119
|
-
expect(typeof title).toBe('string')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
expect(typeof name).toBe('string')
|
|
123
|
-
expect(typeof email).toBe('string')
|
|
124
|
-
expect(typeof id).toBe('string')
|
|
125
|
-
expect(typeof password.compare).toBe('function')
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('should verify TypeScript narrowing works correctly', async () => {
|
|
130
|
-
const context = getContext(await testConfig, mockPrismaClient, null)
|
|
131
|
-
|
|
132
|
-
const user = await context.db.user.findUnique({ where: { id: '1' } })
|
|
133
|
-
|
|
134
|
-
if (user) {
|
|
135
|
-
// This is the key test: if all fields were string | HashedPassword,
|
|
136
|
-
// we couldn't assign to string without type assertion
|
|
137
|
-
|
|
138
|
-
// These should compile without type assertions
|
|
139
|
-
function expectString(val: string): void {
|
|
140
|
-
expect(typeof val).toBe('string')
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function expectHashedPassword(val: HashedPassword): void {
|
|
144
|
-
expect(typeof val.compare).toBe('function')
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// These calls prove the types are correctly narrowed
|
|
148
|
-
expectString(user.name)
|
|
149
|
-
expectString(user.email)
|
|
150
|
-
expectString(user.id)
|
|
151
|
-
expectHashedPassword(user.password)
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
})
|