@crvouga/mockingbird-service-postgres 3.6.0 → 3.8.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.
@@ -0,0 +1,32 @@
1
+ export interface SchemaReportOptions {
2
+ /** Hard upper bounds are 4 MiB, 10,000 statements and 1,000 diagnostics. */
3
+ maxInputBytes?: number;
4
+ maxStatements?: number;
5
+ maxDiagnostics?: number;
6
+ }
7
+ export interface SchemaDiagnostic {
8
+ statement: number;
9
+ offset: number;
10
+ line: number;
11
+ column: number;
12
+ object?: string;
13
+ sqlstate: string | null;
14
+ category: "unsupported" | "syntax" | "prerequisite" | "execution" | "unknown" | "limit";
15
+ message: string;
16
+ prerequisiteStatement?: number;
17
+ }
18
+ export interface SchemaReport {
19
+ /** Identifies the local implementation; this is not a live PostgreSQL compatibility assertion. */
20
+ engine: "mockingbird-postgres";
21
+ version: string;
22
+ statements: number;
23
+ accepted: number;
24
+ /** false means a detected gap; null means semantics still require oracle verification. */
25
+ compatible: false | null;
26
+ truncated: boolean;
27
+ diagnostics: SchemaDiagnostic[];
28
+ }
29
+ /** Analyze plain schema SQL in a discarded in-memory database, without network or filesystem access.
30
+ * Successful execution is explicitly unverified: function bodies and dynamic SQL are not proved.
31
+ */
32
+ export declare function analyzeSchema(sql: string, options?: SchemaReportOptions): SchemaReport;
@@ -555,6 +555,7 @@ export interface CreateSequenceStmt {
555
555
  readonly options: SequenceOptions;
556
556
  }
