@powersync/service-core 0.5.0 → 0.6.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/CHANGELOG.md +12 -0
- package/dist/entry/commands/compact-action.js +3 -4
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +883 -0
- package/dist/routes/configure-fastify.js +58 -0
- package/dist/routes/configure-fastify.js.map +1 -0
- package/dist/routes/configure-rsocket.d.ts +13 -0
- package/dist/routes/configure-rsocket.js +46 -0
- package/dist/routes/configure-rsocket.js.map +1 -0
- package/dist/routes/endpoints/socket-route.js +3 -10
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/route-register.d.ts +1 -1
- package/dist/routes/route-register.js +1 -1
- package/dist/routes/route-register.js.map +1 -1
- package/dist/routes/router-socket.d.ts +4 -4
- package/dist/routes/router-socket.js.map +1 -1
- package/dist/routes/router.d.ts +1 -0
- package/dist/routes/router.js.map +1 -1
- package/dist/routes/routes-index.d.ts +2 -0
- package/dist/routes/routes-index.js +2 -0
- package/dist/routes/routes-index.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +6 -0
- package/dist/storage/mongo/MongoCompactor.d.ts +2 -0
- package/dist/storage/mongo/MongoCompactor.js +16 -2
- package/dist/storage/mongo/MongoCompactor.js.map +1 -1
- package/dist/sync/sync-index.d.ts +1 -0
- package/dist/sync/sync-index.js +1 -0
- package/dist/sync/sync-index.js.map +1 -1
- package/package.json +3 -3
- package/src/entry/commands/compact-action.ts +3 -4
- package/src/routes/configure-fastify.ts +102 -0
- package/src/routes/configure-rsocket.ts +59 -0
- package/src/routes/endpoints/socket-route.ts +3 -10
- package/src/routes/route-register.ts +2 -2
- package/src/routes/router-socket.ts +5 -5
- package/src/routes/router.ts +2 -0
- package/src/routes/routes-index.ts +2 -0
- package/src/storage/BucketStorage.ts +7 -0
- package/src/storage/mongo/MongoCompactor.ts +17 -2
- package/src/sync/sync-index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -3,20 +3,13 @@ import { RequestParameters } from '@powersync/service-sync-rules';
|
|
|
3
3
|
import { serialize } from 'bson';
|
|
4
4
|
|
|
5
5
|
import { Metrics } from '../../metrics/Metrics.js';
|
|
6
|
-
import
|
|
6
|
+
import * as sync from '../../sync/sync-index.js';
|
|
7
7
|
import * as util from '../../util/util-index.js';
|
|
8
8
|
import { SocketRouteGenerator } from '../router-socket.js';
|
|
9
9
|
import { SyncRoutes } from './sync-stream.js';
|
|
10
|
-
import { RequestTracker } from '../../sync/RequestTracker.js';
|
|
11
10
|
|
|
12
11
|
export const syncStreamReactive: SocketRouteGenerator = (router) =>
|
|
13
12
|
router.reactiveStream<util.StreamingSyncRequest, any>(SyncRoutes.STREAM, {
|
|
14
|
-
authorize: ({ context }) => {
|
|
15
|
-
return {
|
|
16
|
-
authorized: !!context.token_payload,
|
|
17
|
-
errors: ['Authentication required'].concat(context.token_errors ?? [])
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
13
|
validator: schema.createTsCodecValidator(util.StreamingSyncRequest, { allowAdditional: true }),
|
|
21
14
|
handler: async ({ context, params, responder, observer, initialN }) => {
|
|
22
15
|
const { system } = context;
|
|
@@ -67,9 +60,9 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
|
|
|
67
60
|
});
|
|
68
61
|
|
|
69
62
|
Metrics.getInstance().concurrent_connections.add(1);
|
|
70
|
-
const tracker = new RequestTracker();
|
|
63
|
+
const tracker = new sync.RequestTracker();
|
|
71
64
|
try {
|
|
72
|
-
for await (const data of streamResponse({
|
|
65
|
+
for await (const data of sync.streamResponse({
|
|
73
66
|
storage,
|
|
74
67
|
params: {
|
|
75
68
|
...params,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fastify from 'fastify';
|
|
1
|
+
import type fastify from 'fastify';
|
|
2
2
|
|
|
3
|
-
import { errors,
|
|
3
|
+
import { errors, HTTPMethod, logger, router } from '@powersync/lib-services-framework';
|
|
4
4
|
import { Context, ContextProvider, RequestEndpoint, RequestEndpointHandlerPayload } from './router.js';
|
|
5
5
|
|
|
6
6
|
export type FastifyEndpoint<I, O, C> = RequestEndpoint<I, O, C> & {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { IReactiveStream, ReactiveSocketRouter } from '@powersync/service-rsocket-router';
|
|
1
2
|
import * as t from 'ts-codec';
|
|
2
|
-
import { ReactiveSocketRouter, IReactiveStream } from '@powersync/service-rsocket-router';
|
|
3
3
|
|
|
4
4
|
import { Context } from './router.js';
|
|
5
5
|
|
|
6
|
-
export const RSocketContextMeta = t.object({
|
|
7
|
-
token: t.string
|
|
8
|
-
});
|
|
9
|
-
|
|
10
6
|
/**
|
|
11
7
|
* Creates a socket route handler given a router instance
|
|
12
8
|
*/
|
|
13
9
|
export type SocketRouteGenerator = (router: ReactiveSocketRouter<Context>) => IReactiveStream;
|
|
10
|
+
|
|
11
|
+
export const RSocketContextMeta = t.object({
|
|
12
|
+
token: t.string
|
|
13
|
+
});
|
package/src/routes/router.ts
CHANGED
|
@@ -426,4 +426,11 @@ export interface CompactOptions {
|
|
|
426
426
|
* not be compacted, to avoid invalidating checkpoints in use.
|
|
427
427
|
*/
|
|
428
428
|
maxOpId?: bigint;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* If specified, compact only the specific buckets.
|
|
432
|
+
*
|
|
433
|
+
* If not specified, compacts all buckets.
|
|
434
|
+
*/
|
|
435
|
+
compactBuckets?: string[];
|
|
429
436
|
}
|
|
@@ -55,6 +55,7 @@ export class MongoCompactor {
|
|
|
55
55
|
private moveBatchQueryLimit: number;
|
|
56
56
|
private clearBatchLimit: number;
|
|
57
57
|
private maxOpId: bigint | undefined;
|
|
58
|
+
private buckets: string[] | undefined;
|
|
58
59
|
|
|
59
60
|
constructor(private db: PowerSyncMongo, private group_id: number, options?: MongoCompactOptions) {
|
|
60
61
|
this.idLimitBytes = (options?.memoryLimitMB ?? DEFAULT_MEMORY_LIMIT_MB) * 1024 * 1024;
|
|
@@ -62,6 +63,7 @@ export class MongoCompactor {
|
|
|
62
63
|
this.moveBatchQueryLimit = options?.moveBatchQueryLimit ?? DEFAULT_MOVE_BATCH_QUERY_LIMIT;
|
|
63
64
|
this.clearBatchLimit = options?.clearBatchLimit ?? DEFAULT_CLEAR_BATCH_LIMIT;
|
|
64
65
|
this.maxOpId = options?.maxOpId;
|
|
66
|
+
this.buckets = options?.compactBuckets;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -70,6 +72,19 @@ export class MongoCompactor {
|
|
|
70
72
|
* See /docs/compacting-operations.md for details.
|
|
71
73
|
*/
|
|
72
74
|
async compact() {
|
|
75
|
+
if (this.buckets) {
|
|
76
|
+
for (let bucket of this.buckets) {
|
|
77
|
+
// We can make this more efficient later on by iterating
|
|
78
|
+
// through the buckets in a single query.
|
|
79
|
+
// That makes batching more tricky, so we leave for later.
|
|
80
|
+
await this.compactInternal(bucket);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
await this.compactInternal(undefined);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async compactInternal(bucket: string | undefined) {
|
|
73
88
|
const idLimitBytes = this.idLimitBytes;
|
|
74
89
|
|
|
75
90
|
let currentState: CurrentBucketState | null = null;
|
|
@@ -77,14 +92,14 @@ export class MongoCompactor {
|
|
|
77
92
|
// Constant lower bound
|
|
78
93
|
const lowerBound: BucketDataKey = {
|
|
79
94
|
g: this.group_id,
|
|
80
|
-
b: new MinKey() as any,
|
|
95
|
+
b: bucket ?? (new MinKey() as any),
|
|
81
96
|
o: new MinKey() as any
|
|
82
97
|
};
|
|
83
98
|
|
|
84
99
|
// Upper bound is adjusted for each batch
|
|
85
100
|
let upperBound: BucketDataKey = {
|
|
86
101
|
g: this.group_id,
|
|
87
|
-
b: new MaxKey() as any,
|
|
102
|
+
b: bucket ?? (new MaxKey() as any),
|
|
88
103
|
o: new MaxKey() as any
|
|
89
104
|
};
|
|
90
105
|
|
package/src/sync/sync-index.ts
CHANGED