@opensaas/stack-core 0.43.0 → 0.44.0-alpha.2
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 +2753 -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 +1035 -611
- 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 +629 -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 +294 -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 +153 -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 +462 -678
- 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 +237 -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
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { createPostgresControlClient } from '@prisma/orm-postgres/control';
|
|
6
|
+
import postgres from '@prisma/orm-postgres/runtime';
|
|
7
|
+
import { buildPrismaContract, toEmittedContract } from '../contract/prisma.js';
|
|
8
|
+
import { deriveContract } from '../contract/derive.js';
|
|
9
|
+
import { getContext } from '../context/index.js';
|
|
10
|
+
import { originTripwire, withOrigin } from '../origin.js';
|
|
11
|
+
import { ESCAPE_VARIABLES, requireUsableDatabaseEscape } from './escape.js';
|
|
12
|
+
import { contractPacks, loadExtensionPacks, } from './extensions.js';
|
|
13
|
+
/**
|
|
14
|
+
* Every pack this harness knows how to make available on the in-process
|
|
15
|
+
* database, keyed by the binding name `db.extensions` spells. PGlite loads its
|
|
16
|
+
* extensions at construction, so a pack the map does not name reaches
|
|
17
|
+
* `CREATE EXTENSION` with nothing to install.
|
|
18
|
+
*/
|
|
19
|
+
const DEV_DATABASE_EXTENSIONS = { pgvector: 'vector' };
|
|
20
|
+
/**
|
|
21
|
+
* The prefix every database the escape path creates carries, followed by a
|
|
22
|
+
* UTC `YYYYMMDDHHMMSS` stamp and a UUID. A run killed before `close()` leaves
|
|
23
|
+
* one behind, and the stamp is what makes the leftovers sweepable by age
|
|
24
|
+
* rather than only greppable — see the `Known limits` note on
|
|
25
|
+
* {@link createTestDatabase} for the statement.
|
|
26
|
+
*/
|
|
27
|
+
export const ESCAPE_DATABASE_PREFIX = 'opensaas_test_';
|
|
28
|
+
function stamp() {
|
|
29
|
+
return new Date()
|
|
30
|
+
.toISOString()
|
|
31
|
+
.replaceAll(/[^0-9]/g, '')
|
|
32
|
+
.slice(0, 14);
|
|
33
|
+
}
|
|
34
|
+
function isCollection(value) {
|
|
35
|
+
return typeof value === 'object' && value !== null;
|
|
36
|
+
}
|
|
37
|
+
function isReachable(value) {
|
|
38
|
+
return value !== null && (typeof value === 'object' || typeof value === 'function');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `client.orm` and its namespaces are Proxies with a `get` trap and no `has`
|
|
42
|
+
* trap, so `key in container` reports false for a collection that is right
|
|
43
|
+
* there. Reads go through `Reflect.get` and the result is checked instead.
|
|
44
|
+
*/
|
|
45
|
+
function reach(container, key) {
|
|
46
|
+
if (container === null || (typeof container !== 'object' && typeof container !== 'function')) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return Reflect.get(container, key);
|
|
50
|
+
}
|
|
51
|
+
function keysOf(container) {
|
|
52
|
+
return isCollection(container) ? Object.keys(container) : [];
|
|
53
|
+
}
|
|
54
|
+
function listed(keys) {
|
|
55
|
+
return keys.length === 0 ? '(none)' : keys.join(', ');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Thrown when the client exposes no collection for a model the contract
|
|
59
|
+
* declares. The engine reaches every model through this map, so an entry that
|
|
60
|
+
* resolved to `undefined` would build a context that refuses every operation
|
|
61
|
+
* with `OrmModelMissingError` — advice to re-run `opensaas generate`, which a
|
|
62
|
+
* harness user cannot act on. This is the assertion that the client's shape is
|
|
63
|
+
* the one the harness derives from.
|
|
64
|
+
*/
|
|
65
|
+
export class OrmCollectionMissingError extends Error {
|
|
66
|
+
model;
|
|
67
|
+
namespace;
|
|
68
|
+
namespaces;
|
|
69
|
+
collections;
|
|
70
|
+
constructor(model, namespace, namespaces, collections) {
|
|
71
|
+
super(`The test harness built a client with no collection for model "${model}" at ` +
|
|
72
|
+
`orm."${namespace}". The client's namespaces are: ${listed(namespaces)}; that ` +
|
|
73
|
+
`namespace holds: ${listed(collections)}. A context over this client would refuse ` +
|
|
74
|
+
`every operation, so the harness refuses to build one.`);
|
|
75
|
+
this.model = model;
|
|
76
|
+
this.namespace = namespace;
|
|
77
|
+
this.namespaces = namespaces;
|
|
78
|
+
this.collections = collections;
|
|
79
|
+
this.name = 'OrmCollectionMissingError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The client's collections, keyed the way {@link ormModel} looks them up.
|
|
84
|
+
*
|
|
85
|
+
* A Prisma 8 client exposes its collections at `orm.<namespace>.<Model>` while
|
|
86
|
+
* the engine reaches a model by db key; this is the same reconciliation the
|
|
87
|
+
* generated context performs, in one place, until the runtime spec makes it
|
|
88
|
+
* unnecessary.
|
|
89
|
+
*/
|
|
90
|
+
export function ormClientFor(data, orm) {
|
|
91
|
+
const models = {};
|
|
92
|
+
for (const model of data.models) {
|
|
93
|
+
const namespaceName = model.namespace ?? 'public';
|
|
94
|
+
const namespace = reach(orm, namespaceName);
|
|
95
|
+
const collection = reach(namespace, model.name);
|
|
96
|
+
if (!isReachable(collection)) {
|
|
97
|
+
throw new OrmCollectionMissingError(model.name, namespaceName, keysOf(orm), keysOf(namespace));
|
|
98
|
+
}
|
|
99
|
+
models[model.name] = collection;
|
|
100
|
+
}
|
|
101
|
+
return models;
|
|
102
|
+
}
|
|
103
|
+
function qualified(data) {
|
|
104
|
+
return data.models.map((model) => {
|
|
105
|
+
const namespace = model.namespace ?? 'public';
|
|
106
|
+
return `"${namespace}"."${model.table ?? model.name}"`;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function pgModule() {
|
|
110
|
+
return (await import('pg')).default;
|
|
111
|
+
}
|
|
112
|
+
async function onClient(url, statement) {
|
|
113
|
+
const pg = await pgModule();
|
|
114
|
+
const client = new pg.Client({ connectionString: url });
|
|
115
|
+
await client.connect();
|
|
116
|
+
try {
|
|
117
|
+
await client.query(statement);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
await client.end();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A `TemplateStringsArray` for a fully-formed SQL string with no interpolated
|
|
125
|
+
* values, so a statement assembled entirely from server-derived identifiers
|
|
126
|
+
* (never caller input — {@link qualified}'s table names) can be handed to the
|
|
127
|
+
* contract-bound raw tag without it being treated as a bind parameter.
|
|
128
|
+
*/
|
|
129
|
+
function rawTemplate(sql) {
|
|
130
|
+
return Object.assign([sql], { raw: [sql] });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Runs a statement-only raw plan through the client's own runtime — the same
|
|
134
|
+
* pool the client was constructed with, entering the unsafe origin the
|
|
135
|
+
* tripwire requires. This is how {@link TestDatabase.truncate} empties tables
|
|
136
|
+
* without opening a second connection to the target database (see the
|
|
137
|
+
* `Known limits` note on {@link createTestDatabase}).
|
|
138
|
+
*/
|
|
139
|
+
async function executeRaw(client, statement) {
|
|
140
|
+
const plan = client.raw.sql(rawTemplate(statement)).affectedCount().build();
|
|
141
|
+
await withOrigin('unsafe', () => client.runtime().execute(plan));
|
|
142
|
+
}
|
|
143
|
+
function withDatabase(url, name) {
|
|
144
|
+
const parsed = new URL(url);
|
|
145
|
+
parsed.pathname = `/${name}`;
|
|
146
|
+
return parsed.href;
|
|
147
|
+
}
|
|
148
|
+
async function seedContractSpaces(migrationsDir, extensions) {
|
|
149
|
+
if (extensions.length === 0)
|
|
150
|
+
return;
|
|
151
|
+
const { runContractSpaceSeedPhase } = await import('@prisma/orm-toolchain/cli/control-api');
|
|
152
|
+
await runContractSpaceSeedPhase({ migrationsDir, extensions });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Thrown when the control client refuses to apply the schema — a server
|
|
156
|
+
* missing a declared extension is the common case, and ADR-0065 leaves that
|
|
157
|
+
* report to Prisma. `assertOk()` would say only "Expected Ok result but got
|
|
158
|
+
* NotOk", so the failure's own payload is carried through here.
|
|
159
|
+
*/
|
|
160
|
+
export class SchemaApplyError extends Error {
|
|
161
|
+
url;
|
|
162
|
+
failure;
|
|
163
|
+
constructor(url, failure) {
|
|
164
|
+
super(`The test harness could not apply the schema to ${url}: ${JSON.stringify(failure, null, 2)}`);
|
|
165
|
+
this.url = url;
|
|
166
|
+
this.failure = failure;
|
|
167
|
+
this.name = 'SchemaApplyError';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function refuseEveryQuestion(questions) {
|
|
171
|
+
if (questions.length > 0) {
|
|
172
|
+
throw new Error(`The test harness will not lose data or widen access: ${JSON.stringify(questions)}`);
|
|
173
|
+
}
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
async function applySchema(url, migrationsDir, contract, extensions) {
|
|
177
|
+
const control = createPostgresControlClient({ connection: url, extensions });
|
|
178
|
+
try {
|
|
179
|
+
const result = await control.dbUpdate({
|
|
180
|
+
contract: toEmittedContract(contract),
|
|
181
|
+
mode: 'apply',
|
|
182
|
+
migrationsDir,
|
|
183
|
+
answerQuestions: refuseEveryQuestion,
|
|
184
|
+
invocation: { cwd: migrationsDir, configPath: undefined, dbGiven: true },
|
|
185
|
+
});
|
|
186
|
+
if (!result.ok)
|
|
187
|
+
throw new SchemaApplyError(url, result.failure);
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
await control.close();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** The optional peers the in-process database needs, in the order it needs them. */
|
|
194
|
+
const DEV_DATABASE_PEERS = [
|
|
195
|
+
'@electric-sql/pglite',
|
|
196
|
+
'@electric-sql/pglite-socket',
|
|
197
|
+
'@electric-sql/pglite-pgvector',
|
|
198
|
+
];
|
|
199
|
+
/**
|
|
200
|
+
* Thrown when the harness falls to the in-process database and one of PGlite's
|
|
201
|
+
* packages is not installed. They are optional peers of core, so a production
|
|
202
|
+
* install carries no WASM Postgres — and a test run without them needs to say
|
|
203
|
+
* which install is missing rather than report a bare module-resolution failure
|
|
204
|
+
* from inside the dev database.
|
|
205
|
+
*/
|
|
206
|
+
export class DevDatabaseUnavailableError extends Error {
|
|
207
|
+
cause;
|
|
208
|
+
constructor(cause) {
|
|
209
|
+
super(`The in-process test database could not start: ${cause instanceof Error ? cause.message : String(cause)}. ` +
|
|
210
|
+
`PGlite is an optional peer of @opensaas/stack-core, so install ${DEV_DATABASE_PEERS.join(', ')} ` +
|
|
211
|
+
`as dev dependencies of this package, or set ${ESCAPE_VARIABLES.join(' or ')} to a Postgres server and run the ` +
|
|
212
|
+
`suite against that instead.`);
|
|
213
|
+
this.cause = cause;
|
|
214
|
+
this.name = 'DevDatabaseUnavailableError';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A module-resolution failure, wherever it sits in the chain: a loader — and
|
|
219
|
+
* Vitest's module mocker — reports the original as the `cause` of its own
|
|
220
|
+
* error rather than re-throwing it.
|
|
221
|
+
*/
|
|
222
|
+
function isModuleNotFound(error) {
|
|
223
|
+
for (let step = error; step instanceof Error; step = step.cause) {
|
|
224
|
+
if ('code' in step &&
|
|
225
|
+
(step.code === 'ERR_MODULE_NOT_FOUND' || step.code === 'MODULE_NOT_FOUND')) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
async function startInstance(escape, extensions) {
|
|
232
|
+
if (escape !== undefined) {
|
|
233
|
+
const name = `${ESCAPE_DATABASE_PREFIX}${stamp()}_${randomUUID().replaceAll('-', '')}`;
|
|
234
|
+
await onClient(escape, `create database "${name}"`);
|
|
235
|
+
return {
|
|
236
|
+
url: withDatabase(escape, name),
|
|
237
|
+
provenance: 'escape',
|
|
238
|
+
release: async () => {
|
|
239
|
+
await onClient(escape, `drop database if exists "${name}" with (force)`);
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const stateDir = mkdtempSync(path.join(tmpdir(), 'opensaas-test-db-'));
|
|
244
|
+
const loaded = extensions.filter((name) => name === 'vector');
|
|
245
|
+
let database;
|
|
246
|
+
try {
|
|
247
|
+
const { startDevDatabase } = await import('../db/dev-database.js');
|
|
248
|
+
database = await startDevDatabase({
|
|
249
|
+
stateFile: path.join(stateDir, 'dev-db.json'),
|
|
250
|
+
extensions: loaded,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
rmSync(stateDir, { recursive: true, force: true });
|
|
255
|
+
throw isModuleNotFound(error) ? new DevDatabaseUnavailableError(error) : error;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
url: database.url,
|
|
259
|
+
provenance: 'pglite',
|
|
260
|
+
release: async () => {
|
|
261
|
+
await database.stop();
|
|
262
|
+
rmSync(stateDir, { recursive: true, force: true });
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Stand up one database for a test file: derive the contract from `config`,
|
|
268
|
+
* seed every declared pack's Extension contract space, apply the schema once
|
|
269
|
+
* through the control client's `dbUpdate`, and bind a Prisma 8 client to it
|
|
270
|
+
* with the stack's own tripwire installed (ADR-0057, ADR-0063, ADR-0065).
|
|
271
|
+
*
|
|
272
|
+
* Call this once per file in `beforeAll`, {@link TestDatabase.truncate} in
|
|
273
|
+
* `beforeEach`, and {@link TestDatabase.close} in `afterAll`. Tests within a
|
|
274
|
+
* file share the schema and nothing else.
|
|
275
|
+
*
|
|
276
|
+
* With `DATABASE_URL` set to a Postgres server the identical suite runs there
|
|
277
|
+
* instead, in a database of its own that is dropped on close; set to anything
|
|
278
|
+
* else the variable is a misconfiguration and this throws rather than dialling
|
|
279
|
+
* it. PGlite and its socket and pgvector packages are optional peers imported
|
|
280
|
+
* only on the unset path, so a production install carries no WASM Postgres.
|
|
281
|
+
*
|
|
282
|
+
* The tripwire is installed unconditionally, from the same `../origin.js` the
|
|
283
|
+
* generator emits — one copy, so a regression in the Engine stamp fails a test
|
|
284
|
+
* rather than a production login. A query the harness itself issues through
|
|
285
|
+
* {@link TestDatabase.client} is refused unless it enters an origin.
|
|
286
|
+
*
|
|
287
|
+
* Known limits:
|
|
288
|
+
* - `context.db` reads and writes for real; `connect` and the row lock arrive
|
|
289
|
+
* in later specs, so a payload here carries this list's own scalars.
|
|
290
|
+
* - PGlite serialises every transaction, so nothing contention-shaped is
|
|
291
|
+
* observable on the default harness. Those guarantees are escape-only.
|
|
292
|
+
* - Only `pgvector` is mapped to a PGlite extension. A pack outside that map
|
|
293
|
+
* reaches `CREATE EXTENSION` with nothing installed and the apply fails
|
|
294
|
+
* naming the missing control file; run it under the escape.
|
|
295
|
+
* - Packs are imported by package name from core's own module. A pack the
|
|
296
|
+
* consuming package depends on but core cannot resolve must be passed as
|
|
297
|
+
* `options.packs`.
|
|
298
|
+
* - The escape path issues `CREATE DATABASE` and `DROP DATABASE`, so the role
|
|
299
|
+
* `DATABASE_URL` names needs `CREATEDB`. A superuser — CI's container, a
|
|
300
|
+
* local install — has it. `DROP DATABASE … WITH (FORCE)` needs PostgreSQL
|
|
301
|
+
* 13 or newer.
|
|
302
|
+
* - `close()` runs from `afterAll`, so a killed worker or a `Ctrl-C` leaves
|
|
303
|
+
* its database on the escape server. Each is named
|
|
304
|
+
* `opensaas_test_<YYYYMMDDHHMMSS>_<uuid>` in UTC, so a sweep is:
|
|
305
|
+
* `select 'drop database ' || quote_ident(datname) || ' with (force);'
|
|
306
|
+
* from pg_database where datname like 'opensaas_test\_%'` — filter on the
|
|
307
|
+
* stamp to spare a run in flight, then execute what it returns.
|
|
308
|
+
* - `truncate()` empties the tables the contract declares. It does not touch
|
|
309
|
+
* Prisma's own marker tables, which the schema apply owns. A contract
|
|
310
|
+
* declaring no model has nothing to empty and `truncate()` is a no-op. It
|
|
311
|
+
* runs the statement through the harness's own client — the same `max: 1`
|
|
312
|
+
* pool a write uses — rather than opening a client of its own, so the
|
|
313
|
+
* database never sees more than the one declared connection while a test
|
|
314
|
+
* is running. The only step that opens a second connection is
|
|
315
|
+
* `startInstance`'s escape-path `CREATE DATABASE`/`DROP DATABASE`, and it
|
|
316
|
+
* necessarily does: those statements run against the control database,
|
|
317
|
+
* before the target database (and its pool) exist to route through, and
|
|
318
|
+
* after `close()` releases that pool.
|
|
319
|
+
* - {@link TestDatabase.client} is the raw Prisma collections, which carry none
|
|
320
|
+
* of the engine's access control or hooks. It is the construction option,
|
|
321
|
+
* not a seam on the secured wrapper: seed through it when a fixture must
|
|
322
|
+
* bypass the engine, and through `context.db` when the engine is the subject.
|
|
323
|
+
*
|
|
324
|
+
* Generic over the context {@link TestDatabase.context} hands back — name the
|
|
325
|
+
* app's own generated `Context` (`createTestDatabase<Context>(config)`) to get
|
|
326
|
+
* typed rows, `where`, `select` and `include` over this harness's database;
|
|
327
|
+
* omitted, `context()` returns the engine's untyped `StackContext<AccessControlledDB>`.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* let db: TestDatabase
|
|
332
|
+
* beforeAll(async () => { db = await createTestDatabase(config) }, 60_000)
|
|
333
|
+
* afterAll(async () => { await db.close() })
|
|
334
|
+
* beforeEach(async () => { await db.truncate() })
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
export async function createTestDatabase(config, options = {}) {
|
|
338
|
+
const data = deriveContract(config);
|
|
339
|
+
const packs = await loadExtensionPacks(data.extensions, options.packs);
|
|
340
|
+
const contract = buildPrismaContract(data, { packs: contractPacks(packs) });
|
|
341
|
+
const control = [];
|
|
342
|
+
const runtimes = [];
|
|
343
|
+
const devExtensions = [];
|
|
344
|
+
for (const extension of data.extensions) {
|
|
345
|
+
const loaded = packs[extension.name];
|
|
346
|
+
control.push(loaded.control);
|
|
347
|
+
runtimes.push(loaded.runtime);
|
|
348
|
+
const available = DEV_DATABASE_EXTENSIONS[extension.name];
|
|
349
|
+
if (available !== undefined)
|
|
350
|
+
devExtensions.push(available);
|
|
351
|
+
}
|
|
352
|
+
const instance = await startInstance(requireUsableDatabaseEscape(), devExtensions);
|
|
353
|
+
const migrationsDir = mkdtempSync(path.join(tmpdir(), 'opensaas-test-migrations-'));
|
|
354
|
+
let pool;
|
|
355
|
+
try {
|
|
356
|
+
await seedContractSpaces(migrationsDir, control);
|
|
357
|
+
await applySchema(instance.url, migrationsDir, contract, control);
|
|
358
|
+
const pg = await pgModule();
|
|
359
|
+
// `max: 1` matches the dev database's single connection, which a write's
|
|
360
|
+
// transaction now holds for its whole duration: anything reaching the
|
|
361
|
+
// database beside that transaction waits on a connection it can never get.
|
|
362
|
+
// `connectionTimeoutMillis` turns that into `timeout exceeded when trying
|
|
363
|
+
// to connect` rather than a test that hangs until the runner kills it.
|
|
364
|
+
pool = new pg.Pool({
|
|
365
|
+
connectionString: instance.url,
|
|
366
|
+
max: 1,
|
|
367
|
+
connectionTimeoutMillis: 10_000,
|
|
368
|
+
});
|
|
369
|
+
const client = postgres({
|
|
370
|
+
contract,
|
|
371
|
+
pg: pool,
|
|
372
|
+
verifyMarker: false,
|
|
373
|
+
middleware: [originTripwire, ...(options.middleware ?? [])],
|
|
374
|
+
extensions: runtimes,
|
|
375
|
+
});
|
|
376
|
+
const orm = ormClientFor(data, client.orm);
|
|
377
|
+
const tables = qualified(data);
|
|
378
|
+
let closed = false;
|
|
379
|
+
// The engine's own `getContext` always returns `StackContext<AccessControlledDB>`
|
|
380
|
+
// — it has no way to know the app's generated `DB` shape. This cast is the
|
|
381
|
+
// same one the generated `.opensaas/context.ts` performs on its own
|
|
382
|
+
// `getContext()`, layering the caller-named `TContext` on top of the
|
|
383
|
+
// identical runtime object. Scoped to `context` alone, so every other
|
|
384
|
+
// member here still gets checked structurally against `TestDatabase<TContext>`.
|
|
385
|
+
const context = (session = null) => getContext(config, orm, session, options.storage, false, undefined, undefined, client);
|
|
386
|
+
return {
|
|
387
|
+
url: instance.url,
|
|
388
|
+
provenance: instance.provenance,
|
|
389
|
+
contract,
|
|
390
|
+
data,
|
|
391
|
+
client,
|
|
392
|
+
context: context,
|
|
393
|
+
truncate: async () => {
|
|
394
|
+
if (tables.length === 0)
|
|
395
|
+
return;
|
|
396
|
+
await executeRaw(client, `truncate table ${tables.join(', ')} restart identity cascade`);
|
|
397
|
+
},
|
|
398
|
+
close: async () => {
|
|
399
|
+
if (closed)
|
|
400
|
+
return;
|
|
401
|
+
closed = true;
|
|
402
|
+
await client.close();
|
|
403
|
+
await instance.release();
|
|
404
|
+
rmSync(migrationsDir, { recursive: true, force: true });
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
await pool?.end().catch(() => { });
|
|
410
|
+
await instance.release().catch(() => { });
|
|
411
|
+
rmSync(migrationsDir, { recursive: true, force: true });
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* A real, fully secured context over an in-process Postgres — the only double
|
|
417
|
+
* the stack offers (ADR-0057). No test fakes the secured surface: the config
|
|
418
|
+
* is derived to a contract, the schema is applied to a database the harness
|
|
419
|
+
* owns, and the context is the same `getContext` an application gets.
|
|
420
|
+
*
|
|
421
|
+
* This is the single-call form of {@link createTestDatabase}, for a file with
|
|
422
|
+
* one session. A file that needs several sessions, or that truncates between
|
|
423
|
+
* tests, should stand the database up once and call
|
|
424
|
+
* {@link TestDatabase.context} per test — every limit documented on
|
|
425
|
+
* `createTestDatabase` applies here unchanged.
|
|
426
|
+
*
|
|
427
|
+
* Generic over the context returned, exactly as {@link createTestDatabase} is
|
|
428
|
+
* — name the app's own generated `Context` to get typed rows over this
|
|
429
|
+
* harness's database instead of the engine's untyped `StackContext<AccessControlledDB>`:
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* import { createTestContext } from '@opensaas/stack-core/testing'
|
|
434
|
+
* import type { Context } from '../.opensaas/types.js'
|
|
435
|
+
*
|
|
436
|
+
* const harness = await createTestContext<Context>(config, { userId: 'user-1' })
|
|
437
|
+
* try {
|
|
438
|
+
* const posts = await harness.context.db.Post.all()
|
|
439
|
+
* } finally {
|
|
440
|
+
* await harness.close()
|
|
441
|
+
* }
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
export async function createTestContext(config, session = null, options = {}) {
|
|
445
|
+
const database = await createTestDatabase(config, options);
|
|
446
|
+
try {
|
|
447
|
+
return { ...database, context: database.context(session) };
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
// `database.context` can now throw (`InvalidSessionError`), after the
|
|
451
|
+
// database is already up — close it rather than leaking the instance.
|
|
452
|
+
// A failure in `close()` itself must not mask the original error.
|
|
453
|
+
await database.close().catch(() => { });
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/testing/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAC1E,OAAO,QAAQ,MAAM,8BAA8B,CAAA;AAMnD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAuB,MAAM,uBAAuB,CAAA;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAA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CAAC,CAAA;QACjC,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QACxC,MAAM,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACvD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAGrC,MAAsB,EACtB,OAAO,GAAwB,IAAI,EACnC,OAAO,GAAwB,EAAE;IAEjC,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAW,MAAM,EAAE,OAAO,CAAC,CAAA;IACpE,IAAI,CAAC;QACH,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sEAAsE;QACtE,sEAAsE;QACtE,kEAAkE;QAClE,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QACtC,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The variables the harness reads, in the same order `resolveDatabaseUrl()`
|
|
3
|
+
* does — `DIRECT_DATABASE_URL` first — and the only escape from in-process
|
|
4
|
+
* PGlite. Re-exported from `../db/url.js` rather than declared here, so the
|
|
5
|
+
* application's lookup and the harness's cannot drift apart again (issue
|
|
6
|
+
* #1210): with only `DIRECT_DATABASE_URL` set, both now agree it names a
|
|
7
|
+
* usable connection.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ESCAPE_VARIABLES: readonly ["DIRECT_DATABASE_URL", "DATABASE_URL"];
|
|
10
|
+
/**
|
|
11
|
+
* What {@link ESCAPE_VARIABLES} say. `'absent'` runs the suite on in-process
|
|
12
|
+
* PGlite; `'postgres'` runs the identical suite against that server;
|
|
13
|
+
* `'unusable'` is a misconfiguration the harness refuses rather than dials.
|
|
14
|
+
*/
|
|
15
|
+
export type DatabaseEscape = {
|
|
16
|
+
readonly kind: 'absent';
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'postgres';
|
|
19
|
+
readonly url: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'unusable';
|
|
22
|
+
readonly variable: string;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly fault: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Thrown when one of {@link ESCAPE_VARIABLES} is set to something that is not
|
|
28
|
+
* a Postgres connection string. Names the variable, its value, the fault and
|
|
29
|
+
* both remedies.
|
|
30
|
+
*
|
|
31
|
+
* A set-but-unusable value is not the same as an unset one: node-postgres
|
|
32
|
+
* quietly falls back to `localhost:5432` for a string it cannot parse, so a
|
|
33
|
+
* suite that dialled it would report a bare `ECONNREFUSED` several frames from
|
|
34
|
+
* the actual mistake. This is the failure a stale SQLite `DATABASE_URL` in CI
|
|
35
|
+
* produced after Postgres became the only provider.
|
|
36
|
+
*/
|
|
37
|
+
export declare class UnusableDatabaseEscapeError extends Error {
|
|
38
|
+
readonly variable: string;
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly fault: string;
|
|
41
|
+
constructor(variable: string, url: string, fault: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Classify {@link ESCAPE_VARIABLES} without dialling them. The first variable
|
|
45
|
+
* that is set and non-empty wins — the same rule `resolveDatabaseUrl()` uses —
|
|
46
|
+
* so a value in `DIRECT_DATABASE_URL` alone is classified exactly as the
|
|
47
|
+
* application would resolve it, rather than falling through to `'absent'`.
|
|
48
|
+
*
|
|
49
|
+
* Read this at module scope in a suite whose guarantee PGlite cannot exercise —
|
|
50
|
+
* ADR-0047's row-lock contention, real pool concurrency — and skip on it by
|
|
51
|
+
* name, so the skip is visible in the reporter rather than silent:
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const escape = readDatabaseEscape()
|
|
56
|
+
* test.skipIf(escape.kind !== 'postgres')(
|
|
57
|
+
* `two bookings contend for one slot [escape-only: ${ESCAPE_VARIABLES.join('/')} names no Postgres]`,
|
|
58
|
+
* async () => { … },
|
|
59
|
+
* )
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function readDatabaseEscape(): DatabaseEscape;
|
|
63
|
+
/**
|
|
64
|
+
* The escape's URL, or `undefined` to run on the dev database.
|
|
65
|
+
*
|
|
66
|
+
* @throws {UnusableDatabaseEscapeError} when one of {@link ESCAPE_VARIABLES}
|
|
67
|
+
* is set to anything that is not a Postgres connection string.
|
|
68
|
+
*/
|
|
69
|
+
export declare function requireUsableDatabaseEscape(): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a Postgres server named by the escape carries the pgvector
|
|
72
|
+
* extension, for a suite that guards a config declaring it (ADR-0065).
|
|
73
|
+
*
|
|
74
|
+
* Only an answer from the server is an answer. A server that is not
|
|
75
|
+
* accepting connections yet is redialled until {@link PROBE_DEADLINE} and
|
|
76
|
+
* then thrown on, so a container still coming up can never be recorded as
|
|
77
|
+
* one without pgvector — the only skip this can produce is a server that
|
|
78
|
+
* answered and said no.
|
|
79
|
+
*
|
|
80
|
+
* @throws when the server stays unreachable for the whole deadline.
|
|
81
|
+
*/
|
|
82
|
+
export declare function probePgvectorAvailability(url: string): Promise<boolean>;
|
|
83
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/testing/escape.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,kDAAuB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACnD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAEL;;;;;;;;;;GAUG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAElD,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM;IAHxB,YACW,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EAQvB;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,CAUnD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,GAAG,SAAS,CAMhE;AA6BD;;;;;;;;;;;GAWG;AACH,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoC7E"}
|