@opencode-ai/sdk 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +7 -0
- package/README.md +356 -0
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +226 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +226 -0
- package/client.d.ts.map +1 -0
- package/client.js +512 -0
- package/client.js.map +1 -0
- package/client.mjs +508 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -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 +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -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 +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +20 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +20 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +35 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +32 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/request-options.d.mts +33 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +33 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +67 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +67 -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 +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -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 +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.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 +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +85 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +79 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +58 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +53 -0
- package/internal/utils/path.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 +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +18 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +18 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +112 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +94 -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 +11 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +139 -0
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- package/resources/app-info.d.mts +31 -0
- package/resources/app-info.d.mts.map +1 -0
- package/resources/app-info.d.ts +31 -0
- package/resources/app-info.d.ts.map +1 -0
- package/resources/app-info.js +15 -0
- package/resources/app-info.js.map +1 -0
- package/resources/app-info.mjs +11 -0
- package/resources/app-info.mjs.map +1 -0
- package/resources/app-initialize.d.mts +14 -0
- package/resources/app-initialize.d.mts.map +1 -0
- package/resources/app-initialize.d.ts +14 -0
- package/resources/app-initialize.d.ts.map +1 -0
- package/resources/app-initialize.js +15 -0
- package/resources/app-initialize.js.map +1 -0
- package/resources/app-initialize.mjs +11 -0
- package/resources/app-initialize.mjs.map +1 -0
- package/resources/config-get.d.mts +236 -0
- package/resources/config-get.d.mts.map +1 -0
- package/resources/config-get.d.ts +236 -0
- package/resources/config-get.d.ts.map +1 -0
- package/resources/config-get.js +15 -0
- package/resources/config-get.js.map +1 -0
- package/resources/config-get.mjs +11 -0
- package/resources/config-get.mjs.map +1 -0
- package/resources/event.d.mts +105 -0
- package/resources/event.d.mts.map +1 -0
- package/resources/event.d.ts +105 -0
- package/resources/event.d.ts.map +1 -0
- package/resources/event.js +15 -0
- package/resources/event.js.map +1 -0
- package/resources/event.mjs +11 -0
- package/resources/event.mjs.map +1 -0
- package/resources/file-search.d.mts +17 -0
- package/resources/file-search.d.mts.map +1 -0
- package/resources/file-search.d.ts +17 -0
- package/resources/file-search.d.ts.map +1 -0
- package/resources/file-search.js +15 -0
- package/resources/file-search.js.map +1 -0
- package/resources/file-search.mjs +11 -0
- package/resources/file-search.mjs.map +1 -0
- package/resources/index.d.mts +18 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +18 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +39 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +19 -0
- package/resources/index.mjs.map +1 -0
- package/resources/installation-info.d.mts +17 -0
- package/resources/installation-info.d.mts.map +1 -0
- package/resources/installation-info.d.ts +17 -0
- package/resources/installation-info.d.ts.map +1 -0
- package/resources/installation-info.js +15 -0
- package/resources/installation-info.js.map +1 -0
- package/resources/installation-info.mjs +11 -0
- package/resources/installation-info.mjs.map +1 -0
- package/resources/path-get.d.mts +19 -0
- package/resources/path-get.d.mts.map +1 -0
- package/resources/path-get.d.ts +19 -0
- package/resources/path-get.d.ts.map +1 -0
- package/resources/path-get.js +15 -0
- package/resources/path-get.js.map +1 -0
- package/resources/path-get.mjs +11 -0
- package/resources/path-get.mjs.map +1 -0
- package/resources/provider-list.d.mts +58 -0
- package/resources/provider-list.d.mts.map +1 -0
- package/resources/provider-list.d.ts +58 -0
- package/resources/provider-list.d.ts.map +1 -0
- package/resources/provider-list.js +15 -0
- package/resources/provider-list.js.map +1 -0
- package/resources/provider-list.mjs +11 -0
- package/resources/provider-list.mjs.map +1 -0
- package/resources/session-abort.d.mts +17 -0
- package/resources/session-abort.d.mts.map +1 -0
- package/resources/session-abort.d.ts +17 -0
- package/resources/session-abort.d.ts.map +1 -0
- package/resources/session-abort.js +15 -0
- package/resources/session-abort.js.map +1 -0
- package/resources/session-abort.mjs +11 -0
- package/resources/session-abort.mjs.map +1 -0
- package/resources/session-chat.d.mts +160 -0
- package/resources/session-chat.d.mts.map +1 -0
- package/resources/session-chat.d.ts +160 -0
- package/resources/session-chat.d.ts.map +1 -0
- package/resources/session-chat.js +15 -0
- package/resources/session-chat.js.map +1 -0
- package/resources/session-chat.mjs +11 -0
- package/resources/session-chat.mjs.map +1 -0
- package/resources/session-create.d.mts +30 -0
- package/resources/session-create.d.mts.map +1 -0
- package/resources/session-create.d.ts +30 -0
- package/resources/session-create.d.ts.map +1 -0
- package/resources/session-create.js +15 -0
- package/resources/session-create.js.map +1 -0
- package/resources/session-create.mjs +11 -0
- package/resources/session-create.mjs.map +1 -0
- package/resources/session-initialize.d.mts +19 -0
- package/resources/session-initialize.d.mts.map +1 -0
- package/resources/session-initialize.d.ts +19 -0
- package/resources/session-initialize.d.ts.map +1 -0
- package/resources/session-initialize.js +15 -0
- package/resources/session-initialize.js.map +1 -0
- package/resources/session-initialize.mjs +11 -0
- package/resources/session-initialize.mjs.map +1 -0
- package/resources/session-list.d.mts +15 -0
- package/resources/session-list.d.mts.map +1 -0
- package/resources/session-list.d.ts +15 -0
- package/resources/session-list.d.ts.map +1 -0
- package/resources/session-list.js +15 -0
- package/resources/session-list.js.map +1 -0
- package/resources/session-list.mjs +11 -0
- package/resources/session-list.mjs.map +1 -0
- package/resources/session-messages.d.mts +18 -0
- package/resources/session-messages.d.mts.map +1 -0
- package/resources/session-messages.d.ts +18 -0
- package/resources/session-messages.d.ts.map +1 -0
- package/resources/session-messages.js +15 -0
- package/resources/session-messages.js.map +1 -0
- package/resources/session-messages.mjs +11 -0
- package/resources/session-messages.mjs.map +1 -0
- package/resources/session-share.d.mts +17 -0
- package/resources/session-share.d.mts.map +1 -0
- package/resources/session-share.d.ts +17 -0
- package/resources/session-share.d.ts.map +1 -0
- package/resources/session-share.js +15 -0
- package/resources/session-share.js.map +1 -0
- package/resources/session-share.mjs +11 -0
- package/resources/session-share.mjs.map +1 -0
- package/resources/session-summarize.d.mts +19 -0
- package/resources/session-summarize.d.mts.map +1 -0
- package/resources/session-summarize.d.ts +19 -0
- package/resources/session-summarize.d.ts.map +1 -0
- package/resources/session-summarize.js +15 -0
- package/resources/session-summarize.js.map +1 -0
- package/resources/session-summarize.mjs +11 -0
- package/resources/session-summarize.mjs.map +1 -0
- package/resources/session-unshare.d.mts +17 -0
- package/resources/session-unshare.d.mts.map +1 -0
- package/resources/session-unshare.d.ts +17 -0
- package/resources/session-unshare.d.ts.map +1 -0
- package/resources/session-unshare.js +15 -0
- package/resources/session-unshare.js.map +1 -0
- package/resources/session-unshare.mjs +11 -0
- package/resources/session-unshare.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +860 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/error.ts +130 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +22 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +97 -0
- package/src/internal/parse.ts +50 -0
- package/src/internal/request-options.ts +38 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +92 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +126 -0
- package/src/internal/utils/path.ts +63 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +105 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +2 -0
- package/src/resources/app-info.ts +46 -0
- package/src/resources/app-initialize.ts +20 -0
- package/src/resources/config-get.ts +294 -0
- package/src/resources/event.ts +150 -0
- package/src/resources/file-search.ts +27 -0
- package/src/resources/index.ts +38 -0
- package/src/resources/installation-info.ts +24 -0
- package/src/resources/path-get.ts +28 -0
- package/src/resources/provider-list.ts +80 -0
- package/src/resources/session-abort.ts +27 -0
- package/src/resources/session-chat.ts +250 -0
- package/src/resources/session-create.ts +44 -0
- package/src/resources/session-initialize.ts +34 -0
- package/src/resources/session-list.ts +21 -0
- package/src/resources/session-messages.ts +31 -0
- package/src/resources/session-share.ts +23 -0
- package/src/resources/session-summarize.ts +34 -0
- package/src/resources/session-unshare.ts +26 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -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,67 @@
|
|
|
1
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
|
2
|
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
3
|
+
export type KeysEnum<T> = {
|
|
4
|
+
[P in keyof Required<T>]: true;
|
|
5
|
+
};
|
|
6
|
+
export type FinalizedRequestInit = RequestInit & {
|
|
7
|
+
headers: Headers;
|
|
8
|
+
};
|
|
9
|
+
type NotAny<T> = [unknown] extends [T] ? never : T;
|
|
10
|
+
/**
|
|
11
|
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
|
12
|
+
*/
|
|
13
|
+
type OverloadedParameters<T> = T extends ({
|
|
14
|
+
(...args: infer A): unknown;
|
|
15
|
+
(...args: infer B): unknown;
|
|
16
|
+
(...args: infer C): unknown;
|
|
17
|
+
(...args: infer D): unknown;
|
|
18
|
+
}) ? A | B | C | D : T extends ({
|
|
19
|
+
(...args: infer A): unknown;
|
|
20
|
+
(...args: infer B): unknown;
|
|
21
|
+
(...args: infer C): unknown;
|
|
22
|
+
}) ? A | B | C : T extends ({
|
|
23
|
+
(...args: infer A): unknown;
|
|
24
|
+
(...args: infer B): unknown;
|
|
25
|
+
}) ? A | B : T extends (...args: infer A) => unknown ? A : never;
|
|
26
|
+
/**
|
|
27
|
+
* These imports attempt to get types from a parent package's dependencies.
|
|
28
|
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
|
29
|
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
|
30
|
+
* directly from parent node_modules folders.
|
|
31
|
+
*
|
|
32
|
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
|
33
|
+
* For example, pnpm generates directories like this:
|
|
34
|
+
* ```
|
|
35
|
+
* node_modules
|
|
36
|
+
* ├── .pnpm
|
|
37
|
+
* │ └── pkg@1.0.0
|
|
38
|
+
* │ └── node_modules
|
|
39
|
+
* │ └── pkg
|
|
40
|
+
* │ └── internal
|
|
41
|
+
* │ └── types.d.ts
|
|
42
|
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
|
43
|
+
* └── undici
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
47
|
+
*/
|
|
48
|
+
/** @ts-ignore For users with \@types/node */
|
|
49
|
+
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>;
|
|
50
|
+
/** @ts-ignore For users with undici */
|
|
51
|
+
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>;
|
|
52
|
+
/** @ts-ignore For users with \@types/bun */
|
|
53
|
+
type BunRequestInit = globalThis.FetchRequestInit;
|
|
54
|
+
/** @ts-ignore For users with node-fetch */
|
|
55
|
+
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>;
|
|
56
|
+
/** @ts-ignore For users who use Deno */
|
|
57
|
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
58
|
+
type RequestInits = NotAny<UndiciTypesRequestInit> | NotAny<UndiciRequestInit> | NotAny<BunRequestInit> | NotAny<NodeFetchRequestInit> | NotAny<RequestInit> | NotAny<FetchRequestInit>;
|
|
59
|
+
/**
|
|
60
|
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
|
61
|
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
|
62
|
+
*/
|
|
63
|
+
export type MergedRequestInit = RequestInits &
|
|
64
|
+
/** We don't include these in the types as they'll be overridden for every request. */
|
|
65
|
+
Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
|
|
66
|
+
export {};
|
|
67
|
+
//# 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,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GA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,OAAO,8CAA8C,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,OAAO,iDAAiD,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,OAAO,oDAAoD,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,OAAO,uDAAuD,EAAE,WAAW,CAAC,CAAC;AAC/uB,wCAAwC;AACxC,KAAK,gBAAgB,GAAG,WAAW,CAAC,oBAAoB,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAG3E,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,YAAY;AAC1C,sFAAsF;AACtF,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
|
2
|
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
3
|
+
export type KeysEnum<T> = {
|
|
4
|
+
[P in keyof Required<T>]: true;
|
|
5
|
+
};
|
|
6
|
+
export type FinalizedRequestInit = RequestInit & {
|
|
7
|
+
headers: Headers;
|
|
8
|
+
};
|
|
9
|
+
type NotAny<T> = [unknown] extends [T] ? never : T;
|
|
10
|
+
/**
|
|
11
|
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
|
12
|
+
*/
|
|
13
|
+
type OverloadedParameters<T> = T extends ({
|
|
14
|
+
(...args: infer A): unknown;
|
|
15
|
+
(...args: infer B): unknown;
|
|
16
|
+
(...args: infer C): unknown;
|
|
17
|
+
(...args: infer D): unknown;
|
|
18
|
+
}) ? A | B | C | D : T extends ({
|
|
19
|
+
(...args: infer A): unknown;
|
|
20
|
+
(...args: infer B): unknown;
|
|
21
|
+
(...args: infer C): unknown;
|
|
22
|
+
}) ? A | B | C : T extends ({
|
|
23
|
+
(...args: infer A): unknown;
|
|
24
|
+
(...args: infer B): unknown;
|
|
25
|
+
}) ? A | B : T extends (...args: infer A) => unknown ? A : never;
|
|
26
|
+
/**
|
|
27
|
+
* These imports attempt to get types from a parent package's dependencies.
|
|
28
|
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
|
29
|
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
|
30
|
+
* directly from parent node_modules folders.
|
|
31
|
+
*
|
|
32
|
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
|
33
|
+
* For example, pnpm generates directories like this:
|
|
34
|
+
* ```
|
|
35
|
+
* node_modules
|
|
36
|
+
* ├── .pnpm
|
|
37
|
+
* │ └── pkg@1.0.0
|
|
38
|
+
* │ └── node_modules
|
|
39
|
+
* │ └── pkg
|
|
40
|
+
* │ └── internal
|
|
41
|
+
* │ └── types.d.ts
|
|
42
|
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
|
43
|
+
* └── undici
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
47
|
+
*/
|
|
48
|
+
/** @ts-ignore For users with \@types/node */
|
|
49
|
+
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>;
|
|
50
|
+
/** @ts-ignore For users with undici */
|
|
51
|
+
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>;
|
|
52
|
+
/** @ts-ignore For users with \@types/bun */
|
|
53
|
+
type BunRequestInit = globalThis.FetchRequestInit;
|
|
54
|
+
/** @ts-ignore For users with node-fetch */
|
|
55
|
+
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>;
|
|
56
|
+
/** @ts-ignore For users who use Deno */
|
|
57
|
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
58
|
+
type RequestInits = NotAny<UndiciTypesRequestInit> | NotAny<UndiciRequestInit> | NotAny<BunRequestInit> | NotAny<NodeFetchRequestInit> | NotAny<RequestInit> | NotAny<FetchRequestInit>;
|
|
59
|
+
/**
|
|
60
|
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
|
61
|
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
|
62
|
+
*/
|
|
63
|
+
export type MergedRequestInit = RequestInits &
|
|
64
|
+
/** We don't include these in the types as they'll be overridden for every request. */
|
|
65
|
+
Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
|
|
66
|
+
export {};
|
|
67
|
+
//# 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,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,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAEnD;;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,OAAO,CAAC;CAC7B,CACF,GACC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAC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AAC,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,YAAY;AAC1C,sFAAsF;AACtF,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,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,42 @@
|
|
|
1
|
+
import { type RequestOptions } from "./request-options.mjs";
|
|
2
|
+
import type { FilePropertyBag, Fetch } from "./builtin-types.mjs";
|
|
3
|
+
import type { Opencode } from "../client.mjs";
|
|
4
|
+
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
5
|
+
type FsReadStream = AsyncIterable<Uint8Array> & {
|
|
6
|
+
path: string | {
|
|
7
|
+
toString(): string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
interface BunFile extends Blob {
|
|
11
|
+
readonly name?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare const checkFileSupport: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Typically, this is a native "File" class.
|
|
16
|
+
*
|
|
17
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
|
18
|
+
* into the File class.
|
|
19
|
+
*
|
|
20
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
|
21
|
+
* the result of fs.createReadStream().
|
|
22
|
+
*/
|
|
23
|
+
export type Uploadable = File | Response | FsReadStream | BunFile;
|
|
24
|
+
/**
|
|
25
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
26
|
+
* for environments that don't define a global `File` yet.
|
|
27
|
+
*/
|
|
28
|
+
export declare function makeFile(fileBits: BlobPart[], fileName: string | undefined, options?: FilePropertyBag): File;
|
|
29
|
+
export declare function getName(value: any): string | undefined;
|
|
30
|
+
export declare const isAsyncIterable: (value: any) => value is AsyncIterable<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
33
|
+
* Otherwise returns the request as is.
|
|
34
|
+
*/
|
|
35
|
+
export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Opencode | Fetch) => Promise<RequestOptions>;
|
|
36
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
|
|
37
|
+
body: unknown;
|
|
38
|
+
};
|
|
39
|
+
export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Opencode | Fetch) => Promise<RequestOptions>;
|
|
40
|
+
export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Opencode | Fetch) => Promise<FormData>;
|
|
41
|
+
export {};
|
|
42
|
+
//# 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,KAAK,EAAE,QAAQ,EAAE;AAGxB,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,QAAQ,CAAC;AAChF,KAAK,YAAY,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAG1F,UAAU,OAAQ,SAAQ,IAAI;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,YAY5B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,CAAC;AAElE;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAAE,EACpB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,CAAC,EAAE,eAAe,GACxB,IAAI,CAGN;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CActD;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,aAAa,CAAC,GAAG,CAC0B,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,cAAc,EACpB,OAAO,QAAQ,GAAG,KAAK,KACtB,OAAO,CAAC,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,GACtC,MAAM,2BAA2B,EACjC,OAAO,QAAQ,GAAG,KAAK,KACtB,OAAO,CAAC,cAAc,CAExB,CAAC;AAkCF,eAAO,MAAM,UAAU,GAAU,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,MAAM,CAAC,GAAG,SAAS,EACnB,OAAO,QAAQ,GAAG,KAAK,KACtB,OAAO,CAAC,QAAQ,CASlB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RequestOptions } from "./request-options.js";
|
|
2
|
+
import type { FilePropertyBag, Fetch } from "./builtin-types.js";
|
|
3
|
+
import type { Opencode } from "../client.js";
|
|
4
|
+
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
5
|
+
type FsReadStream = AsyncIterable<Uint8Array> & {
|
|
6
|
+
path: string | {
|
|
7
|
+
toString(): string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
interface BunFile extends Blob {
|
|
11
|
+
readonly name?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare const checkFileSupport: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Typically, this is a native "File" class.
|
|
16
|
+
*
|
|
17
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
|
18
|
+
* into the File class.
|
|
19
|
+
*
|
|
20
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
|
21
|
+
* the result of fs.createReadStream().
|
|
22
|
+
*/
|
|
23
|
+
export type Uploadable = File | Response | FsReadStream | BunFile;
|
|
24
|
+
/**
|
|
25
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
26
|
+
* for environments that don't define a global `File` yet.
|
|
27
|
+
*/
|
|
28
|
+
export declare function makeFile(fileBits: BlobPart[], fileName: string | undefined, options?: FilePropertyBag): File;
|
|
29
|
+
export declare function getName(value: any): string | undefined;
|
|
30
|
+
export declare const isAsyncIterable: (value: any) => value is AsyncIterable<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
33
|
+
* Otherwise returns the request as is.
|
|
34
|
+
*/
|
|
35
|
+
export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Opencode | Fetch) => Promise<RequestOptions>;
|
|
36
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
|
|
37
|
+
body: unknown;
|
|
38
|
+
};
|
|
39
|
+
export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Opencode | Fetch) => Promise<RequestOptions>;
|
|
40
|
+
export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Opencode | Fetch) => Promise<FormData>;
|
|
41
|
+
export {};
|
|
42
|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AAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,2BAA2B,GACtC,MAAM,2BAA2B,EACjC,OAAO,QAAQ,GAAG,KAAK,KACtB,OAAO,CAAC,cAAc,CAExB,CAAC;AAkCF,eAAO,MAAM,UAAU,GAAU,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,MAAM,CAAC,GAAG,SAAS,EACnB,OAAO,QAAQ,GAAG,KAAK,KACtB,OAAO,CAAC,QAAQ,CASlB,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.isAsyncIterable = exports.checkFileSupport = void 0;
|
|
4
|
+
exports.makeFile = makeFile;
|
|
5
|
+
exports.getName = getName;
|
|
6
|
+
const shims_1 = require("./shims.js");
|
|
7
|
+
const checkFileSupport = () => {
|
|
8
|
+
if (typeof File === 'undefined') {
|
|
9
|
+
const { process } = globalThis;
|
|
10
|
+
const isOldNode = typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
|
|
11
|
+
throw new Error('`File` is not defined as a global, which is required for file uploads.' +
|
|
12
|
+
(isOldNode ?
|
|
13
|
+
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
|
|
14
|
+
: ''));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.checkFileSupport = checkFileSupport;
|
|
18
|
+
/**
|
|
19
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
20
|
+
* for environments that don't define a global `File` yet.
|
|
21
|
+
*/
|
|
22
|
+
function makeFile(fileBits, fileName, options) {
|
|
23
|
+
(0, exports.checkFileSupport)();
|
|
24
|
+
return new File(fileBits, fileName ?? 'unknown_file', options);
|
|
25
|
+
}
|
|
26
|
+
function getName(value) {
|
|
27
|
+
return (((typeof value === 'object' &&
|
|
28
|
+
value !== null &&
|
|
29
|
+
(('name' in value && value.name && String(value.name)) ||
|
|
30
|
+
('url' in value && value.url && String(value.url)) ||
|
|
31
|
+
('filename' in value && value.filename && String(value.filename)) ||
|
|
32
|
+
('path' in value && value.path && String(value.path)))) ||
|
|
33
|
+
'')
|
|
34
|
+
.split(/[\\/]/)
|
|
35
|
+
.pop() || undefined);
|
|
36
|
+
}
|
|
37
|
+
const isAsyncIterable = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
|
38
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
41
|
+
* Otherwise returns the request as is.
|
|
42
|
+
*/
|
|
43
|
+
const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
|
44
|
+
if (!hasUploadableValue(opts.body))
|
|
45
|
+
return opts;
|
|
46
|
+
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
|
47
|
+
};
|
|
48
|
+
exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
|
|
49
|
+
const multipartFormRequestOptions = async (opts, fetch) => {
|
|
50
|
+
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
|
51
|
+
};
|
|
52
|
+
exports.multipartFormRequestOptions = multipartFormRequestOptions;
|
|
53
|
+
const supportsFormDataMap = /** @__PURE__ */ new WeakMap();
|
|
54
|
+
/**
|
|
55
|
+
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
56
|
+
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
|
57
|
+
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
58
|
+
* confusing error messages later on.
|
|
59
|
+
*/
|
|
60
|
+
function supportsFormData(fetchObject) {
|
|
61
|
+
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
|
62
|
+
const cached = supportsFormDataMap.get(fetch);
|
|
63
|
+
if (cached)
|
|
64
|
+
return cached;
|
|
65
|
+
const promise = (async () => {
|
|
66
|
+
try {
|
|
67
|
+
const FetchResponse = ('Response' in fetch ?
|
|
68
|
+
fetch.Response
|
|
69
|
+
: (await fetch('data:,')).constructor);
|
|
70
|
+
const data = new FormData();
|
|
71
|
+
if (data.toString() === (await new FetchResponse(data).text())) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// avoid false negatives
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
})();
|
|
81
|
+
supportsFormDataMap.set(fetch, promise);
|
|
82
|
+
return promise;
|
|
83
|
+
}
|
|
84
|
+
const createForm = async (body, fetch) => {
|
|
85
|
+
if (!(await supportsFormData(fetch))) {
|
|
86
|
+
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
|
87
|
+
}
|
|
88
|
+
const form = new FormData();
|
|
89
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
|
90
|
+
return form;
|
|
91
|
+
};
|
|
92
|
+
exports.createForm = createForm;
|
|
93
|
+
// We check for Blob not File because Bun.File doesn't inherit from File,
|
|
94
|
+
// but they both inherit from Blob and have a `name` property at runtime.
|
|
95
|
+
const isNamedBlob = (value) => value instanceof Blob && 'name' in value;
|
|
96
|
+
const isUploadable = (value) => typeof value === 'object' &&
|
|
97
|
+
value !== null &&
|
|
98
|
+
(value instanceof Response || (0, exports.isAsyncIterable)(value) || isNamedBlob(value));
|
|
99
|
+
const hasUploadableValue = (value) => {
|
|
100
|
+
if (isUploadable(value))
|
|
101
|
+
return true;
|
|
102
|
+
if (Array.isArray(value))
|
|
103
|
+
return value.some(hasUploadableValue);
|
|
104
|
+
if (value && typeof value === 'object') {
|
|
105
|
+
for (const k in value) {
|
|
106
|
+
if (hasUploadableValue(value[k]))
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
};
|
|
112
|
+
const addFormValue = async (form, key, value) => {
|
|
113
|
+
if (value === undefined)
|
|
114
|
+
return;
|
|
115
|
+
if (value == null) {
|
|
116
|
+
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
|
117
|
+
}
|
|
118
|
+
// TODO: make nested formats configurable
|
|
119
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
120
|
+
form.append(key, String(value));
|
|
121
|
+
}
|
|
122
|
+
else if (value instanceof Response) {
|
|
123
|
+
form.append(key, makeFile([await value.blob()], getName(value)));
|
|
124
|
+
}
|
|
125
|
+
else if ((0, exports.isAsyncIterable)(value)) {
|
|
126
|
+
form.append(key, makeFile([await new Response((0, shims_1.ReadableStreamFrom)(value)).blob()], getName(value)));
|
|
127
|
+
}
|
|
128
|
+
else if (isNamedBlob(value)) {
|
|
129
|
+
form.append(key, value, getName(value));
|
|
130
|
+
}
|
|
131
|
+
else if (Array.isArray(value)) {
|
|
132
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
|
133
|
+
}
|
|
134
|
+
else if (typeof value === 'object') {
|
|
135
|
+
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=uploads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.js","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;;AA0CA,4BAOC;AAED,0BAcC;AA9DD,sCAA6C;AAUtC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,EAAE,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shims.mjs";
|
|
2
|
+
export const checkFileSupport = () => {
|
|
3
|
+
if (typeof File === 'undefined') {
|
|
4
|
+
const { process } = globalThis;
|
|
5
|
+
const isOldNode = typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
|
|
6
|
+
throw new Error('`File` is not defined as a global, which is required for file uploads.' +
|
|
7
|
+
(isOldNode ?
|
|
8
|
+
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
|
|
9
|
+
: ''));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
14
|
+
* for environments that don't define a global `File` yet.
|
|
15
|
+
*/
|
|
16
|
+
export function makeFile(fileBits, fileName, options) {
|
|
17
|
+
checkFileSupport();
|
|
18
|
+
return new File(fileBits, fileName ?? 'unknown_file', options);
|
|
19
|
+
}
|
|
20
|
+
export function getName(value) {
|
|
21
|
+
return (((typeof value === 'object' &&
|
|
22
|
+
value !== null &&
|
|
23
|
+
(('name' in value && value.name && String(value.name)) ||
|
|
24
|
+
('url' in value && value.url && String(value.url)) ||
|
|
25
|
+
('filename' in value && value.filename && String(value.filename)) ||
|
|
26
|
+
('path' in value && value.path && String(value.path)))) ||
|
|
27
|
+
'')
|
|
28
|
+
.split(/[\\/]/)
|
|
29
|
+
.pop() || undefined);
|
|
30
|
+
}
|
|
31
|
+
export const isAsyncIterable = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
|
32
|
+
/**
|
|
33
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
34
|
+
* Otherwise returns the request as is.
|
|
35
|
+
*/
|
|
36
|
+
export const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
|
37
|
+
if (!hasUploadableValue(opts.body))
|
|
38
|
+
return opts;
|
|
39
|
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
40
|
+
};
|
|
41
|
+
export const multipartFormRequestOptions = async (opts, fetch) => {
|
|
42
|
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
43
|
+
};
|
|
44
|
+
const supportsFormDataMap = /** @__PURE__ */ new WeakMap();
|
|
45
|
+
/**
|
|
46
|
+
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
47
|
+
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
|
48
|
+
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
49
|
+
* confusing error messages later on.
|
|
50
|
+
*/
|
|
51
|
+
function supportsFormData(fetchObject) {
|
|
52
|
+
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
|
53
|
+
const cached = supportsFormDataMap.get(fetch);
|
|
54
|
+
if (cached)
|
|
55
|
+
return cached;
|
|
56
|
+
const promise = (async () => {
|
|
57
|
+
try {
|
|
58
|
+
const FetchResponse = ('Response' in fetch ?
|
|
59
|
+
fetch.Response
|
|
60
|
+
: (await fetch('data:,')).constructor);
|
|
61
|
+
const data = new FormData();
|
|
62
|
+
if (data.toString() === (await new FetchResponse(data).text())) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// avoid false negatives
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
supportsFormDataMap.set(fetch, promise);
|
|
73
|
+
return promise;
|
|
74
|
+
}
|
|
75
|
+
export const createForm = async (body, fetch) => {
|
|
76
|
+
if (!(await supportsFormData(fetch))) {
|
|
77
|
+
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
|
78
|
+
}
|
|
79
|
+
const form = new FormData();
|
|
80
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
|
81
|
+
return form;
|
|
82
|
+
};
|
|
83
|
+
// We check for Blob not File because Bun.File doesn't inherit from File,
|
|
84
|
+
// but they both inherit from Blob and have a `name` property at runtime.
|
|
85
|
+
const isNamedBlob = (value) => value instanceof Blob && 'name' in value;
|
|
86
|
+
const isUploadable = (value) => typeof value === 'object' &&
|
|
87
|
+
value !== null &&
|
|
88
|
+
(value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));
|
|
89
|
+
const hasUploadableValue = (value) => {
|
|
90
|
+
if (isUploadable(value))
|
|
91
|
+
return true;
|
|
92
|
+
if (Array.isArray(value))
|
|
93
|
+
return value.some(hasUploadableValue);
|
|
94
|
+
if (value && typeof value === 'object') {
|
|
95
|
+
for (const k in value) {
|
|
96
|
+
if (hasUploadableValue(value[k]))
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
const addFormValue = async (form, key, value) => {
|
|
103
|
+
if (value === undefined)
|
|
104
|
+
return;
|
|
105
|
+
if (value == null) {
|
|
106
|
+
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
|
107
|
+
}
|
|
108
|
+
// TODO: make nested formats configurable
|
|
109
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
110
|
+
form.append(key, String(value));
|
|
111
|
+
}
|
|
112
|
+
else if (value instanceof Response) {
|
|
113
|
+
form.append(key, makeFile([await value.blob()], getName(value)));
|
|
114
|
+
}
|
|
115
|
+
else if (isAsyncIterable(value)) {
|
|
116
|
+
form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value)));
|
|
117
|
+
}
|
|
118
|
+
else if (isNamedBlob(value)) {
|
|
119
|
+
form.append(key, value, getName(value));
|
|
120
|
+
}
|
|
121
|
+
else if (Array.isArray(value)) {
|
|
122
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
|
123
|
+
}
|
|
124
|
+
else if (typeof value === 'object') {
|
|
125
|
+
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=uploads.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":"OAGO,EAAE,kBAAkB,EAAE;AAU7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAiB,CAAC;QACtC,MAAM,SAAS,GACb,OAAO,OAAO,EAAE,QAAQ,EAAE,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACjG,MAAM,IAAI,KAAK,CACb,wEAAwE;YACtE,CAAC,SAAS,CAAC,CAAC;gBACV,4FAA4F;gBAC9F,CAAC,CAAC,EAAE,CAAC,CACR,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAaF;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAoB,EACpB,QAA4B,EAC5B,OAAyB;IAEzB,gBAAgB,EAAE,CAAC;IACnB,OAAO,IAAI,IAAI,CAAC,QAAe,EAAE,QAAQ,IAAI,cAAc,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAU;IAChC,OAAO,CACL,CACE,CAAC,OAAO,KAAK,KAAK,QAAQ;QACxB,KAAK,KAAK,IAAI;QACd,CAAC,CAAC,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpD,CAAC,KAAK,IAAI,KAAK,IAAI,KAAK,CAAC,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AAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.mts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,UAgBxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,UAgBxC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.fromBase64 = exports.toBase64 = void 0;
|
|
5
|
+
const error_1 = require("../../core/error.js");
|
|
6
|
+
const bytes_1 = require("./bytes.js");
|
|
7
|
+
const toBase64 = (data) => {
|
|
8
|
+
if (!data)
|
|
9
|
+
return '';
|
|
10
|
+
if (typeof globalThis.Buffer !== 'undefined') {
|
|
11
|
+
return globalThis.Buffer.from(data).toString('base64');
|
|
12
|
+
}
|
|
13
|
+
if (typeof data === 'string') {
|
|
14
|
+
data = (0, bytes_1.encodeUTF8)(data);
|
|
15
|
+
}
|
|
16
|
+
if (typeof btoa !== 'undefined') {
|
|
17
|
+
return btoa(String.fromCharCode.apply(null, data));
|
|
18
|
+
}
|
|
19
|
+
throw new error_1.OpencodeError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
20
|
+
};
|
|
21
|
+
exports.toBase64 = toBase64;
|
|
22
|
+
const fromBase64 = (str) => {
|
|
23
|
+
if (typeof globalThis.Buffer !== 'undefined') {
|
|
24
|
+
const buf = globalThis.Buffer.from(str, 'base64');
|
|
25
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
26
|
+
}
|
|
27
|
+
if (typeof atob !== 'undefined') {
|
|
28
|
+
const bstr = atob(str);
|
|
29
|
+
const buf = new Uint8Array(bstr.length);
|
|
30
|
+
for (let i = 0; i < bstr.length; i++) {
|
|
31
|
+
buf[i] = bstr.charCodeAt(i);
|
|
32
|
+
}
|
|
33
|
+
return buf;
|
|
34
|
+
}
|
|
35
|
+
throw new error_1.OpencodeError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
36
|
+
};
|
|
37
|
+
exports.fromBase64 = fromBase64;
|
|
38
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,+CAAiD;AACjD,sCAAqC;AAE9B,MAAM,QAAQ,GAAG,CAAC,IAA4C,EAAU,EAAE;IAC/E,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACtD,OAAQ,UAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QA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