@atproto/bsync 0.0.42 → 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.
Files changed (62) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/config.d.ts +9 -0
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +13 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/context.d.ts +3 -0
  7. package/dist/context.d.ts.map +1 -1
  8. package/dist/context.js +14 -1
  9. package/dist/context.js.map +1 -1
  10. package/dist/dataplane.d.ts +9 -0
  11. package/dist/dataplane.d.ts.map +1 -0
  12. package/dist/dataplane.js +30 -0
  13. package/dist/dataplane.js.map +1 -0
  14. package/dist/proto/bsync_connect.d.ts +10 -10
  15. package/dist/proto/bsync_connect.d.ts.map +1 -1
  16. package/dist/proto/bsync_connect.js +11 -11
  17. package/dist/proto/bsync_connect.js.map +1 -1
  18. package/dist/proto/bsync_pb.d.ts +35 -39
  19. package/dist/proto/bsync_pb.d.ts.map +1 -1
  20. package/dist/proto/bsync_pb.js +56 -58
  21. package/dist/proto/bsync_pb.js.map +1 -1
  22. package/dist/proto/dataplane_connect.d.ts +20 -0
  23. package/dist/proto/dataplane_connect.d.ts.map +1 -0
  24. package/dist/proto/dataplane_connect.js +24 -0
  25. package/dist/proto/dataplane_connect.js.map +1 -0
  26. package/dist/proto/dataplane_pb.d.ts +37 -0
  27. package/dist/proto/dataplane_pb.d.ts.map +1 -0
  28. package/dist/proto/dataplane_pb.js +61 -0
  29. package/dist/proto/dataplane_pb.js.map +1 -0
  30. package/dist/routes/{add-notif-operation.d.ts → fanout-notification-seen.d.ts} +1 -1
  31. package/dist/routes/fanout-notification-seen.d.ts.map +1 -0
  32. package/dist/routes/fanout-notification-seen.js +26 -0
  33. package/dist/routes/fanout-notification-seen.js.map +1 -0
  34. package/dist/routes/index.d.ts.map +1 -1
  35. package/dist/routes/index.js +12 -4
  36. package/dist/routes/index.js.map +1 -1
  37. package/dist/routes/scan-mute-operations.js +108 -45
  38. package/dist/routes/scan-mute-operations.js.map +1 -1
  39. package/dist/routes/scan-notif-operations.js +105 -42
  40. package/dist/routes/scan-notif-operations.js.map +1 -1
  41. package/dist/routes/scan-operations.js +108 -45
  42. package/dist/routes/scan-operations.js.map +1 -1
  43. package/dist/routes/util.d.ts +2 -1
  44. package/dist/routes/util.d.ts.map +1 -1
  45. package/dist/routes/util.js +35 -12
  46. package/dist/routes/util.js.map +1 -1
  47. package/dist/telemetry/attributes.d.ts +14 -0
  48. package/dist/telemetry/attributes.d.ts.map +1 -0
  49. package/dist/telemetry/attributes.js +14 -0
  50. package/dist/telemetry/attributes.js.map +1 -0
  51. package/dist/telemetry/rpc.d.ts +30 -0
  52. package/dist/telemetry/rpc.d.ts.map +1 -0
  53. package/dist/telemetry/rpc.js +113 -0
  54. package/dist/telemetry/rpc.js.map +1 -0
  55. package/dist/telemetry/telemetry.d.ts +2 -0
  56. package/dist/telemetry/telemetry.d.ts.map +1 -0
  57. package/dist/telemetry/telemetry.js +7 -0
  58. package/dist/telemetry/telemetry.js.map +1 -0
  59. package/package.json +16 -7
  60. package/dist/routes/add-notif-operation.d.ts.map +0 -1
  61. package/dist/routes/add-notif-operation.js +0 -61
  62. package/dist/routes/add-notif-operation.js.map +0 -1
