@sixb/pg 0.1.7 → 0.1.8

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 (49) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +7548 -6387
  4. package/dist/index.js.map +16 -10
  5. package/dist/migrations.d.ts.map +1 -1
  6. package/dist/objects/index.d.ts +2 -0
  7. package/dist/objects/index.d.ts.map +1 -0
  8. package/dist/{pg-object-query-compiler.d.ts → objects/query-compiler.d.ts} +25 -4
  9. package/dist/objects/query-compiler.d.ts.map +1 -0
  10. package/dist/objects/read-scope.d.ts +17 -0
  11. package/dist/objects/read-scope.d.ts.map +1 -0
  12. package/dist/objects/reader.d.ts +50 -0
  13. package/dist/objects/reader.d.ts.map +1 -0
  14. package/dist/objects/rows.d.ts +47 -0
  15. package/dist/objects/rows.d.ts.map +1 -0
  16. package/dist/objects/selected-reader.d.ts +8 -0
  17. package/dist/objects/selected-reader.d.ts.map +1 -0
  18. package/dist/{pg-object-storage.d.ts → objects/storage.d.ts} +12 -20
  19. package/dist/objects/storage.d.ts.map +1 -0
  20. package/dist/pg-execution-storage.d.ts +3 -2
  21. package/dist/pg-execution-storage.d.ts.map +1 -1
  22. package/dist/share-grant-storage.d.ts +11 -0
  23. package/dist/share-grant-storage.d.ts.map +1 -0
  24. package/dist/share-session-storage.d.ts +11 -0
  25. package/dist/share-session-storage.d.ts.map +1 -0
  26. package/dist/storage-errors.d.ts +2 -0
  27. package/dist/storage-errors.d.ts.map +1 -1
  28. package/dist/transactions.d.ts +9 -2
  29. package/dist/transactions.d.ts.map +1 -1
  30. package/package.json +3 -3
  31. package/src/index.ts +16 -3
  32. package/src/migrations/035-share-grants.sql +57 -0
  33. package/src/migrations/036-share-sessions.sql +173 -0
  34. package/src/migrations.ts +4 -0
  35. package/src/objects/index.ts +1 -0
  36. package/src/{pg-object-query-compiler.ts → objects/query-compiler.ts} +185 -100
  37. package/src/objects/read-scope.ts +324 -0
  38. package/src/objects/reader.ts +604 -0
  39. package/src/objects/rows.ts +146 -0
  40. package/src/objects/selected-reader.ts +118 -0
  41. package/src/objects/storage.ts +305 -0
  42. package/src/pg-execution-storage.ts +21 -2
  43. package/src/share-grant-storage.ts +236 -0
  44. package/src/share-session-storage.ts +127 -0
  45. package/src/storage-errors.ts +6 -0
  46. package/src/transactions.ts +46 -5
  47. package/dist/pg-object-query-compiler.d.ts.map +0 -1
  48. package/dist/pg-object-storage.d.ts.map +0 -1
  49. package/src/pg-object-storage.ts +0 -734
@@ -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;AA+E3B,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,aAAa,CAAA;AAEjD,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;IA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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;AA6KD,eAAO,MAAM,yBAAyB,wCAwCpC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { PgObjectStorage } from "./storage";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/objects/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA"}
@@ -47,9 +47,30 @@ type CompiledOrderField = {
47
47
  };
48
48
  export declare function compilePgObjectQuery(projectId: string, query: ObjectQuery, options?: {
49
49
  includeTotal?: boolean;
50
+ source?: PgObjectQuerySource;
50
51
  }): CompiledPgObjectQuery;
