@atproto/repo 0.3.9 → 0.4.1

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 (110) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/block-map.d.ts +1 -0
  3. package/dist/block-map.d.ts.map +1 -0
  4. package/dist/block-map.js +119 -0
  5. package/dist/block-map.js.map +1 -0
  6. package/dist/cid-set.d.ts +1 -0
  7. package/dist/cid-set.d.ts.map +1 -0
  8. package/dist/cid-set.js +48 -0
  9. package/dist/cid-set.js.map +1 -0
  10. package/dist/data-diff.d.ts +1 -0
  11. package/dist/data-diff.d.ts.map +1 -0
  12. package/dist/data-diff.js +134 -0
  13. package/dist/data-diff.js.map +1 -0
  14. package/dist/error.d.ts +1 -0
  15. package/dist/error.d.ts.map +1 -0
  16. package/dist/error.js +76 -0
  17. package/dist/error.js.map +1 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +26 -27225
  21. package/dist/index.js.map +1 -7
  22. package/dist/logger.d.ts +1 -0
  23. package/dist/logger.d.ts.map +1 -0
  24. package/dist/logger.js +7 -0
  25. package/dist/logger.js.map +1 -0
  26. package/dist/mst/diff.d.ts +1 -0
  27. package/dist/mst/diff.d.ts.map +1 -0
  28. package/dist/mst/diff.js +120 -0
  29. package/dist/mst/diff.js.map +1 -0
  30. package/dist/mst/index.d.ts +1 -0
  31. package/dist/mst/index.d.ts.map +1 -0
  32. package/dist/mst/index.js +34 -0
  33. package/dist/mst/index.js.map +1 -0
  34. package/dist/mst/mst.d.ts +6 -5
  35. package/dist/mst/mst.d.ts.map +1 -0
  36. package/dist/mst/mst.js +770 -0
  37. package/dist/mst/mst.js.map +1 -0
  38. package/dist/mst/util.d.ts +1 -0
  39. package/dist/mst/util.d.ts.map +1 -0
  40. package/dist/mst/util.js +167 -0
  41. package/dist/mst/util.js.map +1 -0
  42. package/dist/mst/walker.d.ts +1 -0
  43. package/dist/mst/walker.d.ts.map +1 -0
  44. package/dist/mst/walker.js +123 -0
  45. package/dist/mst/walker.js.map +1 -0
  46. package/dist/parse.d.ts +1 -0
  47. package/dist/parse.d.ts.map +1 -0
  48. package/dist/parse.js +35 -0
  49. package/dist/parse.js.map +1 -0
  50. package/dist/readable-repo.d.ts +1 -0
  51. package/dist/readable-repo.d.ts.map +1 -0
  52. package/dist/readable-repo.js +117 -0
  53. package/dist/readable-repo.js.map +1 -0
  54. package/dist/repo.d.ts +1 -0
  55. package/dist/repo.d.ts.map +1 -0
  56. package/dist/repo.js +190 -0
  57. package/dist/repo.js.map +1 -0
  58. package/dist/storage/index.d.ts +1 -0
  59. package/dist/storage/index.d.ts.map +1 -0
  60. package/dist/storage/index.js +21 -0
  61. package/dist/storage/index.js.map +1 -0
  62. package/dist/storage/memory-blockstore.d.ts +1 -0
  63. package/dist/storage/memory-blockstore.d.ts.map +1 -0
  64. package/dist/storage/memory-blockstore.js +80 -0
  65. package/dist/storage/memory-blockstore.js.map +1 -0
  66. package/dist/storage/readable-blockstore.d.ts +1 -0
  67. package/dist/storage/readable-blockstore.d.ts.map +1 -0
  68. package/dist/storage/readable-blockstore.js +66 -0
  69. package/dist/storage/readable-blockstore.js.map +1 -0
  70. package/dist/storage/sync-storage.d.ts +1 -0
  71. package/dist/storage/sync-storage.d.ts.map +1 -0
  72. package/dist/storage/sync-storage.js +46 -0
  73. package/dist/storage/sync-storage.js.map +1 -0
  74. package/dist/storage/types.d.ts +1 -0
  75. package/dist/storage/types.d.ts.map +1 -0
  76. package/dist/storage/types.js +7 -0
  77. package/dist/storage/types.js.map +1 -0
  78. package/dist/sync/consumer.d.ts +1 -0
  79. package/dist/sync/consumer.d.ts.map +1 -0
  80. package/dist/sync/consumer.js +178 -0
  81. package/dist/sync/consumer.js.map +1 -0
  82. package/dist/sync/index.d.ts +1 -0
  83. package/dist/sync/index.d.ts.map +1 -0
  84. package/dist/sync/index.js +19 -0
  85. package/dist/sync/index.js.map +1 -0
  86. package/dist/sync/provider.d.ts +1 -0
  87. package/dist/sync/provider.d.ts.map +1 -0
  88. package/dist/sync/provider.js +67 -0
  89. package/dist/sync/provider.js.map +1 -0
  90. package/dist/types.d.ts +22 -19
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +62 -0
  93. package/dist/types.js.map +1 -0
  94. package/dist/util.d.ts +2 -1
  95. package/dist/util.d.ts.map +1 -0
  96. package/dist/util.js +219 -0
  97. package/dist/util.js.map +1 -0
  98. package/jest.config.js +3 -3
  99. package/package.json +12 -15
  100. package/src/error.ts +16 -4
  101. package/src/mst/mst.ts +5 -2
  102. package/src/types.ts +4 -2
  103. package/src/util.ts +1 -1
  104. package/tests/_util.ts +4 -0
  105. package/tsconfig.build.json +6 -2
  106. package/tsconfig.json +3 -11
  107. package/tsconfig.tests.json +7 -0
  108. package/babel.config.js +0 -1
  109. package/build.js +0 -14
  110. package/jest.bench.config.js +0 -8
