@powersync/service-module-postgres-storage 0.0.0-dev-20260313100403 → 0.0.0-dev-20260515144844
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/CHANGELOG.md +100 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresBucketStorageFactory.d.ts +2 -1
- package/dist/@types/storage/PostgresReportStorage.d.ts +4 -4
- package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +4 -2
- package/dist/@types/storage/batch/PostgresBucketBatch.d.ts +1 -1
- package/dist/@types/types/models/SyncRules.d.ts +9 -0
- package/dist/@types/types/models/models-index.d.ts +1 -1
- package/dist/@types/utils/test-utils.d.ts +2 -2
- package/dist/@types/utils/utils-index.d.ts +1 -1
- package/dist/migrations/migration-utils.js +2 -2
- package/dist/migrations/migration-utils.js.map +1 -1
- package/dist/migrations/scripts/1684951997326-init.js +24 -100
- package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
- package/dist/migrations/scripts/1749024804042-snapshot-progress.js +12 -88
- package/dist/migrations/scripts/1749024804042-snapshot-progress.js.map +1 -1
- package/dist/migrations/scripts/1756282360128-connection-reporting.js +12 -88
- package/dist/migrations/scripts/1756282360128-connection-reporting.js.map +1 -1
- package/dist/migrations/scripts/1771232439485-storage-version.js +14 -90
- package/dist/migrations/scripts/1771232439485-storage-version.js.map +1 -1
- package/dist/migrations/scripts/1771424826685-current-data-pending-deletes.js +1 -1
- package/dist/migrations/scripts/1771491856000-sync-plan.js +6 -82
- package/dist/migrations/scripts/1771491856000-sync-plan.js.map +1 -1
- package/dist/storage/PostgresBucketStorageFactory.js +6 -5
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresReportStorage.js +10 -10
- package/dist/storage/PostgresReportStorage.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +76 -107
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +5 -5
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/current-data-store.js +1 -1
- package/dist/storage/current-data-store.js.map +1 -1
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +3 -3
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +1 -1
- package/dist/types/models/SyncRules.js +3 -1
- package/dist/types/models/SyncRules.js.map +1 -1
- package/dist/types/models/models-index.js +1 -1
- package/dist/types/models/models-index.js.map +1 -1
- package/dist/utils/test-utils.js +36 -112
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/utils-index.js +1 -1
- package/dist/utils/utils-index.js.map +1 -1
- package/package.json +11 -12
- package/src/migrations/migration-utils.ts +2 -2
- package/src/migrations/scripts/1771424826685-current-data-pending-deletes.ts +1 -1
- package/src/storage/PostgresBucketStorageFactory.ts +7 -5
- package/src/storage/PostgresReportStorage.ts +12 -12
- package/src/storage/PostgresSyncRulesStorage.ts +81 -39
- package/src/storage/batch/PostgresBucketBatch.ts +5 -5
- package/src/storage/checkpoints/PostgresWriteCheckpointAPI.ts +3 -1
- package/src/storage/current-data-store.ts +1 -1
- package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +3 -6
- package/src/types/models/SyncRules.ts +3 -1
- package/src/types/models/models-index.ts +1 -1
- package/src/utils/test-utils.ts +3 -3
- package/src/utils/utils-index.ts +1 -1
- package/test/src/__snapshots__/{client-connections-storage.test.ts.snap → connection-report-storage.test.ts.snap} +22 -22
- package/test/src/__snapshots__/storage_sync.test.ts.snap +282 -0
- package/test/src/{client-connections-storage.test.ts → connection-report-storage.test.ts} +5 -5
- package/test/src/setup.ts +1 -1
- package/test/tsconfig.json +0 -1
- package/dist/@types/storage/current-data-table.d.ts +0 -9
- package/dist/storage/current-data-table.js +0 -22
- package/dist/storage/current-data-table.js.map +0 -1
- package/src/storage/current-data-table.ts +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresPersistedSyncRulesContent.js","sourceRoot":"","sources":["../../../src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"PostgresPersistedSyncRulesContent.js","sourceRoot":"","sources":["../../../src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,MAAM,OAAO,iCAAkC,SAAQ,OAAO,CAAC,yBAAyB;IAI5E;IAHV,YAAY,GAAmC,IAAI,CAAC;IAEpD,YACU,EAA+B,EACvC,GAA4B;QAE5B,KAAK,CAAC;YACJ,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,kBAAkB,EAAE,GAAG,CAAC,OAAO;YAC/B,aAAa,EAAE,GAAG,CAAC,SAAS;YAC5B,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;YAC5C,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;YACpF,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI;YACjF,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,QAAQ;YAC7B,cAAc,EAAE,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,sBAAsB;SACtE,CAAC,CAAC;QAdK,OAAE,GAAF,EAAE,CAA6B;IAezC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,mBAAmB,CAAC;YACnD,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,cAAc,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;SAChD,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,WAAW,EAAE,+DAA+D,CAAC,CAAC;QACjH,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;YACtC,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBAC/C,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC,EAAE,MAAM,CAAC,CAAC;QAEX,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG;YAC1B,aAAa,EAAE,IAAI,CAAC,EAAE;YACtB,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACxB,OAAO,UAAU,CAAC,OAAO,EAAE,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { framework, storage } from '@powersync/service-core';
|
|
2
|
+
import { ReplicationError } from '@powersync/service-types';
|
|
2
3
|
import * as t from 'ts-codec';
|
|
3
4
|
import { bigint, pgwire_number } from '../codecs.js';
|
|
4
5
|
import { jsonContainerObject } from './json.js';
|
|
@@ -56,7 +57,8 @@ export const SyncRules = t.object({
|
|
|
56
57
|
overrides: t.record(t.boolean),
|
|
57
58
|
maxTimeValuePrecision: t.number.optional()
|
|
58
59
|
}),
|
|
59
|
-
eventDescriptors: t.record(t.array(t.string))
|
|
60
|
+
eventDescriptors: t.record(t.array(t.string)),
|
|
61
|
+
errors: t.array(ReplicationError).optional()
|
|
60
62
|
})))
|
|
61
63
|
});
|
|
62
64
|
//# sourceMappingURL=SyncRules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncRules.js","sourceRoot":"","sources":["../../../src/types/models/SyncRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,aAAa;IACjB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;IACpC;;;;OAIG;IACH,aAAa,EAAE,CAAC,CAAC,OAAO;IACxB;;OAEG;IACH,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IACjC;;;;OAIG;IACH,eAAe,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;IAClC;;OAEG;IACH,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC;;OAEG;IACH,oBAAoB,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;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AAE,CAClB,mBAAmB,CACjB,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,GAAG;QACX,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,CAAC,CAAC,MAAM;YACjB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,qBAAqB,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;SAC3C,CAAC;QACF,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;KAC7C,CAAC,CACH,CACF;CACF,CAAC,CAAC"}
|
|
@@ -5,8 +5,8 @@ export * from './BucketParameters.js';
|
|
|
5
5
|
export * from './CurrentData.js';
|
|
6
6
|
export * from './Instance.js';
|
|
7
7
|
export * from './Migration.js';
|
|
8
|
+
export * from './SdkReporting.js';
|
|
8
9
|
export * from './SourceTable.js';
|
|
9
10
|
export * from './SyncRules.js';
|
|
10
11
|
export * from './WriteCheckpoint.js';
|
|
11
|
-
export * from './SdkReporting.js';
|
|
12
12
|
//# sourceMappingURL=models-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models-index.js","sourceRoot":"","sources":["../../../src/types/models/models-index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC
|
|
1
|
+
{"version":3,"file":"models-index.js","sourceRoot":"","sources":["../../../src/types/models/models-index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
package/dist/utils/test-utils.js
CHANGED
|
@@ -1,61 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
1
|
+
import { createLogger, logger as defaultLogger, transports } from '@powersync/lib-services-framework';
|
|
53
2
|
import { framework } from '@powersync/service-core';
|
|
54
3
|
import { PostgresMigrationAgent } from '../migrations/PostgresMigrationAgent.js';
|
|
55
|
-
import { normalizePostgresStorageConfig } from '../types/types.js';
|
|
56
|
-
import { PostgresReportStorage } from '../storage/PostgresReportStorage.js';
|
|
57
4
|
import { PostgresBucketStorageFactory } from '../storage/PostgresBucketStorageFactory.js';
|
|
58
|
-
import {
|
|
5
|
+
import { PostgresReportStorage } from '../storage/PostgresReportStorage.js';
|
|
6
|
+
import { normalizePostgresStorageConfig } from '../types/types.js';
|
|
59
7
|
import { truncateTables } from './db.js';
|
|
60
8
|
export function postgresTestSetup(factoryOptions) {
|
|
61
9
|
const BASE_CONFIG = {
|
|
@@ -65,47 +13,35 @@ export function postgresTestSetup(factoryOptions) {
|
|
|
65
13
|
};
|
|
66
14
|
const TEST_CONNECTION_OPTIONS = normalizePostgresStorageConfig(BASE_CONFIG);
|
|
67
15
|
const runMigrations = async (options) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
16
|
+
await using migrationManager = new framework.MigrationManager();
|
|
17
|
+
await using migrationAgent = factoryOptions.migrationAgent
|
|
18
|
+
? factoryOptions.migrationAgent(BASE_CONFIG)
|
|
19
|
+
: new PostgresMigrationAgent(BASE_CONFIG);
|
|
20
|
+
migrationManager.registerMigrationAgent(migrationAgent);
|
|
21
|
+
const mockServiceContext = { configuration: { storage: BASE_CONFIG } };
|
|
22
|
+
// Migration logs can get really verbose in tests, so only log warnings and up.
|
|
23
|
+
const logger = createLogger({
|
|
24
|
+
level: 'warn',
|
|
25
|
+
format: defaultLogger.format,
|
|
26
|
+
transports: [new transports.Console()]
|
|
27
|
+
});
|
|
28
|
+
if (options.down) {
|
|
29
|
+
await migrationManager.migrate({
|
|
30
|
+
direction: framework.migrations.Direction.Down,
|
|
31
|
+
migrationContext: {
|
|
32
|
+
service_context: mockServiceContext
|
|
33
|
+
},
|
|
34
|
+
logger
|
|
81
35
|
});
|
|
82
|
-
if (options.down) {
|
|
83
|
-
await migrationManager.migrate({
|
|
84
|
-
direction: framework.migrations.Direction.Down,
|
|
85
|
-
migrationContext: {
|
|
86
|
-
service_context: mockServiceContext
|
|
87
|
-
},
|
|
88
|
-
logger
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (options.up) {
|
|
92
|
-
await migrationManager.migrate({
|
|
93
|
-
direction: framework.migrations.Direction.Up,
|
|
94
|
-
migrationContext: {
|
|
95
|
-
service_context: mockServiceContext
|
|
96
|
-
},
|
|
97
|
-
logger
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
catch (e_1) {
|
|
102
|
-
env_1.error = e_1;
|
|
103
|
-
env_1.hasError = true;
|
|
104
36
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
37
|
+
if (options.up) {
|
|
38
|
+
await migrationManager.migrate({
|
|
39
|
+
direction: framework.migrations.Direction.Up,
|
|
40
|
+
migrationContext: {
|
|
41
|
+
service_context: mockServiceContext
|
|
42
|
+
},
|
|
43
|
+
logger
|
|
44
|
+
});
|
|
109
45
|
}
|
|
110
46
|
};
|
|
111
47
|
const migrate = async (direction) => {
|
|
@@ -115,24 +51,12 @@ export function postgresTestSetup(factoryOptions) {
|
|
|
115
51
|
});
|
|
116
52
|
};
|
|
117
53
|
const clearStorage = async () => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}), true);
|
|
125
|
-
await truncateTables(storageFactory.db);
|
|
126
|
-
}
|
|
127
|
-
catch (e_2) {
|
|
128
|
-
env_2.error = e_2;
|
|
129
|
-
env_2.hasError = true;
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
const result_2 = __disposeResources(env_2);
|
|
133
|
-
if (result_2)
|
|
134
|
-
await result_2;
|
|
135
|
-
}
|
|
54
|
+
await runMigrations({ down: false, up: true });
|
|
55
|
+
await using storageFactory = new PostgresBucketStorageFactory({
|
|
56
|
+
config: TEST_CONNECTION_OPTIONS,
|
|
57
|
+
slot_name_prefix: 'test_'
|
|
58
|
+
});
|
|
59
|
+
await truncateTables(storageFactory.db);
|
|
136
60
|
};
|
|
137
61
|
return {
|
|
138
62
|
reportFactory: async (options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/utils/test-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/utils/test-utils.ts"],"names":[],"mappings":"AAAA,O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AC;oBAC/B,MAAM,EAAE,uBAAuB;iBAChC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACZ,iFAAiF;gBACjF,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC5B,MAAM,EAAE,CAAC;YACX,CAAC;QACH,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,OAA4B,EAAE,EAAE;YAC9C,IAAI,CAAC;gBACH,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;oBACzB,MAAM,YAAY,EAAE,CAAC;gBACvB,CAAC;gBAED,OAAO,IAAI,4BAA4B,CAAC;oBACtC,MAAM,EAAE,uBAAuB;oBAC/B,gBAAgB,EAAE,OAAO;iBAC1B,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACZ,iFAAiF;gBACjF,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC5B,MAAM,EAAE,CAAC;YACX,CAAC;QACH,CAAC;QACD,OAAO;QACP,cAAc,EAAE,IAAI;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../../src/utils/utils-index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,
|
|
1
|
+
{"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../../src/utils/utils-index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@powersync/service-module-postgres-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
4
|
"types": "dist/@types/index.d.ts",
|
|
5
|
-
"version": "0.0.0-dev-
|
|
5
|
+
"version": "0.0.0-dev-20260515144844",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "FSL-1.1-ALv2",
|
|
8
8
|
"type": "module",
|
|
@@ -26,20 +26,19 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"ix": "^5.0.0",
|
|
28
28
|
"lru-cache": "^10.2.2",
|
|
29
|
-
"p-defer": "^4.0.1",
|
|
30
29
|
"ts-codec": "^1.3.0",
|
|
31
|
-
"uuid": "^
|
|
32
|
-
"@powersync/lib-service-postgres": "0.0.0-dev-
|
|
33
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
34
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-types": "0.
|
|
36
|
-
"@powersync/service-jpgwire": "0.
|
|
37
|
-
"@powersync/service-jsonbig": "0.17.
|
|
38
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
30
|
+
"uuid": "^14.0.0",
|
|
31
|
+
"@powersync/lib-service-postgres": "0.0.0-dev-20260515144844",
|
|
32
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20260515144844",
|
|
33
|
+
"@powersync/service-core": "0.0.0-dev-20260515144844",
|
|
34
|
+
"@powersync/service-types": "0.15.2",
|
|
35
|
+
"@powersync/service-jpgwire": "0.21.18",
|
|
36
|
+
"@powersync/service-jsonbig": "0.17.13",
|
|
37
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20260515144844"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"typescript": "
|
|
42
|
-
"@powersync/service-core-tests": "0.
|
|
40
|
+
"typescript": "~6.0.3",
|
|
41
|
+
"@powersync/service-core-tests": "0.15.5"
|
|
43
42
|
},
|
|
44
43
|
"scripts": {
|
|
45
44
|
"build": "tsc -b",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
+
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
2
3
|
import { configFile } from '@powersync/service-types';
|
|
3
4
|
import { isPostgresStorageConfig, normalizePostgresStorageConfig, PostgresStorageConfig } from '../types/types.js';
|
|
4
|
-
import { STORAGE_SCHEMA_NAME } from '../utils/db.js';
|
|
5
|
-
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
6
5
|
import { getStorageApplicationName } from '../utils/application-name.js';
|
|
6
|
+
import { STORAGE_SCHEMA_NAME } from '../utils/db.js';
|
|
7
7
|
|
|
8
8
|
export const openMigrationDB = (config: configFile.BaseStorageConfig) => {
|
|
9
9
|
if (!isPostgresStorageConfig(config)) {
|
|
@@ -2,7 +2,7 @@ import { migrations } from '@powersync/service-core';
|
|
|
2
2
|
|
|
3
3
|
export const up: migrations.PowerSyncMigrationFunction = async (_context) => {
|
|
4
4
|
// No-op.
|
|
5
|
-
// Pending-delete support is now storage-version specific and initialized when v3 sync
|
|
5
|
+
// Pending-delete support is now storage-version specific and initialized when v3 sync config is deployed.
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export const down: migrations.PowerSyncMigrationFunction = async (_context) => {
|
|
@@ -18,6 +18,7 @@ export type PostgresBucketStorageOptions = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
21
|
+
[framework.DO_NOT_LOG] = true;
|
|
21
22
|
readonly db: lib_postgres.DatabaseClient;
|
|
22
23
|
public readonly slot_name_prefix: string;
|
|
23
24
|
|
|
@@ -153,7 +154,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
async updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedSyncRulesContent> {
|
|
156
|
-
const storageVersion =
|
|
157
|
+
const storageVersion =
|
|
158
|
+
options.storageVersion ?? options.config.parsed.config.storageVersion ?? storage.CURRENT_STORAGE_VERSION;
|
|
157
159
|
const storageConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
|
|
158
160
|
if (storageConfig == null) {
|
|
159
161
|
throw new framework.ServiceError(
|
|
@@ -254,10 +256,10 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
254
256
|
const next = await this.getNextSyncRulesContent();
|
|
255
257
|
const active = await this.getActiveSyncRulesContent();
|
|
256
258
|
|
|
257
|
-
// In both the below cases, we create a new
|
|
259
|
+
// In both the below cases, we create a new replication stream.
|
|
258
260
|
// The current one will continue serving sync requests until the next one has finished processing.
|
|
259
261
|
if (next != null && next.id == sync_rules_group_id) {
|
|
260
|
-
// We need to redo the "next"
|
|
262
|
+
// We need to redo the "next" replication stream
|
|
261
263
|
|
|
262
264
|
await this.updateSyncRules(next.asUpdateOptions());
|
|
263
265
|
// Pro-actively stop replicating
|
|
@@ -270,7 +272,7 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
270
272
|
AND state = ${{ value: storage.SyncRuleState.PROCESSING, type: 'varchar' }}
|
|
271
273
|
`.execute();
|
|
272
274
|
} else if (next == null && active?.id == sync_rules_group_id) {
|
|
273
|
-
// Slot removed for "active"
|
|
275
|
+
// Slot removed for "active" replication stream, while there is no "next" one.
|
|
274
276
|
await this.updateSyncRules(active.asUpdateOptions());
|
|
275
277
|
|
|
276
278
|
// Pro-actively stop replicating, but still serve clients with existing data
|
|
@@ -283,7 +285,7 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
283
285
|
AND state = ${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }}
|
|
284
286
|
`.execute();
|
|
285
287
|
} else if (next != null && active?.id == sync_rules_group_id) {
|
|
286
|
-
// Already have "next"
|
|
288
|
+
// Already have "next" replication stream - don't update any.
|
|
287
289
|
|
|
288
290
|
// Pro-actively stop replicating, but still serve clients with existing data
|
|
289
291
|
await this.db.sql`
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
1
3
|
import { storage } from '@powersync/service-core';
|
|
2
4
|
import * as pg_wire from '@powersync/service-jpgwire';
|
|
3
5
|
import { event_types } from '@powersync/service-types';
|
|
6
|
+
import { ClientConnectionResponse } from '@powersync/service-types/dist/reports.js';
|
|
7
|
+
import { toInteger } from 'ix/util/tointeger.js';
|
|
4
8
|
import { v4 } from 'uuid';
|
|
5
|
-
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
6
|
-
import { NormalizedPostgresStorageConfig } from '../types/types.js';
|
|
7
9
|
import { SdkReporting, SdkReportingDecoded } from '../types/models/SdkReporting.js';
|
|
8
|
-
import {
|
|
9
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
10
|
+
import { NormalizedPostgresStorageConfig } from '../types/types.js';
|
|
10
11
|
import { getStorageApplicationName } from '../utils/application-name.js';
|
|
11
12
|
import { STORAGE_SCHEMA_NAME } from '../utils/db.js';
|
|
12
|
-
import { ClientConnectionResponse } from '@powersync/service-types/dist/reports.js';
|
|
13
13
|
|
|
14
14
|
export type PostgresReportStorageOptions = {
|
|
15
15
|
config: NormalizedPostgresStorageConfig;
|
|
@@ -48,13 +48,13 @@ export class PostgresReportStorage implements storage.ReportStorage {
|
|
|
48
48
|
): event_types.ClientConnectionReportResponse {
|
|
49
49
|
if (!result) {
|
|
50
50
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
users: 0,
|
|
52
|
+
sdks: []
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
return {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
users: Number(result.users),
|
|
57
|
+
sdks: result.sdks?.data || []
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
private async listConnectionsQuery() {
|
|
@@ -234,12 +234,12 @@ export class PostgresReportStorage implements storage.ReportStorage {
|
|
|
234
234
|
AND connected_at = ${{ type: 1184, value: connectIsoString }}
|
|
235
235
|
`.execute();
|
|
236
236
|
}
|
|
237
|
-
async
|
|
237
|
+
async getConnectedClients(): Promise<event_types.ClientConnectionReportResponse> {
|
|
238
238
|
const result = await this.listConnectionsQuery();
|
|
239
239
|
return this.mapListCurrentConnectionsResponse(result);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
async
|
|
242
|
+
async getClientConnectionReports(
|
|
243
243
|
data: event_types.ClientConnectionReportRequest
|
|
244
244
|
): Promise<event_types.ClientConnectionReportResponse> {
|
|
245
245
|
const { start, end } = data;
|
|
@@ -289,7 +289,7 @@ export class PostgresReportStorage implements storage.ReportStorage {
|
|
|
289
289
|
return this.mapListCurrentConnectionsResponse(result);
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
async
|
|
292
|
+
async getGeneralClientConnectionAnalytics(
|
|
293
293
|
data: event_types.ClientConnectionAnalyticsRequest
|
|
294
294
|
): Promise<event_types.PaginatedResponse<event_types.ClientConnection>> {
|
|
295
295
|
const limit = data.limit || 100;
|