@kubun/store-connector 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/api.d.ts CHANGED
@@ -28,6 +28,12 @@ export type PendingAuthRecord = {
28
28
  export type ConnectorStoreAPI = {
29
29
  getSyncState(connectorName: string, ownerDID: string): Promise<SyncState | null>;
30
30
  setSyncState(connectorName: string, ownerDID: string, state: SyncState): Promise<void>;
31
+ updateSyncProgress(connectorName: string, ownerDID: string, progress: {
32
+ checkpoint: unknown;
33
+ lastSyncedAt: string;
34
+ entityCount: number;
35
+ error?: string | null;
36
+ }): Promise<void>;
31
37
  deleteSyncState(connectorName: string, ownerDID: string): Promise<void>;
32
38
  listSyncStatesForConnector(connectorName: string): Promise<Array<SyncStateEntry>>;
33
39
  createPendingAuth(record: PendingAuthRecord): Promise<void>;
package/lib/api.js CHANGED
@@ -27,9 +27,8 @@ export function createConnectorStore(db, _adapter) {
27
27
  return rowToSyncState(row);
28
28
  },
29
29
  async setSyncState (connectorName, ownerDID, state) {
30
- // The `lease_expires_at` column is dead (the lease moved to the workflow
31
- // engine); a fresh INSERT sets it null and a conflicting update leaves it
32
- // untouched.
30
+ // `lease_expires_at` is dead: a fresh INSERT sets it null and a conflicting
31
+ // update leaves it untouched.
33
32
  await db.insertInto('kubun_connector_sync_state').values({
34
33
  connector_name: connectorName,
35
34
  owner_did: ownerDID,
@@ -50,6 +49,28 @@ export function createConnectorStore(db, _adapter) {
50
49
  error: state.error ?? null
51
50
  })).execute();
52
51
  },
52
+ async updateSyncProgress (connectorName, ownerDID, progress) {
53
+ const checkpoint = progress.checkpoint != null ? JSON.stringify(progress.checkpoint) : null;
54
+ const error = progress.error ?? null;
55
+ await db.insertInto('kubun_connector_sync_state').values({
56
+ connector_name: connectorName,
57
+ owner_did: ownerDID,
58
+ checkpoint,
59
+ last_synced_at: progress.lastSyncedAt,
60
+ entity_count: progress.entityCount,
61
+ status: 'idle',
62
+ error,
63
+ lease_expires_at: null
64
+ }).onConflict((oc)=>oc.columns([
65
+ 'connector_name',
66
+ 'owner_did'
67
+ ]).doUpdateSet({
68
+ checkpoint,
69
+ last_synced_at: progress.lastSyncedAt,
70
+ entity_count: progress.entityCount,
71
+ error
72
+ })).execute();
73
+ },
53
74
  async deleteSyncState (connectorName, ownerDID) {
54
75
  await db.deleteFrom('kubun_connector_sync_state').where('connector_name', '=', connectorName).where('owner_did', '=', ownerDID).execute();
55
76
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/store-connector",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -15,13 +15,13 @@
15
15
  "LICENSE.md"
16
16
  ],
17
17
  "dependencies": {
18
- "@kubun/db": "^0.15.0",
19
- "@kubun/db-adapter": "^0.15.0",
18
+ "@kubun/db": "^0.16.0",
19
+ "@kubun/db-adapter": "^0.16.0",
20
20
  "kysely": "^0.29.5"
21
21
  },
22
22
  "devDependencies": {
23
- "@kubun/db-better-sqlite": "^0.15.0",
24
- "@kubun/db-postgres": "^0.15.0",
23
+ "@kubun/db-better-sqlite": "^0.16.0",
24
+ "@kubun/db-postgres": "^0.16.0",
25
25
  "@testcontainers/postgresql": "^12.1.0"
26
26
  },
27
27
  "publishConfig": {