Files
medusa-store/www/apps/docs/content/references/js-client/modules/internal-8.internal-2.md
github-actions[bot] daea35fe73 chore(docs): Generated JS Client Reference (#5334)
Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-10-10 17:47:07 +00:00

25 KiB

displayed_sidebar
displayed_sidebar
jsClientSidebar

Namespace: internal

internal.internal

Namespaces

Classes

Interfaces

References

Duplex

Re-exports Duplex


DuplexOptions

Re-exports DuplexOptions


PassThrough

Re-exports PassThrough


Readable

Re-exports Readable


Stream

Re-exports Stream


Transform

Re-exports Transform


TransformCallback

Re-exports TransformCallback


TransformOptions

Re-exports TransformOptions

Type Aliases

PipelineCallback

Ƭ PipelineCallback<S>: S extends PipelineDestinationPromiseFunction<any, infer P> ? (err: ErrnoException | null, value: P) => void : (err: ErrnoException | null) => void

Type parameters

Name Type
S extends PipelineDestination<any, any>

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1243


PipelineDestination

Ƭ PipelineDestination<S, P>: S extends PipelineTransformSource<infer ST> ? WritableStream | PipelineDestinationIterableFunction<ST> | PipelineDestinationPromiseFunction<ST, P> : never

Type parameters

Name Type
S extends PipelineTransformSource<any>
P P

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1240


PipelineDestinationIterableFunction

Ƭ PipelineDestinationIterableFunction<T>: (source: AsyncIterable<T>) => AsyncIterable<any>

Type parameters

Name
T

Type declaration

▸ (source): AsyncIterable<any>

Parameters
Name Type
source AsyncIterable<T>
Returns

AsyncIterable<any>

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1238


PipelineDestinationPromiseFunction

Ƭ PipelineDestinationPromiseFunction<T, P>: (source: AsyncIterable<T>) => Promise<P>

Type parameters

Name
T
P

Type declaration

▸ (source): Promise<P>

Parameters
Name Type
source AsyncIterable<T>
Returns

Promise<P>

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1239


PipelinePromise

Ƭ PipelinePromise<S>: S extends PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>

Type parameters

Name Type
S extends PipelineDestination<any, any>

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1246


PipelineSource

Ƭ PipelineSource<T>: Iterable<T> | AsyncIterable<T> | ReadableStream | PipelineSourceFunction<T>

Type parameters

Name
T

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1233


PipelineSourceFunction

Ƭ PipelineSourceFunction<T>: () => Iterable<T> | AsyncIterable<T>

Type parameters

Name
T

Type declaration

▸ (): Iterable<T> | AsyncIterable<T>

Returns

Iterable<T> | AsyncIterable<T>

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1232


PipelineTransform

Ƭ PipelineTransform<S, U>: ReadWriteStream | (source: S extends (...args: any[]) => Iterable<infer ST> | AsyncIterable<infer ST> ? AsyncIterable<ST> : S) => AsyncIterable<U>

Type parameters

Name Type
S extends PipelineTransformSource<any>
U U

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1234


PipelineTransformSource

Ƭ PipelineTransformSource<T>: PipelineSource<T> | PipelineTransform<any, T>

Type parameters

Name
T

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1237

Variables

consumers

Const consumers: typeof internal

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1414


promises

Const promises: typeof internal

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1413

Functions

addAbortSignal

addAbortSignal<T>(signal, stream): T

A stream to attach a signal to.

Attaches an AbortSignal to a readable or writeable stream. This lets code control stream destruction using an AbortController.

Calling abort on the AbortController corresponding to the passedAbortSignal will behave the same way as calling .destroy(new AbortError())on the stream, and controller.error(new AbortError()) for webstreams.

const fs = require('node:fs');

const controller = new AbortController();
const read = addAbortSignal(
  controller.signal,
  fs.createReadStream(('object.json')),
);
// Later, abort the operation closing the stream
controller.abort();

Or using an AbortSignal with a readable stream as an async iterable:

const controller = new AbortController();
setTimeout(() => controller.abort(), 10_000); // set a timeout
const stream = addAbortSignal(
  controller.signal,
  fs.createReadStream(('object.json')),
);
(async () => {
  try {
    for await (const chunk of stream) {
      await process(chunk);
    }
  } catch (e) {
    if (e.name === 'AbortError') {
      // The operation was cancelled
    } else {
      throw e;
    }
  }
})();

Or using an AbortSignal with a ReadableStream:

const controller = new AbortController();
const rs = new ReadableStream({
  start(controller) {
    controller.enqueue('hello');
    controller.enqueue('world');
    controller.close();
  },
});

addAbortSignal(controller.signal, rs);

finished(rs, (err) => {
  if (err) {
    if (err.name === 'AbortError') {
      // The operation was cancelled
    }
  }
});

const reader = rs.getReader();

reader.read().then(({ value, done }) => {
  console.log(value); // hello
  console.log(done); // false
  controller.abort();
});

Type parameters

Name Type
T extends Stream

Parameters

Name Type Description
signal AbortSignal A signal representing possible cancellation
stream T a stream to attach a signal to

Returns

T

Since

v15.4.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1162


finished

finished(stream, options, callback): () => void

A readable and/or writable stream/webstream.

A function to get notified when a stream is no longer readable, writable or has experienced an error or a premature close event.

const { finished } = require('node:stream');
const fs = require('node:fs');

const rs = fs.createReadStream('archive.tar');

finished(rs, (err) => {
  if (err) {
    console.error('Stream failed.', err);
  } else {
    console.log('Stream is done reading.');
  }
});

rs.resume(); // Drain the stream.

Especially useful in error handling scenarios where a stream is destroyed prematurely (like an aborted HTTP request), and will not emit 'end'or 'finish'.

The finished API provides promise version.

stream.finished() leaves dangling event listeners (in particular'error', 'end', 'finish' and 'close') after callback has been invoked. The reason for this is so that unexpected 'error' events (due to incorrect stream implementations) do not cause unexpected crashes. If this is unwanted behavior then the returned cleanup function needs to be invoked in the callback:

const cleanup = finished(rs, (err) => {
  cleanup();
  // ...
});

Parameters

Name Type Description
stream ReadableStream | WritableStream | ReadWriteStream A readable and/or writable stream.
options FinishedOptions -
callback (err?: null | ErrnoException) => void A callback function that takes an optional error argument.

Returns

fn

A cleanup function which removes all registered listeners.

▸ (): void

Returns

void

Since

v10.0.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1227

finished(stream, callback): () => void

Parameters

Name Type
stream ReadableStream | WritableStream | ReadWriteStream
callback (err?: null | ErrnoException) => void

Returns

fn

▸ (): void

Returns

void

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1228


getDefaultHighWaterMark

getDefaultHighWaterMark(objectMode): number

Returns the default highWaterMark used by streams. Defaults to 16384 (16 KiB), or 16 for objectMode.

Parameters

Name Type
objectMode boolean

Returns

number

Since

v19.9.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1169


isErrored

isErrored(stream): boolean

Returns whether the stream has encountered an error.

Parameters

Name Type
stream ReadableStream | WritableStream | Readable | Writable

Returns

boolean

Since

v17.3.0, v16.14.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1406


isReadable

isReadable(stream): boolean

Returns whether the stream is readable.

Parameters

Name Type
stream ReadableStream | Readable

Returns

boolean

Since

v17.4.0, v16.14.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1412


pipeline

pipeline<A, B>(source, destination, callback?): B extends WritableStream ? B : WritableStream

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

const { pipeline } = require('node:stream');
const fs = require('node:fs');
const zlib = require('node:zlib');

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
  fs.createReadStream('archive.tar'),
  zlib.createGzip(),
  fs.createWriteStream('archive.tar.gz'),
  (err) => {
    if (err) {
      console.error('Pipeline failed.', err);
    } else {
      console.log('Pipeline succeeded.');
    }
  },
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

  • Readable streams which have emitted 'end' or 'close'.
  • Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

const fs = require('node:fs');
const http = require('node:http');
const { pipeline } = require('node:stream');

const server = http.createServer((req, res) => {
  const fileStream = fs.createReadStream('./fileNotExist.txt');
  pipeline(fileStream, res, (err) => {
    if (err) {
      console.log(err); // No such file
      // this message can't be sent once `pipeline` already destroyed the socket
      return res.end('error!!!');
    }
  });
});

Type parameters

Name Type
A extends PipelineSource<any>
B extends WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>

Parameters

Name Type Description
source A -
destination B -
callback? PipelineCallback<B> Called when the pipeline is fully done.

Returns

B extends WritableStream ? B : WritableStream

Since

v10.0.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1316

pipeline<A, T1, B>(source, transform1, destination, callback?): B extends WritableStream ? B : WritableStream

Type parameters

Name Type
A extends PipelineSource<any>
T1 extends PipelineTransform<A, any>
B extends WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>

Parameters

Name Type
source A
transform1 T1
destination B
callback? PipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1321

pipeline<A, T1, T2, B>(source, transform1, transform2, destination, callback?): B extends WritableStream ? B : WritableStream

Type parameters

Name Type
A extends PipelineSource<any>
T1 extends PipelineTransform<A, any>
T2 extends PipelineTransform<T1, any>
B extends WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>

Parameters

Name Type
source A
transform1 T1
transform2 T2
destination B
callback? PipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1327

pipeline<A, T1, T2, T3, B>(source, transform1, transform2, transform3, destination, callback?): B extends WritableStream ? B : WritableStream

Type parameters

Name Type
A extends PipelineSource<any>
T1 extends PipelineTransform<A, any>
T2 extends PipelineTransform<T1, any>
T3 extends PipelineTransform<T2, any>
B extends WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>

Parameters

Name Type
source A
transform1 T1
transform2 T2
transform3 T3
destination B
callback? PipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1334

pipeline<A, T1, T2, T3, T4, B>(source, transform1, transform2, transform3, transform4, destination, callback?): B extends WritableStream ? B : WritableStream

Type parameters

Name Type
A extends PipelineSource<any>
T1 extends PipelineTransform<A, any>
T2 extends PipelineTransform<T1, any>
T3 extends PipelineTransform<T2, any>
T4 extends PipelineTransform<T3, any>
B extends WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>

Parameters

Name Type
source A
transform1 T1
transform2 T2
transform3 T3
transform4 T4
destination B
callback? PipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1341

pipeline(streams, callback?): WritableStream

Parameters

Name Type
streams readonly (ReadableStream | WritableStream | ReadWriteStream)[]
callback? (err: null | ErrnoException) => void

Returns

WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1349

pipeline(stream1, stream2, ...streams): WritableStream

Parameters

Name Type
stream1 ReadableStream
stream2 WritableStream | ReadWriteStream
...streams (WritableStream | ReadWriteStream | (err: null | ErrnoException) => void)[]

Returns

WritableStream

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1353


setDefaultHighWaterMark

setDefaultHighWaterMark(objectMode, value): void

Sets the default highWaterMark used by streams.

Parameters

Name Type Description
objectMode boolean
value number highWaterMark value

Returns

void

Since

v19.9.0

Defined in

packages/medusa-js/node_modules/@types/node/stream.d.ts:1176