split-hash 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,7 @@ for await (const hash of iter) {
40
40
  ```js
41
41
  import { SplitHashValidator } from 'split-hash/nodejs'
42
42
  import * as crypto from 'crypto'
43
+ import { pipeline } from 'stream'
43
44
 
44
45
  const KiB = 1024
45
46
 
@@ -58,11 +59,13 @@ const createHash = () => {
58
59
  const hashList = [/* ... */]
59
60
  const validator = new SplitHashValidator(hashList, 512 * KiB, createHash)
60
61
 
61
- const stream = fs.createReadStream('filename.bin')
62
- stream
63
- .pipe(validator)
64
- .on('data', /* same as stream */)
65
- .on('error', err => console.error('not matched'))
62
+ const stream = pipeline(
63
+ fs.createReadStream('filename.bin')
64
+ , validator
65
+ , err => {
66
+ // ...
67
+ }
68
+ )
66
69
  ```
67
70
 
68
71
  ## API
@@ -80,9 +83,9 @@ interface IProgressiveHash<T> {
80
83
  ```ts
81
84
  function splitHash<T>(
82
85
  stream: NodeJS.ReadableStream
83
- , blockSize: number
86
+ , blockSizeBytes: number
84
87
  , createHash: ProgressiveHashFactory<T>
85
- ): AsyncIterable<T>
88
+ ): AsyncIterableIterator<T>
86
89
  ```
87
90
 
88
91
  It throws `StreamEncodingError` when the `stream` encoding is set.
@@ -92,7 +95,7 @@ It throws `StreamEncodingError` when the `stream` encoding is set.
92
95
  class SplitHashValidator<T> extends Stream.Transform {
93
96
  constructor(
94
97
  digests: T[]
95
- , blockSize: number
98
+ , blockSizeBytes: number
96
99
  , createHash: ProgressiveHashFactory<T>
97
100
  , equals: (a: T, b: T) => boolean = Object.is
98
101
  )
@@ -127,5 +130,5 @@ async function* splitHash<T>(
127
130
  stream: ReadableStream
128
131
  , blockSize: number
129
132
  , createHash: ProgressiveHashFactory<T>
130
- ): AsyncIterable<T>
133
+ ): AsyncIterableIterator<T>
131
134
  ```
@@ -1,3 +1,3 @@
1
- export * from './types';
2
- export * from './split-hash';
3
- export * from './split-hash-validator';
1
+ export * from './types.js';
2
+ export * from './split-hash.js';
3
+ export * from './split-hash-validator.js';
@@ -1,20 +1,4 @@
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 __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("./types"), exports);
18
- __exportStar(require("./split-hash"), exports);
19
- __exportStar(require("./split-hash-validator"), exports);
1
+ export * from './types.js';
2
+ export * from './split-hash.js';
3
+ export * from './split-hash-validator.js';
20
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodejs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,+CAA4B;AAC5B,yDAAsC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodejs/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA"}
@@ -1,7 +1,8 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
2
3
  import { Transform, TransformCallback } from 'stream';
3
4
  import { CustomError } from '@blackglory/errors';
4
- import { ProgressiveHashFactory } from './types';
5
+ import { ProgressiveHashFactory } from './types.js';
5
6
  export declare class SplitHashValidator<T> extends Transform {
6
7
  private digests;
7
8
  private blockSize;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotMatchedError = exports.SplitHashValidator = void 0;
4
- const stream_1 = require("stream");
5
- const errors_1 = require("@blackglory/errors");
6
- class SplitHashValidator extends stream_1.Transform {
1
+ import { Transform } from 'stream';
2
+ import { CustomError } from '@blackglory/errors';
3
+ export class SplitHashValidator extends Transform {
7
4
  constructor(digests, blockSize, createHash, equals = Object.is) {
8
5
  super();
9
6
  this.digests = digests;
@@ -58,11 +55,9 @@ class SplitHashValidator extends stream_1.Transform {
58
55
  callback();
59
56
  }
60
57
  }
61
- exports.SplitHashValidator = SplitHashValidator;
62
- class NotMatchedError extends errors_1.CustomError {
58
+ export class NotMatchedError extends CustomError {
63
59
  constructor() {
64
60
  super('hashes do not match');
65
61
  }
66
62
  }
67
- exports.NotMatchedError = NotMatchedError;
68
63
  //# sourceMappingURL=split-hash-validator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"split-hash-validator.js","sourceRoot":"","sources":["../../src/nodejs/split-hash-validator.ts"],"names":[],"mappings":";;;AAAA,mCAAqD;AACrD,+CAAgD;AAGhD,MAAa,kBAAsB,SAAQ,kBAAS;IAKlD,YACU,OAAY,EACZ,SAAiB,EACjB,UAAqC,EACrC,SAAkC,MAAM,CAAC,EAAE;QAEnD,KAAK,EAAE,CAAA;QALC,YAAO,GAAP,OAAO,CAAK;QACZ,cAAS,GAAT,SAAS,CAAQ;QACjB,eAAU,GAAV,UAAU,CAA2B;QACrC,WAAM,GAAN,MAAM,CAAqC;QAR7C,SAAI,GAAwB,IAAI,CAAC,UAAU,EAAE,CAAA;QAC7C,SAAI,GAAG,CAAC,CAAA;QACR,gBAAW,GAAG,CAAC,CAAA;IASvB,CAAC;IAED,UAAU,CACR,KAAa,EACb,QAAwB,EACxB,QAA2B;QAI3B,IAAI,IAAI,CAAC,IA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I,GAAG,CAAC,EAAE;YACjB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;YACjC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE;gBACxD,OAAO,QAAQ,CAAC,IAAI,eAAe,EAAE,CAAC,CAAA;aACvC;YACD,IAAI,CAAC,WAAW,EAAE,CAAA;SACnB;QAED,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC5C,OAAO,QAAQ,CAAC,IAAI,eAAe,EAAE,CAAC,CAAA;SACvC;QAED,QAAQ,EAAE,CAAA;IACZ,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C;QACE,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAC9B,CAAC;CACF"}
@@ -1,7 +1,7 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  import { CustomError } from '@blackglory/errors';
3
- import { ProgressiveHashFactory } from './types';
4
- export declare function splitHash<T>(stream: NodeJS.ReadableStream, blockSizeBytes: number, createHash: ProgressiveHashFactory<T>): AsyncIterable<T>;
3
+ import { ProgressiveHashFactory } from './types.js';
4
+ export declare function splitHash<T>(stream: NodeJS.ReadableStream, blockSizeBytes: number, createHash: ProgressiveHashFactory<T>): AsyncIterableIterator<T>;
5
5
  export declare class StreamEncodingError extends CustomError {
6
6
  constructor();
7
7
  }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamEncodingError = exports.splitHash = void 0;
4
- const errors_1 = require("@blackglory/errors");
5
- async function* splitHash(stream, blockSizeBytes, createHash) {
1
+ import { CustomError } from '@blackglory/errors';
2
+ export async function* splitHash(stream, blockSizeBytes, createHash) {
6
3
  let hash = createHash();
7
4
  let accu = 0;
8
5
  for await (const chunk of stream) {
@@ -36,11 +33,9 @@ async function* splitHash(stream, blockSizeBytes, createHash) {
36
33
  if (accu > 0)
37
34
  yield hash.digest();
38
35
  }
39
- exports.splitHash = splitHash;
40
- class StreamEncodingError extends errors_1.CustomError {
36
+ export class StreamEncodingError extends CustomError {
41
37
  constructor() {
42
38
  super('stream encoding must not be set');
43
39
  }
44
40
  }
45
- exports.StreamEncodingError = StreamEncodingError;
46
41
  //# sourceMappingURL=split-hash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"split-hash.js","sourceRoot":"","sources":["../../src/nodejs/split-hash.ts"],"names":[],"mappings":";;;AAAA,+CAAgD;AAGzC,KAAK,SAAS,CAAC,CAAC,SAAS,CAC9B,MAA6B,EAC7B,cAAsB,EACtB,UAAqC;IAErC,IAAI,IAAI,GAAG,UAAU,EAAE,CAAA;IACvB,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;QAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,mBAAmB,EAAE,CAAA;QAC5D,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE;YACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAClB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAA;SACrB;aAAM;YACL,IAAI,MAAM,GAAG,CAAC,CAAA;YACd,OAAO,IAAI,EAAE;gBACX,MAAM,MAAM,GAAG,cAAc,GAAG,IAAI,CAAA;gBACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;gBAClD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;oBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;oBAC5B,MAAM,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AC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;gBAClD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;oBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;oBAC5B,MAAM,MAAM,CAAA;oBAEZ,IAAI,GAAG,UAAU,EAAE,CAAA;oBACnB,IAAI,GAAG,CAAC,CAAA;oBACR,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;iBACvB;qBAAM;oBAEL,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAA;oBACpB,MAAK;iBACN;aACF;SACF;KACF;IAED,IAAI,IAAI,GAAG,CAAC;QAAE,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;AACnC,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD;QACE,KAAK,CAAC,iCAAiC,CAAC,CAAA;IAC1C,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  export declare type ProgressiveHashFactory<T> = () => IProgressiveHash<T>;
3
3
  export interface IProgressiveHash<T> {
4
4
  update(buffer: Buffer): void;
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
@@ -1,2 +1,2 @@
1
- export * from './types';
2
- export * from './split-hash';
1
+ export * from './types.js';
2
+ export * from './split-hash.js';
@@ -1,19 +1,3 @@
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 __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("./types"), exports);
18
- __exportStar(require("./split-hash"), exports);
1
+ export * from './types.js';
2
+ export * from './split-hash.js';
19
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/whatwg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,+CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/whatwg/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
@@ -1,2 +1,2 @@
1
- import { ProgressiveHashFactory } from './types';
2
- export declare function splitHash<T>(stream: ReadableStream, blockSizeBytes: number, createHash: ProgressiveHashFactory<T>): AsyncIterable<T>;
1
+ import { ProgressiveHashFactory } from './types.js';
2
+ export declare function splitHash<T>(stream: ReadableStream, blockSizeBytes: number, createHash: ProgressiveHashFactory<T>): AsyncIterableIterator<T>;
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitHash = void 0;
4
- async function* splitHash(stream, blockSizeBytes, createHash) {
1
+ import { toAsyncIterableIterator } from 'extra-stream';
2
+ export async function* splitHash(stream, blockSizeBytes, createHash) {
5
3
  let hash = createHash();
6
4
  let accu = 0;
7
- for await (const chunk of getIterator(stream)) {
5
+ for await (const chunk of toAsyncIterableIterator(stream)) {
8
6
  if (accu + chunk.length < blockSizeBytes) {
9
7
  hash.update(chunk);
10
8
  accu += chunk.length;
@@ -33,20 +31,4 @@ async function* splitHash(stream, blockSizeBytes, createHash) {
33
31
  if (accu > 0)
34
32
  yield await hash.digest();
35
33
  }
36
- exports.splitHash = splitHash;
37
- async function* getIterator(stream) {
38
- const reader = stream.getReader();
39
- try {
40
- while (true) {
41
- const { done, value } = await reader.read();
42
- if (done)
43
- break;
44
- yield value;
45
- }
46
- }
47
- finally {
48
- reader.cancel();
49
- reader.releaseLock();
50
- }
51
- }
52
34
  //# sourceMappingURL=split-hash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"split-hash.js","sourceRoot":"","sources":["../../src/whatwg/split-hash.ts"],"names":[],"mappings":";;;AAEO,KAAK,SAAS,CAAC,CAAC,SAAS,CAC9B,MAAsB,EACtB,cAAsB,EACtB,UAAqC;IAErC,IAAI,IAAI,GAAG,UAAU,EAAE,CAAA;IACvB,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE;QAC7C,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE;YACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAClB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAA;SACrB;aAAM;YACL,IAAI,MAAM,GAAG,CAAC,CAAA;YACd,OAAO,IAAI,EAAE;gBACX,MAAM,MAAM,GAAG,cAAc,GAAG,IAAI,CAAA;gBACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;gBAClD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;oBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;oBAClC,MAAM,MAAM,CAAA;oBAEZ,IAAI,GAAG,UAAU,EAAE,CAAA;oBACnB,IAAI,GAAG,CAAC,CAAA;oBACR,MAAM,I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IAAI,EAAE;gBACX,MAAM,MAAM,GAAG,cAAc,GAAG,IAAI,CAAA;gBACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;gBAClD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;oBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;oBAClC,MAAM,MAAM,CAAA;oBAEZ,IAAI,GAAG,UAAU,EAAE,CAAA;oBACnB,IAAI,GAAG,CAAC,CAAA;oBACR,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;iBACvB;qBAAM;oBAGL,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAA;oBACpB,MAAK;iBACN;aACF;SACF;KACF;IAED,IAAI,IAAI,GAAG,CAAC;QAAE,MAAM,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;AACzC,CAAC"}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "split-hash",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Split the stream based on bytes and get digests from each part.",
5
5
  "keywords": [
6
6
  "split",
@@ -12,58 +12,63 @@
12
12
  "files": [
13
13
  "lib"
14
14
  ],
15
+ "type": "module",
15
16
  "exports": {
16
17
  "./nodejs": "./lib/nodejs/index.js",
17
18
  "./whatwg": "./lib/whatwg/index.js"
18
19
  },
19
20
  "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=16.5"
23
+ },
20
24
  "repository": "git@github.com:BlackGlory/split-hash.git",
21
25
  "author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
22
26
  "license": "MIT",
23
27
  "scripts": {
28
+ "prepare": "ts-patch install -s",
24
29
  "lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
25
- "test": "jest --config jest.config.js",
26
- "test:debug": "node --inspect node_modules/.bin/jest --runInBand",
27
- "test:coverage": "jest --coverage --config jest.config.js",
28
- "prepublishOnly": "run-s clean build",
30
+ "test": "vitest --run",
31
+ "prepublishOnly": "run-s prepare clean build",
29
32
  "clean": "rimraf lib",
30
- "build": "run-s build:*",
31
- "build:compile": "tsc --project tsconfig.build.json --module commonjs --target es2018 --outDir lib",
32
- "build:patch": "tscpaths -p tsconfig.build.json -s ./src -o ./lib",
33
+ "build": "tsc --project tsconfig.build.json",
33
34
  "release": "standard-version"
34
35
  },
35
36
  "husky": {
36
37
  "hooks": {
37
- "pre-commit": "run-s lint build test",
38
+ "pre-commit": "run-s prepare lint build test",
38
39
  "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
39
40
  }
40
41
  },
41
42
  "devDependencies": {
42
- "@blackglory/prelude": "^0.1.7",
43
- "@blackglory/structures": "^0.11.3",
44
- "@blackglory/wait-for": "^0.5.3",
45
- "@commitlint/cli": "^17.2.0",
46
- "@commitlint/config-conventional": "^17.2.0",
47
- "@peculiar/webcrypto": "^1.4.0",
48
- "@types/jest": "^27.5.1",
43
+ "@blackglory/prelude": "^0.3.1",
44
+ "@blackglory/structures": "^0.13.3",
45
+ "@blackglory/wait-for": "^0.7.3",
46
+ "@commitlint/cli": "^17.5.0",
47
+ "@commitlint/config-conventional": "^17.4.4",
48
+ "@peculiar/webcrypto": "^1.4.3",
49
49
  "@types/node": "16",
50
- "@typescript-eslint/eslint-plugin": "^5.42.0",
51
- "@typescript-eslint/parser": "^5.42.0",
52
- "eslint": "^8.26.0",
53
- "extra-abort": "^0.2.0",
54
- "extra-promise": "^4.0.0",
50
+ "@typescript-eslint/eslint-plugin": "^5.56.0",
51
+ "@typescript-eslint/parser": "^5.56.0",
52
+ "cross-env": "^7.0.3",
53
+ "eslint": "^8.36.0",
54
+ "extra-abort": "^0.3.4",
55
+ "extra-promise": "^6.0.5",
55
56
  "husky": "^4.3.0",
56
- "iterable-operator": "^2.1.0",
57
- "jest": "^27.4.7",
57
+ "iterable-operator": "^4.0.5",
58
58
  "npm-run-all": "^4.1.5",
59
- "return-style": "^1.0.0",
59
+ "return-style": "^3.0.0",
60
60
  "rimraf": "^3.0.2",
61
61
  "standard-version": "^9.5.0",
62
- "ts-jest": "^27.0.5",
62
+ "ts-patch": "^2.1.0",
63
63
  "tscpaths": "^0.0.9",
64
- "typescript": "^4.6.4"
64
+ "typescript": "4.8",
65
+ "typescript-transform-paths": "^3.4.6",
66
+ "vite": "^4.2.1",
67
+ "vite-tsconfig-paths": "^4.0.7",
68
+ "vitest": "^0.29.7"
65
69
  },
66
70
  "dependencies": {
67
- "@blackglory/errors": "^2.2.3"
71
+ "@blackglory/errors": "^3.0.0",
72
+ "extra-stream": "^0.2.0"
68
73
  }
69
74
  }