@roarkanalytics/sdk 0.1.0-alpha.1 → 0.1.0-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/LICENSE +1 -1
- package/README.md +48 -85
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/{internal/utils.js → _shims/auto/runtime-bun.js} +5 -8
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +908 -0
- package/core.js.map +1 -0
- package/core.mjs +876 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +3 -3
- package/error.d.ts.map +1 -1
- package/error.js +6 -6
- package/error.js.map +1 -1
- package/error.mjs +3 -3
- package/error.mjs.map +1 -1
- package/index.d.mts +109 -5
- package/index.d.ts +109 -5
- package/index.d.ts.map +1 -1
- package/index.js +103 -11
- package/index.js.map +1 -1
- package/index.mjs +77 -5
- package/index.mjs.map +1 -1
- package/package.json +66 -82
- package/resource.d.ts +3 -3
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/calls.d.ts +2 -3
- package/resources/calls.d.ts.map +1 -1
- package/resources/calls.js.map +1 -1
- package/resources/calls.mjs.map +1 -1
- package/resources/index.d.ts.map +1 -1
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1200 -0
- package/src/error.ts +3 -3
- package/src/index.ts +172 -5
- package/src/resource.ts +3 -3
- package/src/resources/calls.ts +2 -3
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +2 -2
- package/src/uploads.ts +255 -1
- package/src/version.ts +1 -1
- package/uploads.d.ts +74 -1
- package/uploads.d.ts.map +1 -1
- package/uploads.js +168 -3
- package/uploads.js.map +1 -1
- package/uploads.mjs +157 -1
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/api-promise.d.mts +0 -47
- package/api-promise.d.mts.map +0 -1
- package/api-promise.d.ts +0 -47
- package/api-promise.d.ts.map +0 -1
- package/api-promise.js +0 -84
- package/api-promise.js.map +0 -1
- package/api-promise.mjs +0 -80
- package/api-promise.mjs.map +0 -1
- package/client.d.mts +0 -186
- package/client.d.mts.map +0 -1
- package/client.d.ts +0 -186
- package/client.d.ts.map +0 -1
- package/client.js +0 -449
- package/client.js.map +0 -1
- package/client.mjs +0 -422
- package/client.mjs.map +0 -1
- package/error.d.mts +0 -47
- package/error.d.mts.map +0 -1
- package/index.d.mts.map +0 -1
- package/internal/builtin-types.d.mts +0 -65
- package/internal/builtin-types.d.mts.map +0 -1
- package/internal/builtin-types.d.ts +0 -65
- package/internal/builtin-types.d.ts.map +0 -1
- package/internal/builtin-types.js +0 -4
- package/internal/builtin-types.js.map +0 -1
- package/internal/builtin-types.mjs +0 -3
- package/internal/builtin-types.mjs.map +0 -1
- package/internal/detect-platform.d.mts +0 -15
- package/internal/detect-platform.d.mts.map +0 -1
- package/internal/detect-platform.d.ts +0 -15
- package/internal/detect-platform.d.ts.map +0 -1
- package/internal/detect-platform.js +0 -162
- package/internal/detect-platform.js.map +0 -1
- package/internal/detect-platform.mjs +0 -157
- package/internal/detect-platform.mjs.map +0 -1
- package/internal/errors.d.mts +0 -3
- package/internal/errors.d.mts.map +0 -1
- package/internal/errors.d.ts +0 -3
- package/internal/errors.d.ts.map +0 -1
- package/internal/errors.js +0 -26
- package/internal/errors.js.map +0 -1
- package/internal/errors.mjs +0 -21
- package/internal/errors.mjs.map +0 -1
- package/internal/headers.d.mts +0 -21
- package/internal/headers.d.mts.map +0 -1
- package/internal/headers.d.ts +0 -21
- package/internal/headers.d.ts.map +0 -1
- package/internal/headers.js +0 -77
- package/internal/headers.js.map +0 -1
- package/internal/headers.mjs +0 -72
- package/internal/headers.mjs.map +0 -1
- package/internal/parse.d.mts +0 -10
- package/internal/parse.d.mts.map +0 -1
- package/internal/parse.d.ts +0 -10
- package/internal/parse.d.ts.map +0 -1
- package/internal/parse.js +0 -28
- package/internal/parse.js.map +0 -1
- package/internal/parse.mjs +0 -24
- package/internal/parse.mjs.map +0 -1
- package/internal/polyfill/crypto.node.d.ts +0 -10
- package/internal/polyfill/crypto.node.js +0 -11
- package/internal/polyfill/crypto.node.mjs +0 -2
- package/internal/polyfill/file.node.d.ts +0 -9
- package/internal/polyfill/file.node.js +0 -17
- package/internal/polyfill/file.node.mjs +0 -9
- package/internal/request-options.d.mts +0 -34
- package/internal/request-options.d.mts.map +0 -1
- package/internal/request-options.d.ts +0 -34
- package/internal/request-options.d.ts.map +0 -1
- package/internal/request-options.js +0 -39
- package/internal/request-options.js.map +0 -1
- package/internal/request-options.mjs +0 -34
- package/internal/request-options.mjs.map +0 -1
- package/internal/shim-types.d.mts +0 -28
- package/internal/shim-types.d.ts +0 -28
- package/internal/shims.d.mts +0 -61
- package/internal/shims.d.mts.map +0 -1
- package/internal/shims.d.ts +0 -61
- package/internal/shims.d.ts.map +0 -1
- package/internal/shims.js +0 -101
- package/internal/shims.js.map +0 -1
- package/internal/shims.mjs +0 -92
- package/internal/shims.mjs.map +0 -1
- package/internal/types.d.mts +0 -68
- package/internal/types.d.mts.map +0 -1
- package/internal/types.d.ts +0 -68
- package/internal/types.d.ts.map +0 -1
- package/internal/types.js +0 -4
- package/internal/types.js.map +0 -1
- package/internal/types.mjs +0 -3
- package/internal/types.mjs.map +0 -1
- package/internal/uploads.d.mts +0 -73
- package/internal/uploads.d.mts.map +0 -1
- package/internal/uploads.d.ts +0 -73
- package/internal/uploads.d.ts.map +0 -1
- package/internal/uploads.js +0 -208
- package/internal/uploads.js.map +0 -1
- package/internal/uploads.mjs +0 -200
- package/internal/uploads.mjs.map +0 -1
- package/internal/utils/base64.d.mts +0 -3
- package/internal/utils/base64.d.mts.map +0 -1
- package/internal/utils/base64.d.ts +0 -3
- package/internal/utils/base64.d.ts.map +0 -1
- package/internal/utils/base64.js +0 -33
- package/internal/utils/base64.js.map +0 -1
- package/internal/utils/base64.mjs +0 -28
- package/internal/utils/base64.mjs.map +0 -1
- package/internal/utils/env.d.mts +0 -9
- package/internal/utils/env.d.mts.map +0 -1
- package/internal/utils/env.d.ts +0 -9
- package/internal/utils/env.d.ts.map +0 -1
- package/internal/utils/env.js +0 -22
- package/internal/utils/env.js.map +0 -1
- package/internal/utils/env.mjs +0 -18
- package/internal/utils/env.mjs.map +0 -1
- package/internal/utils/log.d.mts +0 -4
- package/internal/utils/log.d.mts.map +0 -1
- package/internal/utils/log.d.ts +0 -4
- package/internal/utils/log.d.ts.map +0 -1
- package/internal/utils/log.js +0 -47
- package/internal/utils/log.js.map +0 -1
- package/internal/utils/log.mjs +0 -43
- package/internal/utils/log.mjs.map +0 -1
- package/internal/utils/sleep.d.mts +0 -2
- package/internal/utils/sleep.d.mts.map +0 -1
- package/internal/utils/sleep.d.ts +0 -2
- package/internal/utils/sleep.d.ts.map +0 -1
- package/internal/utils/sleep.js +0 -7
- package/internal/utils/sleep.js.map +0 -1
- package/internal/utils/sleep.mjs +0 -3
- package/internal/utils/sleep.mjs.map +0 -1
- package/internal/utils/uuid.d.mts +0 -5
- package/internal/utils/uuid.d.mts.map +0 -1
- package/internal/utils/uuid.d.ts +0 -5
- package/internal/utils/uuid.d.ts.map +0 -1
- package/internal/utils/uuid.js +0 -15
- package/internal/utils/uuid.js.map +0 -1
- package/internal/utils/uuid.mjs +0 -11
- package/internal/utils/uuid.mjs.map +0 -1
- package/internal/utils/values.d.mts +0 -15
- package/internal/utils/values.d.mts.map +0 -1
- package/internal/utils/values.d.ts +0 -15
- package/internal/utils/values.d.ts.map +0 -1
- package/internal/utils/values.js +0 -100
- package/internal/utils/values.js.map +0 -1
- package/internal/utils/values.mjs +0 -84
- package/internal/utils/values.mjs.map +0 -1
- package/internal/utils.d.mts +0 -7
- package/internal/utils.d.mts.map +0 -1
- package/internal/utils.d.ts +0 -7
- package/internal/utils.d.ts.map +0 -1
- package/internal/utils.js.map +0 -1
- package/internal/utils.mjs +0 -8
- package/internal/utils.mjs.map +0 -1
- package/resource.d.mts +0 -6
- package/resource.d.mts.map +0 -1
- package/resources/calls.d.mts +0 -85
- package/resources/calls.d.mts.map +0 -1
- package/resources/index.d.mts +0 -2
- package/resources/index.d.mts.map +0 -1
- package/src/api-promise.ts +0 -92
- package/src/client.ts +0 -646
- package/src/internal/builtin-types.ts +0 -79
- package/src/internal/detect-platform.ts +0 -196
- package/src/internal/errors.ts +0 -22
- package/src/internal/headers.ts +0 -96
- package/src/internal/parse.ts +0 -41
- package/src/internal/polyfill/crypto.node.d.ts +0 -10
- package/src/internal/polyfill/crypto.node.js +0 -11
- package/src/internal/polyfill/crypto.node.mjs +0 -2
- package/src/internal/polyfill/file.node.d.ts +0 -9
- package/src/internal/polyfill/file.node.js +0 -17
- package/src/internal/polyfill/file.node.mjs +0 -9
- package/src/internal/request-options.ts +0 -67
- package/src/internal/shim-types.d.ts +0 -28
- package/src/internal/shims.ts +0 -145
- package/src/internal/types.ts +0 -98
- package/src/internal/uploads.ts +0 -307
- package/src/internal/utils/base64.ts +0 -37
- package/src/internal/utils/env.ts +0 -18
- package/src/internal/utils/log.ts +0 -49
- package/src/internal/utils/sleep.ts +0 -3
- package/src/internal/utils/uuid.ts +0 -13
- package/src/internal/utils/values.ts +0 -94
- package/src/internal/utils.ts +0 -8
- package/uploads.d.mts +0 -2
- package/uploads.d.mts.map +0 -1
- package/version.d.mts +0 -2
- package/version.d.mts.map +0 -1
package/src/internal/shims.ts
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
/**
|
4
|
-
* This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
|
5
|
-
*
|
6
|
-
* These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error
|
7
|
-
* messages in cases where an environment isn't fully supported.
|
8
|
-
*/
|
9
|
-
|
10
|
-
import { type Fetch } from './builtin-types';
|
11
|
-
import { type ReadableStream } from './shim-types';
|
12
|
-
|
13
|
-
export function getDefaultFetch(): Fetch {
|
14
|
-
if (typeof fetch !== 'undefined') {
|
15
|
-
return fetch as any;
|
16
|
-
}
|
17
|
-
|
18
|
-
throw new Error(
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Petstore({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
20
|
-
);
|
21
|
-
}
|
22
|
-
|
23
|
-
/**
|
24
|
-
* A minimal copy of the NodeJS `stream.Readable` class so that we can
|
25
|
-
* accept the NodeJS types in certain places, e.g. file uploads
|
26
|
-
*
|
27
|
-
* https://nodejs.org/api/stream.html#class-streamreadable
|
28
|
-
*/
|
29
|
-
export interface ReadableLike {
|
30
|
-
readable: boolean;
|
31
|
-
readonly readableEnded: boolean;
|
32
|
-
readonly readableFlowing: boolean | null;
|
33
|
-
readonly readableHighWaterMark: number;
|
34
|
-
readonly readableLength: number;
|
35
|
-
readonly readableObjectMode: boolean;
|
36
|
-
destroyed: boolean;
|
37
|
-
read(size?: number): any;
|
38
|
-
pause(): this;
|
39
|
-
resume(): this;
|
40
|
-
isPaused(): boolean;
|
41
|
-
destroy(error?: Error): this;
|
42
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
43
|
-
}
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Determines if the given value looks like a NodeJS `stream.Readable`
|
47
|
-
* object and that it is readable, i.e. has not been consumed.
|
48
|
-
*
|
49
|
-
* https://nodejs.org/api/stream.html#class-streamreadable
|
50
|
-
*/
|
51
|
-
export function isReadableLike(value: any) {
|
52
|
-
// We declare our own class of Readable here, so it's not feasible to
|
53
|
-
// do an 'instanceof' check. Instead, check for Readable-like properties.
|
54
|
-
return !!value && value.readable === true && typeof value.read === 'function';
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* A minimal copy of the NodeJS `fs.ReadStream` class for usage within file uploads.
|
59
|
-
*
|
60
|
-
* https://nodejs.org/api/fs.html#class-fsreadstream
|
61
|
-
*/
|
62
|
-
export interface FsReadStreamLike extends ReadableLike {
|
63
|
-
path: {}; // real type is string | Buffer but we can't reference `Buffer` here
|
64
|
-
}
|
65
|
-
|
66
|
-
/**
|
67
|
-
* Determines if the given value looks like a NodeJS `fs.ReadStream`
|
68
|
-
* object.
|
69
|
-
*
|
70
|
-
* This just checks if the object matches our `Readable` interface
|
71
|
-
* and defines a `path` property, there may be false positives.
|
72
|
-
*
|
73
|
-
* https://nodejs.org/api/fs.html#class-fsreadstream
|
74
|
-
*/
|
75
|
-
export function isFsReadStreamLike(value: any): value is FsReadStreamLike {
|
76
|
-
return isReadableLike(value) && 'path' in value;
|
77
|
-
}
|
78
|
-
|
79
|
-
type ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;
|
80
|
-
|
81
|
-
export function makeReadableStream(...args: ReadableStreamArgs): ReadableStream {
|
82
|
-
const ReadableStream = (globalThis as any).ReadableStream;
|
83
|
-
if (typeof ReadableStream === 'undefined') {
|
84
|
-
// Note: All of the platforms / runtimes we officially support already define
|
85
|
-
// `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
|
86
|
-
throw new Error(
|
87
|
-
'`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`',
|
88
|
-
);
|
89
|
-
}
|
90
|
-
|
91
|
-
return new ReadableStream(...args);
|
92
|
-
}
|
93
|
-
|
94
|
-
export function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T> {
|
95
|
-
let iter: AsyncIterator<T> | Iterator<T> =
|
96
|
-
Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
97
|
-
|
98
|
-
return makeReadableStream({
|
99
|
-
start() {},
|
100
|
-
async pull(controller: any) {
|
101
|
-
const { done, value } = await iter.next();
|
102
|
-
if (done) {
|
103
|
-
controller.close();
|
104
|
-
} else {
|
105
|
-
controller.enqueue(value);
|
106
|
-
}
|
107
|
-
},
|
108
|
-
async cancel() {
|
109
|
-
await iter.return?.();
|
110
|
-
},
|
111
|
-
});
|
112
|
-
}
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Most browsers don't yet have async iterable support for ReadableStream,
|
116
|
-
* and Node has a very different way of reading bytes from its "ReadableStream".
|
117
|
-
*
|
118
|
-
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
119
|
-
*/
|
120
|
-
export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
|
121
|
-
if (stream[Symbol.asyncIterator]) return stream;
|
122
|
-
|
123
|
-
const reader = stream.getReader();
|
124
|
-
return {
|
125
|
-
async next() {
|
126
|
-
try {
|
127
|
-
const result = await reader.read();
|
128
|
-
if (result?.done) reader.releaseLock(); // release lock when stream becomes closed
|
129
|
-
return result;
|
130
|
-
} catch (e) {
|
131
|
-
reader.releaseLock(); // release lock when stream becomes errored
|
132
|
-
throw e;
|
133
|
-
}
|
134
|
-
},
|
135
|
-
async return() {
|
136
|
-
const cancelPromise = reader.cancel();
|
137
|
-
reader.releaseLock();
|
138
|
-
await cancelPromise;
|
139
|
-
return { done: true, value: undefined };
|
140
|
-
},
|
141
|
-
[Symbol.asyncIterator]() {
|
142
|
-
return this;
|
143
|
-
},
|
144
|
-
};
|
145
|
-
}
|
package/src/internal/types.ts
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
export type PromiseOrValue<T> = T | Promise<T>;
|
4
|
-
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
5
|
-
|
6
|
-
export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
7
|
-
|
8
|
-
type NotAny<T> = [unknown] extends [T] ? never : T;
|
9
|
-
type Literal<T> = PropertyKey extends T ? never : T;
|
10
|
-
type MappedLiteralKeys<T> = T extends any ? Literal<keyof T> : never;
|
11
|
-
type MappedIndex<T, K> =
|
12
|
-
T extends any ?
|
13
|
-
K extends keyof T ?
|
14
|
-
T[K]
|
15
|
-
: never
|
16
|
-
: never;
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
20
|
-
*/
|
21
|
-
type OverloadedParameters<T> =
|
22
|
-
T extends (
|
23
|
-
{
|
24
|
-
(...args: infer A): unknown;
|
25
|
-
(...args: infer B): unknown;
|
26
|
-
(...args: infer C): unknown;
|
27
|
-
(...args: infer D): unknown;
|
28
|
-
}
|
29
|
-
) ?
|
30
|
-
A | B | C | D
|
31
|
-
: T extends (
|
32
|
-
{
|
33
|
-
(...args: infer A): unknown;
|
34
|
-
(...args: infer B): unknown;
|
35
|
-
(...args: infer C): unknown;
|
36
|
-
}
|
37
|
-
) ?
|
38
|
-
A | B | C
|
39
|
-
: T extends (
|
40
|
-
{
|
41
|
-
(...args: infer A): unknown;
|
42
|
-
(...args: infer B): unknown;
|
43
|
-
}
|
44
|
-
) ?
|
45
|
-
A | B
|
46
|
-
: T extends (...args: infer A) => unknown ? A
|
47
|
-
: never;
|
48
|
-
|
49
|
-
/* eslint-disable */
|
50
|
-
/**
|
51
|
-
* These imports attempt to get types from a parent package's dependencies.
|
52
|
-
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
53
|
-
* would cause typescript to show types not present at runtime. To avoid this, we import
|
54
|
-
* directly from parent node_modules folders.
|
55
|
-
*
|
56
|
-
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
57
|
-
* For example, pnpm generates directories like this:
|
58
|
-
* ```
|
59
|
-
* node_modules
|
60
|
-
* ├── .pnpm
|
61
|
-
* │ └── pkg@1.0.0
|
62
|
-
* │ └── node_modules
|
63
|
-
* │ └── pkg
|
64
|
-
* │ └── internal
|
65
|
-
* │ └── types.d.ts
|
66
|
-
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
67
|
-
* └── undici
|
68
|
-
* ```
|
69
|
-
*
|
70
|
-
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
71
|
-
*/
|
72
|
-
/** @ts-ignore For users with \@types/node */
|
73
|
-
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>;
|
74
|
-
/** @ts-ignore For users with undici */
|
75
|
-
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>;
|
76
|
-
/** @ts-ignore For users with \@types/bun */
|
77
|
-
type BunRequestInit = globalThis.FetchRequestInit;
|
78
|
-
/** @ts-ignore For users with node-fetch */
|
79
|
-
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>;
|
80
|
-
/** @ts-ignore For users who use Deno */
|
81
|
-
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
82
|
-
/* eslint-enable */
|
83
|
-
|
84
|
-
type RequestInits =
|
85
|
-
| NotAny<UndiciTypesRequestInit>
|
86
|
-
| NotAny<UndiciRequestInit>
|
87
|
-
| NotAny<BunRequestInit>
|
88
|
-
| NotAny<NodeFetchRequestInit>
|
89
|
-
| NotAny<RequestInit>
|
90
|
-
| NotAny<FetchRequestInit>;
|
91
|
-
|
92
|
-
/**
|
93
|
-
* This type contains `RequestInit` options that may be available on the current runtime,
|
94
|
-
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
95
|
-
*/
|
96
|
-
export type MergedRequestInit = {
|
97
|
-
[K in MappedLiteralKeys<RequestInits>]?: MappedIndex<RequestInits, K> | undefined;
|
98
|
-
};
|
package/src/internal/uploads.ts
DELETED
@@ -1,307 +0,0 @@
|
|
1
|
-
import { type RequestOptions } from './request-options';
|
2
|
-
import type { FilePropertyBag, Fetch } from './builtin-types';
|
3
|
-
import { isFsReadStreamLike, type FsReadStreamLike } from './shims';
|
4
|
-
import type { Petstore } from '../client';
|
5
|
-
import './polyfill/file.node.js';
|
6
|
-
|
7
|
-
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
|
8
|
-
type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
9
|
-
|
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
|
-
/**
|
22
|
-
* Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
|
23
|
-
* Don't add arrayBuffer here, node-fetch doesn't have it
|
24
|
-
*/
|
25
|
-
interface BlobLike {
|
26
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
27
|
-
readonly size: number;
|
28
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
29
|
-
readonly type: string;
|
30
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
31
|
-
text(): Promise<string>;
|
32
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
33
|
-
slice(start?: number, end?: number): BlobLike;
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
38
|
-
*/
|
39
|
-
const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
40
|
-
value != null &&
|
41
|
-
typeof value === 'object' &&
|
42
|
-
typeof value.size === 'number' &&
|
43
|
-
typeof value.type === 'string' &&
|
44
|
-
typeof value.text === 'function' &&
|
45
|
-
typeof value.slice === 'function' &&
|
46
|
-
typeof value.arrayBuffer === 'function';
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Intended to match DOM File, node:buffer File, undici File, etc.
|
50
|
-
*/
|
51
|
-
interface FileLike extends BlobLike {
|
52
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
53
|
-
readonly lastModified: number;
|
54
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
55
|
-
readonly name: string;
|
56
|
-
}
|
57
|
-
declare var FileClass: {
|
58
|
-
prototype: FileLike;
|
59
|
-
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike;
|
60
|
-
};
|
61
|
-
|
62
|
-
/**
|
63
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
64
|
-
*/
|
65
|
-
const isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
66
|
-
value != null &&
|
67
|
-
typeof value === 'object' &&
|
68
|
-
typeof value.name === 'string' &&
|
69
|
-
typeof value.lastModified === 'number' &&
|
70
|
-
isBlobLike(value);
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Intended to match DOM Response, node-fetch Response, undici Response, etc.
|
74
|
-
*/
|
75
|
-
export interface ResponseLike {
|
76
|
-
url: string;
|
77
|
-
blob(): Promise<BlobLike>;
|
78
|
-
}
|
79
|
-
|
80
|
-
const isResponseLike = (value: any): value is ResponseLike =>
|
81
|
-
value != null &&
|
82
|
-
typeof value === 'object' &&
|
83
|
-
typeof value.url === 'string' &&
|
84
|
-
typeof value.blob === 'function';
|
85
|
-
|
86
|
-
const isUploadable = (value: any): value is Uploadable => {
|
87
|
-
return isFileLike(value) || isResponseLike(value) || isFsReadStreamLike(value);
|
88
|
-
};
|
89
|
-
|
90
|
-
type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
91
|
-
|
92
|
-
/**
|
93
|
-
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
94
|
-
* for environments that don't define a global `File` yet and so that we don't
|
95
|
-
* accidentally rely on a global `File` type in our annotations.
|
96
|
-
*/
|
97
|
-
function makeFile(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike {
|
98
|
-
const File = (globalThis as any).File as typeof FileClass | undefined;
|
99
|
-
if (typeof File === 'undefined') {
|
100
|
-
throw new Error('`File` is not defined as a global which is required for file uploads');
|
101
|
-
}
|
102
|
-
|
103
|
-
return new File(fileBits, fileName, options);
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
108
|
-
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
109
|
-
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
110
|
-
* @param {Object=} options additional properties
|
111
|
-
* @param {string=} options.type the MIME type of the content
|
112
|
-
* @param {number=} options.lastModified the last modified timestamp
|
113
|
-
* @returns a {@link File} with the given properties
|
114
|
-
*/
|
115
|
-
export async function toFile(
|
116
|
-
value: ToFileInput | PromiseLike<ToFileInput>,
|
117
|
-
name?: string | null | undefined,
|
118
|
-
options?: FilePropertyBag | undefined,
|
119
|
-
): Promise<FileLike> {
|
120
|
-
// If it's a promise, resolve it.
|
121
|
-
value = await value;
|
122
|
-
|
123
|
-
// If we've been given a `File` we don't need to do anything
|
124
|
-
if (isFileLike(value)) {
|
125
|
-
const File = (globalThis as any).File as typeof FileClass | undefined;
|
126
|
-
if (File && value instanceof File) {
|
127
|
-
return value;
|
128
|
-
}
|
129
|
-
return makeFile([await value.arrayBuffer()], value.name);
|
130
|
-
}
|
131
|
-
|
132
|
-
if (isResponseLike(value)) {
|
133
|
-
const blob = await value.blob();
|
134
|
-
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
|
135
|
-
|
136
|
-
return makeFile(await getBytes(blob), name, options);
|
137
|
-
}
|
138
|
-
|
139
|
-
const parts = await getBytes(value);
|
140
|
-
|
141
|
-
name ||= getName(value) ?? 'unknown_file';
|
142
|
-
|
143
|
-
if (!options?.type) {
|
144
|
-
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
145
|
-
if (typeof type === 'string') {
|
146
|
-
options = { ...options, type };
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
return makeFile(parts, name, options);
|
151
|
-
}
|
152
|
-
|
153
|
-
export async function getBytes(
|
154
|
-
value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>,
|
155
|
-
): Promise<Array<BlobPart>> {
|
156
|
-
let parts: Array<BlobPart> = [];
|
157
|
-
if (
|
158
|
-
typeof value === 'string' ||
|
159
|
-
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
160
|
-
value instanceof ArrayBuffer
|
161
|
-
) {
|
162
|
-
parts.push(value);
|
163
|
-
} else if (isBlobLike(value)) {
|
164
|
-
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
165
|
-
} else if (
|
166
|
-
isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
167
|
-
) {
|
168
|
-
for await (const chunk of value) {
|
169
|
-
parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?
|
170
|
-
}
|
171
|
-
} else {
|
172
|
-
const constructor = value?.constructor?.name;
|
173
|
-
throw new Error(
|
174
|
-
`Unexpected data type: ${typeof value}${
|
175
|
-
constructor ? `; constructor: ${constructor}` : ''
|
176
|
-
}${propsForError(value)}`,
|
177
|
-
);
|
178
|
-
}
|
179
|
-
|
180
|
-
return parts;
|
181
|
-
}
|
182
|
-
|
183
|
-
function propsForError(value: unknown): string {
|
184
|
-
if (typeof value !== 'object' || value === null) return '';
|
185
|
-
const props = Object.getOwnPropertyNames(value);
|
186
|
-
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
187
|
-
}
|
188
|
-
|
189
|
-
function getName(value: unknown): string | undefined {
|
190
|
-
return (
|
191
|
-
(typeof value === 'object' &&
|
192
|
-
value !== null &&
|
193
|
-
(('name' in value && String(value.name)) ||
|
194
|
-
('filename' in value && String(value.filename)) ||
|
195
|
-
('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
|
196
|
-
undefined
|
197
|
-
);
|
198
|
-
}
|
199
|
-
|
200
|
-
const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
|
201
|
-
value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
202
|
-
|
203
|
-
/**
|
204
|
-
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
205
|
-
* Otherwise returns the request as is.
|
206
|
-
*/
|
207
|
-
export const maybeMultipartFormRequestOptions = async (
|
208
|
-
opts: RequestOptions,
|
209
|
-
fetch: Petstore | Fetch,
|
210
|
-
): Promise<RequestOptions> => {
|
211
|
-
if (!hasUploadableValue(opts.body)) return opts;
|
212
|
-
|
213
|
-
return { ...opts, body: await createForm(opts.body, fetch) };
|
214
|
-
};
|
215
|
-
|
216
|
-
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };
|
217
|
-
|
218
|
-
export const multipartFormRequestOptions = async (
|
219
|
-
opts: MultipartFormRequestOptions,
|
220
|
-
fetch: Petstore | Fetch,
|
221
|
-
): Promise<RequestOptions> => {
|
222
|
-
return { ...opts, body: await createForm(opts.body, fetch) };
|
223
|
-
};
|
224
|
-
|
225
|
-
const supportsFormDataMap = new WeakMap<Fetch, Promise<boolean>>();
|
226
|
-
|
227
|
-
/**
|
228
|
-
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
229
|
-
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
230
|
-
* This function detects if the fetch function provided supports the global FormData object to avoid
|
231
|
-
* confusing error messages later on.
|
232
|
-
*/
|
233
|
-
function supportsFormData(fetchObject: Petstore | Fetch): Promise<boolean> {
|
234
|
-
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
235
|
-
const cached = supportsFormDataMap.get(fetch);
|
236
|
-
if (cached) return cached;
|
237
|
-
const promise = (async () => {
|
238
|
-
try {
|
239
|
-
const FetchResponse = (
|
240
|
-
'Response' in fetch ?
|
241
|
-
fetch.Response
|
242
|
-
: (await fetch('data:,')).constructor) as typeof Response;
|
243
|
-
const data = new FormData();
|
244
|
-
if (data.toString() === (await new FetchResponse(data).text())) {
|
245
|
-
return false;
|
246
|
-
}
|
247
|
-
return true;
|
248
|
-
} catch {
|
249
|
-
// avoid false negatives
|
250
|
-
return true;
|
251
|
-
}
|
252
|
-
})();
|
253
|
-
supportsFormDataMap.set(fetch, promise);
|
254
|
-
return promise;
|
255
|
-
}
|
256
|
-
|
257
|
-
export const createForm = async <T = Record<string, unknown>>(
|
258
|
-
body: T | undefined,
|
259
|
-
fetch: Petstore | Fetch,
|
260
|
-
): Promise<FormData> => {
|
261
|
-
if (!(await supportsFormData(fetch))) {
|
262
|
-
throw new TypeError(
|
263
|
-
'The provided fetch function does not support file uploads with the current global FormData class.',
|
264
|
-
);
|
265
|
-
}
|
266
|
-
const form = new FormData();
|
267
|
-
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
268
|
-
return form;
|
269
|
-
};
|
270
|
-
|
271
|
-
const hasUploadableValue = (value: unknown): boolean => {
|
272
|
-
if (isUploadable(value)) return true;
|
273
|
-
if (Array.isArray(value)) return value.some(hasUploadableValue);
|
274
|
-
if (value && typeof value === 'object') {
|
275
|
-
for (const k in value) {
|
276
|
-
if (hasUploadableValue((value as any)[k])) return true;
|
277
|
-
}
|
278
|
-
}
|
279
|
-
return false;
|
280
|
-
};
|
281
|
-
|
282
|
-
const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
|
283
|
-
if (value === undefined) return;
|
284
|
-
if (value == null) {
|
285
|
-
throw new TypeError(
|
286
|
-
`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
|
287
|
-
);
|
288
|
-
}
|
289
|
-
|
290
|
-
// TODO: make nested formats configurable
|
291
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
292
|
-
form.append(key, String(value));
|
293
|
-
} else if (isUploadable(value)) {
|
294
|
-
const file = await toFile(value);
|
295
|
-
form.append(key, file as any);
|
296
|
-
} else if (Array.isArray(value)) {
|
297
|
-
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
298
|
-
} else if (typeof value === 'object') {
|
299
|
-
await Promise.all(
|
300
|
-
Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
|
301
|
-
);
|
302
|
-
} else {
|
303
|
-
throw new TypeError(
|
304
|
-
`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
|
305
|
-
);
|
306
|
-
}
|
307
|
-
};
|
@@ -1,37 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
import { PetstoreError } from '../../error';
|
4
|
-
|
5
|
-
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
6
|
-
if (!data) return '';
|
7
|
-
|
8
|
-
if (typeof data === 'string') {
|
9
|
-
data = new (globalThis as any).TextEncoder().encode(data);
|
10
|
-
}
|
11
|
-
|
12
|
-
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
13
|
-
return (globalThis as any).Buffer.from(data).toString('base64');
|
14
|
-
}
|
15
|
-
|
16
|
-
if (typeof btoa !== 'undefined') {
|
17
|
-
return btoa(String.fromCharCode.apply(null, data as any));
|
18
|
-
}
|
19
|
-
|
20
|
-
throw new PetstoreError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
21
|
-
};
|
22
|
-
|
23
|
-
export const fromBase64 = (str: string): Uint8Array => {
|
24
|
-
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
25
|
-
return new Uint8Array((globalThis as any).Buffer.from(str, 'base64'));
|
26
|
-
}
|
27
|
-
|
28
|
-
if (typeof atob !== 'undefined') {
|
29
|
-
return new Uint8Array(
|
30
|
-
atob(str)
|
31
|
-
.split('')
|
32
|
-
.map((c) => c.charCodeAt(0)),
|
33
|
-
);
|
34
|
-
}
|
35
|
-
|
36
|
-
throw new PetstoreError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
37
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Read an environment variable.
|
5
|
-
*
|
6
|
-
* Trims beginning and trailing whitespace.
|
7
|
-
*
|
8
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
9
|
-
*/
|
10
|
-
export const readEnv = (env: string): string | undefined => {
|
11
|
-
if (typeof (globalThis as any).process !== 'undefined') {
|
12
|
-
return (globalThis as any).process.env?.[env]?.trim() ?? undefined;
|
13
|
-
}
|
14
|
-
if (typeof (globalThis as any).Deno !== 'undefined') {
|
15
|
-
return (globalThis as any).Deno.env?.get?.(env)?.trim();
|
16
|
-
}
|
17
|
-
return undefined;
|
18
|
-
};
|
@@ -1,49 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
import type { LogLevel, Logger } from '../../client';
|
4
|
-
import { type Petstore } from '../../client';
|
5
|
-
|
6
|
-
const levelNumbers = {
|
7
|
-
off: 0,
|
8
|
-
error: 200,
|
9
|
-
warn: 300,
|
10
|
-
info: 400,
|
11
|
-
debug: 500,
|
12
|
-
};
|
13
|
-
|
14
|
-
function noop() {}
|
15
|
-
|
16
|
-
function logFn(logger: Logger | undefined, clientLevel: LogLevel | undefined, level: keyof Logger) {
|
17
|
-
if (!logger || levelNumbers[level] > levelNumbers[clientLevel!]!) {
|
18
|
-
return noop;
|
19
|
-
} else {
|
20
|
-
// Don't wrap logger functions, we want the stacktrace intact!
|
21
|
-
return logger[level].bind(logger);
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
let lastLogger: { deref(): Logger } | undefined;
|
26
|
-
let lastLevel: LogLevel | undefined;
|
27
|
-
let lastLevelLogger: Logger;
|
28
|
-
|
29
|
-
export function logger(client: Petstore): Logger {
|
30
|
-
let { logger, logLevel: clientLevel } = client;
|
31
|
-
if (lastLevel === clientLevel && (logger === lastLogger || logger === lastLogger?.deref())) {
|
32
|
-
return lastLevelLogger;
|
33
|
-
}
|
34
|
-
const levelLogger = {
|
35
|
-
error: logFn(logger, clientLevel, 'error'),
|
36
|
-
warn: logFn(logger, clientLevel, 'warn'),
|
37
|
-
info: logFn(logger, clientLevel, 'info'),
|
38
|
-
debug: logFn(logger, clientLevel, 'debug'),
|
39
|
-
};
|
40
|
-
const { WeakRef } = globalThis as any;
|
41
|
-
lastLogger =
|
42
|
-
logger ?
|
43
|
-
WeakRef ? new WeakRef(logger)
|
44
|
-
: { deref: () => logger }
|
45
|
-
: undefined;
|
46
|
-
lastLevel = clientLevel;
|
47
|
-
lastLevelLogger = levelLogger;
|
48
|
-
return levelLogger;
|
49
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
|
3
|
-
import { crypto } from '../polyfill/crypto.node';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* https://stackoverflow.com/a/2117523
|
7
|
-
*/
|
8
|
-
export function uuid4() {
|
9
|
-
if (crypto.randomUUID) return crypto.randomUUID();
|
10
|
-
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
11
|
-
(+c ^ (crypto.getRandomValues(new Uint8Array(1))[0]! & (15 >> (+c / 4)))).toString(16),
|
12
|
-
);
|
13
|
-
}
|