@powersync/service-core 0.2.2 → 0.3.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 +13 -0
- package/dist/api/diagnostics.js +2 -2
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/api/schema.js.map +1 -1
- package/dist/auth/CachedKeyCollector.js.map +1 -1
- package/dist/auth/KeySpec.js.map +1 -1
- package/dist/auth/KeyStore.js +2 -2
- package/dist/auth/KeyStore.js.map +1 -1
- package/dist/auth/LeakyBucket.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/auth/SupabaseKeyCollector.js.map +1 -1
- package/dist/db/mongo.js.map +1 -1
- package/dist/entry/cli-entry.js +2 -2
- package/dist/entry/cli-entry.js.map +1 -1
- package/dist/entry/commands/config-command.js.map +1 -1
- package/dist/entry/commands/migrate-action.js.map +1 -1
- package/dist/entry/commands/start-action.js.map +1 -1
- package/dist/entry/commands/teardown-action.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/locks/LockManager.d.ts +10 -0
- package/dist/locks/LockManager.js +7 -0
- package/dist/locks/LockManager.js.map +1 -0
- package/dist/locks/MongoLocks.d.ts +36 -0
- package/dist/locks/MongoLocks.js +81 -0
- package/dist/locks/MongoLocks.js.map +1 -0
- package/dist/locks/locks-index.d.ts +2 -0
- package/dist/locks/locks-index.js +3 -0
- package/dist/locks/locks-index.js.map +1 -0
- package/dist/metrics/Metrics.js +6 -6
- package/dist/metrics/Metrics.js.map +1 -1
- package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -1
- package/dist/migrations/definitions.d.ts +18 -0
- package/dist/migrations/definitions.js +6 -0
- package/dist/migrations/definitions.js.map +1 -0
- package/dist/migrations/executor.d.ts +16 -0
- package/dist/migrations/executor.js +64 -0
- package/dist/migrations/executor.js.map +1 -0
- package/dist/migrations/migrations-index.d.ts +3 -0
- package/dist/migrations/migrations-index.js +4 -0
- package/dist/migrations/migrations-index.js.map +1 -0
- package/dist/migrations/migrations.d.ts +1 -1
- package/dist/migrations/migrations.js +4 -8
- package/dist/migrations/migrations.js.map +1 -1
- package/dist/migrations/store/migration-store.d.ts +11 -0
- package/dist/migrations/store/migration-store.js +46 -0
- package/dist/migrations/store/migration-store.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.js.map +1 -1
- package/dist/replication/PgRelation.js.map +1 -1
- package/dist/replication/WalConnection.js.map +1 -1
- package/dist/replication/WalStream.d.ts +0 -1
- package/dist/replication/WalStream.js +21 -25
- package/dist/replication/WalStream.js.map +1 -1
- package/dist/replication/WalStreamManager.js +12 -13
- package/dist/replication/WalStreamManager.js.map +1 -1
- package/dist/replication/WalStreamRunner.js +8 -8
- package/dist/replication/WalStreamRunner.js.map +1 -1
- package/dist/replication/util.js.map +1 -1
- package/dist/routes/auth.d.ts +8 -10
- package/dist/routes/auth.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +1011 -0
- package/dist/routes/{admin.js → endpoints/admin.js} +33 -18
- package/dist/routes/endpoints/admin.js.map +1 -0
- package/dist/routes/endpoints/checkpointing.d.ts +76 -0
- package/dist/routes/endpoints/checkpointing.js +36 -0
- package/dist/routes/endpoints/checkpointing.js.map +1 -0
- package/dist/routes/endpoints/dev.d.ts +312 -0
- package/dist/routes/{dev.js → endpoints/dev.js} +25 -16
- package/dist/routes/endpoints/dev.js.map +1 -0
- package/dist/routes/endpoints/route-endpoints-index.d.ts +6 -0
- package/dist/routes/endpoints/route-endpoints-index.js +7 -0
- package/dist/routes/endpoints/route-endpoints-index.js.map +1 -0
- package/dist/routes/endpoints/socket-route.d.ts +2 -0
- package/dist/routes/{socket-route.js → endpoints/socket-route.js} +10 -10
- package/dist/routes/endpoints/socket-route.js.map +1 -0
- package/dist/routes/endpoints/sync-rules.d.ts +174 -0
- package/dist/routes/{sync-rules.js → endpoints/sync-rules.js} +44 -24
- package/dist/routes/endpoints/sync-rules.js.map +1 -0
- package/dist/routes/endpoints/sync-stream.d.ts +132 -0
- package/dist/routes/{sync-stream.js → endpoints/sync-stream.js} +26 -17
- package/dist/routes/endpoints/sync-stream.js.map +1 -0
- package/dist/routes/hooks.d.ts +10 -0
- package/dist/routes/hooks.js +31 -0
- package/dist/routes/hooks.js.map +1 -0
- package/dist/routes/route-register.d.ts +10 -0
- package/dist/routes/route-register.js +87 -0
- package/dist/routes/route-register.js.map +1 -0
- package/dist/routes/router.d.ts +16 -4
- package/dist/routes/router.js +6 -1
- package/dist/routes/router.js.map +1 -1
- package/dist/routes/routes-index.d.ts +5 -3
- package/dist/routes/routes-index.js +5 -3
- package/dist/routes/routes-index.js.map +1 -1
- package/dist/runner/teardown.js +9 -9
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +3 -0
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/MongoBucketStorage.js +5 -5
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/mongo/MongoBucketBatch.js +23 -18
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
- package/dist/storage/mongo/MongoIdSequence.js.map +1 -1
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/mongo/MongoSyncRulesLock.js +3 -3
- package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/mongo/OperationBatch.js.map +1 -1
- package/dist/storage/mongo/PersistedBatch.js +2 -2
- package/dist/storage/mongo/PersistedBatch.js.map +1 -1
- package/dist/storage/mongo/db.d.ts +2 -2
- package/dist/storage/mongo/db.js.map +1 -1
- package/dist/storage/mongo/util.js.map +1 -1
- package/dist/sync/BroadcastIterable.js.map +1 -1
- package/dist/sync/LastValueSink.js.map +1 -1
- package/dist/sync/merge.js.map +1 -1
- package/dist/sync/safeRace.js.map +1 -1
- package/dist/sync/sync.js +4 -4
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.js.map +1 -1
- package/dist/system/CorePowerSyncSystem.d.ts +12 -7
- package/dist/system/CorePowerSyncSystem.js +26 -2
- package/dist/system/CorePowerSyncSystem.js.map +1 -1
- package/dist/system/system-index.d.ts +1 -0
- package/dist/system/system-index.js +2 -0
- package/dist/system/system-index.js.map +1 -0
- package/dist/util/Mutex.js.map +1 -1
- package/dist/util/PgManager.js.map +1 -1
- package/dist/util/alerting.d.ts +0 -2
- package/dist/util/alerting.js +0 -6
- package/dist/util/alerting.js.map +1 -1
- package/dist/util/config/collectors/config-collector.js +3 -3
- package/dist/util/config/collectors/config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/filesystem-config-collector.js +7 -5
- package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +4 -4
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js.map +1 -1
- package/dist/util/config.js.map +1 -1
- package/dist/util/env.d.ts +1 -2
- package/dist/util/env.js +3 -2
- package/dist/util/env.js.map +1 -1
- package/dist/util/memory-tracking.js +2 -2
- package/dist/util/memory-tracking.js.map +1 -1
- package/dist/util/migration_lib.js.map +1 -1
- package/dist/util/pgwire_utils.js +2 -2
- package/dist/util/pgwire_utils.js.map +1 -1
- package/dist/util/populate_test_data.js.map +1 -1
- package/dist/util/secs.js.map +1 -1
- package/dist/util/utils.js +4 -4
- package/dist/util/utils.js.map +1 -1
- package/package.json +12 -9
- package/src/api/diagnostics.ts +5 -5
- package/src/api/schema.ts +1 -1
- package/src/auth/KeyStore.ts +2 -2
- package/src/entry/cli-entry.ts +3 -4
- package/src/entry/commands/config-command.ts +1 -1
- package/src/entry/commands/migrate-action.ts +2 -2
- package/src/entry/commands/start-action.ts +1 -1
- package/src/entry/commands/teardown-action.ts +1 -1
- package/src/index.ts +5 -2
- package/src/locks/LockManager.ts +16 -0
- package/src/locks/MongoLocks.ts +142 -0
- package/src/locks/locks-index.ts +2 -0
- package/src/metrics/Metrics.ts +8 -8
- package/src/migrations/db/migrations/1684951997326-init.ts +3 -3
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +3 -3
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +2 -2
- package/src/migrations/definitions.ts +21 -0
- package/src/migrations/executor.ts +87 -0
- package/src/migrations/migrations-index.ts +3 -0
- package/src/migrations/migrations.ts +7 -11
- package/src/migrations/store/migration-store.ts +63 -0
- package/src/replication/WalConnection.ts +2 -2
- package/src/replication/WalStream.ts +24 -29
- package/src/replication/WalStreamManager.ts +14 -15
- package/src/replication/WalStreamRunner.ts +10 -10
- package/src/replication/util.ts +1 -1
- package/src/routes/auth.ts +22 -16
- package/src/routes/endpoints/admin.ts +237 -0
- package/src/routes/endpoints/checkpointing.ts +41 -0
- package/src/routes/endpoints/dev.ts +199 -0
- package/src/routes/endpoints/route-endpoints-index.ts +6 -0
- package/src/routes/{socket-route.ts → endpoints/socket-route.ts} +11 -11
- package/src/routes/endpoints/sync-rules.ts +227 -0
- package/src/routes/endpoints/sync-stream.ts +101 -0
- package/src/routes/hooks.ts +45 -0
- package/src/routes/route-register.ts +104 -0
- package/src/routes/router.ts +34 -6
- package/src/routes/routes-index.ts +5 -4
- package/src/runner/teardown.ts +9 -9
- package/src/storage/BucketStorage.ts +7 -2
- package/src/storage/ChecksumCache.ts +2 -2
- package/src/storage/MongoBucketStorage.ts +8 -8
- package/src/storage/SourceTable.ts +2 -2
- package/src/storage/mongo/MongoBucketBatch.ts +29 -22
- package/src/storage/mongo/MongoSyncBucketStorage.ts +3 -3
- package/src/storage/mongo/MongoSyncRulesLock.ts +3 -3
- package/src/storage/mongo/OperationBatch.ts +1 -1
- package/src/storage/mongo/PersistedBatch.ts +3 -3
- package/src/storage/mongo/db.ts +3 -4
- package/src/sync/sync.ts +8 -8
- package/src/sync/util.ts +2 -2
- package/src/system/CorePowerSyncSystem.ts +31 -10
- package/src/system/system-index.ts +1 -0
- package/src/util/alerting.ts +0 -8
- package/src/util/config/collectors/config-collector.ts +5 -3
- package/src/util/config/collectors/impl/filesystem-config-collector.ts +8 -6
- package/src/util/config/compound-config-collector.ts +4 -4
- package/src/util/env.ts +4 -2
- package/src/util/memory-tracking.ts +2 -2
- package/src/util/pgwire_utils.ts +3 -3
- package/src/util/utils.ts +5 -5
- package/test/src/auth.test.ts +4 -2
- package/test/src/data_storage.test.ts +177 -0
- package/test/src/env.ts +6 -6
- package/test/src/setup.ts +7 -0
- package/test/src/slow_tests.test.ts +45 -6
- package/test/tsconfig.json +1 -1
- package/tsconfig.json +5 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +1 -3
- package/dist/migrations/db/store.d.ts +0 -3
- package/dist/migrations/db/store.js +0 -10
- package/dist/migrations/db/store.js.map +0 -1
- package/dist/routes/admin.d.ts +0 -7
- package/dist/routes/admin.js.map +0 -1
- package/dist/routes/checkpointing.d.ts +0 -3
- package/dist/routes/checkpointing.js +0 -30
- package/dist/routes/checkpointing.js.map +0 -1
- package/dist/routes/dev.d.ts +0 -6
- package/dist/routes/dev.js.map +0 -1
- package/dist/routes/route-generators.d.ts +0 -15
- package/dist/routes/route-generators.js +0 -32
- package/dist/routes/route-generators.js.map +0 -1
- package/dist/routes/socket-route.d.ts +0 -2
- package/dist/routes/socket-route.js.map +0 -1
- package/dist/routes/sync-rules.d.ts +0 -6
- package/dist/routes/sync-rules.js.map +0 -1
- package/dist/routes/sync-stream.d.ts +0 -5
- package/dist/routes/sync-stream.js.map +0 -1
- package/src/migrations/db/store.ts +0 -11
- package/src/routes/admin.ts +0 -229
- package/src/routes/checkpointing.ts +0 -38
- package/src/routes/dev.ts +0 -194
- package/src/routes/route-generators.ts +0 -39
- package/src/routes/sync-rules.ts +0 -210
- package/src/routes/sync-stream.ts +0 -95
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-endpoints-index.js","sourceRoot":"","sources":["../../../src/routes/endpoints/route-endpoints-index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { serialize } from 'bson';
|
|
2
2
|
import { normalizeTokenParameters } from '@powersync/service-sync-rules';
|
|
3
|
-
import
|
|
4
|
-
import * as util from '
|
|
5
|
-
import { streamResponse } from '
|
|
3
|
+
import { errors, logger, schema } from '@powersync/lib-services-framework';
|
|
4
|
+
import * as util from '../../util/util-index.js';
|
|
5
|
+
import { streamResponse } from '../../sync/sync.js';
|
|
6
6
|
import { SyncRoutes } from './sync-stream.js';
|
|
7
|
-
import { Metrics } from '
|
|
8
|
-
export const
|
|
7
|
+
import { Metrics } from '../../metrics/Metrics.js';
|
|
8
|
+
export const syncStreamReactive = (router) => router.reactiveStream(SyncRoutes.STREAM, {
|
|
9
9
|
authorize: ({ context }) => {
|
|
10
10
|
return {
|
|
11
11
|
authorized: !!context.token_payload,
|
|
12
12
|
errors: ['Authentication required'].concat(context.token_errors ?? [])
|
|
13
13
|
};
|
|
14
14
|
},
|
|
15
|
-
validator:
|
|
15
|
+
validator: schema.createTsCodecValidator(util.StreamingSyncRequest, { allowAdditional: true }),
|
|
16
16
|
handler: async ({ context, params, responder, observer, initialN }) => {
|
|
17
17
|
const { system } = context;
|
|
18
18
|
if (system.closed) {
|
|
19
|
-
responder.onError(new
|
|
19
|
+
responder.onError(new errors.JourneyError({
|
|
20
20
|
status: 503,
|
|
21
21
|
code: 'SERVICE_UNAVAILABLE',
|
|
22
22
|
description: 'Service temporarily unavailable'
|
|
@@ -30,7 +30,7 @@ export const sync_stream_reactive = (router) => router.reactiveStream(SyncRoutes
|
|
|
30
30
|
// Sanity check before we start the stream
|
|
31
31
|
const cp = await storage.getActiveCheckpoint();
|
|
32
32
|
if (!cp.hasSyncRules()) {
|
|
33
|
-
responder.onError(new
|
|
33
|
+
responder.onError(new errors.JourneyError({
|
|
34
34
|
status: 500,
|
|
35
35
|
code: 'NO_SYNC_RULES',
|
|
36
36
|
description: 'No sync rules available'
|
|
@@ -104,8 +104,8 @@ export const sync_stream_reactive = (router) => router.reactiveStream(SyncRoutes
|
|
|
104
104
|
catch (ex) {
|
|
105
105
|
// Convert to our standard form before responding.
|
|
106
106
|
// This ensures the error can be serialized.
|
|
107
|
-
const error = new
|
|
108
|
-
|
|
107
|
+
const error = new errors.InternalServerError(ex);
|
|
108
|
+
logger.error('Sync stream error', error);
|
|
109
109
|
responder.onError(error);
|
|
110
110
|
}
|
|
111
111
|
finally {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-route.js","sourceRoot":"","sources":["../../../src/routes/endpoints/socket-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAkB,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,MAAM,CAAC,MAAM,kBAA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ework';
|
|
3
|
+
export declare const yamlPlugin: FastifyPluginAsync;
|
|
4
|
+
export declare const deploySyncRules: router.Endpoint<{
|
|
5
|
+
content: string;
|
|
6
|
+
}, {
|
|
7
|
+
slot_name: string;
|
|
8
|
+
}, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
9
|
+
content: string;
|
|
10
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
11
|
+
content: string;
|
|
12
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
|
|
13
|
+
slot_name: string;
|
|
14
|
+
}>> & {
|
|
15
|
+
path: string;
|
|
16
|
+
method: router.HTTPMethod.POST;
|
|
17
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
18
|
+
authorized: boolean;
|
|
19
|
+
errors: string[];
|
|
20
|
+
} | {
|
|
21
|
+
authorized: boolean;
|
|
22
|
+
errors?: undefined;
|
|
23
|
+
};
|
|
24
|
+
parse: boolean;
|
|
25
|
+
plugins: FastifyPluginAsync[];
|
|
26
|
+
validator: schema.MicroValidator<{
|
|
27
|
+
content: string;
|
|
28
|
+
}, string[]>;
|
|
29
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
30
|
+
content: string;
|
|
31
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
|
|
32
|
+
slot_name: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
export declare const validateSyncRules: router.Endpoint<{
|
|
36
|
+
content: string;
|
|
37
|
+
}, router.RouterResponse<string>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
38
|
+
content: string;
|
|
39
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
40
|
+
content: string;
|
|
41
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<string>>> & {
|
|
42
|
+
path: string;
|
|
43
|
+
method: router.HTTPMethod.POST;
|
|
44
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
45
|
+
authorized: boolean;
|
|
46
|
+
errors: string[];
|
|
47
|
+
} | {
|
|
48
|
+
authorized: boolean;
|
|
49
|
+
errors?: undefined;
|
|
50
|
+
};
|
|
51
|
+
parse: boolean;
|
|
52
|
+
plugins: FastifyPluginAsync[];
|
|
53
|
+
validator: schema.MicroValidator<{
|
|
54
|
+
content: string;
|
|
55
|
+
}, string[]>;
|
|
56
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
57
|
+
content: string;
|
|
58
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<string>>;
|
|
59
|
+
};
|
|
60
|
+
export declare const currentSyncRules: router.Endpoint<any, router.RouterResponse<string>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<string>>> & {
|
|
61
|
+
path: string;
|
|
62
|
+
method: router.HTTPMethod.GET;
|
|
63
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
64
|
+
authorized: boolean;
|
|
65
|
+
errors: string[];
|
|
66
|
+
} | {
|
|
67
|
+
authorized: boolean;
|
|
68
|
+
errors?: undefined;
|
|
69
|
+
};
|
|
70
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<string>>;
|
|
71
|
+
};
|
|
72
|
+
export declare const reprocessSyncRules: router.Endpoint<{}, {
|
|
73
|
+
slot_name: string;
|
|
74
|
+
}, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
|
|
75
|
+
slot_name: string;
|
|
76
|
+
}>> & {
|
|
77
|
+
path: string;
|
|
78
|
+
method: router.HTTPMethod.POST;
|
|
79
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
80
|
+
authorized: boolean;
|
|
81
|
+
errors: string[];
|
|
82
|
+
} | {
|
|
83
|
+
authorized: boolean;
|
|
84
|
+
errors?: undefined;
|
|
85
|
+
};
|
|
86
|
+
validator: schema.MicroValidator<{}, string[]>;
|
|
87
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
|
|
88
|
+
slot_name: string;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
export declare const SYNC_RULES_ROUTES: ((router.Endpoint<{
|
|
92
|
+
content: string;
|
|
93
|
+
}, {
|
|
94
|
+
slot_name: string;
|
|
95
|
+
}, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
96
|
+
content: string;
|
|
97
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
98
|
+
content: string;
|
|
99
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
|
|
100
|
+
slot_name: string;
|
|
101
|
+
}>> & {
|
|
102
|
+
path: string;
|
|
103
|
+
method: router.HTTPMethod.POST;
|
|
104
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
105
|
+
authorized: boolean;
|
|
106
|
+
errors: string[];
|
|
107
|
+
} | {
|
|
108
|
+
authorized: boolean;
|
|
109
|
+
errors?: undefined;
|
|
110
|
+
};
|
|
111
|
+
parse: boolean;
|
|
112
|
+
plugins: FastifyPluginAsync[];
|
|
113
|
+
validator: schema.MicroValidator<{
|
|
114
|
+
content: string;
|
|
115
|
+
}, string[]>;
|
|
116
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
117
|
+
content: string;
|
|
118
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
|
|
119
|
+
slot_name: string;
|
|
120
|
+
}>;
|
|
121
|
+
}) | (router.Endpoint<{
|
|
122
|
+
content: string;
|
|
123
|
+
}, router.RouterResponse<string>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
124
|
+
content: string;
|
|
125
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
126
|
+
content: string;
|
|
127
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<string>>> & {
|
|
128
|
+
path: string;
|
|
129
|
+
method: router.HTTPMethod.POST;
|
|
130
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
131
|
+
authorized: boolean;
|
|
132
|
+
errors: string[];
|
|
133
|
+
} | {
|
|
134
|
+
authorized: boolean;
|
|
135
|
+
errors?: undefined;
|
|
136
|
+
};
|
|
137
|
+
parse: boolean;
|
|
138
|
+
plugins: FastifyPluginAsync[];
|
|
139
|
+
validator: schema.MicroValidator<{
|
|
140
|
+
content: string;
|
|
141
|
+
}, string[]>;
|
|
142
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
143
|
+
content: string;
|
|
144
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<string>>;
|
|
145
|
+
}) | (router.Endpoint<any, router.RouterResponse<string>, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<string>>> & {
|
|
146
|
+
path: string;
|
|
147
|
+
method: router.HTTPMethod.GET;
|
|
148
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
149
|
+
authorized: boolean;
|
|
150
|
+
errors: string[];
|
|
151
|
+
} | {
|
|
152
|
+
authorized: boolean;
|
|
153
|
+
errors?: undefined;
|
|
154
|
+
};
|
|
155
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<any, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<string>>;
|
|
156
|
+
}) | (router.Endpoint<{}, {
|
|
157
|
+
slot_name: string;
|
|
158
|
+
}, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
|
|
159
|
+
slot_name: string;
|
|
160
|
+
}>> & {
|
|
161
|
+
path: string;
|
|
162
|
+
method: router.HTTPMethod.POST;
|
|
163
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => {
|
|
164
|
+
authorized: boolean;
|
|
165
|
+
errors: string[];
|
|
166
|
+
} | {
|
|
167
|
+
authorized: boolean;
|
|
168
|
+
errors?: undefined;
|
|
169
|
+
};
|
|
170
|
+
validator: schema.MicroValidator<{}, string[]>;
|
|
171
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
|
|
172
|
+
slot_name: string;
|
|
173
|
+
}>;
|
|
174
|
+
}))[];
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import * as t from 'ts-codec';
|
|
2
|
-
import
|
|
2
|
+
import { errors, router, schema } from '@powersync/lib-services-framework';
|
|
3
3
|
import { SqlSyncRules, SyncRulesErrors } from '@powersync/service-sync-rules';
|
|
4
|
-
import * as replication from '
|
|
5
|
-
import { authApi } from '
|
|
4
|
+
import * as replication from '../../replication/replication-index.js';
|
|
5
|
+
import { authApi } from '../auth.js';
|
|
6
|
+
import { routeDefinition } from '../router.js';
|
|
6
7
|
const DeploySyncRulesRequest = t.object({
|
|
7
8
|
content: t.string
|
|
8
9
|
});
|
|
9
|
-
const yamlPlugin = async (fastify) => {
|
|
10
|
+
export const yamlPlugin = async (fastify) => {
|
|
10
11
|
fastify.addContentTypeParser('application/yaml', async (request, payload, _d) => {
|
|
11
|
-
const data =
|
|
12
|
+
const data = [];
|
|
13
|
+
for await (const chunk of payload) {
|
|
14
|
+
data.push(chunk);
|
|
15
|
+
}
|
|
12
16
|
request.params = { content: Buffer.concat(data).toString('utf8') };
|
|
13
17
|
});
|
|
14
18
|
};
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Declares the plugin should be available on the same scope
|
|
21
|
+
* without requiring the `fastify-plugin` package as a dependency.
|
|
22
|
+
* https://fastify.dev/docs/latest/Reference/Plugins/#handle-the-scope
|
|
23
|
+
*/
|
|
24
|
+
//@ts-expect-error
|
|
25
|
+
yamlPlugin[Symbol.for('skip-override')] = true;
|
|
26
|
+
export const deploySyncRules = routeDefinition({
|
|
27
|
+
path: '/api/sync-rules/v1/deploy',
|
|
28
|
+
method: router.HTTPMethod.POST,
|
|
16
29
|
authorize: authApi,
|
|
17
30
|
parse: true,
|
|
18
31
|
plugins: [yamlPlugin],
|
|
19
|
-
validator:
|
|
32
|
+
validator: schema.createTsCodecValidator(DeploySyncRulesRequest, { allowAdditional: true }),
|
|
20
33
|
handler: async (payload) => {
|
|
21
34
|
if (payload.context.system.config.sync_rules.present) {
|
|
22
35
|
// If sync rules are configured via the config, disable deploy via the API.
|
|
23
|
-
throw new
|
|
36
|
+
throw new errors.JourneyError({
|
|
24
37
|
status: 422,
|
|
25
38
|
code: 'API_DISABLED',
|
|
26
39
|
description: 'Sync rules API disabled',
|
|
@@ -32,7 +45,7 @@ export const deploySyncRules = (router) => router.post('/api/sync-rules/v1/deplo
|
|
|
32
45
|
SqlSyncRules.fromYaml(payload.params.content);
|
|
33
46
|
}
|
|
34
47
|
catch (e) {
|
|
35
|
-
throw new
|
|
48
|
+
throw new errors.JourneyError({
|
|
36
49
|
status: 422,
|
|
37
50
|
code: 'INVALID_SYNC_RULES',
|
|
38
51
|
description: 'Sync rules parsing failed',
|
|
@@ -50,24 +63,28 @@ export const deploySyncRules = (router) => router.post('/api/sync-rules/v1/deplo
|
|
|
50
63
|
const ValidateSyncRulesRequest = t.object({
|
|
51
64
|
content: t.string
|
|
52
65
|
});
|
|
53
|
-
export const validateSyncRules = (
|
|
66
|
+
export const validateSyncRules = routeDefinition({
|
|
67
|
+
path: '/api/sync-rules/v1/validate',
|
|
68
|
+
method: router.HTTPMethod.POST,
|
|
54
69
|
authorize: authApi,
|
|
55
70
|
parse: true,
|
|
56
71
|
plugins: [yamlPlugin],
|
|
57
|
-
validator:
|
|
72
|
+
validator: schema.createTsCodecValidator(ValidateSyncRulesRequest, { allowAdditional: true }),
|
|
58
73
|
handler: async (payload) => {
|
|
59
74
|
const content = payload.params.content;
|
|
60
75
|
const info = await debugSyncRules(payload.context.system.requirePgPool(), content);
|
|
61
|
-
replyPrettyJson(
|
|
76
|
+
return replyPrettyJson(info);
|
|
62
77
|
}
|
|
63
78
|
});
|
|
64
|
-
export const currentSyncRules = (
|
|
79
|
+
export const currentSyncRules = routeDefinition({
|
|
80
|
+
path: '/api/sync-rules/v1/current',
|
|
81
|
+
method: router.HTTPMethod.GET,
|
|
65
82
|
authorize: authApi,
|
|
66
83
|
handler: async (payload) => {
|
|
67
84
|
const storage = payload.context.system.storage;
|
|
68
85
|
const sync_rules = await storage.getActiveSyncRulesContent();
|
|
69
86
|
if (!sync_rules) {
|
|
70
|
-
throw new
|
|
87
|
+
throw new errors.JourneyError({
|
|
71
88
|
status: 422,
|
|
72
89
|
code: 'NO_SYNC_RULES',
|
|
73
90
|
description: 'No active sync rules'
|
|
@@ -92,18 +109,20 @@ export const currentSyncRules = (router) => router.get('/api/sync-rules/v1/curre
|
|
|
92
109
|
...next_info
|
|
93
110
|
}
|
|
94
111
|
};
|
|
95
|
-
replyPrettyJson(
|
|
112
|
+
return replyPrettyJson({ data: response });
|
|
96
113
|
}
|
|
97
114
|
});
|
|
98
115
|
const ReprocessSyncRulesRequest = t.object({});
|
|
99
|
-
export const reprocessSyncRules = (
|
|
116
|
+
export const reprocessSyncRules = routeDefinition({
|
|
117
|
+
path: '/api/sync-rules/v1/reprocess',
|
|
118
|
+
method: router.HTTPMethod.POST,
|
|
100
119
|
authorize: authApi,
|
|
101
|
-
validator:
|
|
120
|
+
validator: schema.createTsCodecValidator(ReprocessSyncRulesRequest),
|
|
102
121
|
handler: async (payload) => {
|
|
103
122
|
const storage = payload.context.system.storage;
|
|
104
123
|
const sync_rules = await storage.getActiveSyncRules();
|
|
105
124
|
if (sync_rules == null) {
|
|
106
|
-
throw new
|
|
125
|
+
throw new errors.JourneyError({
|
|
107
126
|
status: 422,
|
|
108
127
|
code: 'NO_SYNC_RULES',
|
|
109
128
|
description: 'No active sync rules'
|
|
@@ -117,12 +136,13 @@ export const reprocessSyncRules = (router) => router.post('/api/sync-rules/v1/re
|
|
|
117
136
|
};
|
|
118
137
|
}
|
|
119
138
|
});
|
|
120
|
-
export const
|
|
121
|
-
function replyPrettyJson(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.
|
|
125
|
-
|
|
139
|
+
export const SYNC_RULES_ROUTES = [validateSyncRules, deploySyncRules, reprocessSyncRules, currentSyncRules];
|
|
140
|
+
function replyPrettyJson(payload) {
|
|
141
|
+
return new router.RouterResponse({
|
|
142
|
+
status: 200,
|
|
143
|
+
data: JSON.stringify(payload, null, 2) + '\n',
|
|
144
|
+
headers: { 'Content-Type': 'application/json' }
|
|
145
|
+
});
|
|
126
146
|
}
|
|
127
147
|
async function debugSyncRules(db, sync_rules) {
|
|
128
148
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-rules.js","sourceRoot":"","sources":["../../../src/routes/endpoints/sync-rules.ts"],"names":[],"mappings":"AA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node" resolution-mode="require"/>
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { router, schema } from '@powersync/lib-services-framework';
|
|
4
|
+
export declare enum SyncRoutes {
|
|
5
|
+
STREAM = "/sync/stream"
|
|
6
|
+
}
|
|
7
|
+
export declare const syncStreamed: router.Endpoint<{
|
|
8
|
+
parameters?: Record<string, any> | undefined;
|
|
9
|
+
buckets?: {
|
|
10
|
+
name: string;
|
|
11
|
+
after: string;
|
|
12
|
+
}[] | undefined;
|
|
13
|
+
only?: string[] | undefined;
|
|
14
|
+
include_checksum?: boolean | undefined;
|
|
15
|
+
raw_data?: boolean | undefined;
|
|
16
|
+
binary_data?: boolean | undefined;
|
|
17
|
+
}, router.RouterResponse<Readable> | undefined, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
18
|
+
parameters?: Record<string, any> | undefined;
|
|
19
|
+
buckets?: {
|
|
20
|
+
name: string;
|
|
21
|
+
after: string;
|
|
22
|
+
}[] | undefined;
|
|
23
|
+
only?: string[] | undefined;
|
|
24
|
+
include_checksum?: boolean | undefined;
|
|
25
|
+
raw_data?: boolean | undefined;
|
|
26
|
+
binary_data?: boolean | undefined;
|
|
27
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
28
|
+
parameters?: Record<string, any> | undefined;
|
|
29
|
+
buckets?: {
|
|
30
|
+
name: string;
|
|
31
|
+
after: string;
|
|
32
|
+
}[] | undefined;
|
|
33
|
+
only?: string[] | undefined;
|
|
34
|
+
include_checksum?: boolean | undefined;
|
|
35
|
+
raw_data?: boolean | undefined;
|
|
36
|
+
binary_data?: boolean | undefined;
|
|
37
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<Readable> | undefined>> & {
|
|
38
|
+
path: SyncRoutes;
|
|
39
|
+
method: router.HTTPMethod.POST;
|
|
40
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
|
|
41
|
+
authorized: boolean;
|
|
42
|
+
errors: any[];
|
|
43
|
+
} | {
|
|
44
|
+
authorized: boolean;
|
|
45
|
+
errors?: undefined;
|
|
46
|
+
}>;
|
|
47
|
+
validator: schema.MicroValidator<{
|
|
48
|
+
parameters?: Record<string, any> | undefined;
|
|
49
|
+
buckets?: {
|
|
50
|
+
name: string;
|
|
51
|
+
after: string;
|
|
52
|
+
}[] | undefined;
|
|
53
|
+
only?: string[] | undefined;
|
|
54
|
+
include_checksum?: boolean | undefined;
|
|
55
|
+
raw_data?: boolean | undefined;
|
|
56
|
+
binary_data?: boolean | undefined;
|
|
57
|
+
}, string[]>;
|
|
58
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
59
|
+
parameters?: Record<string, any> | undefined;
|
|
60
|
+
buckets?: {
|
|
61
|
+
name: string;
|
|
62
|
+
after: string;
|
|
63
|
+
}[] | undefined;
|
|
64
|
+
only?: string[] | undefined;
|
|
65
|
+
include_checksum?: boolean | undefined;
|
|
66
|
+
raw_data?: boolean | undefined;
|
|
67
|
+
binary_data?: boolean | undefined;
|
|
68
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<Readable> | undefined>;
|
|
69
|
+
};
|
|
70
|
+
export declare const SYNC_STREAM_ROUTES: (router.Endpoint<{
|
|
71
|
+
parameters?: Record<string, any> | undefined;
|
|
72
|
+
buckets?: {
|
|
73
|
+
name: string;
|
|
74
|
+
after: string;
|
|
75
|
+
}[] | undefined;
|
|
76
|
+
only?: string[] | undefined;
|
|
77
|
+
include_checksum?: boolean | undefined;
|
|
78
|
+
raw_data?: boolean | undefined;
|
|
79
|
+
binary_data?: boolean | undefined;
|
|
80
|
+
}, router.RouterResponse<Readable> | undefined, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
|
|
81
|
+
parameters?: Record<string, any> | undefined;
|
|
82
|
+
buckets?: {
|
|
83
|
+
name: string;
|
|
84
|
+
after: string;
|
|
85
|
+
}[] | undefined;
|
|
86
|
+
only?: string[] | undefined;
|
|
87
|
+
include_checksum?: boolean | undefined;
|
|
88
|
+
raw_data?: boolean | undefined;
|
|
89
|
+
binary_data?: boolean | undefined;
|
|
90
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
|
|
91
|
+
parameters?: Record<string, any> | undefined;
|
|
92
|
+
buckets?: {
|
|
93
|
+
name: string;
|
|
94
|
+
after: string;
|
|
95
|
+
}[] | undefined;
|
|
96
|
+
only?: string[] | undefined;
|
|
97
|
+
include_checksum?: boolean | undefined;
|
|
98
|
+
raw_data?: boolean | undefined;
|
|
99
|
+
binary_data?: boolean | undefined;
|
|
100
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.RouterResponse<Readable> | undefined>> & {
|
|
101
|
+
path: SyncRoutes;
|
|
102
|
+
method: router.HTTPMethod.POST;
|
|
103
|
+
authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
|
|
104
|
+
authorized: boolean;
|
|
105
|
+
errors: any[];
|
|
106
|
+
} | {
|
|
107
|
+
authorized: boolean;
|
|
108
|
+
errors?: undefined;
|
|
109
|
+
}>;
|
|
110
|
+
validator: schema.MicroValidator<{
|
|
111
|
+
parameters?: Record<string, any> | undefined;
|
|
112
|
+
buckets?: {
|
|
113
|
+
name: string;
|
|
114
|
+
after: string;
|
|
115
|
+
}[] | undefined;
|
|
116
|
+
only?: string[] | undefined;
|
|
117
|
+
include_checksum?: boolean | undefined;
|
|
118
|
+
raw_data?: boolean | undefined;
|
|
119
|
+
binary_data?: boolean | undefined;
|
|
120
|
+
}, string[]>;
|
|
121
|
+
handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
|
|
122
|
+
parameters?: Record<string, any> | undefined;
|
|
123
|
+
buckets?: {
|
|
124
|
+
name: string;
|
|
125
|
+
after: string;
|
|
126
|
+
}[] | undefined;
|
|
127
|
+
only?: string[] | undefined;
|
|
128
|
+
include_checksum?: boolean | undefined;
|
|
129
|
+
raw_data?: boolean | undefined;
|
|
130
|
+
binary_data?: boolean | undefined;
|
|
131
|
+
}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<router.RouterResponse<Readable> | undefined>;
|
|
132
|
+
})[];
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import * as micro from '@journeyapps-platform/micro';
|
|
3
2
|
import { normalizeTokenParameters } from '@powersync/service-sync-rules';
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
3
|
+
import { errors, logger, router, schema } from '@powersync/lib-services-framework';
|
|
4
|
+
import * as sync from '../../sync/sync-index.js';
|
|
5
|
+
import * as util from '../../util/util-index.js';
|
|
6
|
+
import { authUser } from '../auth.js';
|
|
7
|
+
import { routeDefinition } from '../router.js';
|
|
8
|
+
import { Metrics } from '../../metrics/Metrics.js';
|
|
8
9
|
export var SyncRoutes;
|
|
9
10
|
(function (SyncRoutes) {
|
|
10
11
|
SyncRoutes["STREAM"] = "/sync/stream";
|
|
11
12
|
})(SyncRoutes || (SyncRoutes = {}));
|
|
12
|
-
export const syncStreamed = (
|
|
13
|
+
export const syncStreamed = routeDefinition({
|
|
14
|
+
path: SyncRoutes.STREAM,
|
|
15
|
+
method: router.HTTPMethod.POST,
|
|
13
16
|
authorize: authUser,
|
|
14
|
-
validator:
|
|
17
|
+
validator: schema.createTsCodecValidator(util.StreamingSyncRequest, { allowAdditional: true }),
|
|
15
18
|
handler: async (payload) => {
|
|
16
|
-
const userId = payload.context.user_id;
|
|
17
19
|
const system = payload.context.system;
|
|
18
20
|
if (system.closed) {
|
|
19
|
-
throw new
|
|
21
|
+
throw new errors.JourneyError({
|
|
20
22
|
status: 503,
|
|
21
23
|
code: 'SERVICE_UNAVAILABLE',
|
|
22
24
|
description: 'Service temporarily unavailable'
|
|
@@ -28,14 +30,12 @@ export const syncStreamed = (router) => router.post(SyncRoutes.STREAM, {
|
|
|
28
30
|
// Sanity check before we start the stream
|
|
29
31
|
const cp = await storage.getActiveCheckpoint();
|
|
30
32
|
if (!cp.hasSyncRules()) {
|
|
31
|
-
throw new
|
|
33
|
+
throw new errors.JourneyError({
|
|
32
34
|
status: 500,
|
|
33
35
|
code: 'NO_SYNC_RULES',
|
|
34
36
|
description: 'No sync rules available'
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
|
-
const res = payload.reply;
|
|
38
|
-
res.status(200).header('Content-Type', 'application/x-ndjson');
|
|
39
39
|
const controller = new AbortController();
|
|
40
40
|
try {
|
|
41
41
|
Metrics.getInstance().concurrent_connections.add(1);
|
|
@@ -58,17 +58,26 @@ export const syncStreamed = (router) => router.post(SyncRoutes.STREAM, {
|
|
|
58
58
|
controller.abort();
|
|
59
59
|
// Note: This appears as a 200 response in the logs.
|
|
60
60
|
if (error.message != 'Shutting down system') {
|
|
61
|
-
|
|
61
|
+
logger.error('Streaming sync request failed', error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return new router.RouterResponse({
|
|
65
|
+
status: 200,
|
|
66
|
+
headers: {
|
|
67
|
+
'Content-Type': 'application/x-ndjson'
|
|
68
|
+
},
|
|
69
|
+
data: stream,
|
|
70
|
+
afterSend: async () => {
|
|
71
|
+
controller.abort();
|
|
72
|
+
Metrics.getInstance().concurrent_connections.add(-1);
|
|
62
73
|
}
|
|
63
74
|
});
|
|
64
|
-
await res.send(stream);
|
|
65
75
|
}
|
|
66
|
-
|
|
76
|
+
catch (ex) {
|
|
67
77
|
controller.abort();
|
|
68
78
|
Metrics.getInstance().concurrent_connections.add(-1);
|
|
69
|
-
// Prevent double-send
|
|
70
|
-
res.hijack();
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
});
|
|
82
|
+
export const SYNC_STREAM_ROUTES = [syncStreamed];
|
|
74
83
|
//# sourceMappingURL=sync-stream.js.map
|
|
@@ -0,0 +1 @@
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EAAE,GAAG,EAAE;gBACtB,UAAU,EAAE,CAAC;YACf,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC3B,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,oDAAoD;gBACpD,IAAI,KAAK,CAAC,OAAO,IAAI,sBAAsB,EAAE;oBAC3C,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;iBACtD;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,MAAM,CAAC,cAAc,CAAC;gBAC/B,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE;oBACP,cAAc,EAAE,sBAAsB;iBACvC;gBACD,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,KAAK,IAAI,EAAE;oBACpB,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvD,CAAC;aACF,CAAC,CAAC;SACJ;QAAC,OAAO,EAAE,EAAE;YACX,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;IACH,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type fastify from 'fastify';
|
|
2
|
+
export type CreateRequestQueueParams = {
|
|
3
|
+
max_queue_depth: number;
|
|
4
|
+
concurrency: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Creates a request queue which limits the amount of concurrent connections which
|
|
8
|
+
* are active at any time.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createRequestQueueHook: (params: CreateRequestQueueParams) => fastify.onRequestHookHandler;
|