@vibeorm/sql 3.0.0 → 4.1.0

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/ast.d.ts CHANGED
@@ -16,17 +16,21 @@ export type ColRef = {
16
16
  readonly table?: string;
17
17
  readonly name: string;
18
18
  /**
19
- * Projection-only wire transform, postgres only. `castText` renders
20
- * `"col"::text AS "col"`, `encodeBase64` renders
21
- * `encode("col", 'base64') AS "col"`. Two users: the lateral subselect (SQL
22
- * review B3 — raw `to_jsonb` would ship BigInt/Decimal as float64 JSON
19
+ * Projection-only wire transform. `jsonText` uses the dialect's JSON text
20
+ * projection to preserve SQL NULL versus the JSON document `null` before
21
+ * driver parsing, without converting a postgres `json` column to `jsonb`.
22
+ * `castText` renders a dialect text cast and preserves `alias ?? name`,
23
+ * including timestamp identity before driver Date truncation. PostgreSQL
24
+ * uses `"col"::text`; SQLite/MySQL use CAST AS TEXT/CHAR. `encodeBase64`
25
+ * is postgres-only and renders `encode("col", 'base64')`. Other users:
26
+ * the lateral subselect (SQL review B3: raw `to_jsonb` would ship BigInt/Decimal as float64 JSON
23
27
  * numbers and Bytes as `\x` hex text), and every row projection of a
24
28
  * `Float[]`/`Json[]` column (bun:sql's array parser refuses float arrays
25
29
  * printed with an exponent and json arrays holding integers beyond int32;
26
30
  * the runtime parses the array literal text itself). Never set on
27
31
  * filter/order refs.
28
32
  */
29
- readonly transform?: "castText" | "encodeBase64";
33
+ readonly transform?: "castText" | "encodeBase64" | "jsonText";
30
34
  /**
31
35
  * Comparison/order/aggregate cast, sqlite Decimal only (SQL review B4):
32
36
  * Decimal stores as exact TEXT there and text comparison is lexicographic —
@@ -74,6 +78,8 @@ export type AggRef = {
74
78
  export type AggSelect = {
75
79
  readonly agg: AggRef;
76
80
  readonly alias: string;
81
+ /** Projection-only result cast; native aggregate comparisons and ordering stay typed. */
82
+ readonly castText?: true;
77
83
  };
