@powersync/service-core 0.0.0-dev-20241111122558 → 0.0.0-dev-20241128134723
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 +35 -17
- package/dist/auth/StaticSupabaseKeyCollector.d.ts +19 -0
- package/dist/auth/StaticSupabaseKeyCollector.js +28 -0
- package/dist/auth/StaticSupabaseKeyCollector.js.map +1 -0
- package/dist/auth/auth-index.d.ts +1 -0
- package/dist/auth/auth-index.js +1 -0
- package/dist/auth/auth-index.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +16 -0
- package/dist/routes/configure-fastify.js +2 -1
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/endpoints/probes.d.ts +74 -0
- package/dist/routes/endpoints/probes.js +51 -0
- package/dist/routes/endpoints/probes.js.map +1 -0
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/router.d.ts +2 -2
- package/dist/storage/BucketStorage.d.ts +10 -0
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/mongo/MongoBucketBatch.d.ts +11 -1
- package/dist/storage/mongo/MongoBucketBatch.js +55 -39
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
- package/dist/storage/mongo/MongoSyncBucketStorage.js +9 -1
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js +9 -2
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/mongo/OperationBatch.d.ts +6 -1
- package/dist/storage/mongo/OperationBatch.js +9 -0
- package/dist/storage/mongo/OperationBatch.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +16 -0
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/package.json +6 -9
- package/src/auth/StaticSupabaseKeyCollector.ts +31 -0
- package/src/auth/auth-index.ts +1 -0
- package/src/routes/configure-fastify.ts +2 -1
- package/src/routes/endpoints/probes.ts +58 -0
- package/src/routes/endpoints/sync-rules.ts +1 -2
- package/src/routes/router.ts +2 -2
- package/src/storage/BucketStorage.ts +10 -0
- package/src/storage/mongo/MongoBucketBatch.ts +74 -54
- package/src/storage/mongo/MongoSyncBucketStorage.ts +13 -12
- package/src/storage/mongo/MongoWriteCheckpointAPI.ts +9 -2
- package/src/storage/mongo/OperationBatch.ts +10 -1
- package/src/util/config/compound-config-collector.ts +19 -1
- package/test/src/routes/probes.integration.test.ts +235 -0
- package/test/src/routes/probes.test.ts +153 -0
- package/test/src/sync.test.ts +62 -1
- package/test/src/util.ts +2 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
# @powersync/service-core
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20241128134723
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
7
|
+
- 74548e4: Add "supabase_jwt_secret" config option to simplify static Supabase auth.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [74548e4]
|
|
12
|
+
- @powersync/service-types@0.0.0-dev-20241128134723
|
|
13
|
+
|
|
14
|
+
## 0.9.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 57bd18b: Added ability to emit data replication events
|
|
19
|
+
- 57bd18b: Introduced alpha support for MySQL as a datasource for replication.
|
|
9
20
|
Bunch of cleanup
|
|
10
|
-
-
|
|
11
|
-
-
|
|
21
|
+
- 57bd18b: Moved Write Checkpoint APIs to SyncBucketStorage
|
|
22
|
+
- 57bd18b: - Introduced modules to the powersync service architecture
|
|
12
23
|
- Core functionality has been moved to "engine" classes. Modules can register additional functionality with these engines.
|
|
13
24
|
- The sync API functionality used by the routes has been abstracted to an interface. API routes are now managed by the RouterEngine.
|
|
14
25
|
- Replication is managed by the ReplicationEngine and new replication data sources can be registered to the engine by modules.
|
|
@@ -17,18 +28,25 @@
|
|
|
17
28
|
|
|
18
29
|
### Patch Changes
|
|
19
30
|
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- Updated dependencies [
|
|
23
|
-
- Updated dependencies [
|
|
24
|
-
- Updated dependencies [
|
|
25
|
-
- Updated dependencies [
|
|
26
|
-
- Updated dependencies [
|
|
27
|
-
- Updated dependencies [
|
|
28
|
-
|
|
29
|
-
- @powersync/
|
|
30
|
-
- @powersync/service-
|
|
31
|
-
- @powersync/service-
|
|
31
|
+
- 57bd18b: Improved sync rules storage cached parsed sync rules, accommodating different parsing options where necessary.
|
|
32
|
+
- 57bd18b: Moved tag variable initialization in diagnostics route to ensure it is initialized before usage
|
|
33
|
+
- Updated dependencies [57bd18b]
|
|
34
|
+
- Updated dependencies [57bd18b]
|
|
35
|
+
- Updated dependencies [57bd18b]
|
|
36
|
+
- Updated dependencies [57bd18b]
|
|
37
|
+
- Updated dependencies [57bd18b]
|
|
38
|
+
- Updated dependencies [57bd18b]
|
|
39
|
+
- Updated dependencies [57bd18b]
|
|
40
|
+
- @powersync/lib-services-framework@0.2.0
|
|
41
|
+
- @powersync/service-sync-rules@0.21.0
|
|
42
|
+
- @powersync/service-rsocket-router@0.0.14
|
|
43
|
+
- @powersync/service-types@0.3.0
|
|
44
|
+
|
|
45
|
+
## 0.8.8
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- 21de621: Add probe endpoints which can be used for system health checks.
|
|
32
50
|
|
|
33
51
|
## 0.8.7
|
|
34
52
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as jose from 'jose';
|
|
2
|
+
import { KeySpec } from './KeySpec.js';
|
|
3
|
+
import { KeyCollector, KeyResult } from './KeyCollector.js';
|
|
4
|
+
/**
|
|
5
|
+
* Set of static keys for Supabase.
|
|
6
|
+
*
|
|
7
|
+
* Same as StaticKeyCollector, but with some configuration tweaks for Supabase.
|
|
8
|
+
*
|
|
9
|
+
* Similar to SupabaseKeyCollector, but using hardcoded keys instead of fetching
|
|
10
|
+
* from the database.
|
|
11
|
+
*
|
|
12
|
+
* A key can be added both with and without a kid, in case wildcard matching is desired.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StaticSupabaseKeyCollector implements KeyCollector {
|
|
15
|
+
private keys;
|
|
16
|
+
static importKeys(keys: jose.JWK[]): Promise<StaticSupabaseKeyCollector>;
|
|
17
|
+
constructor(keys: KeySpec[]);
|
|
18
|
+
getKeys(): Promise<KeyResult>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KeySpec } from './KeySpec.js';
|
|
2
|
+
const SUPABASE_KEY_OPTIONS = {
|
|
3
|
+
requiresAudience: ['authenticated'],
|
|
4
|
+
maxLifetimeSeconds: 86400 * 7 + 1200 // 1 week + 20 minutes margin
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Set of static keys for Supabase.
|
|
8
|
+
*
|
|
9
|
+
* Same as StaticKeyCollector, but with some configuration tweaks for Supabase.
|
|
10
|
+
*
|
|
11
|
+
* Similar to SupabaseKeyCollector, but using hardcoded keys instead of fetching
|
|
12
|
+
* from the database.
|
|
13
|
+
*
|
|
14
|
+
* A key can be added both with and without a kid, in case wildcard matching is desired.
|
|
15
|
+
*/
|
|
16
|
+
export class StaticSupabaseKeyCollector {
|
|
17
|
+
static async importKeys(keys) {
|
|
18
|
+
const parsedKeys = await Promise.all(keys.map((key) => KeySpec.importKey(key, SUPABASE_KEY_OPTIONS)));
|
|
19
|
+
return new StaticSupabaseKeyCollector(parsedKeys);
|
|
20
|
+
}
|
|
21
|
+
constructor(keys) {
|
|
22
|
+
this.keys = keys;
|
|
23
|
+
}
|
|
24
|
+
async getKeys() {
|
|
25
|
+
return { keys: this.keys, errors: [] };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=StaticSupabaseKeyCollector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticSupabaseKeyCollector.js","sourceRoot":"","sources":["../../src/auth/StaticSupabaseKeyCollector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,MAAM,cAAc,CAAC;AAGnD,MAAM,oBAAoB,GAAe;IACvC,gBAAgB,EAAE,CAAC,eAAe,CAAC;IACnC,kBAAkB,EAAE,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,6BAA6B;CACnE,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,OAAO,0BAA0B;IACrC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAgB;QACtC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;QACtG,OAAO,IAAI,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IAED,YAAoB,IAAe;QAAf,SAAI,GAAJ,IAAI,CAAW;IAAG,CAAC;IAEvC,KAAK,CAAC,OAAO;QACX,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACzC,CAAC;CACF"}
|
package/dist/auth/auth-index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-index.js","sourceRoot":"","sources":["../../src/auth/auth-index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"auth-index.js","sourceRoot":"","sources":["../../src/auth/auth-index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC"}
|
|
@@ -663,6 +663,22 @@ export declare const DEFAULT_ROUTE_OPTIONS: {
|
|
|
663
663
|
handler: (payload: import("./router.js").RequestEndpointHandlerPayload<{}, import("./router.js").Context, import("./router.js").BasicRouterRequest>) => Promise<{
|
|
664
664
|
slot_name: string;
|
|
665
665
|
}>;
|
|
666
|
+
}) | (import("@powersync/lib-services-framework").Endpoint<unknown, import("@powersync/lib-services-framework").RouterResponse<{
|
|
667
|
+
ready: boolean;
|
|
668
|
+
started: boolean;
|
|
669
|
+
touched_at: Date;
|
|
670
|
+
}>, import("./router.js").Context, import("./router.js").RequestEndpointHandlerPayload<unknown, import("./router.js").Context, import("./router.js").BasicRouterRequest>, import("@powersync/lib-services-framework").EndpointHandler<import("./router.js").RequestEndpointHandlerPayload<unknown, import("./router.js").Context, import("./router.js").BasicRouterRequest>, import("@powersync/lib-services-framework").RouterResponse<{
|
|
671
|
+
ready: boolean;
|
|
672
|
+
started: boolean;
|
|
673
|
+
touched_at: Date;
|
|
674
|
+
}>>> & {
|
|
675
|
+
path: import("./endpoints/probes.js").ProbeRoutes;
|
|
676
|
+
method: import("@powersync/lib-services-framework").HTTPMethod.GET;
|
|
677
|
+
handler: () => Promise<import("@powersync/lib-services-framework").RouterResponse<{
|
|
678
|
+
ready: boolean;
|
|
679
|
+
started: boolean;
|
|
680
|
+
touched_at: Date;
|
|
681
|
+
}>>;
|
|
666
682
|
}))[];
|
|
667
683
|
queue_options: {
|
|
668
684
|
concurrency: number;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { registerFastifyRoutes } from './route-register.js';
|
|
2
2
|
import { ADMIN_ROUTES } from './endpoints/admin.js';
|
|
3
3
|
import { CHECKPOINT_ROUTES } from './endpoints/checkpointing.js';
|
|
4
|
+
import { PROBES_ROUTES } from './endpoints/probes.js';
|
|
4
5
|
import { SYNC_RULES_ROUTES } from './endpoints/sync-rules.js';
|
|
5
6
|
import { SYNC_STREAM_ROUTES } from './endpoints/sync-stream.js';
|
|
6
7
|
import { createRequestQueueHook } from './hooks.js';
|
|
7
8
|
export const DEFAULT_ROUTE_OPTIONS = {
|
|
8
9
|
api: {
|
|
9
|
-
routes: [...ADMIN_ROUTES, ...CHECKPOINT_ROUTES, ...SYNC_RULES_ROUTES],
|
|
10
|
+
routes: [...ADMIN_ROUTES, ...CHECKPOINT_ROUTES, ...SYNC_RULES_ROUTES, ...PROBES_ROUTES],
|
|
10
11
|
queue_options: {
|
|
11
12
|
concurrency: 10,
|
|
12
13
|
max_queue_depth: 20
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure-fastify.js","sourceRoot":"","sources":["../../src/routes/configure-fastify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAI5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAA4B,MAAM,YAAY,CAAC;AA0B9E,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,GAAG,EAAE;QACH,MAAM,EAAE,CAAC,GAAG,YAAY,EAAE,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,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C;IAEF;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW,YAAY;QAC1C,qBAAqB,CAAC,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,IAAI,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7G,uCAAuC;QACvC,YAAY,CAAC,OAAO,CAClB,WAAW,EACX,sBAAsB,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,IAAI,qBAAqB,CAAC,GAAG,CAAC,aAAa,CAAC,CAC7F,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,qDAAqD;IACrD,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW,YAAY;QAC1C,qBAAqB,CACnB,YAAY,EACZ,eAAe,EACf,MAAM,CAAC,WAAW,EAAE,MAAM,IAAI,qBAAqB,CAAC,WAAW,CAAC,MAAM,CACvE,CAAC;QACF,uCAAuC;QACvC,YAAY,CAAC,OAAO,CAClB,WAAW,EACX,sBAAsB,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,IAAI,qBAAqB,CAAC,WAAW,CAAC,aAAa,CAAC,CAC7G,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { router } from "@powersync/lib-services-framework";
|
|
2
|
+
export declare enum ProbeRoutes {
|
|
3
|
+
STARTUP = "/probes/startup",
|
|
4
|
+
LIVENESS = "/probes/liveness",
|
|
5
|
+
READINESS = "/probes/readiness"
|
|
6
|
+
}
|
|
7
|
+
export declare const startupCheck: router.Endpoint<unknown, router.RouterResponse<{
|
|
8
|
+
ready: boolean;
|
|
9
|
+
started: boolean;
|
|
10
|
+
touched_at: Date;
|
|
11
|
+
}>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<{
|
|
12
|
+
ready: boolean;
|
|
13
|
+
started: boolean;
|
|
14
|
+
touched_at: Date;
|
|
15
|
+
}>>> & {
|
|
16
|
+
path: ProbeRoutes;
|
|
17
|
+
method: router.HTTPMethod.GET;
|
|
18
|
+
handler: () => Promise<router.RouterResponse<{
|
|
19
|
+
ready: boolean;
|
|
20
|
+
started: boolean;
|
|
21
|
+
touched_at: Date;
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
export declare const livenessCheck: router.Endpoint<unknown, router.RouterResponse<{
|
|
25
|
+
ready: boolean;
|
|
26
|
+
started: boolean;
|
|
27
|
+
touched_at: Date;
|
|
28
|
+
}>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<{
|
|
29
|
+
ready: boolean;
|
|
30
|
+
started: boolean;
|
|
31
|
+
touched_at: Date;
|
|
32
|
+
}>>> & {
|
|
33
|
+
path: ProbeRoutes;
|
|
34
|
+
method: router.HTTPMethod.GET;
|
|
35
|
+
handler: () => Promise<router.RouterResponse<{
|
|
36
|
+
ready: boolean;
|
|
37
|
+
started: boolean;
|
|
38
|
+
touched_at: Date;
|
|
39
|
+
}>>;
|
|
40
|
+
};
|
|
41
|
+
export declare const readinessCheck: router.Endpoint<unknown, router.RouterResponse<{
|
|
42
|
+
ready: boolean;
|
|
43
|
+
started: boolean;
|
|
44
|
+
touched_at: Date;
|
|
45
|
+
}>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<{
|
|
46
|
+
ready: boolean;
|
|
47
|
+
started: boolean;
|
|
48
|
+
touched_at: Date;
|
|
49
|
+
}>>> & {
|
|
50
|
+
path: ProbeRoutes;
|
|
51
|
+
method: router.HTTPMethod.GET;
|
|
52
|
+
handler: () => Promise<router.RouterResponse<{
|
|
53
|
+
ready: boolean;
|
|
54
|
+
started: boolean;
|
|
55
|
+
touched_at: Date;
|
|
56
|
+
}>>;
|
|
57
|
+
};
|
|
58
|
+
export declare const PROBES_ROUTES: (router.Endpoint<unknown, router.RouterResponse<{
|
|
59
|
+
ready: boolean;
|
|
60
|
+
started: boolean;
|
|
61
|
+
touched_at: Date;
|
|
62
|
+
}>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<unknown, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<{
|
|
63
|
+
ready: boolean;
|
|
64
|
+
started: boolean;
|
|
65
|
+
touched_at: Date;
|
|
66
|
+
}>>> & {
|
|
67
|
+
path: ProbeRoutes;
|
|
68
|
+
method: router.HTTPMethod.GET;
|
|
69
|
+
handler: () => Promise<router.RouterResponse<{
|
|
70
|
+
ready: boolean;
|
|
71
|
+
started: boolean;
|
|
72
|
+
touched_at: Date;
|
|
73
|
+
}>>;
|
|
74
|
+
})[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { container, router } from "@powersync/lib-services-framework";
|
|
2
|
+
import { routeDefinition } from "../router.js";
|
|
3
|
+
export var ProbeRoutes;
|
|
4
|
+
(function (ProbeRoutes) {
|
|
5
|
+
ProbeRoutes["STARTUP"] = "/probes/startup";
|
|
6
|
+
ProbeRoutes["LIVENESS"] = "/probes/liveness";
|
|
7
|
+
ProbeRoutes["READINESS"] = "/probes/readiness";
|
|
8
|
+
})(ProbeRoutes || (ProbeRoutes = {}));
|
|
9
|
+
export const startupCheck = routeDefinition({
|
|
10
|
+
path: ProbeRoutes.STARTUP,
|
|
11
|
+
method: router.HTTPMethod.GET,
|
|
12
|
+
handler: async () => {
|
|
13
|
+
const state = container.probes.state();
|
|
14
|
+
return new router.RouterResponse({
|
|
15
|
+
status: state.started ? 200 : 400,
|
|
16
|
+
data: {
|
|
17
|
+
...state,
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export const livenessCheck = routeDefinition({
|
|
23
|
+
path: ProbeRoutes.LIVENESS,
|
|
24
|
+
method: router.HTTPMethod.GET,
|
|
25
|
+
handler: async () => {
|
|
26
|
+
const state = container.probes.state();
|
|
27
|
+
const timeDifference = Date.now() - state.touched_at.getTime();
|
|
28
|
+
const status = timeDifference < 10000 ? 200 : 400;
|
|
29
|
+
return new router.RouterResponse({
|
|
30
|
+
status,
|
|
31
|
+
data: {
|
|
32
|
+
...state,
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export const readinessCheck = routeDefinition({
|
|
38
|
+
path: ProbeRoutes.READINESS,
|
|
39
|
+
method: router.HTTPMethod.GET,
|
|
40
|
+
handler: async () => {
|
|
41
|
+
const state = container.probes.state();
|
|
42
|
+
return new router.RouterResponse({
|
|
43
|
+
status: state.ready ? 200 : 400,
|
|
44
|
+
data: {
|
|
45
|
+
...state,
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
export const PROBES_ROUTES = [startupCheck, livenessCheck, readinessCheck];
|
|
51
|
+
//# sourceMappingURL=probes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probes.js","sourceRoot":"","sources":["../../../src/routes/endpoints/probes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,0CAA2B,CAAA;IAC3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AC,GAAG;IAC7B,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEvC,OAAO,IAAI,MAAM,CAAC,cAAc,CAAC;YAC/B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;YAC/B,IAAI,EAAE;gBACJ,GAAG,KAAK;aACT;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-rules.js","sourceRoot":"","sources":["../../../src/routes/endpoints/sync-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE9E,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAG9B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-rules.js","sourceRoot":"","sources":["../../../src/routes/endpoints/sync-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE9E,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAG9B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC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AC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;aACvC,CAAC;QACJ,CAAC;QACD,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;SACpB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/routes/router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { router } from '@powersync/lib-services-framework';
|
|
2
|
-
import
|
|
2
|
+
import type { JwtPayload } from '../auth/auth-index.js';
|
|
3
3
|
import { ServiceContext } from '../system/ServiceContext.js';
|
|
4
4
|
import { RouterEngine } from './RouterEngine.js';
|
|
5
5
|
/**
|
|
@@ -14,7 +14,7 @@ export type RouterServiceContext = ServiceContext & {
|
|
|
14
14
|
export type Context = {
|
|
15
15
|
user_id?: string;
|
|
16
16
|
service_context: RouterServiceContext;
|
|
17
|
-
token_payload?:
|
|
17
|
+
token_payload?: JwtPayload;
|
|
18
18
|
token_errors?: string[];
|
|
19
19
|
/**
|
|
20
20
|
* Only on websocket endpoints.
|
|
@@ -160,6 +160,16 @@ export interface BucketDataBatchOptions {
|
|
|
160
160
|
}
|
|
161
161
|
export interface StartBatchOptions extends ParseSyncRulesOptions {
|
|
162
162
|
zeroLSN: string;
|
|
163
|
+
/**
|
|
164
|
+
* Whether or not to store a copy of the current data.
|
|
165
|
+
*
|
|
166
|
+
* This is needed if we need to apply partial updates, for example
|
|
167
|
+
* when we get TOAST values from Postgres.
|
|
168
|
+
*
|
|
169
|
+
* This is not needed when we get the full document from the source
|
|
170
|
+
* database, for example from MongoDB.
|
|
171
|
+
*/
|
|
172
|
+
storeCurrentData: boolean;
|
|
163
173
|
}
|
|
164
174
|
export interface SyncRulesBucketStorageListener extends DisposableListener {
|
|
165
175
|
batchStarted: (batch: BucketStorageBatch) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BucketStorage.js","sourceRoot":"","sources":["../../src/storage/BucketStorage.ts"],"names":[],"mappings":"AAsLA,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"BucketStorage.js","sourceRoot":"","sources":["../../src/storage/BucketStorage.ts"],"names":[],"mappings":"AAsLA,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAyNlE,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;AACnB,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AA4CD,MAAM,UAAU,UAAU,CAAC,MAA0B,EAAE,SAA6B;IAClF,MAAM,SAAS,GAAuB,EAAE,CAAC;IACzC,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC;YACtC,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -6,6 +6,15 @@ import { SourceTable } from '../SourceTable.js';
|
|
|
6
6
|
import { BatchedCustomWriteCheckpointOptions } from '../WriteCheckpointAPI.js';
|
|
7
7
|
import { PowerSyncMongo } from './db.js';
|
|
8
8
|
import { CurrentBucket } from './models.js';
|
|
9
|
+
export interface MongoBucketBatchOptions {
|
|
10
|
+
db: PowerSyncMongo;
|
|
11
|
+
syncRules: SqlSyncRules;
|
|
12
|
+
groupId: number;
|
|
13
|
+
slotName: string;
|
|
14
|
+
lastCheckpointLsn: string | null;
|
|
15
|
+
noCheckpointBeforeLsn: string;
|
|
16
|
+
storeCurrentData: boolean;
|
|
17
|
+
}
|
|
9
18
|
export declare class MongoBucketBatch extends DisposableObserver<BucketBatchStorageListener> implements BucketStorageBatch {
|
|
10
19
|
private readonly client;
|
|
11
20
|
readonly db: PowerSyncMongo;
|
|
@@ -13,6 +22,7 @@ export declare class MongoBucketBatch extends DisposableObserver<BucketBatchStor
|
|
|
13
22
|
private readonly sync_rules;
|
|
14
23
|
private readonly group_id;
|
|
15
24
|
private readonly slot_name;
|
|
25
|
+
private readonly storeCurrentData;
|
|
16
26
|
private batch;
|
|
17
27
|
private write_checkpoint_batch;
|
|
18
28
|
/**
|
|
@@ -29,7 +39,7 @@ export declare class MongoBucketBatch extends DisposableObserver<BucketBatchStor
|
|
|
29
39
|
* For tests only - not for persistence logic.
|
|
30
40
|
*/
|
|
31
41
|
last_flushed_op: bigint | null;
|
|
32
|
-
constructor(
|
|
42
|
+
constructor(options: MongoBucketBatchOptions);
|
|
33
43
|
addCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): void;
|
|
34
44
|
get lastCheckpointLsn(): string | null;
|
|
35
45
|
flush(): Promise<FlushedResult | null>;
|
|
@@ -20,7 +20,7 @@ const MAX_ROW_SIZE = 15 * 1024 * 1024;
|
|
|
20
20
|
// In the future, we can investigate allowing multiple replication streams operating independently.
|
|
21
21
|
const replicationMutex = new util.Mutex();
|
|
22
22
|
export class MongoBucketBatch extends DisposableObserver {
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(options) {
|
|
24
24
|
super();
|
|
25
25
|
this.batch = null;
|
|
26
26
|
this.write_checkpoint_batch = [];
|
|
@@ -37,14 +37,15 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
37
37
|
* For tests only - not for persistence logic.
|
|
38
38
|
*/
|
|
39
39
|
this.last_flushed_op = null;
|
|
40
|
-
this.client = db.client;
|
|
41
|
-
this.db = db;
|
|
42
|
-
this.group_id =
|
|
43
|
-
this.last_checkpoint_lsn =
|
|
44
|
-
this.no_checkpoint_before_lsn =
|
|
40
|
+
this.client = options.db.client;
|
|
41
|
+
this.db = options.db;
|
|
42
|
+
this.group_id = options.groupId;
|
|
43
|
+
this.last_checkpoint_lsn = options.lastCheckpointLsn;
|
|
44
|
+
this.no_checkpoint_before_lsn = options.noCheckpointBeforeLsn;
|
|
45
45
|
this.session = this.client.startSession();
|
|
46
|
-
this.slot_name =
|
|
47
|
-
this.sync_rules =
|
|
46
|
+
this.slot_name = options.slotName;
|
|
47
|
+
this.sync_rules = options.syncRules;
|
|
48
|
+
this.storeCurrentData = options.storeCurrentData;
|
|
48
49
|
this.batch = new OperationBatch();
|
|
49
50
|
}
|
|
50
51
|
addCustomWriteCheckpoint(checkpoint) {
|
|
@@ -91,38 +92,44 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
91
92
|
return { flushed_op: String(last_op) };
|
|
92
93
|
}
|
|
93
94
|
async replicateBatch(session, batch, op_seq) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
let sizes = undefined;
|
|
96
|
+
if (this.storeCurrentData) {
|
|
97
|
+
// We skip this step if we don't store current_data, since the sizes will
|
|
98
|
+
// always be small in that case.
|
|
99
|
+
// Find sizes of current_data documents, to assist in intelligent batching without
|
|
100
|
+
// exceeding memory limits.
|
|
101
|
+
//
|
|
102
|
+
// A previous attempt tried to do batching by the results of the current_data query
|
|
103
|
+
// (automatically limited to 48MB(?) per batch by MongoDB). The issue is that it changes
|
|
104
|
+
// the order of processing, which then becomes really tricky to manage.
|
|
105
|
+
// This now takes 2+ queries, but doesn't have any issues with order of operations.
|
|
106
|
+
const sizeLookups = batch.batch.map((r) => {
|
|
107
|
+
return { g: this.group_id, t: r.record.sourceTable.id, k: r.beforeId };
|
|
108
|
+
});
|
|
109
|
+
sizes = new Map();
|
|
110
|
+
const sizeCursor = this.db.current_data.aggregate([
|
|
111
|
+
{
|
|
112
|
+
$match: {
|
|
113
|
+
_id: { $in: sizeLookups }
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
$project: {
|
|
118
|
+
_id: 1,
|
|
119
|
+
size: { $bsonSize: '$$ROOT' }
|
|
120
|
+
}
|
|
115
121
|
}
|
|
122
|
+
], { session });
|
|
123
|
+
for await (let doc of sizeCursor.stream()) {
|
|
124
|
+
const key = cacheKey(doc._id.t, doc._id.k);
|
|
125
|
+
sizes.set(key, doc.size);
|
|
116
126
|
}
|
|
117
|
-
], { session });
|
|
118
|
-
for await (let doc of sizeCursor.stream()) {
|
|
119
|
-
const key = cacheKey(doc._id.t, doc._id.k);
|
|
120
|
-
sizes.set(key, doc.size);
|
|
121
127
|
}
|
|
122
128
|
// If set, we need to start a new transaction with this batch.
|
|
123
129
|
let resumeBatch = null;
|
|
124
130
|
let transactionSize = 0;
|
|
125
131
|
// Now batch according to the sizes
|
|
132
|
+
// This is a single batch if storeCurrentData == false
|
|
126
133
|
for await (let b of batch.batched(sizes)) {
|
|
127
134
|
if (resumeBatch) {
|
|
128
135
|
for (let op of b) {
|
|
@@ -155,7 +162,7 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
155
162
|
if (nextData != null) {
|
|
156
163
|
// Update our current_data and size cache
|
|
157
164
|
current_data_lookup.set(op.internalAfterKey, nextData);
|
|
158
|
-
sizes
|
|
165
|
+
sizes?.set(op.internalAfterKey, nextData.data.length());
|
|
159
166
|
}
|
|
160
167
|
if (persistedBatch.shouldFlushTransaction()) {
|
|
161
168
|
// Transaction is getting big.
|
|
@@ -193,13 +200,17 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
193
200
|
existing_buckets = [];
|
|
194
201
|
existing_lookups = [];
|
|
195
202
|
// Log to help with debugging if there was a consistency issue
|
|
196
|
-
|
|
203
|
+
if (this.storeCurrentData) {
|
|
204
|
+
logger.warn(`Cannot find previous record for update on ${record.sourceTable.qualifiedName}: ${beforeId} / ${record.before?.id}`);
|
|
205
|
+
}
|
|
197
206
|
}
|
|
198
207
|
else {
|
|
199
|
-
const data = bson.deserialize(result.data.buffer, BSON_DESERIALIZE_OPTIONS);
|
|
200
208
|
existing_buckets = result.buckets;
|
|
201
209
|
existing_lookups = result.lookups;
|
|
202
|
-
|
|
210
|
+
if (this.storeCurrentData) {
|
|
211
|
+
const data = bson.deserialize(result.data.buffer, BSON_DESERIALIZE_OPTIONS);
|
|
212
|
+
after = mergeToast(after, data);
|
|
213
|
+
}
|
|
203
214
|
}
|
|
204
215
|
}
|
|
205
216
|
else if (record.tag == 'delete') {
|
|
@@ -209,7 +220,9 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
209
220
|
existing_buckets = [];
|
|
210
221
|
existing_lookups = [];
|
|
211
222
|
// Log to help with debugging if there was a consistency issue
|
|
212
|
-
|
|
223
|
+
if (this.storeCurrentData) {
|
|
224
|
+
logger.warn(`Cannot find previous record for delete on ${record.sourceTable.qualifiedName}: ${beforeId} / ${record.before?.id}`);
|
|
225
|
+
}
|
|
213
226
|
}
|
|
214
227
|
else {
|
|
215
228
|
existing_buckets = result.buckets;
|
|
@@ -217,7 +230,10 @@ export class MongoBucketBatch extends DisposableObserver {
|
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
232
|
let afterData;
|
|
220
|
-
if (afterId) {
|
|
233
|
+
if (afterId != null && !this.storeCurrentData) {
|
|
234
|
+
afterData = new bson.Binary(bson.serialize({}));
|
|
235
|
+
}
|
|
236
|
+
else if (afterId != null) {
|
|
221
237
|
try {
|
|
222
238
|
// This will fail immediately if the record is > 16MB.
|
|
223
239
|
afterData = new bson.Binary(bson.serialize(after));
|