@crvouga/mockingbird-service-postgres 0.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.
Files changed (118) hide show
  1. package/AGENTS.md +174 -0
  2. package/COMPATIBILITY-AUDIT.md +156 -0
  3. package/COMPATIBILITY.md +87 -0
  4. package/LICENSE +21 -0
  5. package/README.md +416 -0
  6. package/compat/coverage.json +1081 -0
  7. package/compat/divergences.json +195 -0
  8. package/compat/requirements.json +1105 -0
  9. package/compat/scenario-types.ts +98 -0
  10. package/compat/scenarios.ts +98 -0
  11. package/compat/sections/agg.ts +45 -0
  12. package/compat/sections/api.ts +34 -0
  13. package/compat/sections/arr.ts +45 -0
  14. package/compat/sections/cat.ts +47 -0
  15. package/compat/sections/con.ts +32 -0
  16. package/compat/sections/cpy.ts +24 -0
  17. package/compat/sections/cte.ts +29 -0
  18. package/compat/sections/dat.ts +60 -0
  19. package/compat/sections/ddl.ts +55 -0
  20. package/compat/sections/det.ts +20 -0
  21. package/compat/sections/dml.ts +37 -0
  22. package/compat/sections/eco.ts +16 -0
  23. package/compat/sections/err.ts +16 -0
  24. package/compat/sections/exp.ts +53 -0
  25. package/compat/sections/fun.ts +58 -0
  26. package/compat/sections/fzz.ts +41 -0
  27. package/compat/sections/guc.ts +27 -0
  28. package/compat/sections/joi.ts +33 -0
  29. package/compat/sections/jsn.ts +46 -0
  30. package/compat/sections/lim.ts +13 -0
  31. package/compat/sections/par.ts +54 -0
  32. package/compat/sections/pre.ts +26 -0
  33. package/compat/sections/sch.ts +31 -0
  34. package/compat/sections/sel.ts +43 -0
  35. package/compat/sections/seq.ts +31 -0
  36. package/compat/sections/snp.ts +22 -0
  37. package/compat/sections/tok.ts +53 -0
  38. package/compat/sections/trg.ts +57 -0
  39. package/compat/sections/tsr.ts +37 -0
  40. package/compat/sections/txn.ts +39 -0
  41. package/compat/sections/typ.ts +55 -0
  42. package/compat/sections/uni.ts +13 -0
  43. package/compat/sections/win.ts +43 -0
  44. package/compat/smoke-baseline.json +3 -0
  45. package/compat/unsupported-register.json +2524 -0
  46. package/dist/api/bind.d.ts +11 -0
  47. package/dist/api/database.d.ts +87 -0
  48. package/dist/api/snapshot.d.ts +21 -0
  49. package/dist/api/statement.d.ts +51 -0
  50. package/dist/ast/nodes.d.ts +812 -0
  51. package/dist/constraints/enforce.d.ts +40 -0
  52. package/dist/errors/error.d.ts +24 -0
  53. package/dist/executor/ddl.d.ts +23 -0
  54. package/dist/executor/dml.d.ts +10 -0
  55. package/dist/executor/execute.d.ts +11 -0
  56. package/dist/executor/plpgsql.d.ts +72 -0
  57. package/dist/executor/relation.d.ts +60 -0
  58. package/dist/executor/select.d.ts +45 -0
  59. package/dist/executor/session.d.ts +21 -0
  60. package/dist/executor/triggers-exec.d.ts +1 -0
  61. package/dist/executor/triggers.d.ts +16 -0
  62. package/dist/executor/window.d.ts +13 -0
  63. package/dist/expressions/context.d.ts +23 -0
  64. package/dist/expressions/eval.d.ts +42 -0
  65. package/dist/expressions/operators.d.ts +8 -0
  66. package/dist/expressions/pattern.d.ts +20 -0
  67. package/dist/functions/aggregates.d.ts +17 -0
  68. package/dist/functions/array-fns.d.ts +2 -0
  69. package/dist/functions/datetime-fns.d.ts +26 -0
  70. package/dist/functions/datetime-registry.d.ts +2 -0
  71. package/dist/functions/json-fns.d.ts +7 -0
  72. package/dist/functions/math-fns.d.ts +2 -0
  73. package/dist/functions/misc-fns.d.ts +8 -0
  74. package/dist/functions/scalar.d.ts +10 -0
  75. package/dist/functions/srf.d.ts +12 -0
  76. package/dist/functions/string-fns.d.ts +4 -0
  77. package/dist/functions/tsearch-fns.d.ts +2 -0
  78. package/dist/functions/util.d.ts +14 -0
  79. package/dist/functions/window.d.ts +7 -0
  80. package/dist/index.d.ts +28 -0
  81. package/dist/index.js +23581 -0
  82. package/dist/index.js.map +7 -0
  83. package/dist/indexes/index.d.ts +14 -0
  84. package/dist/indexes/maintain.d.ts +11 -0
  85. package/dist/lexer/tokenize.d.ts +8 -0
  86. package/dist/parser/index.d.ts +1 -0
  87. package/dist/parser/parser.d.ts +98 -0
  88. package/dist/planner/access.d.ts +15 -0
  89. package/dist/runtime/assert.d.ts +5 -0
  90. package/dist/runtime/clock.d.ts +14 -0
  91. package/dist/runtime/index.d.ts +3 -0
  92. package/dist/runtime/options.d.ts +34 -0
  93. package/dist/runtime/prng.d.ts +48 -0
  94. package/dist/schema/catalog-tables.d.ts +1 -0
  95. package/dist/schema/catalog.d.ts +12 -0
  96. package/dist/serialization/codec.d.ts +22 -0
  97. package/dist/serialization/index.d.ts +1 -0
  98. package/dist/serialization/wire.d.ts +63 -0
  99. package/dist/sql/deparse.d.ts +3 -0
  100. package/dist/storage/columnar-slab.d.ts +37 -0
  101. package/dist/storage/database-state.d.ts +253 -0
  102. package/dist/transactions/manager.d.ts +25 -0
  103. package/dist/tsearch/stem.d.ts +5 -0
  104. package/dist/tsearch/tsearch.d.ts +59 -0
  105. package/dist/types/cast.d.ts +26 -0
  106. package/dist/types/compare.d.ts +18 -0
  107. package/dist/types/datetime.d.ts +68 -0
  108. package/dist/types/jsonb.d.ts +47 -0
  109. package/dist/types/jsonpath.d.ts +16 -0
  110. package/dist/types/numeric.d.ts +69 -0
  111. package/dist/types/range.d.ts +17 -0
  112. package/dist/types/resolve.d.ts +15 -0
  113. package/dist/types/timezone.d.ts +9 -0
  114. package/dist/types/value.d.ts +99 -0
  115. package/dist/unstable.d.ts +15 -0
  116. package/dist/unstable.js +21810 -0
  117. package/dist/unstable.js.map +7 -0
  118. package/package.json +131 -0
