@ar.io/sdk 3.12.0-beta.6 → 3.12.0-beta.7

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.
@@ -13,8 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import EventEmitter from 'node:events';
17
- import { PassThrough, Readable } from 'node:stream';
16
+ import { EventEmitter } from 'eventemitter3';
18
17
  import { DataVerificationStrategy, GatewaysProvider, RoutingStrategy } from '../../types/wayfinder.js';
19
18
  import { Logger } from '../logger.js';
20
19
  type WayfinderHttpClient = typeof fetch;
@@ -35,69 +34,52 @@ export declare const resolveWayfinderUrl: ({ originalUrl, selectedGateway, logge
35
34
  * Wayfinder event emitter with verification events
36
35
  */
37
36
  export type WayfinderEvent = {
38
- type: 'verification-succeeded';
39
- txId: string;
40
- } | {
41
- type: 'verification-failed';
42
- txId: string;
43
- error: Error;
44
- } | {
45
- type: 'verification-skipped';
46
- originalUrl: string;
47
- } | {
48
- type: 'verification-progress';
49
- txId: string;
50
- processedBytes: number;
51
- totalBytes: number;
52
- } | {
53
- type: 'routing-started';
54
- originalUrl: string;
55
- } | {
56
- type: 'routing-skipped';
57
- originalUrl: string;
58
- } | {
59
- type: 'routing-succeeded';
60
- originalUrl: string;
61
- selectedGateway: string;
62
- redirectUrl: string;
63
- } | {
64
- type: 'routing-failed';
65
- originalUrl: string;
66
- error: Error;
67
- } | {
68
- type: 'identified-transaction-id';
69
- originalUrl: string;
70
- selectedGateway: string;
71
- txId: string;
37
+ 'verification-succeeded': {
38
+ txId: string;
39
+ };
40
+ 'verification-failed': Error;
41
+ 'verification-skipped': {
42
+ originalUrl: string;
43
+ };
44
+ 'verification-progress': {
45
+ txId: string;
46
+ processedBytes: number;
47
+ totalBytes: number;
48
+ };
49
+ 'routing-started': {
50
+ originalUrl: string;
51
+ };
52
+ 'routing-skipped': {
53
+ originalUrl: string;
54
+ };
55
+ 'routing-succeeded': {
56
+ originalUrl: string;
57
+ selectedGateway: string;
58
+ redirectUrl: string;
59
+ };
60
+ 'routing-failed': Error;
61
+ 'identified-transaction-id': {
62
+ originalUrl: string;
63
+ selectedGateway: string;
64
+ txId: string;
65
+ };
72
66
  };
73
67
  export interface WayfinderEventArgs {
74
- onVerificationPassed?: (payload: Omit<Extract<WayfinderEvent, {
75
- type: 'verification-succeeded';
76
- }>, 'type'>) => void;
77
- onVerificationFailed?: (payload: Omit<Extract<WayfinderEvent, {
78
- type: 'verification-failed';
79
- }>, 'type'>) => void;
80
- onVerificationProgress?: (payload: Omit<Extract<WayfinderEvent, {
81
- type: 'verification-progress';
82
- }>, 'type'>) => void;
68
+ onVerificationSucceeded?: (payload: WayfinderEvent['verification-succeeded']) => void;
69
+ onVerificationFailed?: (payload: WayfinderEvent['verification-failed']) => void;
70
+ onVerificationProgress?: (payload: WayfinderEvent['verification-progress']) => void;
83
71
  }
84
- export declare class WayfinderEmitter extends EventEmitter {
85
- constructor({ onVerificationPassed, onVerificationFailed, onVerificationProgress, }?: WayfinderEventArgs);
86
- emit<E extends WayfinderEvent['type']>(event: E, payload: Omit<Extract<WayfinderEvent, {
87
- type: E;
88
- }>, 'type'>): boolean;
89
- on<E extends WayfinderEvent['type']>(event: E, listener: (payload: Omit<Extract<WayfinderEvent, {
90
- type: E;
91
- }>, 'type'>) => void): this;
72
+ export declare class WayfinderEmitter extends EventEmitter<WayfinderEvent> {
73
+ constructor({ onVerificationSucceeded, onVerificationFailed, onVerificationProgress, }?: WayfinderEventArgs);
92
74
  }
93
- export declare function tapAndVerifyStream<T extends Readable | ReadableStream>({ originalStream, contentLength, verifyData, txId, emitter, strict, }: {
94
- originalStream: T;
75
+ export declare function tapAndVerifyReadableStream({ originalStream, contentLength, verifyData, txId, emitter, strict, }: {
76
+ originalStream: ReadableStream;
95
77
  contentLength: number;
96
78
  verifyData: DataVerificationStrategy['verifyData'];
97
79
  txId: string;
98
80
  emitter?: WayfinderEmitter;
99
81
  strict?: boolean;
100
- }): T extends Readable ? PassThrough : T;
82
+ }): ReadableStream;
101
83
  /**
102
84
  * Gets the sandbox hash for a given transaction id
103
85
  */
@@ -124,7 +106,7 @@ export declare const createWayfinderClient: ({ resolveUrl, verifyData, selectGat
124
106
  logger?: Logger;
125
107
  emitter?: WayfinderEmitter;
126
108
  strict?: boolean;
127
- }) => WayfinderHttpClient;
109
+ }) => (url: string, init?: RequestInit) => Promise<Response>;
128
110
  /**
129
111
  * The main class for the wayfinder
130
112
  */
@@ -263,7 +245,7 @@ export declare class Wayfinder {
263
245
  * @param logger - the logger to use for logging
264
246
  * @param strict - if true, verification will be blocking and will fail requests if verification fails; if false, verification will be non-blocking
265
247
  */
266
- constructor({ logger, gatewaysProvider, routingStrategy, verificationStrategy, events, strict, }: {
248
+ constructor({ logger, gatewaysProvider, routingStrategy, verificationStrategy, events, strict, }?: {
267
249
  routingStrategy?: RoutingStrategy;
268
250
  gatewaysProvider?: GatewaysProvider;
269
251
  verificationStrategy?: DataVerificationStrategy;
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Readable } from 'stream';
17
16
  export interface RoutingStrategy {
18
17
  selectGateway: ({ gateways }: {
19
18
  gateways: URL[];
@@ -22,6 +21,7 @@ export interface RoutingStrategy {
22
21
  export interface GatewaysProvider {
23
22
  getGateways: () => Promise<URL[]>;
24
23
  }
24
+ export type DataStream = AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
25
25
  export interface DataVerificationStrategy {
26
26
  /**
27
27
  * Verifies the provided data for a given txId
@@ -35,7 +35,7 @@ export interface DataVerificationStrategy {
35
35
  * @returns the hash of the data
36
36
  */
37
37
  verifyData: ({ data, txId, }: {
38
- data: Buffer | Readable | ReadableStream;
38
+ data: DataStream;
39
39
  txId: string;
40
40
  }) => Promise<void>;
41
41
  }
@@ -1,4 +1,8 @@
1
- import { Readable } from 'stream';
2
- export declare const hashReadableToB64Url: (stream: Readable, algorithm?: string) => Promise<string>;
3
- export declare const hashReadableStreamToB64Url: (stream: ReadableStream, algorithm?: string) => Promise<string>;
4
- export declare const hashBufferToB64Url: (buffer: Buffer, algorithm?: string) => string;
1
+ import { DataStream } from '../types/wayfinder.js';
2
+ export declare const isAsyncIterable: <T = unknown>(x: any) => x is AsyncIterable<T>;
3
+ export declare const isReadableStream: <T = unknown>(x: any) => x is ReadableStream<T>;
4
+ export declare const readableStreamToAsyncIterable: (stream: ReadableStream<Uint8Array>) => AsyncIterable<Uint8Array>;
5
+ export declare const hashDataStreamToB64Url: (stream: DataStream, algorithm?: string) => Promise<string>;
6
+ export declare const convertDataStreamToDataRoot: ({ dataStream, }: {
7
+ dataStream: DataStream;
8
+ }) => Promise<string>;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.12.0-beta.5";
16
+ export declare const version = "3.12.0-beta.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.12.0-beta.6",
3
+ "version": "3.12.0-beta.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"