@atproto/repo 0.9.1 → 0.10.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 (127) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/block-map.js +10 -19
  3. package/dist/block-map.js.map +1 -1
  4. package/dist/car.d.ts +2 -2
  5. package/dist/car.d.ts.map +1 -1
  6. package/dist/car.js +30 -104
  7. package/dist/car.js.map +1 -1
  8. package/dist/cid-set.js +4 -14
  9. package/dist/cid-set.js.map +1 -1
  10. package/dist/data-diff.d.ts +3 -3
  11. package/dist/data-diff.d.ts.map +1 -1
  12. package/dist/data-diff.js +11 -45
  13. package/dist/data-diff.js.map +1 -1
  14. package/dist/error.js +11 -53
  15. package/dist/error.js.map +1 -1
  16. package/dist/index.d.ts +11 -11
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +11 -27
  19. package/dist/index.js.map +1 -1
  20. package/dist/logger.js +3 -6
  21. package/dist/logger.js.map +1 -1
  22. package/dist/mst/diff.d.ts +2 -2
  23. package/dist/mst/diff.d.ts.map +1 -1
  24. package/dist/mst/diff.js +9 -14
  25. package/dist/mst/diff.js.map +1 -1
  26. package/dist/mst/index.d.ts +4 -4
  27. package/dist/mst/index.d.ts.map +1 -1
  28. package/dist/mst/index.js +4 -43
  29. package/dist/mst/index.js.map +1 -1
  30. package/dist/mst/mst.d.ts +14 -14
  31. package/dist/mst/mst.d.ts.map +1 -1
  32. package/dist/mst/mst.js +41 -118
  33. package/dist/mst/mst.js.map +1 -1
  34. package/dist/mst/util.d.ts +2 -2
  35. package/dist/mst/util.d.ts.map +1 -1
  36. package/dist/mst/util.js +29 -47
  37. package/dist/mst/util.js.map +1 -1
  38. package/dist/mst/walker.d.ts +1 -1
  39. package/dist/mst/walker.d.ts.map +1 -1
  40. package/dist/mst/walker.js +3 -23
  41. package/dist/mst/walker.js.map +1 -1
  42. package/dist/parse.d.ts +1 -1
  43. package/dist/parse.d.ts.map +1 -1
  44. package/dist/parse.js +12 -18
  45. package/dist/parse.js.map +1 -1
  46. package/dist/readable-repo.d.ts +3 -3
  47. package/dist/readable-repo.d.ts.map +1 -1
  48. package/dist/readable-repo.js +13 -77
  49. package/dist/readable-repo.js.map +1 -1
  50. package/dist/repo.d.ts +6 -6
  51. package/dist/repo.d.ts.map +1 -1
  52. package/dist/repo.js +31 -77
  53. package/dist/repo.js.map +1 -1
  54. package/dist/storage/index.d.ts +4 -4
  55. package/dist/storage/index.d.ts.map +1 -1
  56. package/dist/storage/index.js +4 -20
  57. package/dist/storage/index.js.map +1 -1
  58. package/dist/storage/memory-blockstore.d.ts +4 -4
  59. package/dist/storage/memory-blockstore.d.ts.map +1 -1
  60. package/dist/storage/memory-blockstore.js +7 -27
  61. package/dist/storage/memory-blockstore.js.map +1 -1
  62. package/dist/storage/readable-blockstore.d.ts +1 -1
  63. package/dist/storage/readable-blockstore.d.ts.map +1 -1
  64. package/dist/storage/readable-blockstore.js +9 -13
  65. package/dist/storage/readable-blockstore.js.map +1 -1
  66. package/dist/storage/sync-storage.d.ts +2 -2
  67. package/dist/storage/sync-storage.d.ts.map +1 -1
  68. package/dist/storage/sync-storage.js +5 -19
  69. package/dist/storage/sync-storage.js.map +1 -1
  70. package/dist/storage/types.d.ts +2 -2
  71. package/dist/storage/types.d.ts.map +1 -1
  72. package/dist/storage/types.js +1 -5
  73. package/dist/storage/types.js.map +1 -1
  74. package/dist/sync/consumer.d.ts +3 -3
  75. package/dist/sync/consumer.d.ts.map +1 -1
  76. package/dist/sync/consumer.js +32 -75
  77. package/dist/sync/consumer.js.map +1 -1
  78. package/dist/sync/index.d.ts +2 -2
  79. package/dist/sync/index.d.ts.map +1 -1
  80. package/dist/sync/index.js +2 -18
  81. package/dist/sync/index.js.map +1 -1
  82. package/dist/sync/provider.d.ts +2 -2
  83. package/dist/sync/provider.d.ts.map +1 -1
  84. package/dist/sync/provider.js +17 -55
  85. package/dist/sync/provider.js.map +1 -1
  86. package/dist/types.d.ts +39 -39
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/types.js +41 -44
  89. package/dist/types.js.map +1 -1
  90. package/dist/util.d.ts +2 -2
  91. package/dist/util.d.ts.map +1 -1
  92. package/dist/util.js +28 -75
  93. package/dist/util.js.map +1 -1
  94. package/jest.config.cjs +24 -0
  95. package/package.json +19 -14
  96. package/src/car.ts +5 -4
  97. package/src/data-diff.ts +3 -3
  98. package/src/index.ts +11 -11
  99. package/src/mst/diff.ts +3 -3
  100. package/src/mst/index.ts +4 -4
  101. package/src/mst/mst.ts +7 -7
  102. package/src/mst/util.ts +3 -3
  103. package/src/mst/walker.ts +1 -1
  104. package/src/parse.ts +3 -3
  105. package/src/readable-repo.ts +7 -7
  106. package/src/repo.ts +9 -9
  107. package/src/storage/index.ts +4 -4
  108. package/src/storage/memory-blockstore.ts +4 -4
  109. package/src/storage/readable-blockstore.ts +4 -4
  110. package/src/storage/sync-storage.ts +2 -2
  111. package/src/storage/types.ts +2 -2
  112. package/src/sync/consumer.ts +12 -8
  113. package/src/sync/index.ts +2 -2
  114. package/src/sync/provider.ts +7 -7
  115. package/src/types.ts +7 -7
  116. package/src/util.ts +2 -2
  117. package/tests/_util.ts +4 -4
  118. package/tests/car.test.ts +2 -2
  119. package/tests/commit-data.test.ts +7 -2
  120. package/tests/commit-proofs.test.ts +4 -4
  121. package/tests/covering-proofs.test.ts +4 -4
  122. package/tests/mst.test.ts +5 -5
  123. package/tests/proofs.test.ts +4 -4
  124. package/tests/repo.test.ts +4 -4
  125. package/tests/sync.test.ts +4 -4
  126. package/tsconfig.build.tsbuildinfo +1 -1
  127. package/jest.config.js +0 -7
