@vibeorm/sql 2.5.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ast.d.ts +339 -12
  3. package/dist/codecs.d.ts +57 -0
  4. package/dist/dialect.d.ts +54 -0
  5. package/dist/dialects/postgres-index-keys.d.ts +1 -0
  6. package/dist/dialects/postgres-physical-catalog.d.ts +7 -1
  7. package/dist/dialects/sqlite-fts.d.ts +28 -0
  8. package/dist/index.d.ts +19 -7
  9. package/dist/index.js +2100 -983
  10. package/dist/index.js.map +26 -20
  11. package/dist/json-list-parameter.d.ts +37 -0
  12. package/dist/parameter-snapshot.d.ts +6 -0
  13. package/dist/params.d.ts +7 -8
  14. package/dist/pg-array.d.ts +13 -0
  15. package/dist/query/expressions.d.ts +70 -0
  16. package/dist/query/index.d.ts +6 -0
  17. package/dist/query/index.js +1078 -0
  18. package/dist/query/index.js.map +16 -0
  19. package/dist/query/mutations.d.ts +15 -0
  20. package/dist/query/reusable.d.ts +17 -0
  21. package/dist/query/select.d.ts +11 -0
  22. package/dist/query/sources.d.ts +37 -0
  23. package/dist/query/state.d.ts +73 -0
  24. package/dist/query/types.d.ts +188 -0
  25. package/dist/query-plan.d.ts +97 -0
  26. package/dist/render.d.ts +11 -1
  27. package/dist/result-decoder.d.ts +41 -10
  28. package/dist/sql-bindings.d.ts +84 -0
  29. package/dist/sql-input.d.ts +98 -0
  30. package/package.json +9 -3
  31. package/dist/ast.d.ts.map +0 -1
  32. package/dist/capabilities.d.ts.map +0 -1
  33. package/dist/codecs.d.ts.map +0 -1
  34. package/dist/composable.d.ts.map +0 -1
  35. package/dist/dialect.d.ts.map +0 -1
  36. package/dist/dialects/constraint-owned-index.d.ts.map +0 -1
  37. package/dist/dialects/diagnostics.d.ts.map +0 -1
  38. package/dist/dialects/external-dependents.d.ts.map +0 -1
  39. package/dist/dialects/external-ownership.d.ts.map +0 -1
  40. package/dist/dialects/migration-history.d.ts.map +0 -1
  41. package/dist/dialects/migration-inventory.d.ts.map +0 -1
  42. package/dist/dialects/migration-objects.d.ts.map +0 -1
  43. package/dist/dialects/migration-replay-coverage.d.ts.map +0 -1
  44. package/dist/dialects/migration-shadow.d.ts.map +0 -1
  45. package/dist/dialects/migration-visibility.d.ts.map +0 -1
  46. package/dist/dialects/module-dependency.d.ts.map +0 -1
  47. package/dist/dialects/mysql-check-probe.d.ts.map +0 -1
  48. package/dist/dialects/mysql.d.ts.map +0 -1
  49. package/dist/dialects/postgres-default-identity.d.ts.map +0 -1
  50. package/dist/dialects/postgres-diagnostics.d.ts.map +0 -1
  51. package/dist/dialects/postgres-index-keys.d.ts.map +0 -1
  52. package/dist/dialects/postgres-migration.d.ts.map +0 -1
  53. package/dist/dialects/postgres-physical-catalog.d.ts.map +0 -1
  54. package/dist/dialects/postgres-rls-readiness.d.ts.map +0 -1
  55. package/dist/dialects/postgres-rls.d.ts.map +0 -1
  56. package/dist/dialects/postgres-type-identity.d.ts.map +0 -1
  57. package/dist/dialects/postgres.d.ts.map +0 -1
  58. package/dist/dialects/registry.d.ts.map +0 -1
  59. package/dist/dialects/sqlite-constraints.d.ts.map +0 -1
  60. package/dist/dialects/sqlite-session.d.ts.map +0 -1
  61. package/dist/dialects/sqlite-table-definition.d.ts.map +0 -1
  62. package/dist/dialects/sqlite.d.ts.map +0 -1
  63. package/dist/exclusion.d.ts.map +0 -1
  64. package/dist/identifiers.d.ts.map +0 -1
  65. package/dist/index-columns.d.ts.map +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/json-transport.d.ts.map +0 -1
  68. package/dist/like.d.ts.map +0 -1
  69. package/dist/locks.d.ts.map +0 -1
  70. package/dist/module-journal.d.ts.map +0 -1
  71. package/dist/native-enum-parameter.d.ts.map +0 -1
  72. package/dist/params.d.ts.map +0 -1
  73. package/dist/pg-array.d.ts.map +0 -1
  74. package/dist/predicate.d.ts.map +0 -1
  75. package/dist/render.d.ts.map +0 -1
  76. package/dist/result-decoder.d.ts.map +0 -1
