@atproto/bsync 0.0.0-spaces-alpha-20260818021221

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 (132) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +15 -0
  4. package/dist/client.d.ts +7 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +12 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/config.d.ts +37 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +45 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/context.d.ts +25 -0
  13. package/dist/context.d.ts.map +1 -0
  14. package/dist/context.js +21 -0
  15. package/dist/context.js.map +1 -0
  16. package/dist/db/index.d.ts +32 -0
  17. package/dist/db/index.d.ts.map +1 -0
  18. package/dist/db/index.js +150 -0
  19. package/dist/db/index.js.map +1 -0
  20. package/dist/db/migrations/20240108T220751294Z-init.d.ts +4 -0
  21. package/dist/db/migrations/20240108T220751294Z-init.d.ts.map +1 -0
  22. package/dist/db/migrations/20240108T220751294Z-init.js +23 -0
  23. package/dist/db/migrations/20240108T220751294Z-init.js.map +1 -0
  24. package/dist/db/migrations/20240717T224303472Z-notif-ops.d.ts +4 -0
  25. package/dist/db/migrations/20240717T224303472Z-notif-ops.d.ts.map +1 -0
  26. package/dist/db/migrations/20240717T224303472Z-notif-ops.js +21 -0
  27. package/dist/db/migrations/20240717T224303472Z-notif-ops.js.map +1 -0
  28. package/dist/db/migrations/20250527T022203400Z-add-operation.d.ts +4 -0
  29. package/dist/db/migrations/20250527T022203400Z-add-operation.d.ts.map +1 -0
  30. package/dist/db/migrations/20250527T022203400Z-add-operation.js +17 -0
  31. package/dist/db/migrations/20250527T022203400Z-add-operation.js.map +1 -0
  32. package/dist/db/migrations/20250603T163446567Z-alter-operation.d.ts +4 -0
  33. package/dist/db/migrations/20250603T163446567Z-alter-operation.d.ts.map +1 -0
  34. package/dist/db/migrations/20250603T163446567Z-alter-operation.js +15 -0
  35. package/dist/db/migrations/20250603T163446567Z-alter-operation.js.map +1 -0
  36. package/dist/db/migrations/20260618T200000000Z-add-mute-scope.d.ts +4 -0
  37. package/dist/db/migrations/20260618T200000000Z-add-mute-scope.d.ts.map +1 -0
  38. package/dist/db/migrations/20260618T200000000Z-add-mute-scope.js +27 -0
  39. package/dist/db/migrations/20260618T200000000Z-add-mute-scope.js.map +1 -0
  40. package/dist/db/migrations/index.d.ts +6 -0
  41. package/dist/db/migrations/index.d.ts.map +1 -0
  42. package/dist/db/migrations/index.js +9 -0
  43. package/dist/db/migrations/index.js.map +1 -0
  44. package/dist/db/migrations/provider.d.ts +7 -0
  45. package/dist/db/migrations/provider.d.ts.map +1 -0
  46. package/dist/db/migrations/provider.js +9 -0
  47. package/dist/db/migrations/provider.js.map +1 -0
  48. package/dist/db/schema/index.d.ts +9 -0
  49. package/dist/db/schema/index.d.ts.map +1 -0
  50. package/dist/db/schema/index.js +2 -0
  51. package/dist/db/schema/index.js.map +1 -0
  52. package/dist/db/schema/mute_item.d.ts +14 -0
  53. package/dist/db/schema/mute_item.d.ts.map +1 -0
  54. package/dist/db/schema/mute_item.js +2 -0
  55. package/dist/db/schema/mute_item.js.map +1 -0
  56. package/dist/db/schema/mute_op.d.ts +18 -0
  57. package/dist/db/schema/mute_op.d.ts.map +1 -0
  58. package/dist/db/schema/mute_op.js +3 -0
  59. package/dist/db/schema/mute_op.js.map +1 -0
  60. package/dist/db/schema/notif_item.d.ts +12 -0
  61. package/dist/db/schema/notif_item.d.ts.map +1 -0
  62. package/dist/db/schema/notif_item.js +2 -0
  63. package/dist/db/schema/notif_item.js.map +1 -0
  64. package/dist/db/schema/notif_op.d.ts +14 -0
  65. package/dist/db/schema/notif_op.d.ts.map +1 -0
  66. package/dist/db/schema/notif_op.js +3 -0
  67. package/dist/db/schema/notif_op.js.map +1 -0
  68. package/dist/db/schema/operation.d.ts +18 -0
  69. package/dist/db/schema/operation.d.ts.map +1 -0
  70. package/dist/db/schema/operation.js +3 -0
  71. package/dist/db/schema/operation.js.map +1 -0
  72. package/dist/db/types.d.ts +15 -0
  73. package/dist/db/types.d.ts.map +1 -0
  74. package/dist/db/types.js +2 -0
  75. package/dist/db/types.js.map +1 -0
  76. package/dist/index.d.ts +26 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +106 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/logger.d.ts +6 -0
  81. package/dist/logger.d.ts.map +1 -0
  82. package/dist/logger.js +22 -0
  83. package/dist/logger.js.map +1 -0
  84. package/dist/proto/bsync_connect.d.ts +87 -0
  85. package/dist/proto/bsync_connect.d.ts.map +1 -0
  86. package/dist/proto/bsync_connect.js +91 -0
  87. package/dist/proto/bsync_connect.js.map +1 -0
  88. package/dist/proto/bsync_pb.d.ts +481 -0
  89. package/dist/proto/bsync_pb.d.ts.map +1 -0
  90. package/dist/proto/bsync_pb.js +751 -0
  91. package/dist/proto/bsync_pb.js.map +1 -0
  92. package/dist/routes/add-mute-operation.d.ts +6 -0
  93. package/dist/routes/add-mute-operation.d.ts.map +1 -0
  94. package/dist/routes/add-mute-operation.js +128 -0
  95. package/dist/routes/add-mute-operation.js.map +1 -0
  96. package/dist/routes/add-notif-operation.d.ts +6 -0
  97. package/dist/routes/add-notif-operation.d.ts.map +1 -0
  98. package/dist/routes/add-notif-operation.js +61 -0
  99. package/dist/routes/add-notif-operation.js.map +1 -0
  100. package/dist/routes/auth.d.ts +4 -0
  101. package/dist/routes/auth.d.ts.map +1 -0
  102. package/dist/routes/auth.js +13 -0
  103. package/dist/routes/auth.js.map +1 -0
  104. package/dist/routes/delete-operations.d.ts +6 -0
  105. package/dist/routes/delete-operations.d.ts.map +1 -0
  106. package/dist/routes/delete-operations.js +36 -0
  107. package/dist/routes/delete-operations.js.map +1 -0
  108. package/dist/routes/index.d.ts +5 -0
  109. package/dist/routes/index.d.ts.map +1 -0
  110. package/dist/routes/index.js +26 -0
  111. package/dist/routes/index.js.map +1 -0
  112. package/dist/routes/put-operation.d.ts +6 -0
  113. package/dist/routes/put-operation.d.ts.map +1 -0
  114. package/dist/routes/put-operation.js +78 -0
  115. package/dist/routes/put-operation.js.map +1 -0
  116. package/dist/routes/scan-mute-operations.d.ts +6 -0
  117. package/dist/routes/scan-mute-operations.d.ts.map +1 -0
  118. package/dist/routes/scan-mute-operations.js +57 -0
  119. package/dist/routes/scan-mute-operations.js.map +1 -0
  120. package/dist/routes/scan-notif-operations.d.ts +6 -0
  121. package/dist/routes/scan-notif-operations.d.ts.map +1 -0
  122. package/dist/routes/scan-notif-operations.js +54 -0
  123. package/dist/routes/scan-notif-operations.js.map +1 -0
  124. package/dist/routes/scan-operations.d.ts +6 -0
  125. package/dist/routes/scan-operations.d.ts.map +1 -0
  126. package/dist/routes/scan-operations.js +57 -0
  127. package/dist/routes/scan-operations.js.map +1 -0
  128. package/dist/routes/util.d.ts +6 -0
  129. package/dist/routes/util.d.ts.map +1 -0
  130. package/dist/routes/util.js +58 -0
  131. package/dist/routes/util.js.map +1 -0
  132. package/package.json +61 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"put-operation.js","sourceRoot":"","sources":["../../src/routes/put-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAoB,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAGtD,OAAO,EAEL,sBAAsB,GACvB,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACL,MAAM,EAEN,oBAAoB,GACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEzD,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KA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;YACf,MAAM,IAAI,YAAY,CACpB,8DAA8D,EAC9D,IAAI,CAAC,eAAe,CACrB,CAAA;QACH,CAAC;IACH,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,YAAY,CACpB,gDAAgD,EAChD,IAAI,CAAC,eAAe,CACrB,CAAA;IACH,CAAC;IAED,OAAO,GAAgB,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import { Code, ConnectError, type ServiceImpl } from '@connectrpc/connect'\nimport { sql } from 'kysely'\nimport { ensureValidRecordKey } from '@atproto/syntax'\nimport type { AppContext } from '../context.js'\nimport type { Database } from '../db/index.js'\nimport {\n type OperationMethod,\n createOperationChannel,\n} from '../db/schema/operation.js'\nimport type { Service } from '../proto/bsync_connect.js'\nimport {\n Method,\n type PutOperationRequest,\n PutOperationResponse,\n} from '../proto/bsync_pb.js'\nimport { authWithApiKey } from './auth.js'\nimport { isValidDid, validateNamespace } from './util.js'\n\nexport default (ctx: AppContext): Partial<ServiceImpl<typeof Service>> => ({\n async putOperation(req, handlerCtx) {\n authWithApiKey(ctx, handlerCtx)\n const { db } = ctx\n const op = validateOp(req)\n const id = await db.transaction(async (txn) => {\n return putOp(txn, op)\n })\n return new PutOperationResponse({\n operation: {\n id: String(id),\n actorDid: op.actorDid,\n namespace: op.namespace,\n key: op.key,\n method: op.method,\n payload: op.payload,\n },\n })\n },\n})\n\nconst putOp = async (db: Database, op: Operation) => {\n const { ref } = db.db.dynamic\n const { id } = await db.db\n .insertInto('operation')\n .values({\n actorDid: op.actorDid,\n namespace: op.namespace,\n key: op.key,\n method: op.method,\n payload: op.payload,\n })\n .returning('id')\n .executeTakeFirstOrThrow()\n await sql`notify ${ref(createOperationChannel)}`.execute(db.db) // emitted transactionally\n return id\n}\n\nconst validateOp = (req: PutOperationRequest): Operation => {\n try {\n validateNamespace(req.namespace)\n } catch (error) {\n throw new ConnectError(\n 'operation namespace is invalid NSID',\n Code.InvalidArgument,\n )\n }\n\n if (!isValidDid(req.actorDid)) {\n throw new ConnectError(\n 'operation actor_did is invalid DID',\n Code.InvalidArgument,\n )\n }\n\n try {\n ensureValidRecordKey(req.key)\n } catch (error) {\n throw new ConnectError('operation key is required', Code.InvalidArgument)\n }\n\n if (\n req.method !== Method.CREATE &&\n req.method !== Method.UPDATE &&\n req.method !== Method.DELETE\n ) {\n throw new ConnectError('operation method is invalid', Code.InvalidArgument)\n }\n\n if (req.method === Method.CREATE || req.method === Method.UPDATE) {\n try {\n JSON.parse(new TextDecoder().decode(req.payload))\n } catch (error) {\n throw new ConnectError(\n 'payload must be a valid JSON when method is CREATE or UPDATE',\n Code.InvalidArgument,\n )\n }\n }\n\n if (req.method === Method.DELETE && req.payload.length > 0) {\n throw new ConnectError(\n 'cannot specify a payload when method is DELETE',\n Code.InvalidArgument,\n )\n }\n\n return req as Operation\n}\n\ntype Operation = {\n actorDid: string\n namespace: string\n key: string\n payload: Uint8Array<ArrayBuffer>\n method: OperationMethod\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ServiceImpl } from '@connectrpc/connect';
2
+ import type { AppContext } from '../context.js';
3
+ import type { Service } from '../proto/bsync_connect.js';
4
+ export default _default;
5
+ declare function _default(ctx: AppContext): Partial<ServiceImpl<typeof Service>>;
6
+ //# sourceMappingURL=scan-mute-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-mute-operations.d.ts","sourceRoot":"","sources":["../../src/routes/scan-mute-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;;0BAKxC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { once } from 'node:events';
2
+ import { createMuteOpChannel } from '../db/schema/mute_op.js';
3
+ import { ScanMuteOperationsResponse } from '../proto/bsync_pb.js';
4
+ import { authWithApiKey } from './auth.js';
5
+ import { combineSignals, validCursor } from './util.js';
6
+ export default (ctx) => ({
7
+ 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();
36
+ if (!ops.length) {
37
+ return new ScanMuteOperationsResponse({
38
+ operations: [],
39
+ cursor: req.cursor,
40
+ });
41
+ }
42
+ }
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
+ },
56
+ });
57
+ //# sourceMappingURL=sc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} 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"]}
@@ -0,0 +1,6 @@
1
+ import type { ServiceImpl } from '@connectrpc/connect';
2
+ import type { AppContext } from '../context.js';
3
+ import type { Service } from '../proto/bsync_connect.js';
4
+ export default _default;
5
+ declare function _default(ctx: AppContext): Partial<ServiceImpl<typeof Service>>;
6
+ //# sourceMappingURL=scan-notif-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-notif-operations.d.ts","sourceRoot":"","sources":["../../src/routes/scan-notif-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;;0BAKxC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { once } from 'node:events';
2
+ import { createNotifOpChannel } from '../db/schema/notif_op.js';
3
+ import { ScanNotifOperationsResponse } from '../proto/bsync_pb.js';
4
+ import { authWithApiKey } from './auth.js';
5
+ import { combineSignals, validCursor } from './util.js';
6
+ export default (ctx) => ({
7
+ 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();
36
+ if (!ops.length) {
37
+ return new ScanNotifOperationsResponse({
38
+ operations: [],
39
+ cursor: req.cursor,
40
+ });
41
+ }
42
+ }
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
+ },
53
+ });
54
+ //# sourceMappingURL=scan-notif-operations.js.map
@@ -0,0 +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,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,IAAI,CAAA;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACtC,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE;YAC5D,MAAM,EAAE,cAAc,CACpB,GAAG,CAAC,QAAQ,EACZ,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG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C,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"]}
@@ -0,0 +1,6 @@
1
+ import type { ServiceImpl } from '@connectrpc/connect';
2
+ import type { AppContext } from '../context.js';
3
+ import type { Service } from '../proto/bsync_connect.js';
4
+ export default _default;
5
+ declare function _default(ctx: AppContext): Partial<ServiceImpl<typeof Service>>;
6
+ //# sourceMappingURL=scan-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-operations.d.ts","sourceRoot":"","sources":["../../src/routes/scan-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;;0BAKxC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { once } from 'node:events';
2
+ import { createOperationChannel } from '../db/schema/operation.js';
3
+ import { ScanOperationsResponse } from '../proto/bsync_pb.js';
4
+ import { authWithApiKey } from './auth.js';
5
+ import { combineSignals, validCursor } from './util.js';
6
+ export default (ctx) => ({
7
+ 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();
36
+ if (!ops.length) {
37
+ return new ScanOperationsResponse({
38
+ operations: [],
39
+ cursor: req.cursor,
40
+ });
41
+ }
42
+ }
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
+ },
56
+ });
57
+ //# sourceMappingURL=scan-operations.js.map
@@ -0,0 +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,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvD,eAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU;QAClC,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC/B,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;QAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,IAAI,CAAA;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA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CAAA;QAElC,OAAO,IAAI,sBAAsB,CAAC;YAChC,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,SAAS,EAAE,EAAE,CAAC,SAAS;gBACvB,GAAG,EAAE,EAAE,CAAC,GAAG;gBACX,MAAM,EAAE,EAAE,CAAC,MAAM;gBACjB,OAAO,EAAE,EAAE,CAAC,OAAO;aACpB,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 { 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 { combineSignals, 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 const nextOpPromise = once(events, createOperationChannel, {\n signal: combineSignals(\n ctx.shutdown,\n AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs),\n ),\n })\n nextOpPromise.catch(() => null) // ensure timeout is always handled\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 ctx.shutdown.throwIfAborted()\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"]}
@@ -0,0 +1,6 @@
1
+ export declare const validCursor: (cursor: string) => number | null;
2
+ export declare const combineSignals: (a: AbortSignal, b: AbortSignal) => AbortSignal;
3
+ export declare const isValidDid: (did: string) => boolean;
4
+ export declare const isValidAtUri: (uri: string) => boolean;
5
+ export declare const validateNamespace: (namespace: string) => void;
6
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +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,eAAO,MAAM,cAAc,MAAO,WAAW,KAAK,WAAW,KAAG,WAa/D,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,YAUrC,CAAA;AAED,eAAO,MAAM,YAAY,QAAS,MAAM,YAOvC,CAAA;AAED,eAAO,MAAM,iBAAiB,cAAe,MAAM,KAAG,IAarD,CAAA"}
@@ -0,0 +1,58 @@
1
+ import { Code, ConnectError } from '@connectrpc/connect';
2
+ import { InvalidDidError, ensureValidAtUri, ensureValidDid, ensureValidNsid, } from '@atproto/syntax';
3
+ export const validCursor = (cursor) => {
4
+ if (cursor === '')
5
+ return null;
6
+ const int = parseInt(cursor, 10);
7
+ if (isNaN(int) || int < 0) {
8
+ throw new ConnectError('invalid cursor', Code.InvalidArgument);
9
+ }
10
+ return int;
11
+ };
12
+ export const combineSignals = (a, b) => {
13
+ const controller = new AbortController();
14
+ for (const signal of [a, b]) {
15
+ if (signal.aborted) {
16
+ controller.abort();
17
+ return signal;
18
+ }
19
+ signal.addEventListener('abort', () => controller.abort(signal.reason), {
20
+ // @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68625
21
+ signal: controller.signal,
22
+ });
23
+ }
24
+ return controller.signal;
25
+ };
26
+ export const isValidDid = (did) => {
27
+ try {
28
+ ensureValidDid(did);
29
+ return true;
30
+ }
31
+ catch (err) {
32
+ if (err instanceof InvalidDidError) {
33
+ return false;
34
+ }
35
+ throw err;
36
+ }
37
+ };
38
+ export const isValidAtUri = (uri) => {
39
+ try {
40
+ ensureValidAtUri(uri);
41
+ return true;
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ };
47
+ export const validateNamespace = (namespace) => {
48
+ const parts = namespace.split('#');
49
+ if (parts.length !== 1 && parts.length !== 2) {
50
+ throw new Error('namespace must be in the format "nsid[#fragment]"');
51
+ }
52
+ const [nsid, fragment] = parts;
53
+ ensureValidNsid(nsid);
54
+ if (fragment && !/^[a-zA-Z][a-zA-Z0-9]*$/.test(fragment)) {
55
+ throw new Error('namespace fragment must be a valid identifier');
56
+ }
57
+ };
58
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/routes/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAA;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAiB,EAAE;IAC3D,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAC9B,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAChC,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QA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BAAiB,GAAG,CAAC,SAAiB,EAAQ,EAAE;IAC3D,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAElC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAA;IAE9B,eAAe,CAAC,IAAI,CAAC,CAAA;IACrB,IAAI,QAAQ,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { Code, ConnectError } from '@connectrpc/connect'\nimport {\n InvalidDidError,\n ensureValidAtUri,\n ensureValidDid,\n ensureValidNsid,\n} from '@atproto/syntax'\n\nexport const validCursor = (cursor: string): number | null => {\n if (cursor === '') return null\n const int = parseInt(cursor, 10)\n if (isNaN(int) || int < 0) {\n throw new ConnectError('invalid cursor', Code.InvalidArgument)\n }\n return int\n}\n\nexport const combineSignals = (a: AbortSignal, b: AbortSignal): AbortSignal => {\n const controller = new AbortController()\n for (const signal of [a, b]) {\n if (signal.aborted) {\n controller.abort()\n return signal\n }\n signal.addEventListener('abort', () => controller.abort(signal.reason), {\n // @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68625\n signal: controller.signal,\n })\n }\n return controller.signal\n}\n\nexport const isValidDid = (did: string) => {\n try {\n ensureValidDid(did)\n return true\n } catch (err) {\n if (err instanceof InvalidDidError) {\n return false\n }\n throw err\n }\n}\n\nexport const isValidAtUri = (uri: string) => {\n try {\n ensureValidAtUri(uri)\n return true\n } catch {\n return false\n }\n}\n\nexport const validateNamespace = (namespace: string): void => {\n const parts = namespace.split('#')\n\n if (parts.length !== 1 && parts.length !== 2) {\n throw new Error('namespace must be in the format \"nsid[#fragment]\"')\n }\n\n const [nsid, fragment] = parts\n\n ensureValidNsid(nsid)\n if (fragment && !/^[a-zA-Z][a-zA-Z0-9]*$/.test(fragment)) {\n throw new Error('namespace fragment must be a valid identifier')\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@atproto/bsync",
3
+ "version": "0.0.0-spaces-alpha-20260818021221",
4
+ "license": "MIT",
5
+ "description": "Sychronizing service for app.bsky App View (Bluesky API)",
6
+ "keywords": [
7
+ "atproto",
8
+ "bluesky"
9
+ ],
10
+ "homepage": "https://atproto.com",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/bluesky-social/atproto",
14
+ "directory": "packages/bsync"
15
+ },
16
+ "files": [
17
+ "./dist",
18
+ "./README.md",
19
+ "./CHANGELOG.md"
20
+ ],
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "engines": {
29
+ "node": ">=22"
30
+ },
31
+ "dependencies": {
32
+ "@bufbuild/protobuf": "^1.5.0",
33
+ "@connectrpc/connect": "^1.1.4",
34
+ "@connectrpc/connect-node": "^1.1.4",
35
+ "http-terminator": "^3.2.0",
36
+ "kysely": "^0.29.2",
37
+ "pg": "^8.10.0",
38
+ "pino-http": "^11.0.0",
39
+ "@atproto/common": "^0.0.0-spaces-alpha-20260818021221",
40
+ "@atproto/syntax": "^0.0.0-spaces-alpha-20260818021221"
41
+ },
42
+ "devDependencies": {
43
+ "@bufbuild/buf": "^1.28.1",
44
+ "@bufbuild/protoc-gen-es": "^1.5.0",
45
+ "@connectrpc/protoc-gen-connect-es": "^1.1.4",
46
+ "@types/pg": "^8.15.5",
47
+ "get-port": "^5.1.1",
48
+ "jest": "^30.0.0"
49
+ },
50
+ "scripts": {
51
+ "codegen:buf": "buf generate proto",
52
+ "prebuild": "pnpm run '/^(codegen:.+)$/'",
53
+ "build": "tsc --build tsconfig.build.json",
54
+ "start": "node --enable-source-maps dist/bin.js",
55
+ "test": "NODE_OPTIONS=--experimental-vm-modules ../dev-infra/with-test-db.sh jest",
56
+ "test:log": "tail -50 test.log | pino-pretty",
57
+ "test:updateSnapshot": "jest --updateSnapshot",
58
+ "migration:create": "node ./bin/migration-create.ts",
59
+ "buf:gen": ">&2 echo 'DEPRECATED: run `pnpm run codegen:buf` instead ' && pnpm run codegen:buf"
60
+ }
61
+ }