@powersync/service-module-postgres-storage 0.0.0-dev-20250827091123 → 0.0.0-dev-20250828134335
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 +27 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresStorageProvider.d.ts +1 -1
- package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +3 -1
- package/dist/@types/{utils/test-utils.d.ts → storage/PostgresTestStorageFactoryGenerator.d.ts} +3 -5
- package/dist/@types/storage/storage-index.d.ts +1 -0
- package/dist/@types/types/models/models-index.d.ts +0 -1
- package/dist/@types/utils/utils-index.d.ts +0 -1
- package/dist/migrations/scripts/1684951997326-init.js +0 -18
- package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
- package/dist/storage/PostgresStorageProvider.js +1 -10
- package/dist/storage/PostgresStorageProvider.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +19 -6
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/{utils/test-utils.js → storage/PostgresTestStorageFactoryGenerator.js} +6 -22
- package/dist/storage/PostgresTestStorageFactoryGenerator.js.map +1 -0
- package/dist/storage/batch/PostgresBucketBatch.js +5 -2
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/storage-index.js +1 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/models/models-index.js +0 -1
- package/dist/types/models/models-index.js.map +1 -1
- package/dist/utils/utils-index.js +0 -1
- package/dist/utils/utils-index.js.map +1 -1
- package/package.json +12 -11
- package/src/migrations/scripts/1684951997326-init.ts +0 -22
- package/src/storage/PostgresStorageProvider.ts +2 -13
- package/src/storage/PostgresSyncRulesStorage.ts +26 -7
- package/src/{utils/test-utils.ts → storage/PostgresTestStorageFactoryGenerator.ts} +5 -21
- package/src/storage/batch/PostgresBucketBatch.ts +4 -2
- package/src/storage/storage-index.ts +1 -0
- package/src/types/models/models-index.ts +0 -1
- package/src/utils/utils-index.ts +0 -1
- package/test/src/__snapshots__/storage_sync.test.ts.snap +110 -0
- package/test/src/util.ts +6 -3
- package/dist/@types/migrations/scripts/1756282360128-connection-reporting.d.ts +0 -3
- package/dist/@types/storage/PostgresReportStorageFactory.d.ts +0 -24
- package/dist/@types/types/models/SdkReporting.d.ts +0 -21
- package/dist/migrations/scripts/1756282360128-connection-reporting.js +0 -107
- package/dist/migrations/scripts/1756282360128-connection-reporting.js.map +0 -1
- package/dist/storage/PostgresReportStorageFactory.js +0 -238
- package/dist/storage/PostgresReportStorageFactory.js.map +0 -1
- package/dist/types/models/SdkReporting.js +0 -17
- package/dist/types/models/SdkReporting.js.map +0 -1
- package/dist/utils/test-utils.js.map +0 -1
- package/src/migrations/scripts/1756282360128-connection-reporting.ts +0 -41
- package/src/storage/PostgresReportStorageFactory.ts +0 -258
- package/src/types/models/SdkReporting.ts +0 -23
- package/test/src/__snapshots__/connection-report-storage.test.ts.snap +0 -215
- package/test/src/connection-report-storage.test.ts +0 -233
|
@@ -5,9 +5,8 @@ import { storage } from '@powersync/service-core';
|
|
|
5
5
|
import { isPostgresStorageConfig, normalizePostgresStorageConfig, PostgresStorageConfig } from '../types/types.js';
|
|
6
6
|
import { dropTables } from '../utils/db.js';
|
|
7
7
|
import { PostgresBucketStorageFactory } from './PostgresBucketStorageFactory.js';
|
|
8
|
-
import { PostgresReportStorageFactory } from './PostgresReportStorageFactory.js';
|
|
9
8
|
|
|
10
|
-
export class PostgresStorageProvider implements storage.
|
|
9
|
+
export class PostgresStorageProvider implements storage.BucketStorageProvider {
|
|
11
10
|
get type() {
|
|
12
11
|
return lib_postgres.POSTGRES_CONNECTION_TYPE;
|
|
13
12
|
}
|
|
@@ -29,23 +28,13 @@ export class PostgresStorageProvider implements storage.StorageProvider {
|
|
|
29
28
|
config: normalizedConfig,
|
|
30
29
|
slot_name_prefix: options.resolvedConfig.slot_name_prefix
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
const reportStorageFactory = new PostgresReportStorageFactory({
|
|
34
|
-
config: normalizedConfig
|
|
35
|
-
});
|
|
36
|
-
|
|
37
31
|
return {
|
|
38
|
-
reportStorage: reportStorageFactory,
|
|
39
32
|
storage: storageFactory,
|
|
40
|
-
shutDown: async () =>
|
|
41
|
-
await storageFactory.db[Symbol.asyncDispose]();
|
|
42
|
-
await reportStorageFactory.db[Symbol.asyncDispose]();
|
|
43
|
-
},
|
|
33
|
+
shutDown: async () => storageFactory.db[Symbol.asyncDispose](),
|
|
44
34
|
tearDown: async () => {
|
|
45
35
|
logger.info(`Tearing down Postgres storage: ${normalizedConfig.database}...`);
|
|
46
36
|
await dropTables(storageFactory.db);
|
|
47
37
|
await storageFactory.db[Symbol.asyncDispose]();
|
|
48
|
-
await reportStorageFactory.db[Symbol.asyncDispose]();
|
|
49
38
|
return true;
|
|
50
39
|
}
|
|
51
40
|
} satisfies storage.ActiveStorage;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
2
|
import {
|
|
3
3
|
BroadcastIterable,
|
|
4
|
+
BucketChecksum,
|
|
4
5
|
CHECKPOINT_INVALIDATE_ALL,
|
|
5
6
|
CheckpointChanges,
|
|
7
|
+
CompactOptions,
|
|
6
8
|
GetCheckpointChangesOptions,
|
|
7
9
|
InternalOpId,
|
|
8
10
|
internalToExternalOpId,
|
|
9
11
|
LastValueSink,
|
|
10
12
|
maxLsn,
|
|
13
|
+
PartialChecksum,
|
|
11
14
|
ReplicationCheckpoint,
|
|
12
15
|
storage,
|
|
13
16
|
utils,
|
|
@@ -109,6 +112,10 @@ export class PostgresSyncRulesStorage
|
|
|
109
112
|
return new PostgresCompactor(this.db, this.group_id, options).compact();
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
async populatePersistentChecksumCache(options: Pick<CompactOptions, 'signal' | 'maxOpId'>): Promise<void> {
|
|
116
|
+
// no-op - checksum cache is not implemented for Postgres yet
|
|
117
|
+
}
|
|
118
|
+
|
|
112
119
|
lastWriteCheckpoint(filters: storage.SyncStorageLastWriteCheckpointFilters): Promise<bigint | null> {
|
|
113
120
|
return this.writeCheckpointAPI.lastWriteCheckpoint({
|
|
114
121
|
...filters,
|
|
@@ -571,6 +578,10 @@ export class PostgresSyncRulesStorage
|
|
|
571
578
|
return this.checksumCache.getChecksumMap(checkpoint, buckets);
|
|
572
579
|
}
|
|
573
580
|
|
|
581
|
+
clearChecksumCache() {
|
|
582
|
+
this.checksumCache.clear();
|
|
583
|
+
}
|
|
584
|
+
|
|
574
585
|
async terminate(options?: storage.TerminateOptions) {
|
|
575
586
|
if (!options || options?.clearStorage) {
|
|
576
587
|
await this.clear(options);
|
|
@@ -692,16 +703,24 @@ export class PostgresSyncRulesStorage
|
|
|
692
703
|
b.bucket_name;
|
|
693
704
|
`.rows<{ bucket: string; checksum_total: bigint; total: bigint; has_clear_op: number }>();
|
|
694
705
|
|
|
695
|
-
return new Map<string, storage.
|
|
706
|
+
return new Map<string, storage.PartialOrFullChecksum>(
|
|
696
707
|
results.map((doc) => {
|
|
708
|
+
const checksum = Number(BigInt(doc.checksum_total) & 0xffffffffn) & 0xffffffff;
|
|
709
|
+
|
|
697
710
|
return [
|
|
698
711
|
doc.bucket,
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
712
|
+
doc.has_clear_op == 1
|
|
713
|
+
? ({
|
|
714
|
+
// full checksum
|
|
715
|
+
bucket: doc.bucket,
|
|
716
|
+
count: Number(doc.total),
|
|
717
|
+
checksum
|
|
718
|
+
} satisfies BucketChecksum)
|
|
719
|
+
: ({
|
|
720
|
+
bucket: doc.bucket,
|
|
721
|
+
partialCount: Number(doc.total),
|
|
722
|
+
partialChecksum: checksum
|
|
723
|
+
} satisfies PartialChecksum)
|
|
705
724
|
];
|
|
706
725
|
})
|
|
707
726
|
);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { framework, PowerSyncMigrationManager, ServiceContext, TestStorageOptions } from '@powersync/service-core';
|
|
2
2
|
import { PostgresMigrationAgent } from '../migrations/PostgresMigrationAgent.js';
|
|
3
3
|
import { normalizePostgresStorageConfig, PostgresStorageConfigDecoded } from '../types/types.js';
|
|
4
|
-
import {
|
|
5
|
-
import { PostgresBucketStorageFactory } from '../storage/PostgresBucketStorageFactory.js';
|
|
4
|
+
import { PostgresBucketStorageFactory } from './PostgresBucketStorageFactory.js';
|
|
6
5
|
|
|
7
6
|
export type PostgresTestStorageOptions = {
|
|
8
7
|
url: string;
|
|
@@ -13,7 +12,7 @@ export type PostgresTestStorageOptions = {
|
|
|
13
12
|
migrationAgent?: (config: PostgresStorageConfigDecoded) => PostgresMigrationAgent;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
|
-
export
|
|
15
|
+
export const postgresTestSetup = (factoryOptions: PostgresTestStorageOptions) => {
|
|
17
16
|
const BASE_CONFIG = {
|
|
18
17
|
type: 'postgresql' as const,
|
|
19
18
|
uri: factoryOptions.url,
|
|
@@ -49,21 +48,6 @@ export function postgresTestSetup(factoryOptions: PostgresTestStorageOptions) {
|
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
return {
|
|
52
|
-
reportFactory: async (options?: TestStorageOptions) => {
|
|
53
|
-
try {
|
|
54
|
-
if (!options?.doNotClear) {
|
|
55
|
-
await migrate(framework.migrations.Direction.Up);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return new PostgresReportStorageFactory({
|
|
59
|
-
config: TEST_CONNECTION_OPTIONS
|
|
60
|
-
});
|
|
61
|
-
} catch (ex) {
|
|
62
|
-
// Vitest does not display these errors nicely when using the `await using` syntx
|
|
63
|
-
console.error(ex, ex.cause);
|
|
64
|
-
throw ex;
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
51
|
factory: async (options?: TestStorageOptions) => {
|
|
68
52
|
try {
|
|
69
53
|
if (!options?.doNotClear) {
|
|
@@ -82,8 +66,8 @@ export function postgresTestSetup(factoryOptions: PostgresTestStorageOptions) {
|
|
|
82
66
|
},
|
|
83
67
|
migrate
|
|
84
68
|
};
|
|
85
|
-
}
|
|
69
|
+
};
|
|
86
70
|
|
|
87
|
-
export
|
|
71
|
+
export const PostgresTestStorageFactoryGenerator = (factoryOptions: PostgresTestStorageOptions) => {
|
|
88
72
|
return postgresTestSetup(factoryOptions).factory;
|
|
89
|
-
}
|
|
73
|
+
};
|
|
@@ -687,7 +687,8 @@ export class PostgresBucketBatch
|
|
|
687
687
|
// We store bytea colums for source keys
|
|
688
688
|
const beforeId = operation.beforeId;
|
|
689
689
|
const afterId = operation.afterId;
|
|
690
|
-
let
|
|
690
|
+
let sourceAfter = record.after;
|
|
691
|
+
let after = sourceAfter && this.sync_rules.applyRowContext(sourceAfter);
|
|
691
692
|
const sourceTable = record.sourceTable;
|
|
692
693
|
|
|
693
694
|
let existingBuckets: CurrentBucket[] = [];
|
|
@@ -825,7 +826,8 @@ export class PostgresBucketBatch
|
|
|
825
826
|
if (sourceTable.syncData) {
|
|
826
827
|
const { results: evaluated, errors: syncErrors } = this.sync_rules.evaluateRowWithErrors({
|
|
827
828
|
record: after,
|
|
828
|
-
sourceTable
|
|
829
|
+
sourceTable,
|
|
830
|
+
bucketIdTransformer: sync_rules.SqlSyncRules.versionedBucketIdTransformer(`${this.group_id}`)
|
|
829
831
|
});
|
|
830
832
|
|
|
831
833
|
for (const error of syncErrors) {
|
package/src/utils/utils-index.ts
CHANGED
|
@@ -104,6 +104,116 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
|
|
|
104
104
|
]
|
|
105
105
|
`;
|
|
106
106
|
|
|
107
|
+
exports[`sync - postgres > encodes sync rules id in buckes for streams 1`] = `
|
|
108
|
+
[
|
|
109
|
+
{
|
|
110
|
+
"checkpoint": {
|
|
111
|
+
"buckets": [
|
|
112
|
+
{
|
|
113
|
+
"bucket": "1#test|0[]",
|
|
114
|
+
"checksum": 920318466,
|
|
115
|
+
"count": 1,
|
|
116
|
+
"priority": 3,
|
|
117
|
+
"subscriptions": [
|
|
118
|
+
{
|
|
119
|
+
"default": 0,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
"last_op_id": "1",
|
|
125
|
+
"streams": [
|
|
126
|
+
{
|
|
127
|
+
"errors": [],
|
|
128
|
+
"is_default": true,
|
|
129
|
+
"name": "test",
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
"write_checkpoint": undefined,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"data": {
|
|
137
|
+
"after": "0",
|
|
138
|
+
"bucket": "1#test|0[]",
|
|
139
|
+
"data": [
|
|
140
|
+
{
|
|
141
|
+
"checksum": 920318466,
|
|
142
|
+
"data": "{"id":"t1","description":"Test 1"}",
|
|
143
|
+
"object_id": "t1",
|
|
144
|
+
"object_type": "test",
|
|
145
|
+
"op": "PUT",
|
|
146
|
+
"op_id": "1",
|
|
147
|
+
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
"has_more": false,
|
|
151
|
+
"next_after": "1",
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"checkpoint_complete": {
|
|
156
|
+
"last_op_id": "1",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
]
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
exports[`sync - postgres > encodes sync rules id in buckes for streams 2`] = `
|
|
163
|
+
[
|
|
164
|
+
{
|
|
165
|
+
"checkpoint": {
|
|
166
|
+
"buckets": [
|
|
167
|
+
{
|
|
168
|
+
"bucket": "2#test|0[]",
|
|
169
|
+
"checksum": 920318466,
|
|
170
|
+
"count": 1,
|
|
171
|
+
"priority": 3,
|
|
172
|
+
"subscriptions": [
|
|
173
|
+
{
|
|
174
|
+
"default": 0,
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
"last_op_id": "2",
|
|
180
|
+
"streams": [
|
|
181
|
+
{
|
|
182
|
+
"errors": [],
|
|
183
|
+
"is_default": true,
|
|
184
|
+
"name": "test",
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
"write_checkpoint": undefined,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"data": {
|
|
192
|
+
"after": "0",
|
|
193
|
+
"bucket": "2#test|0[]",
|
|
194
|
+
"data": [
|
|
195
|
+
{
|
|
196
|
+
"checksum": 920318466,
|
|
197
|
+
"data": "{"id":"t1","description":"Test 1"}",
|
|
198
|
+
"object_id": "t1",
|
|
199
|
+
"object_type": "test",
|
|
200
|
+
"op": "PUT",
|
|
201
|
+
"op_id": "2",
|
|
202
|
+
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
"has_more": false,
|
|
206
|
+
"next_after": "2",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"checkpoint_complete": {
|
|
211
|
+
"last_op_id": "2",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
]
|
|
215
|
+
`;
|
|
216
|
+
|
|
107
217
|
exports[`sync - postgres > expired token 1`] = `
|
|
108
218
|
[
|
|
109
219
|
{
|
package/test/src/util.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { normalizePostgresStorageConfig
|
|
3
|
+
import { normalizePostgresStorageConfig } from '../../src//types/types.js';
|
|
4
|
+
import { PostgresMigrationAgent } from '../../src/migrations/PostgresMigrationAgent.js';
|
|
5
|
+
import {
|
|
6
|
+
postgresTestSetup,
|
|
7
|
+
PostgresTestStorageFactoryGenerator
|
|
8
|
+
} from '../../src/storage/PostgresTestStorageFactoryGenerator.js';
|
|
4
9
|
import { env } from './env.js';
|
|
5
|
-
import { postgresTestSetup } from '../../src/utils/test-utils.js';
|
|
6
10
|
|
|
7
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
12
|
const __dirname = path.dirname(__filename);
|
|
@@ -33,4 +37,3 @@ export const POSTGRES_STORAGE_SETUP = postgresTestSetup({
|
|
|
33
37
|
});
|
|
34
38
|
|
|
35
39
|
export const POSTGRES_STORAGE_FACTORY = POSTGRES_STORAGE_SETUP.factory;
|
|
36
|
-
export const POSTGRES_REPORT_STORAGE_FACTORY = POSTGRES_STORAGE_SETUP.reportFactory;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { storage } from '@powersync/service-core';
|
|
2
|
-
import * as pg_wire from '@powersync/service-jpgwire';
|
|
3
|
-
import { event_types } from '@powersync/service-types';
|
|
4
|
-
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
5
|
-
import { NormalizedPostgresStorageConfig } from '../types/types.js';
|
|
6
|
-
export type PostgresReportStorageOptions = {
|
|
7
|
-
config: NormalizedPostgresStorageConfig;
|
|
8
|
-
};
|
|
9
|
-
export declare class PostgresReportStorageFactory implements storage.ReportStorage {
|
|
10
|
-
protected options: PostgresReportStorageOptions;
|
|
11
|
-
readonly db: lib_postgres.DatabaseClient;
|
|
12
|
-
constructor(options: PostgresReportStorageOptions);
|
|
13
|
-
private parseJsDate;
|
|
14
|
-
private mapListCurrentConnectionsResponse;
|
|
15
|
-
private listConnectionsQuery;
|
|
16
|
-
private updateTableFilter;
|
|
17
|
-
reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void>;
|
|
18
|
-
reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void>;
|
|
19
|
-
getConnectedClients(): Promise<event_types.ClientConnectionReportResponse>;
|
|
20
|
-
getClientConnectionReports(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReportResponse>;
|
|
21
|
-
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
22
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
23
|
-
prepareStatements(connection: pg_wire.PgConnection): Promise<void>;
|
|
24
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as t from 'ts-codec';
|
|
2
|
-
export declare const Sdks: t.ObjectCodec<{
|
|
3
|
-
sdk: t.IdentityCodec<t.CodecType.String>;
|
|
4
|
-
clients: t.IdentityCodec<t.CodecType.Number>;
|
|
5
|
-
users: t.IdentityCodec<t.CodecType.Number>;
|
|
6
|
-
}>;
|
|
7
|
-
export type Sdks = t.Encoded<typeof Sdks>;
|
|
8
|
-
export declare const SdkReporting: t.ObjectCodec<{
|
|
9
|
-
users: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
10
|
-
sdks: t.Union<t.Codec<{
|
|
11
|
-
data: {
|
|
12
|
-
sdk: string;
|
|
13
|
-
clients: number;
|
|
14
|
-
users: number;
|
|
15
|
-
}[];
|
|
16
|
-
} | undefined, {
|
|
17
|
-
data: string;
|
|
18
|
-
} | undefined, string, t.CodecProps>, t.Codec<null, null, t.CodecType.Null, t.CodecProps>>;
|
|
19
|
-
}>;
|
|
20
|
-
export type SdkReporting = t.Encoded<typeof SdkReporting>;
|
|
21
|
-
export type SdkReportingDecoded = t.Decoded<typeof SdkReporting>;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
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
|
-
});
|
|
53
|
-
import { openMigrationDB } from '../migration-utils.js';
|
|
54
|
-
export const up = async (context) => {
|
|
55
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
56
|
-
try {
|
|
57
|
-
const { service_context: { configuration } } = context;
|
|
58
|
-
const client = __addDisposableResource(env_1, openMigrationDB(configuration.storage), true);
|
|
59
|
-
await client.transaction(async (db) => {
|
|
60
|
-
await db.sql `
|
|
61
|
-
CREATE TABLE IF NOT EXISTS connection_report_events (
|
|
62
|
-
id TEXT PRIMARY KEY,
|
|
63
|
-
user_agent TEXT NOT NULL,
|
|
64
|
-
client_id TEXT NOT NULL,
|
|
65
|
-
user_id TEXT NOT NULL,
|
|
66
|
-
sdk TEXT NOT NULL,
|
|
67
|
-
jwt_exp TIMESTAMP WITH TIME ZONE,
|
|
68
|
-
connected_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
69
|
-
disconnected_at TIMESTAMP WITH TIME ZONE
|
|
70
|
-
)
|
|
71
|
-
`.execute();
|
|
72
|
-
await db.sql `
|
|
73
|
-
CREATE INDEX IF NOT EXISTS sdk_list_index ON connection_report_events (connected_at, jwt_exp, disconnected_at)
|
|
74
|
-
`.execute();
|
|
75
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_user_id_index ON connection_report_events (user_id)`.execute();
|
|
76
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_client_id_index ON connection_report_events (client_id)`.execute();
|
|
77
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_index ON connection_report_events (sdk)`.execute();
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (e_1) {
|
|
81
|
-
env_1.error = e_1;
|
|
82
|
-
env_1.hasError = true;
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
const result_1 = __disposeResources(env_1);
|
|
86
|
-
if (result_1)
|
|
87
|
-
await result_1;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
export const down = async (context) => {
|
|
91
|
-
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
92
|
-
try {
|
|
93
|
-
const { service_context: { configuration } } = context;
|
|
94
|
-
const client = __addDisposableResource(env_2, openMigrationDB(configuration.storage), true);
|
|
95
|
-
await client.sql `DROP TABLE IF EXISTS connection_report_events`.execute();
|
|
96
|
-
}
|
|
97
|
-
catch (e_2) {
|
|
98
|
-
env_2.error = e_2;
|
|
99
|
-
env_2.hasError = true;
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
const result_2 = __disposeResources(env_2);
|
|
103
|
-
if (result_2)
|
|
104
|
-
await result_2;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=1756282360128-connection-reporting.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1756282360128-connection-reporting.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1756282360128-connection-reporting.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAC5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YACpC,MAAM,EAAE,CAAC,GAAG,CAAA;;;;;;;;;;;KAWX,CAAC,OAAO,EAAE,CAAC;YAEZ,MAAM,EAAE,CAAC,GAAG,CAAA;;KAEX,CAAC,OAAO,EAAE,CAAC;YAEZ,MAAM,EAAE,CAAC,GAAG,CAAA,oFAAoF,CAAC,OAAO,EAAE,CAAC;YAE3G,MAAM,EAAE,CAAC,GAAG,CAAA,wFAAwF,CAAC,OAAO,EAAE,CAAC;YAE/G,MAAM,EAAE,CAAC,GAAG,CAAA,wEAAwE,CAAC,OAAO,EAAE,CAAC;QACjG,CAAC,CAAC,CAAC;;;;;;;;;;;CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAC5D,MAAM,MAAM,CAAC,GAAG,CAAA,+CAA+C,CAAC,OAAO,EAAE,CAAC;;;;;;;;;;;CAC3E,CAAC"}
|