78
84
  /**
79
85
  * JSON path predicates (Prisma's Json filter surface). `not` is `equals` with
@@ -464,6 +470,12 @@ export type KeyTableMember = {
464
470
  } | {
465
471
  readonly kind: "decimal";
466
472
  readonly scale: number;
473
+ }
474
+ /** MySQL-only lossless temporal operands in mixed collation-aware key tuples. */
475
+ | {
476
+ readonly kind: "timestamp";
477
+ } | {
478
+ readonly kind: "time";
467
479
  } | {
468
480
  readonly kind: "citext";
469
481
  } | {
@@ -637,13 +649,18 @@ export declare function excludedRef(params: {
637
649
  /** Is this SET cell an {@link ExcludedRef}? */
638
650
  export declare function isExcludedRef(value: unknown): value is ExcludedRef;
639
651
  /**
640
- * One RETURNING column: a bare column name renders `"col"`; the object form
641
- * renders `"col"::text AS "col"` (postgres only) — the `Float[]`/`Json[]`
642
- * projection rule {@link ColRef.transform} documents, applied to RETURNING.
652
+ * One RETURNING column: a bare column name renders `"col"`; `castText` renders
653
+ * a dialect text cast (postgres `::text`, sqlite `CAST AS TEXT`) for lossless
654
+ * transport, including timestamps and postgres arrays. `jsonText`
655
+ * applies the dialect's JSON text projection, as {@link ColRef.transform} does
656
+ * for SELECT. Dialects without RETURNING still omit the clause and flag it.
643
657
  */
644
658
  export type ReturningColumn = string | {
645
659
  readonly name: string;
646
660
  readonly castText: true;
661
+ } | {
662
+ readonly name: string;
663
+ readonly transform: "jsonText";
647
664
  };
648
665
  /** The column name a {@link ReturningColumn} exposes in the result row. */
649
666
  export declare function returningColumnName(column: ReturningColumn): string;
package/dist/codecs.d.ts CHANGED
@@ -122,6 +122,15 @@ export declare function parseDateTimeText(params: {
122
122
  export declare function timeOfDayCodec(params: {
123
123
  nativeType: string | undefined;
124
124
  }): ScalarCodec | undefined;
125
+ /**
126
+ * Parse stored JSON text at the centralized codec boundary. A supplied context
127
+ * marks a bound field: its error contains only that context, never the document
128
+ * or the native parser cause. Without context, legacy codec errors are unchanged.
129
+ */
130
+ export declare function parseJsonText(params: {
131
+ text: string;
132
+ context?: Readonly<Record<string, unknown>>;
133
+ }): unknown;
125
134
  /**
126
135
  * The SHORTEST decimal that round-trips through float32 to the same value as
127
136
  * `value` — what postgres itself prints for a `real` (`0.1`, `3.4028235e+38`).
package/dist/dialect.d.ts CHANGED
@@ -198,6 +198,8 @@ export type SqlDialect = {
198
198
  * {@link JsonParamCell} cells and the json-filter operands.
199
199
  */
200
200
  readonly jsonParamCast: string;
201
+ /** Physical types for standalone validated scalar values, without column inference. */
202
+ readonly valueCastTypes: Readonly<Record<ScalarType, string>>;
201
203
  /**
202
204
  * Statement that reads back the id generated by the previous INSERT, for
203
205
  * dialects without RETURNING. `null` where RETURNING covers it. The single
@@ -283,6 +285,14 @@ export type SqlDialect = {
283
285
  placeholder(params: {
284
286
  index: number;
285
287
  }): string;
288
+ /**
289
+ * Project a JSON document as text while preserving SQL NULL. PostgreSQL
290
+ * casts to text, MySQL casts to CHAR and SQLite keeps its stored text. The
291
+ * expression is already rendered SQL, not an identifier or a bound value.
292
+ */
293
+ jsonTextProjection(params: {
294
+ expression: string;
295
+ }): string;
286
296
  /**
287
297
  * The database-clock expression for `DbNowMarker` sites: `now()` on
288
298
  * postgres, `NOW(6)` on mysql, and on sqlite an ISO-8601 `strftime` whose
@@ -54,6 +54,8 @@ export declare function renderMigrationSessionRestore(params: {
54
54
  * expressions as PostgreSQL itself deparses them (newline-joined so every
55
55
  * adapter decodes one plain text column), its partial predicate and the full
56
56
  * `pg_get_indexdef` text for the operator to read in an error message.
57
+ * Complete recovery also reads NULL uniqueness and lossless ordered JSON text
58
+ * for key and included definitions. PostgreSQL 16/17/18 expose these fields.
57
59
  *
58
60
  * `indisvalid = false` is the state a cancelled/failed concurrent build
59
61
  * leaves behind: the index exists, is skipped by the planner, and is still
@@ -0,0 +1,15 @@
1
+ import type { SqlDialect } from "../dialect.ts";
2
+ /**
3
+ * Compare both JSON trees by decoded key/index paths, node type and atomic value.
4
+ * Object order and JSON escape spelling do not matter; array positions do.
5
+ * Container nodes retain empty-object/array distinctions, and multiplicity stops
6
+ * duplicate object members from disappearing as they would in a set difference.
7
+ * SQL NULL remains unknown. The tree input is guarded against non-JSON scalar
8
+ * text even when SQLite evaluates this expression before the outer type guard.
9
+ */
10
+ export declare function renderSqliteJsonEquality(params: {
11
+ dialect: SqlDialect;
12
+ left: string;
13
+ right: string;
14
+ }): string;
15
+ //# sourceMappingURL=sqlite-json-equality.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { cloneTimestampDate, compareTimestampDates, timestampIdentityKey, timestampIdentityText } from "./timestamp-identity.ts";
1
2
  export { nativeEnumArrayParameter, isNativeEnumArrayParameter } from "./native-enum-parameter.ts";
2
3
  export type { NativeEnumArrayParameter } from "./native-enum-parameter.ts";
3
4
  export { isJsonListParameter, jsonListParameter } from "./json-list-parameter.ts";
@@ -19,9 +20,17 @@ export { MODULE_JOURNAL_COLUMN, renderModuleJournal } from "./module-journal.ts"
19
20
  export { renderSqliteFtsUpdateTrigger, sqliteFtsUpdateUpgrade } from "./dialects/sqlite-fts.ts";
20
21
  export { SQLITE_SESSION_SQL } from "./dialects/sqlite-session.ts";
21
22
  export { sql, isSqlFragment, renderSqlFragment, compileSql, sqlUsesIncoming, mapConflictColumns } from "./composable.ts";
23
+ export { registerSqlHandleCheck } from "./sql-handles.ts";
22
24
  export type { SqlFragment, SqlTag } from "./composable.ts";
23
- export { decode } from "./result-decoder.ts";
24
- export type { ResultDecoder, Decoded, ExtendedDateTime } from "./result-decoder.ts";
25
+ export { createSqlQuery, createSqlCommand, isSqlQuery, isSqlCommand, compileSqlQuery, compileSqlCommand } from "./query-plan.ts";
26
+ export type { SqlQuery, SqlCommand, SqlPlanRender, CompiledSqlQuery, CompiledSqlCommand, ReusableSqlQuery, ReusableSqlCommand } from "./query-plan.ts";
27
+ export { createReusableSqlQuery, createReusableSqlCommand, isReusableSqlQuery, isReusableSqlCommand, compileReusableSqlQuery, compileReusableSqlCommand } from "./query-plan.ts";
28
+ export { isSqlParam, createSqlInput, sqlInputContract, createSqlInputScope, sealSqlInputScope, assertSqlParamBuilding, sqlParamContract } from "./sql-input.ts";
29
+ export type { SqlParam, SqlInput, SqlInputMap, SqlInputValue, SqlInputValues, SqlInputTokens, SqlExecutionParams, SqlInputContract, SqlInputScope } from "./sql-input.ts";
30
+ export { isSqlBindingCollector, recordSqlBinding, recordSqlBindingCheck } from "./sql-bindings.ts";
31
+ export type { SqlBindingSource, SqlParameterTransport, SqlBindingEncoder } from "./sql-bindings.ts";
32
+ export { decode, encode, resultScalarContract, sameResultDecoder } from "./result-decoder.ts";
33
+ export type { ResultDecoder, ResultReadDecoder, ResultParameterEncoder, ResultScalarContract, Decoded, ExtendedDateTime } from "./result-decoder.ts";
25
34
  /**
26
35
  * @vibeorm/sql — dialect-aware SQL layer for VibeORM v2.
27
36
  *
@@ -42,10 +51,11 @@ export { tableDefinitionParts } from "./dialects/sqlite-table-definition.ts";
42
51
  export { renderPredicate } from "./predicate.ts";
43
52
  export type { PredicateModel, PredicateUsage } from "./predicate.ts";
44
53
  export { DIALECT_CAPABILITIES, MYSQL_CAPABILITIES, POSTGRES_CAPABILITIES, SQLITE_CAPABILITIES, } from "./capabilities.ts";
45
- export { DIALECT_CODECS, MYSQL_CODECS, POSTGRES_CODECS, SQLITE_CODECS, decodeIsNoop, enumMembershipCodec, float32Codec, parseDateTimeText, postgresArrayElementFromText, shortestFloat32, timeOfDayCodec, } from "./codecs.ts";
54
+ export { DIALECT_CODECS, MYSQL_CODECS, POSTGRES_CODECS, SQLITE_CODECS, decodeIsNoop, enumMembershipCodec, float32Codec, parseDateTimeText, parseJsonText, postgresArrayElementFromText, shortestFloat32, timeOfDayCodec, } from "./codecs.ts";
46
55
  export type { CodecTable, ScalarCodec, WireFidelity } from "./codecs.ts";
47
56
  export { renderExpr, renderFragment, renderProjection, renderStatement } from "./render.ts";
48
57
  export type { RenderedQuery } from "./render.ts";
58
+ export { snapshotSqlValue } from "./parameter-snapshot.ts";
49
59
  export { ParamCollector } from "./params.ts";
50
60
  export { NATIVE_RLS, renderRlsColumnType, renderRlsContext, renderRlsDisable, renderRlsDropPolicy, renderRlsEnable, renderRlsForce, renderRlsNoForce, renderRlsPolicy, renderRlsPredicate, renderRlsRole } from "./dialects/postgres-rls.ts";
51
61
  export type { RlsContextStatement, RlsDisableStatement, RlsDropPolicyStatement, RlsEnableStatement, RlsForceStatement, RlsNoForceStatement, RlsPolicyStatement, RlsRoleStatement } from "./ast.ts";