package/dist/util.js ADDED
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ensureV3Commit = exports.cidForRecord = exports.cborToLexRecord = exports.cborToLex = exports.verifyCommitSig = exports.signCommit = exports.metaEqual = exports.formatDataKey = exports.parseDataKey = exports.ensureCreates = exports.diffToWriteDescripts = exports.readCarWithRoot = exports.readCarStream = exports.readCar = exports.carToBlocks = exports.blocksToCarFile = exports.blocksToCarStream = exports.writeCar = exports.writeCarStream = exports.verifyIncomingCarBlocks = void 0;
30
+ const promises_1 = require("node:timers/promises");
31
+ const cbor = __importStar(require("@ipld/dag-cbor"));
32
+ const iterator_1 = require("@ipld/car/iterator");
33
+ const writer_1 = require("@ipld/car/writer");
34
+ const common_1 = require("@atproto/common");
35
+ const lexicon_1 = require("@atproto/lexicon");
36
+ const crypto = __importStar(require("@atproto/crypto"));
37
+ const types_1 = require("./types");
38
+ const block_map_1 = __importDefault(require("./block-map"));
39
+ async function* verifyIncomingCarBlocks(car) {
40
+ for await (const block of car) {
41
+ await (0, common_1.verifyCidForBytes)(block.cid, block.bytes);
42
+ yield block;
43
+ }
44
+ }
45
+ exports.verifyIncomingCarBlocks = verifyIncomingCarBlocks;
46
+ // we have to turn the car writer output into a stream in order to properly handle errors
47
+ function writeCarStream(root, fn) {
48
+ const { writer, out } = root !== null ? writer_1.CarWriter.create(root) : writer_1.CarWriter.create();
49
+ const stream = (0, common_1.byteIterableToStream)(out);
50
+ fn(writer)
51
+ .catch((err) => {
52
+ stream.destroy(err);
53
+ })
54
+ .finally(() => writer.close());
55
+ return stream;
56
+ }
57
+ exports.writeCarStream = writeCarStream;
58
+ async function* writeCar(root, fn) {
59
+ const stream = writeCarStream(root, fn);
60
+ for await (const chunk of stream) {
61
+ yield chunk;
62
+ }
63
+ }
64
+ exports.writeCar = writeCar;
65
+ const blocksToCarStream = (root, blocks) => {
66
+ return writeCar(root, async (writer) => {
67
+ for (const entry of blocks.entries()) {
68
+ await writer.put(entry);
69
+ }
70
+ });
71
+ };
72
+ exports.blocksToCarStream = blocksToCarStream;
73
+ const blocksToCarFile = (root, blocks) => {
74
+ const carStream = (0, exports.blocksToCarStream)(root, blocks);
75
+ return (0, common_1.streamToBuffer)(carStream);
76
+ };
77
+ exports.blocksToCarFile = blocksToCarFile;
78
+ const carToBlocks = async (car) => {
79
+ const roots = await car.getRoots();
80
+ const blocks = new block_map_1.default();
81
+ for await (const block of verifyIncomingCarBlocks(car)) {
82
+ blocks.set(block.cid, block.bytes);
83
+ // break up otherwise "synchronous" work in car parsing
84
+ await (0, promises_1.setImmediate)();
85
+ }
86
+ return {
87
+ roots,
88
+ blocks,
89
+ };
90
+ };
91
+ exports.carToBlocks = carToBlocks;
92
+ const readCar = async (bytes) => {
93
+ const car = await iterator_1.CarBlockIterator.fromBytes(bytes);
94
+ return (0, exports.carToBlocks)(car);
95
+ };
96
+ exports.readCar = readCar;
97
+ const readCarStream = async (stream) => {
98
+ const car = await iterator_1.CarBlockIterator.fromIterable(stream);
99
+ return (0, exports.carToBlocks)(car);
100
+ };
101
+ exports.readCarStream = readCarStream;
102
+ const readCarWithRoot = async (bytes) => {
103
+ const { roots, blocks } = await (0, exports.readCar)(bytes);
104
+ if (roots.length !== 1) {
105
+ throw new Error(`Expected one root, got ${roots.length}`);
106
+ }
107
+ const root = roots[0];
108
+ return {
109
+ root,
110
+ blocks,
111
+ };
112
+ };
113
+ exports.readCarWithRoot = readCarWithRoot;
114
+ const diffToWriteDescripts = (diff) => {
115
+ return Promise.all([
116
+ ...diff.addList().map(async (add) => {
117
+ const { collection, rkey } = (0, exports.parseDataKey)(add.key);
118
+ return {
119
+ action: types_1.WriteOpAction.Create,
120
+ collection,
121
+ rkey,
122
+ cid: add.cid,
123
+ };
124
+ }),
125
+ ...diff.updateList().map(async (upd) => {
126
+ const { collection, rkey } = (0, exports.parseDataKey)(upd.key);
127
+ return {
128
+ action: types_1.WriteOpAction.Update,
129
+ collection,
130
+ rkey,
131
+ cid: upd.cid,
132
+ prev: upd.prev,
133
+ };
134
+ }),
135
+ ...diff.deleteList().map((del) => {
136
+ const { collection, rkey } = (0, exports.parseDataKey)(del.key);
137
+ return {
138
+ action: types_1.WriteOpAction.Delete,
139
+ collection,
140
+ rkey,
141
+ cid: del.cid,
142
+ };
143
+ }),
144
+ ]);
145
+ };
146
+ exports.diffToWriteDescripts = diffToWriteDescripts;
147
+ const ensureCreates = (descripts) => {
148
+ const creates = [];
149
+ for (const descript of descripts) {
150
+ if (descript.action !== types_1.WriteOpAction.Create) {
151
+ throw new Error(`Unexpected action: ${descript.action}`);
152
+ }
153
+ else {
154
+ creates.push(descript);
155
+ }
156
+ }
157
+ return creates;
158
+ };
159
+ exports.ensureCreates = ensureCreates;
160
+ const parseDataKey = (key) => {
161
+ const parts = key.split('/');
162
+ if (parts.length !== 2)
163
+ throw new Error(`Invalid record key: ${key}`);
164
+ return { collection: parts[0], rkey: parts[1] };
165
+ };
166
+ exports.parseDataKey = parseDataKey;
167
+ const formatDataKey = (collection, rkey) => {
168
+ return collection + '/' + rkey;
169
+ };
170
+ exports.formatDataKey = formatDataKey;
171
+ const metaEqual = (a, b) => {
172
+ return a.did === b.did && a.version === b.version;
173
+ };
174
+ exports.metaEqual = metaEqual;
175
+ const signCommit = async (unsigned, keypair) => {
176
+ const encoded = cbor.encode(unsigned);
177
+ const sig = await keypair.sign(encoded);
178
+ return {
179
+ ...unsigned,
180
+ sig,
181
+ };
182
+ };
183
+ exports.signCommit = signCommit;
184
+ const verifyCommitSig = async (commit, didKey) => {
185
+ const { sig, ...rest } = commit;
186
+ const encoded = cbor.encode(rest);
187
+ return crypto.verifySignature(didKey, encoded, sig);
188
+ };
189
+ exports.verifyCommitSig = verifyCommitSig;
190
+ const cborToLex = (val) => {
191
+ return (0, lexicon_1.ipldToLex)((0, common_1.cborDecode)(val));
192
+ };
193
+ exports.cborToLex = cborToLex;
194
+ const cborToLexRecord = (val) => {
195
+ const parsed = (0, exports.cborToLex)(val);
196
+ if (!common_1.check.is(parsed, common_1.schema.map)) {
197
+ throw new Error('lexicon records be a json object');
198
+ }
199
+ return parsed;
200
+ };
201
+ exports.cborToLexRecord = cborToLexRecord;
202
+ const cidForRecord = async (val) => {
203
+ return (0, common_1.cidForCbor)((0, lexicon_1.lexToIpld)(val));
204
+ };
205
+ exports.cidForRecord = cidForRecord;
206
+ const ensureV3Commit = (commit) => {
207
+ if (commit.version === 3) {
208
+ return commit;
209
+ }
210
+ else {
211
+ return {
212
+ ...commit,
213
+ version: 3,
214
+ rev: commit.rev ?? common_1.TID.nextStr(),
215
+ };
216
+ }
217
+ };
218
+ exports.ensureV3Commit = ensureV3Commit;
219
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAmD;AAEnD,qDAAsC;AACtC,iDAAqD;AACrD,6CAAyD;AACzD,4CASwB;AACxB,8CAA6E;AAE7E,wDAAyC;AAEzC,mCAWgB;AAChB,4DAAkC;AAI3B,KAAK,SAAS,CAAC,CAAC,uBAAuB,CAC5C,GAA4B;IAE5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QAC9B,MAAM,IAAA,0BAAiB,EAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QAC/C,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAPD,0DAOC;AAED,yFAAyF;AACzF,SAAgB,cAAc,CAC5B,IAAgB,EAChB,EAAuC;IAEvC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GACnB,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,M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AAc,GAAG,CAAC,MAA+B,EAAU,EAAE;IACxE,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,MAAM,CAAA;IACf,CAAC;SAAM,CAAC;QACN,OAAO;YACL,GAAG,MAAM;YACT,OAAO,EAAE,CAAC;YACV,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,YAAG,CAAC,OAAO,EAAE;SACjC,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AAVY,QAAA,cAAc,kBAU1B"}
package/jest.config.js CHANGED
@@ -1,6 +1,6 @@
1
- const base = require('../../jest.config.base.js')
2
-
1
+ /** @type {import('jest').Config} */
3
2
  module.exports = {
4
- ...base,
5
3
  displayName: 'Repo',
4
+ transform: { '^.+\\.(t|j)s$': '@swc/jest' },
5
+ setupFiles: ['<rootDir>/../../jest.setup.ts'],
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/repo",
3
- "version": "0.3.9",
3
+ "version": "0.4.1",
4
4
  "license": "MIT",
5
5
  "description": "atproto repo and MST implementation",
6
6
  "keywords": [
@@ -14,27 +14,24 @@
14
14
  "directory": "packages/repo"
15
15
  },
16
16
  "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
17
18
  "dependencies": {
18
19
  "@ipld/car": "^3.2.3",
19
20
  "@ipld/dag-cbor": "^7.0.0",
20
21
  "multiformats": "^9.9.0",
21
22
  "uint8arrays": "3.0.0",
22
- "zod": "^3.21.4",
23
- "@atproto/common": "^0.3.4",
24
- "@atproto/common-web": "^0.2.4",
25
- "@atproto/crypto": "^0.3.0",
26
- "@atproto/identity": "^0.3.3",
27
- "@atproto/lexicon": "^0.3.3",
28
- "@atproto/syntax": "^0.2.1"
23
+ "zod": "^3.23.8",
24
+ "@atproto/common": "^0.4.1",
25
+ "@atproto/common-web": "^0.3.0",
26
+ "@atproto/crypto": "^0.4.0",
27
+ "@atproto/lexicon": "^0.4.0"
28
+ },
29
+ "devDependencies": {
30
+ "jest": "^28.1.2"
29
31
  },
30
32
  "scripts": {
31
33
  "test": "jest",
32
34
  "test:profile": "node --inspect ../../node_modules/.bin/jest",
33
- "bench": "jest --config jest.bench.config.js",
34
- "bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js",
35
- "build": "node ./build.js",
36
- "postbuild": "tsc --build tsconfig.build.json",
37
- "update-main-to-dist": "node ../../update-main-to-dist.js packages/repo"
38
- },
39
- "types": "dist/index.d.ts"
35
+ "build": "tsc --build tsconfig.build.json"
36
+ }
40
37
  }