@@ -0,0 +1,26 @@
1
+ import { Code, ConnectError } from '@connectrpc/connect';
2
+ import { httpLogger } from '../logger.js';
3
+ import { authWithApiKey } from './auth.js';
4
+ import { isValidDid } from './util.js';
5
+ export default (ctx) => ({
6
+ async fanoutNotificationSeen(req, handlerCtx) {
7
+ authWithApiKey(ctx, handlerCtx);
8
+ const { actorDid, timestamp } = req;
9
+ if (!isValidDid(actorDid)) {
10
+ throw new ConnectError('actor_did must be a valid did', Code.InvalidArgument);
11
+ }
12
+ if (!timestamp) {
13
+ throw new ConnectError('timestamp is required', Code.InvalidArgument);
14
+ }
15
+ if (ctx.dataplaneClients.length === 0) {
16
+ httpLogger.warn('no dataplane clients configured');
17
+ return {};
18
+ }
19
+ const results = await Promise.allSettled(ctx.dataplaneClients.map((client) => client.updateNotificationSeen({ actorDid, timestamp })));
20
+ if (results.every((result) => result.status === 'rejected')) {
21
+ throw new ConnectError('all dataplane updates failed', Code.Unavailable);
22
+ }
23
+ return {};
24
+ },
25
+ });
26
+ //# sourceMappingURL=fanout-notification-seen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fanout-notification-seen.js","sourceRoot":"","sources":["../../src/routes/fanout-notification-seen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAoB,MAAM,qBAAqB,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK,CAAC,sBAAsB,CAAC,GAAG,EAAE,UAAU;QAC1C,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC/B,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,GAAG,CAAA;QACnC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,YAAY,CACpB,+BAA+B,EAC/B,IAAI,CAAC,eAAe,CACrB,CAAA;QACH,CAAC;QACD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,YAAY,CAAC,uBAAuB,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QACvE,CAAC;QACD,IAAI,GAAG,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,UAAU,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAA;YAClD,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CACtC,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAClC,MAAM,CAAC,sBAAsB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CACvD,CACF,CAAA;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,YAAY,CAAC,8BAA8B,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAC1E,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { Code, ConnectError, type ServiceImpl } from '@connectrpc/connect'\nimport type { AppContext } from '../context.js'\nimport { httpLogger } from '../logger.js'\nimport type { Service } from '../proto/bsync_connect.js'\nimport { authWithApiKey } from './auth.js'\nimport { isValidDid } from './util.js'\n\nexport default (ctx: AppContext): Partial<ServiceImpl<typeof Service>> => ({\n async fanoutNotificationSeen(req, handlerCtx) {\n authWithApiKey(ctx, handlerCtx)\n const { actorDid, timestamp } = req\n if (!isValidDid(actorDid)) {\n throw new ConnectError(\n 'actor_did must be a valid did',\n Code.InvalidArgument,\n )\n }\n if (!timestamp) {\n throw new ConnectError('timestamp is required', Code.InvalidArgument)\n }\n if (ctx.dataplaneClients.length === 0) {\n httpLogger.warn('no dataplane clients configured')\n return {}\n }\n\n const results = await Promise.allSettled(\n ctx.dataplaneClients.map((client) =>\n client.updateNotificationSeen({ actorDid, timestamp }),\n ),\n )\n if (results.every((result) => result.status === 'rejected')) {\n throw new ConnectError('all dataplane updates failed', Code.Unavailable)\n }\n return {}\n },\n})\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;;0BAU/B,GAAG,EAAE,UAAU,YAAc,aAAa"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;;0BAY/B,GAAG,EAAE,UAAU,YAAc,aAAa"}
@@ -1,26 +1,34 @@
1
1
  import { sql } from 'kysely';
2
+ import { ATTR_BSYNC_NAMESPACE } from '@atproto-labs/opentelemetry-node/conventions';
2
3
  import { Service } from '../proto/bsync_connect.js';
4
+ import { operationAttributes } from '../telemetry/attributes.js';
5
+ import { withRpcServerTelemetry } from '../telemetry/rpc.js';
3
6
  import addMuteOperation from './add-mute-operation.js';
4
- import addNotifOperation from './add-notif-operation.js';
5
7
  import deleteOperations from './delete-operations.js';
8
+ import fanoutNotificationSeen from './fanout-notification-seen.js';
6
9
  import putOperation from './put-operation.js';
7
10
  import scanMuteOperations from './scan-mute-operations.js';
8
11
  import scanNotifOperations from './scan-notif-operations.js';
9
12
  import scanOperations from './scan-operations.js';
10
13
  export default (ctx) => (router) => {
11
- return router.service(Service, {
14
+ return router.service(Service, withRpcServerTelemetry({
12
15
  ...addMuteOperation(ctx),
13
16
  ...scanMuteOperations(ctx),
14
- ...addNotifOperation(ctx),
15
17
  ...scanNotifOperations(ctx),
16
18
  ...putOperation(ctx),
17
19
  ...scanOperations(ctx),
18
20
  ...deleteOperations(ctx),
21
+ ...fanoutNotificationSeen(ctx),
19
22
  async ping() {
20
23
  const { db } = ctx;
21
24
  await sql `select 1`.execute(db.db);
22
25
  return {};
23
26
  },
24
- });
27
+ }, {
28
+ putOperation: operationAttributes,
29
+ deleteOperationsByActorAndNamespace: (req) => ({
30
+ [ATTR_BSYNC_NAMESPACE]: req.namespace,
31
+ }),
32
+ }));
25
33
  };