@@ -0,0 +1,37 @@
1
+ declare const JSON_LIST_PARAMETER: unique symbol;
2
+ /**
3
+ * The element type of a postgres Json LIST column: `jsonb[]` by default,
4
+ * `json[]` for `Json[] @db.Json`. Comparison sites (`has`, `hasEvery`,
5
+ * `hasSome`, `equals`) render a `json` operand and its column as jsonb —
6
+ * `json` has no equality operator; write sites (`push`) keep `json`.
7
+ */
8
+ export type JsonListStorage = "jsonb" | "json";
9
+ /**
10
+ * A Json LIST parameter — one element's JSON text (`has`, `push` of one
11
+ * element) or a whole list of JSON texts (`hasEvery`, `hasSome`, `equals`,
12
+ * `push` of an array) — plus the column's element type. Never passed to a
13
+ * driver: the ParamCollector collects the plain value and renders
14
+ * `$n::text::jsonb` (or `$n::text::jsonb[]` for a whole list).
15
+ *
16
+ * Why it exists: an OID-typed driver (bun:sql with named statements) resolves
17
+ * the parameter's postgres type and re-serializes the JS value AS that type. A
18
+ * pre-stringified JSON element bound into a slot the server infers as `jsonb`
19
+ * (`$n = ANY("col")`, `array_append("col", $n)`) arrives DOUBLE-ENCODED, and
20
+ * `has: { a: 1 }` then matches nothing (live-proven on Bun 1.4.3). The `::text`
21
+ * pin makes every driver send the text and the SERVER parse it — the same
22
+ * trap `JsonParamCell` closes for Json columns.
23
+ */
24
+ export type JsonListParameter = {
25
+ readonly [JSON_LIST_PARAMETER]: true;
26
+ readonly value: string | readonly string[];
27
+ readonly storage: JsonListStorage;
28
+ };
29
+ /** Attach the json/jsonb element type to an encoded Json list operand, without re-encoding it. */
30
+ export declare function jsonListParameter(params: {
31
+ value: string | readonly string[];
32
+ storage: JsonListStorage;
33
+ }): JsonListParameter;
34
+ /** Narrow the internal typed parameter before collecting its plain wire value. */
35
+ export declare function isJsonListParameter(value: unknown): value is JsonListParameter;
36
+ export {};
37
+ //# sourceMappingURL=json-list-parameter.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Snapshot mutable values while preserving plain-object and array validation evidence.
3
+ * Reusable execution bags pass `isHandle` so authentic SQL handles refuse at every depth.
4
+ */
5
+ export declare function snapshotSqlValue(value: unknown, ancestors?: ReadonlySet<object>, isHandle?: (value: object) => boolean): unknown;
6
+ //# sourceMappingURL=parameter-snapshot.d.ts.map
package/dist/params.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- /**
2
- * Parameter collection during rendering.
3
- *
4
- * The single place placeholder indices are produced — renderers never
5
- * hand-write `$1`/`?`, so numbering and value order can never drift apart.
6
- */
7
1
  import type { SqlDialect } from "./dialect.ts";
8
2
  export declare class ParamCollector {
9
3
  private readonly dialect;
4
+ private reserved;
10
5
  readonly values: unknown[];
11
6
  constructor(dialect: SqlDialect);
12
- /** Register one parameter value; returns its placeholder text. */
7
+ /** @internal Allocate recorded positions without inserting sample values. */
8
+ reserve(): string;
9
+ /** Actual positional slots, including repeats of a named input. */
10
+ count(): number;
11
+ /** Register one value; ordinary and reusable paths share transport spelling. */
13
12
  add(value: unknown): string;
14
- /** Register many values; returns their placeholders in order. */
13
+ /** Register many values in positional order. */
15
14
  addMany(values: readonly unknown[]): string[];
16
15
  }
17
16
  //# sourceMappingURL=params.d.ts.map