package/src/error.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { CID } from 'multiformats/cid'
2
2
 
3
3
  export class MissingBlockError extends Error {
4
- constructor(public cid: CID, def?: string) {
4
+ constructor(
5
+ public cid: CID,
6
+ def?: string,
7
+ ) {
5
8
  let msg = `block not found: ${cid.toString()}`
6
9
  if (def) {
7
10
  msg += `, expected type: ${def}`
@@ -11,21 +14,30 @@ export class MissingBlockError extends Error {
11
14
  }
12
15
 
13
16
  export class MissingBlocksError extends Error {
14
- constructor(public context: string, public cids: CID[]) {
17
+ constructor(
18
+ public context: string,
19
+ public cids: CID[],
20
+ ) {
15
21
  const cidStr = cids.map((c) => c.toString())
16
22
  super(`missing ${context} blocks: ${cidStr}`)
17
23
  }
18
24
  }
19
25
 
20
26
  export class MissingCommitBlocksError extends Error {
21
- constructor(public commit: CID, public cids: CID[]) {
27
+ constructor(
28
+ public commit: CID,
29
+ public cids: CID[],
30
+ ) {
22
31
  const cidStr = cids.map((c) => c.toString())
23
32
  super(`missing blocks for commit ${commit.toString()}: ${cidStr}`)
24
33
  }
25
34
  }
26
35
 
27
36
  export class UnexpectedObjectError extends Error {
28
- constructor(public cid: CID, public def: string) {
37
+ constructor(
38
+ public cid: CID,
39
+ public def: string,
40
+ ) {
29
41
  super(`unexpected object at ${cid.toString()}, expected: ${def}`)
30
42
  }
31
43
  }
package/src/mst/mst.ts CHANGED
@@ -3,7 +3,7 @@ import { CID } from 'multiformats'
3
3
 
4
4
  import { ReadableBlockstore } from '../storage'
5
5
  import { schema as common, cidForCbor, dataToCborBlock } from '@atproto/common'
6
- import { BlockWriter } from '@ipld/car/api'
6
+ import { BlockWriter } from '@ipld/car/writer'
7
7
  import * as util from './util'
8
8
  import BlockMap from '../block-map'
9
9
  import CidSet from '../cid-set'
@@ -776,7 +776,10 @@ export class MST {
776
776
  }
777
777
 
778
778
  export class Leaf {
779
- constructor(public key: string, public value: CID) {}
779
+ constructor(
780
+ public key: string,
781
+ public value: CID,
782
+ ) {}
780
783
 
781
784
  isTree(): this is MST {
782
785
  return false
package/src/types.ts CHANGED
@@ -2,7 +2,6 @@ import { z } from 'zod'
2
2
  import { def as commonDef } from '@atproto/common-web'
3
3
  import { schema as common } from '@atproto/common'
4
4
  import { CID } from 'multiformats'
5
- import * as car from '@ipld/car/api'
6
5
  import BlockMap from './block-map'
7
6
  import { RepoRecord } from '@atproto/lexicon'
8
7
  import CidSet from './cid-set'
@@ -174,4 +173,7 @@ export type VerifiedRepo = {
174
173
  commit: CommitData
175
174
  }
176
175
 
177
- export type CarBlock = car.Block
176
+ export type CarBlock = {
177
+ cid: CID
178
+ bytes: Uint8Array
179
+ }
package/src/util.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { setImmediate } from 'node:timers/promises'
2
2
  import { CID } from 'multiformats/cid'
3
3
  import * as cbor from '@ipld/dag-cbor'
4
- import { CarBlockIterator } from '@ipld/car'
4
+ import { CarBlockIterator } from '@ipld/car/iterator'
5
5
  import { BlockWriter, CarWriter } from '@ipld/car/writer'
6
6
  import {
7
7
  streamToBuffer,
package/tests/_util.ts CHANGED
@@ -24,6 +24,7 @@ type IdMapping = Record<string, CID>
24
24
  export const randomCid = async (storage?: RepoStorage): Promise<CID> => {
25
25
  const block = await dataToCborBlock({ test: randomStr(50) })
26
26
  if (storage) {
27
+ // @ts-expect-error FIXME remove this comment (and fix the TS error)
27
28
  await storage.putBlock(block.cid, block.bytes)
28
29
  }
29
30
  return block.cid
@@ -189,6 +190,7 @@ export const pathsForOps = (ops: RecordWriteOp[]): RecordPath[] =>
189
190
 
190
191
  export const saveMst = async (storage: RepoStorage, mst: MST): Promise<CID> => {
191
192
  const diff = await mst.getUnstoredBlocks()
193
+ // @ts-expect-error FIXME remove this comment (and fix the TS error)
192
194
  await storage.putMany(diff.blocks)
193
195
  return diff.root
194
196
  }
@@ -215,6 +217,8 @@ export const addBadCommit = async (
215
217
  sig: await keypair.sign(randomBytes(256)),
216
218
  }
217
219
  const commitCid = await newBlocks.add(commit)
220
+
221
+ // @ts-expect-error FIXME remove this comment (and fix the TS error)
218
222
  await repo.storage.applyCommit({
219
223
  cid: commitCid,
220
224
  rev,
@@ -1,4 +1,8 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["**/*.spec.ts", "**/*.test.ts"]
2
+ "extends": "../../tsconfig/node.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "include": ["./src"]
4
8
  }
package/tsconfig.json CHANGED
@@ -1,15 +1,7 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist", // Your outDir,
6
- "emitDeclarationOnly": true
7
- },
8
- "include": ["./src", "__tests__/**/**.ts"],
2
+ "include": [],
9
3
  "references": [
10
- { "path": "../common/tsconfig.build.json" },
11
- { "path": "../crypto/tsconfig.build.json" },
12
- { "path": "../identity/tsconfig.build.json" },
13
- { "path": "../nsid/tsconfig.build.json" }
4
+ { "path": "./tsconfig.build.json" },
5
+ { "path": "./tsconfig.tests.json" }
14
6
  ]
15
7
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig/tests.json",
3
+ "compilerOptions": {
4
+ "rootDir": "."
5
+ },
6
+ "include": ["./tests"]
7
+ }
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('../../babel.config.js')
package/build.js DELETED
@@ -1,14 +0,0 @@
1
- const { nodeExternalsPlugin } = require('esbuild-node-externals')
2
-
3
- const buildShallow =
4
- process.argv.includes('--shallow') || process.env.ATP_BUILD_SHALLOW === 'true'
5
-
6
- require('esbuild').build({
7
- logLevel: 'info',
8
- entryPoints: ['src/index.ts'],
9
- bundle: true,
10
- sourcemap: true,
11
- outdir: 'dist',
12
- platform: 'node',
13
- plugins: buildShallow ? [nodeExternalsPlugin()] : [],
14
- })
@@ -1,8 +0,0 @@
1
- const base = require('./jest.config')
2
-
3
- module.exports = {
4
- ...base,
5
- roots: ['<rootDir>/bench'],
6
- testRegex: '(.*.bench)',
7
- testTimeout: 3000000,
8
- }