@roarkanalytics/sdk 0.1.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +25 -0
- package/LICENSE +201 -0
- package/README.md +344 -0
- package/api-promise.d.mts +47 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +47 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +84 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +80 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +186 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +186 -0
- package/client.d.ts.map +1 -0
- package/client.js +449 -0
- package/client.js.map +1 -0
- package/client.mjs +422 -0
- package/client.mjs.map +1 -0
- package/error.d.mts +47 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +47 -0
- package/error.d.ts.map +1 -0
- package/error.js +113 -0
- package/error.js.map +1 -0
- package/error.mjs +97 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +6 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +30 -0
- package/index.js.map +1 -0
- package/index.mjs +7 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +65 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +65 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +26 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +21 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +21 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +21 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +77 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +72 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +10 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +10 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +28 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +24 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/polyfill/crypto.node.d.ts +10 -0
- package/internal/polyfill/crypto.node.js +11 -0
- package/internal/polyfill/crypto.node.mjs +2 -0
- package/internal/polyfill/file.node.d.ts +9 -0
- package/internal/polyfill/file.node.js +17 -0
- package/internal/polyfill/file.node.mjs +9 -0
- package/internal/request-options.d.mts +34 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +34 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +39 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +34 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +28 -0
- package/internal/shim-types.d.ts +28 -0
- package/internal/shims.d.mts +61 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +61 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +101 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +92 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/types.d.mts +68 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +68 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +73 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +73 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +208 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +200 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +33 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +28 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +4 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +4 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +47 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +43 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +15 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +11 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +15 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +15 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +100 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +84 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +24 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +119 -0
- package/resource.d.mts +6 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +6 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +11 -0
- package/resource.js.map +1 -0
- package/resource.mjs +7 -0
- package/resource.mjs.map +1 -0
- package/resources/calls.d.mts +85 -0
- package/resources/calls.d.mts.map +1 -0
- package/resources/calls.d.ts +85 -0
- package/resources/calls.d.ts.map +1 -0
- package/resources/calls.js +15 -0
- package/resources/calls.js.map +1 -0
- package/resources/calls.mjs +11 -0
- package/resources/calls.mjs.map +1 -0
- package/resources/index.d.mts +2 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +2 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +7 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +3 -0
- package/resources/index.mjs.map +1 -0
- package/src/api-promise.ts +92 -0
- package/src/client.ts +646 -0
- package/src/error.ts +130 -0
- package/src/index.ts +22 -0
- package/src/internal/builtin-types.ts +79 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +22 -0
- package/src/internal/headers.ts +96 -0
- package/src/internal/parse.ts +41 -0
- package/src/internal/polyfill/crypto.node.d.ts +10 -0
- package/src/internal/polyfill/crypto.node.js +11 -0
- package/src/internal/polyfill/crypto.node.mjs +2 -0
- package/src/internal/polyfill/file.node.d.ts +9 -0
- package/src/internal/polyfill/file.node.js +17 -0
- package/src/internal/polyfill/file.node.mjs +9 -0
- package/src/internal/request-options.ts +67 -0
- package/src/internal/shim-types.d.ts +28 -0
- package/src/internal/shims.ts +145 -0
- package/src/internal/types.ts +98 -0
- package/src/internal/uploads.ts +307 -0
- package/src/internal/utils/base64.ts +37 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +49 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +13 -0
- package/src/internal/utils/values.ts +94 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +11 -0
- package/src/resources/calls.ts +118 -0
- package/src/resources/index.ts +3 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +1 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
export function getDefaultFetch() {
|
3
|
+
if (typeof fetch !== 'undefined') {
|
4
|
+
return fetch;
|
5
|
+
}
|
6
|
+
throw new Error('`fetch` is not defined as a global; Either pass `fetch` to the client, `new Petstore({ fetch })` or polyfill the global, `globalThis.fetch = fetch`');
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* Determines if the given value looks like a NodeJS `stream.Readable`
|
10
|
+
* object and that it is readable, i.e. has not been consumed.
|
11
|
+
*
|
12
|
+
* https://nodejs.org/api/stream.html#class-streamreadable
|
13
|
+
*/
|
14
|
+
export function isReadableLike(value) {
|
15
|
+
// We declare our own class of Readable here, so it's not feasible to
|
16
|
+
// do an 'instanceof' check. Instead, check for Readable-like properties.
|
17
|
+
return !!value && value.readable === true && typeof value.read === 'function';
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* Determines if the given value looks like a NodeJS `fs.ReadStream`
|
21
|
+
* object.
|
22
|
+
*
|
23
|
+
* This just checks if the object matches our `Readable` interface
|
24
|
+
* and defines a `path` property, there may be false positives.
|
25
|
+
*
|
26
|
+
* https://nodejs.org/api/fs.html#class-fsreadstream
|
27
|
+
*/
|
28
|
+
export function isFsReadStreamLike(value) {
|
29
|
+
return isReadableLike(value) && 'path' in value;
|
30
|
+
}
|
31
|
+
export function makeReadableStream(...args) {
|
32
|
+
const ReadableStream = globalThis.ReadableStream;
|
33
|
+
if (typeof ReadableStream === 'undefined') {
|
34
|
+
// Note: All of the platforms / runtimes we officially support already define
|
35
|
+
// `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
|
36
|
+
throw new Error('`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`');
|
37
|
+
}
|
38
|
+
return new ReadableStream(...args);
|
39
|
+
}
|
40
|
+
export function ReadableStreamFrom(iterable) {
|
41
|
+
let iter = Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
42
|
+
return makeReadableStream({
|
43
|
+
start() { },
|
44
|
+
async pull(controller) {
|
45
|
+
const { done, value } = await iter.next();
|
46
|
+
if (done) {
|
47
|
+
controller.close();
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
controller.enqueue(value);
|
51
|
+
}
|
52
|
+
},
|
53
|
+
async cancel() {
|
54
|
+
await iter.return?.();
|
55
|
+
},
|
56
|
+
});
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
60
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
61
|
+
*
|
62
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
63
|
+
*/
|
64
|
+
export function ReadableStreamToAsyncIterable(stream) {
|
65
|
+
if (stream[Symbol.asyncIterator])
|
66
|
+
return stream;
|
67
|
+
const reader = stream.getReader();
|
68
|
+
return {
|
69
|
+
async next() {
|
70
|
+
try {
|
71
|
+
const result = await reader.read();
|
72
|
+
if (result?.done)
|
73
|
+
reader.releaseLock(); // release lock when stream becomes closed
|
74
|
+
return result;
|
75
|
+
}
|
76
|
+
catch (e) {
|
77
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
78
|
+
throw e;
|
79
|
+
}
|
80
|
+
},
|
81
|
+
async return() {
|
82
|
+
const cancelPromise = reader.cancel();
|
83
|
+
reader.releaseLock();
|
84
|
+
await cancelPromise;
|
85
|
+
return { done: true, value: undefined };
|
86
|
+
},
|
87
|
+
[Symbol.asyncIterator]() {
|
88
|
+
return this;
|
89
|
+
},
|
90
|
+
};
|
91
|
+
}
|
92
|
+
//# sourceMappingURL=shims.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shims.mjs","sourceRoot":"","sources":["../src/internal/shims.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAYtF,MAAM,UAAU,eAAe;IAC7B,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAChC,OAAO,KAAY,CAAC;KACrB;IAED,MAAM,IAAI,KAAK,CACb,qJAAqJ,CACtJ,CAAC;AACJ,CAAC;AAwBD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAU;IACvC,qEAAqE;IACrE,yEAAyE;IACzE,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAChF,CAAC;AAWD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAU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ACR,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBACnC,IAAI,MAAM,EAAE,IAAI;oBAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,0CAA0C;gBAClF,OAAO,MAAM,CAAC;aACf;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,2CAA2C;gBACjE,MAAM,CAAC,CAAC;aACT;QACH,CAAC;QACD,KAAK,CAAC,MAAM;YACV,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,aAAa,CAAC;YACpB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC1C,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
3
|
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
4
|
+
export type KeysEnum<T> = {
|
5
|
+
[P in keyof Required<T>]: true;
|
6
|
+
};
|
7
|
+
type NotAny<T> = [unknown] extends [T] ? never : T;
|
8
|
+
type Literal<T> = PropertyKey extends T ? never : T;
|
9
|
+
type MappedLiteralKeys<T> = T extends any ? Literal<keyof T> : never;
|
10
|
+
type MappedIndex<T, K> = T extends any ? K extends keyof T ? T[K] : never : never;
|
11
|
+
/**
|
12
|
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
13
|
+
*/
|
14
|
+
type OverloadedParameters<T> = T extends ({
|
15
|
+
(...args: infer A): unknown;
|
16
|
+
(...args: infer B): unknown;
|
17
|
+
(...args: infer C): unknown;
|
18
|
+
(...args: infer D): unknown;
|
19
|
+
}) ? A | B | C | D : T extends ({
|
20
|
+
(...args: infer A): unknown;
|
21
|
+
(...args: infer B): unknown;
|
22
|
+
(...args: infer C): unknown;
|
23
|
+
}) ? A | B | C : T extends ({
|
24
|
+
(...args: infer A): unknown;
|
25
|
+
(...args: infer B): unknown;
|
26
|
+
}) ? A | B : T extends (...args: infer A) => unknown ? A : never;
|
27
|
+
/**
|
28
|
+
* These imports attempt to get types from a parent package's dependencies.
|
29
|
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
30
|
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
31
|
+
* directly from parent node_modules folders.
|
32
|
+
*
|
33
|
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
34
|
+
* For example, pnpm generates directories like this:
|
35
|
+
* ```
|
36
|
+
* node_modules
|
37
|
+
* ├── .pnpm
|
38
|
+
* │ └── pkg@1.0.0
|
39
|
+
* │ └── node_modules
|
40
|
+
* │ └── pkg
|
41
|
+
* │ └── internal
|
42
|
+
* │ └── types.d.ts
|
43
|
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
44
|
+
* └── undici
|
45
|
+
* ```
|
46
|
+
*
|
47
|
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
48
|
+
*/
|
49
|
+
/** @ts-ignore For users with \@types/node */
|
50
|
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
|
51
|
+
/** @ts-ignore For users with undici */
|
52
|
+
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
|
53
|
+
/** @ts-ignore For users with \@types/bun */
|
54
|
+
type BunRequestInit = globalThis.FetchRequestInit;
|
55
|
+
/** @ts-ignore For users with node-fetch */
|
56
|
+
type NodeFetchRequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
57
|
+
/** @ts-ignore For users who use Deno */
|
58
|
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
59
|
+
type RequestInits = NotAny<UndiciTypesRequestInit> | NotAny<UndiciRequestInit> | NotAny<BunRequestInit> | NotAny<NodeFetchRequestInit> | NotAny<RequestInit> | NotAny<FetchRequestInit>;
|
60
|
+
/**
|
61
|
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
62
|
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
63
|
+
*/
|
64
|
+
export type MergedRequestInit = {
|
65
|
+
[K in MappedLiteralKeys<RequestInits>]?: MappedIndex<RequestInits, K> | undefined;
|
66
|
+
};
|
67
|
+
export {};
|
68
|
+
//# sourceMappingURL=types.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/internal/types.ts"],"names":[],"mappings":";AAEA,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;CAAE,CAAC;AAE7D,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AACnD,KAAK,OAAO,CAAC,CAAC,IAAI,WAAW,SAAS,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AACpD,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC;AACrE,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,IACnB,CAAC,SAAS,GAAG,GACX,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,GACJ,KAAK,GACP,KAAK,CAAC;AAEV;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,IACzB,CAAC,SAAS,CACR;IACE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;IAC5B,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;IAC5B,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;IAC5B,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,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,KAAK,YAAY,GACb,MAAM,CAAC,sBAAsB,CAAC,GAC9B,MAAM,CAAC,iBAAiB,CAAC,GACzB,MAAM,CAAC,cAAc,CAAC,GACtB,MAAM,CAAC,oBAAoB,CAAC,GAC5B,MAAM,CAAC,WAAW,CAAC,GACnB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;KAC7B,CAAC,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,GAAG,SAAS;CAClF,CAAC"}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
3
|
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
4
|
+
export type KeysEnum<T> = {
|
5
|
+
[P in keyof Required<T>]: true;
|
6
|
+
};
|
7
|
+
type NotAny<T> = [unknown] extends [T] ? never : T;
|
8
|
+
type Literal<T> = PropertyKey extends T ? never : T;
|
9
|
+
type MappedLiteralKeys<T> = T extends any ? Literal<keyof T> : never;
|
10
|
+
type MappedIndex<T, K> = T extends any ? K extends keyof T ? T[K] : never : never;
|
11
|
+
/**
|
12
|
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
13
|
+
*/
|
14
|
+
type OverloadedParameters<T> = T extends ({
|
15
|
+
(...args: infer A): unknown;
|
16
|
+
(...args: infer B): unknown;
|
17
|
+
(...args: infer C): unknown;
|
18
|
+
(...args: infer D): unknown;
|
19
|
+
}) ? A | B | C | D : T extends ({
|
20
|
+
(...args: infer A): unknown;
|
21
|
+
(...args: infer B): unknown;
|
22
|
+
(...args: infer C): unknown;
|
23
|
+
}) ? A | B | C : T extends ({
|
24
|
+
(...args: infer A): unknown;
|
25
|
+
(...args: infer B): unknown;
|
26
|
+
}) ? A | B : T extends (...args: infer A) => unknown ? A : never;
|
27
|
+
/**
|
28
|
+
* These imports attempt to get types from a parent package's dependencies.
|
29
|
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
30
|
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
31
|
+
* directly from parent node_modules folders.
|
32
|
+
*
|
33
|
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
34
|
+
* For example, pnpm generates directories like this:
|
35
|
+
* ```
|
36
|
+
* node_modules
|
37
|
+
* ├── .pnpm
|
38
|
+
* │ └── pkg@1.0.0
|
39
|
+
* │ └── node_modules
|
40
|
+
* │ └── pkg
|
41
|
+
* │ └── internal
|
42
|
+
* │ └── types.d.ts
|
43
|
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
44
|
+
* └── undici
|
45
|
+
* ```
|
46
|
+
*
|
47
|
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
48
|
+
*/
|
49
|
+
/** @ts-ignore For users with \@types/node */
|
50
|
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
|
51
|
+
/** @ts-ignore For users with undici */
|
52
|
+
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
|
53
|
+
/** @ts-ignore For users with \@types/bun */
|
54
|
+
type BunRequestInit = globalThis.FetchRequestInit;
|
55
|
+
/** @ts-ignore For users with node-fetch */
|
56
|
+
type NodeFetchRequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
57
|
+
/** @ts-ignore For users who use Deno */
|
58
|
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
59
|
+
type RequestInits = NotAny<UndiciTypesRequestInit> | NotAny<UndiciRequestInit> | NotAny<BunRequestInit> | NotAny<NodeFetchRequestInit> | NotAny<RequestInit> | NotAny<FetchRequestInit>;
|
60
|
+
/**
|
61
|
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
62
|
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
63
|
+
*/
|
64
|
+
export type MergedRequestInit = {
|
65
|
+
[K in MappedLiteralKeys<RequestInits>]?: MappedIndex<RequestInits, K> | undefined;
|
66
|
+
};
|
67
|
+
export {};
|
68
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/internal/types.ts"],"names":[],"mappings":";AAEA,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,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MAAM,MAAM,iBAAiB,GAAG;KAC7B,CAAC,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,GAAG,SAAS;CAClF,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/internal/types.ts"],"names":[],"mappings":";AAAA,sFAAsF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/internal/types.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
import { type RequestOptions } from "./request-options.mjs";
|
4
|
+
import type { FilePropertyBag, Fetch } from "./builtin-types.mjs";
|
5
|
+
import { type FsReadStreamLike } from "./shims.mjs";
|
6
|
+
import type { Petstore } from "../client.mjs";
|
7
|
+
import "./polyfill/file.node.mjs";
|
8
|
+
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
|
9
|
+
type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
10
|
+
/**
|
11
|
+
* Typically, this is a native "File" class.
|
12
|
+
*
|
13
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
14
|
+
* into the File class.
|
15
|
+
*
|
16
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
17
|
+
* the result of fs.createReadStream().
|
18
|
+
*/
|
19
|
+
export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
|
20
|
+
/**
|
21
|
+
* Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
|
22
|
+
* Don't add arrayBuffer here, node-fetch doesn't have it
|
23
|
+
*/
|
24
|
+
interface BlobLike {
|
25
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
26
|
+
readonly size: number;
|
27
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
28
|
+
readonly type: string;
|
29
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
30
|
+
text(): Promise<string>;
|
31
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
32
|
+
slice(start?: number, end?: number): BlobLike;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Intended to match DOM File, node:buffer File, undici File, etc.
|
36
|
+
*/
|
37
|
+
interface FileLike extends BlobLike {
|
38
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
39
|
+
readonly lastModified: number;
|
40
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
41
|
+
readonly name: string;
|
42
|
+
}
|
43
|
+
/**
|
44
|
+
* Intended to match DOM Response, node-fetch Response, undici Response, etc.
|
45
|
+
*/
|
46
|
+
export interface ResponseLike {
|
47
|
+
url: string;
|
48
|
+
blob(): Promise<BlobLike>;
|
49
|
+
}
|
50
|
+
type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
51
|
+
/**
|
52
|
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
53
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
54
|
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
55
|
+
* @param {Object=} options additional properties
|
56
|
+
* @param {string=} options.type the MIME type of the content
|
57
|
+
* @param {number=} options.lastModified the last modified timestamp
|
58
|
+
* @returns a {@link File} with the given properties
|
59
|
+
*/
|
60
|
+
export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
|
61
|
+
export declare function getBytes(value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>>;
|
62
|
+
/**
|
63
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
64
|
+
* Otherwise returns the request as is.
|
65
|
+
*/
|
66
|
+
export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Petstore | Fetch) => Promise<RequestOptions>;
|
67
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
|
68
|
+
body: unknown;
|
69
|
+
};
|
70
|
+
export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Petstore | Fetch) => Promise<RequestOptions>;
|
71
|
+
export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Petstore | Fetch) => Promise<FormData>;
|
72
|
+
export {};
|
73
|
+
//# sourceMappingURL=uploads.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"uploads.d.mts","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;OAAO,EAAE,KAAK,cAAc,EAAE;OACvB,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;OAC/B,EAAsB,KAAK,gBAAgB,EAAE;OAC7C,KAAK,EAAE,QAAQ,EAAE;;AAGxB,KAAK,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACjF,KAAK,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,QAAQ,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAEpE;;;GAGG;AACH,UAAU,QAAQ;IAChB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,6EAA6E;IAC7E,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,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73 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
import { type RequestOptions } from "./request-options.js";
|
4
|
+
import type { FilePropertyBag, Fetch } from "./builtin-types.js";
|
5
|
+
import { type FsReadStreamLike } from "./shims.js";
|
6
|
+
import type { Petstore } from "../client.js";
|
7
|
+
import "./polyfill/file.node.js";
|
8
|
+
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
|
9
|
+
type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
10
|
+
/**
|
11
|
+
* Typically, this is a native "File" class.
|
12
|
+
*
|
13
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
14
|
+
* into the File class.
|
15
|
+
*
|
16
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
17
|
+
* the result of fs.createReadStream().
|
18
|
+
*/
|
19
|
+
export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
|
20
|
+
/**
|
21
|
+
* Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
|
22
|
+
* Don't add arrayBuffer here, node-fetch doesn't have it
|
23
|
+
*/
|
24
|
+
interface BlobLike {
|
25
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
26
|
+
readonly size: number;
|
27
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
28
|
+
readonly type: string;
|
29
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
30
|
+
text(): Promise<string>;
|
31
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
32
|
+
slice(start?: number, end?: number): BlobLike;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Intended to match DOM File, node:buffer File, undici File, etc.
|
36
|
+
*/
|
37
|
+
interface FileLike extends BlobLike {
|
38
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
39
|
+
readonly lastModified: number;
|
40
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
41
|
+
readonly name: string;
|
42
|
+
}
|
43
|
+
/**
|
44
|
+
* Intended to match DOM Response, node-fetch Response, undici Response, etc.
|
45
|
+
*/
|
46
|
+
export interface ResponseLike {
|
47
|
+
url: string;
|
48
|
+
blob(): Promise<BlobLike>;
|
49
|
+
}
|
50
|
+
type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
51
|
+
/**
|
52
|
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
53
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
54
|
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
55
|
+
* @param {Object=} options additional properties
|
56
|
+
* @param {string=} options.type the MIME type of the content
|
57
|
+
* @param {number=} options.lastModified the last modified timestamp
|
58
|
+
* @returns a {@link File} with the given properties
|
59
|
+
*/
|
60
|
+
export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
|
61
|
+
export declare function getBytes(value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>>;
|
62
|
+
/**
|
63
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
64
|
+
* Otherwise returns the request as is.
|
65
|
+
*/
|
66
|
+
export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Petstore | Fetch) => Promise<RequestOptions>;
|
67
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
|
68
|
+
body: unknown;
|
69
|
+
};
|
70
|
+
export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Petstore | Fetch) => Promise<RequestOptions>;
|
71
|
+
export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Petstore | Fetch) => Promise<FormData>;
|
72
|
+
export {};
|
73
|
+
//# s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AAa,CAAC,YAAY,CAAC,CAAC;AAgB5F;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,EAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,GACpC,OAAO,CAAC,QAAQ,CAAC,CAgCnB;AAED,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,GAC7D,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CA0B1B;AAsBD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,SACrC,cAAc,SACb,QAAQ,GAAG,KAAK,KACtB,QAAQ,cAAc,CAIxB,CAAC;AAEF,KAAK,2BAA2B,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,2BAA2B,SAChC,2BAA2B,SAC1B,QAAQ,GAAG,KAAK,KACtB,QAAQ,cAAc,CAExB,CAAC;AAkCF,eAAO,MAAM,UAAU,4DAEd,QAAQ,GAAG,KAAK,KACtB,QAAQ,QAAQ,CASlB,CAAC"}
|
@@ -0,0 +1,208 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.getBytes = exports.toFile = void 0;
|
4
|
+
const shims_1 = require("./shims.js");
|
5
|
+
require("./polyfill/file.node.js");
|
6
|
+
/**
|
7
|
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
8
|
+
*/
|
9
|
+
const isBlobLike = (value) => value != null &&
|
10
|
+
typeof value === 'object' &&
|
11
|
+
typeof value.size === 'number' &&
|
12
|
+
typeof value.type === 'string' &&
|
13
|
+
typeof value.text === 'function' &&
|
14
|
+
typeof value.slice === 'function' &&
|
15
|
+
typeof value.arrayBuffer === 'function';
|
16
|
+
/**
|
17
|
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
18
|
+
*/
|
19
|
+
const isFileLike = (value) => value != null &&
|
20
|
+
typeof value === 'object' &&
|
21
|
+
typeof value.name === 'string' &&
|
22
|
+
typeof value.lastModified === 'number' &&
|
23
|
+
isBlobLike(value);
|
24
|
+
const isResponseLike = (value) => value != null &&
|
25
|
+
typeof value === 'object' &&
|
26
|
+
typeof value.url === 'string' &&
|
27
|
+
typeof value.blob === 'function';
|
28
|
+
const isUploadable = (value) => {
|
29
|
+
return isFileLike(value) || isResponseLike(value) || (0, shims_1.isFsReadStreamLike)(value);
|
30
|
+
};
|
31
|
+
/**
|
32
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
33
|
+
* for environments that don't define a global `File` yet and so that we don't
|
34
|
+
* accidentally rely on a global `File` type in our annotations.
|
35
|
+
*/
|
36
|
+
function makeFile(fileBits, fileName, options) {
|
37
|
+
const File = globalThis.File;
|
38
|
+
if (typeof File === 'undefined') {
|
39
|
+
throw new Error('`File` is not defined as a global which is required for file uploads');
|
40
|
+
}
|
41
|
+
return new File(fileBits, fileName, options);
|
42
|
+
}
|
43
|
+
/**
|
44
|
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
45
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
46
|
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
47
|
+
* @param {Object=} options additional properties
|
48
|
+
* @param {string=} options.type the MIME type of the content
|
49
|
+
* @param {number=} options.lastModified the last modified timestamp
|
50
|
+
* @returns a {@link File} with the given properties
|
51
|
+
*/
|
52
|
+
async function toFile(value, name, options) {
|
53
|
+
// If it's a promise, resolve it.
|
54
|
+
value = await value;
|
55
|
+
// If we've been given a `File` we don't need to do anything
|
56
|
+
if (isFileLike(value)) {
|
57
|
+
const File = globalThis.File;
|
58
|
+
if (File && value instanceof File) {
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
return makeFile([await value.arrayBuffer()], value.name);
|
62
|
+
}
|
63
|
+
if (isResponseLike(value)) {
|
64
|
+
const blob = await value.blob();
|
65
|
+
name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
|
66
|
+
return makeFile(await getBytes(blob), name, options);
|
67
|
+
}
|
68
|
+
const parts = await getBytes(value);
|
69
|
+
name || (name = getName(value) ?? 'unknown_file');
|
70
|
+
if (!options?.type) {
|
71
|
+
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
72
|
+
if (typeof type === 'string') {
|
73
|
+
options = { ...options, type };
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return makeFile(parts, name, options);
|
77
|
+
}
|
78
|
+
exports.toFile = toFile;
|
79
|
+
async function getBytes(value) {
|
80
|
+
let parts = [];
|
81
|
+
if (typeof value === 'string' ||
|
82
|
+
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
83
|
+
value instanceof ArrayBuffer) {
|
84
|
+
parts.push(value);
|
85
|
+
}
|
86
|
+
else if (isBlobLike(value)) {
|
87
|
+
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
88
|
+
}
|
89
|
+
else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
90
|
+
) {
|
91
|
+
for await (const chunk of value) {
|
92
|
+
parts.push(...(await getBytes(chunk))); // TODO, consider validating?
|
93
|
+
}
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
const constructor = value?.constructor?.name;
|
97
|
+
throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
|
98
|
+
}
|
99
|
+
return parts;
|
100
|
+
}
|
101
|
+
exports.getBytes = getBytes;
|
102
|
+
function propsForError(value) {
|
103
|
+
if (typeof value !== 'object' || value === null)
|
104
|
+
return '';
|
105
|
+
const props = Object.getOwnPropertyNames(value);
|
106
|
+
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
107
|
+
}
|
108
|
+
function getName(value) {
|
109
|
+
return ((typeof value === 'object' &&
|
110
|
+
value !== null &&
|
111
|
+
(('name' in value && String(value.name)) ||
|
112
|
+
('filename' in value && String(value.filename)) ||
|
113
|
+
('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
|
114
|
+
undefined);
|
115
|
+
}
|
116
|
+
const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
117
|
+
/**
|
118
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
119
|
+
* Otherwise returns the request as is.
|
120
|
+
*/
|
121
|
+
const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
122
|
+
if (!hasUploadableValue(opts.body))
|
123
|
+
return opts;
|
124
|
+
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
125
|
+
};
|
126
|
+
exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
|
127
|
+
const multipartFormRequestOptions = async (opts, fetch) => {
|
128
|
+
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
129
|
+
};
|
130
|
+
exports.multipartFormRequestOptions = multipartFormRequestOptions;
|
131
|
+
const supportsFormDataMap = new WeakMap();
|
132
|
+
/**
|
133
|
+
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
134
|
+
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
135
|
+
* This function detects if the fetch function provided supports the global FormData object to avoid
|
136
|
+
* confusing error messages later on.
|
137
|
+
*/
|
138
|
+
function supportsFormData(fetchObject) {
|
139
|
+
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
140
|
+
const cached = supportsFormDataMap.get(fetch);
|
141
|
+
if (cached)
|
142
|
+
return cached;
|
143
|
+
const promise = (async () => {
|
144
|
+
try {
|
145
|
+
const FetchResponse = ('Response' in fetch ?
|
146
|
+
fetch.Response
|
147
|
+
: (await fetch('data:,')).constructor);
|
148
|
+
const data = new FormData();
|
149
|
+
if (data.toString() === (await new FetchResponse(data).text())) {
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
return true;
|
153
|
+
}
|
154
|
+
catch {
|
155
|
+
// avoid false negatives
|
156
|
+
return true;
|
157
|
+
}
|
158
|
+
})();
|
159
|
+
supportsFormDataMap.set(fetch, promise);
|
160
|
+
return promise;
|
161
|
+
}
|
162
|
+
const createForm = async (body, fetch) => {
|
163
|
+
if (!(await supportsFormData(fetch))) {
|
164
|
+
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
165
|
+
}
|
166
|
+
const form = new FormData();
|
167
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
168
|
+
return form;
|
169
|
+
};
|
170
|
+
exports.createForm = createForm;
|
171
|
+
const hasUploadableValue = (value) => {
|
172
|
+
if (isUploadable(value))
|
173
|
+
return true;
|
174
|
+
if (Array.isArray(value))
|
175
|
+
return value.some(hasUploadableValue);
|
176
|
+
if (value && typeof value === 'object') {
|
177
|
+
for (const k in value) {
|
178
|
+
if (hasUploadableValue(value[k]))
|
179
|
+
return true;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return false;
|
183
|
+
};
|
184
|
+
const addFormValue = async (form, key, value) => {
|
185
|
+
if (value === undefined)
|
186
|
+
return;
|
187
|
+
if (value == null) {
|
188
|
+
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
189
|
+
}
|
190
|
+
// TODO: make nested formats configurable
|
191
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
192
|
+
form.append(key, String(value));
|
193
|
+
}
|
194
|
+
else if (isUploadable(value)) {
|
195
|
+
const file = await toFile(value);
|
196
|
+
form.append(key, file);
|
197
|
+
}
|
198
|
+
else if (Array.isArray(value)) {
|
199
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
200
|
+
}
|
201
|
+
else if (typeof value === 'object') {
|
202
|
+
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
203
|
+
}
|
204
|
+
else {
|
205
|
+
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
206
|
+
}
|
207
|
+
};
|
208
|
+
//# sourceMappingURL=uploads.js.map
|