@vibeorm/sql 3.0.0 → 4.0.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,7 +16,10 @@ export type ColRef = {
16
16
  readonly table?: string;
17
17
  readonly name: string;
18
18
  /**
19
- * Projection-only wire transform, postgres only. `castText` renders
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
+ * The other transforms are postgres only. `castText` renders
20
23
  * `"col"::text AS "col"`, `encodeBase64` renders
21
24
  * `encode("col", 'base64') AS "col"`. Two users: the lateral subselect (SQL
22
25
  * review B3 — raw `to_jsonb` would ship BigInt/Decimal as float64 JSON
@@ -26,7 +29,7 @@ export type ColRef = {
26
29
  * the runtime parses the array literal text itself). Never set on
27
30
  * filter/order refs.
28
31
  */
29
- readonly transform?: "castText" | "encodeBase64";
32
+ readonly transform?: "castText" | "encodeBase64" | "jsonText";
30
33
  /**
31
34
  * Comparison/order/aggregate cast, sqlite Decimal only (SQL review B4):
32
35
  * Decimal stores as exact TEXT there and text comparison is lexicographic —
@@ -637,13 +640,17 @@ export declare function excludedRef(params: {
637
640
  /** Is this SET cell an {@link ExcludedRef}? */
638
641
  export declare function isExcludedRef(value: unknown): value is ExcludedRef;
639
642
  /**
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.
643
+ * One RETURNING column: a bare column name renders `"col"`; `castText` renders
644
+ * `"col"::text AS "col"` (postgres only) for `Float[]`/`Json[]`. `jsonText`
645
+ * applies the dialect's JSON text projection, as {@link ColRef.transform} does
646
+ * for SELECT. Dialects without RETURNING still omit the clause and flag it.
643
647
  */
644
648
  export type ReturningColumn = string | {
645
649
  readonly name: string;
646
650
  readonly castText: true;
651
+ } | {
652
+ readonly name: string;
653
+ readonly transform: "jsonText";
647
654
  };
648
655
  /** The column name a {@link ReturningColumn} exposes in the result row. */
649
656
  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
package/dist/index.d.ts CHANGED
@@ -20,8 +20,15 @@ export { renderSqliteFtsUpdateTrigger, sqliteFtsUpdateUpgrade } from "./dialects
20
20
  export { SQLITE_SESSION_SQL } from "./dialects/sqlite-session.ts";
21
21
  export { sql, isSqlFragment, renderSqlFragment, compileSql, sqlUsesIncoming, mapConflictColumns } from "./composable.ts";
22
22
  export type { SqlFragment, SqlTag } from "./composable.ts";
23
- export { decode } from "./result-decoder.ts";
24
- export type { ResultDecoder, Decoded, ExtendedDateTime } from "./result-decoder.ts";
23
+ export { createSqlQuery, createSqlCommand, isSqlQuery, isSqlCommand, compileSqlQuery, compileSqlCommand } from "./query-plan.ts";
24
+ export type { SqlQuery, SqlCommand, SqlPlanRender, CompiledSqlQuery, CompiledSqlCommand, ReusableSqlQuery, ReusableSqlCommand } from "./query-plan.ts";
25
+ export { createReusableSqlQuery, createReusableSqlCommand, isReusableSqlQuery, isReusableSqlCommand, compileReusableSqlQuery, compileReusableSqlCommand } from "./query-plan.ts";
26
+ export { isSqlParam, createSqlInput, sqlInputContract, createSqlInputScope, sealSqlInputScope, assertSqlParamBuilding, sqlParamContract } from "./sql-input.ts";
27
+ export type { SqlParam, SqlInput, SqlInputMap, SqlInputValue, SqlInputValues, SqlInputTokens, SqlExecutionParams, SqlInputContract, SqlInputScope } from "./sql-input.ts";
28
+ export { isSqlBindingCollector, recordSqlBinding, recordSqlBindingCheck } from "./sql-bindings.ts";
29
+ export type { SqlBindingSource, SqlParameterTransport, SqlBindingEncoder } from "./sql-bindings.ts";
30
+ export { decode, encode, resultScalarContract } from "./result-decoder.ts";
31
+ export type { ResultDecoder, ResultReadDecoder, ResultParameterEncoder, ResultScalarContract, Decoded, ExtendedDateTime } from "./result-decoder.ts";
25
32
  /**
26
33
  * @vibeorm/sql — dialect-aware SQL layer for VibeORM v2.
27
34
  *
@@ -42,10 +49,11 @@ export { tableDefinitionParts } from "./dialects/sqlite-table-definition.ts";
42
49
  export { renderPredicate } from "./predicate.ts";
43
50
  export type { PredicateModel, PredicateUsage } from "./predicate.ts";
44
51
  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";
52
+ export { DIALECT_CODECS, MYSQL_CODECS, POSTGRES_CODECS, SQLITE_CODECS, decodeIsNoop, enumMembershipCodec, float32Codec, parseDateTimeText, parseJsonText, postgresArrayElementFromText, shortestFloat32, timeOfDayCodec, } from "./codecs.ts";
46
53
  export type { CodecTable, ScalarCodec, WireFidelity } from "./codecs.ts";
47
54
  export { renderExpr, renderFragment, renderProjection, renderStatement } from "./render.ts";
48
55
  export type { RenderedQuery } from "./render.ts";
56
+ export { snapshotSqlValue } from "./parameter-snapshot.ts";
49
57
  export { ParamCollector } from "./params.ts";
50
58
  export { NATIVE_RLS, renderRlsColumnType, renderRlsContext, renderRlsDisable, renderRlsDropPolicy, renderRlsEnable, renderRlsForce, renderRlsNoForce, renderRlsPolicy, renderRlsPredicate, renderRlsRole } from "./dialects/postgres-rls.ts";
51
59
  export type { RlsContextStatement, RlsDisableStatement, RlsDropPolicyStatement, RlsEnableStatement, RlsForceStatement, RlsNoForceStatement, RlsPolicyStatement, RlsRoleStatement } from "./ast.ts";