@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,147 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { createConnection, createServer } from 'node:net';
|
|
3
|
+
const SSL_REQUEST_CODE = 80877103;
|
|
4
|
+
const GSS_ENC_REQUEST_CODE = 80877104;
|
|
5
|
+
const CANCEL_REQUEST_CODE = 80877102;
|
|
6
|
+
const HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
7
|
+
const PROTOCOL_VERSION_3 = 196608;
|
|
8
|
+
const CLEARTEXT_PASSWORD_REQUEST = Buffer.from([0x52, 0, 0, 0, 8, 0, 0, 0, 3]);
|
|
9
|
+
function authenticationFailed(user) {
|
|
10
|
+
const fields = [
|
|
11
|
+
['S', 'FATAL'],
|
|
12
|
+
['V', 'FATAL'],
|
|
13
|
+
['C', '28P01'],
|
|
14
|
+
['M', `password authentication failed for user "${user}"`],
|
|
15
|
+
];
|
|
16
|
+
const body = Buffer.concat([
|
|
17
|
+
...fields.map(([code, text]) => Buffer.from(`${code}${text}\0`, 'utf8')),
|
|
18
|
+
Buffer.from([0]),
|
|
19
|
+
]);
|
|
20
|
+
const header = Buffer.alloc(5);
|
|
21
|
+
header.write('E', 0, 'latin1');
|
|
22
|
+
header.writeUInt32BE(body.length + 4, 1);
|
|
23
|
+
return Buffer.concat([header, body]);
|
|
24
|
+
}
|
|
25
|
+
function startupUser(startup) {
|
|
26
|
+
const parameters = startup.subarray(8).toString('utf8').split('\0');
|
|
27
|
+
const index = parameters.indexOf('user');
|
|
28
|
+
return index === -1 ? '' : (parameters[index + 1] ?? '');
|
|
29
|
+
}
|
|
30
|
+
function passwordMatches(candidate, expected) {
|
|
31
|
+
const a = Buffer.from(candidate, 'utf8');
|
|
32
|
+
const b = Buffer.from(expected, 'utf8');
|
|
33
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
34
|
+
}
|
|
35
|
+
function admit(client, innerPath, password) {
|
|
36
|
+
let buffer = Buffer.alloc(0);
|
|
37
|
+
let startup;
|
|
38
|
+
let user = '';
|
|
39
|
+
let settled = false;
|
|
40
|
+
const handshakeTimer = setTimeout(() => client.destroy(), HANDSHAKE_TIMEOUT_MS);
|
|
41
|
+
client.once('close', () => clearTimeout(handshakeTimer));
|
|
42
|
+
const reject = () => {
|
|
43
|
+
settled = true;
|
|
44
|
+
client.removeListener('data', onData);
|
|
45
|
+
client.end(authenticationFailed(user.replace(/[^\w.@-]/g, '?')));
|
|
46
|
+
};
|
|
47
|
+
const proxy = (leftover) => {
|
|
48
|
+
settled = true;
|
|
49
|
+
clearTimeout(handshakeTimer);
|
|
50
|
+
client.pause();
|
|
51
|
+
client.removeListener('data', onData);
|
|
52
|
+
const inner = createConnection(innerPath);
|
|
53
|
+
inner.on('error', () => client.destroy());
|
|
54
|
+
client.on('error', () => inner.destroy());
|
|
55
|
+
client.once('close', () => inner.destroy());
|
|
56
|
+
inner.once('close', () => client.destroy());
|
|
57
|
+
inner.once('connect', () => {
|
|
58
|
+
inner.write(startup);
|
|
59
|
+
if (leftover.length > 0)
|
|
60
|
+
inner.write(leftover);
|
|
61
|
+
client.pipe(inner);
|
|
62
|
+
inner.pipe(client);
|
|
63
|
+
client.resume();
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const onData = (chunk) => {
|
|
67
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
68
|
+
for (;;) {
|
|
69
|
+
if (settled)
|
|
70
|
+
return;
|
|
71
|
+
if (startup === undefined) {
|
|
72
|
+
if (buffer.length < 8)
|
|
73
|
+
return;
|
|
74
|
+
const length = buffer.readUInt32BE(0);
|
|
75
|
+
if (length < 8 || length > 10_000)
|
|
76
|
+
return void client.destroy();
|
|
77
|
+
if (buffer.length < length)
|
|
78
|
+
return;
|
|
79
|
+
const code = buffer.readUInt32BE(4);
|
|
80
|
+
const frame = buffer.subarray(0, length);
|
|
81
|
+
buffer = buffer.subarray(length);
|
|
82
|
+
if (code === SSL_REQUEST_CODE || code === GSS_ENC_REQUEST_CODE) {
|
|
83
|
+
client.write('N');
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (code === CANCEL_REQUEST_CODE) {
|
|
87
|
+
const inner = createConnection(innerPath);
|
|
88
|
+
inner.on('error', () => undefined);
|
|
89
|
+
inner.end(Buffer.from(frame));
|
|
90
|
+
return void client.destroy();
|
|
91
|
+
}
|
|
92
|
+
if (code !== PROTOCOL_VERSION_3)
|
|
93
|
+
return void client.destroy();
|
|
94
|
+
startup = Buffer.from(frame);
|
|
95
|
+
user = startupUser(startup);
|
|
96
|
+
client.write(CLEARTEXT_PASSWORD_REQUEST);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (buffer.length < 5)
|
|
100
|
+
return;
|
|
101
|
+
if (buffer[0] !== 0x70)
|
|
102
|
+
return void reject();
|
|
103
|
+
const length = buffer.readUInt32BE(1);
|
|
104
|
+
if (length < 5 || length > 10_000)
|
|
105
|
+
return void reject();
|
|
106
|
+
if (buffer.length < 1 + length)
|
|
107
|
+
return;
|
|
108
|
+
const supplied = buffer.subarray(5, length).toString('utf8').replace(/\0$/, '');
|
|
109
|
+
const leftover = Buffer.from(buffer.subarray(1 + length));
|
|
110
|
+
if (!passwordMatches(supplied, password))
|
|
111
|
+
return void reject();
|
|
112
|
+
proxy(leftover);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
client.on('data', onData);
|
|
117
|
+
client.on('error', () => client.destroy());
|
|
118
|
+
}
|
|
119
|
+
export async function startPasswordFront(options) {
|
|
120
|
+
const sockets = new Set();
|
|
121
|
+
const server = createServer((client) => {
|
|
122
|
+
sockets.add(client);
|
|
123
|
+
client.once('close', () => sockets.delete(client));
|
|
124
|
+
admit(client, options.innerPath, options.password);
|
|
125
|
+
});
|
|
126
|
+
await new Promise((resolve, reject) => {
|
|
127
|
+
server.once('error', reject);
|
|
128
|
+
server.listen(0, options.host, () => {
|
|
129
|
+
server.removeListener('error', reject);
|
|
130
|
+
resolve();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
const address = server.address();
|
|
134
|
+
if (address === null || typeof address === 'string') {
|
|
135
|
+
server.close();
|
|
136
|
+
throw new Error('The dev database password front reported no TCP port.');
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
port: address.port,
|
|
140
|
+
stop: async () => {
|
|
141
|
+
for (const socket of sockets)
|
|
142
|
+
socket.destroy();
|
|
143
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=password-front.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-front.js","sourceRoot":"","sources":["../../src/db/password-front.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAA;AAEnF,MAAM,gBAAgB,GAAG,QAAQ,CAAA;AACjC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AACrC,MAAM,mBAAmB,GAAG,QAAQ,CAAA;AACpC,MAAM,oBAAoB,GAAG,MAAM,CAAA;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEjC,MAAM,0BAA0B,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CA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,QAAQ,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;IACF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE;YAClC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACtC,OAAO,EAAE,CAAA;QACX,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;IAChC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,KAAK,MAAM,MAAM,IAAI,OAAO;gBAAE,MAAM,CAAC,OAAO,EAAE,CAAA;YAC9C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QACrE,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** A pid, and — where the platform can supply one — when that pid started. */
|
|
3
|
+
export declare const processClaimSchema: z.ZodObject<{
|
|
4
|
+
pid: z.ZodNumber;
|
|
5
|
+
startedAt: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
/** What a process recorded about itself, for a later reader to check against. */
|
|
8
|
+
export type ProcessClaim = z.infer<typeof processClaimSchema>;
|
|
9
|
+
/** Whether `pid` names a process this machine still runs. `EPERM` counts as alive. */
|
|
10
|
+
export declare function isProcessAlive(pid: number): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* A process's own start time in epoch milliseconds — best-effort, and never
|
|
13
|
+
* exact. `undefined` on a platform this cannot introspect (anything but
|
|
14
|
+
* Linux and macOS) or when the lookup itself fails, including for a pid that
|
|
15
|
+
* is not currently running.
|
|
16
|
+
*
|
|
17
|
+
* Linux divides `/proc/<pid>/stat`'s ticks-since-boot by an assumed 100 Hz
|
|
18
|
+
* clock; macOS shells to `ps -o lstart=`, which only carries one-second
|
|
19
|
+
* resolution. Callers compare with tolerance, never for exact equality.
|
|
20
|
+
*/
|
|
21
|
+
export declare function processStartTime(pid: number): number | undefined;
|
|
22
|
+
/** What this process should record about itself in a claim it publishes. */
|
|
23
|
+
export declare function describeSelf(): ProcessClaim;
|
|
24
|
+
/**
|
|
25
|
+
* Whether `claim` still names the process that published it — not merely a
|
|
26
|
+
* pid that happens to be alive right now. A pid outlives the reboot or wrap
|
|
27
|
+
* that hands it to an unrelated process, so bare liveness cannot tell the
|
|
28
|
+
* two apart; comparing recorded and freshly observed start times can, on the
|
|
29
|
+
* platforms {@link processStartTime} supports.
|
|
30
|
+
*
|
|
31
|
+
* Where neither reading is available — `claim.startedAt` was never recorded,
|
|
32
|
+
* or this platform cannot look one up now — the check degrades to bare pid
|
|
33
|
+
* liveness, exactly as it did before this comparison existed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function identifiesLiveProcess(claim: ProcessClaim): boolean;
|
|
36
|
+
//# sourceMappingURL=process-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.d.ts","sourceRoot":"","sources":["../../src/db/process-identity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB;;;iBAG7B,CAAA;AAEF,iFAAiF;AACjF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE7D,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOnD;AAkDD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIhE;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,IAAI,YAAY,CAE3C;AAUD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAMlE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/** A pid, and — where the platform can supply one — when that pid started. */
|
|
5
|
+
export const processClaimSchema = z.object({
|
|
6
|
+
pid: z.number().int().positive(),
|
|
7
|
+
startedAt: z.number().positive().optional(),
|
|
8
|
+
});
|
|
9
|
+
/** Whether `pid` names a process this machine still runs. `EPERM` counts as alive. */
|
|
10
|
+
export function isProcessAlive(pid) {
|
|
11
|
+
try {
|
|
12
|
+
process.kill(pid, 0);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return error instanceof Error && 'code' in error && error.code === 'EPERM';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Linux reports ticks since boot at this rate on every architecture this primitive targets. */
|
|
20
|
+
const LINUX_CLOCK_TICKS_PER_SECOND = 100;
|
|
21
|
+
/** Index of `starttime` among the fields following `/proc/<pid>/stat`'s `)`-terminated comm. */
|
|
22
|
+
const STAT_STARTTIME_FIELD_INDEX = 19;
|
|
23
|
+
function linuxProcessStartTime(pid) {
|
|
24
|
+
let stat;
|
|
25
|
+
let uptimeSeconds;
|
|
26
|
+
try {
|
|
27
|
+
stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
28
|
+
uptimeSeconds = readFileSync('/proc/uptime', 'utf8').split(' ')[0] ?? '';
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
// `comm` (the second field) is wrapped in parens and may itself contain
|
|
34
|
+
// ")" or spaces, so the fields before it are unsafe to split on — only the
|
|
35
|
+
// last ")" is guaranteed to end it.
|
|
36
|
+
const afterComm = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
37
|
+
const startTicks = Number(afterComm[STAT_STARTTIME_FIELD_INDEX]);
|
|
38
|
+
const uptime = Number(uptimeSeconds);
|
|
39
|
+
if (!Number.isFinite(startTicks) || !Number.isFinite(uptime))
|
|
40
|
+
return undefined;
|
|
41
|
+
const bootEpochMs = Date.now() - uptime * 1000;
|
|
42
|
+
return Math.round(bootEpochMs + (startTicks / LINUX_CLOCK_TICKS_PER_SECOND) * 1000);
|
|
43
|
+
}
|
|
44
|
+
function macosProcessStartTime(pid) {
|
|
45
|
+
let output;
|
|
46
|
+
try {
|
|
47
|
+
output = execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], {
|
|
48
|
+
encoding: 'utf8',
|
|
49
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
50
|
+
// `ps` renders weekday/month names and `Date.parse` reads them back in
|
|
51
|
+
// the process's own locale; forcing C here keeps the two in the same
|
|
52
|
+
// locale regardless of the caller's — an unpinned locale would parse to
|
|
53
|
+
// `Invalid Date` under a non-English one and silently disable this.
|
|
54
|
+
env: { ...process.env, LC_ALL: 'C', LANG: 'C' },
|
|
55
|
+
}).trim();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (output.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
const parsed = new Date(output);
|
|
63
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed.getTime();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A process's own start time in epoch milliseconds — best-effort, and never
|
|
67
|
+
* exact. `undefined` on a platform this cannot introspect (anything but
|
|
68
|
+
* Linux and macOS) or when the lookup itself fails, including for a pid that
|
|
69
|
+
* is not currently running.
|
|
70
|
+
*
|
|
71
|
+
* Linux divides `/proc/<pid>/stat`'s ticks-since-boot by an assumed 100 Hz
|
|
72
|
+
* clock; macOS shells to `ps -o lstart=`, which only carries one-second
|
|
73
|
+
* resolution. Callers compare with tolerance, never for exact equality.
|
|
74
|
+
*/
|
|
75
|
+
export function processStartTime(pid) {
|
|
76
|
+
if (process.platform === 'linux')
|
|
77
|
+
return linuxProcessStartTime(pid);
|
|
78
|
+
if (process.platform === 'darwin')
|
|
79
|
+
return macosProcessStartTime(pid);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/** What this process should record about itself in a claim it publishes. */
|
|
83
|
+
export function describeSelf() {
|
|
84
|
+
return { pid: process.pid, startedAt: processStartTime(process.pid) };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Start times are compared with slack, not for exact equality: the two
|
|
88
|
+
* readings come from different measurements taken seconds apart (Linux's
|
|
89
|
+
* assumed clock rate, macOS's one-second `ps` resolution), so a real match
|
|
90
|
+
* still drifts by up to a couple of seconds.
|
|
91
|
+
*/
|
|
92
|
+
const START_TIME_TOLERANCE_MS = 2_000;
|
|
93
|
+
/**
|
|
94
|
+
* Whether `claim` still names the process that published it — not merely a
|
|
95
|
+
* pid that happens to be alive right now. A pid outlives the reboot or wrap
|
|
96
|
+
* that hands it to an unrelated process, so bare liveness cannot tell the
|
|
97
|
+
* two apart; comparing recorded and freshly observed start times can, on the
|
|
98
|
+
* platforms {@link processStartTime} supports.
|
|
99
|
+
*
|
|
100
|
+
* Where neither reading is available — `claim.startedAt` was never recorded,
|
|
101
|
+
* or this platform cannot look one up now — the check degrades to bare pid
|
|
102
|
+
* liveness, exactly as it did before this comparison existed.
|
|
103
|
+
*/
|
|
104
|
+
export function identifiesLiveProcess(claim) {
|
|
105
|
+
if (!isProcessAlive(claim.pid))
|
|
106
|
+
return false;
|
|
107
|
+
if (claim.startedAt === undefined)
|
|
108
|
+
return true;
|
|
109
|
+
const observed = processStartTime(claim.pid);
|
|
110
|
+
if (observed === undefined)
|
|
111
|
+
return true;
|
|
112
|
+
return Math.abs(observed - claim.startedAt) <= START_TIME_TOLERANCE_MS;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=process-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../src/db/process-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CAC5C,CAAC,CAAA;AAKF,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAA;IAC5E,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAExC,gGAAgG;AAChG,MAAM,0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AA;IAC5C,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IAC9C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IACvC,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,uBAAuB,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const stateSchema: z.ZodObject<{
|
|
3
|
+
pid: z.ZodNumber;
|
|
4
|
+
startedAt: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
url: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
/** What the Dev database sidecar publishes about itself: where it listens and who owns it. */
|
|
8
|
+
export type DevDatabaseState = z.infer<typeof stateSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* What a caller writing the state file provides — `startedAt` is derived from
|
|
11
|
+
* the sidecar's own pid at write time, never supplied by the caller.
|
|
12
|
+
*/
|
|
13
|
+
export type PublishedDevDatabaseState = Omit<DevDatabaseState, 'startedAt'>;
|
|
14
|
+
/** Where the state file is looked for, when it is not named outright. */
|
|
15
|
+
export interface DevDatabaseStateLocation {
|
|
16
|
+
/**
|
|
17
|
+
* The project root whose Generated bundle holds the state file.
|
|
18
|
+
* Defaults to `process.cwd()`.
|
|
19
|
+
*/
|
|
20
|
+
cwd?: string;
|
|
21
|
+
/**
|
|
22
|
+
* An explicit state file path, bypassing `cwd` and the bundle directory.
|
|
23
|
+
* Production requires an absolute path; when omitted, production reads
|
|
24
|
+
* `OPENSAAS_DEV_DATABASE_STATE_FILE` instead of discovering from `cwd`.
|
|
25
|
+
*/
|
|
26
|
+
stateFile?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Resolves the absolute state file path for a location. */
|
|
29
|
+
export declare function devDatabaseStatePath(location?: DevDatabaseStateLocation): string;
|
|
30
|
+
/**
|
|
31
|
+
* Reads the Dev database state, or `undefined` when there is nothing usable
|
|
32
|
+
* there: no file, unreadable JSON, a shape that is not the state file's, or a
|
|
33
|
+
* pid that no longer identifies the sidecar that wrote it — either because
|
|
34
|
+
* nothing runs there anymore, or because a reboot or pid wrap has handed that
|
|
35
|
+
* pid to an unrelated process (see {@link identifiesLiveProcess}). A crashed
|
|
36
|
+
* sidecar leaves its file behind; this is what tells a live database from a
|
|
37
|
+
* stale record.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readDevDatabaseState(location?: DevDatabaseStateLocation): DevDatabaseState | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Writes the state file, creating the Generated bundle directory if needed.
|
|
42
|
+
* The write goes to a sibling temp file and is renamed into place, so a reader
|
|
43
|
+
* never observes a half-written record. `startedAt` is stamped from `pid`'s
|
|
44
|
+
* own start time (best-effort — see {@link processStartTime}), not taken from
|
|
45
|
+
* `state`: only the sidecar itself is in a position to look this up.
|
|
46
|
+
*/
|
|
47
|
+
export declare function writeDevDatabaseState(filePath: string, state: PublishedDevDatabaseState): void;
|
|
48
|
+
/**
|
|
49
|
+
* Removes the state file, but only while it still describes `url` — a sidecar
|
|
50
|
+
* shutting down must not delete the record a newer one wrote over it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function clearDevDatabaseState(filePath: string, url: string): void;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=state-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-file.d.ts","sourceRoot":"","sources":["../../src/db/state-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AASvB,QAAA,MAAM,WAAW;;;;iBAEf,CAAA;AAEF,8FAA8F;AAC9F,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAE1D;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAA;AAE3E,yEAAyE;AACzE,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,CAAC,QAAQ,GAAE,wBAA6B,GAAG,MAAM,CAGpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,GAAE,wBAA6B,GACtC,gBAAgB,GAAG,SAAS,CA0B9B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAc9F;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAIzE"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { identifiesLiveProcess, processClaimSchema, processStartTime } from './process-identity.js';
|
|
5
|
+
/** The Generated bundle directory the state file lives in. */
|
|
6
|
+
const DEFAULT_BUNDLE_DIR = '.opensaas';
|
|
7
|
+
/** The state file's name inside the Generated bundle directory. */
|
|
8
|
+
const STATE_FILE_NAME = 'dev-db.json';
|
|
9
|
+
const stateSchema = processClaimSchema.extend({
|
|
10
|
+
url: z.string().min(1),
|
|
11
|
+
});
|
|
12
|
+
/** Resolves the absolute state file path for a location. */
|
|
13
|
+
export function devDatabaseStatePath(location = {}) {
|
|
14
|
+
if (location.stateFile !== undefined)
|
|
15
|
+
return path.resolve(location.stateFile);
|
|
16
|
+
return path.join(location.cwd ?? process.cwd(), DEFAULT_BUNDLE_DIR, STATE_FILE_NAME);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads the Dev database state, or `undefined` when there is nothing usable
|
|
20
|
+
* there: no file, unreadable JSON, a shape that is not the state file's, or a
|
|
21
|
+
* pid that no longer identifies the sidecar that wrote it — either because
|
|
22
|
+
* nothing runs there anymore, or because a reboot or pid wrap has handed that
|
|
23
|
+
* pid to an unrelated process (see {@link identifiesLiveProcess}). A crashed
|
|
24
|
+
* sidecar leaves its file behind; this is what tells a live database from a
|
|
25
|
+
* stale record.
|
|
26
|
+
*/
|
|
27
|
+
export function readDevDatabaseState(location = {}) {
|
|
28
|
+
// Keep the production branch beside the filesystem read so bundlers erase
|
|
29
|
+
// project-root discovery before tracing deployment files (issue #1602).
|
|
30
|
+
const stateFile = process.env.NODE_ENV === 'production'
|
|
31
|
+
? (location.stateFile ?? process.env.OPENSAAS_DEV_DATABASE_STATE_FILE)
|
|
32
|
+
: devDatabaseStatePath(location);
|
|
33
|
+
if (stateFile === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (process.env.NODE_ENV === 'production' && !path.isAbsolute(stateFile))
|
|
36
|
+
return undefined;
|
|
37
|
+
let contents;
|
|
38
|
+
try {
|
|
39
|
+
contents = readFileSync(stateFile, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(contents);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const state = stateSchema.safeParse(parsed);
|
|
52
|
+
if (!state.success)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!identifiesLiveProcess(state.data))
|
|
55
|
+
return undefined;
|
|
56
|
+
return state.data;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Writes the state file, creating the Generated bundle directory if needed.
|
|
60
|
+
* The write goes to a sibling temp file and is renamed into place, so a reader
|
|
61
|
+
* never observes a half-written record. `startedAt` is stamped from `pid`'s
|
|
62
|
+
* own start time (best-effort — see {@link processStartTime}), not taken from
|
|
63
|
+
* `state`: only the sidecar itself is in a position to look this up.
|
|
64
|
+
*/
|
|
65
|
+
export function writeDevDatabaseState(filePath, state) {
|
|
66
|
+
const directory = path.dirname(filePath);
|
|
67
|
+
mkdirSync(directory, { recursive: true });
|
|
68
|
+
const record = { ...state, startedAt: processStartTime(state.pid) };
|
|
69
|
+
const contents = `${JSON.stringify(stateSchema.parse(record), null, 2)}\n`;
|
|
70
|
+
const temporary = path.join(directory, `${path.basename(filePath)}.${process.pid}.tmp`);
|
|
71
|
+
try {
|
|
72
|
+
writeFileSync(temporary, contents, { encoding: 'utf8', mode: 0o600 });
|
|
73
|
+
chmodSync(temporary, 0o600);
|
|
74
|
+
renameSync(temporary, filePath);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
rmSync(temporary, { force: true });
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Removes the state file, but only while it still describes `url` — a sidecar
|
|
83
|
+
* shutting down must not delete the record a newer one wrote over it.
|
|
84
|
+
*/
|
|
85
|
+
export function clearDevDatabaseState(filePath, url) {
|
|
86
|
+
const state = readDevDatabaseState({ stateFile: filePath });
|
|
87
|
+
if (state?.url !== url)
|
|
88
|
+
return;
|
|
89
|
+
rmSync(filePath, { force: true });
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=state-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-file.js","sourceRoot":"","sources":["../../src/db/state-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC/F,OAAO,KAAK,IAAI,MAA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QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QACrE,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAC3B,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QAClC,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,GAAW;IACjE,MAAM,KAAK,GAAG,oBAAoB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC3D,IAAI,KAAK,EAAE,GAAG,KAAK,GAAG;QAAE,OAAM;IAC9B,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AACnC,CAAC"}
|
package/dist/db/url.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type DevDatabaseStateLocation } from './state-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* The environment variables consulted, in order. `DIRECT_DATABASE_URL` wins so
|
|
4
|
+
* a schema command reaches the direct connection rather than a pooler that
|
|
5
|
+
* cannot run DDL (ADR-0003).
|
|
6
|
+
*
|
|
7
|
+
* This is the one place the list is written down — the test harness's escape
|
|
8
|
+
* (`@opensaas/stack-core/testing`'s `ESCAPE_VARIABLES`) imports it rather than
|
|
9
|
+
* keeping its own, so the two lookups cannot disagree about which variable
|
|
10
|
+
* counts (issue #1210).
|
|
11
|
+
*/
|
|
12
|
+
export declare const CONNECTION_VARIABLES: readonly ['DIRECT_DATABASE_URL', 'DATABASE_URL'];
|
|
13
|
+
/** Thrown by {@link resolveDatabaseUrl} when neither remedy has been taken. */
|
|
14
|
+
export declare class DatabaseUrlUnresolvedError extends Error {
|
|
15
|
+
constructor(names: readonly string[]);
|
|
16
|
+
}
|
|
17
|
+
/** Why a connection string is not a Postgres one, or `undefined` when it is. */
|
|
18
|
+
export declare function connectionStringFault(url: string): string | undefined;
|
|
19
|
+
/** Thrown by {@link resolveDatabaseUrl} when a connection variable is set to something that is not Postgres. */
|
|
20
|
+
export declare class UnusableDatabaseUrlError extends Error {
|
|
21
|
+
readonly variable: string;
|
|
22
|
+
readonly url: string;
|
|
23
|
+
readonly fault: string;
|
|
24
|
+
constructor(variable: string, url: string, fault: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where a connection string came from. `'env'` is a database the stack does
|
|
28
|
+
* not own; `'dev-database'` is the sidecar `opensaas dev` runs, which the
|
|
29
|
+
* generated runtime binds differently (one connection, no marker check —
|
|
30
|
+
* ADR-0063).
|
|
31
|
+
*/
|
|
32
|
+
export type DatabaseUrlProvenance = 'env' | 'dev-database';
|
|
33
|
+
/** A connection string and the lookup branch that produced it. */
|
|
34
|
+
export interface ResolvedDatabaseUrl {
|
|
35
|
+
readonly url: string;
|
|
36
|
+
readonly provenance: DatabaseUrlProvenance;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Where the Dev database state file is looked for when the environment names
|
|
40
|
+
* no connection. In production, only an absolute `stateFile` option or
|
|
41
|
+
* `OPENSAAS_DEV_DATABASE_STATE_FILE` is read; `cwd` discovery is disabled.
|
|
42
|
+
*/
|
|
43
|
+
export type DatabaseUrlLookupOptions = DevDatabaseStateLocation;
|
|
44
|
+
/**
|
|
45
|
+
* The stack's database URL lookup, non-throwing: the connection string if one
|
|
46
|
+
* is set or a dev database is running, `undefined` otherwise.
|
|
47
|
+
*
|
|
48
|
+
* This is what the generated `prisma.config.ts` calls. That file is evaluated
|
|
49
|
+
* for every Prisma command, including the offline ones (`contract emit`), so it
|
|
50
|
+
* must not fail when nothing is configured — a command that does need a
|
|
51
|
+
* connection reports its own missing-connection error.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* db: { connection: findDatabaseUrl() }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function findDatabaseUrl(options?: DatabaseUrlLookupOptions): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* {@link resolveDatabaseUrl}'s lookup, provenance and all, without the throw.
|
|
61
|
+
* Stack-internal — it reaches sibling packages through
|
|
62
|
+
* `@opensaas/stack-core/internal`, never the package root; the public
|
|
63
|
+
* non-throwing accessor is {@link findDatabaseUrl}.
|
|
64
|
+
*/
|
|
65
|
+
export declare function findDatabaseConnection(options?: DatabaseUrlLookupOptions): ResolvedDatabaseUrl | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The stack's database URL lookup — the one place a connection string is
|
|
68
|
+
* chosen (ADR-0063, amending ADR-0014). `DATABASE_URL` (or
|
|
69
|
+
* `DIRECT_DATABASE_URL`) wins; otherwise the Dev database state file written by
|
|
70
|
+
* `startDevDatabase`; otherwise a throw. A deploy that forgets the
|
|
71
|
+
* variable gets that error, never a silent in-process Postgres.
|
|
72
|
+
*
|
|
73
|
+
* The provenance is load-bearing, not informational: only on `'dev-database'`
|
|
74
|
+
* does the generated context bind a single connection and disable Prisma's
|
|
75
|
+
* contract-marker read, which is why the dev loop must never inject a
|
|
76
|
+
* `DATABASE_URL` into the app it spawns.
|
|
77
|
+
*
|
|
78
|
+
* @throws {DatabaseUrlUnresolvedError} naming both remedies — the environment
|
|
79
|
+
* variable and `opensaas dev`.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { resolveDatabaseUrl } from '@opensaas/stack-core'
|
|
84
|
+
* const { url, provenance } = resolveDatabaseUrl()
|
|
85
|
+
* const db = postgres({ contractJson, url })
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveDatabaseUrl(options?: DatabaseUrlLookupOptions): ResolvedDatabaseUrl;
|
|
89
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,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