51
- export declare function compilePgObjectCountQuery(projectId: string, query: ObjectQuery): CompiledPgScalarQuery;
52
- export declare function compilePgObjectExistsQuery(projectId: string, query: ObjectQuery): CompiledPgScalarQuery;
53
- export declare function compilePgObjectFacetQuery(projectId: string, query: ObjectQuery, propertyId: string, limit: number): CompiledPgFacetQuery;
52
+ /** Physical relations used by the PostgreSQL object-query compiler. */
53
+ export interface PgObjectQuerySource {
54
+ readonly objectsTable: string;
55
+ readonly linksTable: string;
56
+ /** Wrap a terminal SELECT without its own WITH clause; the selected source owns the only WITH. */
57
+ wrapStatement(sql: string, args?: readonly unknown[]): {
58
+ readonly sql: string;
59
+ readonly args: unknown[];
60
+ };
61
+ wrapQuery(query: CompiledPgObjectQuery): CompiledPgObjectQuery;
62
+ }
63
+ /** Prefix an optional query source, then assign PostgreSQL positional placeholders. */
64
+ export declare function compilePgObjectStatement(sql: string, args?: readonly unknown[], source?: PgObjectQuerySource): CompiledPgScalarQuery;
65
+ export declare const DEFAULT_OBJECT_QUERY_SOURCE: PgObjectQuerySource;
66
+ export declare function compilePgObjectCountQuery(projectId: string, query: ObjectQuery, options?: {
67
+ source?: PgObjectQuerySource;
68
+ }): CompiledPgScalarQuery;
69
+ export declare function compilePgObjectExistsQuery(projectId: string, query: ObjectQuery, options?: {
70
+ source?: PgObjectQuerySource;
71
+ }): CompiledPgScalarQuery;
72
+ export declare function compilePgObjectFacetQuery(projectId: string, query: ObjectQuery, propertyId: string, limit: number, options?: {
73
+ source?: PgObjectQuerySource;
74
+ }): CompiledPgFacetQuery;
54
75
  export {};
