qubu 0.6.1 → 0.6.3
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/dist/{complete-DP7pliuY.mjs → canonical-B5_ouh-c.mjs} +466 -241
- package/dist/codegen.d.mts +2 -2
- package/dist/codegen.mjs +180 -90
- package/dist/column-Cyc2CMnG.mjs +116 -0
- package/dist/column-DDRvD7SF.mjs +721 -0
- package/dist/{constraints-DM_tarXc.mjs → constraints-CAmi18Uk.mjs} +8 -3
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +4 -4
- package/dist/diff.d.mts +9 -9
- package/dist/diff.mjs +152 -102
- package/dist/{explain-CkIK13L_.mjs → explain-BIqEmZha.mjs} +1 -1
- package/dist/{expressions-BCjc08zw.mjs → expressions-_6JF_J77.mjs} +2 -1
- package/dist/index-CaxrMD1A.d.mts +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +368 -74
- package/dist/introspection/mysql.d.mts +1 -1
- package/dist/introspection/mysql.mjs +156 -23
- package/dist/introspection/postgres.d.mts +6 -3
- package/dist/introspection/postgres.mjs +388 -53
- package/dist/introspection/sqlite.d.mts +1 -1
- package/dist/introspection/sqlite.mjs +198 -12
- package/dist/introspection.d.mts +26 -12
- package/dist/introspection.mjs +2 -672
- package/dist/mysql.d.mts +3 -3
- package/dist/mysql.mjs +6 -5
- package/dist/{errors-Dxv73YJu.mjs → omit-VEr9Ydux.mjs} +5 -1
- package/dist/{on-conflict-CnaY5qso.mjs → on-conflict-B2rFyHGF.mjs} +6 -8
- package/dist/on-duplicate-key-update-Czsw1Yq-.mjs +95 -0
- package/dist/{postgres-Dey7QXPL.mjs → postgres-hFhd0I9n.mjs} +4 -5
- package/dist/postgres.d.mts +2 -2
- package/dist/postgres.mjs +2 -2
- package/dist/{registry-oWDiqD7i.mjs → registry-BXE_4M9P.mjs} +1 -1
- package/dist/{relational-DSAJ-l58.mjs → relational-CoPBETjI.mjs} +3 -2
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +8 -8
- package/dist/{serialize-CE-gw5_s.mjs → serialize-CyobNEx-.mjs} +174 -30
- package/dist/serialize-Du2UPZMt.d.mts +92 -0
- package/dist/snapshot/mysql.d.mts +5 -5
- package/dist/snapshot/mysql.mjs +8 -8
- package/dist/snapshot/postgres.d.mts +3 -3
- package/dist/snapshot/postgres.mjs +9 -9
- package/dist/snapshot/sqlite.d.mts +3 -3
- package/dist/snapshot/sqlite.mjs +7 -7
- package/dist/snapshot-mIb-Zzb5.mjs +1489 -0
- package/dist/snapshot.d.mts +4 -5
- package/dist/snapshot.mjs +3 -4
- package/dist/{source-BDuUXmAk.mjs → source-DYSUqzvb.mjs} +2 -2
- package/dist/sqlite.d.mts +2 -2
- package/dist/sqlite.mjs +6 -6
- package/dist/{table-C1QGNe4P.mjs → table-B8zEq0az.mjs} +4 -4
- package/dist/{types-BLNRatG_.mjs → types-CYHpSPwj.mjs} +10 -5
- package/dist/{types-BEn0N_al.d.mts → types-CiMvKi5V.d.mts} +14 -4
- package/dist/{types-DUe6eeI0.d.mts → types-Dqr4o2I1.d.mts} +590 -168
- package/dist/value-CpaUFtjw.mjs +45 -0
- package/dist/vite/ambient.d.ts +2 -0
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +2 -0
- package/docs/dialects-and-execution.md +105 -26
- package/docs/getting-started.md +10 -10
- package/docs/guides/better-auth.md +16 -5
- package/docs/guides/compose-queries.md +21 -9
- package/docs/guides/drizzle.md +8 -3
- package/docs/guides/extensions/dialects.md +1 -1
- package/docs/guides/extensions/overview.md +1 -1
- package/docs/guides/extensions/sources-and-clauses.md +7 -3
- package/docs/guides/extensions/typed-expressions.md +26 -12
- package/docs/guides/extensions/unsafe-syntax.md +10 -6
- package/docs/guides/json.md +126 -8
- package/docs/guides/mutations.md +51 -6
- package/docs/guides/select/conditions.md +18 -11
- package/docs/guides/select/grouping-and-windows.md +5 -2
- package/docs/guides/select/ordering-and-pagination.md +5 -3
- package/docs/guides/select/overview.md +6 -3
- package/docs/guides/sql-templates.md +11 -5
- package/docs/guides/valtio-sync.md +11 -5
- package/docs/guides/vite-plugin.md +2 -2
- package/docs/index.md +25 -18
- package/docs/migrations/adapters.md +92 -27
- package/docs/migrations/artifacts-and-policy.md +49 -20
- package/docs/migrations/index.md +15 -8
- package/docs/migrations/lotta-adoption.md +16 -5
- package/docs/migrations/operations.md +29 -15
- package/docs/migrations/recovery.md +40 -17
- package/docs/query-model/fragments.md +33 -5
- package/docs/query-model/result-shapes.md +2 -2
- package/docs/query-model/source-scope.md +5 -3
- package/docs/reference/introspection-support.md +42 -37
- package/docs/reference/mysql-snapshot.md +19 -4
- package/docs/reference/postgres-snapshot.md +17 -4
- package/docs/reference/sqlite-snapshot.md +19 -2
- package/docs/reference/supported-surface.md +221 -84
- package/docs/schema/catalog-model.md +44 -14
- package/docs/schema/code-generation.md +40 -21
- package/docs/schema/columns-and-writes.md +21 -11
- package/docs/schema/constraints-and-indexes.md +12 -5
- package/docs/schema/ddl-emission.md +16 -5
- package/docs/schema/diff.md +13 -5
- package/docs/schema/introspection.md +64 -31
- package/docs/schema/migration-plans.md +18 -10
- package/docs/schema/snapshots.md +68 -30
- package/docs/schema/storage-and-schema-sql.md +16 -5
- package/docs/schema/tables-and-names.md +1 -1
- package/docs/sql-semantic-types.md +11 -8
- package/docs/troubleshooting.md +14 -6
- package/package.json +2 -1
- package/dist/canonical-DMvR9yBe.mjs +0 -972
- package/dist/column-BzN8KFJa.mjs +0 -364
- package/dist/column-CFvSbil0.mjs +0 -309
- package/dist/complete-types-CNMWBWap.d.mts +0 -371
- package/dist/index-CGui70hi.d.mts +0 -32
- package/dist/json-Db7XRD91.mjs +0 -169
- package/dist/omit-OxV58AwX.mjs +0 -5
- package/dist/serialize-OvXCLzjm.d.mts +0 -66
- package/dist/snapshot-DgsOhf_8.mjs +0 -354
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as unsafeSchemaSql } from "./expressions-
|
|
1
|
+
import { g as freezeSchemaMetadata, h as dialectMismatchDiagnostic, r as isColumnReference } from "./column-DDRvD7SF.mjs";
|
|
2
|
+
import { c as unsafeSchemaSql } from "./expressions-_6JF_J77.mjs";
|
|
3
3
|
//#region src/schema/indexes.ts
|
|
4
4
|
/**
|
|
5
5
|
* Validate portable and dialect-owned index facts for one target adapter. Unsupported features are
|
|
@@ -35,7 +35,7 @@ function validateIndexDialect(indexMetadata, dialect, path = ["index"]) {
|
|
|
35
35
|
/** Declare a portable column or expression index. */
|
|
36
36
|
function index(terms, options) {
|
|
37
37
|
const resolvedOptions = options ?? {};
|
|
38
|
-
const candidateKey = resolvedOptions.unique === true && resolvedOptions.where === void 0 && terms.every((term) => {
|
|
38
|
+
const candidateKey = resolvedOptions.unique === true && resolvedOptions.where === void 0 && resolvedOptions.termOptions === void 0 && terms.every((term) => {
|
|
39
39
|
return ("orderKind" in term ? term.expression : term).expressionKind === "column";
|
|
40
40
|
});
|
|
41
41
|
return Object.freeze({
|
|
@@ -46,6 +46,9 @@ function index(terms, options) {
|
|
|
46
46
|
...resolvedOptions.include !== void 0 ? { includedColumns: Object.freeze([...resolvedOptions.include]) } : {},
|
|
47
47
|
...resolvedOptions.physicalName !== void 0 ? { physicalName: resolvedOptions.physicalName } : {},
|
|
48
48
|
...resolvedOptions.dialect !== void 0 ? { dialect: freezeSchemaMetadata(resolvedOptions.dialect) } : {},
|
|
49
|
+
...resolvedOptions.method === void 0 ? {} : { method: resolvedOptions.method },
|
|
50
|
+
...resolvedOptions.backingConstraint === void 0 ? {} : { backingConstraint: resolvedOptions.backingConstraint },
|
|
51
|
+
...resolvedOptions.termOptions === void 0 ? {} : { termOptions: Object.freeze(resolvedOptions.termOptions.map((term) => term === void 0 ? void 0 : Object.freeze({ ...term }))) },
|
|
49
52
|
candidateKey
|
|
50
53
|
});
|
|
51
54
|
}
|
|
@@ -195,6 +198,8 @@ function freezeConstraint(kind, columns, options, extra) {
|
|
|
195
198
|
else if (kind === "unique-constraint") value.nulls = extra;
|
|
196
199
|
if (optionValues?.physicalName !== void 0) value.physicalName = optionValues.physicalName;
|
|
197
200
|
if (optionValues?.dialect !== void 0) value.dialect = freezeSchemaMetadata(optionValues.dialect);
|
|
201
|
+
if (optionValues?.validated !== void 0) value.validated = optionValues.validated;
|
|
202
|
+
if ((kind === "primary-key" || kind === "unique" || kind === "unique-constraint") && optionValues?.backingIndex !== void 0) value.backingIndex = optionValues.backingIndex;
|
|
198
203
|
if (optionValues?.deferrable !== void 0) value.deferrable = optionValues.deferrable;
|
|
199
204
|
if (optionValues?.initially !== void 0) value.initially = optionValues.initially;
|
|
200
205
|
if (kind === "foreign-key") {
|
package/dist/core.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $d as isFragment, $t as assertDialectCapability, Ad as MetadataOf, Ao as SelectClause, Bd as RenderFunction, Bs as typedCast, Bt as DialectPagination, Cd as GroupingKeysOf, Dd as HasWindow, Du as RenderOptions, Ed as HasSubquery, Eu as RenderCapabilityValidation, Fd as ProvidesOuterOf, Ft as DialectCapability, Gd as RequiresOuterSourceMeta, Gt as NamedCastTarget, Hd as RequiresOf, Ht as ExplainFormat, Id as ProvidesOuterSourceMeta, Is as typedValue, It as DialectCastTypes, Iu as expressionFragment, Jd as SqlTypeOf, Jt as PortableCastTarget, Ju as isExpression, Kd as RequiresSourceMeta, Kt as PaginationKind, Ld as ProvidesSourceMeta, Lt as DialectExplain, Md as NullableSourceMeta, Nd as NullableSourcesOf, Nt as CastTarget, Od as InheritedMetadata, Ou as RenderedQuery, Pd as OutputOf, Pt as Dialect, Qd as fragment, Qo as typedCall, Qt as SchemaLiteralRenderer, Rd as QueryCardinality, Rt as DialectJson, Sd as GroupingDependenciesOf, Sf as SqlUuid, Td as HasAggregate, Ud as RequiresOuterMetadataOf, Ut as ExplainRenderOptions, Vd as RequiresCapabilityMeta, Vt as DialectRowLocking, Wd as RequiresOuterOf, Wt as JsonScalarKind, Xd as VisibleDependenciesOf, Xt as RowLockMode, Xu as markExpressionCategory, Yd as SubqueryMeta, Yt as PortableCastType, Yu as makeExpression, Zd as WindowMeta, Zt as RowLockWaitPolicy, Zu as withDialectCapability, _d as CardinalityOf, _f as SqlTextLike, af as SqlBoolean, bd as Fragment, bf as SqlTypeSatisfies, cf as SqlEqualityComparable, dd as AggregateDependenciesOf, df as SqlJson, ef as parenthesize, en as createDialect, fd as AggregateMeta, ff as SqlNumericLike, gd as CardinalityMeta, gf as SqlText, hd as CapabilityMetadataOf, hf as SqlSemanticType, if as SqlBinary, jd as NullabilityOf, kd as InheritedMetadataOf, ko as ClausePlacement, ku as render, ld as resultValue, lf as SqlEqualityCompatible, md as CapabilitiesOf, mf as SqlOrderable, nf as AnySqlType, nn as resolveCastTarget, of as SqlDate, pd as AnyFragment, pf as SqlOrderCompatible, qd as ResultMeta, qt as PaginationPart, rf as SqlBigInt, sf as SqlDecimal, tf as sequence, tn as extendDialect, uf as SqlInteger, vd as DependenciesOf, vf as SqlTimestamp, wd as GroupingMeta, xd as FragmentMeta, xf as SqlUnknown, yd as ExpressionMeta, yf as SqlTypeName, zd as RenderContext, zt as DialectOptions, zu as Expression } from "./types-Dqr4o2I1.mjs";
|
|
2
2
|
//#region src/core/primitives/compose.d.ts
|
|
3
3
|
declare function commaSeparated<const TParts extends readonly AnyFragment[]>(parts: TParts): Fragment<InheritedMetadata<TParts[number]>>;
|
|
4
4
|
declare function keyword<TPart extends AnyFragment | undefined>(value: string, part?: TPart): Fragment<TPart extends AnyFragment ? InheritedMetadata<TPart> : never>;
|
|
@@ -8,7 +8,7 @@ declare function identifier(name: string): Fragment<never>;
|
|
|
8
8
|
declare function qualifiedIdentifier(...parts: readonly string[]): Fragment<never>;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/core/primitives/parameter.d.ts
|
|
11
|
-
declare function parameter<T>(_value: T): Fragment<never>;
|
|
11
|
+
declare function parameter<T>(_value: T, sqlType?: SqlTypeName): Fragment<never>;
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/core/primitives/routine.d.ts
|
|
14
14
|
/** Render a validated, unquoted SQL routine name such as `LOWER` or `app.fn`. */
|
|
@@ -30,4 +30,4 @@ declare function customClause<TMetadata = never>(options: {
|
|
|
30
30
|
readonly render: (context: RenderContext) => void;
|
|
31
31
|
}): SelectClause<TMetadata>;
|
|
32
32
|
//#endregion
|
|
33
|
-
export { AggregateDependenciesOf, AggregateMeta, AnyFragment, AnySqlType, CapabilitiesOf, CapabilityMetadataOf, CardinalityMeta, CardinalityOf, CastTarget, DependenciesOf, Dialect, DialectCapability, DialectCastTypes, DialectExplain, DialectJson, DialectOptions, DialectPagination, DialectRowLocking, ExplainFormat, ExplainRenderOptions, ExpressionMeta, Fragment, FragmentMeta, GroupingDependenciesOf, GroupingKeysOf, GroupingMeta, HasAggregate, HasSubquery, HasWindow, InheritedMetadata, InheritedMetadataOf, JsonScalarKind, MetadataOf, NamedCastTarget, NullabilityOf, NullableSourceMeta, NullableSourcesOf, OutputOf, PaginationKind, PaginationPart, PortableCastTarget, PortableCastType, ProvidesOuterOf, ProvidesOuterSourceMeta, ProvidesSourceMeta, QueryCardinality, RenderCapabilityValidation, RenderContext, RenderFunction, RenderOptions, RenderedQuery, RequiresCapabilityMeta, RequiresOf, RequiresOuterMetadataOf, RequiresOuterOf, RequiresOuterSourceMeta, RequiresSourceMeta, ResultMeta, RowLockMode, RowLockWaitPolicy, SchemaLiteralRenderer, SqlBigInt, SqlBinary, SqlBoolean, SqlDate, SqlDecimal, SqlEqualityComparable, SqlEqualityCompatible, SqlInteger, SqlJson, SqlNumericLike, SqlOrderCompatible, SqlOrderable, SqlSemanticType, SqlText, SqlTextLike, SqlTimestamp, SqlTypeOf, SqlTypeSatisfies, SqlUnknown, SqlUuid, SubqueryMeta, VisibleDependenciesOf, WindowMeta, assertDialectCapability, commaSeparated, createDialect, customClause, expressionFragment, fragment, identifier, isExpression, isFragment, keyword, makeExpression, markExpressionCategory, parameter, parenthesize, qualifiedIdentifier, render, resolveCastTarget, routineName, sequence, syntax, typedCall, typedCast, typedValue, unsafeExpression, withDialectCapability };
|
|
33
|
+
export { AggregateDependenciesOf, AggregateMeta, AnyFragment, AnySqlType, CapabilitiesOf, CapabilityMetadataOf, CardinalityMeta, CardinalityOf, CastTarget, DependenciesOf, Dialect, DialectCapability, DialectCastTypes, DialectExplain, DialectJson, DialectOptions, DialectPagination, DialectRowLocking, ExplainFormat, ExplainRenderOptions, ExpressionMeta, Fragment, FragmentMeta, GroupingDependenciesOf, GroupingKeysOf, GroupingMeta, HasAggregate, HasSubquery, HasWindow, InheritedMetadata, InheritedMetadataOf, JsonScalarKind, MetadataOf, NamedCastTarget, NullabilityOf, NullableSourceMeta, NullableSourcesOf, OutputOf, PaginationKind, PaginationPart, PortableCastTarget, PortableCastType, ProvidesOuterOf, ProvidesOuterSourceMeta, ProvidesSourceMeta, QueryCardinality, RenderCapabilityValidation, RenderContext, RenderFunction, RenderOptions, RenderedQuery, RequiresCapabilityMeta, RequiresOf, RequiresOuterMetadataOf, RequiresOuterOf, RequiresOuterSourceMeta, RequiresSourceMeta, ResultMeta, RowLockMode, RowLockWaitPolicy, SchemaLiteralRenderer, SqlBigInt, SqlBinary, SqlBoolean, SqlDate, SqlDecimal, SqlEqualityComparable, SqlEqualityCompatible, SqlInteger, SqlJson, SqlNumericLike, SqlOrderCompatible, SqlOrderable, SqlSemanticType, SqlText, SqlTextLike, SqlTimestamp, SqlTypeName, SqlTypeOf, SqlTypeSatisfies, SqlUnknown, SqlUuid, SubqueryMeta, VisibleDependenciesOf, WindowMeta, assertDialectCapability, commaSeparated, createDialect, customClause, expressionFragment, extendDialect, fragment, identifier, isExpression, isFragment, keyword, makeExpression, markExpressionCategory, parameter, parenthesize, qualifiedIdentifier, render, resolveCastTarget, resultValue, routineName, sequence, syntax, typedCall, typedCast, typedValue, unsafeExpression, withDialectCapability };
|
package/dist/core.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as routineName, c as render, i as typedCall, s as typedCast, t as createClause } from "./types-
|
|
1
|
+
import { $ as resolveCastTarget, A as fragment, C as isExpression, D as markExpressionCategory, M as parenthesize, N as sequence, Q as extendDialect, T as makeExpression, U as resultValue, X as assertDialectCapability, Z as createDialect, a as qualifiedIdentifier, i as identifier, j as isFragment, k as withDialectCapability, n as expressionFragment } from "./column-DDRvD7SF.mjs";
|
|
2
|
+
import { a as parameter, r as typedValue } from "./value-CpaUFtjw.mjs";
|
|
3
|
+
import { a as routineName, c as render, i as typedCall, s as typedCast, t as createClause } from "./types-CYHpSPwj.mjs";
|
|
4
4
|
//#region src/core/primitives/compose.ts
|
|
5
5
|
function commaSeparated(parts) {
|
|
6
6
|
return sequence(parts, ", ");
|
|
@@ -32,4 +32,4 @@ function customClause(options) {
|
|
|
32
32
|
return createClause(options.name, options.placement ?? "after-select", options.order, options.render);
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
|
-
export { assertDialectCapability, commaSeparated, createDialect, customClause, expressionFragment, fragment, identifier, isExpression, isFragment, keyword, makeExpression, markExpressionCategory, parameter, parenthesize, qualifiedIdentifier, render, resolveCastTarget, routineName, sequence, syntax, typedCall, typedCast, typedValue, unsafeExpression, withDialectCapability };
|
|
35
|
+
export { assertDialectCapability, commaSeparated, createDialect, customClause, expressionFragment, extendDialect, fragment, identifier, isExpression, isFragment, keyword, makeExpression, markExpressionCategory, parameter, parenthesize, qualifiedIdentifier, render, resolveCastTarget, resultValue, routineName, sequence, syntax, typedCall, typedCast, typedValue, unsafeExpression, withDialectCapability };
|
package/dist/diff.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { T as SnapshotJsonValue, m as SnapshotDialect, n as SchemaSnapshot } from "./types-
|
|
2
|
-
import { S as CompleteSnapshotObjectKind, t as CompleteSchemaSnapshot } from "./complete-types-CNMWBWap.mjs";
|
|
1
|
+
import { T as SnapshotJsonValue, m as SnapshotDialect, n as SchemaSnapshot, st as CompleteSnapshotObjectKind } from "./types-Dqr4o2I1.mjs";
|
|
3
2
|
//#region src/diff/types.d.ts
|
|
4
3
|
/** Object families understood by the snapshot diff engine. */
|
|
5
4
|
type SnapshotDiffObjectKind = CompleteSnapshotObjectKind;
|
|
@@ -27,7 +26,7 @@ interface SnapshotRenameHint {
|
|
|
27
26
|
readonly to: string | SnapshotRenameTarget;
|
|
28
27
|
}
|
|
29
28
|
/** Input accepted by the diff and hint helpers. */
|
|
30
|
-
type SnapshotDiffInput = SchemaSnapshot |
|
|
29
|
+
type SnapshotDiffInput = SchemaSnapshot | string | Readonly<Record<string, unknown>>;
|
|
31
30
|
/** Evidence attached to an object, match, operation, or diagnostic. */
|
|
32
31
|
interface SnapshotDiffEvidence {
|
|
33
32
|
readonly kind: "logical-id" | "physical-name" | "physical-reference" | "provenance" | "dialect" | "canonical" | "explicit-hint" | "structural" | "ambiguity";
|
|
@@ -58,6 +57,7 @@ interface SnapshotDiffObjectReference {
|
|
|
58
57
|
readonly kind: SnapshotDiffObjectKind;
|
|
59
58
|
readonly id: string;
|
|
60
59
|
readonly namespace?: string;
|
|
60
|
+
readonly physicalName?: string;
|
|
61
61
|
}
|
|
62
62
|
/** One changed property in a matched object pair. */
|
|
63
63
|
interface SnapshotDiffPropertyChange {
|
|
@@ -134,8 +134,8 @@ interface SnapshotDiffOptions {
|
|
|
134
134
|
/** The complete immutable output of `diffSnapshots`. */
|
|
135
135
|
interface SnapshotDiff {
|
|
136
136
|
readonly equal: boolean;
|
|
137
|
-
readonly beforeVersion?: 1
|
|
138
|
-
readonly afterVersion?: 1
|
|
137
|
+
readonly beforeVersion?: 1;
|
|
138
|
+
readonly afterVersion?: 1;
|
|
139
139
|
readonly beforeDialect?: SnapshotDialect;
|
|
140
140
|
readonly afterDialect?: SnapshotDialect;
|
|
141
141
|
readonly beforeFingerprint?: string;
|
|
@@ -169,8 +169,8 @@ type SnapshotRenameHintResult = {
|
|
|
169
169
|
/** Decode diagnostics without throwing, suitable for editor and CLI callers. */
|
|
170
170
|
type SnapshotDiffDecodeResult = {
|
|
171
171
|
readonly ok: true;
|
|
172
|
-
readonly version: 1
|
|
173
|
-
readonly value: SchemaSnapshot
|
|
172
|
+
readonly version: 1;
|
|
173
|
+
readonly value: SchemaSnapshot;
|
|
174
174
|
} | {
|
|
175
175
|
readonly ok: false;
|
|
176
176
|
readonly diagnostics: readonly SnapshotDiffDiagnostic[];
|
|
@@ -178,7 +178,7 @@ type SnapshotDiffDecodeResult = {
|
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/diff/diff.d.ts
|
|
180
180
|
/**
|
|
181
|
-
* Compare Snapshot v1
|
|
181
|
+
* Compare Snapshot v1 values and return immutable, reviewable data.
|
|
182
182
|
*
|
|
183
183
|
* The function never opens a connection, renders SQL, or turns a heuristic match into a rename.
|
|
184
184
|
* Invalid input and malformed hints are represented by diagnostics in the returned value.
|
|
@@ -186,7 +186,7 @@ type SnapshotDiffDecodeResult = {
|
|
|
186
186
|
declare function diffSnapshots(beforeInput: SnapshotDiffInput, afterInput: SnapshotDiffInput, options?: SnapshotDiffOptions): SnapshotDiff;
|
|
187
187
|
/** Alias that reads naturally in comparison-oriented callers. */
|
|
188
188
|
declare const compareSnapshots: typeof diffSnapshots;
|
|
189
|
-
/** Decode and normalize a Snapshot v1
|
|
189
|
+
/** Decode and normalize a Snapshot v1 value without throwing. */
|
|
190
190
|
declare function decodeSnapshotForDiff(input: SnapshotDiffInput): SnapshotDiffDecodeResult;
|
|
191
191
|
/** Validate rename hints and return a frozen, serializable list. */
|
|
192
192
|
declare function validateSnapshotRenameHints(hints: readonly SnapshotRenameHint[] | unknown): SnapshotRenameHintResult;
|
package/dist/diff.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as decodeCompleteSchemaSnapshot, s as completeSchemaSnapshotFingerprint } from "./complete-DP7pliuY.mjs";
|
|
1
|
+
import { _ as decodeCompleteSchemaSnapshot, a as toSnapshotJsonValue, g as completeSchemaSnapshotFingerprint, n as canonicalJson } from "./canonical-B5_ouh-c.mjs";
|
|
3
2
|
//#region src/diff/diff.ts
|
|
4
3
|
const objectKinds = /* @__PURE__ */ new Set([
|
|
5
4
|
"namespace",
|
|
@@ -30,7 +29,7 @@ const operationOrder = /* @__PURE__ */ new Map([
|
|
|
30
29
|
["add", 3]
|
|
31
30
|
]);
|
|
32
31
|
/**
|
|
33
|
-
* Compare Snapshot v1
|
|
32
|
+
* Compare Snapshot v1 values and return immutable, reviewable data.
|
|
34
33
|
*
|
|
35
34
|
* The function never opens a connection, renders SQL, or turns a heuristic match into a rename.
|
|
36
35
|
* Invalid input and malformed hints are represented by diagnostics in the returned value.
|
|
@@ -91,6 +90,11 @@ function diffSnapshots(beforeInput, afterInput, options = {}) {
|
|
|
91
90
|
const usedBefore = /* @__PURE__ */ new Set();
|
|
92
91
|
const usedAfter = /* @__PURE__ */ new Set();
|
|
93
92
|
const matches = [];
|
|
93
|
+
const parentRenameMappings = /* @__PURE__ */ new Map();
|
|
94
|
+
const recordMatch = (match) => {
|
|
95
|
+
matches.push(match);
|
|
96
|
+
addParentRenameMapping(match, parentRenameMappings);
|
|
97
|
+
};
|
|
94
98
|
for (const hint of validHints) {
|
|
95
99
|
const beforeCandidates = resolveHintTarget(left.records, hint.kind, hint.namespace, hint.from);
|
|
96
100
|
const afterCandidates = resolveHintTarget(right.records, hint.kind, hint.namespace, hint.to);
|
|
@@ -116,7 +120,7 @@ function diffSnapshots(beforeInput, afterInput, options = {}) {
|
|
|
116
120
|
}
|
|
117
121
|
usedBefore.add(beforeObject);
|
|
118
122
|
usedAfter.add(afterObject);
|
|
119
|
-
|
|
123
|
+
recordMatch({
|
|
120
124
|
before: beforeObject,
|
|
121
125
|
after: afterObject,
|
|
122
126
|
source: "explicit-hint",
|
|
@@ -131,20 +135,43 @@ function diffSnapshots(beforeInput, afterInput, options = {}) {
|
|
|
131
135
|
if (usedBefore.has(beforeObject) || usedAfter.has(afterObject)) continue;
|
|
132
136
|
usedBefore.add(beforeObject);
|
|
133
137
|
usedAfter.add(afterObject);
|
|
134
|
-
|
|
138
|
+
recordMatch({
|
|
135
139
|
before: beforeObject,
|
|
136
140
|
after: afterObject,
|
|
137
141
|
source: "stable-id",
|
|
138
142
|
evidence: [evidence("logical-id", [...beforeObject.object.path, "id"], beforeObject.object.id, 1, "Stable logical ID match")]
|
|
139
143
|
});
|
|
140
144
|
}
|
|
145
|
+
let matchedDescendant = true;
|
|
146
|
+
while (matchedDescendant) {
|
|
147
|
+
matchedDescendant = false;
|
|
148
|
+
const remainingBefore = left.records.filter((record) => !usedBefore.has(record) && record.object.parent !== void 0);
|
|
149
|
+
const remainingAfter = right.records.filter((record) => !usedAfter.has(record) && record.object.parent !== void 0);
|
|
150
|
+
const beforeByMappedKey = groupByKey(remainingBefore, (record) => remappedObjectKey(record, parentRenameMappings));
|
|
151
|
+
const afterByRemainingKey = groupByKey(remainingAfter);
|
|
152
|
+
for (const [key, beforeCandidates] of beforeByMappedKey) {
|
|
153
|
+
const afterCandidates = afterByRemainingKey.get(key) ?? [];
|
|
154
|
+
if (beforeCandidates.length !== 1 || afterCandidates.length !== 1) continue;
|
|
155
|
+
const beforeObject = beforeCandidates[0];
|
|
156
|
+
const afterObject = afterCandidates[0];
|
|
157
|
+
usedBefore.add(beforeObject);
|
|
158
|
+
usedAfter.add(afterObject);
|
|
159
|
+
recordMatch({
|
|
160
|
+
before: beforeObject,
|
|
161
|
+
after: afterObject,
|
|
162
|
+
source: "stable-id",
|
|
163
|
+
evidence: [evidence("logical-id", [...beforeObject.object.path, "id"], beforeObject.object.id, 1, "Stable logical ID match within a renamed parent scope")]
|
|
164
|
+
});
|
|
165
|
+
matchedDescendant = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
141
168
|
const suggestions = [];
|
|
142
169
|
const suggestionThreshold = clampThreshold(options.suggestionThreshold);
|
|
143
170
|
const unmatchedBefore = left.records.filter((record) => !usedBefore.has(record));
|
|
144
171
|
const unmatchedAfter = right.records.filter((record) => !usedAfter.has(record));
|
|
145
172
|
if (options.suggestions !== false) for (const beforeObject of unmatchedBefore) {
|
|
146
173
|
if (beforeObject.lossy || beforeObject.unsupported) continue;
|
|
147
|
-
const candidates = unmatchedAfter.filter((candidate) => !candidate.lossy && !candidate.unsupported && candidate.scopeKey === beforeObject
|
|
174
|
+
const candidates = unmatchedAfter.filter((candidate) => !candidate.lossy && !candidate.unsupported && candidate.scopeKey === scopeKeyForRecord(beforeObject, parentRenameMappings)).map((candidate) => ({
|
|
148
175
|
candidate,
|
|
149
176
|
score: structuralScore(beforeObject, candidate)
|
|
150
177
|
})).filter((candidate) => candidate.score >= suggestionThreshold).sort((leftCandidate, rightCandidate) => rightCandidate.score - leftCandidate.score || compareObject(leftCandidate.candidate, rightCandidate.candidate));
|
|
@@ -254,7 +281,7 @@ function diffSnapshots(beforeInput, afterInput, options = {}) {
|
|
|
254
281
|
}
|
|
255
282
|
/** Alias that reads naturally in comparison-oriented callers. */
|
|
256
283
|
const compareSnapshots = diffSnapshots;
|
|
257
|
-
/** Decode and normalize a Snapshot v1
|
|
284
|
+
/** Decode and normalize a Snapshot v1 value without throwing. */
|
|
258
285
|
function decodeSnapshotForDiff(input) {
|
|
259
286
|
const decoded = decodeSnapshot(input);
|
|
260
287
|
if (!decoded.snapshot) return {
|
|
@@ -362,26 +389,9 @@ function decodeSnapshot(input) {
|
|
|
362
389
|
return { diagnostics };
|
|
363
390
|
}
|
|
364
391
|
const version = value.version;
|
|
365
|
-
const normalized = sortSnapshotArrays(value
|
|
366
|
-
if (version === 2) {
|
|
367
|
-
const result = decodeCompleteSchemaSnapshot(normalized);
|
|
368
|
-
if (!result.ok) {
|
|
369
|
-
diagnostics.push(...mapSnapshotDiagnostics(result.diagnostics));
|
|
370
|
-
return { diagnostics };
|
|
371
|
-
}
|
|
372
|
-
const snapshot = result.value;
|
|
373
|
-
return {
|
|
374
|
-
diagnostics,
|
|
375
|
-
snapshot: {
|
|
376
|
-
version: 2,
|
|
377
|
-
value: snapshot,
|
|
378
|
-
records: extractCompleteObjects(snapshot),
|
|
379
|
-
fingerprint: completeSchemaSnapshotFingerprint(snapshot)
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
}
|
|
392
|
+
const normalized = sortSnapshotArrays(value);
|
|
383
393
|
if (version === 1) {
|
|
384
|
-
const result =
|
|
394
|
+
const result = decodeCompleteSchemaSnapshot(normalized);
|
|
385
395
|
if (!result.ok) {
|
|
386
396
|
diagnostics.push(...mapSnapshotDiagnostics(result.diagnostics));
|
|
387
397
|
return { diagnostics };
|
|
@@ -392,41 +402,15 @@ function decodeSnapshot(input) {
|
|
|
392
402
|
snapshot: {
|
|
393
403
|
version: 1,
|
|
394
404
|
value: snapshot,
|
|
395
|
-
records:
|
|
396
|
-
fingerprint:
|
|
405
|
+
records: extractSnapshotObjects(snapshot),
|
|
406
|
+
fingerprint: completeSchemaSnapshotFingerprint(snapshot)
|
|
397
407
|
}
|
|
398
408
|
};
|
|
399
409
|
}
|
|
400
410
|
diagnostics.push(diffDiagnostic("invalid-snapshot", `Unsupported schema snapshot version: ${String(version)}`, ["version"]));
|
|
401
411
|
return { diagnostics };
|
|
402
412
|
}
|
|
403
|
-
function
|
|
404
|
-
const records = [];
|
|
405
|
-
const namespace = snapshot.namespace;
|
|
406
|
-
for (const [tableIndex, table] of snapshot.tables.entries()) {
|
|
407
|
-
const tableObject = addInternalObject(records, "table", table, ["tables", tableIndex], namespace, void 0, snapshot);
|
|
408
|
-
for (const [columnIndex, column] of table.columns.entries()) addInternalObject(records, "column", column, [
|
|
409
|
-
"tables",
|
|
410
|
-
tableIndex,
|
|
411
|
-
"columns",
|
|
412
|
-
columnIndex
|
|
413
|
-
], namespace, tableObject, snapshot);
|
|
414
|
-
for (const [constraintIndex, constraint] of table.constraints.entries()) addInternalObject(records, "constraint", constraint, [
|
|
415
|
-
"tables",
|
|
416
|
-
tableIndex,
|
|
417
|
-
"constraints",
|
|
418
|
-
constraintIndex
|
|
419
|
-
], namespace, tableObject, snapshot);
|
|
420
|
-
for (const [indexIndex, index] of table.indexes.entries()) addInternalObject(records, "index", index, [
|
|
421
|
-
"tables",
|
|
422
|
-
tableIndex,
|
|
423
|
-
"indexes",
|
|
424
|
-
indexIndex
|
|
425
|
-
], namespace, tableObject, snapshot);
|
|
426
|
-
}
|
|
427
|
-
return freeze(records.sort(compareObject));
|
|
428
|
-
}
|
|
429
|
-
function extractCompleteObjects(snapshot) {
|
|
413
|
+
function extractSnapshotObjects(snapshot) {
|
|
430
414
|
const records = [];
|
|
431
415
|
const namespace = snapshot.namespace.name;
|
|
432
416
|
addInternalObject(records, "namespace", snapshot.namespace, ["namespace"], namespace, void 0, snapshot);
|
|
@@ -481,6 +465,15 @@ function extractCompleteObjects(snapshot) {
|
|
|
481
465
|
columnIndex
|
|
482
466
|
], namespace, object, snapshot);
|
|
483
467
|
}
|
|
468
|
+
if (kind === "domain") {
|
|
469
|
+
const constraints = value.constraints ?? [];
|
|
470
|
+
for (const [constraintIndex, constraint] of constraints.entries()) addInternalObject(records, "constraint", constraint, [
|
|
471
|
+
String(group),
|
|
472
|
+
index,
|
|
473
|
+
"constraints",
|
|
474
|
+
constraintIndex
|
|
475
|
+
], namespace, object, snapshot);
|
|
476
|
+
}
|
|
484
477
|
}
|
|
485
478
|
}
|
|
486
479
|
return freeze(records.sort(compareObject));
|
|
@@ -502,6 +495,7 @@ function addInternalObject(records, kind, value, path, namespace, parent, snapsh
|
|
|
502
495
|
...parent === void 0 ? {} : { parent: freeze({
|
|
503
496
|
kind: parent.object.kind,
|
|
504
497
|
id: parent.object.id,
|
|
498
|
+
...parent.object.physicalName === void 0 ? {} : { physicalName: parent.object.physicalName },
|
|
505
499
|
...namespace === void 0 ? {} : { namespace }
|
|
506
500
|
}) },
|
|
507
501
|
id,
|
|
@@ -541,34 +535,45 @@ function operationForMatch(match, diagnostics) {
|
|
|
541
535
|
relatedPaths: [after.path],
|
|
542
536
|
evidence: [...before.evidence, ...after.evidence]
|
|
543
537
|
}));
|
|
544
|
-
if (physicalRename && !blockedRename) return freeze({
|
|
545
|
-
type: "physical-rename",
|
|
546
|
-
operation: "physical-rename",
|
|
547
|
-
classification: "physical-rename",
|
|
548
|
-
changeKind: "physical-rename",
|
|
549
|
-
kind: before.kind,
|
|
550
|
-
objectKind: before.kind,
|
|
551
|
-
namespace: before.namespace ?? after.namespace,
|
|
552
|
-
path: after.path,
|
|
553
|
-
dialect: after.dialect,
|
|
554
|
-
...after.physicalReference === void 0 ? {} : { physicalReference: after.physicalReference },
|
|
555
|
-
...after.provenance === void 0 ? {} : { provenance: after.provenance },
|
|
556
|
-
before,
|
|
557
|
-
after,
|
|
558
|
-
object: after,
|
|
559
|
-
logicalId: after.id,
|
|
560
|
-
physicalName: after.physicalName,
|
|
561
|
-
...changedProperties.length === 0 ? {} : { changedProperties },
|
|
562
|
-
evidence: freeze([
|
|
563
|
-
...match.evidence,
|
|
564
|
-
evidence("physical-name", [...before.path, "physicalName"], before.physicalName, 1, "Physical name changed while the logical match remained stable"),
|
|
565
|
-
evidence("physical-name", [...after.path, "physicalName"], after.physicalName, 1, "New physical name")
|
|
566
|
-
]),
|
|
567
|
-
source: match.source,
|
|
568
|
-
destructive: false
|
|
569
|
-
});
|
|
570
|
-
if (effectiveChanges.length === 0) return;
|
|
571
538
|
const destructive = effectiveChanges.some(isDestructiveProperty);
|
|
539
|
+
if (physicalRename && !blockedRename) {
|
|
540
|
+
if (destructive) diagnostics.push(diffDiagnostic("destructive", `Property changes on ${before.kind} "${before.id}" may remove or narrow existing data`, before.path, {
|
|
541
|
+
kind: before.kind,
|
|
542
|
+
namespace: before.namespace,
|
|
543
|
+
logicalId: before.id,
|
|
544
|
+
physicalName: before.physicalName,
|
|
545
|
+
dialect: after.dialect,
|
|
546
|
+
relatedPaths: [after.path],
|
|
547
|
+
evidence: match.evidence
|
|
548
|
+
}));
|
|
549
|
+
return freeze({
|
|
550
|
+
type: "physical-rename",
|
|
551
|
+
operation: "physical-rename",
|
|
552
|
+
classification: "physical-rename",
|
|
553
|
+
changeKind: "physical-rename",
|
|
554
|
+
kind: before.kind,
|
|
555
|
+
objectKind: before.kind,
|
|
556
|
+
namespace: before.namespace ?? after.namespace,
|
|
557
|
+
path: after.path,
|
|
558
|
+
dialect: after.dialect,
|
|
559
|
+
...after.physicalReference === void 0 ? {} : { physicalReference: after.physicalReference },
|
|
560
|
+
...after.provenance === void 0 ? {} : { provenance: after.provenance },
|
|
561
|
+
before,
|
|
562
|
+
after,
|
|
563
|
+
object: after,
|
|
564
|
+
logicalId: after.id,
|
|
565
|
+
physicalName: after.physicalName,
|
|
566
|
+
...changedProperties.length === 0 ? {} : { changedProperties },
|
|
567
|
+
evidence: freeze([
|
|
568
|
+
...match.evidence,
|
|
569
|
+
evidence("physical-name", [...before.path, "physicalName"], before.physicalName, 1, "Physical name changed while the logical match remained stable"),
|
|
570
|
+
evidence("physical-name", [...after.path, "physicalName"], after.physicalName, 1, "New physical name")
|
|
571
|
+
]),
|
|
572
|
+
source: match.source,
|
|
573
|
+
destructive
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
if (effectiveChanges.length === 0) return;
|
|
572
577
|
if (destructive) diagnostics.push(diffDiagnostic("destructive", `Property changes on ${before.kind} "${before.id}" may remove or narrow existing data`, before.path, {
|
|
573
578
|
kind: before.kind,
|
|
574
579
|
namespace: before.namespace,
|
|
@@ -652,13 +657,13 @@ function structuralScore(left, right) {
|
|
|
652
657
|
function structuralSignature(value) {
|
|
653
658
|
return canonicalJson(stripIdentity(value));
|
|
654
659
|
}
|
|
655
|
-
function stripIdentity(value) {
|
|
656
|
-
if (Array.isArray(value)) return value.map((item) => stripIdentity(item));
|
|
660
|
+
function stripIdentity(value, root = true) {
|
|
661
|
+
if (Array.isArray(value)) return value.map((item) => stripIdentity(item, false));
|
|
657
662
|
if (value === null || typeof value !== "object") return value;
|
|
658
663
|
const result = {};
|
|
659
664
|
for (const [key, child] of Object.entries(value)) {
|
|
660
|
-
if (
|
|
661
|
-
result[key] = stripIdentity(child);
|
|
665
|
+
if (root && isIdentityField(key)) continue;
|
|
666
|
+
result[key] = stripIdentity(child, false);
|
|
662
667
|
}
|
|
663
668
|
return result;
|
|
664
669
|
}
|
|
@@ -669,7 +674,7 @@ function propertyChangesBetween(before, after) {
|
|
|
669
674
|
}
|
|
670
675
|
function compareValues(before, after, path, changes) {
|
|
671
676
|
const key = path[path.length - 1];
|
|
672
|
-
if (key === "id" || key === "physicalName" || key === "physicalReference") return;
|
|
677
|
+
if (path.length === 1 && (key === "id" || key === "physicalName" || key === "physicalReference")) return;
|
|
673
678
|
if (path.length === 1 && (key === "columns" || key === "constraints" || key === "indexes")) return;
|
|
674
679
|
if (canonicalEquivalent(before, after)) return;
|
|
675
680
|
if (isSnapshotRecord(before) && isSnapshotRecord(after)) {
|
|
@@ -688,6 +693,9 @@ function compareValues(before, after, path, changes) {
|
|
|
688
693
|
...after === void 0 ? {} : { after }
|
|
689
694
|
});
|
|
690
695
|
}
|
|
696
|
+
function isIdentityField(key) {
|
|
697
|
+
return key === "id" || key === "physicalName" || key === "physicalReference" || key === "provenance";
|
|
698
|
+
}
|
|
691
699
|
function isDestructiveProperty(change) {
|
|
692
700
|
if (change.after === void 0) return true;
|
|
693
701
|
const key = change.path[change.path.length - 1];
|
|
@@ -736,37 +744,79 @@ function mapSnapshotDiagnostics(diagnostics) {
|
|
|
736
744
|
return diffDiagnostic(item.code === "unknown-field" ? "unknown" : item.code === "future-version" || item.code === "unsupported-expression" || item.code === "unsupported-dialect-option" ? "unsupported" : "invalid-snapshot", item.message, item.path, { relatedPaths: item.relatedPaths });
|
|
737
745
|
});
|
|
738
746
|
}
|
|
739
|
-
function groupByKey(records) {
|
|
747
|
+
function groupByKey(records, keyFor = (record) => record.key) {
|
|
740
748
|
const groups = /* @__PURE__ */ new Map();
|
|
741
749
|
for (const record of records) {
|
|
742
|
-
const
|
|
743
|
-
|
|
750
|
+
const key = keyFor(record);
|
|
751
|
+
const values = groups.get(key);
|
|
752
|
+
if (values === void 0) groups.set(key, [record]);
|
|
744
753
|
else values.push(record);
|
|
745
754
|
}
|
|
746
755
|
return groups;
|
|
747
756
|
}
|
|
748
757
|
function objectKey(kind, namespace, parent, id) {
|
|
749
|
-
return
|
|
758
|
+
return objectKeyFor(kind, namespace, parent?.object.kind, parent?.object.id, id);
|
|
750
759
|
}
|
|
751
|
-
function
|
|
752
|
-
|
|
760
|
+
function objectKeyFor(kind, namespace, parentKind, parentId, id) {
|
|
761
|
+
return `${kind}\u0000${namespace ?? ""}\u0000${parentKind ?? ""}\u0000${parentId ?? ""}\u0000${id}`;
|
|
762
|
+
}
|
|
763
|
+
function addParentRenameMapping(match, mappings) {
|
|
764
|
+
const before = match.before.object;
|
|
765
|
+
const after = match.after.object;
|
|
766
|
+
const key = parentMappingKey(before.kind, before.namespace, before.id);
|
|
767
|
+
const existing = mappings.get(key);
|
|
768
|
+
if (existing === void 0 || existing === after.id) mappings.set(key, after.id);
|
|
769
|
+
}
|
|
770
|
+
function parentMappingKey(kind, namespace, id) {
|
|
771
|
+
return `${kind}\u0000${namespace ?? ""}\u0000${id}`;
|
|
772
|
+
}
|
|
773
|
+
function remappedObjectKey(record, mappings) {
|
|
774
|
+
const parent = record.object.parent;
|
|
775
|
+
if (parent === void 0) return record.key;
|
|
776
|
+
const parentNamespace = parent.namespace ?? record.object.namespace;
|
|
777
|
+
const parentId = mappings.get(parentMappingKey(parent.kind, parentNamespace, parent.id)) ?? parent.id;
|
|
778
|
+
return objectKeyFor(record.object.kind, record.object.namespace, parent.kind, parentId, record.object.id);
|
|
779
|
+
}
|
|
780
|
+
function scopeKeyForRecord(record, mappings = /* @__PURE__ */ new Map()) {
|
|
781
|
+
const parent = record.object.parent;
|
|
782
|
+
if (parent === void 0) return `${record.object.kind}\u0000${record.object.namespace ?? ""}\u0000`;
|
|
783
|
+
const parentNamespace = parent.namespace ?? record.object.namespace;
|
|
784
|
+
const parentId = mappings.get(parentMappingKey(parent.kind, parentNamespace, parent.id)) ?? parent.id;
|
|
785
|
+
return `${record.object.kind}\u0000${record.object.namespace ?? ""}\u0000${parentId}`;
|
|
786
|
+
}
|
|
787
|
+
function sortSnapshotArrays(value) {
|
|
788
|
+
const visit = (current, path) => {
|
|
753
789
|
if (Array.isArray(current)) {
|
|
754
|
-
const values = current.map((item) => visit(item,
|
|
755
|
-
if (
|
|
756
|
-
if (
|
|
757
|
-
if (
|
|
790
|
+
const values = current.map((item, index) => visit(item, [...path, index]));
|
|
791
|
+
if (isObjectArrayPath(path) && values.every(isRecord)) return values.sort(compareUnknownRecords);
|
|
792
|
+
if (isUnorderedArrayPath(path)) return values.sort(compareUnknownRecords);
|
|
793
|
+
if (isPositionedArrayPath(path)) return values.sort(comparePositionedRecords);
|
|
758
794
|
return values;
|
|
759
795
|
}
|
|
760
796
|
if (!isRecord(current)) return current;
|
|
761
797
|
const output = {};
|
|
762
|
-
for (const [childKey, child] of Object.entries(current)) output[childKey] = visit(child, childKey);
|
|
798
|
+
for (const [childKey, child] of Object.entries(current)) output[childKey] = visit(child, [...path, childKey]);
|
|
763
799
|
return output;
|
|
764
800
|
};
|
|
765
|
-
return visit(value,
|
|
801
|
+
return visit(value, []);
|
|
802
|
+
}
|
|
803
|
+
function isObjectArrayPath(path) {
|
|
804
|
+
if (path.length === 1) return path[0] === "tables" || path[0] === "views" || path[0] === "sequences" || path[0] === "enums" || path[0] === "domains" || path[0] === "collations" || path[0] === "triggers" || path[0] === "routines" || path[0] === "partitions" || path[0] === "policies" || path[0] === "extensions" || path[0] === "deferredObjects" || path[0] === "opaqueObjects" || path[0] === "comments" || path[0] === "ownership";
|
|
805
|
+
if (path.length !== 3 || !Number.isSafeInteger(path[1])) return false;
|
|
806
|
+
if (path[0] === "tables") return path[2] === "columns" || path[2] === "constraints" || path[2] === "indexes";
|
|
807
|
+
if (path[0] === "views") return path[2] === "columns";
|
|
808
|
+
return path[0] === "domains" && path[2] === "constraints";
|
|
809
|
+
}
|
|
810
|
+
function isUnorderedArrayPath(path) {
|
|
811
|
+
if (path.length === 3 && Number.isSafeInteger(path[1])) {
|
|
812
|
+
if ((path[0] === "views" || path[0] === "routines") && path[2] === "dependencies") return true;
|
|
813
|
+
if (path[0] === "policies" && path[2] === "roles" || path[0] === "triggers" && path[2] === "events") return true;
|
|
814
|
+
}
|
|
815
|
+
return path.length === 5 && path[0] === "tables" && Number.isSafeInteger(path[1]) && path[2] === "indexes" && Number.isSafeInteger(path[3]) && path[4] === "includedColumns";
|
|
766
816
|
}
|
|
767
|
-
function
|
|
768
|
-
if (
|
|
769
|
-
return
|
|
817
|
+
function isPositionedArrayPath(path) {
|
|
818
|
+
if (path.length === 3 && Number.isSafeInteger(path[1])) return path[0] === "enums" && path[2] === "values" || path[0] === "routines" && path[2] === "parameters";
|
|
819
|
+
return path.length === 5 && path[0] === "tables" && Number.isSafeInteger(path[1]) && path[2] === "indexes" && Number.isSafeInteger(path[3]) && path[4] === "terms";
|
|
770
820
|
}
|
|
771
821
|
function compareUnknownRecords(left, right) {
|
|
772
822
|
const leftRecord = isRecord(left) ? left : void 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as queryValidationError } from "./omit-VEr9Ydux.mjs";
|
|
2
2
|
//#region src/dialects/explain.ts
|
|
3
3
|
const readQueryKinds = /* @__PURE__ */ new Set(["select", "set"]);
|
|
4
4
|
function assertExplainAnalysisAllowed(dialect, queryKind, options) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { E as
|
|
1
|
+
import { E as makeSchemaExpression, O as markSchemaExpression, r as isColumnReference, w as isSchemaExpression } from "./column-DDRvD7SF.mjs";
|
|
2
|
+
import { n as isValueExpression, o as standardDialect } from "./value-CpaUFtjw.mjs";
|
|
2
3
|
//#region src/schema/expressions.ts
|
|
3
4
|
/** Error raised before a schema expression can become persisted SQL. */
|
|
4
5
|
var SchemaExpressionError = class extends TypeError {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|