@atproto/sync 0.2.2 → 0.3.0-next.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 (45) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/events.js +1 -2
  3. package/dist/firehose/index.d.ts +2 -2
  4. package/dist/firehose/index.d.ts.map +1 -1
  5. package/dist/firehose/index.js +48 -104
  6. package/dist/firehose/index.js.map +1 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -19
  10. package/dist/index.js.map +1 -1
  11. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.js +54 -57
  12. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.js.map +1 -1
  13. package/dist/lexicons/com/atproto/sync/subscribeRepos.js +2 -41
  14. package/dist/lexicons/com/atproto/sync/subscribeRepos.js.map +1 -1
  15. package/dist/lexicons/com/atproto/sync.js +1 -37
  16. package/dist/lexicons/com/atproto/sync.js.map +1 -1
  17. package/dist/lexicons/com/atproto.js +1 -37
  18. package/dist/lexicons/com/atproto.js.map +1 -1
  19. package/dist/lexicons/com.js +1 -37
  20. package/dist/lexicons/com.js.map +1 -1
  21. package/dist/lexicons/index.js +1 -37
  22. package/dist/lexicons/index.js.map +1 -1
  23. package/dist/runner/consecutive-list.js +6 -31
  24. package/dist/runner/consecutive-list.js.map +1 -1
  25. package/dist/runner/index.d.ts +3 -3
  26. package/dist/runner/index.d.ts.map +1 -1
  27. package/dist/runner/index.js +3 -19
  28. package/dist/runner/index.js.map +1 -1
  29. package/dist/runner/memory-runner.d.ts +6 -4
  30. package/dist/runner/memory-runner.d.ts.map +1 -1
  31. package/dist/runner/memory-runner.js +8 -42
  32. package/dist/runner/memory-runner.js.map +1 -1
  33. package/dist/runner/types.js +1 -2
  34. package/dist/util.js +6 -10
  35. package/dist/util.js.map +1 -1
  36. package/{jest.config.js → jest.config.cjs} +8 -1
  37. package/package.json +19 -14
  38. package/src/firehose/index.ts +3 -3
  39. package/src/index.ts +3 -3
  40. package/src/runner/index.ts +3 -3
  41. package/src/runner/memory-runner.ts +6 -4
  42. package/tests/firehose.test.ts +7 -1
  43. package/tests/runner.test.ts +1 -1
  44. package/tsconfig.build.tsbuildinfo +1 -1
  45. package/tsconfig.tests.json +1 -1
@@ -1,46 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MemoryRunner = void 0;
7
- const p_queue_1 = __importDefault(require("p-queue"));
8
- const consecutive_list_1 = require("./consecutive-list");
1
+ import PQueue from 'p-queue';
2
+ import { ConsecutiveList } from './consecutive-list.js';
9
3
  // A queue with arbitrarily many partitions, each processing work sequentially.
10
4
  // Partitions are created lazily and taken out of memory when they go idle.
