@axiom-lattice/pg-stores 3.1.10 → 3.1.11
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +10 -0
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +88 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/PostgreSQLTaskWorkItemStore.test.ts +13 -0
- package/src/createPgStoreConfig.ts +4 -0
- package/src/migrations/user_push_subscription_migration.ts +30 -0
- package/src/stores/PostgreSQLTaskWorkItemStore.ts +5 -5
- package/src/stores/PostgreSQLUserPushSubscriptionStore.ts +61 -0
package/dist/index.mjs
CHANGED
|
@@ -8736,12 +8736,12 @@ var PostgreSQLTaskWorkItemStore = class {
|
|
|
8736
8736
|
tenantId: row.tenant_id,
|
|
8737
8737
|
action: row.action,
|
|
8738
8738
|
actor: row.actor,
|
|
8739
|
-
threadId: row.thread_id,
|
|
8740
|
-
summary: row.summary,
|
|
8739
|
+
threadId: row.thread_id == null ? void 0 : row.thread_id,
|
|
8740
|
+
summary: row.summary == null ? void 0 : row.summary,
|
|
8741
8741
|
detail: isRecord2(row.detail) ? row.detail : void 0,
|
|
8742
|
-
attempt: row.attempt,
|
|
8743
|
-
workspaceId: row.workspace_id,
|
|
8744
|
-
projectId: row.project_id,
|
|
8742
|
+
attempt: row.attempt == null ? void 0 : row.attempt,
|
|
8743
|
+
workspaceId: row.workspace_id == null ? void 0 : row.workspace_id,
|
|
8744
|
+
projectId: row.project_id == null ? void 0 : row.project_id,
|
|
8745
8745
|
eventKey: row.event_key == null ? void 0 : row.event_key,
|
|
8746
8746
|
createdAt: new Date(row.created_at)
|
|
8747
8747
|
};
|
|
@@ -9884,6 +9884,35 @@ var createProjectRoomReadStates = {
|
|
|
9884
9884
|
}
|
|
9885
9885
|
};
|
|
9886
9886
|
|
|
9887
|
+
// src/migrations/user_push_subscription_migration.ts
|
|
9888
|
+
var createUserPushSubscriptions = {
|
|
9889
|
+
version: 178,
|
|
9890
|
+
name: "create_user_push_subscriptions",
|
|
9891
|
+
up: async (client) => {
|
|
9892
|
+
await client.query(`
|
|
9893
|
+
CREATE TABLE IF NOT EXISTS lattice_user_push_subscriptions (
|
|
9894
|
+
id VARCHAR(255) PRIMARY KEY,
|
|
9895
|
+
tenant_id VARCHAR(255) NOT NULL,
|
|
9896
|
+
user_id VARCHAR(255) NOT NULL,
|
|
9897
|
+
endpoint TEXT NOT NULL,
|
|
9898
|
+
p256dh TEXT NOT NULL,
|
|
9899
|
+
auth TEXT NOT NULL,
|
|
9900
|
+
user_agent TEXT,
|
|
9901
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
9902
|
+
UNIQUE (tenant_id, user_id, endpoint)
|
|
9903
|
+
)
|
|
9904
|
+
`);
|
|
9905
|
+
await client.query(`
|
|
9906
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_user_push_subscriptions_user
|
|
9907
|
+
ON lattice_user_push_subscriptions (tenant_id, user_id)
|
|
9908
|
+
`);
|
|
9909
|
+
},
|
|
9910
|
+
down: async (client) => {
|
|
9911
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_user_push_subscriptions_user");
|
|
9912
|
+
await client.query("DROP TABLE IF EXISTS lattice_user_push_subscriptions");
|
|
9913
|
+
}
|
|
9914
|
+
};
|
|
9915
|
+
|
|
9887
9916
|
// src/stores/PostgreSQLCapabilityBundleStore.ts
|
|
9888
9917
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
9889
9918
|
import { Pool as Pool26 } from "pg";
|
|
@@ -10756,6 +10785,58 @@ var PostgreSQLProjectRoomReadStateStore = class {
|
|
|
10756
10785
|
}
|
|
10757
10786
|
};
|
|
10758
10787
|
|
|
10788
|
+
// src/stores/PostgreSQLUserPushSubscriptionStore.ts
|
|
10789
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
10790
|
+
var columns4 = "id, tenant_id, user_id, endpoint, p256dh, auth, user_agent, created_at";
|
|
10791
|
+
function mapRow7(row) {
|
|
10792
|
+
if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.user_id !== "string" || typeof row.endpoint !== "string" || typeof row.p256dh !== "string" || typeof row.auth !== "string" || !(row.created_at instanceof Date) || Number.isNaN(row.created_at.getTime())) {
|
|
10793
|
+
throw new Error("Invalid user push subscription row");
|
|
10794
|
+
}
|
|
10795
|
+
return {
|
|
10796
|
+
id: row.id,
|
|
10797
|
+
tenantId: row.tenant_id,
|
|
10798
|
+
userId: row.user_id,
|
|
10799
|
+
endpoint: row.endpoint,
|
|
10800
|
+
keys: { p256dh: row.p256dh, auth: row.auth },
|
|
10801
|
+
...typeof row.user_agent === "string" ? { userAgent: row.user_agent } : {},
|
|
10802
|
+
createdAt: row.created_at.toISOString()
|
|
10803
|
+
};
|
|
10804
|
+
}
|
|
10805
|
+
var PostgreSQLUserPushSubscriptionStore = class {
|
|
10806
|
+
/** Creates a store using an externally managed shared pool. */
|
|
10807
|
+
constructor(options) {
|
|
10808
|
+
this.pool = options.pool;
|
|
10809
|
+
}
|
|
10810
|
+
/** Lists every subscription for a user. */
|
|
10811
|
+
async list(tenantId, userId) {
|
|
10812
|
+
const result = await this.pool.query(
|
|
10813
|
+
`SELECT ${columns4} FROM lattice_user_push_subscriptions WHERE tenant_id = $1 AND user_id = $2`,
|
|
10814
|
+
[tenantId, userId]
|
|
10815
|
+
);
|
|
10816
|
+
return result.rows.map(mapRow7);
|
|
10817
|
+
}
|
|
10818
|
+
/** Upserts a subscription keyed by tenant + user + endpoint. */
|
|
10819
|
+
async save(input) {
|
|
10820
|
+
const result = await this.pool.query(
|
|
10821
|
+
`INSERT INTO lattice_user_push_subscriptions (${columns4})
|
|
10822
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW())
|
|
10823
|
+
ON CONFLICT (tenant_id, user_id, endpoint) DO UPDATE
|
|
10824
|
+
SET p256dh = EXCLUDED.p256dh, auth = EXCLUDED.auth, user_agent = EXCLUDED.user_agent
|
|
10825
|
+
RETURNING ${columns4}`,
|
|
10826
|
+
[randomUUID4(), input.tenantId, input.userId, input.endpoint, input.keys.p256dh, input.keys.auth, input.userAgent ?? null]
|
|
10827
|
+
);
|
|
10828
|
+
return mapRow7(result.rows[0]);
|
|
10829
|
+
}
|
|
10830
|
+
/** Deletes one subscription by endpoint. */
|
|
10831
|
+
async delete(tenantId, userId, endpoint) {
|
|
10832
|
+
const result = await this.pool.query(
|
|
10833
|
+
`DELETE FROM lattice_user_push_subscriptions WHERE tenant_id = $1 AND user_id = $2 AND endpoint = $3`,
|
|
10834
|
+
[tenantId, userId, endpoint]
|
|
10835
|
+
);
|
|
10836
|
+
return (result.rowCount ?? 0) > 0;
|
|
10837
|
+
}
|
|
10838
|
+
};
|
|
10839
|
+
|
|
10759
10840
|
// src/createPgStoreConfig.ts
|
|
10760
10841
|
async function createPgStoreConfig(connectionString) {
|
|
10761
10842
|
const pool = new Pool27({ connectionString });
|
|
@@ -10823,6 +10904,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
10823
10904
|
mm.register(addProjectLifecycleEventIndex);
|
|
10824
10905
|
mm.register(addAgentWebAppsIdentity);
|
|
10825
10906
|
mm.register(createProjectRoomReadStates);
|
|
10907
|
+
mm.register(createUserPushSubscriptions);
|
|
10826
10908
|
await mm.migrate();
|
|
10827
10909
|
const checkpoint = PostgresSaver.fromConnString(connectionString);
|
|
10828
10910
|
checkpoint.setup().catch((err) => {
|
|
@@ -10862,6 +10944,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
10862
10944
|
projectBotMembership: new PostgreSQLProjectBotMembershipStore(opts),
|
|
10863
10945
|
projectRoomMessage: new PostgreSQLProjectRoomMessageStore(opts),
|
|
10864
10946
|
projectRoomReadState: new PostgreSQLProjectRoomReadStateStore(opts),
|
|
10947
|
+
userPushSubscription: new PostgreSQLUserPushSubscriptionStore(opts),
|
|
10865
10948
|
vectorStoreProvider: new PGVectorStoreProvider(pool, connectionString),
|
|
10866
10949
|
checkpoint
|
|
10867
10950
|
};
|