@sixb/pg 0.1.14 → 0.1.15
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/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +742 -312
- package/dist/index.js.map +14 -14
- package/dist/latest-run-query.d.ts +2 -0
- package/dist/latest-run-query.d.ts.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-state.d.ts.map +1 -1
- package/dist/ontology-storage/shared.d.ts +12 -9
- package/dist/ontology-storage/shared.d.ts.map +1 -1
- package/dist/ontology-storage/source-cleanup.d.ts +7 -1
- package/dist/ontology-storage/source-cleanup.d.ts.map +1 -1
- package/dist/ontology-storage/source-roots.d.ts +8 -0
- package/dist/ontology-storage/source-roots.d.ts.map +1 -1
- package/dist/ontology-storage/sources.d.ts +8 -3
- package/dist/ontology-storage/sources.d.ts.map +1 -1
- package/dist/pg-client.d.ts +2 -0
- package/dist/pg-client.d.ts.map +1 -1
- package/dist/pg-projection-run-storage.d.ts +3 -1
- package/dist/pg-projection-run-storage.d.ts.map +1 -1
- package/dist/storage-errors.d.ts +13 -3
- package/dist/storage-errors.d.ts.map +1 -1
- package/dist/transactions.d.ts +23 -1
- package/dist/transactions.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +8 -1
- package/src/latest-run-query.ts +10 -2
- package/src/migrations/051-projection-run-supersession.sql +43 -0
- package/src/migrations/052-compact-source-storage.sql +118 -0
- package/src/migrations.ts +26 -23
- package/src/ontology-storage/materialization-state.ts +20 -46
- package/src/ontology-storage/shared.ts +18 -12
- package/src/ontology-storage/source-cleanup.ts +66 -22
- package/src/ontology-storage/source-roots.ts +164 -102
- package/src/ontology-storage/sources.ts +150 -120
- package/src/pg-client.ts +132 -2
- package/src/pg-projection-run-storage.ts +56 -2
- package/src/storage-errors.ts +101 -15
- package/src/transactions.ts +113 -20
|
@@ -19,6 +19,8 @@ export declare function queryLatestRunsByOwnerId<TRow>(input: {
|
|
|
19
19
|
readonly projectId: string;
|
|
20
20
|
readonly ownerIdFor: (row: TRow) => string;
|
|
21
21
|
readonly selectList?: PgLatestRunSelectList;
|
|
22
|
+
/** A status that never counts as the latest run, such as a run made stale by a newer one. */
|
|
23
|
+
readonly excludedStatus?: string;
|
|
22
24
|
} & PgLatestRunTarget): Promise<readonly TRow[]>;
|
|
23
25
|
export {};
|
|
24
26
|
//# sourceMappingURL=latest-run-query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latest-run-query.d.ts","sourceRoot":"","sources":["../src/latest-run-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,aAAa,CAAA;AAE1D,KAAK,iBAAiB,GAClB;IAAE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAA;CAAE,GAC5E;IAAE,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAA;CAAE,GAChF;IAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAA;CAAE,GACpE;IAAE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAA;CAAE,CAAA;AAEhF,KAAK,qBAAqB,GAAG,GAAG,GAAG,iDAAiD,CAAA;AAEpF,wBAAsB,wBAAwB,CAAC,IAAI,EACjD,KAAK,EAAE;IACL,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,CAAA;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"latest-run-query.d.ts","sourceRoot":"","sources":["../src/latest-run-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,aAAa,CAAA;AAE1D,KAAK,iBAAiB,GAClB;IAAE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAA;CAAE,GAC5E;IAAE,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAA;CAAE,GAChF;IAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAA;CAAE,GACpE;IAAE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAA;CAAE,CAAA;AAEhF,KAAK,qBAAqB,GAAG,GAAG,GAAG,iDAAiD,CAAA;AAEpF,wBAAsB,wBAAwB,CAAC,IAAI,EACjD,KAAK,EAAE;IACL,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,CAAA;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,qBAAqB,CAAA;IAC3C,6FAA6F;IAC7F,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC,GAAG,iBAAiB,GACpB,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAmC1B"}
|
package/dist/migrations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.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AE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxF;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5E;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKrD;AAuKD,eAAO,MAAM,yBAAyB,wCAwDpC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialization-state.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materialization-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EACnB,MAAM,qCAAqC,CAAA;AAgB5C,OAAO,KAAK,EACV,gCAAgC,EAChC,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAO5B,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"materialization-state.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materialization-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EACnB,MAAM,qCAAqC,CAAA;AAgB5C,OAAO,KAAK,EACV,gCAAgC,EAChC,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAO5B,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAkB7C,eAAO,MAAM,6BAA6B,kCAAkC,CAAA;AAC5E,eAAO,MAAM,yBAAyB,8BAA8B,CAAA;AAyEpE,MAAM,MAAM,mBAAmB,GAC3B;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ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,EAAE,EAC9E,WAAW,UAAQ,GAClB,OAAO,CAAC,SAAS,0BAA0B,EAAE,CAAC;IAyB3C,uBAAuB,CAC3B,GAAG,EAAE,iBAAiB,EACtB,IAAI,UAAQ,GACX,OAAO,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAI/E,wBAAwB,CAC5B,IAAI,EAAE,SAAS,iBAAiB,EAAE,EAClC,IAAI,UAAQ,GACX,OAAO,CACR,WAAW,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CACxF;IAoCK,uBAAuB,CAC3B,GAAG,EAAE,eAAe,EACpB,IAAI,UAAQ,GACX,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAI/B,wBAAwB,CAC5B,IAAI,EAAE,SAAS,eAAe,EAAE,EAChC,IAAI,UAAQ,GACX,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;YA4BhC,kBAAkB;YA8BlB,4BAA4B;YAQ5B,yBAAyB;YA0BzB,uBAAuB;CAgHtC;AAkMD,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAM3D;AAUD,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CASzD"}
|
|
@@ -22,6 +22,7 @@ export interface PgOntologyCommitRow {
|
|
|
22
22
|
readonly committed_at: Date | string;
|
|
23
23
|
}
|
|
24
24
|
export interface PgOntologySourceRow {
|
|
25
|
+
readonly version_id: string;
|
|
25
26
|
readonly project_id: string;
|
|
26
27
|
readonly source_id: string;
|
|
27
28
|
readonly materialization_id: string;
|
|
@@ -47,19 +48,21 @@ export interface PgOntologySourceRow {
|
|
|
47
48
|
readonly last_commit_id: string | null;
|
|
48
49
|
readonly updated_at: Date | string;
|
|
49
50
|
}
|
|
51
|
+
/** An assertion with its root and version, as `sourceAssertionColumns` selects it. */
|
|
50
52
|
export interface PgOntologySourceAssertionRow {
|
|
51
|
-
readonly project_id: string;
|
|
52
53
|
readonly source_id: string;
|
|
53
54
|
readonly materialization_id: string;
|
|
54
|
-
readonly
|
|
55
|
-
readonly entity_key: unknown;
|
|
56
|
-
readonly entity_sort_key: string;
|
|
57
|
-
readonly root_kind: "object" | "link";
|
|
58
|
-
readonly root_key: unknown;
|
|
59
|
-
readonly root_sort_key: string;
|
|
55
|
+
readonly root_key: string;
|
|
60
56
|
readonly staging_ordinal: number | string;
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
57
|
+
readonly entity_kind: "object" | "link";
|
|
58
|
+
readonly object_type_id: string | null;
|
|
59
|
+
readonly primary_id: string | null;
|
|
60
|
+
readonly source_type_id: string | null;
|
|
61
|
+
readonly source_primary_id: string | null;
|
|
62
|
+
readonly link_id: string | null;
|
|
63
|
+
readonly target_type_id: string | null;
|
|
64
|
+
readonly target_primary_id: string | null;
|
|
65
|
+
readonly payload: unknown;
|
|
63
66
|
}
|
|
64
67
|
export interface PgStoredOverrideRow {
|
|
65
68
|
readonly value: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/shared.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,yCAAyC,EACzC,oBAAoB,EAEpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,q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C,IAAI,CAAC,CA2Df;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEjF"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type { CleanupTerminalSourceMaterializationsInput, CleanupTerminalSourceMaterializationsResult } from "@sixb/core/storage";
|
|
1
|
+
import type { CleanupTerminalSourceMaterializationsInput, CleanupTerminalSourceMaterializationsResult, PurgeAbandonedSourceMaterializationsInput } from "@sixb/core/storage";
|
|
2
2
|
import type { SQLClient } from "../pg-client";
|
|
3
|
+
/**
|
|
4
|
+
* Superseded versions can still hold live roots (a delta keeps unchanged roots where they were),
|
|
5
|
+
* so they are cleaned root by root once retired. An abandoned candidate was never published:
|
|
6
|
+
* everything it holds goes, one whole version at a time, each delete on its own version prefix.
|
|
7
|
+
*/
|
|
8
|
+
export declare function purgeAbandonedSourceVersions(sql: SQLClient, input: PurgeAbandonedSourceMaterializationsInput): Promise<CleanupTerminalSourceMaterializationsResult>;
|
|
3
9
|
export declare function cleanupSourceVersions(sql: SQLClient, input: CleanupTerminalSourceMaterializationsInput): Promise<CleanupTerminalSourceMaterializationsResult>;
|
|
4
10
|
//# sourceMappingURL=source-cleanup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-cleanup.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/source-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,2CAA2C,
|
|
1
|
+
{"version":3,"file":"source-cleanup.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/source-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,2CAA2C,EAC3C,yCAAyC,EAC1C,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C;;;;GAIG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,yCAAyC,GAC/C,OAAO,CAAC,2CAA2C,CAAC,CAwCtD;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,0CAA0C,GAChD,OAAO,CAAC,2CAA2C,CAAC,CA4CtD"}
|
|
@@ -3,6 +3,11 @@ import type { SourceActivationWrite, StageSourceRowsInput } from "@sixb/core/sto
|
|
|
3
3
|
import type { SQLClient } from "../pg-client";
|
|
4
4
|
import type { PgOntologySourceAssertionRow } from "./shared";
|
|
5
5
|
import { type PgOntologySourceRow } from "./shared";
|
|
6
|
+
/** The columns `sourceAssertion` reads, over `versions`, `roots` and `rows`. */
|
|
7
|
+
export declare function sourceAssertionColumns(sql: SQLClient): import("postgres").PendingQuery<(import("postgres").Row & Iterable<import("postgres").Row>)[]>;
|
|
8
|
+
/** Keeps `rows` to those of live roots in `projectId`, joined as `roots` and `versions`. */
|
|
9
|
+
export declare function liveSourceRowsJoin(sql: SQLClient, projectId: string): import("postgres").PendingQuery<import("postgres").Row[]>;
|
|
10
|
+
/** The candidate's rows, plus the rows of the live roots it may replace. */
|
|
6
11
|
export declare function replacementSourceRows(sql: SQLClient, input: {
|
|
7
12
|
readonly projectId: string;
|
|
8
13
|
readonly sourceId: string;
|
|
@@ -10,9 +15,12 @@ export declare function replacementSourceRows(sql: SQLClient, input: {
|
|
|
10
15
|
readonly incremental: boolean;
|
|
11
16
|
}): import("postgres").PendingQuery<import("postgres").Row[]>;
|
|
12
17
|
export declare function stageSourceRoots(sql: SQLClient, manifest: PgOntologySourceRow, input: StageSourceRowsInput): Promise<void>;
|
|
18
|
+
/** Retires what the candidate replaces; its own roots go live when its version turns active. */
|
|
13
19
|
export declare function activateSourceRoots(sql: SQLClient, projectId: string, candidate: PgOntologySourceRow, activation: SourceActivationWrite): Promise<void>;
|
|
14
20
|
export declare function assertSourceRootCoverage(sql: SQLClient, manifest: PgOntologySourceRow): Promise<void>;
|
|
21
|
+
/** The live assertions of `refs`, whichever source asserts them. */
|
|
15
22
|
export declare function activeSourceRows(sql: SQLClient, projectId: string, refs: readonly ProjectionEntityRef[]): import("postgres").PendingQuery<PgOntologySourceAssertionRow[]>;
|
|
23
|
+
/** The candidate's assertions of `refs`, and optionally the live ones they would replace. */
|
|
16
24
|
export declare function replacementAssertionRows(sql: SQLClient, input: {
|
|
17
25
|
projectId: string;
|
|
18
26
|
sourceId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-roots.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/source-roots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"source-roots.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/source-roots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAU9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAC5D,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAalE,gFAAgF;AAChF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,SAAS,kGAKpD;AAED,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,6DAOnE;AAgDD,4EAA4E;AAC5E,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,SAAS,EACd,KAAK,EAAE;IACL,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC9B,6DA8BF;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,SAAS,EACd,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,gGAAgG;AAChG,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,mBAAmB,EAC9B,UAAU,EAAE,qBAAqB,GAChC,OAAO,CAAC,IAAI,CAAC,CAiCf;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,SAAS,EACd,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,mBAAmB,EAAE,mEAgBrC;AAED,6FAA6F;AAC7F,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,SAAS,EACd,KAAK,EAAE;IACL,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,eAAe,EAAE,OAAO,CAAA;IACxB,IAAI,EAAE,SAAS,mBAAmB,EAAE,CAAA;CACrC,mEAyCF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbandonSourceMaterializationCandidateInput, BeginSourceMaterializationInput, CleanupTerminalSourceMaterializationsInput, CleanupTerminalSourceMaterializationsResult, GetActiveOntologySourceInput, MarkSourceMaterializationReadyInput, OntologySourceRecord, OntologySourceStorage,
|
|
1
|
+
import type { AbandonRunSourceMaterializationInput, AbandonSourceMaterializationCandidateInput, AdoptedSourceMaterialization, AdoptSourceMaterializationInput, BeginSourceMaterializationInput, CleanupTerminalSourceMaterializationsInput, CleanupTerminalSourceMaterializationsResult, GetActiveOntologySourceInput, MarkSourceMaterializationReadyInput, OntologySourceRecord, OntologySourceStorage, PurgeAbandonedSourceMaterializationsInput, StageSourceRowsInput, StageSourceRowsResult, SummarizeTerminalSourceMaterializationsInput, TerminalSourceMaterializationSummary } from "@sixb/core/storage";
|
|
2
2
|
import { type PgRootOperation } from "./shared";
|
|
3
3
|
export declare class PgOntologySourceStorage implements OntologySourceStorage {
|
|
4
4
|
private readonly runRootOperation;
|
|
@@ -7,14 +7,19 @@ export declare class PgOntologySourceStorage implements OntologySourceStorage {
|
|
|
7
7
|
stageRows(input: StageSourceRowsInput): Promise<StageSourceRowsResult>;
|
|
8
8
|
markReady(input: MarkSourceMaterializationReadyInput): Promise<OntologySourceRecord>;
|
|
9
9
|
getActive(input: GetActiveOntologySourceInput): Promise<OntologySourceRecord | null>;
|
|
10
|
+
adopt(input: AdoptSourceMaterializationInput): Promise<AdoptedSourceMaterialization | null>;
|
|
10
11
|
abandon(input: AbandonSourceMaterializationCandidateInput): Promise<OntologySourceRecord>;
|
|
11
|
-
abandon(input:
|
|
12
|
+
abandon(input: AbandonRunSourceMaterializationInput): Promise<OntologySourceRecord | null>;
|
|
12
13
|
cleanupTerminal(input: CleanupTerminalSourceMaterializationsInput): Promise<CleanupTerminalSourceMaterializationsResult>;
|
|
14
|
+
purgeAbandoned(input: PurgeAbandonedSourceMaterializationsInput): Promise<CleanupTerminalSourceMaterializationsResult>;
|
|
13
15
|
summarizeTerminal(input: SummarizeTerminalSourceMaterializationsInput): Promise<TerminalSourceMaterializationSummary>;
|
|
14
16
|
private abandonCandidate;
|
|
15
|
-
|
|
17
|
+
/** The run's one staging or ready candidate, locked, whichever execution staged it. */
|
|
18
|
+
private lockRunCandidate;
|
|
19
|
+
private lastStagedOrdinal;
|
|
16
20
|
private transitionToAbandoned;
|
|
17
21
|
private assertReadyState;
|
|
22
|
+
/** Already staged assertions sharing a root or an ordinal with `rows`. */
|
|
18
23
|
private findStageRows;
|
|
19
24
|
private insertStageRows;
|
|
20
25
|
private assertExecution;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/sources.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,0CAA0C,
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/sources.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,oCAAoC,EACpC,0CAA0C,EAE1C,4BAA4B,EAC5B,+BAA+B,EAE/B,+BAA+B,EAC/B,0CAA0C,EAC1C,2CAA2C,EAC3C,4BAA4B,EAC5B,mCAAmC,EACnC,oBAAoB,EACpB,qBAAqB,EACrB,yCAAyC,EACzC,oBAAoB,EACpB,qBAAqB,EACrB,4CAA4C,EAC5C,oCAAoC,EACrC,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAUL,KAAK,eAAe,EAIrB,MAAM,UAAU,CAAA;AAIjB,qBAAa,uBAAwB,YAAW,qBAAqB;IACvD,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,eAAe;IAExD,oBAAoB,CACxB,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,oBAAoB,CAAC;IA8E1B,SAAS,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA2BtE,SAAS,CAAC,KAAK,EAAE,mCAAmC,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6DpF,SAAS,CAAC,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAapF,KAAK,CACT,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;IA+BzC,OAAO,CAAC,KAAK,EAAE,0CAA0C,GAAG,OAAO,CAAC,oBAAoB,CAAC;IACzF,OAAO,CAAC,KAAK,EAAE,oCAAoC,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAa1F,eAAe,CACnB,KAAK,EAAE,0CAA0C,GAChD,OAAO,CAAC,2CAA2C,CAAC;IASjD,cAAc,CAClB,KAAK,EAAE,yCAAyC,GAC/C,OAAO,CAAC,2CAA2C,CAAC;IAQjD,iBAAiB,CACrB,KAAK,EAAE,4CAA4C,GAClD,OAAO,CAAC,oCAAoC,CAAC;YAqBlC,gBAAgB;IA2B9B,uFAAuF;YACzE,gBAAgB;YAwBhB,iBAAiB;YAQjB,qBAAqB;YAgCrB,gBAAgB;IA2F9B,0EAA0E;YAC5D,aAAa;YAsBb,eAAe;IA0C7B,OAAO,CAAC,eAAe;YAkBT,eAAe;YAef,WAAW;YAkBX,eAAe;CAW9B"}
|
package/dist/pg-client.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type SQL = postgres.Sql<Record<string, never>>;
|
|
|
18
18
|
* `begin`/`reserve`/`end`).
|
|
19
19
|
*/
|
|
20
20
|
export type SQLClient = postgres.ISql<Record<string, never>>;
|
|
21
|
+
/** One pool connection held outside the pool until `release()` — see `withReservedPgConnection`. */
|
|
22
|
+
export type ReservedSQL = postgres.ReservedSql<Record<string, never>>;
|
|
21
23
|
/**
|
|
22
24
|
* A value accepted as a positional parameter by {@link SQLClient.unsafe}. Dynamically built
|
|
23
25
|
* parameter arrays (from the query-IR compiler / run-list helpers) are cast to this since
|
package/dist/pg-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-client.d.ts","sourceRoot":"","sources":["../src/pg-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg-client.d.ts","sourceRoot":"","sources":["../src/pg-client.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAY/B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AAErD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AAE,qBAAqB,GAAG,GAAG,CAkDlE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AdvanceProjectionTelemetryCheckpointInput, ExecutionStorage, FailProjectionRunEnqueueInput, FinishProjectionRunInput, ListLatestProjectionRunsInput, ListLatestProjectionRunsResult, ListProjectionRunsInput, ListProjectionRunsResult, LockProjectionRunForMaterializationInput, ProjectionRunClaim, ProjectionRunRecord, ProjectionRunStorage, QueueProjectionRunInput, RecordProjectionMissingTargetInput, StartOrReclaimProjectionRunInput, TelemetryProjectionRunRecord, UpdateProjectionRunInput } from "@sixb/core/storage";
|
|
1
|
+
import type { AdvanceProjectionTelemetryCheckpointInput, ExecutionStorage, FailProjectionRunEnqueueInput, FindSupersedingProjectionRunInput, FinishProjectionRunInput, ListLatestProjectionRunsInput, ListLatestProjectionRunsResult, ListProjectionRunsInput, ListProjectionRunsResult, LockProjectionRunForMaterializationInput, ProjectionRunClaim, ProjectionRunRecord, ProjectionRunStorage, QueueProjectionRunInput, RecordProjectionAttemptFailureInput, RecordProjectionMissingTargetInput, StartOrReclaimProjectionRunInput, TelemetryProjectionRunRecord, UpdateProjectionRunInput } from "@sixb/core/storage";
|
|
2
2
|
import { type PgStoreClient } from "./transactions";
|
|
3
3
|
export declare class PgProjectionRunStorage implements ProjectionRunStorage {
|
|
4
4
|
private readonly sql;
|
|
@@ -9,6 +9,7 @@ export declare class PgProjectionRunStorage implements ProjectionRunStorage {
|
|
|
9
9
|
failEnqueue(input: FailProjectionRunEnqueueInput): Promise<ProjectionRunRecord>;
|
|
10
10
|
lockForMaterialization(input: LockProjectionRunForMaterializationInput): Promise<ProjectionRunRecord>;
|
|
11
11
|
update(input: UpdateProjectionRunInput): Promise<ProjectionRunRecord>;
|
|
12
|
+
recordAttemptFailure(input: RecordProjectionAttemptFailureInput): Promise<ProjectionRunRecord>;
|
|
12
13
|
finish(input: FinishProjectionRunInput): Promise<ProjectionRunRecord>;
|
|
13
14
|
advanceTelemetryCheckpoint(input: AdvanceProjectionTelemetryCheckpointInput): Promise<TelemetryProjectionRunRecord>;
|
|
14
15
|
recordMissingTarget(input: RecordProjectionMissingTargetInput): Promise<TelemetryProjectionRunRecord>;
|
|
@@ -17,6 +18,7 @@ export declare class PgProjectionRunStorage implements ProjectionRunStorage {
|
|
|
17
18
|
id: string;
|
|
18
19
|
}): Promise<ProjectionRunRecord | null>;
|
|
19
20
|
list(input: ListProjectionRunsInput): Promise<ListProjectionRunsResult>;
|
|
21
|
+
findSupersedingRun(input: FindSupersedingProjectionRunInput): Promise<ProjectionRunRecord | null>;
|
|
20
22
|
listLatestByProjectionIds(input: ListLatestProjectionRunsInput): Promise<ListLatestProjectionRunsResult>;
|
|
21
23
|
}
|
|
22
24
|
//# sourceMappingURL=pg-projection-run-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-projection-run-storage.d.ts","sourceRoot":"","sources":["../src/pg-projection-run-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg-projection-run-storage.d.ts","sourceRoot":"","sources":["../src/pg-projection-run-storage.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EACV,yCAAyC,EACzC,gBAAgB,EAChB,6BAA6B,EAC7B,iCAAiC,EACjC,wBAAwB,EACxB,6BAA6B,EAC7B,8BAA8B,EAC9B,uBAAuB,EACvB,wBAAwB,EACxB,wCAAwC,EAExC,kBAAkB,EAClB,mBAAmB,EAEnB,oBAAoB,EACpB,uBAAuB,EACvB,mCAAmC,EACnC,kCAAkC,EAClC,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAoB,KAAK,aAAa,EAAoB,MAAM,gBAAgB,CAAA;AAEvF,qBAAa,sBAAuB,YAAW,oBAAoB;IAE/D,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,gBAAgB;IAGzC,KAAK,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkFnE,cAAc,CAAC,KAAK,EAAE,gCAAgC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8BpF,WAAW,CAAC,KAAK,EAAE,6BAA6B,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAwB/E,sBAAsB,CAC1B,KAAK,EAAE,wCAAwC,GAC9C,OAAO,CAAC,mBAAmB,CAAC;IAOzB,MAAM,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuBrE,oBAAoB,CACxB,KAAK,EAAE,mCAAmC,GACzC,OAAO,CAAC,mBAAmB,CAAC;IAkBzB,MAAM,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2BrE,0BAA0B,CAC9B,KAAK,EAAE,yCAAyC,GAC/C,OAAO,CAAC,4BAA4B,CAAC;IA6BlC,mBAAmB,CACvB,KAAK,EAAE,kCAAkC,GACxC,OAAO,CAAC,4BAA4B,CAAC;IAwBlC,OAAO,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IASvF,IAAI,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAyFvE,kBAAkB,CACtB,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IA4BhC,yBAAyB,CAC7B,KAAK,EAAE,6BAA6B,GACnC,OAAO,CAAC,8BAA8B,CAAC;CAa3C"}
|
package/dist/storage-errors.d.ts
CHANGED
|
@@ -11,8 +11,18 @@ export declare function isForeignKeyViolation(error: unknown): boolean;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function isRetryableTransactionConflict(error: unknown): boolean;
|
|
13
13
|
/**
|
|
14
|
-
* True when the error
|
|
15
|
-
*
|
|
14
|
+
* True when the error means the session is gone: PostgreSQL has already rolled back its open
|
|
15
|
+
* transaction and released its locks, and nothing more may be sent on that connection.
|
|
16
|
+
*
|
|
17
|
+
* PostgreSQL ends the session after every `FATAL` or `PANIC` error — `pg_terminate_backend` (57P01),
|
|
18
|
+
* a server shutdown (57P02), `idle_in_transaction_session_timeout` (25P03) — so the severity decides
|
|
19
|
+
* rather than a list of SQLSTATEs.
|
|
16
20
|
*/
|
|
17
|
-
export declare function
|
|
21
|
+
export declare function isConnectionLost(error: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Replace an error that says something about the database rather than the statement: a lost or
|
|
24
|
+
* unopenable connection becomes the retryable `storage.unavailable`, a full lock table an error
|
|
25
|
+
* naming the table and the setting that sizes it. Every other error is returned unchanged.
|
|
26
|
+
*/
|
|
27
|
+
export declare function explainPgError(error: unknown): unknown;
|
|
18
28
|
//# sourceMappingURL=storage-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-errors.d.ts","sourceRoot":"","sources":["../src/storage-errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage-errors.d.ts","sourceRoot":"","sources":["../src/storage-errors.ts"],"names":[],"mappings":"AAmEA,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAQ9D;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGtE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAsBtD"}
|
package/dist/transactions.d.ts
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import type { SQL, SQLClient } from "./pg-client";
|
|
1
|
+
import type { ReservedSQL, SQL, SQLClient } from "./pg-client";
|
|
2
2
|
export type PgStoreClient = SQL | SQLClient;
|
|
3
3
|
export interface RunPgTransactionOptions {
|
|
4
4
|
/** Open the transaction at an explicit isolation; omit for the server default. */
|
|
5
5
|
readonly isolation?: "repeatableRead" | "serializable";
|
|
6
6
|
}
|
|
7
|
+
type PgTransactionIsolation = "unverifiedDefault" | "repeatableRead" | "serializable";
|
|
7
8
|
export declare function runPgTransaction<T>(sql: PgStoreClient, run: (tx: SQLClient) => Promise<T>, options?: RunPgTransactionOptions): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Hold one pool connection for `run`, and hand it back to the pool only while it is still usable.
|
|
11
|
+
* A connection whose session is gone stays out of the pool, which replaces it on its own.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withReservedPgConnection<T>(sql: SQL, run: (connection: ReservedSQL) => Promise<T>): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Run `run` inside one transaction on a reserved connection.
|
|
16
|
+
*
|
|
17
|
+
* PostgreSQL answers COMMIT with a `ROLLBACK` tag, not an error, when a statement of the
|
|
18
|
+
* transaction failed and the callback caught that error and carried on. That outcome is surfaced
|
|
19
|
+
* as an error: returning normally would report writes that were discarded.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runPgTransactionOn<T>(connection: ReservedSQL, run: () => Promise<T>, isolation?: PgTransactionIsolation): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Run `run`; when it throws, first undo the session state it left on its connection (an open
|
|
24
|
+
* transaction, a session lock), then rethrow. Nothing is undone when the connection itself was lost:
|
|
25
|
+
* the server has already discarded that state, and anything more sent on it would crash
|
|
26
|
+
* postgres.js (see the top of this file).
|
|
27
|
+
*/
|
|
28
|
+
export declare function undoOnFailure<T>(run: () => Promise<T>, undo: () => Promise<unknown>): Promise<T>;
|
|
8
29
|
/**
|
|
9
30
|
* Run a multi-statement read against one proven PostgreSQL snapshot.
|
|
10
31
|
*
|
|
@@ -14,4 +35,5 @@ export declare function runPgTransaction<T>(sql: PgStoreClient, run: (tx: SQLCli
|
|
|
14
35
|
export declare function runPgRepeatableReadTransaction<T>(sql: PgStoreClient, run: (tx: SQLClient) => Promise<T>): Promise<T>;
|
|
15
36
|
export declare function authLockKey(kind: string, ...parts: readonly string[]): string;
|
|
16
37
|
export declare function lockAdvisoryKeys(sql: SQLClient, keys: readonly string[]): Promise<void>;
|
|
38
|
+
export {};
|
|
17
39
|
//# sourceMappingURL=transactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../src/transactions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../src/transactions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAmB9D,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,SAAS,CAAA;AAE3C,MAAM,WAAW,uBAAuB;IACtC,kFAAkF;IAClF,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAA;CACvD;AAED,KAAK,sBAAsB,GAAG,mBAAmB,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAcrF,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,CAAC,CAAC,CAyBZ;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,CAAC,EAC9C,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,CAAC,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3C,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,UAAU,EAAE,WAAW,EACvB,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,SAAS,GAAE,sBAA4C,GACtD,OAAO,CAAC,CAAC,CAAC,CAYZ;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CASZ;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAAC,CAAC,EACpD,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAE7E;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAY7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/pg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "PostgreSQL storage provider for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"postgres": "^3.4.5"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@sixb/core": "0.1.
|
|
43
|
+
"@sixb/core": "0.1.15"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@sixb/core": "0.1.
|
|
46
|
+
"@sixb/core": "0.1.15",
|
|
47
47
|
"@types/bun": "latest",
|
|
48
48
|
"typescript": "^5.7.0"
|
|
49
49
|
},
|
package/src/index.ts
CHANGED
|
@@ -58,7 +58,14 @@ import { registerPostgresStorageTestingAdapter } from "./testing"
|
|
|
58
58
|
import { type PgStoreClient, runPgTransaction } from "./transactions"
|
|
59
59
|
|
|
60
60
|
export interface PostgresStorageOptions {
|
|
61
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Full connection string (e.g. DATABASE_URL). Takes precedence over individual fields.
|
|
63
|
+
*
|
|
64
|
+
* Add `sslnegotiation=direct` (with `sslmode=require`, `verify-ca` or `verify-full`) to open TLS
|
|
65
|
+
* directly, as libpq does against PostgreSQL 17 or later. It saves a round trip per connection
|
|
66
|
+
* and avoids a Bun 1.4.0–1.4.2 bug that keeps in memory every byte read over a TLS connection
|
|
67
|
+
* negotiated the classic way.
|
|
68
|
+
*/
|
|
62
69
|
connectionString?: string
|
|
63
70
|
|
|
64
71
|
/** PostgreSQL host. Defaults to 'localhost'. */
|
package/src/latest-run-query.ts
CHANGED
|
@@ -15,6 +15,8 @@ export async function queryLatestRunsByOwnerId<TRow>(
|
|
|
15
15
|
readonly projectId: string
|
|
16
16
|
readonly ownerIdFor: (row: TRow) => string
|
|
17
17
|
readonly selectList?: PgLatestRunSelectList
|
|
18
|
+
/** A status that never counts as the latest run, such as a run made stale by a newer one. */
|
|
19
|
+
readonly excludedStatus?: string
|
|
18
20
|
} & PgLatestRunTarget
|
|
19
21
|
): Promise<readonly TRow[]> {
|
|
20
22
|
const ownerIds = [...new Set(input.ownerIds)]
|
|
@@ -23,6 +25,12 @@ export async function queryLatestRunsByOwnerId<TRow>(
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const placeholders = ownerIds.map((_, index) => `$${index + 2}`).join(", ")
|
|
28
|
+
const parameters: SqlParameter[] = [input.projectId, ...ownerIds]
|
|
29
|
+
let statusFilter = ""
|
|
30
|
+
if (input.excludedStatus !== undefined) {
|
|
31
|
+
parameters.push(input.excludedStatus)
|
|
32
|
+
statusFilter = ` AND status <> $${parameters.length}`
|
|
33
|
+
}
|
|
26
34
|
const orderColumn =
|
|
27
35
|
input.tableName === "sync_runs" ||
|
|
28
36
|
input.tableName === "pipeline_runs" ||
|
|
@@ -33,10 +41,10 @@ export async function queryLatestRunsByOwnerId<TRow>(
|
|
|
33
41
|
`
|
|
34
42
|
SELECT DISTINCT ON (${input.ownerColumn}) ${input.selectList ?? "*"}
|
|
35
43
|
FROM ${input.tableName}
|
|
36
|
-
WHERE project_id = $1 AND ${input.ownerColumn} IN (${placeholders})
|
|
44
|
+
WHERE project_id = $1 AND ${input.ownerColumn} IN (${placeholders})${statusFilter}
|
|
37
45
|
ORDER BY ${input.ownerColumn}, ${orderColumn} DESC, id DESC
|
|
38
46
|
`,
|
|
39
|
-
|
|
47
|
+
parameters
|
|
40
48
|
)
|
|
41
49
|
|
|
42
50
|
const latestByOwnerId = new Map(rows.map((row) => [input.ownerIdFor(row), row]))
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
-- Projection runs gain the terminal status `superseded`, and a running run may carry the failure
|
|
2
|
+
-- of its last attempt in `error` while the queue retries it.
|
|
3
|
+
|
|
4
|
+
-- The status checks were unnamed. Drop exactly the two that enumerate the terminal statuses, then
|
|
5
|
+
-- replace them with named ones that admit `superseded`.
|
|
6
|
+
DO $$
|
|
7
|
+
DECLARE status_constraint RECORD;
|
|
8
|
+
BEGIN
|
|
9
|
+
FOR status_constraint IN
|
|
10
|
+
SELECT conname
|
|
11
|
+
FROM pg_constraint
|
|
12
|
+
WHERE conrelid = 'projection_runs'::regclass
|
|
13
|
+
AND contype = 'c'
|
|
14
|
+
AND pg_get_constraintdef(oid) LIKE '%''cancelled''%'
|
|
15
|
+
LOOP
|
|
16
|
+
EXECUTE format('ALTER TABLE projection_runs DROP CONSTRAINT %I', status_constraint.conname);
|
|
17
|
+
END LOOP;
|
|
18
|
+
END $$;
|
|
19
|
+
|
|
20
|
+
ALTER TABLE projection_runs
|
|
21
|
+
ADD CONSTRAINT projection_runs_status_check CHECK (
|
|
22
|
+
status IN ('queued', 'running', 'succeeded', 'failed', 'cancelled', 'superseded')
|
|
23
|
+
),
|
|
24
|
+
ADD CONSTRAINT projection_runs_lifecycle_check CHECK (
|
|
25
|
+
(status = 'queued' AND attempt = 0 AND started_at IS NULL AND finished_at IS NULL
|
|
26
|
+
AND error IS NULL)
|
|
27
|
+
OR (status = 'running' AND attempt >= 1 AND started_at IS NOT NULL AND finished_at IS NULL)
|
|
28
|
+
OR (
|
|
29
|
+
status IN ('succeeded', 'failed', 'cancelled', 'superseded')
|
|
30
|
+
AND finished_at IS NOT NULL
|
|
31
|
+
AND (
|
|
32
|
+
(error->>'code' = 'queue.enqueue_failed'
|
|
33
|
+
AND status = 'failed' AND attempt = 0 AND started_at IS NULL)
|
|
34
|
+
OR (COALESCE(error->>'code', '') != 'queue.enqueue_failed'
|
|
35
|
+
AND attempt >= 1 AND started_at IS NOT NULL)
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
),
|
|
39
|
+
-- A run is superseded instead of materialized, so it carries no failure, and only replacement
|
|
40
|
+
-- runs can be: telemetry appends readings rather than replace a source.
|
|
41
|
+
ADD CONSTRAINT projection_runs_superseded_check CHECK (
|
|
42
|
+
status != 'superseded' OR (error IS NULL AND materialization_protocol = 'replacement')
|
|
43
|
+
);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
-- Source versions get a compact surrogate key; roots and rows stop repeating the text triple.
|
|
2
|
+
ALTER TABLE ontology_sources ADD COLUMN version_id BIGINT GENERATED ALWAYS AS IDENTITY;
|
|
3
|
+
ALTER TABLE ontology_sources ADD CONSTRAINT ontology_sources_version_id_key UNIQUE (version_id);
|
|
4
|
+
|
|
5
|
+
ALTER TABLE ontology_source_rows RENAME TO legacy_ontology_source_rows;
|
|
6
|
+
ALTER TABLE ontology_source_roots RENAME TO legacy_ontology_source_roots;
|
|
7
|
+
-- Index names are schema-wide: free them for the new tables.
|
|
8
|
+
DO $$
|
|
9
|
+
DECLARE
|
|
10
|
+
legacy record;
|
|
11
|
+
BEGIN
|
|
12
|
+
FOR legacy IN
|
|
13
|
+
SELECT index_class.relname AS name
|
|
14
|
+
FROM pg_index
|
|
15
|
+
JOIN pg_class AS index_class ON index_class.oid = pg_index.indexrelid
|
|
16
|
+
JOIN pg_class AS table_class ON table_class.oid = pg_index.indrelid
|
|
17
|
+
WHERE table_class.relnamespace = current_schema()::regnamespace
|
|
18
|
+
AND table_class.relname IN ('legacy_ontology_source_rows', 'legacy_ontology_source_roots')
|
|
19
|
+
LOOP
|
|
20
|
+
EXECUTE format('ALTER INDEX %I RENAME TO %I', legacy.name, left('legacy_' || legacy.name, 63));
|
|
21
|
+
END LOOP;
|
|
22
|
+
END $$;
|
|
23
|
+
|
|
24
|
+
-- A root is live while its version is published (active or superseded), it is not retired and
|
|
25
|
+
-- it is not a deletion. Activation therefore writes only the roots it replaces, never its own.
|
|
26
|
+
-- `root_key` is the canonical key; "C" orders it by its UTF-8 bytes.
|
|
27
|
+
CREATE TABLE ontology_source_roots (
|
|
28
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
29
|
+
version_id BIGINT NOT NULL REFERENCES ontology_sources (version_id) ON DELETE RESTRICT,
|
|
30
|
+
project_id TEXT NOT NULL,
|
|
31
|
+
root_key TEXT COLLATE "C" NOT NULL,
|
|
32
|
+
staging_ordinal BIGINT NOT NULL CHECK (staging_ordinal >= 0),
|
|
33
|
+
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
34
|
+
retired_at TIMESTAMPTZ,
|
|
35
|
+
CONSTRAINT ontology_source_roots_key UNIQUE (version_id, root_key),
|
|
36
|
+
CONSTRAINT ontology_source_roots_ordinal UNIQUE (version_id, staging_ordinal)
|
|
37
|
+
);
|
|
38
|
+
CREATE INDEX idx_ontology_source_roots_live
|
|
39
|
+
ON ontology_source_roots (project_id, root_key) WHERE retired_at IS NULL AND NOT deleted;
|
|
40
|
+
CREATE INDEX idx_ontology_source_roots_retired
|
|
41
|
+
ON ontology_source_roots (project_id, retired_at) WHERE retired_at IS NOT NULL;
|
|
42
|
+
|
|
43
|
+
-- A row's identity lives in its typed columns; `payload` is the assertion without kind and ref.
|
|
44
|
+
CREATE TABLE ontology_source_rows (
|
|
45
|
+
root_id BIGINT NOT NULL REFERENCES ontology_source_roots (id) ON DELETE RESTRICT,
|
|
46
|
+
entity_kind TEXT NOT NULL CHECK (entity_kind IN ('object', 'link')),
|
|
47
|
+
object_type_id TEXT,
|
|
48
|
+
primary_id TEXT,
|
|
49
|
+
source_type_id TEXT,
|
|
50
|
+
source_primary_id TEXT,
|
|
51
|
+
link_id TEXT,
|
|
52
|
+
target_type_id TEXT,
|
|
53
|
+
target_primary_id TEXT,
|
|
54
|
+
payload JSONB,
|
|
55
|
+
CHECK (
|
|
56
|
+
(
|
|
57
|
+
entity_kind = 'object'
|
|
58
|
+
AND object_type_id IS NOT NULL AND primary_id IS NOT NULL
|
|
59
|
+
AND source_type_id IS NULL AND source_primary_id IS NULL AND link_id IS NULL
|
|
60
|
+
AND target_type_id IS NULL AND target_primary_id IS NULL
|
|
61
|
+
)
|
|
62
|
+
OR
|
|
63
|
+
(
|
|
64
|
+
entity_kind = 'link'
|
|
65
|
+
AND object_type_id IS NULL AND primary_id IS NULL
|
|
66
|
+
AND source_type_id IS NOT NULL AND source_primary_id IS NOT NULL AND link_id IS NOT NULL
|
|
67
|
+
AND target_type_id IS NOT NULL AND target_primary_id IS NOT NULL
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
CREATE INDEX idx_ontology_source_rows_root ON ontology_source_rows (root_id);
|
|
72
|
+
CREATE INDEX idx_ontology_source_rows_link_source
|
|
73
|
+
ON ontology_source_rows (source_type_id, source_primary_id, link_id)
|
|
74
|
+
WHERE entity_kind = 'link';
|
|
75
|
+
CREATE INDEX idx_ontology_source_rows_link_target
|
|
76
|
+
ON ontology_source_rows (target_type_id, target_primary_id)
|
|
77
|
+
WHERE entity_kind = 'link';
|
|
78
|
+
|
|
79
|
+
-- A published root that was not active is retired, so liveness stays exactly what it was.
|
|
80
|
+
INSERT INTO ontology_source_roots (
|
|
81
|
+
version_id, project_id, root_key, staging_ordinal, deleted, retired_at
|
|
82
|
+
)
|
|
83
|
+
SELECT versions.version_id, roots.project_id,
|
|
84
|
+
convert_from(decode(roots.root_sort_key, 'hex'), 'UTF8'), roots.staging_ordinal, roots.deleted,
|
|
85
|
+
CASE
|
|
86
|
+
WHEN roots.active THEN NULL
|
|
87
|
+
WHEN roots.retired_at IS NOT NULL THEN roots.retired_at
|
|
88
|
+
WHEN versions.status IN ('active', 'superseded') THEN versions.updated_at
|
|
89
|
+
END
|
|
90
|
+
FROM legacy_ontology_source_roots AS roots
|
|
91
|
+
JOIN ontology_sources AS versions USING (project_id, source_id, materialization_id);
|
|
92
|
+
|
|
93
|
+
INSERT INTO ontology_source_rows (
|
|
94
|
+
root_id, entity_kind, object_type_id, primary_id,
|
|
95
|
+
source_type_id, source_primary_id, link_id, target_type_id, target_primary_id, payload
|
|
96
|
+
)
|
|
97
|
+
SELECT roots.id, rows.entity_kind, rows.object_type_id, rows.primary_id,
|
|
98
|
+
rows.source_type_id, rows.source_primary_id, rows.link_id, rows.target_type_id,
|
|
99
|
+
rows.target_primary_id, NULLIF(rows.assertion - 'kind' - 'ref', '{}'::jsonb)
|
|
100
|
+
FROM legacy_ontology_source_rows AS rows
|
|
101
|
+
JOIN ontology_sources AS versions USING (project_id, source_id, materialization_id)
|
|
102
|
+
JOIN ontology_source_roots AS roots
|
|
103
|
+
ON roots.version_id = versions.version_id
|
|
104
|
+
AND roots.root_key = convert_from(decode(rows.root_sort_key, 'hex'), 'UTF8');
|
|
105
|
+
|
|
106
|
+
DO $$
|
|
107
|
+
BEGIN
|
|
108
|
+
IF (SELECT count(*) FROM legacy_ontology_source_roots)
|
|
109
|
+
<> (SELECT count(*) FROM ontology_source_roots)
|
|
110
|
+
OR (SELECT count(*) FROM legacy_ontology_source_rows)
|
|
111
|
+
<> (SELECT count(*) FROM ontology_source_rows) THEN
|
|
112
|
+
RAISE EXCEPTION 'Source roots or rows were lost while compacting source storage.';
|
|
113
|
+
END IF;
|
|
114
|
+
END $$;
|
|
115
|
+
|
|
116
|
+
DROP TABLE legacy_ontology_source_rows;
|
|
117
|
+
DROP TABLE legacy_ontology_source_roots;
|
|
118
|
+
ANALYZE ontology_sources, ontology_source_roots, ontology_source_rows;
|