26
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,iBAAiB,MAAM,0BAA0B,CAAA;AACxD,OAAO,gBAAgB,MAAM,wBAAwB,CAAA;AACrD,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAC7C,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAC1D,OAAO,mBAAmB,MAAM,4BAA4B,CAAA;AAC5D,OAAO,cAAc,MAAM,sBAAsB,CAAA;AAEjD,eAAe,CAAC,GAAe,EAAE,EAAE,CAAC,CAAC,MAAqB,EAAE,EAAE;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,GAAG,gBAAgB,CAAC,GAAG,CAAC;QACxB,GAAG,kBAAkB,CAAC,GAAG,CAAC;QAC1B,GAAG,iBAAiB,CAAC,GAAG,CAAC;QACzB,GAAG,mBAAmB,CAAC,GAAG,CAAC;QAC3B,GAAG,YAAY,CAAC,GAAG,CAAC;QACpB,GAAG,cAAc,CAAC,GAAG,CAAC;QACtB,GAAG,gBAAgB,CAAC,GAAG,CAAC;QACxB,KAAK,CAAC,IAAI;YACR,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAA;YAClB,MAAM,GAAG,CAAA,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;YAClC,OAAO,EAAE,CAAA;QACX,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import type { ConnectRouter } from '@connectrpc/connect'\nimport { sql } from 'kysely'\nimport type { AppContext } from '../context.js'\nimport { Service } from '../proto/bsync_connect.js'\nimport addMuteOperation from './add-mute-operation.js'\nimport addNotifOperation from './add-notif-operation.js'\nimport deleteOperations from './delete-operations.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(Service, {\n ...addMuteOperation(ctx),\n ...scanMuteOperations(ctx),\n ...addNotifOperation(ctx),\n ...scanNotifOperations(ctx),\n ...putOperation(ctx),\n ...scanOperations(ctx),\n ...deleteOperations(ctx),\n async ping() {\n const { db } = ctx\n await sql`select 1`.execute(db.db)\n return {}\n },\n })\n}\n"]}
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,MAAM,qBAAqB,CAAA;AAC5D,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,gBAAgB,MAAM,wBAAwB,CAAA;AACrD,OAAO,sBAAsB,MAAM,+BAA+B,CAAA;AAClE,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAC7C,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAC1D,OAAO,mBAAmB,MAAM,4BAA4B,CAAA;AAC5D,OAAO,cAAc,MAAM,sBAAsB,CAAA;AAEjD,eAAe,CAAC,GAAe,EAAE,EAAE,CAAC,CAAC,MAAqB,EAAE,EAAE;IAC5D,OAAO,MAAM,CAAC,OAAO,CACnB,OAAO,EACP,sBAAsB,CACpB;QACE,GAAG,gBAAgB,CAAC,GAAG,CAAC;QACxB,GAAG,kBAAkB,CAAC,GAAG,CAAC;QAC1B,GAAG,mBAAmB,CAAC,GAAG,CAAC;QAC3B,GAAG,YAAY,CAAC,GAAG,CAAC;QACpB,GAAG,cAAc,CAAC,GAAG,CAAC;QACtB,GAAG,gBAAgB,CAAC,GAAG,CAAC;QACxB,GAAG,sBAAsB,CAAC,GAAG,CAAC;QAC9B,KAAK,CAAC,IAAI;YACR,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAA;YAClB,MAAM,GAAG,CAAA,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,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 { combineSignals, validCursor } from './util.js';
57
+ import { combinedSignals, validCursor } from './util.js';
6
58
  export default (ctx) => ({
7
59
  async scanMuteOperations(req, handlerCtx) {
8
- authWithApiKey(ctx, handlerCtx);
9
- const { db, events } = ctx;
10
- const limit = req.limit || 1000;
11
- const cursor = validCursor(req.cursor);
12
- const nextMuteOpPromise = once(events, createMuteOpChannel, {
13
- signal: combineSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)),
14
- });
15
- nextMuteOpPromise.catch(() => null); // ensure timeout is always handled
16
- const nextMuteOpPageQb = db.db
17
- .selectFrom('mute_op')
18
- .selectAll()
19
- .where('id', '>', cursor ?? -1)
20
- .orderBy('id', 'asc')
21
- .limit(limit);
22
- let ops = await nextMuteOpPageQb.execute();
23
- if (!ops.length) {
24
- // if there were no ops on the page, wait for an event then try again.
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
- return new ScanMuteOperationsResponse({
38
- operations: [],
39
- cursor: req.cursor,
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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C;YAChB,sEAAsE;YACtE,IAAI,CAAC;gBACH,MAAM,iBAAiB,CAAA;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,GAAG,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAA;gBAC7B,OAAO,IAAI,0BAA0B,CAAC;oBACpC,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;iBACnB,CAAC,CAAA;YACJ,CAAC;YACD,GAAG,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAA;YACtC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;gBAChB,OAAO,IAAI,0BAA0B,CAAC;oBACpC,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;iBACnB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAElC,OAAO,IAAI,0BAA0B,CAAC;YACpC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;gBACpB,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,QAAQ,EAAE,EAAE,CAAC,QAAQ;gBACrB,OAAO,EAAE,EAAE,CAAC,OAAO;gBACnB,WAAW,EAAE,EAAE,CAAC,WAAW;gBAC3B,cAAc,EAAE,EAAE,CAAC,cAAc;aAClC,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;SAC7B,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 { combineSignals, 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 const nextMuteOpPromise = once(events, createMuteOpChannel, {\n signal: combineSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n ),\n })\n nextMuteOpPromise.catch(() => null) // ensure timeout is always handled\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 ctx.shutdown.throwIfAborted()\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
+ {"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,0BA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iBAAiB,CAAA;gBACzB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO;wBAAE,MAAM,GAAG,CAAA;oBAEnC,OAAO,IAAI,0BAA0B,CAAC;wBACpC,UAAU,EAAE,EAAE;wBACd,MAAM,EAAE,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 { combineSignals, validCursor } from './util.js';
57
+ import { combinedSignals, validCursor } from './util.js';
6
58
  export default (ctx) => ({
7
59
  async scanNotifOperations(req, handlerCtx) {
8
- authWithApiKey(ctx, handlerCtx);
9
- const { db, events } = ctx;
10
- const limit = req.limit || 1000;
11
- const cursor = validCursor(req.cursor);
12
- const nextNotifOpPromise = once(events, createNotifOpChannel, {
13
- signal: combineSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)),
14
- });
15
- nextNotifOpPromise.catch(() => null); // ensure timeout is always handled
16
- const nextNotifOpPageQb = db.db
17
- .selectFrom('notif_op')
18
- .selectAll()
19
- .where('id', '>', cursor ?? -1)
20
- .orderBy('id', 'asc')
21
- .limit(limit);
22
- let ops = await nextNotifOpPageQb.execute();
23
- if (!ops.length) {
24
- // if there were no ops on the page, wait for an event then try again.
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
- return new ScanNotifOperationsResponse({
38
- operations: [],
39
- cursor: req.cursor,
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,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvD,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,UAAU;QACvC,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC/B,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;QAC1B,MAAM,K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AAG,CAAC,MAAM;iBACnB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAElC,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;gBACpB,QAAQ,EAAE,EAAE,CAAC,QAAQ;gBACrB,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,SAAS;aACnC,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;SAC7B,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 { combineSignals, 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 const nextNotifOpPromise = once(events, createNotifOpChannel, {\n signal: combineSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n ),\n })\n nextNotifOpPromise.catch(() => null) // ensure timeout is always handled\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 ctx.shutdown.throwIfAborted()\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
+ {"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,iBAAi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gBACrC,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,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 { combineSignals, validCursor } from './util.js';
57
+ import { combinedSignals, validCursor } from './util.js';
6
58
  export default (ctx) => ({
7
59
  async scanOperations(req, handlerCtx) {
8
- authWithApiKey(ctx, handlerCtx);
9
- const { db, events } = ctx;
10
- const limit = req.limit || 1000;
11
- const cursor = validCursor(req.cursor);
12
- const nextOpPromise = once(events, createOperationChannel, {
13
- signal: combineSignals(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)),
14
- });
15
- nextOpPromise.catch(() => null); // ensure timeout is always handled
16
- const nextOpPageQb = db.db
17
- .selectFrom('operation')
18
- .selectAll()
19
- .where('id', '>', cursor ?? -1)
20
- .orderBy('id', 'asc')
21
- .limit(limit);
22
- let ops = await nextOpPageQb.execute();
23
- if (!ops.length) {
24
- // if there were no ops on the page, wait for an event then try again.
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
- return new ScanOperationsResponse({
38
- operations: [],
39
- cursor: req.cursor,
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