package/dist/util.js CHANGED
@@ -1,61 +1,23 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ensureV3Commit = exports.cidForRecord = exports.cborToLexRecord = exports.cborToLex = exports.verifyCommitSig = exports.signCommit = exports.metaEqual = exports.formatDataKey = exports.parseDataKey = exports.ensureCreates = exports.diffToWriteDescripts = void 0;
37
- exports.concatBytesAsync = concatBytesAsync;
38
- exports.concatBytes = concatBytes;
39
- const common_web_1 = require("@atproto/common-web");
40
- const crypto = __importStar(require("@atproto/crypto"));
41
- const cbor = __importStar(require("@atproto/lex-cbor"));
42
- const lex_data_1 = require("@atproto/lex-data");
43
- const types_1 = require("./types");
44
- const diffToWriteDescripts = (diff) => {
1
+ import { TID } from '@atproto/common-web';
2
+ import * as crypto from '@atproto/crypto';
3
+ import * as cbor from '@atproto/lex-cbor';
4
+ import { isPlainObject } from '@atproto/lex-data';
5
+ import { WriteOpAction, } from './types.js';
6
+ export const diffToWriteDescripts = (diff) => {
45
7
  return Promise.all([
46
8
  ...diff.addList().map(async (add) => {
47
- const { collection, rkey } = (0, exports.parseDataKey)(add.key);
9
+ const { collection, rkey } = parseDataKey(add.key);
48
10
  return {
49
- action: types_1.WriteOpAction.Create,
11
+ action: WriteOpAction.Create,
50
12
  collection,
51
13
  rkey,
52
14
  cid: add.cid,
53
15
  };
54
16
  }),
55
17
  ...diff.updateList().map(async (upd) => {
56
- const { collection, rkey } = (0, exports.parseDataKey)(upd.key);
18
+ const { collection, rkey } = parseDataKey(upd.key);
57
19
  return {
58
- action: types_1.WriteOpAction.Update,
20
+ action: WriteOpAction.Update,
59
21
  collection,
60
22
  rkey,
61
23
  cid: upd.cid,
@@ -63,9 +25,9 @@ const diffToWriteDescripts = (diff) => {
63
25
  };
64
26
  }),
65
27
  ...diff.deleteList().map((del) => {
66
- const { collection, rkey } = (0, exports.parseDataKey)(del.key);
28
+ const { collection, rkey } = parseDataKey(del.key);
67
29
  return {
68
- action: types_1.WriteOpAction.Delete,
30
+ action: WriteOpAction.Delete,
69
31
  collection,
70
32
  rkey,
71
33
  cid: del.cid,
@@ -73,11 +35,10 @@ const diffToWriteDescripts = (diff) => {
73
35
  }),
74
36
  ]);
75
37
  };
76
- exports.diffToWriteDescripts = diffToWriteDescripts;
77
- const ensureCreates = (descripts) => {
38
+ export const ensureCreates = (descripts) => {
78
39
  const creates = [];
79
40
  for (const descript of descripts) {
80
- if (descript.action !== types_1.WriteOpAction.Create) {
41
+ if (descript.action !== WriteOpAction.Create) {
81
42
  throw new Error(`Unexpected action: ${descript.action}`);
82
43
  }
83
44
  else {
@@ -86,23 +47,19 @@ const ensureCreates = (descripts) => {
86
47
  }
87
48
  return creates;
88
49
  };
89
- exports.ensureCreates = ensureCreates;
90
- const parseDataKey = (key) => {
50
+ export const parseDataKey = (key) => {
91
51
  const { length, 0: collection, 1: rkey } = key.split('/');
92
52
  if (length !== 2)
93
53
  throw new Error(`Invalid record key: ${key}`);
94
54
  return { collection, rkey };
95
55
  };
96
- exports.parseDataKey = parseDataKey;
97
- const formatDataKey = (collection, rkey) => {
56
+ export const formatDataKey = (collection, rkey) => {
98
57
  return collection + '/' + rkey;
99
58
  };
100
- exports.formatDataKey = formatDataKey;
101
- const metaEqual = (a, b) => {
59
+ export const metaEqual = (a, b) => {
102
60
  return a.did === b.did && a.version === b.version;
103
61
  };
104
- exports.metaEqual = metaEqual;
105
- const signCommit = async (unsigned, keypair) => {
62
+ export const signCommit = async (unsigned, keypair) => {
106
63
  const encoded = cbor.encode(unsigned);
107
64
  const sig = await keypair.sign(encoded);
108
65
  return {
@@ -110,24 +67,21 @@ const signCommit = async (unsigned, keypair) => {
110
67
  sig,
111
68
  };
112
69
  };
113
- exports.signCommit = signCommit;
114
- const verifyCommitSig = async (commit, didKey) => {
70
+ export const verifyCommitSig = async (commit, didKey) => {
115
71
  const { sig, ...rest } = commit;
116
72
  const encoded = cbor.encode(rest);
117
73
  return crypto.verifySignature(didKey, encoded, sig);
118
74
  };
119
- exports.verifyCommitSig = verifyCommitSig;
120
- exports.cborToLex = cbor.decode;
121
- const cborToLexRecord = (val) => {
122
- const parsed = (0, exports.cborToLex)(val);
123
- if (!(0, lex_data_1.isPlainObject)(parsed)) {
75
+ export const cborToLex = cbor.decode;
76
+ export const cborToLexRecord = (val) => {
77
+ const parsed = cborToLex(val);
78
+ if (!isPlainObject(parsed)) {
124
79
  throw new Error('lexicon records be a json object');
125
80
  }
126
81
  return parsed;
127
82
  };
128
- exports.cborToLexRecord = cborToLexRecord;
129
- exports.cidForRecord = cbor.cidForLex;
130
- const ensureV3Commit = (commit) => {
83
+ export const cidForRecord = cbor.cidForLex;
84
+ export const ensureV3Commit = (commit) => {
131
85
  if (commit.version === 3) {
132
86
  return commit;
133
87
  }
@@ -135,12 +89,11 @@ const ensureV3Commit = (commit) => {
135
89
  return {
136
90
  ...commit,
137
91
  version: 3,
138
- rev: commit.rev ?? common_web_1.TID.nextStr(),
92
+ rev: commit.rev ?? TID.nextStr(),
139
93
  };
140
94
  }
141
95
  };
142
- exports.ensureV3Commit = ensureV3Commit;
143
- async function concatBytesAsync(iterable) {
96
+ export async function concatBytesAsync(iterable) {
144
97
  const chunks = [];
145
98
  for await (const chunk of iterable)
146
99
  chunks.push(chunk);
@@ -149,7 +102,7 @@ async function concatBytesAsync(iterable) {
149
102
  /**
150
103
  * This is the same as {@link Buffer.concat}, without the `totalLength` argument.
151
104
  */
152
- function concatBytes(chunks) {
105
+ export function concatBytes(chunks) {
153
106
  let totalLength = 0;
154
107
  for (const chunk of chunks)
155
108
  totalLength += chunk.byteLength;
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8HA,4CAIC;AAKD,kCAUC;AAjJD,oDAAyC;AACzC,wDAAyC;AAEzC,wDAAyC;AACzC,gDAAwE;AAExE,mCAUgB;AAET,MAAM,oBAAoB,GAAG,CAClC,IAAc,EACkB,EAAE;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC;QACjB,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAClC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAY,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAClD,OAAO;gBACL,MAAM,EAAE,qBAAa,CAAC,MAAM;gBAC5B,UAAU;gBACV,IAAI;gBACJ,GAAG,EAAE,GAAG,CAAC,GAAG;aACW,CAAA;QAC3B,CAAC,CAAC;QACF,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACrC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAY,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAClD,OAAO;gBACL,MAAM,EAAE,qBAAa,CAAC,MAAM;gBAC5B,UAAU;gBACV,IAAI;gBACJ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AC","sourcesContent":["import { TID } from '@atproto/common-web'\nimport * as crypto from '@atproto/crypto'\nimport { Keypair } from '@atproto/crypto'\nimport * as cbor from '@atproto/lex-cbor'\nimport { Cid, LexMap, LexValue, isPlainObject } from '@atproto/lex-data'\nimport { DataDiff } from './data-diff'\nimport {\n Commit,\n LegacyV2Commit,\n RecordCreateDescript,\n RecordDeleteDescript,\n RecordPath,\n RecordUpdateDescript,\n RecordWriteDescript,\n UnsignedCommit,\n WriteOpAction,\n} from './types'\n\nexport const diffToWriteDescripts = (\n diff: DataDiff,\n): Promise<RecordWriteDescript[]> => {\n return Promise.all([\n ...diff.addList().map(async (add) => {\n const { collection, rkey } = parseDataKey(add.key)\n return {\n action: WriteOpAction.Create,\n collection,\n rkey,\n cid: add.cid,\n } as RecordCreateDescript\n }),\n ...diff.updateList().map(async (upd) => {\n const { collection, rkey } = parseDataKey(upd.key)\n return {\n action: WriteOpAction.Update,\n collection,\n rkey,\n cid: upd.cid,\n prev: upd.prev,\n } as RecordUpdateDescript\n }),\n ...diff.deleteList().map((del) => {\n const { collection, rkey } = parseDataKey(del.key)\n return {\n action: WriteOpAction.Delete,\n collection,\n rkey,\n cid: del.cid,\n } as RecordDeleteDescript\n }),\n ])\n}\n\nexport const ensureCreates = (\n descripts: RecordWriteDescript[],\n): RecordCreateDescript[] => {\n const creates: RecordCreateDescript[] = []\n for (const descript of descripts) {\n if (descript.action !== WriteOpAction.Create) {\n throw new Error(`Unexpected action: ${descript.action}`)\n } else {\n creates.push(descript)\n }\n }\n return creates\n}\n\nexport const parseDataKey = (key: string): RecordPath => {\n const { length, 0: collection, 1: rkey } = key.split('/')\n if (length !== 2) throw new Error(`Invalid record key: ${key}`)\n return { collection, rkey }\n}\n\nexport const formatDataKey = (collection: string, rkey: string): string => {\n return collection + '/' + rkey\n}\n\nexport const metaEqual = (a: Commit, b: Commit): boolean => {\n return a.did === b.did && a.version === b.version\n}\n\nexport const signCommit = async (\n unsigned: UnsignedCommit,\n keypair: Keypair,\n): Promise<Commit> => {\n const encoded = cbor.encode(unsigned)\n const sig = await keypair.sign(encoded)\n return {\n ...unsigned,\n sig,\n }\n}\n\nexport const verifyCommitSig = async (\n commit: Commit,\n didKey: string,\n): Promise<boolean> => {\n const { sig, ...rest } = commit\n const encoded = cbor.encode(rest)\n return crypto.verifySignature(didKey, encoded, sig)\n}\n\nexport const cborToLex: (val: Uint8Array) => LexValue = cbor.decode\n\nexport const cborToLexRecord = (val: Uint8Array): LexMap => {\n const parsed = cborToLex(val)\n if (!isPlainObject(parsed)) {\n throw new Error('lexicon records be a json object')\n }\n return parsed\n}\n\nexport const cidForRecord: (val: LexValue) => Promise<Cid> = cbor.cidForLex\n\nexport const ensureV3Commit = (commit: LegacyV2Commit | Commit): Commit => {\n if (commit.version === 3) {\n return commit\n } else {\n return {\n ...commit,\n version: 3,\n rev: commit.rev ?? TID.nextStr(),\n }\n }\n}\n\nexport async function concatBytesAsync(iterable: AsyncIterable<Uint8Array>) {\n const chunks: Uint8Array[] = []\n for await (const chunk of iterable) chunks.push(chunk)\n return concatBytes(chunks)\n}\n\n/**\n * This is the same as {@link Buffer.concat}, without the `totalLength` argument.\n */\nexport function concatBytes(chunks: readonly Uint8Array[]): Uint8Array {\n let totalLength = 0\n for (const chunk of chunks) totalLength += chunk.byteLength\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const chunk of chunks) {\n result.set(chunk, offset)\n offset += chunk.byteLength\n }\n return result\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AAEzC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAyB,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAExE,OAAO,EASL,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,MAAM,CAAC,MAAM,oBA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,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAA6B;IACvD,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,WAAW,IAAI,KAAK,CAAC,UAAU,CAAA;IAC3D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAC1C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QACzB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAA;IAC5B,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { TID } from '@atproto/common-web'\nimport * as crypto from '@atproto/crypto'\nimport { Keypair } from '@atproto/crypto'\nimport * as cbor from '@atproto/lex-cbor'\nimport { Cid, LexMap, LexValue, isPlainObject } from '@atproto/lex-data'\nimport { DataDiff } from './data-diff.js'\nimport {\n Commit,\n LegacyV2Commit,\n RecordCreateDescript,\n RecordDeleteDescript,\n RecordPath,\n RecordUpdateDescript,\n RecordWriteDescript,\n UnsignedCommit,\n WriteOpAction,\n} from './types.js'\n\nexport const diffToWriteDescripts = (\n diff: DataDiff,\n): Promise<RecordWriteDescript[]> => {\n return Promise.all([\n ...diff.addList().map(async (add) => {\n const { collection, rkey } = parseDataKey(add.key)\n return {\n action: WriteOpAction.Create,\n collection,\n rkey,\n cid: add.cid,\n } as RecordCreateDescript\n }),\n ...diff.updateList().map(async (upd) => {\n const { collection, rkey } = parseDataKey(upd.key)\n return {\n action: WriteOpAction.Update,\n collection,\n rkey,\n cid: upd.cid,\n prev: upd.prev,\n } as RecordUpdateDescript\n }),\n ...diff.deleteList().map((del) => {\n const { collection, rkey } = parseDataKey(del.key)\n return {\n action: WriteOpAction.Delete,\n collection,\n rkey,\n cid: del.cid,\n } as RecordDeleteDescript\n }),\n ])\n}\n\nexport const ensureCreates = (\n descripts: RecordWriteDescript[],\n): RecordCreateDescript[] => {\n const creates: RecordCreateDescript[] = []\n for (const descript of descripts) {\n if (descript.action !== WriteOpAction.Create) {\n throw new Error(`Unexpected action: ${descript.action}`)\n } else {\n creates.push(descript)\n }\n }\n return creates\n}\n\nexport const parseDataKey = (key: string): RecordPath => {\n const { length, 0: collection, 1: rkey } = key.split('/')\n if (length !== 2) throw new Error(`Invalid record key: ${key}`)\n return { collection, rkey }\n}\n\nexport const formatDataKey = (collection: string, rkey: string): string => {\n return collection + '/' + rkey\n}\n\nexport const metaEqual = (a: Commit, b: Commit): boolean => {\n return a.did === b.did && a.version === b.version\n}\n\nexport const signCommit = async (\n unsigned: UnsignedCommit,\n keypair: Keypair,\n): Promise<Commit> => {\n const encoded = cbor.encode(unsigned)\n const sig = await keypair.sign(encoded)\n return {\n ...unsigned,\n sig,\n }\n}\n\nexport const verifyCommitSig = async (\n commit: Commit,\n didKey: string,\n): Promise<boolean> => {\n const { sig, ...rest } = commit\n const encoded = cbor.encode(rest)\n return crypto.verifySignature(didKey, encoded, sig)\n}\n\nexport const cborToLex: (val: Uint8Array) => LexValue = cbor.decode\n\nexport const cborToLexRecord = (val: Uint8Array): LexMap => {\n const parsed = cborToLex(val)\n if (!isPlainObject(parsed)) {\n throw new Error('lexicon records be a json object')\n }\n return parsed\n}\n\nexport const cidForRecord: (val: LexValue) => Promise<Cid> = cbor.cidForLex\n\nexport const ensureV3Commit = (commit: LegacyV2Commit | Commit): Commit => {\n if (commit.version === 3) {\n return commit\n } else {\n return {\n ...commit,\n version: 3,\n rev: commit.rev ?? TID.nextStr(),\n }\n }\n}\n\nexport async function concatBytesAsync(iterable: AsyncIterable<Uint8Array>) {\n const chunks: Uint8Array[] = []\n for await (const chunk of iterable) chunks.push(chunk)\n return concatBytes(chunks)\n}\n\n/**\n * This is the same as {@link Buffer.concat}, without the `totalLength` argument.\n */\nexport function concatBytes(chunks: readonly Uint8Array[]): Uint8Array {\n let totalLength = 0\n for (const chunk of chunks) totalLength += chunk.byteLength\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const chunk of chunks) {\n result.set(chunk, offset)\n offset += chunk.byteLength\n }\n return result\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /** @type {import('jest').Config} */
2
+ module.exports = {
3
+ displayName: 'Repo',
4
+ transform: {
5
+ '^.+\\.(t|j)s$': [
6
+ '@swc/jest',
7
+ {
8
+ jsc: {
9
+ parser: { syntax: 'typescript', importAttributes: true },
10
+ experimental: { keepImportAttributes: true },
11
+ transform: {},
12
+ },
13
+ module: { type: 'es6' },
14
+ },
15
+ ],
16
+ },
17
+ extensionsToTreatAsEsm: ['.ts'],
18
+ transformIgnorePatterns: [],
19
+ setupFiles: ['<rootDir>/../../test.setup.ts'],
20
+ moduleNameMapper: {
21
+ '^varint$': '<rootDir>/../../jest.varint-shim.cjs',
22
+ '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'],
23
+ },
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/repo",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "description": "atproto repo and MST implementation",
6
6
  "keywords": [
@@ -8,7 +8,7 @@
8
8
  "mst"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=18.7.0"
11
+ "node": ">=22"
12
12
  },
13
13
  "homepage": "https://atproto.com",
14
14
  "repository": {
@@ -16,25 +16,30 @@
16
16
  "url": "https://github.com/bluesky-social/atproto",
17
17
  "directory": "packages/repo"
18
18
  },
19
- "main": "dist/index.js",
20
- "types": "dist/index.d.ts",
21
19
  "dependencies": {
22
20
  "varint": "^6.0.0",
23
21
  "zod": "^3.23.8",
24
- "@atproto/common": "^0.5.16",
25
- "@atproto/common-web": "^0.4.20",
26
- "@atproto/crypto": "^0.4.5",
27
- "@atproto/lex-cbor": "^0.0.16",
28
- "@atproto/lex-data": "^0.0.15",
29
- "@atproto/syntax": "^0.5.3"
22
+ "@atproto/common": "^0.6.0",
23
+ "@atproto/common-web": "^0.5.0",
24
+ "@atproto/crypto": "^0.5.0",
25
+ "@atproto/lex-cbor": "^0.1.0",
26
+ "@atproto/lex-data": "^0.1.0",
27
+ "@atproto/syntax": "^0.6.0"
30
28
  },
31
29
  "devDependencies": {
32
- "jest": "^28.1.2",
33
- "typescript": "^5.6.3"
30
+ "jest": "^30.0.0",
31
+ "typescript": "^6.0.3"
32
+ },
33
+ "type": "module",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ }
34
39
  },
35
40
  "scripts": {
36
- "test": "jest",
37
- "test:profile": "node --inspect ../../node_modules/.bin/jest",
41
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
42
+ "test:profile": "node --experimental-vm-modules --inspect ../../node_modules/.bin/jest",
38
43
  "build": "tsc --build tsconfig.build.json"
39
44
  }
40
45
  }
package/src/car.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { setImmediate } from 'node:timers/promises'
2
- import * as varint from 'varint'
2
+ // eslint-disable-next-line import/default, import/no-named-as-default-member
3
+ import varint from 'varint'
3
4
  import * as cbor from '@atproto/lex-cbor'
4
5
  import { Cid, decodeCid, isCidForBytes } from '@atproto/lex-data'
5
- import { BlockMap } from './block-map'
6
- import { CarBlock, schema } from './types'
7
- import { concatBytesAsync } from './util'
6
+ import { BlockMap } from './block-map.js'
7
+ import { CarBlock, schema } from './types.js'
8
+ import { concatBytesAsync } from './util.js'
8
9
 
9
10
  export async function* writeCarStream(
10
11
  root: Cid | null,
package/src/data-diff.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Cid } from '@atproto/lex-data'
2
- import { BlockMap } from './block-map'
3
- import { CidSet } from './cid-set'
4
- import { MST, NodeEntry, mstDiff } from './mst'
2
+ import { BlockMap } from './block-map.js'
3
+ import { CidSet } from './cid-set.js'
4
+ import { MST, NodeEntry, mstDiff } from './mst/index.js'
5
5
 
6
6
  export class DataDiff {
7
7
  adds: Record<string, DataAdd> = {}
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './block-map'
2
- export * from './cid-set'
3
- export * from './repo'
4
- export * from './mst'
5
- export * from './parse'
6
- export * from './storage'
7
- export * from './sync'
8
- export * from './types'
9
- export * from './data-diff'
10
- export * from './car'
11
- export * from './util'
1
+ export * from './block-map.js'
2
+ export * from './cid-set.js'
3
+ export * from './repo.js'
4
+ export * from './mst/index.js'
5
+ export * from './parse.js'
6
+ export * from './storage/index.js'
7
+ export * from './sync/index.js'
8
+ export * from './types.js'
9
+ export * from './data-diff.js'
10
+ export * from './car.js'
11
+ export * from './util.js'
package/src/mst/diff.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { DataDiff } from '../data-diff'
2
- import { MST } from './mst'
3
- import { MstWalker } from './walker'
1
+ import { DataDiff } from '../data-diff.js'
2
+ import { MST } from './mst.js'
3
+ import { MstWalker } from './walker.js'
4
4
 
5
5
  export const nullDiff = async (tree: MST): Promise<DataDiff> => {
6
6
  const diff = new DataDiff()
package/src/mst/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './mst'
2
- export * from './diff'
3
- export * from './walker'
4
- export * as mstUtil from './util'
1
+ export * from './mst.js'
2
+ export * from './diff.js'
3
+ export * from './walker.js'
4
+ export * as mstUtil from './util.js'
package/src/mst/mst.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { z } from 'zod'
2
2
  import { cidForLex, encode } from '@atproto/lex-cbor'
3
3
  import { Cid, cidForCbor } from '@atproto/lex-data'
4
- import { BlockMap } from '../block-map'
5
- import { CidSet } from '../cid-set'
6
- import { MissingBlockError, MissingBlocksError } from '../error'
7
- import * as parse from '../parse'
8
- import { ReadableBlockstore } from '../storage'
9
- import { CarBlock, schema } from '../types'
10
- import * as util from './util'
4
+ import { BlockMap } from '../block-map.js'
5
+ import { CidSet } from '../cid-set.js'
6
+ import { MissingBlockError, MissingBlocksError } from '../error.js'
7
+ import * as parse from '../parse.js'
8
+ import { ReadableBlockstore } from '../storage/index.js'
9
+ import { CarBlock, schema } from '../types.js'
10
+ import * as util from './util.js'
11
11
 
12
12
  /**
13
13
  * This is an implementation of a Merkle Search Tree (MST)
package/src/mst/util.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { sha256 } from '@atproto/crypto'
2
2
  import { cidForLex } from '@atproto/lex-cbor'
3
3
  import { Cid } from '@atproto/lex-data'
4
- import { ReadableBlockstore } from '../storage'
5
- import { Leaf, MST, MstOpts, NodeData, NodeEntry } from './mst'
4
+ import { ReadableBlockstore } from '../storage/index.js'
5
+ import { Leaf, MST, MstOpts, NodeData, NodeEntry } from './mst.js'
6
6
 
7
7
  function toAscii(bytes: Uint8Array): string {
8
8
  let string = ''
@@ -12,7 +12,7 @@ function toAscii(bytes: Uint8Array): string {
12
12
  return string
13
13
  }
14
14
 
15
- function fromAscii(str: string): Uint8Array {
15
+ function fromAscii(str: string): Uint8Array<ArrayBuffer> {
16
16
  const bytes = new Uint8Array(str.length)
17
17
  for (let i = 0; i < str.length; i++) {
18
18
  bytes[i] = str.charCodeAt(i)
package/src/mst/walker.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MST, NodeEntry } from './mst'
1
+ import { MST, NodeEntry } from './mst.js'
2
2
 
3
3
  type WalkerStatusDone = {
4
4
  done: true
package/src/parse.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { check } from '@atproto/common-web'
2
2
  import { decode } from '@atproto/lex-cbor'
3
3
  import { Cid, LexMap } from '@atproto/lex-data'
4
- import { BlockMap } from './block-map'
5
- import { MissingBlockError, UnexpectedObjectError } from './error'
6
- import { cborToLexRecord } from './util'
4
+ import { BlockMap } from './block-map.js'
5
+ import { MissingBlockError, UnexpectedObjectError } from './error.js'
6
+ import { cborToLexRecord } from './util.js'
7
7
 
8
8
  export const getAndParseRecord = async (
9
9
  blocks: BlockMap,
@@ -1,11 +1,11 @@
1
1
  import { Cid, LexMap } from '@atproto/lex-data'
2
- import { MissingBlocksError } from './error'
3
- import log from './logger'
4
- import { MST } from './mst'
5
- import * as parse from './parse'
6
- import { ReadableBlockstore } from './storage'
7
- import { Commit, RepoContents, def } from './types'
8
- import * as util from './util'
2
+ import { MissingBlocksError } from './error.js'
3
+ import log from './logger.js'
4
+ import { MST } from './mst/index.js'
5
+ import * as parse from './parse.js'
6
+ import { ReadableBlockstore } from './storage/index.js'
7
+ import { Commit, RepoContents, def } from './types.js'
8
+ import * as util from './util.js'
9
9
 
10
10
  type Params = {
11
11
  storage: ReadableBlockstore
package/src/repo.ts CHANGED
@@ -2,13 +2,13 @@ import { TID } from '@atproto/common-web'
2
2
  import * as crypto from '@atproto/crypto'
3
3
  import { encode } from '@atproto/lex-cbor'
4
4
  import { Cid, cidForCbor } from '@atproto/lex-data'
5
- import { BlockMap } from './block-map'
6
- import { CidSet } from './cid-set'
7
- import { DataDiff } from './data-diff'
8
- import log from './logger'
9
- import { MST } from './mst'
10
- import { ReadableRepo } from './readable-repo'
11
- import { RepoStorage } from './storage'
5
+ import { BlockMap } from './block-map.js'
6
+ import { CidSet } from './cid-set.js'
7
+ import { DataDiff } from './data-diff.js'
8
+ import log from './logger.js'
9
+ import { MST } from './mst/index.js'
10
+ import { ReadableRepo } from './readable-repo.js'
11
+ import { RepoStorage } from './storage/index.js'
12
12
  import {
13
13
  Commit,
14
14
  CommitData,
@@ -16,8 +16,8 @@ import {
16
16
  RecordWriteOp,
17
17
  WriteOpAction,
18
18
  def,
19
- } from './types'
20
- import * as util from './util'
19
+ } from './types.js'
20
+ import * as util from './util.js'
21
21
 
22
22
  type Params = {
23
23
  storage: RepoStorage
@@ -1,4 +1,4 @@
1
- export * from './readable-blockstore'
2
- export * from './memory-blockstore'
3
- export * from './sync-storage'
4
- export * from './types'
1
+ export * from './readable-blockstore.js'
2
+ export * from './memory-blockstore.js'
3
+ export * from './sync-storage.js'
4
+ export * from './types.js'
@@ -1,8 +1,8 @@
1
1
  import { Cid } from '@atproto/lex-data'
2
- import { BlockMap } from '../block-map'
3
- import { CommitData } from '../types'
4
- import { ReadableBlockstore } from './readable-blockstore'
5
- import { RepoStorage } from './types'
2
+ import { BlockMap } from '../block-map.js'
3
+ import { CommitData } from '../types.js'
4
+ import { ReadableBlockstore } from './readable-blockstore.js'
5
+ import { RepoStorage } from './types.js'
6
6
 
7
7
  export class MemoryBlockstore
8
8
  extends ReadableBlockstore
@@ -1,9 +1,9 @@
1
1
  import { check } from '@atproto/common-web'
2
2
  import { Cid, LexMap } from '@atproto/lex-data'
3
- import { BlockMap } from '../block-map'
4
- import { MissingBlockError } from '../error'
5
- import { parseObjByDef } from '../parse'
6
- import { cborToLexRecord } from '../util'
3
+ import { BlockMap } from '../block-map.js'
4
+ import { MissingBlockError } from '../error.js'
5
+ import { parseObjByDef } from '../parse.js'
6
+ import { cborToLexRecord } from '../util.js'
7
7
 
8
8
  export abstract class ReadableBlockstore {
9
9
  abstract getBytes(cid: Cid): Promise<Uint8Array | null>
@@ -1,6 +1,6 @@
1
1
  import { Cid } from '@atproto/lex-data'
2
- import { BlockMap } from '../block-map'
3
- import { ReadableBlockstore } from './readable-blockstore'
2
+ import { BlockMap } from '../block-map.js'
3
+ import { ReadableBlockstore } from './readable-blockstore.js'
4
4
 
5
5
  export class SyncStorage extends ReadableBlockstore {
6
6
  constructor(
@@ -1,8 +1,8 @@
1
1
  import type { Readable } from 'node:stream'
2
2
  import { check } from '@atproto/common-web'
3
3
  import { Cid, LexMap } from '@atproto/lex-data'
4
- import { BlockMap } from '../block-map'
5
- import { CommitData } from '../types'
4
+ import { BlockMap } from '../block-map.js'
5
+ import { CommitData } from '../types.js'
6
6
 
7
7
  export interface RepoStorage {
8
8
  // Writable
@@ -1,18 +1,22 @@
1
1
  import { Cid } from '@atproto/lex-data'
2
- import { BlockMap } from '../block-map'
3
- import { readCarWithRoot } from '../car'
4
- import { DataDiff } from '../data-diff'
5
- import { MST } from '../mst'
6
- import { ReadableRepo } from '../readable-repo'
7
- import { MemoryBlockstore, ReadableBlockstore, SyncStorage } from '../storage'
2
+ import { BlockMap } from '../block-map.js'
3
+ import { readCarWithRoot } from '../car.js'
4
+ import { DataDiff } from '../data-diff.js'
5
+ import { MST } from '../mst/index.js'
6
+ import { ReadableRepo } from '../readable-repo.js'
7
+ import {
8
+ MemoryBlockstore,
9
+ ReadableBlockstore,
10
+ SyncStorage,
11
+ } from '../storage/index.js'
8
12
  import {
9
13
  RecordCidClaim,
10
14
  RecordClaim,
11
15
  VerifiedDiff,
12
16
  VerifiedRepo,
13
17
  def,
14
- } from '../types'
15
- import * as util from '../util'
18
+ } from '../types.js'
19
+ import * as util from '../util.js'
16
20
 
17
21
  export const verifyRepoCar = async (
18
22
  carBytes: Uint8Array,
package/src/sync/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './consumer'
2
- export * from './provider'
1
+ export * from './consumer.js'
2
+ export * from './provider.js'
@@ -1,11 +1,11 @@
1
1
  import { Cid } from '@atproto/lex-data'
2
- import { writeCarStream } from '../car'
3
- import { CidSet } from '../cid-set'
4
- import { MissingBlocksError } from '../error'
5
- import { MST } from '../mst'
6
- import { ReadableBlockstore, RepoStorage } from '../storage'
7
- import { CarBlock, RecordPath, def } from '../types'
8
- import * as util from '../util'
2
+ import { writeCarStream } from '../car.js'
3
+ import { CidSet } from '../cid-set.js'
4
+ import { MissingBlocksError } from '../error.js'
5
+ import { MST } from '../mst/index.js'
6
+ import { ReadableBlockstore, RepoStorage } from '../storage/index.js'
7
+ import { CarBlock, RecordPath, def } from '../types.js'
8
+ import * as util from '../util.js'
9
9
 
10
10
  // Full Repo
11
11
  // -------------