@crvouga/mockingbird-service-postgres 3.1.0 → 3.3.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 (53) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/COMPATIBILITY.md +35 -5
  3. package/README.md +147 -4
  4. package/compat/coverage.json +8 -7
  5. package/compat/divergences.json +37 -2
  6. package/compat/requirements.json +1 -1
  7. package/compat/sections/cat.ts +49 -0
  8. package/compat/sections/ddl.ts +11 -0
  9. package/compat/unsupported-register.json +0 -3
  10. package/dist/admin.js +3330 -668
  11. package/dist/admin.js.map +4 -4
  12. package/dist/api/database.d.ts +11 -0
  13. package/dist/ast/nodes.d.ts +43 -1
  14. package/dist/constraints/enforce.d.ts +2 -0
  15. package/dist/executor/alter-column.d.ts +27 -0
  16. package/dist/executor/comment.d.ts +4 -0
  17. package/dist/executor/ddl.d.ts +1 -2
  18. package/dist/executor/dml.d.ts +2 -0
  19. package/dist/executor/extensions.d.ts +11 -0
  20. package/dist/executor/maintenance.d.ts +25 -0
  21. package/dist/expressions/context.d.ts +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +3249 -549
  24. package/dist/index.js.map +4 -4
  25. package/dist/parser/parser.d.ts +9 -0
  26. package/dist/schema/catalog-extensions.d.ts +5 -0
  27. package/dist/schema/extensions.d.ts +33 -0
  28. package/dist/schema/index-catalog.d.ts +40 -0
  29. package/dist/schema/persistence.d.ts +32 -0
  30. package/dist/schema/storage.d.ts +22 -0
  31. package/dist/server.js +5384 -743
  32. package/dist/server.js.map +4 -4
  33. package/dist/sql/deparse-default.d.ts +12 -0
  34. package/dist/sql/deparse-index.d.ts +12 -2
  35. package/dist/sql/keywords.d.ts +6 -0
  36. package/dist/sql/ruleutils.d.ts +27 -0
  37. package/dist/storage/database-state.d.ts +51 -0
  38. package/dist/types/regnamespace.d.ts +23 -0
  39. package/dist/types/value.d.ts +2 -0
  40. package/dist/unstable.js +11520 -8875
  41. package/dist/unstable.js.map +4 -4
  42. package/dist/wire/cli.js +5396 -750
  43. package/dist/wire/cli.js.map +4 -4
  44. package/dist/wire/cluster.d.ts +8 -0
  45. package/dist/wire/connection.d.ts +38 -0
  46. package/dist/wire/durable.d.ts +82 -0
  47. package/dist/wire/file-storage.d.ts +3 -0
  48. package/dist/wire/fleet.d.ts +2 -0
  49. package/dist/wire/index.d.ts +21 -1
  50. package/dist/wire/index.js +5383 -741
  51. package/dist/wire/index.js.map +4 -4
  52. package/dist/wire/startup.d.ts +36 -0
  53. package/package.json +1 -1
