@rebasepro/server-postgres 0.30.1 → 0.31.0-canary.g59cd6fd
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/README.md +11 -8
- package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
- package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +99 -54
- package/dist/PostgresBootstrapper.d.ts +12 -27
- package/dist/auth/ensure-tables.d.ts +16 -5
- package/dist/auth/schema-version.d.ts +2 -2
- package/dist/auth/services.d.ts +2 -3
- package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
- package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
- package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
- package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
- package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
- package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
- package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
- package/dist/cli-console-DsRgGSBR.js.map +1 -0
- package/dist/cli-console.d.ts +16 -13
- package/dist/cli-flags.d.ts +8 -9
- package/dist/cli-helpers.d.ts +15 -11
- package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
- package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
- package/dist/cli-schema-dir.d.ts +64 -0
- package/dist/cli.js +192 -257
- package/dist/cli.js.map +1 -1
- package/dist/data-transformer.d.ts +50 -19
- package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
- package/dist/database-preflight-bfnIBnjM.js.map +1 -0
- package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
- package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
- package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
- package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
- package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
- package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
- package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
- package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
- package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
- package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
- package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
- package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
- package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
- package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
- package/dist/generate-files-tlJ9_lGI.js.map +1 -0
- package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
- package/dist/generate-next-step-CO09dovd.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
- package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
- package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
- package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
- package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
- package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
- package/dist/history/ensure-history-table.d.ts +22 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.es.js +201 -25
- package/dist/index.es.js.map +1 -1
- package/dist/interfaces.d.ts +3 -4
- package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
- package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
- package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
- package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
- package/dist/load-tables-B1Re74ng.js +92 -0
- package/dist/load-tables-B1Re74ng.js.map +1 -0
- package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
- package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
- package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
- package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
- package/dist/model/PostgresTableRegistry.d.ts +159 -0
- package/dist/model/build-registry.d.ts +25 -0
- package/dist/model/refresh-relational-schema.d.ts +24 -0
- package/dist/model/runtime-table.d.ts +53 -0
- package/dist/{collections → model}/validate-relations.d.ts +15 -21
- package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
- package/dist/open-rebase-4kisUF_k.js.map +1 -0
- package/dist/open-rebase.d.ts +16 -15
- package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
- package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
- package/dist/plan-schema-Hbtjhge3.js +1633 -0
- package/dist/plan-schema-Hbtjhge3.js.map +1 -0
- package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
- package/dist/policy-drift-BVMyqHSa.js.map +1 -0
- package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
- package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
- package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
- package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
- package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
- package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
- package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
- package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
- package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
- package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
- package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
- package/dist/render-ddl-D4n86NHz.js.map +1 -0
- package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
- package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
- package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
- package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
- package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
- package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
- package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
- package/dist/rls-settings-CmGK2U0a.js.map +1 -0
- package/dist/schema/auth-users-columns.d.ts +1 -11
- package/dist/schema/catalogue-schema.d.ts +33 -29
- package/dist/schema/classify-change.d.ts +23 -16
- package/dist/schema/column-type-drift.d.ts +16 -0
- package/dist/schema/config-relations.d.ts +10 -9
- package/dist/schema/deferred-index-build.d.ts +1 -1
- package/dist/schema/doctor-cli.js +1544 -66
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +7 -7
- package/dist/schema/doctor-policy-checks.d.ts +4 -4
- package/dist/schema/doctor-search-scale.d.ts +14 -14
- package/dist/schema/doctor.d.ts +27 -27
- package/dist/schema/dynamic-tables.d.ts +6 -5
- package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
- package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
- package/dist/schema/enum-labels-kept.d.ts +6 -6
- package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +6 -6
- package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
- package/dist/schema/generate-postgres-ddl.js +11 -11
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/generate-schema-commit.d.ts +13 -8
- package/dist/schema/generated-schema-diff.d.ts +16 -16
- package/dist/schema/generated-schema-staleness.d.ts +11 -11
- package/dist/schema/index-adoption.d.ts +4 -4
- package/dist/schema/introspect-db-customization.d.ts +47 -0
- package/dist/schema/introspect-db-inference.d.ts +30 -9
- package/dist/schema/introspect-db-logic.d.ts +79 -110
- package/dist/schema/introspect-db-project.d.ts +15 -18
- package/dist/schema/introspect-db-queries.d.ts +1 -1
- package/dist/schema/introspect-db-search.d.ts +25 -4
- package/dist/schema/introspect-db-storage.d.ts +4 -74
- package/dist/schema/introspect-db.js +102 -90
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/introspect-runtime.d.ts +47 -36
- package/dist/schema/introspect-tables.d.ts +182 -0
- package/dist/schema/load-tables.d.ts +55 -0
- package/dist/schema/migrate-policy-stamps.d.ts +4 -4
- package/dist/schema/migration-freshness.d.ts +13 -13
- package/dist/schema/plan/column-order.d.ts +82 -0
- package/dist/schema/plan/diff-plan.d.ts +9 -3
- package/dist/schema/plan/plan-schema.d.ts +55 -52
- package/dist/schema/plan/render-drizzle.d.ts +1 -1
- package/dist/schema/plan/types.d.ts +24 -15
- package/dist/schema/push-index-adoption.d.ts +3 -3
- package/dist/schema/push-index-prebuild.d.ts +3 -3
- package/dist/schema/push-kept-defaults.d.ts +7 -7
- package/dist/schema/push-legacy-renames.d.ts +3 -3
- package/dist/schema/push-policy-plan.d.ts +5 -5
- package/dist/schema/reconcile-schema.d.ts +5 -5
- package/dist/schema/relation-names.d.ts +15 -20
- package/dist/schema/render-outputs.d.ts +76 -0
- package/dist/schema/search-column.d.ts +11 -43
- package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
- package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
- package/dist/schema/vector-index.d.ts +24 -28
- package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
- package/dist/search-column-BO-WND-B.js.map +1 -0
- package/dist/security/caller-sql-columns.d.ts +9 -6
- package/dist/security/policy-drift.d.ts +14 -14
- package/dist/security/rls-enforcement.d.ts +19 -25
- package/dist/security/rls-settings.d.ts +2 -2
- package/dist/security/served-table-protection.d.ts +125 -0
- package/dist/services/FetchService.d.ts +22 -133
- package/dist/services/PersistService.d.ts +6 -17
- package/dist/services/RelationService.d.ts +57 -106
- package/dist/services/RelationWriteService.d.ts +59 -66
- package/dist/services/cdc/identity-columns.d.ts +7 -5
- package/dist/services/cdc/junction-tables.d.ts +14 -14
- package/dist/services/collection-helpers.d.ts +52 -95
- package/dist/services/dataService.d.ts +15 -12
- package/dist/services/field-op-sql.d.ts +11 -9
- package/dist/services/field-viewer.d.ts +12 -11
- package/dist/services/hidden-columns.d.ts +30 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/junction-writes.d.ts +37 -18
- package/dist/services/nested-path.d.ts +18 -18
- package/dist/services/read-field-access.d.ts +23 -7
- package/dist/services/read-scope.d.ts +10 -9
- package/dist/services/realtimeService.d.ts +25 -10
- package/dist/services/relation-tables.d.ts +97 -0
- package/dist/services/row-pipeline.d.ts +50 -69
- package/dist/services/soft-delete.d.ts +25 -24
- package/dist/services/table-hooks.d.ts +146 -0
- package/dist/services/view-access.d.ts +7 -7
- package/dist/services/write-transaction-scope.d.ts +1 -1
- package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
- package/dist/source-VxbrQojV.js.map +1 -0
- package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
- package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +70 -84
- package/dist/utils/pg-array-null-patch.d.ts +27 -10
- package/dist/utils/pg-error-utils.d.ts +4 -4
- package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
- package/dist/vector-index-VSh3ufTd.js.map +1 -0
- package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
- package/dist/websocket-BevXvwfo.js.map +1 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +7 -7
- package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
- package/dist/cli-collections-path.d.ts +0 -31
- package/dist/cli-console-DBPw-oAz.js.map +0 -1
- package/dist/cli-errors-DYTxnLbW.js.map +0 -1
- package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
- package/dist/collections/buildRegistry.d.ts +0 -27
- package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
- package/dist/column-plan-helpers-BeSztMor.js +0 -161
- package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
- package/dist/database-preflight-iBpT7-vv.js.map +0 -1
- package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
- package/dist/doctor-Kg1oUK0Q.js +0 -1458
- package/dist/doctor-Kg1oUK0Q.js.map +0 -1
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
- package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
- package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
- package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
- package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
- package/dist/generate-files-CsaVzatS.js.map +0 -1
- package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
- package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
- package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
- package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
- package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
- package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
- package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
- package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
- package/dist/open-rebase-40paQfVW.js.map +0 -1
- package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
- package/dist/plan-schema-vJd3UEmT.js +0 -1604
- package/dist/plan-schema-vJd3UEmT.js.map +0 -1
- package/dist/policy-drift-C-m0uWHH.js.map +0 -1
- package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
- package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
- package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
- package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
- package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
- package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
- package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
- package/dist/rls-settings-BCGMIig3.js.map +0 -1
- package/dist/schema/column-plan-helpers.d.ts +0 -161
- package/dist/schema/introspect-db-naming.d.ts +0 -10
- package/dist/search-column-BM-GV6vH.js.map +0 -1
- package/dist/source-fZb92pN8.js.map +0 -1
- package/dist/vector-index-DsQ3V2d2.js.map +0 -1
- package/dist/websocket-B7ex6AQM.js.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the Postgres driver runs a table's hooks: the global ones, the table's
|
|
3
|
+
* own (`defineTable({ hooks })`, or `setTableHooks`), and its columns'
|
|
4
|
+
* field-level `.transform()`s — native `TableHooks`, read off the compiled
|
|
5
|
+
* table the registry holds, with their real props (`table` is the descriptor).
|
|
6
|
+
*
|
|
7
|
+
* The order, everywhere: **global, then the table's, then its columns'**. A
|
|
8
|
+
* column transform has only `beforeSave` and `afterRead`, so the other five
|
|
9
|
+
* hooks run global then table.
|
|
10
|
+
*
|
|
11
|
+
* `afterRead` masks what a caller must not see, so every path a row leaves
|
|
12
|
+
* the server by runs it exactly once, through {@link afterReadOnRows}: the
|
|
13
|
+
* driver's fetches, the REST/SDK fetch service, the realtime initial fetch and
|
|
14
|
+
* refetches, a write's own response. That one function also masks a row's
|
|
15
|
+
* embedded relations — at every level an `include` loaded — with each TARGET
|
|
16
|
+
* table's hooks, so `comment.post.author.email` is the authors table's to
|
|
17
|
+
* mask, never served raw.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { type ColumnTransform, type EntityStatus, type RebaseCallContext, type TableDescriptor, type TableHooks, type TableRow, type TransformNode } from "@rebasepro/types";
|
|
22
|
+
import type { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
23
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
24
|
+
/**
|
|
25
|
+
* The hooks that apply to one table, resolved once per operation.
|
|
26
|
+
*
|
|
27
|
+
* `table` is `undefined` when the path names no table this driver serves;
|
|
28
|
+
* then only global hooks can be present, and running one is refused (see
|
|
29
|
+
* {@link requireHookTable}) — a hook with no table to be told about cannot run,
|
|
30
|
+
* and one that does not run on a masked read is a leak.
|
|
31
|
+
*/
|
|
32
|
+
export interface TableHookSet {
|
|
33
|
+
/** The table the hooks run for. */
|
|
34
|
+
readonly table: RuntimeTable | undefined;
|
|
35
|
+
/** The global hooks, which run for every table (`initializeRebaseBackend({ hooks })`, `openRebase({ hooks })`). */
|
|
36
|
+
readonly global: TableHooks | undefined;
|
|
37
|
+
/** The table's own hooks. */
|
|
38
|
+
readonly own: TableHooks | undefined;
|
|
39
|
+
/** The table's field-level hooks, one tree per column key. */
|
|
40
|
+
readonly transforms: Record<string, TransformNode> | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** A hook set with nothing in it. */
|
|
43
|
+
export declare const NO_HOOKS: TableHookSet;
|
|
44
|
+
/**
|
|
45
|
+
* The hooks for the table a path addresses.
|
|
46
|
+
*
|
|
47
|
+
* The path is resolved through the registry (`registry.tableAt`: a slug, or a
|
|
48
|
+
* nested path such as `posts/1/comments`, which addresses `comments`). A path
|
|
49
|
+
* that names no table has only the global hooks.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveTableHooks(registry: PostgresTableRegistry | undefined, path: string): TableHookSet;
|
|
52
|
+
/** The hooks of a runtime table already in hand (a relation's target). */
|
|
53
|
+
export declare function hookSetOf(registry: PostgresTableRegistry | undefined, table: RuntimeTable | undefined): TableHookSet;
|
|
54
|
+
/** Whether any column of the set declares the field-level `hook`. */
|
|
55
|
+
export declare function transformsDeclare(set: TableHookSet, hook: keyof ColumnTransform): boolean;
|
|
56
|
+
/** Whether `afterRead` runs for this table, on any tier. */
|
|
57
|
+
export declare function hasAfterRead(set: TableHookSet): boolean;
|
|
58
|
+
/** Whether `beforeSave` runs for this table, on any tier. */
|
|
59
|
+
export declare function hasBeforeSave(set: TableHookSet): boolean;
|
|
60
|
+
/** Whether `beforeQuery` runs for this table (global or the table's: a column has none). */
|
|
61
|
+
export declare function hasBeforeQueryHook(set: TableHookSet): boolean;
|
|
62
|
+
/** Whether a hook of this name runs for this table, global or the table's. */
|
|
63
|
+
export declare function hasRowHook(set: TableHookSet, hook: keyof TableHooks): boolean;
|
|
64
|
+
/** Whether any application code at all runs for this table: a hook on any tier, or a transform. */
|
|
65
|
+
export declare function declaresAnyHook(set: TableHookSet): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The descriptor every hook of the set is told about. Throws a 404 naming the
|
|
68
|
+
* path when there is no table — only a global hook can bring a call here
|
|
69
|
+
* without one, and it cannot be run for a table that is not there.
|
|
70
|
+
*/
|
|
71
|
+
export declare function requireHookTable(set: TableHookSet, path: string): TableDescriptor;
|
|
72
|
+
/**
|
|
73
|
+
* `afterRead` on one row of the set's table: global, then the table's, then
|
|
74
|
+
* its columns' transforms. Each tier sees the row the previous one returned;
|
|
75
|
+
* a tier that returns nothing leaves it as it was.
|
|
76
|
+
*/
|
|
77
|
+
export declare function afterReadOnRow(set: TableHookSet, row: TableRow, path: string, context: RebaseCallContext): Promise<TableRow>;
|
|
78
|
+
/**
|
|
79
|
+
* Whether {@link afterReadOnRows} would run anything for rows of this table:
|
|
80
|
+
* its own `afterRead` on any tier, or that of any table an `include` reaches
|
|
81
|
+
* from it, at any depth.
|
|
82
|
+
*/
|
|
83
|
+
export declare function afterReadApplies(registry: PostgresTableRegistry | undefined, set: TableHookSet): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* `afterRead` on rows leaving the server — THE read chain, for every path.
|
|
86
|
+
*
|
|
87
|
+
* Runs {@link afterReadOnRow} on each row, then walks the row's embedded
|
|
88
|
+
* relations — whatever an `include` attached under a relation's name, a row
|
|
89
|
+
* or a list, to-one, to-many, many-to-many and `via` alike — and runs each
|
|
90
|
+
* TARGET table's chain on them, then theirs, down to the last level the
|
|
91
|
+
* include tree loaded. The walk follows the rows, so it is bounded by the
|
|
92
|
+
* include that produced them, never by a fixed depth; a self-referencing
|
|
93
|
+
* include (`parent.parent`) is walked level by level like any other. A
|
|
94
|
+
* many-to-many row's `_pivot` rides on the target row, so the target's
|
|
95
|
+
* hooks (global included) see it; a pivot column has no field hooks of its
|
|
96
|
+
* own (the compiler refuses `.transform()` there).
|
|
97
|
+
*
|
|
98
|
+
* An embedded row is handed to the hooks as a copy: a related row the
|
|
99
|
+
* loader shares between two parents is not masked twice, nor masked for one
|
|
100
|
+
* parent by a hook another level ran. An object that contains itself is
|
|
101
|
+
* refused (it could not be served anyway).
|
|
102
|
+
*
|
|
103
|
+
* `context` is asked for only when a hook will run, so a table without hooks
|
|
104
|
+
* (and none reachable) costs a map lookup per relation. `onHookRun` is called
|
|
105
|
+
* once, before the first hook runs: the driver notes application code on the
|
|
106
|
+
* write scope there.
|
|
107
|
+
*/
|
|
108
|
+
export declare function afterReadOnRows(registry: PostgresTableRegistry | undefined, set: TableHookSet, rows: TableRow[], path: string, context: () => RebaseCallContext, onHookRun?: () => void): Promise<TableRow[]>;
|
|
109
|
+
/** What a write's hooks are told about it. */
|
|
110
|
+
export interface WriteHookCall {
|
|
111
|
+
path: string;
|
|
112
|
+
id: string | number | undefined;
|
|
113
|
+
previousValues: TableRow | undefined;
|
|
114
|
+
status: EntityStatus;
|
|
115
|
+
context: RebaseCallContext;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* `beforeSave`: global, then the table's, then its columns' transforms. A
|
|
119
|
+
* tier's returned object is shallow-merged over the values; a tier that
|
|
120
|
+
* returns nothing changes nothing. A throw propagates (the driver answers it
|
|
121
|
+
* as `CALLBACK_REJECTED`).
|
|
122
|
+
*/
|
|
123
|
+
export declare function beforeSave<V extends TableRow>(set: TableHookSet, values: V, call: WriteHookCall): Promise<V>;
|
|
124
|
+
/** `afterSave`: global, then the table's, each awaited. */
|
|
125
|
+
export declare function afterSave(set: TableHookSet, savedId: string | number, values: TableRow, call: WriteHookCall): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* `afterSaveError`: global, then the table's — each on its own, guarded: a
|
|
128
|
+
* hook that throws is handed to `onThrow` and the next still runs, so it can
|
|
129
|
+
* never replace the failure the caller is owed.
|
|
130
|
+
*/
|
|
131
|
+
export declare function afterSaveError(set: TableHookSet, values: TableRow, error: unknown, call: WriteHookCall, onThrow: (tier: "global" | "table", hookError: unknown) => void): Promise<void>;
|
|
132
|
+
/** What a delete's hooks are told about it. */
|
|
133
|
+
export interface DeleteHookCall {
|
|
134
|
+
path: string;
|
|
135
|
+
id: string | number;
|
|
136
|
+
/** The row being deleted, as stored. */
|
|
137
|
+
values: TableRow;
|
|
138
|
+
context: RebaseCallContext;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* `beforeDelete`: global, then the table's. Every tier runs; `true` back when
|
|
142
|
+
* any returned `false` (a veto). A throw propagates.
|
|
143
|
+
*/
|
|
144
|
+
export declare function beforeDeleteVetoes(set: TableHookSet, call: DeleteHookCall): Promise<boolean>;
|
|
145
|
+
/** `afterDelete`: global, then the table's, each awaited. */
|
|
146
|
+
export declare function afterDelete(set: TableHookSet, call: DeleteHookCall): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a
|
|
2
|
+
* What a table that serves a SQL view (`defineView`, `descriptor.kind === "view"`)
|
|
3
3
|
* allows: reads, and for a materialized view only by the roles it names.
|
|
4
4
|
*
|
|
5
5
|
* A plain view runs as the caller (`security_invoker`), so the policies of the
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* `beforeQueryConditions`) — and not of the server's own work, which reads
|
|
11
11
|
* with no viewer at all.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
14
14
|
import { DEFAULT_VIEW_ROLES } from "../schema/plan/view-names.js";
|
|
15
15
|
export { DEFAULT_VIEW_ROLES };
|
|
16
|
-
/** Whether a
|
|
17
|
-
export declare function
|
|
16
|
+
/** Whether a table serves a view rather than a stored table. */
|
|
17
|
+
export declare function isViewTable(table: TableDescriptor | undefined): boolean;
|
|
18
18
|
/** Refuse a caller who holds none of a materialized view's roles. A no-op for anything else. */
|
|
19
|
-
export declare function assertViewReadable(
|
|
20
|
-
/** Refuse a write to a
|
|
21
|
-
export declare function
|
|
19
|
+
export declare function assertViewReadable(table: TableDescriptor | undefined): void;
|
|
20
|
+
/** Refuse a write to a table that serves a view. */
|
|
21
|
+
export declare function assertTableWritable(table: TableDescriptor | undefined, path: string): void;
|
|
@@ -77,7 +77,7 @@ export declare class WriteTransactionScope implements AmbientTransaction {
|
|
|
77
77
|
*/
|
|
78
78
|
assertCommittable(): Promise<void>;
|
|
79
79
|
/**
|
|
80
|
-
* Application code — a
|
|
80
|
+
* Application code — a global or table hook, a column `.transform()`, a
|
|
81
81
|
* `beforeQuery` — is about to run on this transaction, so it may catch a
|
|
82
82
|
* failed statement and leave the transaction aborted: the commit then has
|
|
83
83
|
* to ask ({@link assertCommittable}).
|
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { i as __exportAll } from "./cli-prompt-DXG0yk-h.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { parseEnvBoolean } from "@rebasepro/types";
|
|
5
|
+
import { columnByKey, columnNameOf } from "@rebasepro/common";
|
|
6
6
|
import { sha1Hex, truncateToBytes } from "@rebasepro/utils";
|
|
7
7
|
import process$1 from "node:process";
|
|
8
8
|
import os from "node:os";
|
|
9
9
|
import tty from "node:tty";
|
|
10
|
-
//#region src/schema/
|
|
11
|
-
var
|
|
12
|
-
CollectionIndexConfigError: () => CollectionIndexConfigError,
|
|
10
|
+
//#region src/schema/table-index.ts
|
|
11
|
+
var table_index_exports = /* @__PURE__ */ __exportAll({
|
|
13
12
|
FOREIGN_KEY_INDEX_REASON: () => FOREIGN_KEY_INDEX_REASON,
|
|
14
13
|
MAX_INDEX_KEYS: () => 5,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
collectionIndexStatement: () => collectionIndexStatement,
|
|
18
|
-
collectionIndexStatements: () => collectionIndexStatements,
|
|
14
|
+
TableIndexConfigError: () => TableIndexConfigError,
|
|
15
|
+
buildTableIndexSpecs: () => buildTableIndexSpecs,
|
|
19
16
|
deriveIndexName: () => deriveIndexName,
|
|
20
17
|
foreignKeyIndexSpec: () => foreignKeyIndexSpec,
|
|
21
18
|
indexFingerprint: () => indexFingerprint,
|
|
22
19
|
isRebaseIndexName: () => isRebaseIndexName,
|
|
23
20
|
leadsWithColumn: () => leadsWithColumn,
|
|
24
21
|
renderPredicate: () => renderPredicate,
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
sortIndexSpecs: () => sortIndexSpecs,
|
|
23
|
+
tableIndexStatement: () => tableIndexStatement,
|
|
24
|
+
tableIndexStatements: () => tableIndexStatements
|
|
27
25
|
});
|
|
28
26
|
/**
|
|
29
27
|
* A declaration that cannot become an index.
|
|
@@ -32,12 +30,12 @@ var collection_index_exports = /* @__PURE__ */ __exportAll({
|
|
|
32
30
|
* the alternative is a `CREATE INDEX` that fails during a push with a Postgres
|
|
33
31
|
* error mentioning a column the author never wrote.
|
|
34
32
|
*/
|
|
35
|
-
var
|
|
33
|
+
var TableIndexConfigError = class extends Error {
|
|
36
34
|
collectionSlug;
|
|
37
35
|
position;
|
|
38
36
|
constructor(collectionSlug, position, message) {
|
|
39
37
|
super(`${collectionSlug}.indexes[${position}]: ${message}`);
|
|
40
|
-
this.name = "
|
|
38
|
+
this.name = "TableIndexConfigError";
|
|
41
39
|
this.collectionSlug = collectionSlug;
|
|
42
40
|
this.position = position;
|
|
43
41
|
}
|
|
@@ -133,7 +131,7 @@ var renderPredicate = (predicate) => {
|
|
|
133
131
|
* nothing for a UNIQUE index — the rendered text is `CREATE UNIQUE INDEX …`
|
|
134
132
|
* and the pattern never matches.
|
|
135
133
|
*/
|
|
136
|
-
var
|
|
134
|
+
var tableIndexStatement = (spec, options = {}) => {
|
|
137
135
|
const unique = spec.unique ? "UNIQUE " : "";
|
|
138
136
|
const concurrently = options.concurrently ? "CONCURRENTLY " : "";
|
|
139
137
|
const ifNotExists = options.ifNotExists ? "IF NOT EXISTS " : "";
|
|
@@ -149,33 +147,82 @@ var collectionIndexStatement = (spec, options = {}) => {
|
|
|
149
147
|
const where = spec.predicate ? ` WHERE ${renderPredicate(spec.predicate)}` : "";
|
|
150
148
|
return `CREATE ${unique}INDEX ${concurrently}${ifNotExists}"${spec.indexName}" ON "${spec.schema}"."${spec.table}"${using} (${keys})${include}${where};`;
|
|
151
149
|
};
|
|
152
|
-
var
|
|
153
|
-
var
|
|
150
|
+
var tableIndexStatements = (specs, options = {}) => specs.map((spec) => tableIndexStatement(spec, options));
|
|
151
|
+
var tableIndexKey = (entry) => typeof entry === "string" ? { key: entry } : {
|
|
152
|
+
key: entry.column,
|
|
153
|
+
...entry.direction !== void 0 ? { direction: entry.direction } : {},
|
|
154
|
+
...entry.nulls !== void 0 ? { nulls: entry.nulls } : {}
|
|
155
|
+
};
|
|
156
|
+
var tablePredicate = (predicate) => {
|
|
157
|
+
if ("and" in predicate) return { and: predicate.and.map(tablePredicate) };
|
|
158
|
+
switch (predicate.op) {
|
|
159
|
+
case "is null":
|
|
160
|
+
case "is not null": return {
|
|
161
|
+
key: predicate.column,
|
|
162
|
+
op: predicate.op
|
|
163
|
+
};
|
|
164
|
+
case "in": return {
|
|
165
|
+
key: predicate.column,
|
|
166
|
+
op: "in",
|
|
167
|
+
value: predicate.value
|
|
168
|
+
};
|
|
169
|
+
default: return {
|
|
170
|
+
key: predicate.column,
|
|
171
|
+
op: predicate.op,
|
|
172
|
+
value: predicate.value
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var tableIndexSource = (index) => ({
|
|
177
|
+
on: index.columns.map(tableIndexKey),
|
|
178
|
+
...index.using !== void 0 ? { using: index.using } : {},
|
|
179
|
+
...index.unique !== void 0 ? { unique: index.unique } : {},
|
|
180
|
+
...index.include !== void 0 ? { include: index.include } : {},
|
|
181
|
+
...index.where !== void 0 ? { where: tablePredicate(index.where) } : {},
|
|
182
|
+
...index.reason !== void 0 ? { reason: index.reason } : {}
|
|
183
|
+
});
|
|
154
184
|
/**
|
|
155
|
-
* The column a
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
* The SQL column an index key names on a table: a column key, or a
|
|
186
|
+
* `belongsTo` relation (its foreign-key column). Another relation kind has no
|
|
187
|
+
* column here — its foreign key is on the target, or in a junction.
|
|
188
|
+
*/
|
|
189
|
+
var tableIndexColumn = (table, key, fail) => {
|
|
190
|
+
const column = columnByKey(table, key);
|
|
191
|
+
if (column) return column.column;
|
|
192
|
+
const relation = table.relations.find((candidate) => candidate.name === key);
|
|
193
|
+
if (relation?.kind === "belongsTo") return relation.localKey;
|
|
194
|
+
if (relation) return fail(`"${key}" is a ${relation.kind} relation, which has no column on this table — the foreign key lives on "${relation.target}". Declare the index there.`);
|
|
195
|
+
return fail(`"${key}" is no column key or \`belongsTo\` relation of this table.`);
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Every index one table declares (`indexes`), resolved and named, read from
|
|
199
|
+
* its descriptor — what the planner calls, for a table and for a
|
|
200
|
+
* materialized view's stored rows alike.
|
|
161
201
|
*
|
|
162
|
-
*
|
|
163
|
-
* on the target's table, or in a junction. Indexing them here is refused
|
|
164
|
-
* rather than resolved to a column that does not exist.
|
|
202
|
+
* Throws {@link TableIndexConfigError} rather than dropping a bad entry.
|
|
165
203
|
*/
|
|
166
|
-
var
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
var buildTableIndexSpecs = (table) => {
|
|
205
|
+
const declared = table.indexes;
|
|
206
|
+
if (!declared || declared.length === 0) return [];
|
|
207
|
+
return indexSpecsFrom({
|
|
208
|
+
slug: table.slug,
|
|
209
|
+
schema: table.schema,
|
|
210
|
+
table: table.table,
|
|
211
|
+
primaryKey: table.primaryKey.map((key) => columnNameOf(table, key) ?? key),
|
|
212
|
+
indexes: declared.map(tableIndexSource),
|
|
213
|
+
column: (key, fail) => tableIndexColumn(table, key, fail),
|
|
214
|
+
declaresUnique: (key) => {
|
|
215
|
+
const column = columnByKey(table, key);
|
|
216
|
+
if (column) return column.unique === true;
|
|
217
|
+
const relation = table.relations.find((candidate) => candidate.name === key);
|
|
218
|
+
if (relation?.kind !== "belongsTo") return false;
|
|
219
|
+
return table.columns.some((candidate) => candidate.column === relation.localKey && candidate.unique === true);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
175
222
|
};
|
|
176
|
-
var
|
|
177
|
-
if ("and" in predicate) return { and: predicate.and.map((p) =>
|
|
178
|
-
const column =
|
|
223
|
+
var resolveSourcePredicate = (source, predicate, fail) => {
|
|
224
|
+
if ("and" in predicate) return { and: predicate.and.map((p) => resolveSourcePredicate(source, p, fail)) };
|
|
225
|
+
const column = source.column(predicate.key, fail);
|
|
179
226
|
switch (predicate.op) {
|
|
180
227
|
case "is null":
|
|
181
228
|
case "is not null": return {
|
|
@@ -183,7 +230,7 @@ var resolvePredicate = (collection, predicate, resolveColumnName, fail) => {
|
|
|
183
230
|
op: predicate.op
|
|
184
231
|
};
|
|
185
232
|
case "in":
|
|
186
|
-
if (new Set(predicate.value).size !== predicate.value.length) fail(`the \`in\` list for "${predicate.
|
|
233
|
+
if (new Set(predicate.value).size !== predicate.value.length) fail(`the \`in\` list for "${predicate.key}" repeats a value, which changes nothing.`);
|
|
187
234
|
return {
|
|
188
235
|
column,
|
|
189
236
|
op: "in",
|
|
@@ -196,57 +243,43 @@ var resolvePredicate = (collection, predicate, resolveColumnName, fail) => {
|
|
|
196
243
|
};
|
|
197
244
|
}
|
|
198
245
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* Every index one collection declares, resolved and named.
|
|
203
|
-
*
|
|
204
|
-
* Throws {@link CollectionIndexConfigError} rather than dropping a bad entry:
|
|
205
|
-
* an index that silently does not exist is the failure mode this whole feature
|
|
206
|
-
* is here to remove.
|
|
207
|
-
*/
|
|
208
|
-
var buildCollectionIndexSpecs = (collection, resolveColumnName) => {
|
|
209
|
-
if (!isPostgresCollectionConfig(collection)) return [];
|
|
210
|
-
const declared = collection.indexes;
|
|
211
|
-
if (!declared || declared.length === 0) return [];
|
|
212
|
-
const slug = collection.slug ?? getTableName(collection);
|
|
213
|
-
const schema = collection.schema ?? "public";
|
|
214
|
-
const table = getTableName(collection);
|
|
215
|
-
const pk = primaryKeyColumns(collection, resolveColumnName).sort().join(",");
|
|
246
|
+
var indexSpecsFrom = (source) => {
|
|
247
|
+
const { slug, schema, table } = source;
|
|
248
|
+
const pk = [...source.primaryKey].sort().join(",");
|
|
216
249
|
const specs = [];
|
|
217
250
|
const byName = /* @__PURE__ */ new Map();
|
|
218
|
-
|
|
251
|
+
source.indexes.forEach((index, position) => {
|
|
219
252
|
const fail = (message) => {
|
|
220
|
-
throw new
|
|
253
|
+
throw new TableIndexConfigError(slug, position, message);
|
|
221
254
|
};
|
|
222
|
-
if (
|
|
223
|
-
if (!Array.isArray(index.on) || index.on.length === 0) fail("`on` must name at least one property.");
|
|
255
|
+
if (index.on.length === 0) fail("`on` must name at least one column.");
|
|
224
256
|
if (index.on.length > 5) fail(`\`on\` has ${index.on.length} keys; the limit is 5. Payload columns belong in \`include\`.`);
|
|
225
257
|
const method = index.using ?? "btree";
|
|
226
258
|
const unique = method === "btree" && Boolean(index.unique);
|
|
227
259
|
if (!isOrderedMethod(method)) {
|
|
228
|
-
for (const key of index.on) if (
|
|
260
|
+
for (const key of index.on) if (key.direction !== void 0 || key.nulls !== void 0) fail(`access method "${method}" does not support ASC/DESC or NULLS options.`);
|
|
229
261
|
}
|
|
230
262
|
const keys = index.on.map((key) => {
|
|
231
|
-
const column =
|
|
232
|
-
const direction =
|
|
263
|
+
const column = source.column(key.key, fail);
|
|
264
|
+
const direction = key.direction ?? "asc";
|
|
233
265
|
return {
|
|
234
266
|
column,
|
|
235
267
|
direction,
|
|
236
|
-
nulls:
|
|
268
|
+
nulls: key.nulls ?? (direction === "desc" ? "first" : "last")
|
|
237
269
|
};
|
|
238
270
|
});
|
|
239
271
|
const duplicateKey = keys.map((k) => k.column).find((c, i, all) => all.indexOf(c) !== i);
|
|
240
272
|
if (duplicateKey) fail(`"${duplicateKey}" appears twice in \`on\`.`);
|
|
241
273
|
if (keys.map((k) => k.column).sort().join(",") === pk && pk !== "") fail(`this is the primary key — "${table}_pkey" already indexes exactly these columns.`);
|
|
242
|
-
const include = (index.include ?? []).map((
|
|
274
|
+
const include = (index.include ?? []).map((key) => source.column(key, fail));
|
|
243
275
|
const overlap = include.find((c) => keys.some((k) => k.column === c));
|
|
244
276
|
if (overlap) fail(`"${overlap}" is in both \`on\` and \`include\`; Postgres rejects the overlap.`);
|
|
245
277
|
if (unique && keys.length === 1) {
|
|
246
|
-
const
|
|
247
|
-
if ((
|
|
278
|
+
const key = index.on[0].key;
|
|
279
|
+
if (source.declaresUnique(key)) fail(`"${key}" already declares a single-column UNIQUE (\`.unique()\`, legacy \`validation.unique\`). Two declarations of one guarantee — remove one.`);
|
|
248
280
|
}
|
|
249
|
-
const predicate = index.where ?
|
|
281
|
+
const predicate = index.where ? resolveSourcePredicate(source, index.where, fail) : null;
|
|
282
|
+
const reason = index.reason === void 0 || index.reason.trim() === "" ? {} : { reason: index.reason };
|
|
250
283
|
const withoutName = {
|
|
251
284
|
schema,
|
|
252
285
|
table,
|
|
@@ -255,7 +288,7 @@ var buildCollectionIndexSpecs = (collection, resolveColumnName) => {
|
|
|
255
288
|
keys,
|
|
256
289
|
include,
|
|
257
290
|
predicate,
|
|
258
|
-
reason
|
|
291
|
+
...reason
|
|
259
292
|
};
|
|
260
293
|
const indexName = deriveIndexName(withoutName);
|
|
261
294
|
const clash = byName.get(indexName);
|
|
@@ -269,15 +302,6 @@ var buildCollectionIndexSpecs = (collection, resolveColumnName) => {
|
|
|
269
302
|
return specs;
|
|
270
303
|
};
|
|
271
304
|
/**
|
|
272
|
-
* Every declared index across a set of collections, in a stable order.
|
|
273
|
-
*
|
|
274
|
-
* Sorted because the result reaches `schema.sql`, which `doctor` string-
|
|
275
|
-
* compares against a regenerated copy — `generatePostgresDdl` does not sort its
|
|
276
|
-
* collections, so leaving this in declaration order would make the artifact
|
|
277
|
-
* depend on the order files happened to load in.
|
|
278
|
-
*/
|
|
279
|
-
var buildCollectionIndexPlan = (collections, resolveColumnName) => sortIndexSpecs(collections.flatMap((collection) => buildCollectionIndexSpecs(collection, resolveColumnName)));
|
|
280
|
-
/**
|
|
281
305
|
* The stable order every consumer of a set of index specs uses.
|
|
282
306
|
*
|
|
283
307
|
* Exported because the boot-time diff reads the specs off the schema plan
|
|
@@ -462,6 +486,7 @@ var wantsStack = () => parseEnvBoolean(process.env.REBASE_DEBUG) === true;
|
|
|
462
486
|
*/
|
|
463
487
|
var describeFailure = (error) => {
|
|
464
488
|
if (!(error instanceof Error)) return String(error);
|
|
489
|
+
if (isSchemaDefinitionRefusal(error) && !wantsStack()) return error.message;
|
|
465
490
|
const failedQuery = describeFailedQuery(error);
|
|
466
491
|
const lead = failedQuery?.reason ? `${failedQuery.reason}\n ` : "";
|
|
467
492
|
if (wantsStack() && error.stack) {
|
|
@@ -474,6 +499,13 @@ var describeFailure = (error) => {
|
|
|
474
499
|
return `${error.message}\n Re-run with --debug for the stack trace.`;
|
|
475
500
|
};
|
|
476
501
|
/**
|
|
502
|
+
* Whether an error is `SchemaDefinitionError` (`@rebasepro/common`), told by
|
|
503
|
+
* its code so this module does not import the package.
|
|
504
|
+
*/
|
|
505
|
+
function isSchemaDefinitionRefusal(error) {
|
|
506
|
+
return "code" in error && error.code === "SCHEMA_DEFINITION_INVALID";
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
477
509
|
* A failed query as a reader needs it: why it failed — Postgres' own reason
|
|
478
510
|
* with its SQLSTATE (`relation "nope_table" does not exist (42P01)`), or the
|
|
479
511
|
* driver's when Postgres never answered — and the query without the values it
|
|
@@ -911,6 +943,6 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
911
943
|
var chalk = createChalk();
|
|
912
944
|
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
913
945
|
//#endregion
|
|
914
|
-
export {
|
|
946
|
+
export { table_index_exports as _, outWarn as a, buildTableIndexSpecs as c, isRebaseIndexName as d, leadsWithColumn as f, tableIndexStatements as g, tableIndexStatement as h, outError as i, deriveIndexName as l, sortIndexSpecs as m, describeFailure as n, atlasExcludePattern as o, renderPredicate as p, out as r, excludePatternParts as s, chalk as t, foreignKeyIndexSpec as u };
|
|
915
947
|
|
|
916
|
-
//# sourceMappingURL=source-
|
|
948
|
+
//# sourceMappingURL=source-VxbrQojV.js.map
|