@@ -11,4 +11,17 @@ export declare function toPgArrayLiteral(params: {
11
11
  export declare function parsePgArrayLiteral(params: {
12
12
  literal: string;
13
13
  }): (string | null)[] | null;
14
+ /** One element of a parsed array literal: its text, SQL NULL, or one nested dimension. */
15
+ export type PgArrayLiteralElement = string | null | readonly PgArrayLiteralElement[];
16
+ /**
17
+ * Parse a postgres array literal of ANY number of dimensions —
18
+ * `{{1,2},{3,NULL}}` becomes `[["1","2"],["3",null]]`, the nesting
19
+ * node-postgres returns for a known array type — or `null` when the text is
20
+ * not a well-formed literal. Explicit bounds (`[1:2][0:1]=`) are dropped.
21
+ * {@link parsePgArrayLiteral} stays the one-dimensional fast path; it would
22
+ * split `{{1,2}}` at every comma.
23
+ */
24
+ export declare function parsePgArrayLiteralNested(params: {
25
+ literal: string;
26
+ }): PgArrayLiteralElement[] | null;
14
27
  //# sourceMappingURL=pg-array.d.ts.map
@@ -0,0 +1,70 @@
1
+ import type { ResultDecoder, ResultReadDecoder, SqlFragment, SqlInputContract } from "@vibeorm/sql";
2
+ import type { ColumnDefinition, Expression, Expressions } from "./types.ts";
3
+ import type { RenderContext } from "./state.ts";
4
+ export declare function nullableDecoder<T>(decoder: ResultReadDecoder<T>): ResultReadDecoder<T | null>;
5
+ export declare function assertDecoder(decoder: ResultReadDecoder<unknown>): void;
6
+ /** Keep physical native refinements in the central codec implementations. */
7
+ export declare function nativeColumnDefinition(definition: ColumnDefinition<unknown>): ColumnDefinition<unknown>;
8
+ /** Transport conversion belongs only at the final result boundary. */
9
+ export declare function transportProjection(params: {
10
+ context: RenderContext;
11
+ expression: string;
12
+ definition: ColumnDefinition<unknown>;
13
+ }): string;
14
+ /** Write contracts carry encoding identity independently from projection output. */
15
+ export declare function columnInputContract(definition: ColumnDefinition<unknown>): SqlInputContract;
16
+ export declare function bindColumnValue(params: {
17
+ context: RenderContext;
18
+ definition: ColumnDefinition<unknown>;
19
+ value: unknown;
20
+ encoder?: ResultDecoder<unknown>;
21
+ rejectNull?: boolean;
22
+ }): string;
23
+ /** Construct a typed value for the public qb.value contract. */
24
+ export declare function literal<T>(params: {
25
+ value: T;
26
+ decoder: ResultDecoder<T>;
27
+ }): Expression<T>;
28
+ /** Construct an explicit fragment projection for the public qb.raw contract. */
29
+ export declare function rawExpression<T>(params: {
30
+ sql: SqlFragment;
31
+ decoder: ResultReadDecoder<T>;
32
+ references?: readonly Expression<unknown>[];
33
+ }): Expression<T>;
34
+ /** Compare typed operands for equality, preserving SQL NULL propagation. */
35
+ export declare const eq: Expressions["eq"];
36
+ /** Compare typed operands for inequality. */
37
+ export declare const ne: Expressions["ne"];
38
+ /** Compare typed operands using greater-than. */
39
+ export declare const gt: Expressions["gt"];
40
+ /** Compare typed operands using greater-than-or-equal. */
41
+ export declare const gte: Expressions["gte"];
42
+ /** Compare typed operands using less-than. */
43
+ export declare const lt: Expressions["lt"];
44
+ /** Compare typed operands using less-than-or-equal. */
45
+ export declare const lte: Expressions["lte"];
46
+ /** Test SQL NULL without comparing a bound null value. */
47
+ export declare const isNull: Expressions["isNull"];
48
+ /** Test SQL non-nullness without comparing a bound null value. */
49
+ export declare const isNotNull: Expressions["isNotNull"];
50
+ /** Combine predicates with SQL AND; an empty conjunction is true. */
51
+ export declare const and: Expressions["and"];
52
+ /** Combine predicates with SQL OR; an empty disjunction is false. */
53
+ export declare const or: Expressions["or"];
54
+ /** Negate a predicate with SQL's three-valued boolean semantics. */
55
+ export declare const not: Expressions["not"];
56
+ /** Match a literal list; an empty list is false. */
57
+ export declare const inList: Expressions["inList"];
58
+ /** Exclude a literal list; an empty list is true. */
59
+ export declare const notInList: Expressions["notInList"];
60
+ /** Count rows or non-null expression values with exact bigint transport. */
61
+ export declare const count: Expressions["count"];
62
+ /** Minimum of a qualified ordered scalar, nullable for empty input. */
63
+ export declare const min: Expressions["min"];
64
+ /** Maximum of a qualified ordered scalar, nullable for empty input. */
65
+ export declare const max: Expressions["max"];
66
+ /** Sum of a qualified double-precision Float, nullable for empty input. */
67
+ export declare const sum: Expressions["sum"];
68
+ /** Average of a qualified double-precision Float, nullable for empty input. */
69
+ export declare const avg: Expressions["avg"];
70
+ //# sourceMappingURL=expressions.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { QueryBuilder } from "./types.ts";
2
+ /** Opt-in native SQL builder. Core fragments/plans are bare-imported from @vibeorm/sql. */
3
+ export declare const qb: QueryBuilder;
4
+ export { and, avg, count, eq, gt, gte, inList, isNotNull, isNull, lt, lte, max, min, ne, not, notInList, or, sum } from "./expressions.ts";
5
+ export type { ColumnDefinition, ColumnDefinitions, Columns, Expression, Expressions, MutationBuilder, NullableRow, Order, Projection, ProjectionRow, QueryBuilder, Scope, SelectBuilder, Source, Table, WriteValues } from "./types.ts";
6
+ //# sourceMappingURL=index.d.ts.map