@rebasepro/server-postgres 0.24.0 → 0.24.1-canary.g19596ef
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 +16 -0
- package/dist/{BranchService-BRt78gfa.js → BranchService-UgKa416x.js} +14 -3
- package/dist/BranchService-UgKa416x.js.map +1 -0
- package/dist/PostgresBackendDriver.d.ts +104 -2
- package/dist/PostgresBootstrapper.d.ts +101 -2
- package/dist/auth/ensure-tables.d.ts +12 -0
- package/dist/auth/services.d.ts +6 -0
- package/dist/backup/backup-cli.d.ts +75 -2
- package/dist/backup/backup-service.d.ts +2 -2
- package/dist/backup/pg-binary.d.ts +5 -0
- package/dist/{backup-cli-DW5p9_zv.js → backup-cli-yiKd1GsC.js} +168 -75
- package/dist/backup-cli-yiKd1GsC.js.map +1 -0
- package/dist/{backup-service-EwcDVG-8.js → backup-service-AZWc2wvI.js} +99 -28
- package/dist/backup-service-AZWc2wvI.js.map +1 -0
- package/dist/boot-ddl-B9ZmBJ75.js +105 -0
- package/dist/boot-ddl-B9ZmBJ75.js.map +1 -0
- package/dist/cli-console-DGee3Zl7.js +225 -0
- package/dist/cli-console-DGee3Zl7.js.map +1 -0
- package/dist/cli-console.d.ts +39 -0
- package/dist/cli-errors-oVUuD8k0.js +2180 -0
- package/dist/cli-errors-oVUuD8k0.js.map +1 -0
- package/dist/cli-errors.d.ts +91 -9
- package/dist/{cli-flags-BglvpjHv.js → cli-flags-DnPHXjRH.js} +56 -6
- package/dist/cli-flags-DnPHXjRH.js.map +1 -0
- package/dist/cli-flags.d.ts +15 -0
- package/dist/cli-helpers.d.ts +76 -22
- package/dist/cli-output.d.ts +16 -28
- package/dist/{arg-Dni7MzLB.js → cli-prompt-egtNKkZl.js} +49 -3
- package/dist/cli-prompt-egtNKkZl.js.map +1 -0
- package/dist/cli-prompt.d.ts +19 -0
- package/dist/cli-push.d.ts +87 -0
- package/dist/cli-scratch-database.d.ts +33 -8
- package/dist/cli.js +764 -222
- package/dist/cli.js.map +1 -1
- package/dist/{column-plan-helpers-1-LQD0yI.js → column-plan-helpers-D_V4oaZh.js} +11 -5
- package/dist/{column-plan-helpers-1-LQD0yI.js.map → column-plan-helpers-D_V4oaZh.js.map} +1 -1
- package/dist/{databasePoolManager-Bj5FbeAs.js → connection-C938nR3E.js} +25 -113
- package/dist/connection-C938nR3E.js.map +1 -0
- package/dist/connection.d.ts +13 -2
- package/dist/databasePoolManager-DZgnBOgj.js +119 -0
- package/dist/databasePoolManager-DZgnBOgj.js.map +1 -0
- package/dist/{ensure-collection-tables-kkkHk8oo.js → deferred-index-build-BqmEHGaD.js} +485 -347
- package/dist/deferred-index-build-BqmEHGaD.js.map +1 -0
- package/dist/{doctor-C-sYWbmt.js → doctor-CUAAOFZm.js} +65 -54
- package/dist/doctor-CUAAOFZm.js.map +1 -0
- package/dist/ensure-collection-policies-Bb51V2OV.js +541 -0
- package/dist/ensure-collection-policies-Bb51V2OV.js.map +1 -0
- package/dist/ensure-collection-tables-egjGBjhv.js +532 -0
- package/dist/ensure-collection-tables-egjGBjhv.js.map +1 -0
- package/dist/{ensure-tables-BmI_tRxc.js → ensure-tables-DMPWhJ6R.js} +174 -78
- package/dist/ensure-tables-DMPWhJ6R.js.map +1 -0
- package/dist/enum-labels-kept-Msq5gMcb.js +56 -0
- package/dist/enum-labels-kept-Msq5gMcb.js.map +1 -0
- package/dist/generate-drizzle-schema-DrA-YgXv.js +57 -0
- package/dist/generate-drizzle-schema-DrA-YgXv.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-sSFDp6LR.js → generate-drizzle-schema-logic-BaT0H7Gq.js} +6 -6
- package/dist/generate-drizzle-schema-logic-BaT0H7Gq.js.map +1 -0
- package/dist/generate-files-OoRJLEdk.js +199 -0
- package/dist/generate-files-OoRJLEdk.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js → generate-postgres-ddl-logic-B4k9djAV.js} +4 -4
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js.map → generate-postgres-ddl-logic-B4k9djAV.js.map} +1 -1
- package/dist/{generated-schema-staleness-Di9c4ZxN.js → generated-schema-staleness-BWN_PsMi.js} +2 -2
- package/dist/{generated-schema-staleness-Di9c4ZxN.js.map → generated-schema-staleness-BWN_PsMi.js.map} +1 -1
- package/dist/generated-sql.d.ts +8 -2
- package/dist/history/HistoryService.d.ts +64 -5
- package/dist/history/ensure-history-table.d.ts +63 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +139 -19236
- package/dist/index.es.js.map +1 -1
- package/dist/{introspect-db-logic-kCETE8TY.js → introspect-db-logic-BCc1Jym2.js} +136 -9
- package/dist/introspect-db-logic-BCc1Jym2.js.map +1 -0
- package/dist/{introspect-db-queries-C_Q5VgQw.js → introspect-db-queries-BhhJg0b8.js} +48 -1
- package/dist/introspect-db-queries-BhhJg0b8.js.map +1 -0
- package/dist/open-rebase-CAjWpPjs.js +20895 -0
- package/dist/open-rebase-CAjWpPjs.js.map +1 -0
- package/dist/open-rebase.d.ts +94 -0
- package/dist/pg-error-utils-Bs_Ue4wn.js +395 -0
- package/dist/pg-error-utils-Bs_Ue4wn.js.map +1 -0
- package/dist/{plan-schema-DU9exq6C.js → plan-schema-CsNgK0qi.js} +152 -42
- package/dist/plan-schema-CsNgK0qi.js.map +1 -0
- package/dist/{policy-drift-B-J2hhm0.js → policy-drift-BKC50y2p.js} +32 -8
- package/dist/policy-drift-BKC50y2p.js.map +1 -0
- package/dist/push-index-prebuild-C_qhyoJa.js +45 -0
- package/dist/push-index-prebuild-C_qhyoJa.js.map +1 -0
- package/dist/push-legacy-renames-5g9h3HOa.js +34 -0
- package/dist/push-legacy-renames-5g9h3HOa.js.map +1 -0
- package/dist/{render-ddl-Ds2t_d9V.js → render-ddl-CrfEe__B.js} +15 -10
- package/dist/render-ddl-CrfEe__B.js.map +1 -0
- package/dist/{rls-bootstrap-sql-_KNnjanK.js → rls-bootstrap-sql-Bd-hJk08.js} +125 -1325
- package/dist/rls-bootstrap-sql-Bd-hJk08.js.map +1 -0
- package/dist/{rls-enforcement-CfXOJJaW.js → rls-enforcement-D7P4-ZYX.js} +130 -18
- package/dist/rls-enforcement-D7P4-ZYX.js.map +1 -0
- package/dist/{__vite-browser-external-BnuHet1e.js → rolldown-runtime-V7rFbMRe.js} +1 -8
- package/dist/schema/atlas-exclude.d.ts +42 -0
- package/dist/schema/auth-schema.d.ts +2 -2
- package/dist/schema/boot-ddl.d.ts +47 -0
- package/dist/schema/carved-out-migration.d.ts +5 -4
- package/dist/schema/collection-index.d.ts +45 -0
- package/dist/schema/column-plan-helpers.d.ts +5 -0
- package/dist/schema/deferred-index-build.d.ts +131 -0
- package/dist/schema/destructive-sql.d.ts +30 -1
- package/dist/schema/doctor-cli.js +110 -6
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-search-scale.d.ts +45 -0
- package/dist/schema/doctor.d.ts +20 -1
- package/dist/schema/ensure-collection-policies.d.ts +73 -35
- package/dist/schema/ensure-collection-tables.d.ts +56 -3
- package/dist/schema/enum-labels-kept.d.ts +26 -0
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +44 -0
- package/dist/schema/generate-next-step.d.ts +0 -13
- package/dist/schema/generate-postgres-ddl.js +10 -81
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/generated-schema-diff.d.ts +7 -0
- package/dist/schema/introspect-db-logic.d.ts +32 -0
- package/dist/schema/introspect-db-queries.d.ts +20 -1
- package/dist/schema/introspect-db-structure.d.ts +10 -0
- package/dist/schema/introspect-db.js +16 -20
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/migrate-baseline.d.ts +33 -0
- package/dist/schema/migration-post-process.d.ts +34 -0
- package/dist/schema/plan/diff-plan.d.ts +126 -0
- package/dist/schema/plan/render-ddl.d.ts +2 -1
- package/dist/schema/plan/types.d.ts +8 -0
- package/dist/schema/push-index-prebuild.d.ts +25 -0
- package/dist/schema/push-legacy-renames.d.ts +20 -0
- package/dist/schema/rls-bootstrap-sql.d.ts +15 -0
- package/dist/schema/undeclarable-constraints.d.ts +59 -0
- package/dist/security/rls-enforcement.d.ts +32 -4
- package/dist/services/BranchService.d.ts +7 -0
- package/dist/services/FetchService.d.ts +58 -8
- package/dist/services/PersistService.d.ts +15 -0
- package/dist/services/RelationService.d.ts +88 -3
- package/dist/services/cdc/CdcListener.d.ts +17 -6
- package/dist/services/cdc/trigger-cdc.d.ts +151 -27
- package/dist/services/channel-bus/index.d.ts +1 -1
- package/dist/services/channel-history.d.ts +15 -4
- package/dist/services/collection-helpers.d.ts +15 -0
- package/dist/services/field-viewer.d.ts +15 -1
- package/dist/services/pg-notify-listener.d.ts +7 -0
- package/dist/services/realtimeService.d.ts +314 -14
- package/dist/services/row-pipeline.d.ts +16 -9
- package/dist/services/socket-liveness.d.ts +42 -2
- package/dist/services/sql-script.d.ts +207 -3
- package/dist/services/vector-iterative-scan.d.ts +40 -0
- package/dist/services/write-depth.d.ts +6 -0
- package/dist/services/write-transaction-scope.d.ts +9 -0
- package/dist/socket-opt-ins.d.ts +64 -0
- package/dist/source-DB6xJv3p.js +873 -0
- package/dist/source-DB6xJv3p.js.map +1 -0
- package/dist/tsx-loader.d.ts +14 -0
- package/dist/utils/connection-string.d.ts +31 -0
- package/dist/utils/drizzle-conditions.d.ts +21 -1
- package/dist/utils/error-cause.d.ts +7 -0
- package/dist/utils/pg-error-utils.d.ts +2 -4
- package/dist/utils/result-rows.d.ts +10 -0
- package/dist/{vector-index-CMJKb3C9.js → vector-index-BFhyEaiz.js} +2 -2
- package/dist/{vector-index-CMJKb3C9.js.map → vector-index-BFhyEaiz.js.map} +1 -1
- package/dist/websocket-DUiiwQd2.js +1632 -0
- package/dist/websocket-DUiiwQd2.js.map +1 -0
- package/dist/websocket.d.ts +13 -0
- package/package.json +7 -7
- package/dist/BranchService-BRt78gfa.js.map +0 -1
- package/dist/__vite-browser-external-BnuHet1e.js.map +0 -1
- package/dist/arg-Dni7MzLB.js.map +0 -1
- package/dist/backup-cli-DW5p9_zv.js.map +0 -1
- package/dist/backup-service-EwcDVG-8.js.map +0 -1
- package/dist/cli-errors-DsA-K9uP.js +0 -893
- package/dist/cli-errors-DsA-K9uP.js.map +0 -1
- package/dist/cli-flags-BglvpjHv.js.map +0 -1
- package/dist/cli-output-CNdMql-L.js +0 -47
- package/dist/cli-output-CNdMql-L.js.map +0 -1
- package/dist/collection-index-DdnsxiJ_.js +0 -286
- package/dist/collection-index-DdnsxiJ_.js.map +0 -1
- package/dist/databasePoolManager-Bj5FbeAs.js.map +0 -1
- package/dist/doctor-C-sYWbmt.js.map +0 -1
- package/dist/ensure-collection-policies-B1ureSIV.js +0 -160
- package/dist/ensure-collection-policies-B1ureSIV.js.map +0 -1
- package/dist/ensure-collection-tables-kkkHk8oo.js.map +0 -1
- package/dist/ensure-tables-BmI_tRxc.js.map +0 -1
- package/dist/generate-drizzle-schema-93M0lUxK.js +0 -123
- package/dist/generate-drizzle-schema-93M0lUxK.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-sSFDp6LR.js.map +0 -1
- package/dist/introspect-db-logic-kCETE8TY.js.map +0 -1
- package/dist/introspect-db-queries-C_Q5VgQw.js.map +0 -1
- package/dist/plan-schema-DU9exq6C.js.map +0 -1
- package/dist/policy-drift-B-J2hhm0.js.map +0 -1
- package/dist/render-ddl-Ds2t_d9V.js.map +0 -1
- package/dist/rls-bootstrap-sql-_KNnjanK.js.map +0 -1
- package/dist/rls-enforcement-CfXOJJaW.js.map +0 -1
- package/dist/source-Br7L7GOI.js +0 -410
- package/dist/source-Br7L7GOI.js.map +0 -1
- package/dist/utils/sql-redaction.d.ts +0 -21
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
__createRequire(import.meta.url);
|
|
3
|
+
import { n as __exportAll } from "./rolldown-runtime-V7rFbMRe.js";
|
|
4
|
+
import { isPostgresCollectionConfig, parseEnvBoolean } from "@rebasepro/types";
|
|
5
|
+
import { getTableName, resolveCollectionRelations } from "@rebasepro/common";
|
|
6
|
+
import { sha1Hex, truncateToBytes } from "@rebasepro/utils";
|
|
7
|
+
import process$1 from "node:process";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import tty from "node:tty";
|
|
10
|
+
//#region src/schema/collection-index.ts
|
|
11
|
+
var collection_index_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
CollectionIndexConfigError: () => CollectionIndexConfigError,
|
|
13
|
+
FOREIGN_KEY_INDEX_REASON: () => FOREIGN_KEY_INDEX_REASON,
|
|
14
|
+
MAX_INDEX_KEYS: () => 5,
|
|
15
|
+
buildCollectionIndexPlan: () => buildCollectionIndexPlan,
|
|
16
|
+
buildCollectionIndexSpecs: () => buildCollectionIndexSpecs,
|
|
17
|
+
collectionIndexStatement: () => collectionIndexStatement,
|
|
18
|
+
collectionIndexStatements: () => collectionIndexStatements,
|
|
19
|
+
deriveIndexName: () => deriveIndexName,
|
|
20
|
+
foreignKeyIndexSpec: () => foreignKeyIndexSpec,
|
|
21
|
+
indexFingerprint: () => indexFingerprint,
|
|
22
|
+
isRebaseIndexName: () => isRebaseIndexName,
|
|
23
|
+
leadsWithColumn: () => leadsWithColumn,
|
|
24
|
+
renderPredicate: () => renderPredicate,
|
|
25
|
+
resolveIndexableColumn: () => resolveIndexableColumn,
|
|
26
|
+
sortIndexSpecs: () => sortIndexSpecs
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* A declaration that cannot become an index.
|
|
30
|
+
*
|
|
31
|
+
* Thrown at build time, naming the collection and the array position, because
|
|
32
|
+
* the alternative is a `CREATE INDEX` that fails during a push with a Postgres
|
|
33
|
+
* error mentioning a column the author never wrote.
|
|
34
|
+
*/
|
|
35
|
+
var CollectionIndexConfigError = class extends Error {
|
|
36
|
+
collectionSlug;
|
|
37
|
+
position;
|
|
38
|
+
constructor(collectionSlug, position, message) {
|
|
39
|
+
super(`${collectionSlug}.indexes[${position}]: ${message}`);
|
|
40
|
+
this.name = "CollectionIndexConfigError";
|
|
41
|
+
this.collectionSlug = collectionSlug;
|
|
42
|
+
this.position = position;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* `_ix`/`_ux` plus `_` plus 7 hex — the part of the name that must always
|
|
47
|
+
* survive truncation, and therefore is never inside the truncated portion.
|
|
48
|
+
*/
|
|
49
|
+
var NAME_SUFFIX_BYTES = 11;
|
|
50
|
+
/**
|
|
51
|
+
* Every Rebase-managed index name, and nothing else.
|
|
52
|
+
*
|
|
53
|
+
* The terminal `_ix_`/`_ux_` plus exactly seven lowercase hex characters is
|
|
54
|
+
* what separates this scheme from every other producer in the codebase —
|
|
55
|
+
* `_fkey`, `_gin`, `_trgm`, `_pkey`, `_key`, the vector distances, and the
|
|
56
|
+
* `idx_` prefix auth uses. `_idx` was rejected as a tail because it is already
|
|
57
|
+
* taken for real: `users_email_verification_token_idx` is byte-for-byte what a
|
|
58
|
+
* naive `<table>_<column>_idx` derives on an auth-enabled `users` collection.
|
|
59
|
+
*
|
|
60
|
+
* Load-bearing for safety, not just tidiness. An index that does NOT match this
|
|
61
|
+
* belongs to somebody else — a hand-written one, or one an introspected
|
|
62
|
+
* database arrived with — and is excluded from the Atlas diff so the push
|
|
63
|
+
* cannot drop it.
|
|
64
|
+
*/
|
|
65
|
+
var isRebaseIndexName = (name) => /_(?:ix|ux)_[0-9a-f]{7}$/.test(name);
|
|
66
|
+
var isOrderedMethod = (method) => method === "btree";
|
|
67
|
+
/**
|
|
68
|
+
* The parts of an index that decide what it *is*.
|
|
69
|
+
*
|
|
70
|
+
* A semantic projection, not the rendered statement — the same arrangement as
|
|
71
|
+
* `getPolicyNameHash`, and for the same reason. A change to how this file
|
|
72
|
+
* formats SQL (eliding a default `USING btree`, quoting differently, emitting
|
|
73
|
+
* `NULLS LAST` explicitly) must not silently rename every index in every
|
|
74
|
+
* deployed database. Hashing generator output would make every cosmetic edit a
|
|
75
|
+
* fleet-wide DROP + CREATE.
|
|
76
|
+
*
|
|
77
|
+
* `reason` is deliberately absent: rewording a comment must not rebuild an
|
|
78
|
+
* index. `nulls` is the *effective* placement, so writing Postgres's own
|
|
79
|
+
* default down is a no-op rather than a redefinition.
|
|
80
|
+
*
|
|
81
|
+
* `v` is the only escape hatch, and it is expensive on purpose: bumping it
|
|
82
|
+
* renames every index in the field.
|
|
83
|
+
*/
|
|
84
|
+
var indexFingerprint = (spec) => sha1Hex(JSON.stringify({
|
|
85
|
+
v: 1,
|
|
86
|
+
s: spec.schema,
|
|
87
|
+
t: spec.table,
|
|
88
|
+
m: spec.method,
|
|
89
|
+
u: spec.unique,
|
|
90
|
+
k: spec.keys.map((k) => [
|
|
91
|
+
k.column,
|
|
92
|
+
k.direction,
|
|
93
|
+
k.nulls
|
|
94
|
+
]),
|
|
95
|
+
i: spec.include,
|
|
96
|
+
w: spec.predicate
|
|
97
|
+
})).substring(0, 7);
|
|
98
|
+
/**
|
|
99
|
+
* `<table>_<columns>_ix_<hash>`, or `_ux_` when unique.
|
|
100
|
+
*
|
|
101
|
+
* Truncation eats the readable head and never the hash. `toPostgresIdentifier`
|
|
102
|
+
* truncates the whole string at 63 bytes, which on a hashed name would cut off
|
|
103
|
+
* the one part that makes it unique — the failure already frozen into
|
|
104
|
+
* `contracts/derived-names.txt`, where a foreign key is recorded with its
|
|
105
|
+
* `_fkey` suffix truncated away, so a second foreign key on that table would
|
|
106
|
+
* derive a byte-identical name.
|
|
107
|
+
*/
|
|
108
|
+
var deriveIndexName = (spec) => {
|
|
109
|
+
const suffix = `_${spec.unique ? "ux" : "ix"}_${indexFingerprint(spec)}`;
|
|
110
|
+
return `${truncateToBytes(`${spec.table}_${spec.keys.map((k) => k.column).join("_")}`, 63 - NAME_SUFFIX_BYTES)}${suffix}`;
|
|
111
|
+
};
|
|
112
|
+
var quoteLiteral = (value) => {
|
|
113
|
+
if (typeof value === "number") return String(value);
|
|
114
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
115
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
116
|
+
};
|
|
117
|
+
/** Render a resolved predicate as the body of a `WHERE` clause. */
|
|
118
|
+
var renderPredicate = (predicate) => {
|
|
119
|
+
if ("and" in predicate) return predicate.and.map(renderPredicate).join(" AND ");
|
|
120
|
+
switch (predicate.op) {
|
|
121
|
+
case "is null":
|
|
122
|
+
case "is not null": return `"${predicate.column}" ${predicate.op.toUpperCase()}`;
|
|
123
|
+
case "in": return `"${predicate.column}" IN (${predicate.value.map(quoteLiteral).join(", ")})`;
|
|
124
|
+
default: return `"${predicate.column}" ${predicate.op} ${quoteLiteral(predicate.value)}`;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The `CREATE INDEX` for one spec.
|
|
129
|
+
*
|
|
130
|
+
* `concurrently` is a parameter rather than a string replacement on the way
|
|
131
|
+
* out. `search-column.ts` and `vector-index.ts` both reach for
|
|
132
|
+
* `.replace("CREATE INDEX IF NOT EXISTS", …)` instead, which silently does
|
|
133
|
+
* nothing for a UNIQUE index — the rendered text is `CREATE UNIQUE INDEX …`
|
|
134
|
+
* and the pattern never matches.
|
|
135
|
+
*/
|
|
136
|
+
var collectionIndexStatement = (spec, options = {}) => {
|
|
137
|
+
const unique = spec.unique ? "UNIQUE " : "";
|
|
138
|
+
const concurrently = options.concurrently ? "CONCURRENTLY " : "";
|
|
139
|
+
const ifNotExists = options.ifNotExists ? "IF NOT EXISTS " : "";
|
|
140
|
+
const using = spec.method === "btree" ? "" : ` USING ${spec.method}`;
|
|
141
|
+
const keys = spec.keys.map((k) => {
|
|
142
|
+
if (!isOrderedMethod(spec.method)) return `"${k.column}"`;
|
|
143
|
+
const direction = k.direction === "desc" ? " DESC" : "";
|
|
144
|
+
const impliedNulls = k.direction === "desc" ? "first" : "last";
|
|
145
|
+
const nulls = k.nulls === impliedNulls ? "" : ` NULLS ${k.nulls.toUpperCase()}`;
|
|
146
|
+
return `"${k.column}"${direction}${nulls}`;
|
|
147
|
+
}).join(", ");
|
|
148
|
+
const include = spec.include.length > 0 ? ` INCLUDE (${spec.include.map((c) => `"${c}"`).join(", ")})` : "";
|
|
149
|
+
const where = spec.predicate ? ` WHERE ${renderPredicate(spec.predicate)}` : "";
|
|
150
|
+
return `CREATE ${unique}INDEX ${concurrently}${ifNotExists}"${spec.indexName}" ON "${spec.schema}"."${spec.table}"${using} (${keys})${include}${where};`;
|
|
151
|
+
};
|
|
152
|
+
var collectionIndexStatements = (specs, options = {}) => specs.map((spec) => collectionIndexStatement(spec, options));
|
|
153
|
+
var relationOf = (collection, propKey) => resolveCollectionRelations(collection)[propKey];
|
|
154
|
+
/**
|
|
155
|
+
* The column a property key indexes.
|
|
156
|
+
*
|
|
157
|
+
* A `belongsTo` resolves to its `localKey` — `primaryCategory` becomes
|
|
158
|
+
* `primary_category_id` — which is the case an index is most often wanted for
|
|
159
|
+
* and the case where the property key and the column differ. Everything else
|
|
160
|
+
* goes through `resolveColumnName`.
|
|
161
|
+
*
|
|
162
|
+
* The other relation kinds have no local column at all: the foreign key lives
|
|
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.
|
|
165
|
+
*/
|
|
166
|
+
var resolveIndexableColumn = (collection, propKey, resolveColumnName, fail) => {
|
|
167
|
+
const relation = relationOf(collection, propKey);
|
|
168
|
+
if (relation) {
|
|
169
|
+
if (relation.kind === "belongsTo") return relation.localKey;
|
|
170
|
+
fail(`"${propKey}" is a ${relation.kind} relation, which has no column on this table — the foreign key lives on "${relation.targetSlug}". Declare the index there.`);
|
|
171
|
+
}
|
|
172
|
+
const property = collection.properties?.[propKey];
|
|
173
|
+
if (!property) fail(`"${propKey}" is not a property of this collection.`);
|
|
174
|
+
return resolveColumnName(propKey, property);
|
|
175
|
+
};
|
|
176
|
+
var resolvePredicate = (collection, predicate, resolveColumnName, fail) => {
|
|
177
|
+
if ("and" in predicate) return { and: predicate.and.map((p) => resolvePredicate(collection, p, resolveColumnName, fail)) };
|
|
178
|
+
const column = resolveIndexableColumn(collection, predicate.prop, resolveColumnName, fail);
|
|
179
|
+
switch (predicate.op) {
|
|
180
|
+
case "is null":
|
|
181
|
+
case "is not null": return {
|
|
182
|
+
column,
|
|
183
|
+
op: predicate.op
|
|
184
|
+
};
|
|
185
|
+
case "in":
|
|
186
|
+
if (new Set(predicate.value).size !== predicate.value.length) fail(`the \`in\` list for "${predicate.prop}" repeats a value, which changes nothing.`);
|
|
187
|
+
return {
|
|
188
|
+
column,
|
|
189
|
+
op: "in",
|
|
190
|
+
value: [...predicate.value]
|
|
191
|
+
};
|
|
192
|
+
default: return {
|
|
193
|
+
column,
|
|
194
|
+
op: predicate.op,
|
|
195
|
+
value: predicate.value
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/** The primary key columns of a collection, for the "you already have this" refusal. */
|
|
200
|
+
var primaryKeyColumns = (collection, resolveColumnName) => Object.entries(collection.properties ?? {}).filter(([, prop]) => prop && typeof prop === "object" && "isId" in prop && Boolean(prop.isId)).map(([key, prop]) => resolveColumnName(key, prop));
|
|
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(",");
|
|
216
|
+
const specs = [];
|
|
217
|
+
const byName = /* @__PURE__ */ new Map();
|
|
218
|
+
declared.forEach((index, position) => {
|
|
219
|
+
const fail = (message) => {
|
|
220
|
+
throw new CollectionIndexConfigError(slug, position, message);
|
|
221
|
+
};
|
|
222
|
+
if (typeof index.reason !== "string" || index.reason.trim() === "") fail("`reason` is required — see the doc comment. An index nobody can justify is one nobody can delete.");
|
|
223
|
+
if (!Array.isArray(index.on) || index.on.length === 0) fail("`on` must name at least one property.");
|
|
224
|
+
if (index.on.length > 5) fail(`\`on\` has ${index.on.length} keys; the limit is 5. Payload columns belong in \`include\`.`);
|
|
225
|
+
const method = index.using ?? "btree";
|
|
226
|
+
const unique = method === "btree" && Boolean(index.unique);
|
|
227
|
+
if (!isOrderedMethod(method)) {
|
|
228
|
+
for (const key of index.on) if (typeof key !== "string" && ("direction" in key || "nulls" in key)) fail(`access method "${method}" does not support ASC/DESC or NULLS options.`);
|
|
229
|
+
}
|
|
230
|
+
const keys = index.on.map((key) => {
|
|
231
|
+
const column = resolveIndexableColumn(collection, typeof key === "string" ? key : key.prop, resolveColumnName, fail);
|
|
232
|
+
const direction = (typeof key === "string" ? void 0 : key.direction) ?? "asc";
|
|
233
|
+
return {
|
|
234
|
+
column,
|
|
235
|
+
direction,
|
|
236
|
+
nulls: (typeof key === "string" ? void 0 : key.nulls) ?? (direction === "desc" ? "first" : "last")
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
const duplicateKey = keys.map((k) => k.column).find((c, i, all) => all.indexOf(c) !== i);
|
|
240
|
+
if (duplicateKey) fail(`"${duplicateKey}" appears twice in \`on\`.`);
|
|
241
|
+
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((propKey) => resolveIndexableColumn(collection, propKey, resolveColumnName, fail));
|
|
243
|
+
const overlap = include.find((c) => keys.some((k) => k.column === c));
|
|
244
|
+
if (overlap) fail(`"${overlap}" is in both \`on\` and \`include\`; Postgres rejects the overlap.`);
|
|
245
|
+
if (unique && keys.length === 1) {
|
|
246
|
+
const propKey = typeof index.on[0] === "string" ? index.on[0] : index.on[0].prop;
|
|
247
|
+
if ((collection.properties?.[propKey])?.validation?.unique) fail(`"${propKey}" already declares \`validation.unique\`, which compiles to an inline UNIQUE. Two declarations of one guarantee — remove one.`);
|
|
248
|
+
}
|
|
249
|
+
const predicate = index.where ? resolvePredicate(collection, index.where, resolveColumnName, fail) : null;
|
|
250
|
+
const withoutName = {
|
|
251
|
+
schema,
|
|
252
|
+
table,
|
|
253
|
+
method,
|
|
254
|
+
unique,
|
|
255
|
+
keys,
|
|
256
|
+
include,
|
|
257
|
+
predicate,
|
|
258
|
+
reason: index.reason
|
|
259
|
+
};
|
|
260
|
+
const indexName = deriveIndexName(withoutName);
|
|
261
|
+
const clash = byName.get(indexName);
|
|
262
|
+
if (clash !== void 0) fail(`derives the same name as indexes[${clash}] — they are the same index declared twice.`);
|
|
263
|
+
byName.set(indexName, position);
|
|
264
|
+
specs.push({
|
|
265
|
+
...withoutName,
|
|
266
|
+
indexName
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
return specs;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
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
|
+
* The stable order every consumer of a set of index specs uses.
|
|
282
|
+
*
|
|
283
|
+
* Exported because the boot-time diff reads the specs off the schema plan
|
|
284
|
+
* rather than rebuilding them, and it has to reach the same order the CLI's
|
|
285
|
+
* exclude list and `schema.sql` do — a second sort written out beside this one
|
|
286
|
+
* is a second order the moment either is edited.
|
|
287
|
+
*/
|
|
288
|
+
var sortIndexSpecs = (specs) => [...specs].sort((a, b) => a.schema.localeCompare(b.schema) || a.table.localeCompare(b.table) || a.indexName.localeCompare(b.indexName));
|
|
289
|
+
/**
|
|
290
|
+
* The `reason` a derived foreign-key index carries. Never part of the name —
|
|
291
|
+
* see {@link indexFingerprint} — so rewording it renames nothing.
|
|
292
|
+
*/
|
|
293
|
+
var FOREIGN_KEY_INDEX_REASON = "Derived for a foreign key: Postgres indexes the key a constraint points at, never the column holding it.";
|
|
294
|
+
/**
|
|
295
|
+
* Whether an index already serves an equality lookup on `column` alone.
|
|
296
|
+
*
|
|
297
|
+
* A btree whose *leading* key is the column does, unique or not — that is the
|
|
298
|
+
* prefix rule, and it is why a composite `(author_id, created_at)` makes a
|
|
299
|
+
* second index on `author_id` pure write amplification. A partial index does
|
|
300
|
+
* not: it serves only the rows its predicate admits, and a foreign-key lookup
|
|
301
|
+
* has to reach every row. Nor does GIN or BRIN, which answer different
|
|
302
|
+
* questions than "the rows whose key is one of these".
|
|
303
|
+
*/
|
|
304
|
+
var leadsWithColumn = (spec, column) => spec.method === "btree" && spec.predicate === null && spec.keys[0]?.column === column;
|
|
305
|
+
/**
|
|
306
|
+
* The btree a foreign-key column gets when nothing else already leads with it.
|
|
307
|
+
*
|
|
308
|
+
* Postgres creates the index a foreign key *references* (the target's primary
|
|
309
|
+
* key) and never the one on the column *holding* it. Every read from the other
|
|
310
|
+
* side of the link filters on that column — a `hasMany`/`hasOne` include, a
|
|
311
|
+
* nested listing (`/authors/5/posts`, page and count), the reverse side of a
|
|
312
|
+
* many-to-many — and so does the `ON DELETE` check when a target row goes. With
|
|
313
|
+
* no index each of those is a sequential scan of the child table: measured at
|
|
314
|
+
* 13 ms for 25 parents over 100k children, and about 250 ms per nested listing
|
|
315
|
+
* at a million.
|
|
316
|
+
*
|
|
317
|
+
* Named by {@link deriveIndexName} like every other index, so it is a
|
|
318
|
+
* Rebase-managed name (`_ix_<fingerprint>`), it is in the Atlas diff, and it
|
|
319
|
+
* is byte-for-byte the name an author's own plain index on the column would
|
|
320
|
+
* derive. That identity is what makes the derived index and a declared one the
|
|
321
|
+
* same object rather than two.
|
|
322
|
+
*/
|
|
323
|
+
var foreignKeyIndexSpec = (schema, table, column) => {
|
|
324
|
+
const withoutName = {
|
|
325
|
+
schema,
|
|
326
|
+
table,
|
|
327
|
+
method: "btree",
|
|
328
|
+
unique: false,
|
|
329
|
+
keys: [{
|
|
330
|
+
column,
|
|
331
|
+
direction: "asc",
|
|
332
|
+
nulls: "last"
|
|
333
|
+
}],
|
|
334
|
+
include: [],
|
|
335
|
+
predicate: null,
|
|
336
|
+
reason: FOREIGN_KEY_INDEX_REASON
|
|
337
|
+
};
|
|
338
|
+
return {
|
|
339
|
+
...withoutName,
|
|
340
|
+
indexName: deriveIndexName(withoutName),
|
|
341
|
+
derived: "foreign-key"
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/schema/atlas-exclude.ts
|
|
346
|
+
/**
|
|
347
|
+
* The names `db push` hands Atlas's `--exclude`, spelled so they match.
|
|
348
|
+
*
|
|
349
|
+
* An exclude is the only thing between `atlas schema apply --auto-approve` and
|
|
350
|
+
* an object Rebase does not own: a table no collection backs, a hand-written
|
|
351
|
+
* index, a CHECK constraint, the search and vector columns Rebase applies
|
|
352
|
+
* itself. Atlas reads each one as a glob split on `.`, so a name is not a
|
|
353
|
+
* pattern as it stands. Measured against the pinned 1.2.3:
|
|
354
|
+
*
|
|
355
|
+
* - a `.` in a name makes one more part, and Atlas refuses the whole command,
|
|
356
|
+
* `too many parts in pattern` — so every push fails on that database;
|
|
357
|
+
* - `[`, `]`, `*` and `?` are glob syntax. `[v1]` is a class matching `v` or
|
|
358
|
+
* `1`, so `idx[v1]` matches `idxv` and not the index called `idx[v1]`:
|
|
359
|
+
* nothing is excluded, nothing is reported, and Atlas plans the drop. For
|
|
360
|
+
* an index that drop is not gated, so it applied without a word.
|
|
361
|
+
*
|
|
362
|
+
* So each part is escaped on its own and the parts are joined: a `.` becomes
|
|
363
|
+
* `?`, which matches it (and any one character, so a pattern that also keeps a
|
|
364
|
+
* near-namesake errs on the side of keeping), and glob syntax is escaped with
|
|
365
|
+
* `\`, which Atlas reads as the literal.
|
|
366
|
+
*
|
|
367
|
+
* Code that reads these patterns back — the migration stripper, the generated
|
|
368
|
+
* column ownership check, the index ownership check — reads them with
|
|
369
|
+
* {@link excludePatternParts}, the exact inverse for a pattern built here.
|
|
370
|
+
*/
|
|
371
|
+
/** One part of an Atlas `--exclude` pattern that matches exactly this name. */
|
|
372
|
+
function atlasExcludeSegment(name) {
|
|
373
|
+
return name.replace(/[\\*?[\]]/g, (ch) => `\\${ch}`).replace(/\./g, "?");
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* The pattern that matches exactly the object these names qualify:
|
|
377
|
+
* `(schema, table)` for a table, `(schema, table, object)` for a column, an
|
|
378
|
+
* index or a constraint. Three parts for anything on a table: a two-part
|
|
379
|
+
* pattern reads as a table, matches nothing, and reports no error.
|
|
380
|
+
*/
|
|
381
|
+
function atlasExcludePattern(...parts) {
|
|
382
|
+
return parts.map(atlasExcludeSegment).join(".");
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The names a pattern from {@link atlasExcludePattern} was built from, or
|
|
386
|
+
* `undefined` for one that is not a plain name — a wildcard such as `auth.*`.
|
|
387
|
+
*
|
|
388
|
+
* Exact for every pattern built there: a `\` escapes the character after it,
|
|
389
|
+
* and an unescaped `?` can only be a dot.
|
|
390
|
+
*/
|
|
391
|
+
function excludePatternParts(pattern) {
|
|
392
|
+
const parts = [];
|
|
393
|
+
for (const segment of pattern.split(".")) {
|
|
394
|
+
let name = "";
|
|
395
|
+
for (let i = 0; i < segment.length; i++) {
|
|
396
|
+
const ch = segment[i];
|
|
397
|
+
if (ch === "\\" && i + 1 < segment.length) name += segment[++i];
|
|
398
|
+
else if (ch === "?") name += ".";
|
|
399
|
+
else if (ch === "*" || ch === "[" || ch === "]") return;
|
|
400
|
+
else name += ch;
|
|
401
|
+
}
|
|
402
|
+
parts.push(name);
|
|
403
|
+
}
|
|
404
|
+
return parts;
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/cli-output.ts
|
|
408
|
+
/**
|
|
409
|
+
* Terminal output for the `rebase db|schema|doctor` commands.
|
|
410
|
+
*
|
|
411
|
+
* These commands used to write every line through `logger`, and that is a
|
|
412
|
+
* category error with three separate consequences:
|
|
413
|
+
*
|
|
414
|
+
* - `logger` prefixes each line with its own level, so a box-drawn report
|
|
415
|
+
* arrived as `ℹ️ [INFO] ┌─ ✗ Missing Column ───` and the frame no longer
|
|
416
|
+
* lined up with anything;
|
|
417
|
+
* - `logger` is gated by `LOG_LEVEL`, which ships in the scaffold's own
|
|
418
|
+
* `.env.example` — a developer who quietened their dev server with
|
|
419
|
+
* `LOG_LEVEL=warn` got a `rebase db push` that printed almost nothing and
|
|
420
|
+
* still exited non-zero, indistinguishable from a crash;
|
|
421
|
+
* - under `NODE_ENV=production` `logger` emits JSON, so the whole report
|
|
422
|
+
* became log records with the chalk escape codes embedded in them.
|
|
423
|
+
*
|
|
424
|
+
* A CLI's report *is* its return value. It goes to the terminal unconditionally
|
|
425
|
+
* and unadorned. `packages/cli` has always written its output this way; this is
|
|
426
|
+
* the same three functions for the plugin CLI that `rebase` delegates to.
|
|
427
|
+
*
|
|
428
|
+
* `logger` still belongs in this package's *runtime* — a request handler has no
|
|
429
|
+
* terminal and its lines want levels, timestamps and redaction. The rule is the
|
|
430
|
+
* caller, not the severity: anything a developer reads because they typed a
|
|
431
|
+
* command goes here, anything a server emits while running goes to `logger`.
|
|
432
|
+
*
|
|
433
|
+
* Errors and warnings go to stderr so `rebase db push > plan.txt` keeps the
|
|
434
|
+
* diagnosis on the terminal where it is readable.
|
|
435
|
+
*/
|
|
436
|
+
/** One line of human-facing output on stdout. */
|
|
437
|
+
var out = (line = "") => {
|
|
438
|
+
console.log(line);
|
|
439
|
+
};
|
|
440
|
+
/** One line of human-facing warning output on stderr. */
|
|
441
|
+
var outWarn = (line = "") => {
|
|
442
|
+
console.warn(line);
|
|
443
|
+
};
|
|
444
|
+
/** One line of human-facing error output on stderr. */
|
|
445
|
+
var outError = (line = "") => {
|
|
446
|
+
console.error(line);
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Whether a failure should be printed with its stack — `rebase --debug`, which
|
|
450
|
+
* the launcher passes down as `REBASE_DEBUG`, or `REBASE_DEBUG` set by hand.
|
|
451
|
+
*/
|
|
452
|
+
var wantsStack = () => parseEnvBoolean(process.env.REBASE_DEBUG) === true;
|
|
453
|
+
/**
|
|
454
|
+
* An error as a person reads it: its message, and its stack only under
|
|
455
|
+
* `--debug`.
|
|
456
|
+
*
|
|
457
|
+
* The rule `rebase` itself follows (`bin/rebase.js`). These commands run in a
|
|
458
|
+
* child process the launcher's handler never sees, so a syntax error in a
|
|
459
|
+
* collection file reached the terminal as `Doctor failed CollectionConfigError:`
|
|
460
|
+
* followed by twenty frames of loader internals, under a sentence that already
|
|
461
|
+
* said which file and which line.
|
|
462
|
+
*/
|
|
463
|
+
var describeFailure = (error) => {
|
|
464
|
+
if (!(error instanceof Error)) return String(error);
|
|
465
|
+
if (wantsStack() && error.stack) return error.stack;
|
|
466
|
+
return `${error.message}\n Re-run with --debug for the stack trace.`;
|
|
467
|
+
};
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
470
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
471
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
472
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
|
|
473
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
474
|
+
var styles$1 = {
|
|
475
|
+
modifier: {
|
|
476
|
+
reset: [0, 0],
|
|
477
|
+
bold: [1, 22],
|
|
478
|
+
dim: [2, 22],
|
|
479
|
+
italic: [3, 23],
|
|
480
|
+
underline: [4, 24],
|
|
481
|
+
overline: [53, 55],
|
|
482
|
+
inverse: [7, 27],
|
|
483
|
+
hidden: [8, 28],
|
|
484
|
+
strikethrough: [9, 29]
|
|
485
|
+
},
|
|
486
|
+
color: {
|
|
487
|
+
black: [30, 39],
|
|
488
|
+
red: [31, 39],
|
|
489
|
+
green: [32, 39],
|
|
490
|
+
yellow: [33, 39],
|
|
491
|
+
blue: [34, 39],
|
|
492
|
+
magenta: [35, 39],
|
|
493
|
+
cyan: [36, 39],
|
|
494
|
+
white: [37, 39],
|
|
495
|
+
blackBright: [90, 39],
|
|
496
|
+
gray: [90, 39],
|
|
497
|
+
grey: [90, 39],
|
|
498
|
+
redBright: [91, 39],
|
|
499
|
+
greenBright: [92, 39],
|
|
500
|
+
yellowBright: [93, 39],
|
|
501
|
+
blueBright: [94, 39],
|
|
502
|
+
magentaBright: [95, 39],
|
|
503
|
+
cyanBright: [96, 39],
|
|
504
|
+
whiteBright: [97, 39]
|
|
505
|
+
},
|
|
506
|
+
bgColor: {
|
|
507
|
+
bgBlack: [40, 49],
|
|
508
|
+
bgRed: [41, 49],
|
|
509
|
+
bgGreen: [42, 49],
|
|
510
|
+
bgYellow: [43, 49],
|
|
511
|
+
bgBlue: [44, 49],
|
|
512
|
+
bgMagenta: [45, 49],
|
|
513
|
+
bgCyan: [46, 49],
|
|
514
|
+
bgWhite: [47, 49],
|
|
515
|
+
bgBlackBright: [100, 49],
|
|
516
|
+
bgGray: [100, 49],
|
|
517
|
+
bgGrey: [100, 49],
|
|
518
|
+
bgRedBright: [101, 49],
|
|
519
|
+
bgGreenBright: [102, 49],
|
|
520
|
+
bgYellowBright: [103, 49],
|
|
521
|
+
bgBlueBright: [104, 49],
|
|
522
|
+
bgMagentaBright: [105, 49],
|
|
523
|
+
bgCyanBright: [106, 49],
|
|
524
|
+
bgWhiteBright: [107, 49]
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
Object.keys(styles$1.modifier);
|
|
528
|
+
var foregroundColorNames = Object.keys(styles$1.color);
|
|
529
|
+
var backgroundColorNames = Object.keys(styles$1.bgColor);
|
|
530
|
+
[...foregroundColorNames, ...backgroundColorNames];
|
|
531
|
+
function assembleStyles() {
|
|
532
|
+
const codes = /* @__PURE__ */ new Map();
|
|
533
|
+
for (const [groupName, group] of Object.entries(styles$1)) {
|
|
534
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
535
|
+
styles$1[styleName] = {
|
|
536
|
+
open: `\u001B[${style[0]}m`,
|
|
537
|
+
close: `\u001B[${style[1]}m`
|
|
538
|
+
};
|
|
539
|
+
group[styleName] = styles$1[styleName];
|
|
540
|
+
codes.set(style[0], style[1]);
|
|
541
|
+
}
|
|
542
|
+
Object.defineProperty(styles$1, groupName, {
|
|
543
|
+
value: group,
|
|
544
|
+
enumerable: false
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
Object.defineProperty(styles$1, "codes", {
|
|
548
|
+
value: codes,
|
|
549
|
+
enumerable: false
|
|
550
|
+
});
|
|
551
|
+
styles$1.color.close = "\x1B[39m";
|
|
552
|
+
styles$1.bgColor.close = "\x1B[49m";
|
|
553
|
+
styles$1.color.ansi = wrapAnsi16();
|
|
554
|
+
styles$1.color.ansi256 = wrapAnsi256();
|
|
555
|
+
styles$1.color.ansi16m = wrapAnsi16m();
|
|
556
|
+
styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
557
|
+
styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
558
|
+
styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
559
|
+
Object.defineProperties(styles$1, {
|
|
560
|
+
rgbToAnsi256: {
|
|
561
|
+
value(red, green, blue) {
|
|
562
|
+
if (red === green && green === blue) {
|
|
563
|
+
if (red < 8) return 16;
|
|
564
|
+
if (red > 248) return 231;
|
|
565
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
566
|
+
}
|
|
567
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
568
|
+
},
|
|
569
|
+
enumerable: false
|
|
570
|
+
},
|
|
571
|
+
hexToRgb: {
|
|
572
|
+
value(hex) {
|
|
573
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
574
|
+
if (!matches) return [
|
|
575
|
+
0,
|
|
576
|
+
0,
|
|
577
|
+
0
|
|
578
|
+
];
|
|
579
|
+
let [colorString] = matches;
|
|
580
|
+
if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
|
|
581
|
+
const integer = Number.parseInt(colorString, 16);
|
|
582
|
+
return [
|
|
583
|
+
integer >> 16 & 255,
|
|
584
|
+
integer >> 8 & 255,
|
|
585
|
+
integer & 255
|
|
586
|
+
];
|
|
587
|
+
},
|
|
588
|
+
enumerable: false
|
|
589
|
+
},
|
|
590
|
+
hexToAnsi256: {
|
|
591
|
+
value: (hex) => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
|
|
592
|
+
enumerable: false
|
|
593
|
+
},
|
|
594
|
+
ansi256ToAnsi: {
|
|
595
|
+
value(code) {
|
|
596
|
+
if (code < 8) return 30 + code;
|
|
597
|
+
if (code < 16) return 90 + (code - 8);
|
|
598
|
+
let red;
|
|
599
|
+
let green;
|
|
600
|
+
let blue;
|
|
601
|
+
if (code >= 232) {
|
|
602
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
603
|
+
green = red;
|
|
604
|
+
blue = red;
|
|
605
|
+
} else {
|
|
606
|
+
code -= 16;
|
|
607
|
+
const remainder = code % 36;
|
|
608
|
+
red = Math.floor(code / 36) / 5;
|
|
609
|
+
green = Math.floor(remainder / 6) / 5;
|
|
610
|
+
blue = remainder % 6 / 5;
|
|
611
|
+
}
|
|
612
|
+
const value = Math.max(red, green, blue) * 2;
|
|
613
|
+
if (value === 0) return 30;
|
|
614
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
615
|
+
if (value === 2) result += 60;
|
|
616
|
+
return result;
|
|
617
|
+
},
|
|
618
|
+
enumerable: false
|
|
619
|
+
},
|
|
620
|
+
rgbToAnsi: {
|
|
621
|
+
value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
|
|
622
|
+
enumerable: false
|
|
623
|
+
},
|
|
624
|
+
hexToAnsi: {
|
|
625
|
+
value: (hex) => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
|
|
626
|
+
enumerable: false
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return styles$1;
|
|
630
|
+
}
|
|
631
|
+
var ansiStyles = assembleStyles();
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
634
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
|
|
635
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
636
|
+
const position = argv.indexOf(prefix + flag);
|
|
637
|
+
const terminatorPosition = argv.indexOf("--");
|
|
638
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
639
|
+
}
|
|
640
|
+
var { env } = process$1;
|
|
641
|
+
var flagForceColor;
|
|
642
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
|
|
643
|
+
else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
|
|
644
|
+
function envForceColor() {
|
|
645
|
+
if ("FORCE_COLOR" in env) {
|
|
646
|
+
if (env.FORCE_COLOR === "true") return 1;
|
|
647
|
+
if (env.FORCE_COLOR === "false") return 0;
|
|
648
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
function translateLevel(level) {
|
|
652
|
+
if (level === 0) return false;
|
|
653
|
+
return {
|
|
654
|
+
level,
|
|
655
|
+
hasBasic: true,
|
|
656
|
+
has256: level >= 2,
|
|
657
|
+
has16m: level >= 3
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
661
|
+
const noFlagForceColor = envForceColor();
|
|
662
|
+
if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
|
|
663
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
664
|
+
if (forceColor === 0) return 0;
|
|
665
|
+
if (sniffFlags) {
|
|
666
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
|
|
667
|
+
if (hasFlag("color=256")) return 2;
|
|
668
|
+
}
|
|
669
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
|
|
670
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
|
|
671
|
+
const min = forceColor || 0;
|
|
672
|
+
if (env.TERM === "dumb") return min;
|
|
673
|
+
if (process$1.platform === "win32") {
|
|
674
|
+
const osRelease = os.release().split(".");
|
|
675
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
676
|
+
return 1;
|
|
677
|
+
}
|
|
678
|
+
if ("CI" in env) {
|
|
679
|
+
if ([
|
|
680
|
+
"GITHUB_ACTIONS",
|
|
681
|
+
"GITEA_ACTIONS",
|
|
682
|
+
"CIRCLECI"
|
|
683
|
+
].some((key) => key in env)) return 3;
|
|
684
|
+
if ([
|
|
685
|
+
"TRAVIS",
|
|
686
|
+
"APPVEYOR",
|
|
687
|
+
"GITLAB_CI",
|
|
688
|
+
"BUILDKITE",
|
|
689
|
+
"DRONE"
|
|
690
|
+
].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
|
|
691
|
+
return min;
|
|
692
|
+
}
|
|
693
|
+
if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
694
|
+
if (env.COLORTERM === "truecolor") return 3;
|
|
695
|
+
if (env.TERM === "xterm-kitty") return 3;
|
|
696
|
+
if (env.TERM === "xterm-ghostty") return 3;
|
|
697
|
+
if (env.TERM === "wezterm") return 3;
|
|
698
|
+
if ("TERM_PROGRAM" in env) {
|
|
699
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
700
|
+
switch (env.TERM_PROGRAM) {
|
|
701
|
+
case "iTerm.app": return version >= 3 ? 3 : 2;
|
|
702
|
+
case "Apple_Terminal": return 2;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (/-256(color)?$/i.test(env.TERM)) return 2;
|
|
706
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
|
|
707
|
+
if ("COLORTERM" in env) return 1;
|
|
708
|
+
return min;
|
|
709
|
+
}
|
|
710
|
+
function createSupportsColor(stream, options = {}) {
|
|
711
|
+
return translateLevel(_supportsColor(stream, {
|
|
712
|
+
streamIsTTY: stream && stream.isTTY,
|
|
713
|
+
...options
|
|
714
|
+
}));
|
|
715
|
+
}
|
|
716
|
+
var supportsColor = {
|
|
717
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
718
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
719
|
+
};
|
|
720
|
+
//#endregion
|
|
721
|
+
//#region ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
722
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
723
|
+
let index = string.indexOf(substring);
|
|
724
|
+
if (index === -1) return string;
|
|
725
|
+
const substringLength = substring.length;
|
|
726
|
+
let endIndex = 0;
|
|
727
|
+
let returnValue = "";
|
|
728
|
+
do {
|
|
729
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
730
|
+
endIndex = index + substringLength;
|
|
731
|
+
index = string.indexOf(substring, endIndex);
|
|
732
|
+
} while (index !== -1);
|
|
733
|
+
returnValue += string.slice(endIndex);
|
|
734
|
+
return returnValue;
|
|
735
|
+
}
|
|
736
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
737
|
+
let endIndex = 0;
|
|
738
|
+
let returnValue = "";
|
|
739
|
+
do {
|
|
740
|
+
const gotCR = string[index - 1] === "\r";
|
|
741
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
742
|
+
endIndex = index + 1;
|
|
743
|
+
index = string.indexOf("\n", endIndex);
|
|
744
|
+
} while (index !== -1);
|
|
745
|
+
returnValue += string.slice(endIndex);
|
|
746
|
+
return returnValue;
|
|
747
|
+
}
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
750
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
|
|
751
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
752
|
+
var STYLER = Symbol("STYLER");
|
|
753
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
754
|
+
var levelMapping = [
|
|
755
|
+
"ansi",
|
|
756
|
+
"ansi",
|
|
757
|
+
"ansi256",
|
|
758
|
+
"ansi16m"
|
|
759
|
+
];
|
|
760
|
+
var styles = Object.create(null);
|
|
761
|
+
var applyOptions = (object, options = {}) => {
|
|
762
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error("The `level` option should be an integer from 0 to 3");
|
|
763
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
764
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
765
|
+
};
|
|
766
|
+
var chalkFactory = (options) => {
|
|
767
|
+
const chalk = (...strings) => strings.join(" ");
|
|
768
|
+
applyOptions(chalk, options);
|
|
769
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
770
|
+
return chalk;
|
|
771
|
+
};
|
|
772
|
+
function createChalk(options) {
|
|
773
|
+
return chalkFactory(options);
|
|
774
|
+
}
|
|
775
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
776
|
+
for (const [styleName, style] of Object.entries(ansiStyles)) styles[styleName] = { get() {
|
|
777
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
778
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
779
|
+
return builder;
|
|
780
|
+
} };
|
|
781
|
+
styles.visible = { get() {
|
|
782
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
783
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
784
|
+
return builder;
|
|
785
|
+
} };
|
|
786
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
787
|
+
if (model === "rgb") {
|
|
788
|
+
if (level === "ansi16m") return ansiStyles[type].ansi16m(...arguments_);
|
|
789
|
+
if (level === "ansi256") return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
|
|
790
|
+
return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
|
|
791
|
+
}
|
|
792
|
+
if (model === "hex") return getModelAnsi("rgb", level, type, ...ansiStyles.hexToRgb(...arguments_));
|
|
793
|
+
return ansiStyles[type][model](...arguments_);
|
|
794
|
+
};
|
|
795
|
+
for (const model of [
|
|
796
|
+
"rgb",
|
|
797
|
+
"hex",
|
|
798
|
+
"ansi256"
|
|
799
|
+
]) {
|
|
800
|
+
styles[model] = { get() {
|
|
801
|
+
const { level } = this;
|
|
802
|
+
return function(...arguments_) {
|
|
803
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansiStyles.color.close, this[STYLER]);
|
|
804
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
805
|
+
};
|
|
806
|
+
} };
|
|
807
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
808
|
+
styles[bgModel] = { get() {
|
|
809
|
+
const { level } = this;
|
|
810
|
+
return function(...arguments_) {
|
|
811
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
|
|
812
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
813
|
+
};
|
|
814
|
+
} };
|
|
815
|
+
}
|
|
816
|
+
var proto = Object.defineProperties(() => {}, {
|
|
817
|
+
...styles,
|
|
818
|
+
level: {
|
|
819
|
+
enumerable: true,
|
|
820
|
+
get() {
|
|
821
|
+
return this[GENERATOR].level;
|
|
822
|
+
},
|
|
823
|
+
set(level) {
|
|
824
|
+
this[GENERATOR].level = level;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
var createStyler = (open, close, parent) => {
|
|
829
|
+
let openAll;
|
|
830
|
+
let closeAll;
|
|
831
|
+
if (parent === void 0) {
|
|
832
|
+
openAll = open;
|
|
833
|
+
closeAll = close;
|
|
834
|
+
} else {
|
|
835
|
+
openAll = parent.openAll + open;
|
|
836
|
+
closeAll = close + parent.closeAll;
|
|
837
|
+
}
|
|
838
|
+
return {
|
|
839
|
+
open,
|
|
840
|
+
close,
|
|
841
|
+
openAll,
|
|
842
|
+
closeAll,
|
|
843
|
+
parent
|
|
844
|
+
};
|
|
845
|
+
};
|
|
846
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
847
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
848
|
+
Object.setPrototypeOf(builder, proto);
|
|
849
|
+
builder[GENERATOR] = self;
|
|
850
|
+
builder[STYLER] = _styler;
|
|
851
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
852
|
+
return builder;
|
|
853
|
+
};
|
|
854
|
+
var applyStyle = (self, string) => {
|
|
855
|
+
if (self.level <= 0 || !string) return self[IS_EMPTY] ? "" : string;
|
|
856
|
+
let styler = self[STYLER];
|
|
857
|
+
if (styler === void 0) return string;
|
|
858
|
+
const { openAll, closeAll } = styler;
|
|
859
|
+
if (string.includes("\x1B")) while (styler !== void 0) {
|
|
860
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
861
|
+
styler = styler.parent;
|
|
862
|
+
}
|
|
863
|
+
const lfIndex = string.indexOf("\n");
|
|
864
|
+
if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
865
|
+
return openAll + string + closeAll;
|
|
866
|
+
};
|
|
867
|
+
Object.defineProperties(createChalk.prototype, styles);
|
|
868
|
+
var chalk = createChalk();
|
|
869
|
+
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
870
|
+
//#endregion
|
|
871
|
+
export { sortIndexSpecs as _, outWarn as a, buildCollectionIndexSpecs as c, collection_index_exports as d, deriveIndexName as f, renderPredicate as g, leadsWithColumn as h, outError as i, collectionIndexStatement as l, isRebaseIndexName as m, describeFailure as n, atlasExcludePattern as o, foreignKeyIndexSpec as p, out as r, excludePatternParts as s, chalk as t, collectionIndexStatements as u };
|
|
872
|
+
|
|
873
|
+
//# sourceMappingURL=source-DB6xJv3p.js.map
|