@atproto/bsync 0.0.44 → 0.1.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 +10 -0
- package/dist/proto/bsync_connect.d.ts +1 -10
- package/dist/proto/bsync_connect.d.ts.map +1 -1
- package/dist/proto/bsync_connect.js +1 -10
- package/dist/proto/bsync_connect.js.map +1 -1
- package/dist/proto/bsync_pb.d.ts +0 -38
- package/dist/proto/bsync_pb.d.ts.map +1 -1
- package/dist/proto/bsync_pb.js +0 -57
- package/dist/proto/bsync_pb.js.map +1 -1
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +0 -2
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/scan-mute-operations.js +108 -45
- package/dist/routes/scan-mute-operations.js.map +1 -1
- package/dist/routes/scan-notif-operations.js +105 -42
- package/dist/routes/scan-notif-operations.js.map +1 -1
- package/dist/routes/scan-operations.js +108 -45
- package/dist/routes/scan-operations.js.map +1 -1
- package/dist/routes/util.d.ts +2 -1
- package/dist/routes/util.d.ts.map +1 -1
- package/dist/routes/util.js +35 -12
- package/dist/routes/util.js.map +1 -1
- package/package.json +3 -4
- package/dist/routes/add-notif-operation.d.ts +0 -6
- package/dist/routes/add-notif-operation.d.ts.map +0 -1
- package/dist/routes/add-notif-operation.js +0 -61
- package/dist/routes/add-notif-operation.js.map +0 -1
package/dist/routes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAA;AAEnF,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAA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,CAAA;YAClC,OAAO,EAAE,CAAA;QACX,CAAC;KACF,EACD;QACE,YAAY,EAAE,mBAAmB;QACjC,mCAAmC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC7C,CAAC,oBAAoB,CAAC,EAAE,GAAG,CAAC,SAAS;SACtC,CAAC;KACH,CACF,CACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type { ConnectRouter } from '@connectrpc/connect'\nimport { sql } from 'kysely'\nimport { ATTR_BSYNC_NAMESPACE } from '@atproto-labs/opentelemetry-node/conventions'\nimport type { AppContext } from '../context.js'\nimport { Service } from '../proto/bsync_connect.js'\nimport { operationAttributes } from '../telemetry/attributes.js'\nimport { withRpcServerTelemetry } from '../telemetry/rpc.js'\nimport addMuteOperation from './add-mute-operation.js'\nimport deleteOperations from './delete-operations.js'\nimport fanoutNotificationSeen from './fanout-notification-seen.js'\nimport putOperation from './put-operation.js'\nimport scanMuteOperations from './scan-mute-operations.js'\nimport scanNotifOperations from './scan-notif-operations.js'\nimport scanOperations from './scan-operations.js'\n\nexport default (ctx: AppContext) => (router: ConnectRouter) => {\n return router.service(\n Service,\n withRpcServerTelemetry(\n {\n ...addMuteOperation(ctx),\n ...scanMuteOperations(ctx),\n ...scanNotifOperations(ctx),\n ...putOperation(ctx),\n ...scanOperations(ctx),\n ...deleteOperations(ctx),\n ...fanoutNotificationSeen(ctx),\n async ping() {\n const { db } = ctx\n await sql`select 1`.execute(db.db)\n return {}\n },\n },\n {\n putOperation: operationAttributes,\n deleteOperationsByActorAndNamespace: (req) => ({\n [ATTR_BSYNC_NAMESPACE]: req.namespace,\n }),\n },\n ),\n )\n}\n"]}
|
|
@@ -1,57 +1,120 @@
|
|
|
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
|
+
});
|
|
1
53
|
import { once } from 'node:events';
|
|
2
54
|
import { createMuteOpChannel } from '../db/schema/mute_op.js';
|
|
3
55
|
import { ScanMuteOperationsResponse } from '../proto/bsync_pb.js';
|
|
4
56
|
import { authWithApiKey } from './auth.js';
|
|
5
|
-
import {
|
|
57
|
+
import { combinedSignals, validCursor } from './util.js';
|
|
6
58
|
export default (ctx) => ({
|
|
7
59
|
async scanMuteOperations(req, handlerCtx) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
await nextMuteOpPromise;
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
ctx.shutdown.throwIfAborted();
|
|
30
|
-
return new ScanMuteOperationsResponse({
|
|
31
|
-
operations: [],
|
|
32
|
-
cursor: req.cursor,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
ops = await nextMuteOpPageQb.execute();
|
|
60
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
61
|
+
try {
|
|
62
|
+
authWithApiKey(ctx, handlerCtx);
|
|
63
|
+
const { db, events } = ctx;
|
|
64
|
+
const limit = req.limit || 1000;
|
|
65
|
+
const cursor = validCursor(req.cursor);
|
|
66
|
+
const signal = __addDisposableResource(env_1, combinedSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)), false);
|
|
67
|
+
const nextMuteOpPromise = once(events, createMuteOpChannel, { signal });
|
|
68
|
+
// awaited later
|
|
69
|
+
void nextMuteOpPromise.catch(() => null);
|
|
70
|
+
const nextMuteOpPageQb = db.db
|
|
71
|
+
.selectFrom('mute_op')
|
|
72
|
+
.selectAll()
|
|
73
|
+
.where('id', '>', cursor ?? -1)
|
|
74
|
+
.orderBy('id', 'asc')
|
|
75
|
+
.limit(limit);
|
|
76
|
+
let ops = await nextMuteOpPageQb.execute();
|
|
36
77
|
if (!ops.length) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
78
|
+
// if there were no ops on the page, wait for an event then try again.
|
|
79
|
+
try {
|
|
80
|
+
await nextMuteOpPromise;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (ctx.shutdown.aborted)
|
|
84
|
+
throw err;
|
|
85
|
+
return new ScanMuteOperationsResponse({
|
|
86
|
+
operations: [],
|
|
87
|
+
cursor: req.cursor,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
ops = await nextMuteOpPageQb.execute();
|
|
91
|
+
if (!ops.length) {
|
|
92
|
+
return new ScanMuteOperationsResponse({
|
|
93
|
+
operations: [],
|
|
94
|
+
cursor: req.cursor,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
41
97
|
}
|
|
98
|
+
const lastOp = ops[ops.length - 1];
|
|
99
|
+
return new ScanMuteOperationsResponse({
|
|
100
|
+
operations: ops.map((op) => ({
|
|
101
|
+
id: op.id.toString(),
|
|
102
|
+
type: op.type,
|
|
103
|
+
actorDid: op.actorDid,
|
|
104
|
+
subject: op.subject,
|
|
105
|
+
onlyReposts: op.onlyReposts,
|
|
106
|
+
onlyQuoteposts: op.onlyQuoteposts,
|
|
107
|
+
})),
|
|
108
|
+
cursor: lastOp.id.toString(),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (e_1) {
|
|
112
|
+
env_1.error = e_1;
|
|
113
|
+
env_1.hasError = true;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
__disposeResources(env_1);
|
|
42
117
|
}
|
|
43
|
-
const lastOp = ops[ops.length - 1];
|
|
44
|
-
return new ScanMuteOperationsResponse({
|
|
45
|
-
operations: ops.map((op) => ({
|
|
46
|
-
id: op.id.toString(),
|
|
47
|
-
type: op.type,
|
|
48
|
-
actorDid: op.actorDid,
|
|
49
|
-
subject: op.subject,
|
|
50
|
-
onlyReposts: op.onlyReposts,
|
|
51
|
-
onlyQuoteposts: op.onlyQuoteposts,
|
|
52
|
-
})),
|
|
53
|
-
cursor: lastOp.id.toString(),
|
|
54
|
-
});
|
|
55
118
|
},
|
|
56
119
|
});
|
|
57
120
|
//# sourceMappingURL=scan-mute-operations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan-mute-operations.js","sourceRoot":"","sources":["../../src/routes/scan-mute-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"scan-mute-operations.js","sourceRoot":"","sources":["../../src/routes/scan-mute-operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAExD,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK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AAE,GAAG,CAAC,MAAM;qBACnB,CAAC,CAAA;gBACJ,CAAC;gBACD,GAAG,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAA;gBACtC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;oBAChB,OAAO,IAAI,0BAA0B,CAAC;wBACpC,UAAU,EAAE,EAAE;wBACd,MAAM,EAAE,GAAG,CAAC,MAAM;qBACnB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAElC,OAAO,IAAI,0BAA0B,CAAC;gBACpC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;oBACpB,IAAI,EAAE,EAAE,CAAC,IAAI;oBACb,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,OAAO,EAAE,EAAE,CAAC,OAAO;oBACnB,WAAW,EAAE,EAAE,CAAC,WAAW;oBAC3B,cAAc,EAAE,EAAE,CAAC,cAAc;iBAClC,CAAC,CAAC;gBACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;aAC7B,CAAC,CAAA;;;;;;;;;IACJ,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { once } from 'node:events'\nimport type { ServiceImpl } from '@connectrpc/connect'\nimport type { AppContext } from '../context.js'\nimport { createMuteOpChannel } from '../db/schema/mute_op.js'\nimport type { Service } from '../proto/bsync_connect.js'\nimport { ScanMuteOperationsResponse } from '../proto/bsync_pb.js'\nimport { authWithApiKey } from './auth.js'\nimport { combinedSignals, validCursor } from './util.js'\n\nexport default (ctx: AppContext): Partial<ServiceImpl<typeof Service>> => ({\n async scanMuteOperations(req, handlerCtx) {\n authWithApiKey(ctx, handlerCtx)\n const { db, events } = ctx\n const limit = req.limit || 1000\n const cursor = validCursor(req.cursor)\n\n using signal = combinedSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n )\n\n const nextMuteOpPromise = once(events, createMuteOpChannel, { signal })\n\n // awaited later\n void nextMuteOpPromise.catch(() => null)\n\n const nextMuteOpPageQb = db.db\n .selectFrom('mute_op')\n .selectAll()\n .where('id', '>', cursor ?? -1)\n .orderBy('id', 'asc')\n .limit(limit)\n\n let ops = await nextMuteOpPageQb.execute()\n\n if (!ops.length) {\n // if there were no ops on the page, wait for an event then try again.\n try {\n await nextMuteOpPromise\n } catch (err) {\n if (ctx.shutdown.aborted) throw err\n\n return new ScanMuteOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n ops = await nextMuteOpPageQb.execute()\n if (!ops.length) {\n return new ScanMuteOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n }\n\n const lastOp = ops[ops.length - 1]\n\n return new ScanMuteOperationsResponse({\n operations: ops.map((op) => ({\n id: op.id.toString(),\n type: op.type,\n actorDid: op.actorDid,\n subject: op.subject,\n onlyReposts: op.onlyReposts,\n onlyQuoteposts: op.onlyQuoteposts,\n })),\n cursor: lastOp.id.toString(),\n })\n },\n})\n"]}
|
|
@@ -1,54 +1,117 @@
|
|
|
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
|
+
});
|
|
1
53
|
import { once } from 'node:events';
|
|
2
54
|
import { createNotifOpChannel } from '../db/schema/notif_op.js';
|
|
3
55
|
import { ScanNotifOperationsResponse } from '../proto/bsync_pb.js';
|
|
4
56
|
import { authWithApiKey } from './auth.js';
|
|
5
|
-
import {
|
|
57
|
+
import { combinedSignals, validCursor } from './util.js';
|
|
6
58
|
export default (ctx) => ({
|
|
7
59
|
async scanNotifOperations(req, handlerCtx) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
await nextNotifOpPromise;
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
ctx.shutdown.throwIfAborted();
|
|
30
|
-
return new ScanNotifOperationsResponse({
|
|
31
|
-
operations: [],
|
|
32
|
-
cursor: req.cursor,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
ops = await nextNotifOpPageQb.execute();
|
|
60
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
61
|
+
try {
|
|
62
|
+
authWithApiKey(ctx, handlerCtx);
|
|
63
|
+
const { db, events } = ctx;
|
|
64
|
+
const limit = req.limit || 1000;
|
|
65
|
+
const cursor = validCursor(req.cursor);
|
|
66
|
+
const signal = __addDisposableResource(env_1, combinedSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)), false);
|
|
67
|
+
const nextNotifOpPromise = once(events, createNotifOpChannel, { signal });
|
|
68
|
+
// awaited later
|
|
69
|
+
void nextNotifOpPromise.catch(() => null);
|
|
70
|
+
const nextNotifOpPageQb = db.db
|
|
71
|
+
.selectFrom('notif_op')
|
|
72
|
+
.selectAll()
|
|
73
|
+
.where('id', '>', cursor ?? -1)
|
|
74
|
+
.orderBy('id', 'asc')
|
|
75
|
+
.limit(limit);
|
|
76
|
+
let ops = await nextNotifOpPageQb.execute();
|
|
36
77
|
if (!ops.length) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
78
|
+
// if there were no ops on the page, wait for an event then try again.
|
|
79
|
+
try {
|
|
80
|
+
await nextNotifOpPromise;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (ctx.shutdown.aborted)
|
|
84
|
+
throw err;
|
|
85
|
+
return new ScanNotifOperationsResponse({
|
|
86
|
+
operations: [],
|
|
87
|
+
cursor: req.cursor,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
ops = await nextNotifOpPageQb.execute();
|
|
91
|
+
if (!ops.length) {
|
|
92
|
+
return new ScanNotifOperationsResponse({
|
|
93
|
+
operations: [],
|
|
94
|
+
cursor: req.cursor,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
41
97
|
}
|
|
98
|
+
const lastOp = ops[ops.length - 1];
|
|
99
|
+
return new ScanNotifOperationsResponse({
|
|
100
|
+
operations: ops.map((op) => ({
|
|
101
|
+
id: op.id.toString(),
|
|
102
|
+
actorDid: op.actorDid,
|
|
103
|
+
priority: op.priority ?? undefined,
|
|
104
|
+
})),
|
|
105
|
+
cursor: lastOp.id.toString(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (e_1) {
|
|
109
|
+
env_1.error = e_1;
|
|
110
|
+
env_1.hasError = true;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
__disposeResources(env_1);
|
|
42
114
|
}
|
|
43
|
-
const lastOp = ops[ops.length - 1];
|
|
44
|
-
return new ScanNotifOperationsResponse({
|
|
45
|
-
operations: ops.map((op) => ({
|
|
46
|
-
id: op.id.toString(),
|
|
47
|
-
actorDid: op.actorDid,
|
|
48
|
-
priority: op.priority ?? undefined,
|
|
49
|
-
})),
|
|
50
|
-
cursor: lastOp.id.toString(),
|
|
51
|
-
});
|
|
52
115
|
},
|
|
53
116
|
});
|
|
54
117
|
//# sourceMappingURL=scan-notif-operations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan-notif-operations.js","sourceRoot":"","sources":["../../src/routes/scan-notif-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"scan-notif-operations.js","sourceRoot":"","sources":["../../src/routes/scan-notif-operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAExD,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,UAAU;;;YACvC,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;YAC/B,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;YAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,IAAI,CAAA;YAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAEtC,MAAM,MAAM,kCAAG,eAAe,CAC5B,GAAG,CAAC,QAAQ,EACZ,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CACvD,QAAA,CAAA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CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;oBACpB,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,SAAS;iBACnC,CAAC,CAAC;gBACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;aAC7B,CAAC,CAAA;;;;;;;;;IACJ,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { once } from 'node:events'\nimport type { ServiceImpl } from '@connectrpc/connect'\nimport type { AppContext } from '../context.js'\nimport { createNotifOpChannel } from '../db/schema/notif_op.js'\nimport type { Service } from '../proto/bsync_connect.js'\nimport { ScanNotifOperationsResponse } from '../proto/bsync_pb.js'\nimport { authWithApiKey } from './auth.js'\nimport { combinedSignals, validCursor } from './util.js'\n\nexport default (ctx: AppContext): Partial<ServiceImpl<typeof Service>> => ({\n async scanNotifOperations(req, handlerCtx) {\n authWithApiKey(ctx, handlerCtx)\n const { db, events } = ctx\n const limit = req.limit || 1000\n const cursor = validCursor(req.cursor)\n\n using signal = combinedSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n )\n\n const nextNotifOpPromise = once(events, createNotifOpChannel, { signal })\n\n // awaited later\n void nextNotifOpPromise.catch(() => null)\n\n const nextNotifOpPageQb = db.db\n .selectFrom('notif_op')\n .selectAll()\n .where('id', '>', cursor ?? -1)\n .orderBy('id', 'asc')\n .limit(limit)\n\n let ops = await nextNotifOpPageQb.execute()\n\n if (!ops.length) {\n // if there were no ops on the page, wait for an event then try again.\n try {\n await nextNotifOpPromise\n } catch (err) {\n if (ctx.shutdown.aborted) throw err\n\n return new ScanNotifOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n ops = await nextNotifOpPageQb.execute()\n if (!ops.length) {\n return new ScanNotifOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n }\n\n const lastOp = ops[ops.length - 1]\n\n return new ScanNotifOperationsResponse({\n operations: ops.map((op) => ({\n id: op.id.toString(),\n actorDid: op.actorDid,\n priority: op.priority ?? undefined,\n })),\n cursor: lastOp.id.toString(),\n })\n },\n})\n"]}
|
|
@@ -1,57 +1,120 @@
|
|
|
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
|
+
});
|
|
1
53
|
import { once } from 'node:events';
|
|
2
54
|
import { createOperationChannel } from '../db/schema/operation.js';
|
|
3
55
|
import { ScanOperationsResponse } from '../proto/bsync_pb.js';
|
|
4
56
|
import { authWithApiKey } from './auth.js';
|
|
5
|
-
import {
|
|
57
|
+
import { combinedSignals, validCursor } from './util.js';
|
|
6
58
|
export default (ctx) => ({
|
|
7
59
|
async scanOperations(req, handlerCtx) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
await nextOpPromise;
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
ctx.shutdown.throwIfAborted();
|
|
30
|
-
return new ScanOperationsResponse({
|
|
31
|
-
operations: [],
|
|
32
|
-
cursor: req.cursor,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
ops = await nextOpPageQb.execute();
|
|
60
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
61
|
+
try {
|
|
62
|
+
authWithApiKey(ctx, handlerCtx);
|
|
63
|
+
const { db, events } = ctx;
|
|
64
|
+
const limit = req.limit || 1000;
|
|
65
|
+
const cursor = validCursor(req.cursor);
|
|
66
|
+
const signal = __addDisposableResource(env_1, combinedSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)), false);
|
|
67
|
+
const nextOpPromise = once(events, createOperationChannel, { signal });
|
|
68
|
+
// awaited later
|
|
69
|
+
void nextOpPromise.catch(() => null);
|
|
70
|
+
const nextOpPageQb = db.db
|
|
71
|
+
.selectFrom('operation')
|
|
72
|
+
.selectAll()
|
|
73
|
+
.where('id', '>', cursor ?? -1)
|
|
74
|
+
.orderBy('id', 'asc')
|
|
75
|
+
.limit(limit);
|
|
76
|
+
let ops = await nextOpPageQb.execute();
|
|
36
77
|
if (!ops.length) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
78
|
+
// if there were no ops on the page, wait for an event then try again.
|
|
79
|
+
try {
|
|
80
|
+
await nextOpPromise;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (ctx.shutdown.aborted)
|
|
84
|
+
throw err;
|
|
85
|
+
return new ScanOperationsResponse({
|
|
86
|
+
operations: [],
|
|
87
|
+
cursor: req.cursor,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
ops = await nextOpPageQb.execute();
|
|
91
|
+
if (!ops.length) {
|
|
92
|
+
return new ScanOperationsResponse({
|
|
93
|
+
operations: [],
|
|
94
|
+
cursor: req.cursor,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
41
97
|
}
|
|
98
|
+
const lastOp = ops[ops.length - 1];
|
|
99
|
+
return new ScanOperationsResponse({
|
|
100
|
+
operations: ops.map((op) => ({
|
|
101
|
+
id: op.id.toString(),
|
|
102
|
+
actorDid: op.actorDid,
|
|
103
|
+
namespace: op.namespace,
|
|
104
|
+
key: op.key,
|
|
105
|
+
method: op.method,
|
|
106
|
+
payload: op.payload,
|
|
107
|
+
})),
|
|
108
|
+
cursor: lastOp.id.toString(),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (e_1) {
|
|
112
|
+
env_1.error = e_1;
|
|
113
|
+
env_1.hasError = true;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
__disposeResources(env_1);
|
|
42
117
|
}
|
|
43
|
-
const lastOp = ops[ops.length - 1];
|
|
44
|
-
return new ScanOperationsResponse({
|
|
45
|
-
operations: ops.map((op) => ({
|
|
46
|
-
id: op.id.toString(),
|
|
47
|
-
actorDid: op.actorDid,
|
|
48
|
-
namespace: op.namespace,
|
|
49
|
-
key: op.key,
|
|
50
|
-
method: op.method,
|
|
51
|
-
payload: op.payload,
|
|
52
|
-
})),
|
|
53
|
-
cursor: lastOp.id.toString(),
|
|
54
|
-
});
|
|
55
118
|
},
|
|
56
119
|
});
|
|
57
120
|
//# sourceMappingURL=scan-operations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan-operations.js","sourceRoot":"","sources":["../../src/routes/scan-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"scan-operations.js","sourceRoot":"","sources":["../../src/routes/scan-operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC,OAAO,EAAE,sBAAsB,EAA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E;gBACtE,IAAI,CAAC;oBACH,MAAM,aAAa,CAAA;gBACrB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO;wBAAE,MAAM,GAAG,CAAA;oBAEnC,OAAO,IAAI,sBAAsB,CAAC;wBAChC,UAAU,EAAE,EAAE;wBACd,MAAM,EAAE,GAAG,CAAC,MAAM;qBACnB,CAAC,CAAA;gBACJ,CAAC;gBACD,GAAG,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;gBAClC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;oBAChB,OAAO,IAAI,sBAAsB,CAAC;wBAChC,UAAU,EAAE,EAAE;wBACd,MAAM,EAAE,GAAG,CAAC,MAAM;qBACnB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAElC,OAAO,IAAI,sBAAsB,CAAC;gBAChC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;oBACpB,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,SAAS,EAAE,EAAE,CAAC,SAAS;oBACvB,GAAG,EAAE,EAAE,CAAC,GAAG;oBACX,MAAM,EAAE,EAAE,CAAC,MAAM;oBACjB,OAAO,EAAE,EAAE,CAAC,OAAO;iBACpB,CAAC,CAAC;gBACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;aAC7B,CAAC,CAAA;;;;;;;;;IACJ,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { once } from 'node:events'\nimport type { ServiceImpl } from '@connectrpc/connect'\nimport type { AppContext } from '../context.js'\nimport { createOperationChannel } from '../db/schema/operation.js'\nimport type { Service } from '../proto/bsync_connect.js'\nimport { ScanOperationsResponse } from '../proto/bsync_pb.js'\nimport { authWithApiKey } from './auth.js'\nimport { combinedSignals, validCursor } from './util.js'\n\nexport default (ctx: AppContext): Partial<ServiceImpl<typeof Service>> => ({\n async scanOperations(req, handlerCtx) {\n authWithApiKey(ctx, handlerCtx)\n const { db, events } = ctx\n const limit = req.limit || 1000\n const cursor = validCursor(req.cursor)\n\n using signal = combinedSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n )\n\n const nextOpPromise = once(events, createOperationChannel, { signal })\n\n // awaited later\n void nextOpPromise.catch(() => null)\n\n const nextOpPageQb = db.db\n .selectFrom('operation')\n .selectAll()\n .where('id', '>', cursor ?? -1)\n .orderBy('id', 'asc')\n .limit(limit)\n\n let ops = await nextOpPageQb.execute()\n\n if (!ops.length) {\n // if there were no ops on the page, wait for an event then try again.\n try {\n await nextOpPromise\n } catch (err) {\n if (ctx.shutdown.aborted) throw err\n\n return new ScanOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n ops = await nextOpPageQb.execute()\n if (!ops.length) {\n return new ScanOperationsResponse({\n operations: [],\n cursor: req.cursor,\n })\n }\n }\n\n const lastOp = ops[ops.length - 1]\n\n return new ScanOperationsResponse({\n operations: ops.map((op) => ({\n id: op.id.toString(),\n actorDid: op.actorDid,\n namespace: op.namespace,\n key: op.key,\n method: op.method,\n payload: op.payload,\n })),\n cursor: lastOp.id.toString(),\n })\n },\n})\n"]}
|
package/dist/routes/util.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const validCursor: (cursor: string) => number | null;
|
|
2
|
-
export declare
|
|
2
|
+
export declare function combineSignals(...signals: readonly (AbortSignal | undefined)[]): AbortController & Disposable;
|
|
3
|
+
export declare function combinedSignals(...signals: readonly (AbortSignal | undefined)[]): AbortSignal & Disposable;
|
|
3
4
|
export declare const isValidDid: (did: string) => boolean;
|
|
4
5
|
export declare const isValidAtUri: (uri: string) => boolean;
|
|
5
6
|
export declare const validateNamespace: (namespace: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/routes/util.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,MAAM,GAAG,IAOrD,CAAA;AAED,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/routes/util.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,MAAM,GAAG,IAOrD,CAAA;AAED,wBAAgB,cAAc,CAC5B,GAAG,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,GAC/C,eAAe,GAAG,UAAU,CAwB9B;AAED,wBAAgB,eAAe,CAC7B,GAAG,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,GAC/C,WAAW,GAAG,UAAU,CAK1B;AAYD,eAAO,MAAM,UAAU,QAAS,MAAM,YAUrC,CAAA;AAED,eAAO,MAAM,YAAY,QAAS,MAAM,YAOvC,CAAA;AAED,eAAO,MAAM,iBAAiB,cAAe,MAAM,KAAG,IAarD,CAAA"}
|