@atproto/common 0.5.16 → 0.6.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.
- package/CHANGELOG.md +21 -0
- package/dist/buffers.d.ts +1 -1
- package/dist/buffers.d.ts.map +1 -1
- package/dist/buffers.js +2 -6
- package/dist/buffers.js.map +1 -1
- package/dist/dates.js +1 -4
- package/dist/dates.js.map +1 -1
- package/dist/env.js +6 -13
- package/dist/env.js.map +1 -1
- package/dist/fs.js +15 -25
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -26
- package/dist/index.js.map +1 -1
- package/dist/ipld-multi.js +3 -6
- package/dist/ipld-multi.js.map +1 -1
- package/dist/ipld.d.ts +2 -2
- package/dist/ipld.d.ts.map +1 -1
- package/dist/ipld.js +34 -60
- package/dist/ipld.js.map +1 -1
- package/dist/logger.js +4 -8
- package/dist/logger.js.map +1 -1
- package/dist/obfuscate.js +8 -18
- package/dist/obfuscate.js.map +1 -1
- package/dist/streams.js +25 -53
- package/dist/streams.js.map +1 -1
- package/jest.config.cjs +21 -0
- package/package.json +17 -12
- package/src/buffers.ts +1 -1
- package/src/index.ts +9 -9
- package/src/ipld.ts +5 -2
- package/tests/ipld-multi.test.ts +1 -1
- package/tests/ipld.test.ts +2 -2
- package/tests/streams.test.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/jest.config.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atproto/common
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`affb50c`](https://github.com/bluesky-social/atproto/commit/affb50c040b497a12631df99a6310f8e78cab557) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** `ui8ToArrayBuffer(bytes)` now requires `Uint8Array<ArrayBuffer>` (rather than `Uint8Array`, which defaults to `<ArrayBufferLike>`). Most callers can pass the value through unchanged; in the rare case of a `SharedArrayBuffer`-backed `Uint8Array`, copy into a regular `Uint8Array` first.
|
|
8
|
+
|
|
9
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
10
|
+
|
|
11
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
12
|
+
|
|
13
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
14
|
+
|
|
15
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c), [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9), [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705)]:
|
|
20
|
+
- @atproto/common-web@0.5.0
|
|
21
|
+
- @atproto/lex-cbor@0.1.0
|
|
22
|
+
- @atproto/lex-data@0.1.0
|
|
23
|
+
|
|
3
24
|
## 0.5.16
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/buffers.d.ts
CHANGED
package/dist/buffers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffers.d.ts","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAErD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"buffers.d.ts","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAErD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,WAAW,CAK5E"}
|
package/dist/buffers.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ui8ToBuffer = ui8ToBuffer;
|
|
4
|
-
exports.ui8ToArrayBuffer = ui8ToArrayBuffer;
|
|
5
|
-
function ui8ToBuffer(bytes) {
|
|
1
|
+
export function ui8ToBuffer(bytes) {
|
|
6
2
|
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
7
3
|
}
|
|
8
|
-
function ui8ToArrayBuffer(bytes) {
|
|
4
|
+
export function ui8ToArrayBuffer(bytes) {
|
|
9
5
|
return bytes.buffer.slice(bytes.byteOffset, bytes.byteLength + bytes.byteOffset);
|
|
10
6
|
}
|
|
11
7
|
//# sourceMappingURL=buffers.js.map
|
package/dist/buffers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffers.js","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffers.js","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA8B;IAC7D,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CACvB,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAA;AACH,CAAC","sourcesContent":["export function ui8ToBuffer(bytes: Uint8Array): Buffer {\n return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n}\n\nexport function ui8ToArrayBuffer(bytes: Uint8Array<ArrayBuffer>): ArrayBuffer {\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteLength + bytes.byteOffset,\n )\n}\n"]}
|
package/dist/dates.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toSimplifiedISOSafe = toSimplifiedISOSafe;
|
|
4
1
|
// Normalize date strings to simplified ISO so that the lexical sort preserves temporal sort.
|
|
5
2
|
// Rather than failing on an invalid date format, returns valid unix epoch.
|
|
6
|
-
function toSimplifiedISOSafe(dateStr) {
|
|
3
|
+
export function toSimplifiedISOSafe(dateStr) {
|
|
7
4
|
const date = new Date(dateStr);
|
|
8
5
|
if (isNaN(date.getTime())) {
|
|
9
6
|
return new Date(0).toISOString();
|
package/dist/dates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAE9B,kEAAkE;IAClE,gCAAgC;IAChC,sGAAsG;IACtG,6EAA6E;IAC7E,qDAAqD;IACrD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IAED,OAAO,GAAG,CAAA,CAAC,2BAA2B;AACxC,CAAC","sourcesContent":["// Normalize date strings to simplified ISO so that the lexical sort preserves temporal sort.\n// Rather than failing on an invalid date format, returns valid unix epoch.\nexport function toSimplifiedISOSafe(dateStr: string) {\n const date = new Date(dateStr)\n if (isNaN(date.getTime())) {\n return new Date(0).toISOString()\n }\n const iso = date.toISOString()\n\n // Date.toISOString() always returns `YYYY-MM-DDTHH:mm:ss.sssZ` or\n // `±YYYYYY-MM-DDTHH:mm:ss.sssZ`\n // (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)\n // However, the leading `±` and 6 digit year can break lexical sorting, so we\n // need to catch those cases and return a safe value.\n if (iso.startsWith('-') || iso.startsWith('+')) {\n return new Date(0).toISOString()\n }\n\n return iso // YYYY-MM-DDTHH:mm:ss.sssZ\n}\n"]}
|
package/dist/env.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.envList = exports.envBool = exports.envStr = exports.envInt = void 0;
|
|
4
|
-
const common_web_1 = require("@atproto/common-web");
|
|
5
|
-
const envInt = (name) => {
|
|
1
|
+
import { parseIntWithFallback } from '@atproto/common-web';
|
|
2
|
+
export const envInt = (name) => {
|
|
6
3
|
const str = process.env[name];
|
|
7
|
-
return
|
|
4
|
+
return parseIntWithFallback(str, undefined);
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
const envStr = (name) => {
|
|
6
|
+
export const envStr = (name) => {
|
|
11
7
|
const str = process.env[name];
|
|
12
8
|
if (str === undefined || str.length === 0)
|
|
13
9
|
return undefined;
|
|
14
10
|
return str;
|
|
15
11
|
};
|
|
16
|
-
|
|
17
|
-
const envBool = (name) => {
|
|
12
|
+
export const envBool = (name) => {
|
|
18
13
|
const str = process.env[name];
|
|
19
14
|
if (str === 'true' || str === '1')
|
|
20
15
|
return true;
|
|
@@ -22,12 +17,10 @@ const envBool = (name) => {
|
|
|
22
17
|
return false;
|
|
23
18
|
return undefined;
|
|
24
19
|
};
|
|
25
|
-
|
|
26
|
-
const envList = (name) => {
|
|
20
|
+
export const envList = (name) => {
|
|
27
21
|
const str = process.env[name];
|
|
28
22
|
if (str === undefined || str.length === 0)
|
|
29
23
|
return [];
|
|
30
24
|
return str.split(',');
|
|
31
25
|
};
|
|
32
|
-
exports.envList = envList;
|
|
33
26
|
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAsB,EAAE;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,OAAO,oBAAoB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAsB,EAAE;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAC3D,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAuB,EAAE;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IAChD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAY,EAAE;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACpD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC,CAAA","sourcesContent":["import { parseIntWithFallback } from '@atproto/common-web'\n\nexport const envInt = (name: string): number | undefined => {\n const str = process.env[name]\n return parseIntWithFallback(str, undefined)\n}\n\nexport const envStr = (name: string): string | undefined => {\n const str = process.env[name]\n if (str === undefined || str.length === 0) return undefined\n return str\n}\n\nexport const envBool = (name: string): boolean | undefined => {\n const str = process.env[name]\n if (str === 'true' || str === '1') return true\n if (str === 'false' || str === '0') return false\n return undefined\n}\n\nexport const envList = (name: string): string[] => {\n const str = process.env[name]\n if (str === undefined || str.length === 0) return []\n return str.split(',')\n}\n"]}
|
package/dist/fs.js
CHANGED
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renameIfExists = exports.rmIfExists = exports.readIfExists = exports.fileExists = void 0;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
-
const common_web_1 = require("@atproto/common-web");
|
|
10
|
-
const fileExists = async (location) => {
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { isErrnoException } from '@atproto/common-web';
|
|
4
|
+
export const fileExists = async (location) => {
|
|
11
5
|
try {
|
|
12
|
-
await
|
|
6
|
+
await fs.access(location, constants.F_OK);
|
|
13
7
|
return true;
|
|
14
8
|
}
|
|
15
9
|
catch (err) {
|
|
16
|
-
if (
|
|
10
|
+
if (isErrnoException(err) && err.code === 'ENOENT') {
|
|
17
11
|
return false;
|
|
18
12
|
}
|
|
19
13
|
throw err;
|
|
20
14
|
}
|
|
21
15
|
};
|
|
22
|
-
|
|
23
|
-
const readIfExists = async (filepath) => {
|
|
16
|
+
export const readIfExists = async (filepath) => {
|
|
24
17
|
try {
|
|
25
|
-
return await
|
|
18
|
+
return await fs.readFile(filepath);
|
|
26
19
|
}
|
|
27
20
|
catch (err) {
|
|
28
|
-
if (
|
|
21
|
+
if (isErrnoException(err) && err.code === 'ENOENT') {
|
|
29
22
|
return;
|
|
30
23
|
}
|
|
31
24
|
throw err;
|
|
32
25
|
}
|
|
33
26
|
};
|
|
34
|
-
|
|
35
|
-
const rmIfExists = async (filepath, recursive = false) => {
|
|
27
|
+
export const rmIfExists = async (filepath, recursive = false) => {
|
|
36
28
|
try {
|
|
37
|
-
await
|
|
29
|
+
await fs.rm(filepath, { recursive });
|
|
38
30
|
}
|
|
39
31
|
catch (err) {
|
|
40
|
-
if (
|
|
32
|
+
if (isErrnoException(err) && err.code === 'ENOENT') {
|
|
41
33
|
return;
|
|
42
34
|
}
|
|
43
35
|
throw err;
|
|
44
36
|
}
|
|
45
37
|
};
|
|
46
|
-
|
|
47
|
-
const renameIfExists = async (oldPath, newPath) => {
|
|
38
|
+
export const renameIfExists = async (oldPath, newPath) => {
|
|
48
39
|
try {
|
|
49
|
-
await
|
|
40
|
+
await fs.rename(oldPath, newPath);
|
|
50
41
|
}
|
|
51
42
|
catch (err) {
|
|
52
|
-
if (
|
|
43
|
+
if (isErrnoException(err) && err.code === 'ENOENT') {
|
|
53
44
|
return;
|
|
54
45
|
}
|
|
55
46
|
throw err;
|
|
56
47
|
}
|
|
57
48
|
};
|
|
58
|
-
exports.renameIfExists = renameIfExists;
|
|
59
49
|
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAoB,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,QAAgB,EACiB,EAAE;IACnC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACpC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAM;QACR,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,QAAgB,EAChB,SAAS,GAAG,KAAK,EACF,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAM;QACR,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,OAAe,EACf,OAAe,EACA,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAM;QACR,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { constants } from 'node:fs'\nimport fs from 'node:fs/promises'\nimport { isErrnoException } from '@atproto/common-web'\n\nexport const fileExists = async (location: string): Promise<boolean> => {\n try {\n await fs.access(location, constants.F_OK)\n return true\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return false\n }\n throw err\n }\n}\n\nexport const readIfExists = async (\n filepath: string,\n): Promise<Uint8Array | undefined> => {\n try {\n return await fs.readFile(filepath)\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n\nexport const rmIfExists = async (\n filepath: string,\n recursive = false,\n): Promise<void> => {\n try {\n await fs.rm(filepath, { recursive })\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n\nexport const renameIfExists = async (\n oldPath: string,\n newPath: string,\n): Promise<void> => {\n try {\n await fs.rename(oldPath, newPath)\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from '@atproto/common-web';
|
|
2
|
-
export * from './buffers';
|
|
3
|
-
export * from './dates';
|
|
4
|
-
export * from './env';
|
|
5
|
-
export * from './fs';
|
|
6
|
-
export * from './ipld';
|
|
7
|
-
export * from './ipld-multi';
|
|
8
|
-
export * from './logger';
|
|
9
|
-
export * from './obfuscate';
|
|
10
|
-
export * from './streams';
|
|
2
|
+
export * from './buffers.js';
|
|
3
|
+
export * from './dates.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './fs.js';
|
|
6
|
+
export * from './ipld.js';
|
|
7
|
+
export * from './ipld-multi.js';
|
|
8
|
+
export * from './logger.js';
|
|
9
|
+
export * from './obfuscate.js';
|
|
10
|
+
export * from './streams.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("@atproto/common-web"), exports);
|
|
18
|
-
__exportStar(require("./buffers"), exports);
|
|
19
|
-
__exportStar(require("./dates"), exports);
|
|
20
|
-
__exportStar(require("./env"), exports);
|
|
21
|
-
__exportStar(require("./fs"), exports);
|
|
22
|
-
__exportStar(require("./ipld"), exports);
|
|
23
|
-
__exportStar(require("./ipld-multi"), exports);
|
|
24
|
-
__exportStar(require("./logger"), exports);
|
|
25
|
-
__exportStar(require("./obfuscate"), exports);
|
|
26
|
-
__exportStar(require("./streams"), exports);
|
|
1
|
+
export * from '@atproto/common-web';
|
|
2
|
+
export * from './buffers.js';
|
|
3
|
+
export * from './dates.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './fs.js';
|
|
6
|
+
export * from './ipld.js';
|
|
7
|
+
export * from './ipld-multi.js';
|
|
8
|
+
export * from './logger.js';
|
|
9
|
+
export * from './obfuscate.js';
|
|
10
|
+
export * from './streams.js';
|
|
27
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA","sourcesContent":["export * from '@atproto/common-web'\nexport * from './buffers.js'\nexport * from './dates.js'\nexport * from './env.js'\nexport * from './fs.js'\nexport * from './ipld.js'\nexport * from './ipld-multi.js'\nexport * from './logger.js'\nexport * from './obfuscate.js'\nexport * from './streams.js'\n"]}
|
package/dist/ipld-multi.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cborDecodeMulti = cborDecodeMulti;
|
|
4
|
-
const lex_cbor_1 = require("@atproto/lex-cbor");
|
|
1
|
+
import { decodeAll } from '@atproto/lex-cbor';
|
|
5
2
|
/**
|
|
6
3
|
* @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.
|
|
7
4
|
*/
|
|
8
|
-
function cborDecodeMulti(encoded) {
|
|
9
|
-
return Array.from(
|
|
5
|
+
export function cborDecodeMulti(encoded) {
|
|
6
|
+
return Array.from(decodeAll(encoded));
|
|
10
7
|
}
|
|
11
8
|
//# sourceMappingURL=ipld-multi.js.map
|
package/dist/ipld-multi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipld-multi.js","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipld-multi.js","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG7C;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAmB;IACjD,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;AACvC,CAAC","sourcesContent":["import { decodeAll } from '@atproto/lex-cbor'\nimport { LexValue } from '@atproto/lex-data'\n\n/**\n * @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.\n */\nexport function cborDecodeMulti(encoded: Uint8Array): LexValue[] {\n return Array.from(decodeAll(encoded))\n}\n"]}
|
package/dist/ipld.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'node:stream';
|
|
2
|
-
import {
|
|
2
|
+
import type { BlockView, ByteView } from 'multiformats/block/interface';
|
|
3
3
|
import { type CID, Cid } from '@atproto/lex-data';
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
|
|
@@ -14,7 +14,7 @@ export { cborDecodeLegacy as cborDecode };
|
|
|
14
14
|
/**
|
|
15
15
|
* @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
|
|
16
16
|
*/
|
|
17
|
-
export declare function dataToCborBlock<T>(value: T): Promise<
|
|
17
|
+
export declare function dataToCborBlock<T>(value: T): Promise<BlockView<T, 0x71, 0x12, 1>>;
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
|
|
20
20
|
*/
|
package/dist/ipld.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipld.d.ts","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+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,CAIf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,GAAG,CAEpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAExD;AAED,qBAAa,kBAAmB,SAAQ,SAAS;IAC5B,GAAG,EAAE,GAAG;gBAAR,GAAG,EAAE,GAAG;CAqB5B;AAKD,qBAAa,cAAe,SAAQ,KAAK;IAE9B,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG;gBADX,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,GAAG;CAIrB"}
|
package/dist/ipld.js
CHANGED
|
@@ -1,89 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.cborBytesToRecord = cborBytesToRecord;
|
|
8
|
-
exports.verifyCidForBytes = verifyCidForBytes;
|
|
9
|
-
exports.sha256RawToCid = sha256RawToCid;
|
|
10
|
-
exports.parseCidFromBytes = parseCidFromBytes;
|
|
11
|
-
const node_crypto_1 = require("node:crypto");
|
|
12
|
-
const node_stream_1 = require("node:stream");
|
|
13
|
-
const block_1 = require("multiformats/block");
|
|
14
|
-
const sha2_1 = require("multiformats/hashes/sha2");
|
|
15
|
-
const lex_cbor_1 = require("@atproto/lex-cbor");
|
|
16
|
-
const lex_data_1 = require("@atproto/lex-data");
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { Transform } from 'node:stream';
|
|
3
|
+
import { encode as encodeBlock } from 'multiformats/block';
|
|
4
|
+
import { sha256 as hasher } from 'multiformats/hashes/sha2';
|
|
5
|
+
import { cidForLex, decode, encode } from '@atproto/lex-cbor';
|
|
6
|
+
import { CBOR_DATA_CODEC, asMultiformatsCID, cidForRawHash, decodeCid, isCidForBytes, isTypedLexMap, validateCidString, } from '@atproto/lex-data';
|
|
17
7
|
/**
|
|
18
8
|
* @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
|
|
19
9
|
*/
|
|
20
|
-
const cborEncodeLegacy =
|
|
21
|
-
|
|
10
|
+
const cborEncodeLegacy = encode;
|
|
11
|
+
export { cborEncodeLegacy as cborEncode };
|
|
22
12
|
/**
|
|
23
13
|
* @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.
|
|
24
14
|
*/
|
|
25
|
-
const cborDecodeLegacy =
|
|
26
|
-
|
|
15
|
+
const cborDecodeLegacy = decode;
|
|
16
|
+
export { cborDecodeLegacy as cborDecode };
|
|
27
17
|
/**
|
|
28
18
|
* @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
|
|
29
19
|
*/
|
|
30
|
-
async function dataToCborBlock(value) {
|
|
31
|
-
return (
|
|
20
|
+
export async function dataToCborBlock(value) {
|
|
21
|
+
return encodeBlock({
|
|
32
22
|
value,
|
|
33
23
|
codec: {
|
|
34
24
|
name: 'at-cbor', // Not actually used
|
|
35
|
-
code:
|
|
36
|
-
encode:
|
|
25
|
+
code: CBOR_DATA_CODEC,
|
|
26
|
+
encode: encode,
|
|
37
27
|
},
|
|
38
|
-
hasher
|
|
28
|
+
hasher,
|
|
39
29
|
});
|
|
40
30
|
}
|
|
41
31
|
/**
|
|
42
32
|
* @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
|
|
43
33
|
*/
|
|
44
34
|
async function cidForCborLegacy(data) {
|
|
45
|
-
return
|
|
35
|
+
return asMultiformatsCID(await cidForLex(data));
|
|
46
36
|
}
|
|
37
|
+
export { cidForCborLegacy as cidForCbor };
|
|
47
38
|
/**
|
|
48
39
|
* @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
|
|
49
40
|
*/
|
|
50
|
-
async function isValidCid(cidStr) {
|
|
41
|
+
export async function isValidCid(cidStr) {
|
|
51
42
|
// @NOTE we keep the wrapper function to return a Promise (for backward
|
|
52
43
|
// compatibility).
|
|
53
|
-
return
|
|
44
|
+
return validateCidString(cidStr);
|
|
54
45
|
}
|
|
55
46
|
/**
|
|
56
47
|
* @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.
|
|
57
48
|
*/
|
|
58
|
-
function cborBytesToRecord(bytes) {
|
|
59
|
-
const data =
|
|
60
|
-
if (
|
|
49
|
+
export function cborBytesToRecord(bytes) {
|
|
50
|
+
const data = decode(bytes);
|
|
51
|
+
if (isTypedLexMap(data))
|
|
61
52
|
return data;
|
|
62
53
|
throw new Error(`Expected record with $type property`);
|
|
63
54
|
}
|
|
64
55
|
/**
|
|
65
56
|
* @deprecated Use {@link isCidForBytes} from `@atproto/lex-cbor` instead.
|
|
66
57
|
*/
|
|
67
|
-
async function verifyCidForBytes(cid, bytes) {
|
|
68
|
-
if (!(await
|
|
58
|
+
export async function verifyCidForBytes(cid, bytes) {
|
|
59
|
+
if (!(await isCidForBytes(cid, bytes))) {
|
|
69
60
|
throw new Error(`Not a valid CID for bytes (${cid.toString()})`);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
/**
|
|
73
64
|
* @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
|
|
74
65
|
*/
|
|
75
|
-
function sha256RawToCid(hash) {
|
|
76
|
-
return
|
|
66
|
+
export function sha256RawToCid(hash) {
|
|
67
|
+
return asMultiformatsCID(cidForRawHash(hash));
|
|
77
68
|
}
|
|
78
69
|
/**
|
|
79
70
|
* @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.
|
|
80
71
|
*/
|
|
81
|
-
function parseCidFromBytes(bytes) {
|
|
82
|
-
return
|
|
72
|
+
export function parseCidFromBytes(bytes) {
|
|
73
|
+
return asMultiformatsCID(decodeCid(bytes, { flavor: 'dasl' }));
|
|
83
74
|
}
|
|
84
|
-
class VerifyCidTransform extends
|
|
75
|
+
export class VerifyCidTransform extends Transform {
|
|
85
76
|
constructor(cid) {
|
|
86
|
-
const hasher =
|
|
77
|
+
const hasher = createHash('sha256');
|
|
87
78
|
super({
|
|
88
79
|
transform(chunk, encoding, callback) {
|
|
89
80
|
hasher.update(chunk);
|
|
@@ -104,32 +95,15 @@ class VerifyCidTransform extends node_stream_1.Transform {
|
|
|
104
95
|
}
|
|
105
96
|
},
|
|
106
97
|
});
|
|
107
|
-
|
|
108
|
-
enumerable: true,
|
|
109
|
-
configurable: true,
|
|
110
|
-
writable: true,
|
|
111
|
-
value: cid
|
|
112
|
-
});
|
|
98
|
+
this.cid = cid;
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
|
-
exports.VerifyCidTransform = VerifyCidTransform;
|
|
116
101
|
const asError = (err) => err instanceof Error ? err : new Error('Unexpected error', { cause: err });
|
|
117
|
-
class VerifyCidError extends Error {
|
|
102
|
+
export class VerifyCidError extends Error {
|
|
118
103
|
constructor(expected, actual) {
|
|
119
104
|
super('Bad cid check');
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
configurable: true,
|
|
123
|
-
writable: true,
|
|
124
|
-
value: expected
|
|
125
|
-
});
|
|
126
|
-
Object.defineProperty(this, "actual", {
|
|
127
|
-
enumerable: true,
|
|
128
|
-
configurable: true,
|
|
129
|
-
writable: true,
|
|
130
|
-
value: actual
|
|
131
|
-
});
|
|
105
|
+
this.expected = expected;
|
|
106
|
+
this.actual = actual;
|
|
132
107
|
}
|
|
133
108
|
}
|
|
134
|
-
exports.VerifyCidError = VerifyCidError;
|
|
135
109
|
//# sourceMappingURL=ipld.js.map
|
package/dist/ipld.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MA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ClD,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QAnBe,QAAG,GAAH,GAAG,CAAK;IAoB3B,CAAC;CACF;AAED,MAAM,OAAO,GAAG,CAAC,GAAY,EAAS,EAAE,CACtC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;AAE5E,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YACS,QAAa,EACb,MAAW;QAElB,KAAK,CAAC,eAAe,CAAC,CAAA;QAHf,aAAQ,GAAR,QAAQ,CAAK;QACb,WAAM,GAAN,MAAM,CAAK;IAGpB,CAAC;CACF","sourcesContent":["import { createHash } from 'node:crypto'\nimport { Transform } from 'node:stream'\nimport { encode as encodeBlock } from 'multiformats/block'\nimport type { BlockView, ByteView } from 'multiformats/block/interface'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport { cidForLex, decode, encode } from '@atproto/lex-cbor'\nimport {\n CBOR_DATA_CODEC,\n type CID,\n Cid,\n LexValue,\n asMultiformatsCID,\n // eslint-disable-next-line\n cidForCbor,\n cidForRawHash,\n decodeCid,\n isCidForBytes,\n isTypedLexMap,\n validateCidString,\n} from '@atproto/lex-data'\n\n/**\n * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.\n */\nconst cborEncodeLegacy = encode as <T = unknown>(data: T) => ByteView<T>\nexport { cborEncodeLegacy as cborEncode }\n\n/**\n * @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.\n */\nconst cborDecodeLegacy = decode as <T = unknown>(bytes: ByteView<T>) => T\nexport { cborDecodeLegacy as cborDecode }\n\n/**\n * @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.\n */\nexport async function dataToCborBlock<T>(\n value: T,\n): Promise<BlockView<T, 0x71, 0x12, 1>> {\n return encodeBlock<T, 0x71, 0x12>({\n value,\n codec: {\n name: 'at-cbor', // Not actually used\n code: CBOR_DATA_CODEC,\n encode: encode as (data: T) => ByteView<T>,\n },\n hasher,\n })\n}\n\n/**\n * @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.\n */\nasync function cidForCborLegacy(data: unknown): Promise<CID> {\n return asMultiformatsCID(await cidForLex(data as LexValue))\n}\nexport { cidForCborLegacy as cidForCbor }\n\n/**\n * @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.\n */\nexport async function isValidCid(cidStr: string): Promise<boolean> {\n // @NOTE we keep the wrapper function to return a Promise (for backward\n // compatibility).\n return validateCidString(cidStr)\n}\n\n/**\n * @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.\n */\nexport function cborBytesToRecord(bytes: Uint8Array): Record<string, unknown> {\n const data = decode(bytes) as LexValue\n if (isTypedLexMap(data)) return data\n\n throw new Error(`Expected record with $type property`)\n}\n\n/**\n * @deprecated Use {@link isCidForBytes} from `@atproto/lex-cbor` instead.\n */\nexport async function verifyCidForBytes(\n cid: Cid,\n bytes: Uint8Array,\n): Promise<void> {\n if (!(await isCidForBytes(cid, bytes))) {\n throw new Error(`Not a valid CID for bytes (${cid.toString()})`)\n }\n}\n\n/**\n * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.\n */\nexport function sha256RawToCid(hash: Uint8Array): CID {\n return asMultiformatsCID(cidForRawHash(hash))\n}\n\n/**\n * @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.\n */\nexport function parseCidFromBytes(bytes: Uint8Array): CID {\n return asMultiformatsCID(decodeCid(bytes, { flavor: 'dasl' }))\n}\n\nexport class VerifyCidTransform extends Transform {\n constructor(public cid: Cid) {\n const hasher = createHash('sha256')\n super({\n transform(chunk, encoding, callback) {\n hasher.update(chunk)\n callback(null, chunk)\n },\n flush(callback) {\n try {\n const actual = sha256RawToCid(hasher.digest())\n if (actual.equals(cid)) {\n return callback()\n } else {\n return callback(new VerifyCidError(cid, actual))\n }\n } catch (err) {\n return callback(asError(err))\n }\n },\n })\n }\n}\n\nconst asError = (err: unknown): Error =>\n err instanceof Error ? err : new Error('Unexpected error', { cause: err })\n\nexport class VerifyCidError extends Error {\n constructor(\n public expected: Cid,\n public actual: Cid,\n ) {\n super('Bad cid check')\n }\n}\n"]}
|
package/dist/logger.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.subsystemLogger = void 0;
|
|
4
|
-
const pino_1 = require("pino");
|
|
1
|
+
import { destination, pino } from 'pino';
|
|
5
2
|
const allSystemsEnabled = !process.env.LOG_SYSTEMS;
|
|
6
3
|
const enabledSystems = (process.env.LOG_SYSTEMS || '')
|
|
7
4
|
.replace(',', ' ')
|
|
@@ -14,10 +11,10 @@ const config = {
|
|
|
14
11
|
level,
|
|
15
12
|
};
|
|
16
13
|
const rootLogger = process.env.LOG_DESTINATION
|
|
17
|
-
?
|
|
18
|
-
:
|
|
14
|
+
? pino(config, destination(process.env.LOG_DESTINATION))
|
|
15
|
+
: pino(config);
|
|
19
16
|
const subsystems = {};
|
|
20
|
-
const subsystemLogger = (name) => {
|
|
17
|
+
export const subsystemLogger = (name) => {
|
|
21
18
|
if (subsystems[name])
|
|
22
19
|
return subsystems[name];
|
|
23
20
|
const subsystemEnabled = enabled && (allSystemsEnabled || enabledSystems.indexOf(name) > -1);
|
|
@@ -25,5 +22,4 @@ const subsystemLogger = (name) => {
|
|
|
25
22
|
subsystems[name] = rootLogger.child({ name }, { level: subsystemEnabled ? level : 'silent' });
|
|
26
23
|
return subsystems[name];
|
|
27
24
|
};
|
|
28
|
-
exports.subsystemLogger = subsystemLogger;
|
|
29
25
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAExC,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAClD,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;KACnD,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC,CAAA;AAEb,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAC1C,MAAM,OAAO,GACX,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAA;AAEnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,CAAA;AAE7C,MAAM,MAAM,GAAG;IACb,OAAO;IACP,KAAK;CACN,CAAA;AAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe;IAC5C,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACxD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAEhB,MAAM,UAAU,GAAgC,EAAE,CAAA;AAElD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAe,EAAE;IAC3D,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,gBAAgB,GACpB,OAAO,IAAI,CAAC,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAErE,gGAAgG;IAChG,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CACjC,EAAE,IAAI,EAAE,EACR,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAC/C,CAAA;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import { destination, pino } from 'pino'\n\nconst allSystemsEnabled = !process.env.LOG_SYSTEMS\nconst enabledSystems = (process.env.LOG_SYSTEMS || '')\n .replace(',', ' ')\n .split(' ')\n\nconst enabledEnv = process.env.LOG_ENABLED\nconst enabled =\n enabledEnv === 'true' || enabledEnv === 't' || enabledEnv === '1'\n\nconst level = process.env.LOG_LEVEL || 'info'\n\nconst config = {\n enabled,\n level,\n}\n\nconst rootLogger = process.env.LOG_DESTINATION\n ? pino(config, destination(process.env.LOG_DESTINATION))\n : pino(config)\n\nconst subsystems: Record<string, pino.Logger> = {}\n\nexport const subsystemLogger = (name: string): pino.Logger => {\n if (subsystems[name]) return subsystems[name]\n const subsystemEnabled =\n enabled && (allSystemsEnabled || enabledSystems.indexOf(name) > -1)\n\n // can't disable child loggers, so we just set their level to fatal to effectively turn them off\n subsystems[name] = rootLogger.child(\n { name },\n { level: subsystemEnabled ? level : 'silent' },\n )\n return subsystems[name]\n}\n"]}
|
package/dist/obfuscate.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.obfuscateEmail = obfuscateEmail;
|
|
4
|
-
exports.obfuscateWord = obfuscateWord;
|
|
5
|
-
exports.obfuscateHeaders = obfuscateHeaders;
|
|
6
|
-
exports.obfuscateAuthHeader = obfuscateAuthHeader;
|
|
7
|
-
exports.obfuscateBasic = obfuscateBasic;
|
|
8
|
-
exports.obfuscateBearer = obfuscateBearer;
|
|
9
|
-
exports.obfuscateToken = obfuscateToken;
|
|
10
|
-
exports.obfuscateJwt = obfuscateJwt;
|
|
11
|
-
function obfuscateEmail(email) {
|
|
1
|
+
export function obfuscateEmail(email) {
|
|
12
2
|
const [local, domain] = email.split('@');
|
|
13
3
|
return `${obfuscateWord(local)}@${obfuscateWord(domain)}`;
|
|
14
4
|
}
|
|
15
|
-
function obfuscateWord(word) {
|
|
5
|
+
export function obfuscateWord(word) {
|
|
16
6
|
return `${word.charAt(0)}***${word.charAt(word.length - 1)}`;
|
|
17
7
|
}
|
|
18
|
-
function obfuscateHeaders(headers) {
|
|
8
|
+
export function obfuscateHeaders(headers) {
|
|
19
9
|
const obfuscatedHeaders = {};
|
|
20
10
|
for (const key in headers) {
|
|
21
11
|
if (key.toLowerCase() === 'authorization') {
|
|
@@ -30,7 +20,7 @@ function obfuscateHeaders(headers) {
|
|
|
30
20
|
}
|
|
31
21
|
return obfuscatedHeaders;
|
|
32
22
|
}
|
|
33
|
-
function obfuscateAuthHeader(authHeader) {
|
|
23
|
+
export function obfuscateAuthHeader(authHeader) {
|
|
34
24
|
// This is a hot path (runs on every request). Avoid using split() or regex.
|
|
35
25
|
const spaceIdx = authHeader.indexOf(' ');
|
|
36
26
|
if (spaceIdx === -1)
|
|
@@ -46,7 +36,7 @@ function obfuscateAuthHeader(authHeader) {
|
|
|
46
36
|
return `Invalid`;
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
|
-
function obfuscateBasic(token) {
|
|
39
|
+
export function obfuscateBasic(token) {
|
|
50
40
|
if (!token)
|
|
51
41
|
return null;
|
|
52
42
|
const buffer = Buffer.from(token, 'base64');
|
|
@@ -59,15 +49,15 @@ function obfuscateBasic(token) {
|
|
|
59
49
|
const username = authHeader.slice(0, colIdx);
|
|
60
50
|
return `${username}:***`;
|
|
61
51
|
}
|
|
62
|
-
function obfuscateBearer(token) {
|
|
52
|
+
export function obfuscateBearer(token) {
|
|
63
53
|
return obfuscateJwt(token) || obfuscateToken(token);
|
|
64
54
|
}
|
|
65
|
-
function obfuscateToken(token) {
|
|
55
|
+
export function obfuscateToken(token) {
|
|
66
56
|
if (token.length >= 12)
|
|
67
57
|
return obfuscateWord(token);
|
|
68
58
|
return token ? '***' : '';
|
|
69
59
|
}
|
|
70
|
-
function obfuscateJwt(token) {
|
|
60
|
+
export function obfuscateJwt(token) {
|
|
71
61
|
const firstDot = token.indexOf('.');
|
|
72
62
|
if (firstDot === -1)
|
|
73
63
|
return null;
|
package/dist/obfuscate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obfuscate.js","sourceRoot":"","sources":["../src/obfuscate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"obfuscate.js","sourceRoot":"","sources":["../src/obfuscate.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAA+B;IAC9D,MAAM,iBAAiB,GAA2B,EAAE,CAAA;IACpD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,eAAe,EAAE,CAAC;YAC1C,iBAAiB,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;QAC5D,CAAC;aAAM,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK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U,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACvC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC,GAAG,CAAA;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,cAAc;QACd,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAsB;IACtB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,aAAa,CAAA;AAClD,CAAC","sourcesContent":["export function obfuscateEmail(email: string) {\n const [local, domain] = email.split('@')\n return `${obfuscateWord(local)}@${obfuscateWord(domain)}`\n}\n\nexport function obfuscateWord(word: string) {\n return `${word.charAt(0)}***${word.charAt(word.length - 1)}`\n}\n\nexport function obfuscateHeaders(headers: Record<string, string>) {\n const obfuscatedHeaders: Record<string, string> = {}\n for (const key in headers) {\n if (key.toLowerCase() === 'authorization') {\n obfuscatedHeaders[key] = obfuscateAuthHeader(headers[key])\n } else if (key.toLowerCase() === 'dpop') {\n obfuscatedHeaders[key] = obfuscateJwt(headers[key]) || 'Invalid'\n } else {\n obfuscatedHeaders[key] = headers[key]\n }\n }\n return obfuscatedHeaders\n}\n\nexport function obfuscateAuthHeader(authHeader: string): string {\n // This is a hot path (runs on every request). Avoid using split() or regex.\n\n const spaceIdx = authHeader.indexOf(' ')\n if (spaceIdx === -1) return 'Invalid'\n\n const type = authHeader.slice(0, spaceIdx)\n switch (type.toLowerCase()) {\n case 'bearer':\n case 'dpop':\n return `${type} ${obfuscateBearer(authHeader.slice(spaceIdx + 1))}`\n case 'basic':\n return `${type} ${obfuscateBasic(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`\n default:\n return `Invalid`\n }\n}\n\nexport function obfuscateBasic(token: string): null | string {\n if (!token) return null\n const buffer = Buffer.from(token, 'base64')\n if (!buffer.length) return null // Buffer.from will silently ignore invalid base64 chars\n const authHeader = buffer.toString('utf8')\n const colIdx = authHeader.indexOf(':')\n if (colIdx === -1) return null\n const username = authHeader.slice(0, colIdx)\n return `${username}:***`\n}\n\nexport function obfuscateBearer(token: string): string {\n return obfuscateJwt(token) || obfuscateToken(token)\n}\n\nexport function obfuscateToken(token: string): string {\n if (token.length >= 12) return obfuscateWord(token)\n return token ? '***' : ''\n}\n\nexport function obfuscateJwt(token: string): null | string {\n const firstDot = token.indexOf('.')\n if (firstDot === -1) return null\n\n const secondDot = token.indexOf('.', firstDot + 1)\n if (secondDot === -1) return null\n\n // Expected to be missing\n const thirdDot = token.indexOf('.', secondDot + 1)\n if (thirdDot !== -1) return null\n\n try {\n const payloadEnc = token.slice(firstDot + 1, secondDot)\n const payloadJson = Buffer.from(payloadEnc, 'base64').toString('utf8')\n const payload = JSON.parse(payloadJson)\n if (typeof payload.sub === 'string') return payload.sub\n } catch {\n // Invalid JWT\n return null\n }\n\n // Strip the signature\n return token.slice(0, secondDot) + '.obfuscated'\n}\n"]}
|
package/dist/streams.js
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.decodeStream = decodeStream;
|
|
5
|
-
exports.createDecoders = createDecoders;
|
|
6
|
-
const node_stream_1 = require("node:stream");
|
|
7
|
-
const node_zlib_1 = require("node:zlib");
|
|
8
|
-
const forwardStreamErrors = (...streams) => {
|
|
1
|
+
import { PassThrough, Readable, Transform, pipeline, } from 'node:stream';
|
|
2
|
+
import { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib';
|
|
3
|
+
export const forwardStreamErrors = (...streams) => {
|
|
9
4
|
for (let i = 1; i < streams.length; ++i) {
|
|
10
5
|
const prev = streams[i - 1];
|
|
11
6
|
const next = streams[i];
|
|
12
7
|
prev.once('error', (err) => next.emit('error', err));
|
|
13
8
|
}
|
|
14
9
|
};
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
(0, exports.forwardStreamErrors)(stream, passthrough);
|
|
10
|
+
export const cloneStream = (stream) => {
|
|
11
|
+
const passthrough = new PassThrough();
|
|
12
|
+
forwardStreamErrors(stream, passthrough);
|
|
19
13
|
return stream.pipe(passthrough);
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
const streamSize = async (stream) => {
|
|
15
|
+
export const streamSize = async (stream) => {
|
|
23
16
|
let size = 0;
|
|
24
17
|
for await (const chunk of stream) {
|
|
25
18
|
size += Buffer.byteLength(chunk);
|
|
26
19
|
}
|
|
27
20
|
return size;
|
|
28
21
|
};
|
|
29
|
-
|
|
30
|
-
const streamToBytes = async (stream) =>
|
|
22
|
+
export const streamToBytes = async (stream) =>
|
|
31
23
|
// @NOTE Though Buffer is a sub-class of Uint8Array, we have observed
|
|
32
24
|
// inconsistencies when using a Buffer in place of Uint8Array. For this
|
|
33
25
|
// reason, we convert the Buffer to a Uint8Array.
|
|
34
|
-
new Uint8Array(await
|
|
35
|
-
exports.streamToBytes = streamToBytes;
|
|
26
|
+
new Uint8Array(await streamToNodeBuffer(stream));
|
|
36
27
|
// streamToBuffer identifier name already taken by @atproto/common-web
|
|
37
|
-
const streamToNodeBuffer = async (stream) => {
|
|
28
|
+
export const streamToNodeBuffer = async (stream) => {
|
|
38
29
|
const chunks = [];
|
|
39
30
|
let totalLength = 0; // keep track of total length for Buffer.concat
|
|
40
31
|
for await (const chunk of stream) {
|
|
@@ -48,39 +39,21 @@ const streamToNodeBuffer = async (stream) => {
|
|
|
48
39
|
}
|
|
49
40
|
return Buffer.concat(chunks, totalLength);
|
|
50
41
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return node_stream_1.Readable.from(iter, { objectMode: false });
|
|
42
|
+
export const byteIterableToStream = (iter) => {
|
|
43
|
+
return Readable.from(iter, { objectMode: false });
|
|
54
44
|
};
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const stream = new node_stream_1.Readable();
|
|
45
|
+
export const bytesToStream = (bytes) => {
|
|
46
|
+
const stream = new Readable();
|
|
58
47
|
stream.push(bytes);
|
|
59
48
|
stream.push(null);
|
|
60
49
|
return stream;
|
|
61
50
|
};
|
|
62
|
-
|
|
63
|
-
class MaxSizeChecker extends node_stream_1.Transform {
|
|
51
|
+
export class MaxSizeChecker extends Transform {
|
|
64
52
|
constructor(maxSize, createError) {
|
|
65
53
|
super();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
writable: true,
|
|
70
|
-
value: maxSize
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "createError", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: createError
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(this, "totalSize", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true,
|
|
82
|
-
value: 0
|
|
83
|
-
});
|
|
54
|
+
this.maxSize = maxSize;
|
|
55
|
+
this.createError = createError;
|
|
56
|
+
this.totalSize = 0;
|
|
84
57
|
}
|
|
85
58
|
_transform(chunk, _enc, cb) {
|
|
86
59
|
this.totalSize += chunk.length;
|
|
@@ -92,12 +65,11 @@ class MaxSizeChecker extends node_stream_1.Transform {
|
|
|
92
65
|
}
|
|
93
66
|
}
|
|
94
67
|
}
|
|
95
|
-
|
|
96
|
-
function decodeStream(stream, contentEncoding) {
|
|
68
|
+
export function decodeStream(stream, contentEncoding) {
|
|
97
69
|
const decoders = createDecoders(contentEncoding);
|
|
98
70
|
if (decoders.length === 0)
|
|
99
71
|
return stream;
|
|
100
|
-
return
|
|
72
|
+
return pipeline([stream, ...decoders], () => { });
|
|
101
73
|
}
|
|
102
74
|
/**
|
|
103
75
|
* Create a series of decoding streams based on the content-encoding header. The
|
|
@@ -105,7 +77,7 @@ function decodeStream(stream, contentEncoding) {
|
|
|
105
77
|
*
|
|
106
78
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
|
|
107
79
|
*/
|
|
108
|
-
function createDecoders(contentEncoding) {
|
|
80
|
+
export function createDecoders(contentEncoding) {
|
|
109
81
|
const decoders = [];
|
|
110
82
|
if (contentEncoding?.length) {
|
|
111
83
|
const encodings = Array.isArray(contentEncoding)
|
|
@@ -137,13 +109,13 @@ function createDecoder(normalizedEncoding) {
|
|
|
137
109
|
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
|
|
138
110
|
case 'gzip':
|
|
139
111
|
case 'x-gzip':
|
|
140
|
-
return
|
|
112
|
+
return createGunzip();
|
|
141
113
|
case 'deflate':
|
|
142
|
-
return
|
|
114
|
+
return createInflate();
|
|
143
115
|
case 'br':
|
|
144
|
-
return
|
|
116
|
+
return createBrotliDecompress();
|
|
145
117
|
case 'identity':
|
|
146
|
-
return new
|
|
118
|
+
return new PassThrough();
|
|
147
119
|
default:
|
|
148
120
|
throw new TypeError(`Unsupported content-encoding: "${normalizedEncoding}"`);
|
|
149
121
|
}
|
package/dist/streams.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,QAAQ,EAER,SAAS,EAET,QAAQ,GACT,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,OAAiB,EAAE,EAAE;IAC1D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3B,MAAM,IAAI,GAAG,OAAO,C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,QAAQ;YACX,OAAO,YAAY,EAAE,CAAA;QACvB,KAAK,SAAS;YACZ,OAAO,aAAa,EAAE,CAAA;QACxB,KAAK,IAAI;YACP,OAAO,sBAAsB,EAAE,CAAA;QACjC,KAAK,UAAU;YACb,OAAO,IAAI,WAAW,EAAE,CAAA;QAC1B;YACE,MAAM,IAAI,SAAS,CACjB,kCAAkC,kBAAkB,GAAG,CACxD,CAAA;IACL,CAAC;AACH,CAAC","sourcesContent":["import {\n Duplex,\n PassThrough,\n Readable,\n Stream,\n Transform,\n TransformCallback,\n pipeline,\n} from 'node:stream'\nimport { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib'\n\nexport const forwardStreamErrors = (...streams: Stream[]) => {\n for (let i = 1; i < streams.length; ++i) {\n const prev = streams[i - 1]\n const next = streams[i]\n\n prev.once('error', (err) => next.emit('error', err))\n }\n}\n\nexport const cloneStream = (stream: Readable): Readable => {\n const passthrough = new PassThrough()\n forwardStreamErrors(stream, passthrough)\n return stream.pipe(passthrough)\n}\n\nexport const streamSize = async (stream: Readable): Promise<number> => {\n let size = 0\n for await (const chunk of stream) {\n size += Buffer.byteLength(chunk)\n }\n return size\n}\n\nexport const streamToBytes = async (stream: AsyncIterable<Uint8Array>) =>\n // @NOTE Though Buffer is a sub-class of Uint8Array, we have observed\n // inconsistencies when using a Buffer in place of Uint8Array. For this\n // reason, we convert the Buffer to a Uint8Array.\n new Uint8Array(await streamToNodeBuffer(stream))\n\n// streamToBuffer identifier name already taken by @atproto/common-web\nexport const streamToNodeBuffer = async (\n stream: Iterable<Uint8Array> | AsyncIterable<Uint8Array>,\n): Promise<Buffer> => {\n const chunks: Uint8Array[] = []\n let totalLength = 0 // keep track of total length for Buffer.concat\n for await (const chunk of stream) {\n if (chunk instanceof Uint8Array) {\n chunks.push(chunk)\n totalLength += Buffer.byteLength(chunk)\n } else {\n throw new TypeError('expected Uint8Array')\n }\n }\n return Buffer.concat(chunks, totalLength)\n}\n\nexport const byteIterableToStream = (\n iter: AsyncIterable<Uint8Array>,\n): Readable => {\n return Readable.from(iter, { objectMode: false })\n}\n\nexport const bytesToStream = (bytes: Uint8Array): Readable => {\n const stream = new Readable()\n stream.push(bytes)\n stream.push(null)\n return stream\n}\n\nexport class MaxSizeChecker extends Transform {\n totalSize = 0\n constructor(\n public maxSize: number,\n public createError: () => Error,\n ) {\n super()\n }\n _transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback) {\n this.totalSize += chunk.length\n if (this.totalSize > this.maxSize) {\n cb(this.createError())\n } else {\n cb(null, chunk)\n }\n }\n}\n\nexport function decodeStream(\n stream: Readable,\n contentEncoding?: string | string[],\n): Readable\nexport function decodeStream(\n stream: AsyncIterable<Uint8Array>,\n contentEncoding?: string | string[],\n): AsyncIterable<Uint8Array> | Readable\nexport function decodeStream(\n stream: Readable | AsyncIterable<Uint8Array>,\n contentEncoding?: string | string[],\n): Readable | AsyncIterable<Uint8Array> {\n const decoders = createDecoders(contentEncoding)\n if (decoders.length === 0) return stream\n return pipeline([stream as Readable, ...decoders], () => {}) as Duplex\n}\n\n/**\n * Create a series of decoding streams based on the content-encoding header. The\n * resulting streams should be piped together to decode the content.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}\n */\nexport function createDecoders(contentEncoding?: string | string[]): Duplex[] {\n const decoders: Duplex[] = []\n\n if (contentEncoding?.length) {\n const encodings: string[] = Array.isArray(contentEncoding)\n ? contentEncoding.flatMap(commaSplit)\n : contentEncoding.split(',')\n for (const encoding of encodings) {\n const normalizedEncoding = normalizeEncoding(encoding)\n\n // @NOTE\n // > The default (identity) encoding [...] is used only in the\n // > Accept-Encoding header, and SHOULD NOT be used in the\n // > Content-Encoding header.\n if (normalizedEncoding === 'identity') continue\n\n decoders.push(createDecoder(normalizedEncoding))\n }\n }\n\n return decoders.reverse()\n}\n\nfunction commaSplit(header: string): string[] {\n return header.split(',')\n}\n\nfunction normalizeEncoding(encoding: string) {\n // https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1\n // > All content-coding values are case-insensitive...\n return encoding.trim().toLowerCase()\n}\n\nfunction createDecoder(normalizedEncoding: string): Duplex {\n switch (normalizedEncoding) {\n // https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2\n case 'gzip':\n case 'x-gzip':\n return createGunzip()\n case 'deflate':\n return createInflate()\n case 'br':\n return createBrotliDecompress()\n case 'identity':\n return new PassThrough()\n default:\n throw new TypeError(\n `Unsupported content-encoding: \"${normalizedEncoding}\"`,\n )\n }\n}\n"]}
|
package/jest.config.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @type {import('jest').Config} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
displayName: 'Common',
|
|
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: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared web-platform-friendly code for atproto libraries",
|
|
6
6
|
"keywords": [
|
|
@@ -12,25 +12,30 @@
|
|
|
12
12
|
"url": "https://github.com/bluesky-social/atproto",
|
|
13
13
|
"directory": "packages/common"
|
|
14
14
|
},
|
|
15
|
-
"main": "dist/index.js",
|
|
16
|
-
"types": "dist/index.d.ts",
|
|
17
15
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
16
|
+
"node": ">=22"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
|
-
"multiformats": "^
|
|
19
|
+
"multiformats": "^13.0.0",
|
|
22
20
|
"pino": "^8.21.0",
|
|
23
|
-
"@atproto/common-web": "^0.
|
|
24
|
-
"@atproto/lex-cbor": "^0.0
|
|
25
|
-
"@atproto/lex-data": "^0.0
|
|
21
|
+
"@atproto/common-web": "^0.5.0",
|
|
22
|
+
"@atproto/lex-cbor": "^0.1.0",
|
|
23
|
+
"@atproto/lex-data": "^0.1.0"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
|
-
"jest": "^
|
|
29
|
-
"typescript": "^
|
|
30
|
-
"uint8arrays": "
|
|
26
|
+
"jest": "^30.0.0",
|
|
27
|
+
"typescript": "^6.0.3",
|
|
28
|
+
"uint8arrays": "^5.0.0"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
31
36
|
},
|
|
32
37
|
"scripts": {
|
|
33
|
-
"test": "jest",
|
|
38
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
34
39
|
"build": "tsc --build tsconfig.build.json"
|
|
35
40
|
}
|
|
36
41
|
}
|
package/src/buffers.ts
CHANGED
|
@@ -2,7 +2,7 @@ export function ui8ToBuffer(bytes: Uint8Array): Buffer {
|
|
|
2
2
|
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function ui8ToArrayBuffer(bytes: Uint8Array): ArrayBuffer {
|
|
5
|
+
export function ui8ToArrayBuffer(bytes: Uint8Array<ArrayBuffer>): ArrayBuffer {
|
|
6
6
|
return bytes.buffer.slice(
|
|
7
7
|
bytes.byteOffset,
|
|
8
8
|
bytes.byteLength + bytes.byteOffset,
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from '@atproto/common-web'
|
|
2
|
-
export * from './buffers'
|
|
3
|
-
export * from './dates'
|
|
4
|
-
export * from './env'
|
|
5
|
-
export * from './fs'
|
|
6
|
-
export * from './ipld'
|
|
7
|
-
export * from './ipld-multi'
|
|
8
|
-
export * from './logger'
|
|
9
|
-
export * from './obfuscate'
|
|
10
|
-
export * from './streams'
|
|
2
|
+
export * from './buffers.js'
|
|
3
|
+
export * from './dates.js'
|
|
4
|
+
export * from './env.js'
|
|
5
|
+
export * from './fs.js'
|
|
6
|
+
export * from './ipld.js'
|
|
7
|
+
export * from './ipld-multi.js'
|
|
8
|
+
export * from './logger.js'
|
|
9
|
+
export * from './obfuscate.js'
|
|
10
|
+
export * from './streams.js'
|
package/src/ipld.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import { Transform } from 'node:stream'
|
|
3
|
-
import {
|
|
3
|
+
import { encode as encodeBlock } from 'multiformats/block'
|
|
4
|
+
import type { BlockView, ByteView } from 'multiformats/block/interface'
|
|
4
5
|
import { sha256 as hasher } from 'multiformats/hashes/sha2'
|
|
5
6
|
import { cidForLex, decode, encode } from '@atproto/lex-cbor'
|
|
6
7
|
import {
|
|
@@ -33,7 +34,9 @@ export { cborDecodeLegacy as cborDecode }
|
|
|
33
34
|
/**
|
|
34
35
|
* @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
|
|
35
36
|
*/
|
|
36
|
-
export async function dataToCborBlock<T>(
|
|
37
|
+
export async function dataToCborBlock<T>(
|
|
38
|
+
value: T,
|
|
39
|
+
): Promise<BlockView<T, 0x71, 0x12, 1>> {
|
|
37
40
|
return encodeBlock<T, 0x71, 0x12>({
|
|
38
41
|
value,
|
|
39
42
|
codec: {
|
package/tests/ipld-multi.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ui8 from 'uint8arrays'
|
|
2
2
|
import { CID } from '@atproto/lex-data'
|
|
3
|
-
import { cborDecodeMulti, cborEncode } from '../src'
|
|
3
|
+
import { cborDecodeMulti, cborEncode } from '../src/index.js'
|
|
4
4
|
|
|
5
5
|
describe('ipld decode multi', () => {
|
|
6
6
|
it('decodes concatenated dag-cbor messages', async () => {
|
package/tests/ipld.test.ts
CHANGED
package/tests/streams.test.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/buffers.ts","./src/dates.ts","./src/env.ts","./src/fs.ts","./src/index.ts","./src/ipld-multi.ts","./src/ipld.ts","./src/logger.ts","./src/obfuscate.ts","./src/streams.ts"],"version":"
|
|
1
|
+
{"root":["./src/buffers.ts","./src/dates.ts","./src/env.ts","./src/fs.ts","./src/index.ts","./src/ipld-multi.ts","./src/ipld.ts","./src/logger.ts","./src/obfuscate.ts","./src/streams.ts"],"version":"6.0.3"}
|
package/jest.config.js
DELETED