11
- class MemoryRunner {
5
+ export class MemoryRunner {
12
6
  constructor(opts = {}) {
13
- Object.defineProperty(this, "opts", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: opts
18
- });
19
- Object.defineProperty(this, "consecutive", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: new consecutive_list_1.ConsecutiveList()
24
- });
25
- Object.defineProperty(this, "mainQueue", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- Object.defineProperty(this, "partitions", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: new Map()
36
- });
37
- Object.defineProperty(this, "cursor", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- this.mainQueue = new p_queue_1.default({ concurrency: opts.concurrency ?? Infinity });
7
+ this.opts = opts;
8
+ this.consecutive = new ConsecutiveList();
9
+ this.partitions = new Map();
10
+ this.mainQueue = new PQueue({ concurrency: opts.concurrency ?? Infinity });
44
11
  this.cursor = opts.startCursor;
45
12
  }
46
13
  getCursor() {
@@ -56,7 +23,7 @@ class MemoryRunner {
56
23
  getPartition(partitionId) {
57
24
  let partition = this.partitions.get(partitionId);
58
25
  if (!partition) {
59
- partition = new p_queue_1.default({ concurrency: 1 });
26
+ partition = new PQueue({ concurrency: 1 });
60
27
  partition.once('idle', () => this.partitions.delete(partitionId));
61
28
  this.partitions.set(partitionId, partition);
62
29
  }
@@ -87,5 +54,4 @@ class MemoryRunner {
87
54
  await this.mainQueue.onIdle();
88
55
  }
89
56
  }
90
- exports.MemoryRunner = MemoryRunner;
91
57
  //# sourceMappingURL=memory-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory-runner.js","sourceRoot":"","sources":["../../src/runner/memory-runner.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA4B;AAC5B,yDAAoD;AASpD,+EAA+E;AAC/E,2EAA2E;AAC3E,MAAa,YAAY;IAMvB,YAAmB,OAA4B,EAAE;QAArC;;;;mBAAO,IAAI;WAA0B;QALjD;;;;mBAAc,IAAI,kCAAe,EAAU;WAAA;QAC3C;;;;;WAAiB;QACjB;;;;mBAAa,IAAI,GAAG,EAAkB;WAAA;QACtC;;;;;WAA0B;QAGxB,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAM,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,QAAQ,EAAE,CAAC,CAAA;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAA;IAChC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,IAAyB;QAC1D,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ;YAAE,OAAM;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE;YAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;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AAC,OAAO;QACX,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;QACtB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;QACtB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QACzC,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAA;IAC/B,CAAC;CACF;AAzDD,oCAyDC","sourcesContent":["import PQueue from 'p-queue'\nimport { ConsecutiveList } from './consecutive-list'\nimport { EventRunner } from './types'\n\nexport type MemoryRunnerOptions = {\n setCursor?: (cursor: number) => Promise<void>\n concurrency?: number\n startCursor?: number\n}\n\n// A queue with arbitrarily many partitions, each processing work sequentially.\n// Partitions are created lazily and taken out of memory when they go idle.\nexport class MemoryRunner implements EventRunner {\n consecutive = new ConsecutiveList<number>()\n mainQueue: PQueue\n partitions = new Map<string, PQueue>()\n cursor: number | undefined\n\n constructor(public opts: MemoryRunnerOptions = {}) {\n this.mainQueue = new PQueue({ concurrency: opts.concurrency ?? Infinity })\n this.cursor = opts.startCursor\n }\n\n getCursor() {\n return this.cursor\n }\n\n async addTask(partitionId: string, task: () => Promise<void>) {\n if (this.mainQueue.isPaused) return\n return this.mainQueue.add(() => {\n return this.getPartition(partitionId).add(task)\n })\n }\n\n private getPartition(partitionId: string) {\n let partition = this.partitions.get(partitionId)\n if (!partition) {\n partition = new PQueue({ concurrency: 1 })\n partition.once('idle', () => this.partitions.delete(partitionId))\n this.partitions.set(partitionId, partition)\n }\n return partition\n }\n\n async trackEvent(did: string, seq: number, handler: () => Promise<void>) {\n if (this.mainQueue.isPaused) return\n const item = this.consecutive.push(seq)\n await this.addTask(did, async () => {\n await handler()\n const latest = item.complete().at(-1)\n if (latest !== undefined) {\n this.cursor = latest\n if (this.opts.setCursor) {\n await this.opts.setCursor(this.cursor)\n }\n }\n })\n }\n\n async processAll() {\n await this.mainQueue.onIdle()\n }\n\n async destroy() {\n this.mainQueue.pause()\n this.mainQueue.clear()\n this.partitions.forEach((p) => p.clear())\n await this.mainQueue.onIdle()\n }\n}\n"]}
1
+ {"version":3,"file":"memory-runner.js","sourceRoot":"","sources":["../../src/runner/memory-runner.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAWvD,+EAA+E;AAC/E,2EAA2E;AAC3E,MAAM,OAAO,YAAY;IAMvB,YAAmB,OAA4B,EAAE;QAA9B,SAAI,GAAJ,IAAI,CAA0B;QALjD,gBAAW,GAAG,IAAI,eAAe,EAAU,CAAA;QAE3C,eAAU,GAAuB,IAAI,GAAG,EAAE,CAAA;QAIxC,IAAI,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,QAAQ,EAAE,CAAC,CAAA;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAA;IAChC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,IAAyB;QAC1D,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ;YAAE,OAAM;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE;YAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,YAAY,CAAC,WAAmB;QACtC,IAAI,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAChD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAA;YAC1C,SAAS,CA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AAC,MAAM,EAAE,CAAA;IAC/B,CAAC;CACF","sourcesContent":["import PQueue from 'p-queue'\nimport { ConsecutiveList } from './consecutive-list.js'\nimport { EventRunner } from './types.js'\n\nexport type MemoryRunnerOptions = {\n setCursor?: (cursor: number) => Promise<void>\n concurrency?: number\n startCursor?: number\n}\n\ntype Queue = InstanceType<typeof PQueue>\n\n// A queue with arbitrarily many partitions, each processing work sequentially.\n// Partitions are created lazily and taken out of memory when they go idle.\nexport class MemoryRunner implements EventRunner {\n consecutive = new ConsecutiveList<number>()\n mainQueue: Queue\n partitions: Map<string, Queue> = new Map()\n cursor: number | undefined\n\n constructor(public opts: MemoryRunnerOptions = {}) {\n this.mainQueue = new PQueue({ concurrency: opts.concurrency ?? Infinity })\n this.cursor = opts.startCursor\n }\n\n getCursor() {\n return this.cursor\n }\n\n async addTask(partitionId: string, task: () => Promise<void>) {\n if (this.mainQueue.isPaused) return\n return this.mainQueue.add(() => {\n return this.getPartition(partitionId).add(task)\n })\n }\n\n private getPartition(partitionId: string) {\n let partition = this.partitions.get(partitionId)\n if (!partition) {\n partition = new PQueue({ concurrency: 1 })\n partition.once('idle', () => this.partitions.delete(partitionId))\n this.partitions.set(partitionId, partition)\n }\n return partition\n }\n\n async trackEvent(did: string, seq: number, handler: () => Promise<void>) {\n if (this.mainQueue.isPaused) return\n const item = this.consecutive.push(seq)\n await this.addTask(did, async () => {\n await handler()\n const latest = item.complete().at(-1)\n if (latest !== undefined) {\n this.cursor = latest\n if (this.opts.setCursor) {\n await this.opts.setCursor(this.cursor)\n }\n }\n })\n }\n\n async processAll() {\n await this.mainQueue.onIdle()\n }\n\n async destroy() {\n this.mainQueue.pause()\n this.mainQueue.clear()\n this.partitions.forEach((p) => p.clear())\n await this.mainQueue.onIdle()\n }\n}\n"]}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/dist/util.js CHANGED
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.didAndSeqForEvt = void 0;
4
- const index_js_1 = require("./lexicons/index.js");
5
- const didAndSeqForEvt = (evt) => {
6
- if (index_js_1.com.atproto.sync.subscribeRepos.commit.$isTypeOf(evt)) {
1
+ import { com } from './lexicons/index.js';
2
+ export const didAndSeqForEvt = (evt) => {
3
+ if (com.atproto.sync.subscribeRepos.commit.$isTypeOf(evt)) {
7
4
  return { seq: evt.seq, did: evt.repo };
8
5
  }
9
- else if (index_js_1.com.atproto.sync.subscribeRepos.account.$isTypeOf(evt) ||
10
- index_js_1.com.atproto.sync.subscribeRepos.identity.$isTypeOf(evt) ||
11
- index_js_1.com.atproto.sync.subscribeRepos.sync.$isTypeOf(evt)) {
6
+ else if (com.atproto.sync.subscribeRepos.account.$isTypeOf(evt) ||
7
+ com.atproto.sync.subscribeRepos.identity.$isTypeOf(evt) ||
8
+ com.atproto.sync.subscribeRepos.sync.$isTypeOf(evt)) {
12
9
  return { seq: evt.seq, did: evt.did };
13
10
  }
14
11
  return undefined;
15
12
  };
16
- exports.didAndSeqForEvt = didAndSeqForEvt;
17
13
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,kDAAyC;AAElC,MAAM,eAAe,GAAG,CAC7B,GAA6C,EACH,EAAE;IAC5C,IAAI,cAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;SAAM,IACL,cAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;QACtD,cAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC;QACvD,cAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EACnD,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;IACvC,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAbY,QAAA,eAAe,mBAa3B","sourcesContent":["import { com } from './lexicons/index.js'\n\nexport const didAndSeqForEvt = (\n evt: com.atproto.sync.subscribeRepos.$Message,\n): { did: string; seq: number } | undefined => {\n if (com.atproto.sync.subscribeRepos.commit.$isTypeOf(evt)) {\n return { seq: evt.seq, did: evt.repo }\n } else if (\n com.atproto.sync.subscribeRepos.account.$isTypeOf(evt) ||\n com.atproto.sync.subscribeRepos.identity.$isTypeOf(evt) ||\n com.atproto.sync.subscribeRepos.sync.$isTypeOf(evt)\n ) {\n return { seq: evt.seq, did: evt.did }\n }\n return undefined\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAEzC,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAA6C,EACH,EAAE;IAC5C,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;SAAM,IACL,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;QACtD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC;QACvD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EACnD,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;IACvC,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import { com } from './lexicons/index.js'\n\nexport const didAndSeqForEvt = (\n evt: com.atproto.sync.subscribeRepos.$Message,\n): { did: string; seq: number } | undefined => {\n if (com.atproto.sync.subscribeRepos.commit.$isTypeOf(evt)) {\n return { seq: evt.seq, did: evt.repo }\n } else if (\n com.atproto.sync.subscribeRepos.account.$isTypeOf(evt) ||\n com.atproto.sync.subscribeRepos.identity.$isTypeOf(evt) ||\n com.atproto.sync.subscribeRepos.sync.$isTypeOf(evt)\n ) {\n return { seq: evt.seq, did: evt.did }\n }\n return undefined\n}\n"]}
@@ -1,7 +1,14 @@
1
1
  /** @type {import('jest').Config} */
2
2
  module.exports = {
3
3
  displayName: 'Sync',
4
- transform: { '^.+\\.ts$': '@swc/jest' },
4
+ transform: {
5
+ '^.+\\.(t|j)s$': [
6
+ '@swc/jest',
7
+ { jsc: { transform: {} }, module: { type: 'es6' } },
8
+ ],
9
+ },
10
+ extensionsToTreatAsEsm: ['.ts'],
11
+ transformIgnorePatterns: [],
5
12
  testTimeout: 60000,
6
13
  setupFiles: ['<rootDir>/../../jest.setup.ts'],
7
14
  moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/sync",
3
- "version": "0.2.2",
3
+ "version": "0.3.0-next.0",
4
4
  "license": "MIT",
5
5
  "description": "atproto sync library",
6
6
  "keywords": [
@@ -16,29 +16,34 @@
16
16
  "directory": "packages/sync"
17
17
  },
18
18
  "engines": {
19
- "node": ">=18.7.0"
19
+ "node": ">=22"
20
20
  },
21
- "main": "dist/index.js",
22
- "types": "dist/index.d.ts",
23
21
  "dependencies": {
24
- "p-queue": "^6.6.2",
22
+ "p-queue": "^8.0.0",
25
23
  "ws": "^8.12.0",
26
- "@atproto/common": "^0.5.16",
27
- "@atproto/identity": "^0.4.12",
28
- "@atproto/lex": "^0.0.25",
29
- "@atproto/repo": "^0.9.1",
30
- "@atproto/syntax": "^0.5.4",
31
- "@atproto/xrpc-server": "^0.10.20"
24
+ "@atproto/common": "^0.6.0-next.0",
25
+ "@atproto/syntax": "^0.6.0-next.0",
26
+ "@atproto/identity": "^0.5.0-next.0",
27
+ "@atproto/xrpc-server": "^0.11.0-next.0",
28
+ "@atproto/repo": "^0.10.0-next.0",
29
+ "@atproto/lex": "^0.1.0-next.0"
32
30
  },
33
31
  "devDependencies": {
34
32
  "@types/ws": "^8.5.4",
35
- "jest": "^28.1.2",
36
- "typescript": "^5.6.3"
33
+ "jest": "^30.0.0",
34
+ "typescript": "^6.0.3"
35
+ },
36
+ "type": "module",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "default": "./dist/index.js"
41
+ }
37
42
  },
38
43
  "scripts": {
39
44
  "codegen": "lex build --override --indexFile --lexicons ../../lexicons --include com.atproto.sync.subscribeRepos",
40
45
  "prebuild": "pnpm run codegen",
41
46
  "build": "tsc --build tsconfig.build.json",
42
- "test": "../dev-infra/with-test-redis-and-db.sh jest"
47
+ "test": "NODE_OPTIONS=--experimental-vm-modules ../dev-infra/with-test-redis-and-db.sh jest"
43
48
  }
44
49
  }
@@ -25,10 +25,10 @@ import {
25
25
  Event,
26
26
  IdentityEvt,
27
27
  SyncEvt,
28
- } from '../events'
28
+ } from '../events.js'
29
29
  import { com } from '../lexicons/index.js'
30
- import { EventRunner } from '../runner'
31
- import { didAndSeqForEvt } from '../util'
30
+ import { EventRunner } from '../runner/index.js'
31
+ import { didAndSeqForEvt } from '../util.js'
32
32
 
33
33
  export type FirehoseOptions = ClientOptions & {
34
34
  idResolver: IdResolver
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './runner'
2
- export * from './firehose'
3
- export * from './events'
1
+ export * from './runner/index.js'
2
+ export * from './firehose/index.js'
3
+ export * from './events.js'
@@ -1,3 +1,3 @@
1
- export * from './consecutive-list'
2
- export * from './memory-runner'
3
- export * from './types'
1
+ export * from './consecutive-list.js'
2
+ export * from './memory-runner.js'
3
+ export * from './types.js'
@@ -1,6 +1,6 @@
1
1
  import PQueue from 'p-queue'
2
- import { ConsecutiveList } from './consecutive-list'
3
- import { EventRunner } from './types'
2
+ import { ConsecutiveList } from './consecutive-list.js'
3
+ import { EventRunner } from './types.js'
4
4
 
5
5
  export type MemoryRunnerOptions = {
6
6
  setCursor?: (cursor: number) => Promise<void>
@@ -8,12 +8,14 @@ export type MemoryRunnerOptions = {
8
8
  startCursor?: number
9
9
  }
10
10
 
11
+ type Queue = InstanceType<typeof PQueue>
12
+
11
13
  // A queue with arbitrarily many partitions, each processing work sequentially.
12
14
  // Partitions are created lazily and taken out of memory when they go idle.
13
15
  export class MemoryRunner implements EventRunner {
14
16
  consecutive = new ConsecutiveList<number>()
15
- mainQueue: PQueue
16
- partitions = new Map<string, PQueue>()
17
+ mainQueue: Queue
18
+ partitions: Map<string, Queue> = new Map()
17
19
  cursor: number | undefined
18
20
 
19
21
  constructor(public opts: MemoryRunnerOptions = {}) {
@@ -6,7 +6,13 @@ import {
6
6
  } from '@atproto/dev-env'
7
7
  import { IdResolver } from '@atproto/identity'
8
8
  import { DidString } from '@atproto/syntax'
9
- import { Create, Event, Firehose, FirehoseOptions, MemoryRunner } from '..'
9
+ import {
10
+ Create,
11
+ Event,
12
+ Firehose,
13
+ FirehoseOptions,
14
+ MemoryRunner,
15
+ } from '../src/index.js'
10
16
 
11
17
  describe('firehose', () => {
12
18
  let network: TestNetworkNoAppView
@@ -1,5 +1,5 @@
1
1
  import { wait } from '@atproto/common'
2
- import { ConsecutiveList, MemoryRunner } from '..'
2
+ import { ConsecutiveList, MemoryRunner } from '../src/index.js'
3
3
 
4
4
  describe('EventRunner utils', () => {
5
5
  describe('ConsecutiveList', () => {
@@ -1 +1 @@
1
- {"root":["./src/events.ts","./src/index.ts","./src/util.ts","./src/firehose/index.ts","./src/lexicons/com.ts","./src/lexicons/index.ts","./src/lexicons/com/atproto.ts","./src/lexicons/com/atproto/sync.ts","./src/lexicons/com/atproto/sync/subscribeRepos.defs.ts","./src/lexicons/com/atproto/sync/subscribeRepos.ts","./src/runner/consecutive-list.ts","./src/runner/index.ts","./src/runner/memory-runner.ts","./src/runner/types.ts"],"version":"5.8.2"}
1
+ {"root":["./src/events.ts","./src/index.ts","./src/util.ts","./src/firehose/index.ts","./src/lexicons/com.ts","./src/lexicons/index.ts","./src/lexicons/com/atproto.ts","./src/lexicons/com/atproto/sync.ts","./src/lexicons/com/atproto/sync/subscriberepos.defs.ts","./src/lexicons/com/atproto/sync/subscriberepos.ts","./src/runner/consecutive-list.ts","./src/runner/index.ts","./src/runner/memory-runner.ts","./src/runner/types.ts"],"version":"6.0.3"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig/tests.json",
3
3
  "compilerOptions": {
4
- "rootDir": "./tests",
4
+ "rootDir": ".",
5
5
  "noUnusedLocals": false
6
6
  },
7
7
  "include": ["./tests"]