55
- //# sourceMappingURL=pg-object-query-compiler.d.ts.map
76
+ //# sourceMappingURL=query-compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-compiler.d.ts","sourceRoot":"","sources":["../../src/objects/query-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAKhB,KAAK,eAAe,EACrB,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,QAAQ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AAC,EAAE,mBAAmB,CAAA;CAAO,GAC7C,oBAAoB,CAqBtB"}
@@ -0,0 +1,17 @@
1
+ import type { CompiledSelectedObjectReadScope } from "@sixb/core/storage";
2
+ import { type PgObjectQuerySource } from "./query-compiler";
3
+ export interface PgSelectedObjectReadSource extends PgObjectQuerySource {
4
+ readonly objectPropertyPermissionsTable: string;
5
+ readonly traversalProbe: {
6
+ readonly sql: string;
7
+ readonly args: readonly unknown[];
8
+ };
9
+ }
10
+ /**
11
+ * Prepare one immutable selected scope as live, path-sensitive PostgreSQL relations.
12
+ *
13
+ * The complete compiled scope is serialized once. Every statement receives that one JSONB
14
+ * document and the bound project id, keeping the parameter count constant as selections grow.
15
+ */
16
+ export declare function compilePgSelectedObjectReadSource(projectId: string, scope: CompiledSelectedObjectReadScope, maxTraversalFacts: number): PgSelectedObjectReadSource;
17
+ //# sourceMappingURL=read-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-scope.d.ts","sourceRoot":"","sources":["../../src/objects/read-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,QAAQ,CAAC,8BAA8B,EAAE,MAAM,CAAA;IAC/C,QAAQ,CAAC,cAAc,EAAE;QACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;QACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAA;KAClC,CAAA;CACF;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,+BAA+B,EACtC,iBAAiB,EAAE,MAAM,GACxB,0BAA0B,CAsD5B"}
@@ -0,0 +1,50 @@
1
+ import type { CountObjectsInput, CountObjectsResult, ExistsObjectsInput, ExistsObjectsResult, FacetObjectsInput, FacetObjectsResult, LinkBatchKey, LinkDirection, ObjectBatchKey, ObjectLinkRow, ObjectReadStorage, ObjectRow, QueryObjectLinksInput, QueryObjectLinksResult, QueryObjectsInput, QueryObjectsResult } from "@sixb/core/storage";
2
+ import type { SQLClient } from "../pg-client";
3
+ import { type PgObjectQuerySource } from "./query-compiler";
4
+ import type { PgSelectedObjectReadSource } from "./read-scope";
5
+ export declare class PgObjectReader {
6
+ private readonly sql;
7
+ private readonly source;
8
+ constructor(sql: SQLClient, source: PgObjectQuerySource | PgSelectedObjectReadSource);
9
+ queryObjects(params: QueryObjectsInput): Promise<QueryObjectsResult>;
10
+ countObjects(params: CountObjectsInput): Promise<CountObjectsResult>;
11
+ existsObjects(params: ExistsObjectsInput): Promise<ExistsObjectsResult>;
12
+ facetObjects(params: FacetObjectsInput): Promise<FacetObjectsResult>;
13
+ getByPrimaryId(params: {
14
+ projectId: string;
15
+ objectTypeId: string;
16
+ primaryId: string;
17
+ }): Promise<ObjectRow | null>;
18
+ selectsObjectProperties(params: Parameters<ObjectReadStorage["selectsObjectProperties"]>[0]): Promise<readonly boolean[]>;
19
+ listLinks(params: {
20
+ projectId: string;
21
+ objectTypeId: string;
22
+ objectId: string;
23
+ linkId?: string;
24
+ direction?: LinkDirection;
25
+ }): Promise<readonly ObjectLinkRow[]>;
26
+ getByPrimaryIdBatch(params: {
27
+ projectId: string;
28
+ items: readonly {
29
+ objectTypeId: string;
30
+ primaryId: string;
31
+ }[];
32
+ }): Promise<Map<ObjectBatchKey, ObjectRow>>;
33
+ listLinksBatch(params: {
34
+ projectId: string;
35
+ direction?: LinkDirection;
36
+ items: readonly {
37
+ objectTypeId: string;
38
+ objectId: string;
39
+ linkId: string;
40
+ }[];
41
+ }): Promise<Map<LinkBatchKey, ObjectLinkRow[]>>;
42
+ queryLinks(params: QueryObjectLinksInput): Promise<QueryObjectLinksResult>;
43
+ list(params: Parameters<ObjectReadStorage["list"]>[0]): Promise<{
44
+ objects: readonly ObjectRow[];
45
+ hasMore: boolean;
46
+ total: number;
47
+ }>;
48
+ }
49
+ export declare function assertLinkQueryLimit(limit: number): void;
50
+ //# sourceMappingURL=reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/objects/reader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EAEd,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAA;AAC3D,OAAO,EAOL,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAgB9D,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,mBAAmB,GAAG,0BAA0B;IAGrE,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAiCpE,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAapE,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAYvE,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsBpE,cAAc,CAAC,MAAM,EAAE;QAC3B,SAAS,EAAE,MAAM,CAAA;QACjB,YAAY,EAAE,MAAM,CAAA;QACpB,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,CAAC,SAAS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AAA;KAAE,CAAC;CA+E/E;AAuDD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAIxD"}
@@ -0,0 +1,47 @@
1
+ import type { ObjectLinkRow, ObjectRow } from "@sixb/core/storage";
2
+ export declare function rowToObject(row: ObjectDatabaseRow): ObjectRow;
3
+ export declare function queryRowToObject(row: ObjectQueryDatabaseRow): ObjectRow;
4
+ export declare function rowToLink(row: LinkDatabaseRow): ObjectLinkRow;
5
+ export declare function linkIdentity(link: ObjectLinkRow): string;
6
+ export interface ObjectDatabaseRow {
7
+ project_id: string;
8
+ object_type_id: string;
9
+ primary_id: string;
10
+ properties: unknown;
11
+ created_at: Date | string;
12
+ updated_at: Date | string;
13
+ version: number;
14
+ last_commit_id: string;
15
+ }
16
+ export interface ObjectQueryDatabaseRow extends ObjectDatabaseRow {
17
+ _cursor_properties?: unknown;
18
+ /** `jsonb_build_object(linkId, value, ...)` from an `expand` pushdown; absent otherwise. */
19
+ _expand?: unknown;
20
+ }
21
+ export interface ObjectBatchDatabaseRow extends ObjectDatabaseRow {
22
+ _batch_index: number;
23
+ }
24
+ export interface PropertyPermissionBatchDatabaseRow {
25
+ _batch_index: number;
26
+ }
27
+ export interface FacetDatabaseRow {
28
+ value_type: string | null;
29
+ value_text: string | null;
30
+ count: string | number | bigint;
31
+ }
32
+ export interface LinkDatabaseRow {
33
+ project_id: string;
34
+ source_type_id: string;
35
+ source_id: string;
36
+ link_id: string;
37
+ target_type_id: string;
38
+ target_id: string;
39
+ properties: unknown | null;
40
+ created_at: Date | string;
41
+ updated_at: Date | string;
42
+ last_commit_id: string;
43
+ }
44
+ export interface LinkBatchDatabaseRow extends LinkDatabaseRow {
45
+ _batch_index: number;
46
+ }
47
+ //# sourceMappingURL=rows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../../src/objects/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,aAAa,EACb,S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AAM,CAAA;IACjB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAA;IAC1B,UAAU,EAAE,IAAI,GAAG,MAAM,CAAA;IACzB,UAAU,EAAE,IAAI,GAAG,MAAM,CAAA;IACzB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,YAAY,EAAE,MAAM,CAAA;CACrB"}
@@ -0,0 +1,8 @@
1
+ import type { CompiledSelectedObjectReadScope, ObjectQueryCapabilities, ObjectReadExecutionLimits, ObjectReadStorage } from "@sixb/core/storage";
2
+ import { type PgStoreClient } from "../transactions";
3
+ export declare function createPgSelectedReader(sql: PgStoreClient, params: {
4
+ projectId: string;
5
+ scope: CompiledSelectedObjectReadScope;
6
+ limits: ObjectReadExecutionLimits;
7
+ }, queryCapabilities: () => ObjectQueryCapabilities): ObjectReadStorage;
8
+ //# sourceMappingURL=selected-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selected-reader.d.ts","sourceRoot":"","sources":["../../src/objects/selected-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,oBAAoB,CAAA;AAS3B,OAAO,EAAE,KAAK,aAAa,EAAkC,MAAM,iBAAiB,CAAA;AAKpF,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE;IACN,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,+BAA+B,CAAA;IACtC,MAAM,EAAE,yBAAyB,CAAA;CAClC,EACD,iBAAiB,EAAE,MAAM,uBAAuB,GAC/C,iBAAiB,CA4EnB"}
@@ -1,26 +1,16 @@
1
- import type { CountObjectsInput, CountObjectsResult, ExistsObjectsInput, ExistsObjectsResult, FacetObjectsInput, FacetObjectsResult, LinkBatchKey, LinkDirection, ObjectBatchKey, ObjectLinkRow, ObjectQueryCapabilities, ObjectRow, ObjectStorage, QueryObjectLinksInput, QueryObjectLinksResult, QueryObjectsInput, QueryObjectsResult } from "@sixb/core/storage";
2
- import type { PgStoreClient } from "./transactions";
3
- /**
4
- * PostgreSQL-based ObjectStorage implementation.
5
- *
6
- * Stores object projections and links. V1 object-query IR pushdown covers the
7
- * scalar JSONB-property and link-traversal subset declared by queryCapabilities().
8
- *
9
- * Requires `search_path` to be set to the Sixb schema on the connection.
10
- *
11
- * JSONB handling notes (Bun SQL specifics):
12
- * - Writes use `${JSON.stringify(v)}::text::jsonb`. The `::text` forces the
13
- * text wire type so that `::jsonb` parses the JSON text into a proper JSONB
14
- * value (object, number, etc.) instead of a JSONB string literal.
15
- * - The `@>` containment operator receives a plain JS object which Bun SQL
16
- * auto-serialises as JSONB.
17
- * - Reads return JSONB as native JS types (objects, numbers, booleans) when
18
- * the data was stored correctly.
19
- */
1
+ import type { CompiledSelectedObjectReadScope, CountObjectsInput, CountObjectsResult, ExistsObjectsInput, ExistsObjectsResult, FacetObjectsInput, FacetObjectsResult, LinkBatchKey, LinkDirection, ObjectBatchKey, ObjectLinkRow, ObjectQueryCapabilities, ObjectReadExecutionLimits, ObjectReadStorage, ObjectRow, ObjectStorage, QueryObjectLinksInput, QueryObjectLinksResult, QueryObjectsInput, QueryObjectsResult } from "@sixb/core/storage";
2
+ import type { PgStoreClient } from "../transactions";
3
+ /** PostgreSQL object provider; interactive reads share one source-aware reader. */
20
4
  export declare class PgObjectStorage implements ObjectStorage {
21
5
  private readonly sql;
6
+ private readonly reader;
22
7
  constructor(sql: PgStoreClient);
23
8
  queryCapabilities(): ObjectQueryCapabilities;
9
+ createSelectedReadScope(params: {
10
+ projectId: string;
11
+ scope: CompiledSelectedObjectReadScope;
12
+ limits: ObjectReadExecutionLimits;
13
+ }): ObjectReadStorage;
24
14
  queryObjects(params: QueryObjectsInput): Promise<QueryObjectsResult>;
25
15
  countObjects(params: CountObjectsInput): Promise<CountObjectsResult>;
26
16
  existsObjects(params: ExistsObjectsInput): Promise<ExistsObjectsResult>;
@@ -30,6 +20,7 @@ export declare class PgObjectStorage implements ObjectStorage {
30
20
  objectTypeId: string;
31
21
  primaryId: string;
32
22
  }): Promise<ObjectRow | null>;