557
557
  export interface AlterSequenceStmt {
558
+ readonly renameTo?: string;
558
559
  readonly type: "alter_sequence";
559
560
  readonly name: string[];
560
561
  readonly ifExists: boolean;
@@ -623,6 +624,7 @@ export interface CreateFunctionStmt {
623
624
  readonly language: string;
624
625
  readonly body: string | null;
625
626
  readonly sqlBody: Statement[] | null;
627
+ readonly settings?: Record<string, string>;
626
628
  readonly volatility: "immutable" | "stable" | "volatile" | null;
627
629
  readonly strict: boolean;
628
630
  }
@@ -643,6 +645,11 @@ export interface CreateTriggerStmt {
643
645
  readonly when: Expr | null;
644
646
  readonly funcName: string[];
645
647
  readonly funcArgs: string[];
648
+ /** `REFERENCING { OLD | NEW } TABLE [AS] name` items in source order; validated when the trigger is created */
649
+ readonly transitions?: ReadonlyArray<{
650
+ isNew: boolean;
651
+ name: string;
652
+ }>;
646
653
  }
647
654
  export type AlterTableAction = {
648
655
  kind: "add_column";
@@ -1,6 +1,12 @@
1
+ import type { Expr } from "../ast/nodes.js";
1
2
  import type { ExecEnv } from "../executor/relation.js";
2
3
  import type { IndexMeta, TableData } from "../storage/database-state.js";
3
- import { type Datum } from "../types/value.js";
4
+ import { type Datum, type TypeId } from "../types/value.js";
5
+ /**
6
+ * The type an expression over `table` yields, found by evaluating it against an all-NULL row.
7
+ * Binding errors (unknown column or function) surface as they would when PostgreSQL parses the expression.
8
+ */
9
+ export declare function expressionTypeOf(env: ExecEnv, table: TableData, expr: Expr): TypeId;
4
10
  /** NOT NULL column constraints (23502). */
5
11
  export declare function checkNotNull(env: ExecEnv, table: TableData, row: Datum[]): void;
6
12
  /** CHECK constraints (23514); NULL results pass. */
@@ -8,6 +8,7 @@ export interface RelColumn {
8
8
  table: string | null;
9
9
  /** hidden columns (e.g. ORDER BY helpers) are excluded from final output */
10
10
  hidden?: boolean;
11
+ system?: boolean;
11
12
  }
12
13
  export interface Relation {
13
14
  columns: RelColumn[];
@@ -16,5 +16,18 @@ export type TriggerExecutor = (env: ExecEnv, table: TableData, trigger: TriggerM
16
16
  export declare function setTriggerExecutor(e: TriggerExecutor): void;
17
17
  export declare function fireRowTriggers(env: ExecEnv, table: TableData, timing: "before" | "after" | "instead_of", event: TriggerEvent, oldRow: Datum[] | null, newRow: Datum[] | null): TriggerFireResult;
18
18
  export declare function hasRowTriggers(table: TableData, timing: "before" | "after" | "instead_of", event: TriggerEvent): boolean;
19
+ /** The rows a statement changed, as the `REFERENCING` transition tables of its AFTER statement triggers. */
20
+ export interface TransitionRows {
21
+ /** rows before the change (UPDATE, DELETE) */
22
+ oldRows: Datum[][];
23
+ /** rows after the change (INSERT, UPDATE); position-aligned with `oldRows` for UPDATE */
24
+ newRows: Datum[][];
25
+ }
26
+ /**
27
+ * Fire the statement-level triggers of `table` for `event`, once, in trigger-name order. AFTER triggers
28
+ * that declare transition tables read them as relations named by their `REFERENCING` clause; the
29
+ * function body sees nothing else of the statement (no outer CTEs, parameters or scope).
30
+ */
31
+ export declare function fireStatementTriggers(env: ExecEnv, table: TableData, timing: "before" | "after", event: TriggerEvent, transitions?: TransitionRows): void;
19
32
  export declare function flushConstraintTriggers(state: DatabaseState, all?: boolean): void;
20
33
  export declare function setConstraints(state: DatabaseState, stmt: SetConstraintsStmt): void;
@@ -8,12 +8,16 @@ import { type TypeId } from "../types/value.js";
8
8
  */
9
9
  export declare class EngineCtx implements CastEnv, CompareCtx {
10
10
  readonly state: DatabaseState;
11
+ private writeXid;
12
+ rowVersionXid(): number;
11
13
  /** transaction timestamp (now(), current_timestamp) — UTC micros since PG epoch */
12
14
  readonly txNow: bigint;
13
15
  /** statement timestamp */
14
16
  readonly stmtNow: bigint;
15
17
  constructor(state: DatabaseState, txNow?: bigint);
16
18
  timezone(): string;
19
+ relationOid(parts: string[]): number;
20
+ relationName(oid: number): string | null;
17
21
  namespaceOid(name: string): number;
18
22
  namespaceName(oid: number): string | null;
19
23
  zoneOffsetAt(utcMicros: bigint): number;
@@ -1,7 +1,7 @@
1
- import type { CreateIndexStmt } from "../ast/nodes.js";
1
+ import type { CreateIndexStmt, Expr } from "../ast/nodes.js";
2
2
  import type { EngineCtx } from "../expressions/context.js";
3
3
  import type { DatabaseState, FunctionData, TableData } from "../storage/database-state.js";
4
- import { type TypedValue } from "../types/value.js";
4
+ import { type TypedValue, type TypeId } from "../types/value.js";
5
5
  export declare function pgTrgmSchema(state: DatabaseState): string | null;
6
6
  export declare function pgTrgmInstalled(state: DatabaseState): boolean;
7
7
  export declare function installPgTrgm(state: DatabaseState, schemaName: string): void;
@@ -11,10 +11,10 @@ export declare function evalPgTrgmFunction(ctx: EngineCtx, fn: FunctionData, arg
11
11
  export declare function evalTrgmWordSimilar(ctx: EngineCtx, left: TypedValue, right: TypedValue): TypedValue;
12
12
  /**
13
13
  * Reject `gin_trgm_ops` unless pg_trgm is installed for access method gin.
14
- * A single text/varchar column is stored as an ordinary non-unique index:
14
+ * A single text/varchar column or expression is stored as an ordinary non-unique index:
15
15
  * lookup speed is not modelled.
16
16
  */
17
- export declare function assertGinTrgmIndex(state: DatabaseState, table: TableData, stmt: CreateIndexStmt): void;
17
+ export declare function assertGinTrgmIndex(state: DatabaseState, table: TableData, stmt: CreateIndexStmt, expressionType: (expr: Expr) => TypeId): void;
18
18
  /** `|intersection| / |union|` as float4. Either empty trigram set yields 0. */
19
19
  export declare function trigramSimilarity(left: string, right: string): number;
20
20
  /**
package/dist/index.d.ts CHANGED
@@ -26,3 +26,4 @@ export type { BindValue, JsValue, QueryRow } from "./api/bind.js";
26
26
  export { Database, type DatabaseFaults, type DatabaseHistory, type DatabaseOptions, type HistoryCheckpoint, type QueryOptions, type RegisterFunctionOptions, Snapshot, } from "./api/database.js";
27
27
  export { type ResultSet, type RunResult, Statement } from "./api/statement.js";
28
28
  export { type ErrorCategory, PostgresError } from "./errors/error.js";
29
+ export { analyzeSchema, type SchemaReport, type SchemaReportOptions, type SchemaDiagnostic, } from "./api/schema-report.js";