@@ -0,0 +1,25 @@
1
+ import type { DatabaseState } from "../storage/database-state.js";
2
+ /**
3
+ * Single-session transaction manager with copy-on-write snapshots: BEGIN /
4
+ * SAVEPOINT freeze shared catalog objects and capture a shallow clone; writes
5
+ * copy-on-write via ensureWritableTable. ROLLBACK restores the snapshot.
6
+ */
7
+ export declare class TransactionManager {
8
+ private readonly state;
9
+ private base;
10
+ private savepoints;
11
+ private freezeDepth;
12
+ constructor(state: DatabaseState);
13
+ get inTransaction(): boolean;
14
+ private takeSnapshot;
15
+ private restore;
16
+ private thawOnce;
17
+ begin(): void;
18
+ commit(): void;
19
+ rollback(): void;
20
+ savepoint(name: string): void;
21
+ releaseSavepoint(name: string): void;
22
+ rollbackToSavepoint(name: string): void;
23
+ private findSavepoint;
24
+ reset(): void;
25
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Porter2 (Snowball English) stemmer — the algorithm behind PostgreSQL's
3
+ * `english` text search dictionary.
4
+ */
5
+ export declare function stemEnglish(input: string): string;
@@ -0,0 +1,59 @@
1
+ export interface Lexeme {
2
+ word: string;
3
+ positions: Array<{
4
+ pos: number;
5
+ weight: string;
6
+ }>;
7
+ }
8
+ /** Build canonical tsvector text: lexemes sorted, with positions. */
9
+ export declare function toTsvector(config: string, text: string): string;
10
+ /** Parse tsvector text (typinput): `'a':1,2 'b':3A b` */
11
+ export declare function parseTsvector(text: string): string;
12
+ /** tsvector || tsvector: shift right-side positions by the left's max position, merge lexemes. */
13
+ export declare function tsvectorConcat(a: string, b: string): string;
14
+ export declare function tsvectorLexemes(vec: string): Lexeme[];
15
+ export type TsQueryNode = {
16
+ kind: "lexeme";
17
+ word: string;
18
+ prefix: boolean;
19
+ weights: string | null;
20
+ } | {
21
+ kind: "and";
22
+ left: TsQueryNode;
23
+ right: TsQueryNode;
24
+ } | {
25
+ kind: "or";
26
+ left: TsQueryNode;
27
+ right: TsQueryNode;
28
+ } | {
29
+ kind: "not";
30
+ operand: TsQueryNode;
31
+ } | {
32
+ kind: "phrase";
33
+ left: TsQueryNode;
34
+ right: TsQueryNode;
35
+ distance: number;
36
+ };
37
+ export declare function toTsquery(config: string, text: string): string;
38
+ export declare function plaintoTsquery(config: string, text: string): string;
39
+ export declare function phrasetoTsquery(config: string, text: string): string;
40
+ export declare function websearchToTsquery(_config: string, _text: string): string;
41
+ export declare function tsqueryText(node: TsQueryNode | null): string;
42
+ export declare function parseTsqueryText(text: string): TsQueryNode | null;
43
+ /** tsquery || tsquery / tsquery && tsquery */
44
+ export declare function tsqueryCombine(op: "and" | "or", a: string, b: string): string;
45
+ /**
46
+ * ts_headline (minimal): wraps query-matching words of the document in
47
+ * StartSel/StopSel. Fragment selection (MaxWords/MinWords windows) is not
48
+ * implemented — short documents match PG output exactly.
49
+ */
50
+ export declare function tsHeadline(config: string, document: string, query: string, options?: string): string;
51
+ /** !! tsquery */
52
+ export declare function tsqueryNegate(a: string): string;
53
+ export declare function tsvectorMatches(vec: string, query: string): boolean;
54
+ export declare const DEFAULT_RANK_WEIGHTS: number[];
55
+ /** calc_rank + normalization flags (RANK_NORM_*). */
56
+ export declare function tsRank(vec: string, query: string, weights?: number[], method?: number): number;
57
+ export declare function tsvectorLength(vec: string): number;
58
+ export declare function tsvectorStrip(vec: string): string;
59
+ export declare function tsvectorSetweight(vec: string, weight: string): string;
@@ -0,0 +1,26 @@
1
+ import { unsupported } from "../errors/error.js";
2
+ import { type Datum, type InputCtx, type OutputCtx, type TypedValue, type TypeId, type TypeMod } from "./value.js";
3
+ export interface CastEnv extends OutputCtx, InputCtx {
4
+ enumLabels(enumType: TypeId): string[] | null;
5
+ }
6
+ export declare const UTC_CAST_ENV: CastEnv;
7
+ export declare function isTextType(t: TypeId): boolean;
8
+ export declare function isNumericType(t: TypeId): boolean;
9
+ export declare function isDatetimeType(t: TypeId): boolean;
10
+ /** implicit-cast reachability (subset of pg_cast castcontext = 'i') */
11
+ export declare function canImplicitCast(from: TypeId, to: TypeId): boolean;
12
+ export declare function canAssignCast(from: TypeId, to: TypeId): boolean;
13
+ export interface CastOptions {
14
+ explicit?: boolean;
15
+ mod?: TypeMod | null;
16
+ /** true for INSERT/UPDATE assignment (allows assignment casts + typmod coercion with truncation errors) */
17
+ assignment?: boolean;
18
+ }
19
+ /** Cast a typed value to `target`. */
20
+ export declare function castTo(env: CastEnv, value: TypedValue, target: TypeId, opts?: CastOptions): TypedValue;
21
+ export declare function numericFamilyCast(from: TypeId, to: TypeId, v: Datum): Datum;
22
+ /** Apply typmod (varchar(n) truncation checks, numeric(p,s), bpchar padding, time precision). */
23
+ export declare function applyTypmod(_env: CastEnv, t: TypeId, v: Datum, opts: CastOptions): Datum;
24
+ /** unify two types for comparison/set operations (simplified union type resolution) */
25
+ export declare function unifyTypes(a: TypeId, b: TypeId): TypeId | null;
26
+ export { unsupported };
@@ -0,0 +1,18 @@
1
+ import { type Datum, type TypeId } from "./value.js";
2
+ /**
3
+ * Total order for non-null datums of the same type. Text uses C-locale
4
+ * (code point) ordering — the engine's pinned collation.
5
+ *
6
+ * Enum ordering needs label positions; callers pass `enumOrder`.
7
+ */
8
+ export interface CompareCtx {
9
+ enumOrder?(enumType: TypeId, label: string): number;
10
+ }
11
+ export declare const DEFAULT_COMPARE_CTX: CompareCtx;
12
+ export declare function datumCompare(t: TypeId, a: Datum, b: Datum, ctx?: CompareCtx): number;
13
+ export declare function datumEquals(t: TypeId, a: Datum, b: Datum, ctx?: CompareCtx): boolean;
14
+ /**
15
+ * Canonical grouping/uniqueness key. Equal values (2.50 = 2.5, +0 = -0)
16
+ * must map to the same key.
17
+ */
18
+ export declare function datumKey(t: TypeId, v: Datum): string;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Internal representations (mirroring PostgreSQL):
3
+ * - date: integer days since 2000-01-01 (PG epoch); ±Infinity as special
4
+ * - time: bigint microseconds since midnight (0 .. 86_400_000_000 inclusive)
5
+ * - timestamp / timestamptz: bigint microseconds since 2000-01-01 00:00:00 (UTC for tz)
6
+ * - interval: { months, days, micros }
7
+ */
8
+ export declare const PG_EPOCH_JDATE = 2451545;
9
+ export declare const UNIX_EPOCH_MICROS_FROM_PG = -946684800000000n;
10
+ export declare const DATE_POS_INF = 2147483647;
11
+ export declare const DATE_NEG_INF = -2147483648;
12
+ export declare const TS_POS_INF = 9223372036854775807n;
13
+ export declare const TS_NEG_INF = -9223372036854775808n;
14
+ export interface Interval {
15
+ readonly kind: "interval";
16
+ readonly months: number;
17
+ readonly days: number;
18
+ readonly micros: bigint;
19
+ }
20
+ export declare function makeInterval(months: number, days: number, micros: bigint): Interval;
21
+ export declare function isInterval(v: unknown): v is Interval;
22
+ export declare const USECS_PER_DAY = 86400000000n;
23
+ export declare const USECS_PER_HOUR = 3600000000n;
24
+ export declare const USECS_PER_MIN = 60000000n;
25
+ export declare const USECS_PER_SEC = 1000000n;
26
+ export declare function civilToDays(y: number, m: number, d: number): number;
27
+ export declare function daysToCivil(days: number): {
28
+ y: number;
29
+ m: number;
30
+ d: number;
31
+ };
32
+ export declare function isLeapYear(y: number): boolean;
33
+ export declare function daysInMonth(y: number, m: number): number;
34
+ export declare function isValidCivil(y: number, m: number, d: number): boolean;
35
+ /** day of week, 0=Sunday (2000-01-01 was a Saturday = 6) */
36
+ export declare function dayOfWeek(days: number): number;
37
+ /** Parse a date string -> days since 2000-01-01. DateStyle ISO, MDY. */
38
+ export declare function parseDate(text: string): number;
39
+ /** Parse time -> micros since midnight. */
40
+ export declare function parseTime(text: string): bigint;
41
+ /** Parse timestamp (no tz interpretation) -> PG micros. */
42
+ export declare function parseTimestamp(text: string): bigint;
43
+ /**
44
+ * Parse timestamptz -> UTC micros. `sessionOffsetSec` applies when the input
45
+ * has no explicit zone (session TimeZone; we default to UTC).
46
+ */
47
+ export declare function parseTimestampTz(text: string, zoneOffsetForNaive: (naiveMicros: bigint) => number): bigint;
48
+ export declare function formatDate(days: number): string;
49
+ export declare function formatTimeOfDay(micros: bigint): string;
50
+ /** floor-divide micros into (days, timeOfDay) */
51
+ export declare function splitTs(micros: bigint): {
52
+ days: number;
53
+ tod: bigint;
54
+ };
55
+ export declare function formatTimestamp(micros: bigint): string;
56
+ /** Format a UTC timestamptz in a fixed zone offset (seconds east of UTC). */
57
+ export declare function formatTimestampTz(micros: bigint, offsetSec: number): string;
58
+ export declare function parseInterval(text: string): Interval;
59
+ /** Render interval in DateStyle 'postgres' (the default). */
60
+ export declare function formatInterval(v: Interval): string;
61
+ export declare function intervalCmp(a: Interval, b: Interval): number;
62
+ export declare function intervalTotalMicros(v: Interval): bigint;
63
+ export declare function intervalAdd(a: Interval, b: Interval): Interval;
64
+ export declare function intervalNeg(a: Interval): Interval;
65
+ export declare function intervalJustifyHours(v: Interval): Interval;
66
+ export declare function intervalJustifyDays(v: Interval): Interval;
67
+ /** date + interval => timestamp micros arithmetic (add months honoring month-end clamping) */
68
+ export declare function timestampAddInterval(ts: bigint, iv: Interval): bigint;
@@ -0,0 +1,47 @@
1
+ import { type Numeric } from "./numeric.js";
2
+ /**
3
+ * jsonb value tree. Numbers are kept as `numeric` (PG stores jsonb numbers
4
+ * as numeric — `1.50::jsonb` keeps its scale). Object keys are unique;
5
+ * output order is (length, byte order), matching PG jsonb.
6
+ */
7
+ export type JsonbValue = {
8
+ j: "null";
9
+ } | {
10
+ j: "bool";
11
+ v: boolean;
12
+ } | {
13
+ j: "num";
14
+ v: Numeric;
15
+ } | {
16
+ j: "str";
17
+ v: string;
18
+ } | {
19
+ j: "arr";
20
+ v: JsonbValue[];
21
+ } | {
22
+ j: "obj";
23
+ v: Map<string, JsonbValue>;
24
+ };
25
+ export declare const JSONB_NULL: JsonbValue;
26
+ export declare function jsonbBool(v: boolean): JsonbValue;
27
+ export declare function jsonbNum(v: Numeric): JsonbValue;
28
+ export declare function jsonbStr(v: string): JsonbValue;
29
+ export declare function jsonbArr(v: JsonbValue[]): JsonbValue;
30
+ export declare function jsonbObj(entries: Iterable<[string, JsonbValue]>): JsonbValue;
31
+ export declare function parseJsonText(text: string): JsonbValue;
32
+ /** Validate json text without canonicalizing (for `json` type input). */
33
+ export declare function validateJsonText(text: string): void;
34
+ /** jsonb key sort: length first, then byte order (PG lexCompareJsonbStringValue). */
35
+ export declare function jsonbKeyCompare(a: string, b: string): number;
36
+ /** Render jsonb in PG's canonical text form: `{"a": 1, "b": [1, 2]}` */
37
+ export declare function jsonbText(v: JsonbValue): string;
38
+ /** Render as compact json text with insertion order (row_to_json / to_json / composite_to_json). */
39
+ export declare function jsonbCompactText(v: JsonbValue): string;
40
+ /** Structural equality (jsonb = jsonb). */
41
+ export declare function jsonbEquals(a: JsonbValue, b: JsonbValue): boolean;
42
+ /** Total order over jsonb (matches jsonb btree comparison semantics). */
43
+ export declare function jsonbCompare(a: JsonbValue, b: JsonbValue): number;
44
+ /** jsonb containment (@>). */
45
+ export declare function jsonbContains(a: JsonbValue, b: JsonbValue, opts?: {
46
+ allowScalarInArray?: boolean;
47
+ }): boolean;
@@ -0,0 +1,16 @@
1
+ import type { JsonbValue } from "./jsonb.js";
2
+ type PathStep = {
3
+ kind: "member";
4
+ name: string;
5
+ } | {
6
+ kind: "index";
7
+ index: number;
8
+ };
9
+ /** Parse a SQL/JSON path subset: `$`, `.key`, `."key"`, `[n]`. */
10
+ export declare function parseJsonpath(text: string): PathStep[];
11
+ /**
12
+ * First match of a jsonpath against a jsonb document.
13
+ * Missing path → SQL NULL (`null` return). JSON null is `{ j: "null" }`.
14
+ */
15
+ export declare function jsonpathQueryFirst(doc: JsonbValue, pathText: string): JsonbValue | null;
16
+ export {};
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Arbitrary-precision decimal mirroring PostgreSQL's `numeric`.
3
+ *
4
+ * Value = (nan/inf special) or coefficient * 10^-dscale where `coef` is a
5
+ * signed bigint and `dscale` (display scale) is the number of digits after
6
+ * the decimal point. Display scale is significant: `2.50` renders as "2.50".
7
+ */
8
+ export interface Numeric {
9
+ readonly kind: "numeric";
10
+ /** signed coefficient; value = coef * 10^-dscale */
11
+ readonly coef: bigint;
12
+ /** display scale (digits after decimal point), >= 0 */
13
+ readonly dscale: number;
14
+ readonly special: "nan" | "inf" | "-inf" | null;
15
+ }
16
+ export declare function makeNumeric(coef: bigint, dscale: number): Numeric;
17
+ export declare const NUMERIC_NAN: Numeric;
18
+ export declare const NUMERIC_PINF: Numeric;
19
+ export declare const NUMERIC_NINF: Numeric;
20
+ export declare function isNumeric(v: unknown): v is Numeric;
21
+ export declare function numericFromBigInt(v: bigint): Numeric;
22
+ export declare function numericFromNumber(v: number): Numeric;
23
+ /** Parse text into numeric. Throws 22P02 on bad syntax (like numeric_in). */
24
+ export declare function parseNumeric(text: string): Numeric;
25
+ export declare function numericRescale(v: Numeric, dscale: number): Numeric;
26
+ export declare function numericText(v: Numeric): string;
27
+ export declare function numericIsZero(v: Numeric): boolean;
28
+ export declare function numericSign(v: Numeric): number;
29
+ /** Compare (NaN sorts greater than everything, like PG). Returns -1|0|1. */
30
+ export declare function numericCmp(a: Numeric, b: Numeric): number;
31
+ export declare function numericAdd(a: Numeric, b: Numeric): Numeric;
32
+ export declare function numericNeg(a: Numeric): Numeric;
33
+ export declare function numericSub(a: Numeric, b: Numeric): Numeric;
34
+ export declare function numericMul(a: Numeric, b: Numeric): Numeric;
35
+ /** Result scale for division, mirroring numeric.c select_div_scale. */
36
+ export declare function selectDivScale(a: Numeric, b: Numeric): number;
37
+ /** Divide with explicit result scale, rounding half away from zero. */
38
+ export declare function numericDivScaled(a: Numeric, b: Numeric, rscale: number): Numeric;
39
+ export declare function numericDiv(a: Numeric, b: Numeric): Numeric;
40
+ /** Truncated integer division (div(a,b) function semantics). */
41
+ export declare function numericDivTrunc(a: Numeric, b: Numeric): Numeric;
42
+ /** Modulo like numeric_mod: result has scale max(s1, s2), sign of dividend. */
43
+ export declare function numericMod(a: Numeric, b: Numeric): Numeric;
44
+ export declare function numericAbs(a: Numeric): Numeric;
45
+ /** round(v, s): round half away from zero; result dscale = max(s, 0). */
46
+ export declare function numericRound(a: Numeric, s: number): Numeric;
47
+ /** trunc(v, s): truncate toward zero. */
48
+ export declare function numericTrunc(a: Numeric, s: number): Numeric;
49
+ export declare function numericFloor(a: Numeric): Numeric;
50
+ export declare function numericCeil(a: Numeric): Numeric;
51
+ export declare function numericToNumber(a: Numeric): number;
52
+ /** Exact bigint if integral after rounding to scale 0 (half away from zero). */
53
+ export declare function numericToBigInt(a: Numeric): bigint;
54
+ /** sqrt via integer Newton iteration at extended scale. */
55
+ export declare function numericSqrt(a: Numeric): Numeric;
56
+ /** power for numeric with numeric result: ports PG's power_var/power_var_int in fixed point. */
57
+ export declare function numericPower(a: Numeric, b: Numeric): Numeric;
58
+ /** exp(numeric) in fixed point with PG's exp_var display-scale rule. */
59
+ export declare function numericExp(a: Numeric): Numeric;
60
+ /** ln(numeric) in fixed point with PG's numeric_ln display-scale rule. */
61
+ export declare function numericLn(a: Numeric): Numeric;
62
+ /** log(base, x) = ln(x)/ln(base) in fixed point with PG's log_var scale rule. */
63
+ export declare function numericLogBase(base: Numeric, x: Numeric): Numeric;
64
+ /** log10(numeric) in fixed point. */
65
+ export declare function numericLog10(a: Numeric): Numeric;
66
+ /** Apply numeric(precision, scale) typmod constraint. */
67
+ export declare function applyNumericTypmod(v: Numeric, precision: number, scale: number): Numeric;
68
+ /** Strip trailing fractional zeros (used by jsonb number canonicalization is NOT this; PG keeps scale). */
69
+ export declare function numericStripTrailingZeros(v: Numeric): Numeric;
@@ -0,0 +1,17 @@
1
+ /** Canonical int4range datum (PG range type). */
2
+ export interface Int4Range {
3
+ readonly kind: "int4range";
4
+ readonly empty: boolean;
5
+ readonly lower: number | null;
6
+ readonly upper: number | null;
7
+ readonly lowerInc: boolean;
8
+ readonly upperInc: boolean;
9
+ }
10
+ export declare function emptyInt4Range(): Int4Range;
11
+ export declare function makeInt4Range(lower: number | null, upper: number | null, lowerInc: boolean, upperInc: boolean): Int4Range;
12
+ /** typinput for int4range: `[1,10)`, `empty`, `(,)` unbounded. */
13
+ export declare function parseInt4RangeText(text: string): Int4Range;
14
+ export declare function int4RangeText(r: Int4Range): string;
15
+ export declare function isInt4Range(v: unknown): v is Int4Range;
16
+ export declare function int4RangeContains(outer: Int4Range, inner: Int4Range | number): boolean;
17
+ export declare function int4RangeOverlaps(a: Int4Range, b: Int4Range): boolean;
@@ -0,0 +1,15 @@
1
+ import type { TypeName } from "../ast/nodes.js";
2
+ import type { DatabaseState } from "../storage/database-state.js";
3
+ import type { ColumnType } from "./value.js";
4
+ export interface ResolvedType {
5
+ readonly column: ColumnType;
6
+ /** "schema.name" when the name resolved to a domain */
7
+ readonly domain: string | null;
8
+ /** serial pseudo-types need sequence creation in DDL */
9
+ readonly serial: "int2" | "int4" | "int8" | null;
10
+ }
11
+ /**
12
+ * Resolve a parsed type name against the catalog: builtin alias, enum, or
13
+ * domain (searched along search_path). Throws 42704 when nothing matches.
14
+ */
15
+ export declare function resolveTypeName(state: DatabaseState, tn: TypeName): ResolvedType;
@@ -0,0 +1,9 @@
1
+ /** Offset (seconds east of UTC) of `zone` at the given UTC instant. */
2
+ export declare function zoneOffsetAtUtc(zone: string, utcMicros: bigint): number;
3
+ /**
4
+ * Offset for interpreting a naive local timestamp in `zone`
5
+ * (two-pass refinement over {@link zoneOffsetAtUtc}).
6
+ */
7
+ export declare function zoneOffsetForNaive(zone: string, naiveMicros: bigint): number;
8
+ /** Validate a zone string (throws when unrecognized). */
9
+ export declare function validateZone(zone: string): void;
@@ -0,0 +1,99 @@
1
+ import { type Interval } from "./datetime.js";
2
+ import { type JsonbValue } from "./jsonb.js";
3
+ import { type Numeric } from "./numeric.js";
4
+ /**
5
+ * Canonical type ids are lowercase PG internal names: "int4", "text",
6
+ * "timestamptz", … Arrays are `elem + "[]"`. Enums are `"enum:" + qualified
7
+ * name`. "unknown" is the type of untyped string literals; "null" never
8
+ * appears (null datums carry whatever type context provides).
9
+ */
10
+ export type TypeId = string;
11
+ export type Datum = null | boolean | number | bigint | string | Uint8Array | Numeric | Interval | PgArray | PgRecord | JsonbWrap;
12
+ export interface PgArray {
13
+ readonly kind: "pgarray";
14
+ readonly elem: TypeId;
15
+ /** dimension lengths, outermost first; empty array => [] */
16
+ readonly dims: number[];
17
+ /** lower bounds per dimension (default 1) */
18
+ readonly lbs: number[];
19
+ /** row-major flattened items */
20
+ readonly items: Datum[];
21
+ }
22
+ export interface PgRecord {
23
+ readonly kind: "pgrecord";
24
+ readonly types: TypeId[];
25
+ readonly values: Datum[];
26
+ readonly names?: string[];
27
+ }
28
+ /** jsonb datums are wrapped so `typeof` dispatch stays unambiguous. */
29
+ export interface JsonbWrap {
30
+ readonly kind: "jsonb";
31
+ readonly value: JsonbValue;
32
+ }
33
+ export declare function wrapJsonb(value: JsonbValue): JsonbWrap;
34
+ export declare function isJsonbWrap(v: unknown): v is JsonbWrap;
35
+ export declare function isPgArray(v: unknown): v is PgArray;
36
+ export declare function isPgRecord(v: unknown): v is PgRecord;
37
+ export declare function makeArray(elem: TypeId, items: Datum[], dims?: number[], lbs?: number[]): PgArray;
38
+ export interface TypedValue {
39
+ readonly t: TypeId;
40
+ readonly v: Datum;
41
+ }
42
+ export declare function tv(t: TypeId, v: Datum): TypedValue;
43
+ export declare const UNKNOWN = "unknown";
44
+ export interface TypeMod {
45
+ /** varchar(n)/bpchar(n): max chars; numeric: precision; time/timestamp: fractional digits */
46
+ readonly a?: number;
47
+ /** numeric scale */
48
+ readonly b?: number;
49
+ }
50
+ export interface ColumnType {
51
+ readonly id: TypeId;
52
+ readonly mod: TypeMod | null;
53
+ }
54
+ export declare function normalizeTypeName(name: string): TypeId | null;
55
+ export declare function isArrayType(t: TypeId): boolean;
56
+ export declare function arrayElemType(t: TypeId): TypeId;
57
+ export declare function arrayTypeOf(elem: TypeId): TypeId;
58
+ export declare function isEnumType(t: TypeId): boolean;
59
+ export declare function enumTypeName(t: TypeId): string;
60
+ /** SQL-facing type name (format_type / pg_typeof style). */
61
+ export declare function typeDisplayName(t: TypeId): string;
62
+ export declare const TYPE_OIDS: Record<string, number>;
63
+ export declare function typeOid(t: TypeId): number;
64
+ export declare function float8Text(v: number): string;
65
+ export declare function float4Text(v: number): string;
66
+ export declare function parseFloatText(text: string, type: "float4" | "float8"): number;
67
+ export declare const INT2_MIN = -32768;
68
+ export declare const INT2_MAX = 32767;
69
+ export declare const INT4_MIN = -2147483648;
70
+ export declare const INT4_MAX = 2147483647;
71
+ export declare const INT8_MIN = -9223372036854775808n;
72
+ export declare const INT8_MAX = 9223372036854775807n;
73
+ export declare function checkInt2(v: number): number;
74
+ export declare function checkInt4(v: number): number;
75
+ export declare function checkInt8(v: bigint): bigint;
76
+ export declare function parseBoolText(text: string): boolean;
77
+ export declare function parseByteaText(text: string): Uint8Array;
78
+ export declare function byteaText(v: Uint8Array): string;
79
+ export declare function parseUuidText(text: string): string;
80
+ export declare function parseMoneyText(text: string): bigint;
81
+ export declare function moneyText(cents: bigint): string;
82
+ export interface OutputCtx {
83
+ /** offset seconds east of UTC for rendering timestamptz at given UTC micros */
84
+ zoneOffsetAt(utcMicros: bigint): number;
85
+ }
86
+ export declare const UTC_OUTPUT: OutputCtx;
87
+ export declare function arrayText(arr: PgArray, ctx: OutputCtx): string;
88
+ export declare function recordText(rec: PgRecord, ctx: OutputCtx): string;
89
+ /** Render a non-null datum of type `t` to PG wire text. */
90
+ export declare function datumText(t: TypeId, v: Datum, ctx: OutputCtx): string;
91
+ export interface InputCtx {
92
+ /** session zone offset lookup for naive timestamptz input */
93
+ zoneOffsetForNaive(naiveMicros: bigint): number;
94
+ /** enum label validation: returns true when label is valid for the enum type */
95
+ enumHasLabel?(enumType: TypeId, label: string): boolean;
96
+ }
97
+ export declare const UTC_INPUT: InputCtx;
98
+ /** Parse PG wire text into a datum of type `t` (typinput). */
99
+ export declare function datumFromText(t: TypeId, text: string, ctx: InputCtx): Datum;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Unstable internals of `@crvouga/mockingbird-service-postgres`. Everything exported here is
4
+ * exempt from semver — pin an exact version if you import from this module.
5
+ *
6
+ * @module
7
+ */
8
+ export { executeStatement, makeEnv } from "./executor/execute.js";
9
+ export { EngineCtx } from "./expressions/context.js";
10
+ export { tokenize } from "./lexer/tokenize.js";
11
+ export { parse, parseSingle } from "./parser/index.js";
12
+ export { type Clock, DEFAULT_NOW, fixedClock, systemClock } from "./runtime/clock.js";
13
+ export { deriveSeed, OsEntropy, Prng } from "./runtime/prng.js";
14
+ export { DatabaseState } from "./storage/database-state.js";
15
+ export { type Datum, datumText, type TypedValue, type TypeId } from "./types/value.js";