@sixb/pg 0.1.13 → 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/auth-storage/auth-storage.d.ts +2 -1
- package/dist/auth-storage/auth-storage.d.ts.map +1 -1
- package/dist/auth-storage/rows.d.ts +1 -1
- package/dist/auth-storage/rows.d.ts.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +779 -357
- package/dist/index.js.map +16 -16
- 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/auth-storage/auth-storage.ts +43 -75
- package/src/auth-storage/rows.ts +1 -1
- package/src/index.ts +8 -1
- package/src/latest-run-query.ts +10 -2
- package/src/migrations/050-directory-group-memberships.sql +5 -0
- package/src/migrations/051-projection-run-supersession.sql +43 -0
- package/src/migrations/052-compact-source-storage.sql +118 -0
- package/src/migrations.ts +30 -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,Q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AAQ,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.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AA6G3B,OAAO,KAAK,EAAe,GAAG,EAAa,MAAM,aAAa,CAAA;AAG9D,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC;AAED,eAAO,MAAM,2BAA2B,wBAAwB,CAAA;AAEhE,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,wBAAwB,CAAC,CAE1F;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/D,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAAC,wBAAwB,CAAC,CAEzC;AAED,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,MAAM,GACjB,SAAS,eAAe,EAAE,CAQ5B;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IACjB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,wBAAwB,CAAC,CAAA;CAC5D,GAAG,eAAe,CAqBlB;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,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,oBAA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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":[],"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1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,yCAAyC,CAAC,UAAU,CAAC,CAAA;CAC1E,GACA,OAAO,CAAC,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;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upTerminalSourceMaterializationsResult, 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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,CAAC,EAAE,MAAM,CAAA;IACtC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAA;CAC9C;AAKD,mDAAmD;AACnD,wBAAgB,cAAc,CAAC,OAAO,EAAE,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,MA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,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,G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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
|
},
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
CompleteSignInResult,
|
|
8
8
|
DeviceAuthorizationRecord,
|
|
9
9
|
GroupMembershipRecord,
|
|
10
|
+
GroupMembershipSource,
|
|
10
11
|
InvitationRecord,
|
|
11
12
|
SessionRecord,
|
|
12
13
|
SuspendUserAndRevokeSessionsInput,
|
|
@@ -232,27 +233,6 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
|
|
235
|
-
if (
|
|
236
|
-
shouldCreateUser &&
|
|
237
|
-
!activeInvitation &&
|
|
238
|
-
input.allowUserCreationWithoutInvitation &&
|
|
239
|
-
input.requireNoActiveUsersForUserCreation &&
|
|
240
|
-
(await hasActiveUsers(tx, projectId))
|
|
241
|
-
) {
|
|
242
|
-
await consumeMagicLink(tx, {
|
|
243
|
-
projectId,
|
|
244
|
-
id: input.magicLinkId,
|
|
245
|
-
tokenHash: input.tokenHash,
|
|
246
|
-
consumedAt: completedAt,
|
|
247
|
-
})
|
|
248
|
-
return {
|
|
249
|
-
error: new AuthStorageError(
|
|
250
|
-
"user_creation_not_allowed",
|
|
251
|
-
`[Sixb] Magic link '${input.magicLinkId}' cannot create a user for project '${projectId}'.`
|
|
252
|
-
),
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
236
|
await validateCompleteSessionInput(tx, projectId, input.session)
|
|
257
237
|
assertSignInSessionAudience(projectId, input.session.audience, magicLink.audience)
|
|
258
238
|
|
|
@@ -294,8 +274,9 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
294
274
|
projectId,
|
|
295
275
|
user,
|
|
296
276
|
})
|
|
297
|
-
const groupMemberships = await this.
|
|
277
|
+
const groupMemberships = await this.applyGroups(tx, {
|
|
298
278
|
completedAt,
|
|
279
|
+
source: "manual",
|
|
299
280
|
existing: invitation.groupMemberships,
|
|
300
281
|
groupIds: manualGroupIds,
|
|
301
282
|
projectId,
|
|
@@ -392,16 +373,6 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
392
373
|
}
|
|
393
374
|
}
|
|
394
375
|
|
|
395
|
-
if (!identity && userRow && (!input.autoLinkByVerifiedEmail || !input.emailVerified)) {
|
|
396
|
-
await this.consumeOidcAttempt(input, completedAt, projectId, tx)
|
|
397
|
-
return {
|
|
398
|
-
error: new AuthStorageError(
|
|
399
|
-
"email_link_not_allowed",
|
|
400
|
-
`[Sixb] OIDC identity cannot auto-link to user '${userRow.id}' for project '${projectId}'.`
|
|
401
|
-
),
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
376
|
if (userRow?.status === "suspended") {
|
|
406
377
|
await this.consumeOidcAttempt(input, completedAt, projectId, tx)
|
|
407
378
|
return {
|
|
@@ -412,16 +383,6 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
412
383
|
}
|
|
413
384
|
}
|
|
414
385
|
|
|
415
|
-
if (shouldCreateUser && !input.emailVerified) {
|
|
416
|
-
await this.consumeOidcAttempt(input, completedAt, projectId, tx)
|
|
417
|
-
return {
|
|
418
|
-
error: new AuthStorageError(
|
|
419
|
-
"user_creation_not_allowed",
|
|
420
|
-
`[Sixb] OIDC authorization attempt '${input.oidcAuthorizationAttemptId}' cannot create a user for project '${projectId}'.`
|
|
421
|
-
),
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
386
|
if (shouldCreateUser && !activeInvitation && !input.allowUserCreationWithoutInvitation) {
|
|
426
387
|
await this.consumeOidcAttempt(input, completedAt, projectId, tx)
|
|
427
388
|
return {
|
|
@@ -432,22 +393,6 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
432
393
|
}
|
|
433
394
|
}
|
|
434
395
|
|
|
435
|
-
if (
|
|
436
|
-
shouldCreateUser &&
|
|
437
|
-
!activeInvitation &&
|
|
438
|
-
input.allowUserCreationWithoutInvitation &&
|
|
439
|
-
input.requireNoActiveUsersForUserCreation &&
|
|
440
|
-
(await hasActiveUsers(tx, projectId))
|
|
441
|
-
) {
|
|
442
|
-
await this.consumeOidcAttempt(input, completedAt, projectId, tx)
|
|
443
|
-
return {
|
|
444
|
-
error: new AuthStorageError(
|
|
445
|
-
"user_creation_not_allowed",
|
|
446
|
-
`[Sixb] OIDC authorization attempt '${input.oidcAuthorizationAttemptId}' cannot create a user for project '${projectId}'.`
|
|
447
|
-
),
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
396
|
await validateCompleteSessionInput(tx, projectId, input.session)
|
|
452
397
|
assertSignInSessionAudience(projectId, input.session.audience, attempt.audience)
|
|
453
398
|
|
|
@@ -497,10 +442,17 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
497
442
|
projectId,
|
|
498
443
|
user,
|
|
499
444
|
})
|
|
500
|
-
const groupMemberships = await this.
|
|
445
|
+
const groupMemberships = await this.syncDirectoryGroups(tx, {
|
|
501
446
|
completedAt,
|
|
502
|
-
existing:
|
|
503
|
-
|
|
447
|
+
existing: await this.applyGroups(tx, {
|
|
448
|
+
completedAt,
|
|
449
|
+
source: "manual",
|
|
450
|
+
existing: invitation.groupMemberships,
|
|
451
|
+
groupIds: manualGroupIds,
|
|
452
|
+
projectId,
|
|
453
|
+
userId: user.id,
|
|
454
|
+
}),
|
|
455
|
+
groupIds: input.directoryGroupIds,
|
|
504
456
|
projectId,
|
|
505
457
|
userId: user.id,
|
|
506
458
|
})
|
|
@@ -703,13 +655,14 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
703
655
|
return { invitation, groupMemberships }
|
|
704
656
|
}
|
|
705
657
|
|
|
706
|
-
private async
|
|
658
|
+
private async applyGroups(
|
|
707
659
|
sql: SQLClient,
|
|
708
660
|
input: {
|
|
709
661
|
readonly completedAt: Date
|
|
710
662
|
readonly existing: readonly GroupMembershipRecord[]
|
|
711
663
|
readonly groupIds: readonly string[]
|
|
712
664
|
readonly projectId: string
|
|
665
|
+
readonly source: GroupMembershipSource
|
|
713
666
|
readonly userId: string
|
|
714
667
|
}
|
|
715
668
|
): Promise<readonly GroupMembershipRecord[]> {
|
|
@@ -721,7 +674,7 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
721
674
|
projectId: input.projectId,
|
|
722
675
|
userId: input.userId,
|
|
723
676
|
groupId,
|
|
724
|
-
source:
|
|
677
|
+
source: input.source,
|
|
725
678
|
createdAt: input.completedAt,
|
|
726
679
|
})
|
|
727
680
|
)
|
|
@@ -729,6 +682,33 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
729
682
|
|
|
730
683
|
return groupMemberships
|
|
731
684
|
}
|
|
685
|
+
// Directory memberships become exactly `groupIds`. A group the user already holds from another
|
|
686
|
+
// source keeps that source, and memberships from other sources are never removed.
|
|
687
|
+
private async syncDirectoryGroups(
|
|
688
|
+
sql: SQLClient,
|
|
689
|
+
input: {
|
|
690
|
+
readonly completedAt: Date
|
|
691
|
+
readonly existing: readonly GroupMembershipRecord[]
|
|
692
|
+
readonly groupIds?: readonly string[]
|
|
693
|
+
readonly projectId: string
|
|
694
|
+
readonly userId: string
|
|
695
|
+
}
|
|
696
|
+
): Promise<readonly GroupMembershipRecord[]> {
|
|
697
|
+
if (!input.groupIds) {
|
|
698
|
+
return input.existing
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const groupIds = normalizeGroupIds(input.groupIds)
|
|
702
|
+
await sql`
|
|
703
|
+
DELETE FROM auth_group_memberships
|
|
704
|
+
WHERE project_id = ${input.projectId}
|
|
705
|
+
AND user_id = ${input.userId}
|
|
706
|
+
AND source = 'directory'
|
|
707
|
+
${groupIds.length > 0 ? sql`AND group_id NOT IN ${sql(groupIds)}` : sql``}
|
|
708
|
+
`
|
|
709
|
+
|
|
710
|
+
return this.applyGroups(sql, { ...input, groupIds, source: "directory" })
|
|
711
|
+
}
|
|
732
712
|
|
|
733
713
|
private async createSignInSession(
|
|
734
714
|
sql: SQLClient,
|
|
@@ -815,18 +795,6 @@ export class PgAuthStorage implements AuthStorage {
|
|
|
815
795
|
}
|
|
816
796
|
}
|
|
817
797
|
|
|
818
|
-
async function hasActiveUsers(sql: SQLClient, projectId: string): Promise<boolean> {
|
|
819
|
-
const rows = (await sql`
|
|
820
|
-
SELECT 1 AS active
|
|
821
|
-
FROM auth_users
|
|
822
|
-
WHERE project_id = ${projectId}
|
|
823
|
-
AND status = 'active'
|
|
824
|
-
LIMIT 1
|
|
825
|
-
`) as Array<{ readonly active: number }>
|
|
826
|
-
|
|
827
|
-
return rows.length > 0
|
|
828
|
-
}
|
|
829
|
-
|
|
830
798
|
function assertSignInSessionAudience(
|
|
831
799
|
projectId: string,
|
|
832
800
|
sessionAudience: string,
|
package/src/auth-storage/rows.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface PgAuthServiceAccountGroupMembershipRow {
|
|
|
58
58
|
readonly project_id: string
|
|
59
59
|
readonly service_account_id: string
|
|
60
60
|
readonly group_id: string
|
|
61
|
-
readonly source:
|
|
61
|
+
readonly source: ServiceAccountGroupMembershipRecord["source"]
|
|
62
62
|
readonly created_at: PgDate
|
|
63
63
|
}
|
|
64
64
|
|
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,5 @@
|
|
|
1
|
+
-- A membership the identity provider owns is recorded with source 'directory' and synced to the
|
|
2
|
+
-- provider's groups on every sign-in. Service accounts never sign in, so their table is unchanged.
|
|
3
|
+
ALTER TABLE auth_group_memberships DROP CONSTRAINT auth_group_memberships_source_check;
|
|
4
|
+
ALTER TABLE auth_group_memberships ADD CONSTRAINT auth_group_memberships_source_check
|
|
5
|
+
CHECK (source IN ('invitation', 'manual', 'agent', 'directory'));
|