@opensaas/stack-core 0.42.3 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2745 -0
- package/README.md +182 -115
- package/dist/.build-hash +1 -0
- package/dist/access/declared-dependencies.d.ts +102 -88
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +83 -71
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +4 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +4 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +68 -20
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +151 -37
- package/dist/access/engine.js.map +1 -1
- package/dist/access/errors.d.ts +33 -48
- package/dist/access/errors.d.ts.map +1 -1
- package/dist/access/errors.js +73 -63
- package/dist/access/errors.js.map +1 -1
- package/dist/access/field-access.d.ts +76 -5
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +235 -61
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/field-visibility.d.ts +50 -4
- package/dist/access/field-visibility.d.ts.map +1 -1
- package/dist/access/field-visibility.js +143 -160
- package/dist/access/field-visibility.js.map +1 -1
- package/dist/access/index.d.ts +5 -12
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -19
- package/dist/access/index.js.map +1 -1
- package/dist/access/orm-client.d.ts +19 -0
- package/dist/access/orm-client.d.ts.map +1 -0
- package/dist/access/orm-client.js +37 -0
- package/dist/access/orm-client.js.map +1 -0
- package/dist/access/query-validation.d.ts +7 -129
- package/dist/access/query-validation.d.ts.map +1 -1
- package/dist/access/query-validation.js +12 -314
- package/dist/access/query-validation.js.map +1 -1
- package/dist/access/system-fields.d.ts +2 -0
- package/dist/access/system-fields.d.ts.map +1 -0
- package/dist/access/system-fields.js +7 -0
- package/dist/access/system-fields.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +25 -2
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +34 -17
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +217 -131
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/field-kind.d.ts +66 -0
- package/dist/config/field-kind.d.ts.map +1 -0
- package/dist/config/field-kind.js +63 -0
- package/dist/config/field-kind.js.map +1 -0
- package/dist/config/hook-only-fields.d.ts +3 -0
- package/dist/config/hook-only-fields.d.ts.map +1 -0
- package/dist/config/hook-only-fields.js +17 -0
- package/dist/config/hook-only-fields.js.map +1 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-tool-names.d.ts +3 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -0
- package/dist/config/mcp-tool-names.js +25 -0
- package/dist/config/mcp-tool-names.js.map +1 -0
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +4 -4
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts +8 -2
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +102 -38
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +966 -614
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/apply-defaults.d.ts +18 -1
- package/dist/context/apply-defaults.d.ts.map +1 -1
- package/dist/context/apply-defaults.js +30 -4
- package/dist/context/apply-defaults.js.map +1 -1
- package/dist/context/engine-context.d.ts +73 -0
- package/dist/context/engine-context.d.ts.map +1 -0
- package/dist/context/engine-context.js +67 -0
- package/dist/context/engine-context.js.map +1 -0
- package/dist/context/hook-pipeline.d.ts +9 -2
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +5 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +98 -89
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +917 -722
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +59 -0
- package/dist/context/junction.d.ts.map +1 -0
- package/dist/context/junction.js +126 -0
- package/dist/context/junction.js.map +1 -0
- package/dist/context/plugin-field-read.d.ts +33 -0
- package/dist/context/plugin-field-read.d.ts.map +1 -0
- package/dist/context/plugin-field-read.js +41 -0
- package/dist/context/plugin-field-read.js.map +1 -0
- package/dist/context/plugin-field-write.d.ts +104 -0
- package/dist/context/plugin-field-write.d.ts.map +1 -0
- package/dist/context/plugin-field-write.js +184 -0
- package/dist/context/plugin-field-write.js.map +1 -0
- package/dist/context/relationship-input.d.ts +146 -0
- package/dist/context/relationship-input.d.ts.map +1 -0
- package/dist/context/relationship-input.js +453 -0
- package/dist/context/relationship-input.js.map +1 -0
- package/dist/context/transaction-boundary.d.ts +54 -28
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +87 -169
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +33 -51
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +372 -185
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/contract/dependencies.d.ts +88 -0
- package/dist/contract/dependencies.d.ts.map +1 -0
- package/dist/contract/dependencies.js +237 -0
- package/dist/contract/dependencies.js.map +1 -0
- package/dist/contract/derive.d.ts +49 -0
- package/dist/contract/derive.d.ts.map +1 -0
- package/dist/contract/derive.js +540 -0
- package/dist/contract/derive.js.map +1 -0
- package/dist/contract/fixtures/contract-configs.d.ts +64 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
- package/dist/contract/fixtures/contract-configs.js +345 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -0
- package/dist/contract/id-boundary.d.ts +53 -0
- package/dist/contract/id-boundary.d.ts.map +1 -0
- package/dist/contract/id-boundary.js +76 -0
- package/dist/contract/id-boundary.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +11 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/prisma.d.ts +58 -0
- package/dist/contract/prisma.d.ts.map +1 -0
- package/dist/contract/prisma.js +282 -0
- package/dist/contract/prisma.js.map +1 -0
- package/dist/contract/relation-graph.d.ts +70 -0
- package/dist/contract/relation-graph.d.ts.map +1 -0
- package/dist/contract/relation-graph.js +113 -0
- package/dist/contract/relation-graph.js.map +1 -0
- package/dist/contract/types.d.ts +135 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/db/client.d.ts +55 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +73 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/dev-database.d.ts +124 -0
- package/dist/db/dev-database.d.ts.map +1 -0
- package/dist/db/dev-database.js +291 -0
- package/dist/db/dev-database.js.map +1 -0
- package/dist/db/password-front.d.ts +10 -0
- package/dist/db/password-front.d.ts.map +1 -0
- package/dist/db/password-front.js +147 -0
- package/dist/db/password-front.js.map +1 -0
- package/dist/db/process-identity.d.ts +36 -0
- package/dist/db/process-identity.d.ts.map +1 -0
- package/dist/db/process-identity.js +114 -0
- package/dist/db/process-identity.js.map +1 -0
- package/dist/db/state-file.d.ts +54 -0
- package/dist/db/state-file.d.ts.map +1 -0
- package/dist/db/state-file.js +91 -0
- package/dist/db/state-file.js.map +1 -0
- package/dist/db/url.d.ts +89 -0
- package/dist/db/url.d.ts.map +1 -0
- package/dist/db/url.js +118 -0
- package/dist/db/url.js.map +1 -0
- package/dist/extend.d.ts +13 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js +24 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +87 -42
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +457 -677
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +3 -4
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +2 -2
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -2
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +0 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +12 -5
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +47 -19
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/types.d.ts +10 -24
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +22 -31
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +33 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/transition-guard.d.ts +61 -0
- package/dist/hooks/transition-guard.d.ts.map +1 -0
- package/dist/hooks/transition-guard.js +93 -0
- package/dist/hooks/transition-guard.js.map +1 -0
- package/dist/index.d.ts +52 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -44
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +221 -0
- package/dist/validation/database-config.js.map +1 -0
- package/dist/validation/default-value.d.ts +21 -0
- package/dist/validation/default-value.d.ts.map +1 -0
- package/dist/validation/default-value.js +72 -0
- package/dist/validation/default-value.js.map +1 -0
- package/dist/validation/extension-packs.d.ts +11 -0
- package/dist/validation/extension-packs.d.ts.map +1 -0
- package/dist/validation/extension-packs.js +53 -0
- package/dist/validation/extension-packs.js.map +1 -0
- package/dist/validation/field-config.d.ts +35 -21
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +51 -41
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +15 -0
- package/dist/validation/field-names.d.ts.map +1 -0
- package/dist/validation/field-names.js +155 -0
- package/dist/validation/field-names.js.map +1 -0
- package/dist/validation/identifier-names.d.ts +4 -0
- package/dist/validation/identifier-names.d.ts.map +1 -0
- package/dist/validation/identifier-names.js +39 -0
- package/dist/validation/identifier-names.js.map +1 -0
- package/dist/validation/needs-closure.d.ts +20 -30
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +29 -105
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts +17 -0
- package/dist/validation/relations.d.ts.map +1 -0
- package/dist/validation/relations.js +268 -0
- package/dist/validation/relations.js.map +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +1 -3
- package/dist/validation/schema.js.map +1 -1
- package/dist/where/like.d.ts +32 -0
- package/dist/where/like.d.ts.map +1 -0
- package/dist/where/like.js +42 -0
- package/dist/where/like.js.map +1 -0
- package/package.json +70 -8
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -609
- package/dist/access/access-filter.d.ts +0 -241
- package/dist/access/access-filter.d.ts.map +0 -1
- package/dist/access/access-filter.js +0 -692
- package/dist/access/access-filter.js.map +0 -1
- package/dist/access/access-filter.test.d.ts +0 -2
- package/dist/access/access-filter.test.d.ts.map +0 -1
- package/dist/access/access-filter.test.js +0 -1256
- package/dist/access/access-filter.test.js.map +0 -1
- package/dist/access/declared-dependencies.test.d.ts +0 -2
- package/dist/access/declared-dependencies.test.d.ts.map +0 -1
- package/dist/access/declared-dependencies.test.js +0 -226
- package/dist/access/declared-dependencies.test.js.map +0 -1
- package/dist/access/denied-relation-visibility.test.d.ts +0 -2
- package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
- package/dist/access/denied-relation-visibility.test.js +0 -114
- package/dist/access/denied-relation-visibility.test.js.map +0 -1
- package/dist/access/engine.test.d.ts +0 -2
- package/dist/access/engine.test.d.ts.map +0 -1
- package/dist/access/engine.test.js +0 -56
- package/dist/access/engine.test.js.map +0 -1
- package/dist/access/field-access.test.d.ts +0 -2
- package/dist/access/field-access.test.d.ts.map +0 -1
- package/dist/access/field-access.test.js +0 -635
- package/dist/access/field-access.test.js.map +0 -1
- package/dist/access/multi-column-read-write.test.d.ts +0 -2
- package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
- package/dist/access/multi-column-read-write.test.js +0 -183
- package/dist/access/multi-column-read-write.test.js.map +0 -1
- package/dist/access/relationship-count.d.ts +0 -98
- package/dist/access/relationship-count.d.ts.map +0 -1
- package/dist/access/relationship-count.js +0 -262
- package/dist/access/relationship-count.js.map +0 -1
- package/dist/access/relationship-count.test.d.ts +0 -2
- package/dist/access/relationship-count.test.d.ts.map +0 -1
- package/dist/access/relationship-count.test.js +0 -247
- package/dist/access/relationship-count.test.js.map +0 -1
- package/dist/access/relationship-label-filter.d.ts +0 -45
- package/dist/access/relationship-label-filter.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.js +0 -22
- package/dist/access/relationship-label-filter.js.map +0 -1
- package/dist/access/relationship-label-filter.test.d.ts +0 -2
- package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.test.js +0 -89
- package/dist/access/relationship-label-filter.test.js.map +0 -1
- package/dist/access/synthetic-include-read.test.d.ts +0 -2
- package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
- package/dist/access/synthetic-include-read.test.js +0 -121
- package/dist/access/synthetic-include-read.test.js.map +0 -1
- package/dist/context/nested-operations.d.ts +0 -47
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -731
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1325
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -184
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3141
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -231
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PostgresOptionsBase, PostgresOptions } from '@prisma/orm-postgres/runtime';
|
|
2
|
+
import type { DatabaseClientConfig } from '../config/types.js';
|
|
3
|
+
import { type DatabaseUrlLookupOptions } from './url.js';
|
|
4
|
+
type PostgresBindingOptions = PostgresOptions<never>;
|
|
5
|
+
/**
|
|
6
|
+
* The connection half of the runtime client's construction options — what the
|
|
7
|
+
* generated context spreads into `postgres()` beside the contract, the
|
|
8
|
+
* extensions and the tripwire. Exactly one of `pg` and `url` is ever present.
|
|
9
|
+
*/
|
|
10
|
+
export interface RuntimeConnectionOptions {
|
|
11
|
+
/** A pool or client the runtime binds to instead of dialling `url` itself. */
|
|
12
|
+
readonly pg?: NonNullable<PostgresBindingOptions['pg']>;
|
|
13
|
+
/** The connection string, when the runtime opens its own pool. */
|
|
14
|
+
readonly url?: string;
|
|
15
|
+
/** Timeouts handed to the runtime's own pool, from `db.client.poolOptions`. */
|
|
16
|
+
readonly poolOptions?: PostgresOptionsBase['poolOptions'];
|
|
17
|
+
/** Present, and `false`, only on the Dev database (ADR-0063). */
|
|
18
|
+
readonly verifyMarker?: PostgresOptionsBase['verifyMarker'];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Choose how the generated runtime client connects, from the app's
|
|
22
|
+
* `db.client` binding and the stack's URL lookup (ADR-0049, ADR-0063).
|
|
23
|
+
*
|
|
24
|
+
* Three branches, in order:
|
|
25
|
+
*
|
|
26
|
+
* 1. `db.client.pg` — the app owns the pool. The factory is called here, and
|
|
27
|
+
* nowhere else, so a config load that never reaches the runtime opens no
|
|
28
|
+
* connection. Call this once per process, under the client singleton. An
|
|
29
|
+
* explicit pool wins outright, so it also displaces branch 2: a pool
|
|
30
|
+
* supplied while the Dev database is running gets neither workaround
|
|
31
|
+
* ADR-0063 requires, and is warned about rather than silently rebound.
|
|
32
|
+
* 2. Dev-database provenance — a single-connection pool with the contract
|
|
33
|
+
* marker check off.
|
|
34
|
+
* 3. An env URL — the connection string and Prisma's defaults.
|
|
35
|
+
*
|
|
36
|
+
* The pool built on branch 2 is not owned by anything: rc.8 installs
|
|
37
|
+
* `ownedDispose` for `kind: 'url'` bindings only, so nothing ends it. The dev
|
|
38
|
+
* loop's database is ephemeral and goes with the process, which is why that is
|
|
39
|
+
* survivable here and not on branch 1.
|
|
40
|
+
*
|
|
41
|
+
* @throws {DatabaseUrlUnresolvedError} on branch 2/3 when neither
|
|
42
|
+
* `DATABASE_URL` nor a running dev database supplies a connection.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* postgres<Contract>({
|
|
47
|
+
* contractJson,
|
|
48
|
+
* middleware: [originTripwire],
|
|
49
|
+
* ...resolveRuntimeConnection(config.db.client),
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveRuntimeConnection(client?: DatabaseClientConfig, options?: DatabaseUrlLookupOptions): RuntimeConnectionOptions;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/db/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACxF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAA8C,KAAK,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAUpG,KAAK,sBAAsB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;AAEpD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA;IACvD,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAA;IACzD,iEAAiE;IACjE,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;CAC5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,CAAC,EAAE,oBAAoB,EAC7B,OAAO,GAAE,wBAA6B,GACrC,wBAAwB,CAkC1B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
import { findDatabaseConnection, resolveDatabaseUrl } from './url.js';
|
|
3
|
+
/**
|
|
4
|
+
* Prisma's own pool waits 20 s for a connection; pg's default is `0` — wait
|
|
5
|
+
* forever. A hand-built pool is not covered by rc.8's `poolOptions`, which
|
|
6
|
+
* `toRuntimeBinding()` applies to `kind: 'url'` bindings only, so the ceiling
|
|
7
|
+
* has to be set here or a stuck checkout wedges the single connection silently.
|
|
8
|
+
*/
|
|
9
|
+
const DEV_CONNECTION_TIMEOUT_MS = 20_000;
|
|
10
|
+
/**
|
|
11
|
+
* Choose how the generated runtime client connects, from the app's
|
|
12
|
+
* `db.client` binding and the stack's URL lookup (ADR-0049, ADR-0063).
|
|
13
|
+
*
|
|
14
|
+
* Three branches, in order:
|
|
15
|
+
*
|
|
16
|
+
* 1. `db.client.pg` — the app owns the pool. The factory is called here, and
|
|
17
|
+
* nowhere else, so a config load that never reaches the runtime opens no
|
|
18
|
+
* connection. Call this once per process, under the client singleton. An
|
|
19
|
+
* explicit pool wins outright, so it also displaces branch 2: a pool
|
|
20
|
+
* supplied while the Dev database is running gets neither workaround
|
|
21
|
+
* ADR-0063 requires, and is warned about rather than silently rebound.
|
|
22
|
+
* 2. Dev-database provenance — a single-connection pool with the contract
|
|
23
|
+
* marker check off.
|
|
24
|
+
* 3. An env URL — the connection string and Prisma's defaults.
|
|
25
|
+
*
|
|
26
|
+
* The pool built on branch 2 is not owned by anything: rc.8 installs
|
|
27
|
+
* `ownedDispose` for `kind: 'url'` bindings only, so nothing ends it. The dev
|
|
28
|
+
* loop's database is ephemeral and goes with the process, which is why that is
|
|
29
|
+
* survivable here and not on branch 1.
|
|
30
|
+
*
|
|
31
|
+
* @throws {DatabaseUrlUnresolvedError} on branch 2/3 when neither
|
|
32
|
+
* `DATABASE_URL` nor a running dev database supplies a connection.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* postgres<Contract>({
|
|
37
|
+
* contractJson,
|
|
38
|
+
* middleware: [originTripwire],
|
|
39
|
+
* ...resolveRuntimeConnection(config.db.client),
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function resolveRuntimeConnection(client, options = {}) {
|
|
44
|
+
const pg = client?.pg?.();
|
|
45
|
+
if (pg !== undefined) {
|
|
46
|
+
if (findDatabaseConnection(options)?.provenance === 'dev-database') {
|
|
47
|
+
console.warn('opensaas: db.client.pg is bound while the dev database is running, so this pool ' +
|
|
48
|
+
'replaces the single-connection binding that database needs (ADR-0063). Expect ' +
|
|
49
|
+
'corrupted session state and a deadlock on the contract marker; unset db.client.pg ' +
|
|
50
|
+
'to run against `opensaas dev`, or point DATABASE_URL at your own Postgres.');
|
|
51
|
+
}
|
|
52
|
+
return { pg };
|
|
53
|
+
}
|
|
54
|
+
const { url, provenance } = resolveDatabaseUrl(options);
|
|
55
|
+
if (provenance === 'dev-database') {
|
|
56
|
+
// `pglite-socket` multiplexes every connection onto one PGlite session, so
|
|
57
|
+
// a client spreading work across a pool corrupts its own session state,
|
|
58
|
+
// and the marker's first-use read deadlocks a request that opens a
|
|
59
|
+
// transaction. Both are properties of the Dev database, not of Postgres:
|
|
60
|
+
// do not lift either to the `url` branch, and do not drop them here
|
|
61
|
+
// (ADR-0063).
|
|
62
|
+
return {
|
|
63
|
+
pg: new Pool({
|
|
64
|
+
connectionString: url,
|
|
65
|
+
max: 1,
|
|
66
|
+
connectionTimeoutMillis: DEV_CONNECTION_TIMEOUT_MS,
|
|
67
|
+
}),
|
|
68
|
+
verifyMarker: false,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return client?.poolOptions !== undefined ? { url, poolOptions: client.poolOptions } : { url };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/db/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAGzB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAiC,MAAM,UAAU,CAAA;AAEpG;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAoBxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA6B,EAC7B,OAAO,GAA6B,EAAE;IAEtC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,CAAA;IACzB,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,UAAU,KAAK,cAAc,EAAE,CAAC;YACnE,OAAO,CAAC,IAAI,CACV,kFAAkF;gBAChF,gFAAgF;gBAChF,oFAAoF;gBACpF,4EAA4E,CAC/E,CAAA;QACH,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,CAAA;IACf,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAEvD,IAAI,UAAU,KAAK,cAAc,EAAE,CAAC;QAClC,2EAA2E;QAC3E,wEAAwE;QACxE,mEAAmE;QACnE,yEAAyE;QACzE,oEAAoE;QACpE,cAAc;QACd,OAAO;YACL,EAAE,EAAE,IAAI,IAAI,CAAC;gBACX,gBAAgB,EAAE,GAAG;gBACrB,GAAG,EAAE,CAAC;gBACN,uBAAuB,EAAE,yBAAyB;aACnD,CAAC;YACF,YAAY,EAAE,KAAK;SACpB,CAAA;IACH,CAAC;IAED,OAAO,MAAM,EAAE,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA;AAC/F,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Dev database: an in-process PGlite the stack runs itself (ADR-0063).
|
|
3
|
+
*
|
|
4
|
+
* Known limits of this primitive:
|
|
5
|
+
*
|
|
6
|
+
* - Every TCP connection is multiplexed onto **one** PGlite session, so a
|
|
7
|
+
* client with a multi-connection pool corrupts its own session state.
|
|
8
|
+
* Clients bind a single connection; `maxConnections` only buys headroom for
|
|
9
|
+
* the several single-connection clients that share one sidecar. That
|
|
10
|
+
* headroom counts distinct PROCESSES (the app, the CLI, a seed, a `psql`) —
|
|
11
|
+
* the generated context's own client is one process-wide singleton
|
|
12
|
+
* regardless of how many times a bundler duplicates its module (ADR-0070),
|
|
13
|
+
* so one running app never claims more than one of these slots on its own.
|
|
14
|
+
* - A connection holding an open transaction holds the whole query queue.
|
|
15
|
+
* - PGlite opens a data directory in one process at a time. `startDevDatabase`
|
|
16
|
+
* enforces this against itself — a second call against the same `dataDir`
|
|
17
|
+
* fails naming the first — but the guard is a lock file inside that
|
|
18
|
+
* directory: a bare `new PGlite({ dataDir })` bypassing this primitive, or
|
|
19
|
+
* the lock file being deleted out from under a running sidecar, is not
|
|
20
|
+
* caught.
|
|
21
|
+
* - There is no daemon, registry or cross-process lookup: the database dies
|
|
22
|
+
* with the process that started it, and other processes find it through the
|
|
23
|
+
* state file.
|
|
24
|
+
* - Stale-sidecar detection (the state file's pid, and the `dataDir` lock's)
|
|
25
|
+
* compares process start times to tell a live pid from an unrelated process
|
|
26
|
+
* that inherited it after a reboot or pid wrap. The comparison is
|
|
27
|
+
* approximate — Linux assumes a 100 Hz clock, macOS's `ps` only carries
|
|
28
|
+
* one-second resolution — and unavailable on any other platform, where a
|
|
29
|
+
* live pid is trusted outright exactly as it was before this check existed.
|
|
30
|
+
* - An IPv6 `host` is bracketed into the published URL, which is the RFC 3986
|
|
31
|
+
* form; node-postgres does not strip those brackets when it parses a
|
|
32
|
+
* connection string, so such a client takes `host` and `port` off the handle
|
|
33
|
+
* instead of the URL.
|
|
34
|
+
* - PGlite is served on a unix socket in a 0700 temp directory; the TCP port
|
|
35
|
+
* is a cleartext-password front carrying a per-boot password in the URL.
|
|
36
|
+
* Platforms without unix-domain sockets are not supported.
|
|
37
|
+
*/
|
|
38
|
+
/** Extensions this primitive can make available on the started instance. */
|
|
39
|
+
export type DevDatabaseExtension = 'vector';
|
|
40
|
+
/** Options for {@link startDevDatabase}. */
|
|
41
|
+
export interface StartDevDatabaseOptions {
|
|
42
|
+
/**
|
|
43
|
+
* The PGlite data directory. Omitted, the database is in-memory and nothing
|
|
44
|
+
* survives the process — which is what the test harness wants and the dev
|
|
45
|
+
* loop does not.
|
|
46
|
+
*
|
|
47
|
+
* Resolved against `cwd` (or `process.cwd()`, absent that) when relative —
|
|
48
|
+
* the same root the state file resolves against — so a relative `dataDir`
|
|
49
|
+
* and an explicit `cwd` never disagree about where the data directory is.
|
|
50
|
+
*/
|
|
51
|
+
dataDir?: string;
|
|
52
|
+
/** Extensions loaded into the instance, ready for `CREATE EXTENSION`. */
|
|
53
|
+
extensions?: readonly DevDatabaseExtension[];
|
|
54
|
+
/**
|
|
55
|
+
* The socket server's connection ceiling. Defaults to
|
|
56
|
+
* {@link DEFAULT_MAX_CONNECTIONS} — headroom for the several
|
|
57
|
+
* single-connection clients that share one sidecar (the app, the CLI, a
|
|
58
|
+
* seed, a `psql`), not licence for any one of them to open a pool.
|
|
59
|
+
*/
|
|
60
|
+
maxConnections?: number;
|
|
61
|
+
/** The loopback address to bind. Defaults to `127.0.0.1`. */
|
|
62
|
+
host?: string;
|
|
63
|
+
/** The project root whose Generated bundle receives the state file. */
|
|
64
|
+
cwd?: string;
|
|
65
|
+
/** An explicit state file path, bypassing `cwd` and the bundle directory. */
|
|
66
|
+
stateFile?: string;
|
|
67
|
+
}
|
|
68
|
+
/** A running Dev database. */
|
|
69
|
+
export interface DevDatabase {
|
|
70
|
+
/** The connection string written to the state file. */
|
|
71
|
+
readonly url: string;
|
|
72
|
+
readonly host: string;
|
|
73
|
+
readonly port: number;
|
|
74
|
+
/** The absolute data directory, or `undefined` when the instance is in-memory. */
|
|
75
|
+
readonly dataDir: string | undefined;
|
|
76
|
+
/** Absolute path to the state file this instance wrote. */
|
|
77
|
+
readonly stateFile: string;
|
|
78
|
+
/**
|
|
79
|
+
* Stops the socket server, closes PGlite, then drops this instance's state
|
|
80
|
+
* file. Idempotent: a second call resolves without touching anything.
|
|
81
|
+
*/
|
|
82
|
+
stop(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Headroom for the several single-connection clients that share one sidecar
|
|
86
|
+
* (ADR-0063).
|
|
87
|
+
*/
|
|
88
|
+
export declare const DEFAULT_MAX_CONNECTIONS = 20;
|
|
89
|
+
/** Thrown by {@link startDevDatabase} when another sidecar already holds `dataDir`. */
|
|
90
|
+
export declare class DevDatabaseInUseError extends Error {
|
|
91
|
+
constructor(dataDir: string, pid: number);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Starts an in-process PGlite behind a socket server on a free loopback TCP
|
|
95
|
+
* port and publishes it in the Generated bundle's state file, so that every
|
|
96
|
+
* other process — the app, `db update` in a second terminal, a seed script —
|
|
97
|
+
* finds it through `resolveDatabaseUrl()` rather than an injected variable
|
|
98
|
+
* (ADR-0063).
|
|
99
|
+
*
|
|
100
|
+
* The state file is rewritten on every boot; a record left behind by a crashed
|
|
101
|
+
* sidecar is ignored on its pid.
|
|
102
|
+
*
|
|
103
|
+
* PGlite and its socket and pgvector packages are optional peers of core,
|
|
104
|
+
* imported only here, only when called — a production install carries no WASM
|
|
105
|
+
* Postgres.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* import { startDevDatabase } from '@opensaas/stack-core/dev-database'
|
|
110
|
+
*
|
|
111
|
+
* const database = await startDevDatabase({
|
|
112
|
+
* dataDir: '.opensaas/dev-db',
|
|
113
|
+
* extensions: ['vector'],
|
|
114
|
+
* })
|
|
115
|
+
* try {
|
|
116
|
+
* // `resolveDatabaseUrl()` now reports provenance 'dev-database' here
|
|
117
|
+
* // and in every child process.
|
|
118
|
+
* } finally {
|
|
119
|
+
* await database.stop()
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function startDevDatabase(options?: StartDevDatabaseOptions): Promise<DevDatabase>;
|
|
124
|
+
//# sourceMappingURL=dev-database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-database.d.ts","sourceRoot":"","sources":["../../src/db/dev-database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAqBH,4EAA4E;AAC5E,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE3C,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yEAAyE;IACzE,UAAU,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAA;IAC5C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAqDzC,uFAAuF;AACvF,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAQvC;CACF;AA+GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,WAAW,CAAC,CAiEtB"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Dev database: an in-process PGlite the stack runs itself (ADR-0063).
|
|
3
|
+
*
|
|
4
|
+
* Known limits of this primitive:
|
|
5
|
+
*
|
|
6
|
+
* - Every TCP connection is multiplexed onto **one** PGlite session, so a
|
|
7
|
+
* client with a multi-connection pool corrupts its own session state.
|
|
8
|
+
* Clients bind a single connection; `maxConnections` only buys headroom for
|
|
9
|
+
* the several single-connection clients that share one sidecar. That
|
|
10
|
+
* headroom counts distinct PROCESSES (the app, the CLI, a seed, a `psql`) —
|
|
11
|
+
* the generated context's own client is one process-wide singleton
|
|
12
|
+
* regardless of how many times a bundler duplicates its module (ADR-0070),
|
|
13
|
+
* so one running app never claims more than one of these slots on its own.
|
|
14
|
+
* - A connection holding an open transaction holds the whole query queue.
|
|
15
|
+
* - PGlite opens a data directory in one process at a time. `startDevDatabase`
|
|
16
|
+
* enforces this against itself — a second call against the same `dataDir`
|
|
17
|
+
* fails naming the first — but the guard is a lock file inside that
|
|
18
|
+
* directory: a bare `new PGlite({ dataDir })` bypassing this primitive, or
|
|
19
|
+
* the lock file being deleted out from under a running sidecar, is not
|
|
20
|
+
* caught.
|
|
21
|
+
* - There is no daemon, registry or cross-process lookup: the database dies
|
|
22
|
+
* with the process that started it, and other processes find it through the
|
|
23
|
+
* state file.
|
|
24
|
+
* - Stale-sidecar detection (the state file's pid, and the `dataDir` lock's)
|
|
25
|
+
* compares process start times to tell a live pid from an unrelated process
|
|
26
|
+
* that inherited it after a reboot or pid wrap. The comparison is
|
|
27
|
+
* approximate — Linux assumes a 100 Hz clock, macOS's `ps` only carries
|
|
28
|
+
* one-second resolution — and unavailable on any other platform, where a
|
|
29
|
+
* live pid is trusted outright exactly as it was before this check existed.
|
|
30
|
+
* - An IPv6 `host` is bracketed into the published URL, which is the RFC 3986
|
|
31
|
+
* form; node-postgres does not strip those brackets when it parses a
|
|
32
|
+
* connection string, so such a client takes `host` and `port` off the handle
|
|
33
|
+
* instead of the URL.
|
|
34
|
+
* - PGlite is served on a unix socket in a 0700 temp directory; the TCP port
|
|
35
|
+
* is a cleartext-password front carrying a per-boot password in the URL.
|
|
36
|
+
* Platforms without unix-domain sockets are not supported.
|
|
37
|
+
*/
|
|
38
|
+
import { randomBytes } from 'node:crypto';
|
|
39
|
+
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
40
|
+
import { tmpdir } from 'node:os';
|
|
41
|
+
import * as path from 'node:path';
|
|
42
|
+
import { startPasswordFront } from './password-front.js';
|
|
43
|
+
import { describeSelf, identifiesLiveProcess, processClaimSchema, } from './process-identity.js';
|
|
44
|
+
import { clearDevDatabaseState, devDatabaseStatePath, writeDevDatabaseState, } from './state-file.js';
|
|
45
|
+
/**
|
|
46
|
+
* Headroom for the several single-connection clients that share one sidecar
|
|
47
|
+
* (ADR-0063).
|
|
48
|
+
*/
|
|
49
|
+
export const DEFAULT_MAX_CONNECTIONS = 20;
|
|
50
|
+
/** PGlite's one database, and therefore the name every URL carries. */
|
|
51
|
+
const DATABASE_NAME = 'postgres';
|
|
52
|
+
const EXTENSION_LOADERS = {
|
|
53
|
+
vector: async () => (await import('@electric-sql/pglite-pgvector')).vector,
|
|
54
|
+
};
|
|
55
|
+
async function loadExtensions(names) {
|
|
56
|
+
const loaded = {};
|
|
57
|
+
for (const name of names) {
|
|
58
|
+
loaded[name] = await EXTENSION_LOADERS[name]();
|
|
59
|
+
}
|
|
60
|
+
return loaded;
|
|
61
|
+
}
|
|
62
|
+
async function release(steps) {
|
|
63
|
+
const failures = [];
|
|
64
|
+
for (const step of steps) {
|
|
65
|
+
try {
|
|
66
|
+
await step();
|
|
67
|
+
}
|
|
68
|
+
catch (failure) {
|
|
69
|
+
failures.push(failure);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (failures.length === 1)
|
|
73
|
+
throw failures[0];
|
|
74
|
+
if (failures.length > 1) {
|
|
75
|
+
throw new AggregateError(failures, 'The dev database did not shut down cleanly.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* pglite-socket 0.2.x (https://github.com/electric-sql/pglite/tree/main/packages/pglite-socket,
|
|
80
|
+
* `PGLiteSocketHandler.handleClose`) runs a closed socket's detach (transaction rollback
|
|
81
|
+
* included) on `setImmediate`, and `server.stop()` resolves without awaiting
|
|
82
|
+
* it. One turn of the check phase runs every detach already scheduled, and
|
|
83
|
+
* the exclusive lock queues behind any rollback they started.
|
|
84
|
+
*/
|
|
85
|
+
async function settleSocketCleanup(pglite) {
|
|
86
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
87
|
+
await pglite.runExclusive(async () => { });
|
|
88
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
89
|
+
}
|
|
90
|
+
function authorityOf(host) {
|
|
91
|
+
return host.includes(':') ? `[${host}]` : host;
|
|
92
|
+
}
|
|
93
|
+
/** Thrown by {@link startDevDatabase} when another sidecar already holds `dataDir`. */
|
|
94
|
+
export class DevDatabaseInUseError extends Error {
|
|
95
|
+
constructor(dataDir, pid) {
|
|
96
|
+
super(`The dev database data directory "${dataDir}" is already open in another process ` +
|
|
97
|
+
`(pid ${pid}). PGlite serves one process at a time, so a second sidecar racing the ` +
|
|
98
|
+
`first over the same files would corrupt it — stop that process or start this one ` +
|
|
99
|
+
`against a different \`dataDir\`.`);
|
|
100
|
+
this.name = 'DevDatabaseInUseError';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The lock file's name inside the data directory it claims. Distinct from
|
|
105
|
+
* anything PGlite itself writes there, so this primitive's own bookkeeping
|
|
106
|
+
* cannot collide with the emulated Postgres data directory it sits beside.
|
|
107
|
+
*/
|
|
108
|
+
const DATA_DIR_LOCK_FILE_NAME = '.opensaas-dev-database.lock';
|
|
109
|
+
function restrictDataDir(dataDir) {
|
|
110
|
+
if (process.platform === 'win32')
|
|
111
|
+
return;
|
|
112
|
+
try {
|
|
113
|
+
chmodSync(dataDir, 0o700);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
117
|
+
throw new Error(`Could not restrict the Dev database data directory ${dataDir} to 0700: ${reason}`, {
|
|
118
|
+
cause: error,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function readDataDirLock(lockFile) {
|
|
123
|
+
let contents;
|
|
124
|
+
try {
|
|
125
|
+
contents = readFileSync(lockFile, 'utf8');
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
let parsed;
|
|
131
|
+
try {
|
|
132
|
+
parsed = JSON.parse(contents);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const claim = processClaimSchema.safeParse(parsed);
|
|
138
|
+
return claim.success ? claim.data : undefined;
|
|
139
|
+
}
|
|
140
|
+
function writeDataDirLock(lockFile, claim) {
|
|
141
|
+
writeFileSync(lockFile, `${JSON.stringify(claim, null, 2)}\n`, {
|
|
142
|
+
encoding: 'utf8',
|
|
143
|
+
flag: 'wx',
|
|
144
|
+
mode: 0o600,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Removes the lock only while it still names the claim that took it. */
|
|
148
|
+
function releaseDataDirLock(lockFile, claim) {
|
|
149
|
+
const existing = readDataDirLock(lockFile);
|
|
150
|
+
if (existing !== undefined &&
|
|
151
|
+
(existing.pid !== claim.pid || existing.startedAt !== claim.startedAt)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
rmSync(lockFile, { force: true });
|
|
155
|
+
}
|
|
156
|
+
/** Bounds the stale-lock replacement loop below — a cost limit, not a real ceiling on contention. */
|
|
157
|
+
const MAX_DATA_DIR_LOCK_ATTEMPTS = 5;
|
|
158
|
+
/**
|
|
159
|
+
* Claims `dataDir` for this process before PGlite ever opens it, so a second
|
|
160
|
+
* `startDevDatabase` against the same directory fails naming the first
|
|
161
|
+
* instead of racing it over the same files. A lock a dead or recycled pid
|
|
162
|
+
* left behind is replaced rather than honoured, mirroring the state file's
|
|
163
|
+
* own stale-record handling (`identifiesLiveProcess`).
|
|
164
|
+
*
|
|
165
|
+
* Replacing a stale lock is read-then-write, not atomic on its own — the
|
|
166
|
+
* `wx` create on the next loop iteration is what actually resolves two
|
|
167
|
+
* starters racing the same replacement: at most one of them can create the
|
|
168
|
+
* file, and the other's next `EEXIST` observes ITS live claim and throws
|
|
169
|
+
* below rather than both believing they hold the directory. `release` is
|
|
170
|
+
* likewise ownership-checked, so a starter that lost that race can never
|
|
171
|
+
* delete the winner's lock out from under it at `stop()`.
|
|
172
|
+
*
|
|
173
|
+
* @throws {DevDatabaseInUseError} when a live sidecar already holds `dataDir`.
|
|
174
|
+
*/
|
|
175
|
+
function acquireDataDirLock(dataDir) {
|
|
176
|
+
mkdirSync(dataDir, { recursive: true, mode: 0o700 });
|
|
177
|
+
restrictDataDir(dataDir);
|
|
178
|
+
const lockFile = path.join(dataDir, DATA_DIR_LOCK_FILE_NAME);
|
|
179
|
+
const claim = describeSelf();
|
|
180
|
+
for (let attempt = 0; attempt < MAX_DATA_DIR_LOCK_ATTEMPTS; attempt++) {
|
|
181
|
+
try {
|
|
182
|
+
writeDataDirLock(lockFile, claim);
|
|
183
|
+
return () => releaseDataDirLock(lockFile, claim);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'EEXIST'))
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
const existing = readDataDirLock(lockFile);
|
|
190
|
+
if (existing !== undefined && identifiesLiveProcess(existing)) {
|
|
191
|
+
throw new DevDatabaseInUseError(dataDir, existing.pid);
|
|
192
|
+
}
|
|
193
|
+
// Stale: the pid that wrote this lock is gone, or a reboot/wrap has
|
|
194
|
+
// handed it to an unrelated process. Clear it and loop back to the `wx`
|
|
195
|
+
// create above.
|
|
196
|
+
rmSync(lockFile, { force: true });
|
|
197
|
+
}
|
|
198
|
+
throw new Error(`Could not claim the dev database data directory "${dataDir}": a stale lock kept reappearing.`);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Starts an in-process PGlite behind a socket server on a free loopback TCP
|
|
202
|
+
* port and publishes it in the Generated bundle's state file, so that every
|
|
203
|
+
* other process — the app, `db update` in a second terminal, a seed script —
|
|
204
|
+
* finds it through `resolveDatabaseUrl()` rather than an injected variable
|
|
205
|
+
* (ADR-0063).
|
|
206
|
+
*
|
|
207
|
+
* The state file is rewritten on every boot; a record left behind by a crashed
|
|
208
|
+
* sidecar is ignored on its pid.
|
|
209
|
+
*
|
|
210
|
+
* PGlite and its socket and pgvector packages are optional peers of core,
|
|
211
|
+
* imported only here, only when called — a production install carries no WASM
|
|
212
|
+
* Postgres.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* import { startDevDatabase } from '@opensaas/stack-core/dev-database'
|
|
217
|
+
*
|
|
218
|
+
* const database = await startDevDatabase({
|
|
219
|
+
* dataDir: '.opensaas/dev-db',
|
|
220
|
+
* extensions: ['vector'],
|
|
221
|
+
* })
|
|
222
|
+
* try {
|
|
223
|
+
* // `resolveDatabaseUrl()` now reports provenance 'dev-database' here
|
|
224
|
+
* // and in every child process.
|
|
225
|
+
* } finally {
|
|
226
|
+
* await database.stop()
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export async function startDevDatabase(options = {}) {
|
|
231
|
+
const { PGlite } = await import('@electric-sql/pglite');
|
|
232
|
+
const { PGLiteSocketServer } = await import('@electric-sql/pglite-socket');
|
|
233
|
+
const host = options.host ?? '127.0.0.1';
|
|
234
|
+
const cwd = options.cwd ?? process.cwd();
|
|
235
|
+
const dataDir = options.dataDir !== undefined ? path.resolve(cwd, options.dataDir) : undefined;
|
|
236
|
+
const extensions = await loadExtensions(options.extensions ?? []);
|
|
237
|
+
const teardown = [];
|
|
238
|
+
if (dataDir !== undefined) {
|
|
239
|
+
const releaseLock = acquireDataDirLock(dataDir);
|
|
240
|
+
teardown.push(async () => releaseLock());
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const pglite = new PGlite({ ...(dataDir !== undefined && { dataDir }), extensions });
|
|
244
|
+
// Registered before the `await` below, not after: a rejected `waitReady`
|
|
245
|
+
// must still close the handle it rejected on, not just release the lock.
|
|
246
|
+
teardown.unshift(() => pglite.close());
|
|
247
|
+
await pglite.waitReady;
|
|
248
|
+
const socketDir = mkdtempSync(path.join(tmpdir(), 'opensaas-dev-db-'));
|
|
249
|
+
teardown.unshift(async () => rmSync(socketDir, { recursive: true, force: true }));
|
|
250
|
+
const socketPath = path.join(socketDir, 'pg.sock');
|
|
251
|
+
const server = new PGLiteSocketServer({
|
|
252
|
+
db: pglite,
|
|
253
|
+
path: socketPath,
|
|
254
|
+
maxConnections: options.maxConnections ?? DEFAULT_MAX_CONNECTIONS,
|
|
255
|
+
});
|
|
256
|
+
await server.start();
|
|
257
|
+
teardown.unshift(() => settleSocketCleanup(pglite));
|
|
258
|
+
teardown.unshift(() => server.stop());
|
|
259
|
+
const password = randomBytes(16).toString('hex');
|
|
260
|
+
const front = await startPasswordFront({ host, innerPath: socketPath, password });
|
|
261
|
+
teardown.unshift(() => front.stop());
|
|
262
|
+
const port = front.port;
|
|
263
|
+
const url = `postgres://${DATABASE_NAME}:${password}@${authorityOf(host)}:${port}/${DATABASE_NAME}`;
|
|
264
|
+
const location = {
|
|
265
|
+
cwd,
|
|
266
|
+
...(options.stateFile !== undefined && { stateFile: options.stateFile }),
|
|
267
|
+
};
|
|
268
|
+
const stateFile = devDatabaseStatePath(location);
|
|
269
|
+
writeDevDatabaseState(stateFile, { url, pid: process.pid });
|
|
270
|
+
let stopped = false;
|
|
271
|
+
return {
|
|
272
|
+
url,
|
|
273
|
+
host,
|
|
274
|
+
port,
|
|
275
|
+
dataDir,
|
|
276
|
+
stateFile,
|
|
277
|
+
stop: async () => {
|
|
278
|
+
if (stopped)
|
|
279
|
+
return;
|
|
280
|
+
stopped = true;
|
|
281
|
+
await release(teardown);
|
|
282
|
+
clearDevDatabaseState(stateFile, url);
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
await release(teardown).catch(() => { });
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=dev-database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-database.js","sourceRoot":"","sources":["../../src/db/dev-database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,GAEnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,GAEtB,MAAM,iBAAiB,CAAA;AAmDxB;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAA;AAEzC,uEAAuE;AACvE,MAAM,aAAa,GAAG,UAAU,CAAA;AAEhC,MAAM,iBAAiB,GAA2D;IAChF,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC,CAAC,MAAM;CAC3E,CAAA;AAED,KAAK,UAAU,cAAc,CAC3B,KAAsC;IAEtC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAC5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,EAAE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,10 @@
|
|
|
1
|
+
export interface PasswordFront {
|
|
2
|
+
readonly port: number;
|
|
3
|
+
stop(): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare function startPasswordFront(options: {
|
|
6
|
+
host: string;
|
|
7
|
+
innerPath: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}): Promise<PasswordFront>;
|
|
10
|
+
//# sourceMappingURL=password-front.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-front.d.ts","sourceRoot":"","sources":["../../src/db/password-front.ts"],"names":[],"mappings":"AAuHA,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,OAAO,CAAC,aAAa,CAAC,CA0BzB"}
|