@@ -19,6 +19,13 @@ export declare class Parser {
19
19
  private qualifiedName;
20
20
  parseStatements(): Statement[];
21
21
  parseStatement(): Statement;
22
+ /**
23
+ * `( option [value] [, ...] )` of ANALYZE / REINDEX. Returns the options that are on;
24
+ * an option outside `known` is the 42601 PostgreSQL raises.
25
+ */
26
+ private parseUtilityOptions;
27
+ private parseAnalyze;
28
+ private parseReindex;
22
29
  private skipToStatementEnd;
23
30
  /** Consume tokens until the matching `)` after an opening `(` already eaten. */
24
31
  private skipBalancedCloseParen;
@@ -54,6 +61,8 @@ export declare class Parser {
54
61
  private parseRefActions;
55
62
  private parseRefAction;
56
63
  private parseColumnDef;
64
+ /** `STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }`: an identifier (not a string) or DEFAULT. */
65
+ private parseStorageMode;
57
66
  private parseIdentityOptions;
58
67
  private parseSequenceOptions;
59
68
  private parseSignedBigInt;
@@ -0,0 +1,5 @@
1
+ import type { Relation } from "../executor/relation.js";
2
+ import type { DatabaseState } from "../storage/database-state.js";
3
+ export declare const EXTENSION_CATALOG_RELATIONS: readonly string[];
4
+ /** Extension catalogs of `pg_catalog`, or null when `name` is not one of them. */
5
+ export declare function extensionCatalogRelation(state: DatabaseState, name: string, namespaceOid: (schema: string) => number): Relation | null;
@@ -0,0 +1,33 @@
1
+ import type { DatabaseState, FunctionData } from "../storage/database-state.js";
2
+ /**
3
+ * Extensions this engine can install, as `pg_available_extensions` lists
4
+ * them. An extension belongs here only when `CREATE EXTENSION` really
5
+ * installs something: everything else stays unavailable and fails loud.
6
+ * Versions and comments are the ones PostgreSQL 18 ships in each control file.
7
+ */
8
+ export interface ExtensionSpec {
9
+ readonly name: string;
10
+ readonly defaultVersion: string;
11
+ /** every version PostgreSQL has an installation script or update path for */
12
+ readonly versions: readonly string[];
13
+ readonly comment: string;
14
+ readonly relocatable: boolean;
15
+ /** set for an extension that is part of every database and lives in a fixed schema */
16
+ readonly builtinSchema?: string;
17
+ }
18
+ export declare const AVAILABLE_EXTENSIONS: readonly ExtensionSpec[];
19
+ export interface InstalledExtension {
20
+ readonly spec: ExtensionSpec;
21
+ readonly version: string;
22
+ readonly schema: string;
23
+ readonly oid: number;
24
+ }
25
+ export declare function findExtensionSpec(name: string): ExtensionSpec | null;
26
+ /**
27
+ * Functions an installed extension owns. `CREATE EXTENSION` marks them with
28
+ * `language = internal` and the extension name as the body, which is what a
29
+ * PGMM snapshot carries, so installation state needs no catalog of its own.
30
+ */
31
+ export declare function extensionMembers(state: DatabaseState, name: string): FunctionData[];
32
+ export declare function installedExtension(state: DatabaseState, spec: ExtensionSpec): InstalledExtension | null;
33
+ export declare function installedExtensions(state: DatabaseState): InstalledExtension[];
@@ -0,0 +1,40 @@
1
+ import type { ConstraintMeta, DatabaseState, IndexMeta, SchemaData, TableData } from "../storage/database-state.js";
2
+ /**
3
+ * Index identity. Every index, including the one PostgreSQL creates behind a
4
+ * PRIMARY KEY or UNIQUE constraint, is an `IndexMeta` in its table's schema with
5
+ * its own oid. `syncIndexCatalog` runs after each statement that can change a
6
+ * table and re-derives the parts of that catalog that follow from the tables:
7
+ * which schema and table an index belongs to, and the indexes that back key
8
+ * constraints. Index objects are shared with transaction snapshots, so every
9
+ * change replaces the entry instead of mutating it.
10
+ */
11
+ export type KeyConstraint = Extract<ConstraintMeta, {
12
+ kind: "primary_key" | "unique";
13
+ }>;
14
+ export declare const isKeyConstraint: (constraint: ConstraintMeta) => constraint is KeyConstraint;
15
+ /** pg_am rows: access method name → [oid, amtype]. */
16
+ export declare const ACCESS_METHODS: ReadonlyMap<string, readonly [oid: number, type: "t" | "i"]>;
17
+ export declare const indexMethod: (index: IndexMeta) => string;
18
+ /** Number of key columns plus INCLUDE columns (`pg_index.indnatts`). */
19
+ export declare const indexAttributeCount: (index: IndexMeta) => number;
20
+ export declare function syncIndexCatalog(state: DatabaseState): void;
21
+ /**
22
+ * The index behind a key constraint is a relation named after the constraint. A name the
23
+ * statement spelled out must be free (42P07); a generated one moves on to the next free
24
+ * name, the way PostgreSQL picks `t_pkey1` when `t_pkey` is already a relation.
25
+ */
26
+ export declare function claimConstraintIndexName(schema: SchemaData, constraint: KeyConstraint, explicit: boolean, reserved?: Set<string>): void;
27
+ export interface FoundIndex {
28
+ schema: SchemaData;
29
+ index: IndexMeta;
30
+ }
31
+ /** Resolve a possibly schema-qualified index name along the search path. */
32
+ export declare function findIndex(state: DatabaseState, parts: readonly string[]): FoundIndex | null;
33
+ export declare function findIndexByOid(state: DatabaseState, oid: number): FoundIndex | null;
34
+ /** The key constraint an index backs, when it backs one. */
35
+ export declare function constraintOfIndex(state: DatabaseState, index: IndexMeta): {
36
+ table: TableData;
37
+ constraint: KeyConstraint;
38
+ } | null;
39
+ /** What kind of non-index relation `parts` names, for "is not an index" errors. */
40
+ export declare function otherRelationKind(state: DatabaseState, parts: readonly string[]): "table" | "view" | "sequence" | null;
@@ -0,0 +1,32 @@
1
+ import type { ConstraintMeta, DatabaseState, SequenceData, TableData } from "../storage/database-state.js";
2
+ /**
3
+ * `pg_class.relpersistence`: `p` permanent (logged), `u` unlogged, `t` temporary.
4
+ *
5
+ * The engine has no write-ahead log, so the three modes store rows the same
6
+ * way. What is modelled is the SQL contract: the catalog value, the
7
+ * transitions `ALTER TABLE ... SET LOGGED | UNLOGGED` allows, and the
8
+ * foreign-key combinations PostgreSQL rejects.
9
+ */
10
+ export type Persistence = "p" | "u" | "t";
11
+ export declare function relPersistence(rel: {
12
+ temp: boolean;
13
+ unlogged?: boolean;
14
+ }): Persistence;
15
+ /**
16
+ * A foreign key may not point at a table that is less durable than the one
17
+ * holding it: permanent tables reference permanent tables, unlogged tables
18
+ * reference permanent or unlogged ones, temporary tables reference temporary
19
+ * ones. `self` is the referencing table when it already exists, so a
20
+ * self-reference is judged against the persistence being created.
21
+ */
22
+ export declare function checkForeignKeyPersistence(state: DatabaseState, persistence: Persistence, constraints: readonly ConstraintMeta[], self?: TableData | null): void;
23
+ /**
24
+ * Validate `ALTER TABLE ... SET LOGGED | UNLOGGED` against the table as it is
25
+ * before the statement runs. Returns false when the table already has the
26
+ * requested persistence (PostgreSQL accepts that as a no-op).
27
+ */
28
+ export declare function prepareLoggedChange(state: DatabaseState, table: TableData, logged: boolean): boolean;
29
+ /** Sequences owned by the table's columns (serial and identity); they follow its persistence. */
30
+ export declare function ownedSequences(state: DatabaseState, table: TableData): SequenceData[];
31
+ /** `ALTER SEQUENCE ... SET LOGGED | UNLOGGED` on a temporary sequence is rejected like a temporary table. */
32
+ export declare function assertSequenceNotTemporary(seq: SequenceData): void;
@@ -0,0 +1,22 @@
1
+ import type { ColumnMeta } from "../storage/database-state.js";
2
+ import { type TypeId } from "../types/value.js";
3
+ /**
4
+ * Column storage strategy as `pg_attribute.attstorage` reports it:
5
+ * `p` PLAIN, `e` EXTERNAL, `x` EXTENDED, `m` MAIN.
6
+ *
7
+ * Only the SQL and catalog contract is modelled. Values are never compressed
8
+ * or moved out of line, so the mode has no effect on how rows are held.
9
+ */
10
+ export type StorageMode = "p" | "e" | "x" | "m";
11
+ /** `pg_type.typstorage`: the strategy a column of this type gets unless `STORAGE` says otherwise. */
12
+ export declare function defaultStorage(type: TypeId): StorageMode;
13
+ /** `pg_attribute.attstorage` for a column: the stored override, else the type default. */
14
+ export declare function columnStorage(column: ColumnMeta): StorageMode;
15
+ /**
16
+ * Resolve a `STORAGE` keyword for a column of `type`, with PostgreSQL's
17
+ * errors: an unknown keyword is 22023, and a type that is not toastable
18
+ * accepts only PLAIN (0A000). Returns `undefined` when the result is the
19
+ * type default, so `SET STORAGE DEFAULT` and an explicit default leave no
20
+ * override behind.
21
+ */
22
+ export declare function resolveStorage(type: TypeId, mode: string): StorageMode | undefined;