23
+ selectsObjectProperties(params: Parameters<ObjectReadStorage["selectsObjectProperties"]>[0]): Promise<readonly boolean[]>;
33
24
  listLinks(params: {
34
25
  projectId: string;
35
26
  objectTypeId: string;
@@ -46,6 +37,7 @@ export declare class PgObjectStorage implements ObjectStorage {
46
37
  }): Promise<Map<ObjectBatchKey, ObjectRow>>;
47
38
  listLinksBatch(params: {
48
39
  projectId: string;
40
+ direction?: LinkDirection;
49
41
  items: readonly {
50
42
  objectTypeId: string;
51
43
  objectId: string;
@@ -88,4 +80,4 @@ export declare class PgObjectStorage implements ObjectStorage {
88
80
  total: number;
89
81
  }>;
90
82
  }
91
- //# sourceMappingURL=pg-object-storage.d.ts.map
83
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/objects/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+BAA+B,EAC/B,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AA8EpD,mFAAmF;AACnF,qBAAa,eAAgB,YAAW,aAAa;IAGvC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAEV,GAAG,EAAE,aAAa;IAI/C,iBAAiB,IAAI,uBAAuB;IAI5C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;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,WAAW,CAAA;QACjD,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KACvB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAGhF"}
@@ -1,10 +1,11 @@
1
- import type { CreateExecutionInput, ExecutionRecord, ExecutionStorage } from "@sixb/core/storage";
1
+ import type { CreateExecutionInput, ExecutionRecord, ExecutionStorage, ShareSessionStorage } from "@sixb/core/storage";
2
2
  import type { PgAuthStorage } from "./auth-storage";
3
3
  import type { PgStoreClient } from "./transactions";
4
4
  export declare class PgExecutionStorage implements ExecutionStorage {
5
5
  private readonly sql;
6
6
  private readonly auth;
7
- constructor(sql: PgStoreClient, auth: PgAuthStorage);
7
+ private readonly shareSessions;
8
+ constructor(sql: PgStoreClient, auth: PgAuthStorage, shareSessions: Pick<ShareSessionStorage, "getById">);
8
9
  create(input: CreateExecutionInput): Promise<ExecutionRecord>;
9
10
  getById(params: {
10
11
  readonly projectId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"pg-execution-storage.d.ts","sourceRoot":"","sources":["../src/pg-execution-storage.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAEjG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,qBAAa,kBAAmB,YAAW,gBAAgB;IAEvD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa;IAGhC,MAAM,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAsE7D,OAAO,CAAC,MAAM,EAAE;QACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;QAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KACpB,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAQpC"}
1
+ {"version":3,"file":"pg-execution-storage.d.ts","sourceRoot":"","sources":["../src/pg-execution-storage.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,qBAAa,kBAAmB,YAAW,gBAAgB;IAEvD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,EACnB,aAAa,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC;IAGhE,MAAM,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IA6E7D,OAAO,CAAC,MAAM,EAAE;QACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;QAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KACpB,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAQpC"}
@@ -0,0 +1,11 @@
1
+ import type { CreateShareGrantInput, GetShareGrantByIdInput, ListShareGrantsInput, ListShareGrantsResult, RevokeShareGrantInput, ShareGrantRecord, ShareGrantStorage } from "@sixb/core/storage";
2
+ import type { PgStoreClient } from "./transactions";
3
+ export declare class PgShareGrantStorage implements ShareGrantStorage {
4
+ private readonly sql;
5
+ constructor(sql: PgStoreClient);
6
+ create(input: CreateShareGrantInput): Promise<ShareGrantRecord>;
7
+ getById(input: GetShareGrantByIdInput): Promise<ShareGrantRecord | null>;
8
+ list(input: ListShareGrantsInput): Promise<ListShareGrantsResult>;
9
+ revoke(input: RevokeShareGrantInput): Promise<ShareGrantRecord | null>;
10
+ }
11
+ //# sourceMappingURL=share-grant-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-grant-storage.d.ts","sourceRoot":"","sources":["../src/share-grant-storage.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,qBAAa,mBAAoB,YAAW,iBAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,aAAa;IAEzC,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqD/D,OAAO,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAUxE,IAAI,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA8CjE,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;CAqB7E"}
@@ -0,0 +1,11 @@
1
+ import type { CreateShareSessionInput, GetShareSessionByIdInput, RenewShareSessionIfValidInput, RevokeShareSessionInput, ShareSessionRecord, ShareSessionStorage } from "@sixb/core/storage";
2
+ import type { PgStoreClient } from "./transactions";
3
+ export declare class PgShareSessionStorage implements ShareSessionStorage {
4
+ private readonly sql;
5
+ constructor(sql: PgStoreClient);
6
+ create(input: CreateShareSessionInput): Promise<ShareSessionRecord>;
7
+ getById(input: GetShareSessionByIdInput): Promise<ShareSessionRecord | null>;
8
+ renewIfValid(input: RenewShareSessionIfValidInput): Promise<ShareSessionRecord | null>;
9
+ revoke(input: RevokeShareSessionInput): Promise<ShareSessionRecord | null>;
10
+ }
11
+ //# sourceMappingURL=share-session-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-session-storage.d.ts","sourceRoot":"","sources":["../src/share-session-storage.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,qBAAa,qBAAsB,YAAW,mBAAmB;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,aAAa;IAEzC,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAiCnE,OAAO,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAS5E,YAAY,CAAC,KAAK,EAAE,6BAA6B,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAkBtF,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;CAgBjF"}
@@ -2,6 +2,8 @@
2
2
  export declare function pgErrorCode(error: unknown): string | undefined;
3
3
  /** True when the error is a PostgreSQL unique-constraint violation (SQLSTATE 23505). */
4
4
  export declare function isUniqueViolation(error: unknown): boolean;
5
+ /** True when the error is a PostgreSQL foreign-key violation (SQLSTATE 23503). */
6
+ export declare function isForeignKeyViolation(error: unknown): boolean;
5
7
  /**
6
8
  * True when the error is a transient transaction-rollback conflict that is safe to retry by
7
9
  * replaying the transaction — a serialization failure (SQLSTATE 40001) or a deadlock (40P01).
@@ -1 +1 @@
1
- {"version":3,"file":"storage-errors.d.ts","sourceRoot":"","sources":["../src/storage-errors.ts"],"names":[],"mappings":"AAgCA,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;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGtE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASzD"}
1
+ {"version":3,"file":"storage-errors.d.ts","sourceRoot":"","sources":["../src/storage-errors.ts"],"names":[],"mappings":"AAiCA,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;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASzD"}
@@ -1,10 +1,17 @@
1
1
  import type { SQL, SQLClient } from "./pg-client";
2
2
  export type PgStoreClient = SQL | SQLClient;
3
3
  export interface RunPgTransactionOptions {
4
- /** Open the transaction at `SERIALIZABLE`; omit for the server default (`READ COMMITTED`). */
5
- readonly isolation?: "serializable";
4
+ /** Open the transaction at an explicit isolation; omit for the server default. */
5
+ readonly isolation?: "repeatableRead" | "serializable";
6
6
  }
7
7
  export declare function runPgTransaction<T>(sql: PgStoreClient, run: (tx: SQLClient) => Promise<T>, options?: RunPgTransactionOptions): Promise<T>;
8
+ /**
9
+ * Run a multi-statement read against one proven PostgreSQL snapshot.
10
+ *
11
+ * A provider-owned repeatable-read or serializable transaction may be reused. An external
12
+ * transaction client is rejected because postgres.js does not expose its current isolation.
13
+ */
14
+ export declare function runPgRepeatableReadTransaction<T>(sql: PgStoreClient, run: (tx: SQLClient) => Promise<T>): Promise<T>;
8
15
  export declare function authLockKey(kind: string, ...parts: readonly string[]): string;
9
16
  export declare function lockAdvisoryKeys(sql: SQLClient, keys: readonly string[]): Promise<void>;
10
17
  //# 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;AAEjD,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,SAAS,CAAA;AAE3C,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAA;CACpC;AAED,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,CAgBZ;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"}
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;AAEjD,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;AAMD,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,CA6BZ;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.7",
3
+ "version": "0.1.8",
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.7"
43
+ "@sixb/core": "0.1.8"
44
44
  },
45
45
  "devDependencies": {
46
- "@sixb/core": "0.1.7",
46
+ "@sixb/core": "0.1.8",
47
47
  "@types/bun": "latest",
48
48
  "typescript": "^5.7.0"
49
49
  },
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ import { ProviderMaterializationTransactionLifecycle } from "@sixb/core/internal
13
13
  import {
14
14
  createAgentOperationScope,
15
15
  createAuthOperationScope,
16
+ createObjectOperationScope,
16
17
  createOntologyOperationScope,
17
18
  createOperationScopedFacade,
18
19
  createStorageOperationScope,
@@ -31,6 +32,7 @@ import { PgAgentStorage } from "./agents"
31
32
  import { PgAuthStorage } from "./auth-storage"
32
33
  import { PgConnectorConnectionStorage } from "./connector-connection-storage"
33
34
  import { createPostgresStorageMigrators, dropSchema } from "./migrations"
35
+ import { PgObjectStorage } from "./objects"
34
36
  import { PgOntologyStorage, type PgOntologyTransactionContext } from "./ontology-storage"
35
37
  import { PgActionRunStorage } from "./pg-action-run-storage"
36
38
  import { PgAiCostStorage } from "./pg-ai-cost-storage"
@@ -38,7 +40,6 @@ import { PgAiLimitStorage } from "./pg-ai-limit-storage"
38
40
  import { PgAiUsageStorage } from "./pg-ai-usage-storage"
39
41
  import { createPgClient, type SQL, type SQLClient } from "./pg-client"
40
42
  import { PgExecutionStorage } from "./pg-execution-storage"
41
- import { PgObjectStorage } from "./pg-object-storage"
42
43
  import { PgPipelineRunStorage } from "./pg-pipeline-run-storage"
43
44
  import { PgProjectionRunStorage } from "./pg-projection-run-storage"
44
45
  import { PgRulesStorage } from "./pg-rules-storage"
@@ -47,6 +48,8 @@ import { PgTimeseriesStorage } from "./pg-timeseries-storage"
47
48
  import { PgWebhookRunStorage } from "./pg-webhook-run-storage"
48
49
  import { PgWorkflowInterventionStorage } from "./pg-workflow-intervention-storage"
49
50
  import { PgWorkflowRunStorage } from "./pg-workflow-run-storage"
51
+ import { PgShareGrantStorage } from "./share-grant-storage"
52
+ import { PgShareSessionStorage } from "./share-session-storage"
50
53
  import { isRetryableTransactionConflict } from "./storage-errors"
51
54
  import { registerPostgresStorageTestingAdapter } from "./testing"
52
55
  import { type PgStoreClient, runPgTransaction } from "./transactions"
@@ -151,6 +154,8 @@ export class PostgresStorage implements MigrationCapableStorage {
151
154
  readonly webhookRuns: PgWebhookRunStorage
152
155
  readonly rules: PgRulesStorage
153
156
  readonly connectorConnections: PgConnectorConnectionStorage
157
+ readonly shareGrants: PgShareGrantStorage
158
+ readonly shareSessions: PgShareSessionStorage
154
159
  readonly migrators: readonly StorageMigrator[]
155
160
 
156
161
  private readonly sql: SQL
@@ -208,7 +213,7 @@ export class PostgresStorage implements MigrationCapableStorage {
208
213
  },
209
214
  () => this.assertRootOperationAvailable()
210
215
  )
211
- this.objects = createOperationScopedFacade(stores.objects, scope)
216
+ this.objects = createObjectOperationScope(stores.objects, scope)
212
217
  this.ontology = createOntologyOperationScope(stores.ontology, scope)
213
218
  this.auth = createAuthOperationScope(stores.auth, scope)
214
219
  this.executions = createOperationScopedFacade(stores.executions, scope)
@@ -226,6 +231,8 @@ export class PostgresStorage implements MigrationCapableStorage {
226
231
  this.webhookRuns = createOperationScopedFacade(stores.webhookRuns, scope)
227
232
  this.rules = createOperationScopedFacade(stores.rules, scope)
228
233
  this.connectorConnections = createOperationScopedFacade(stores.connectorConnections, scope)
234
+ this.shareGrants = createOperationScopedFacade(stores.shareGrants, scope)
235
+ this.shareSessions = createOperationScopedFacade(stores.shareSessions, scope)
229
236
  registerPostgresStorageTestingAdapter(this, (durationMs) =>
230
237
  stores.connectorConnections.advanceTimeForTesting(durationMs)
231
238
  )
@@ -334,7 +341,9 @@ function createPostgresStores(
334
341
  }
335
342
  ): PostgresStoreSet {
336
343
  const auth = new PgAuthStorage({ sql })
337
- const executions = new PgExecutionStorage(sql, auth)
344
+ const shareGrants = new PgShareGrantStorage(sql)
345
+ const shareSessions = new PgShareSessionStorage(sql)
346
+ const executions = new PgExecutionStorage(sql, auth, shareSessions)
338
347
  return {
339
348
  objects: new PgObjectStorage(sql),
340
349
  ontology: new PgOntologyStorage({
@@ -358,6 +367,8 @@ function createPostgresStores(
358
367
  webhookRuns: new PgWebhookRunStorage(sql, executions),
359
368
  rules: new PgRulesStorage(sql),
360
369
  connectorConnections: new PgConnectorConnectionStorage(sql),
370
+ shareGrants,
371
+ shareSessions,
361
372
  }
362
373
  }
363
374
 
@@ -380,6 +391,8 @@ interface PostgresStoreSet {
380
391
  readonly webhookRuns: PgWebhookRunStorage
381
392
  readonly rules: PgRulesStorage
382
393
  readonly connectorConnections: PgConnectorConnectionStorage
394
+ readonly shareGrants: PgShareGrantStorage
395
+ readonly shareSessions: PgShareSessionStorage
383
396
  }
384
397
 
385
398
  function resolveTimeoutMillis(value: number | undefined, label: string): number | undefined {
@@ -0,0 +1,57 @@
1
+ CREATE TABLE share_grants (
2
+ project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
3
+ id TEXT NOT NULL CHECK (length(trim(id)) > 0),
4
+ definition_id TEXT NOT NULL CHECK (length(trim(definition_id)) > 0),
5
+ target_object_type_id TEXT NOT NULL CHECK (length(trim(target_object_type_id)) > 0),
6
+ target_primary_id TEXT NOT NULL CHECK (length(trim(target_primary_id)) > 0),
7
+ issued_by_type TEXT NOT NULL CHECK (issued_by_type IN ('user', 'serviceAccount')),
8
+ issued_by_id TEXT NOT NULL CHECK (length(trim(issued_by_id)) > 0),
9
+ authority_version INTEGER NOT NULL CHECK (authority_version > 0),
10
+ authority_snapshot JSONB NOT NULL CHECK (
11
+ jsonb_typeof(authority_snapshot) = 'object'
12
+ AND jsonb_typeof(authority_snapshot -> 'version') = 'number'
13
+ AND (authority_snapshot ->> 'version')::integer = authority_version
14
+ AND jsonb_typeof(authority_snapshot -> 'access') = 'object'
15
+ ),
16
+ authority_digest TEXT NOT NULL CHECK (authority_digest ~ '^[0-9a-f]{64}$'),
17
+ token_hash TEXT NOT NULL CHECK (token_hash ~ '^[0-9a-f]{64}$'),
18
+ destination_path TEXT NOT NULL CHECK (
19
+ left(destination_path, 1) = '/'
20
+ AND position('?' IN destination_path) = 0
21
+ AND position('#' IN destination_path) = 0
22
+ AND position(chr(92) IN destination_path) = 0
23
+ ),
24
+ created_at TIMESTAMPTZ NOT NULL,
25
+ expires_at TIMESTAMPTZ NOT NULL,
26
+ revoked_at TIMESTAMPTZ,
27
+ revoked_by_type TEXT CHECK (
28
+ revoked_by_type IS NULL OR revoked_by_type IN ('user', 'serviceAccount', 'system')
29
+ ),
30
+ revoked_by_id TEXT CHECK (
31
+ revoked_by_id IS NULL OR length(trim(revoked_by_id)) > 0
32
+ ),
33
+ PRIMARY KEY (project_id, id),
34
+ UNIQUE (project_id, token_hash),
35
+ CHECK (expires_at > created_at),
36
+ CHECK (revoked_at IS NULL OR revoked_at >= created_at),
37
+ CHECK (
38
+ (revoked_at IS NULL AND revoked_by_type IS NULL AND revoked_by_id IS NULL)
39
+ OR
40
+ (revoked_at IS NOT NULL AND revoked_by_type IS NOT NULL AND revoked_by_id IS NOT NULL)
41
+ )
42
+ );
43
+
44
+ CREATE INDEX idx_share_grants_project_created
45
+ ON share_grants (project_id, created_at DESC, id DESC);
46
+ CREATE INDEX idx_share_grants_definition_target
47
+ ON share_grants (
48
+ project_id,
49
+ definition_id,
50
+ target_object_type_id,
51
+ target_primary_id,
52
+ created_at DESC,
53
+ id DESC
54
+ );
55
+ CREATE INDEX idx_share_grants_expiry
56
+ ON share_grants (project_id, expires_at)
57
+ WHERE revoked_at IS NULL;