fluidapi 0.0.3
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/FUNCTIONS.md +85 -0
- package/README.md +429 -0
- package/RUNTIMES.md +48 -0
- package/esm/core.d.ts +10 -0
- package/esm/core.d.ts.map +1 -0
- package/esm/core.js +13 -0
- package/esm/core.js.map +1 -0
- package/esm/funcs/metadata-get-jwks.d.ts +18 -0
- package/esm/funcs/metadata-get-jwks.d.ts.map +1 -0
- package/esm/funcs/metadata-get-jwks.js +67 -0
- package/esm/funcs/metadata-get-jwks.js.map +1 -0
- package/esm/funcs/metadata-health-check.d.ts +15 -0
- package/esm/funcs/metadata-health-check.d.ts.map +1 -0
- package/esm/funcs/metadata-health-check.js +64 -0
- package/esm/funcs/metadata-health-check.js.map +1 -0
- package/esm/funcs/tokens-issue-fluid-token.d.ts +25 -0
- package/esm/funcs/tokens-issue-fluid-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-fluid-token.js +87 -0
- package/esm/funcs/tokens-issue-fluid-token.js.map +1 -0
- package/esm/funcs/tokens-issue-token.d.ts +31 -0
- package/esm/funcs/tokens-issue-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-token.js +93 -0
- package/esm/funcs/tokens-issue-token.js.map +1 -0
- package/esm/funcs/tokens-issue-user-token.d.ts +37 -0
- package/esm/funcs/tokens-issue-user-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-user-token.js +97 -0
- package/esm/funcs/tokens-issue-user-token.js.map +1 -0
- package/esm/hooks/hooks.d.ts +25 -0
- package/esm/hooks/hooks.d.ts.map +1 -0
- package/esm/hooks/hooks.js +82 -0
- package/esm/hooks/hooks.js.map +1 -0
- package/esm/hooks/index.d.ts +3 -0
- package/esm/hooks/index.d.ts.map +1 -0
- package/esm/hooks/index.js +6 -0
- package/esm/hooks/index.js.map +1 -0
- package/esm/hooks/registration.d.ts +3 -0
- package/esm/hooks/registration.d.ts.map +1 -0
- package/esm/hooks/registration.js +12 -0
- package/esm/hooks/registration.js.map +1 -0
- package/esm/hooks/types.d.ts +76 -0
- package/esm/hooks/types.d.ts.map +1 -0
- package/esm/hooks/types.js +5 -0
- package/esm/hooks/types.js.map +1 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +8 -0
- package/esm/index.js.map +1 -0
- package/esm/lib/base64.d.ts +10 -0
- package/esm/lib/base64.d.ts.map +1 -0
- package/esm/lib/base64.js +31 -0
- package/esm/lib/base64.js.map +1 -0
- package/esm/lib/config.d.ts +57 -0
- package/esm/lib/config.d.ts.map +1 -0
- package/esm/lib/config.js +50 -0
- package/esm/lib/config.js.map +1 -0
- package/esm/lib/dlv.d.ts +14 -0
- package/esm/lib/dlv.d.ts.map +1 -0
- package/esm/lib/dlv.js +46 -0
- package/esm/lib/dlv.js.map +1 -0
- package/esm/lib/encodings.d.ts +53 -0
- package/esm/lib/encodings.d.ts.map +1 -0
- package/esm/lib/encodings.js +370 -0
- package/esm/lib/encodings.js.map +1 -0
- package/esm/lib/env.d.ts +14 -0
- package/esm/lib/env.d.ts.map +1 -0
- package/esm/lib/env.js +43 -0
- package/esm/lib/env.js.map +1 -0
- package/esm/lib/files.d.ts +13 -0
- package/esm/lib/files.d.ts.map +1 -0
- package/esm/lib/files.js +73 -0
- package/esm/lib/files.js.map +1 -0
- package/esm/lib/http.d.ts +67 -0
- package/esm/lib/http.d.ts.map +1 -0
- package/esm/lib/http.js +209 -0
- package/esm/lib/http.js.map +1 -0
- package/esm/lib/is-plain-object.d.ts +2 -0
- package/esm/lib/is-plain-object.d.ts.map +1 -0
- package/esm/lib/is-plain-object.js +38 -0
- package/esm/lib/is-plain-object.js.map +1 -0
- package/esm/lib/logger.d.ts +6 -0
- package/esm/lib/logger.d.ts.map +1 -0
- package/esm/lib/logger.js +5 -0
- package/esm/lib/logger.js.map +1 -0
- package/esm/lib/matchers.d.ts +59 -0
- package/esm/lib/matchers.d.ts.map +1 -0
- package/esm/lib/matchers.js +202 -0
- package/esm/lib/matchers.js.map +1 -0
- package/esm/lib/primitives.d.ts +26 -0
- package/esm/lib/primitives.d.ts.map +1 -0
- package/esm/lib/primitives.js +103 -0
- package/esm/lib/primitives.js.map +1 -0
- package/esm/lib/retries.d.ts +38 -0
- package/esm/lib/retries.d.ts.map +1 -0
- package/esm/lib/retries.js +150 -0
- package/esm/lib/retries.js.map +1 -0
- package/esm/lib/schemas.d.ts +21 -0
- package/esm/lib/schemas.d.ts.map +1 -0
- package/esm/lib/schemas.js +57 -0
- package/esm/lib/schemas.js.map +1 -0
- package/esm/lib/sdks.d.ts +63 -0
- package/esm/lib/sdks.d.ts.map +1 -0
- package/esm/lib/sdks.js +258 -0
- package/esm/lib/sdks.js.map +1 -0
- package/esm/lib/security.d.ts +80 -0
- package/esm/lib/security.d.ts.map +1 -0
- package/esm/lib/security.js +122 -0
- package/esm/lib/security.js.map +1 -0
- package/esm/lib/url.d.ts +5 -0
- package/esm/lib/url.d.ts.map +1 -0
- package/esm/lib/url.js +22 -0
- package/esm/lib/url.js.map +1 -0
- package/esm/models/error-response.d.ts +17 -0
- package/esm/models/error-response.d.ts.map +1 -0
- package/esm/models/error-response.js +15 -0
- package/esm/models/error-response.js.map +1 -0
- package/esm/models/errors/error-response.d.ts +21 -0
- package/esm/models/errors/error-response.d.ts.map +1 -0
- package/esm/models/errors/error-response.js +37 -0
- package/esm/models/errors/error-response.js.map +1 -0
- package/esm/models/errors/fluidapi-default-error.d.ts +10 -0
- package/esm/models/errors/fluidapi-default-error.d.ts.map +1 -0
- package/esm/models/errors/fluidapi-default-error.js +30 -0
- package/esm/models/errors/fluidapi-default-error.js.map +1 -0
- package/esm/models/errors/fluidapi-error.d.ts +19 -0
- package/esm/models/errors/fluidapi-error.d.ts.map +1 -0
- package/esm/models/errors/fluidapi-error.js +26 -0
- package/esm/models/errors/fluidapi-error.js.map +1 -0
- package/esm/models/errors/http-client-errors.d.ts +44 -0
- package/esm/models/errors/http-client-errors.d.ts.map +1 -0
- package/esm/models/errors/http-client-errors.js +56 -0
- package/esm/models/errors/http-client-errors.js.map +1 -0
- package/esm/models/errors/index.d.ts +7 -0
- package/esm/models/errors/index.d.ts.map +1 -0
- package/esm/models/errors/index.js +10 -0
- package/esm/models/errors/index.js.map +1 -0
- package/esm/models/errors/response-validation-error.d.ts +26 -0
- package/esm/models/errors/response-validation-error.d.ts.map +1 -0
- package/esm/models/errors/response-validation-error.js +37 -0
- package/esm/models/errors/response-validation-error.js.map +1 -0
- package/esm/models/errors/sdk-validation-error.d.ts +21 -0
- package/esm/models/errors/sdk-validation-error.d.ts.map +1 -0
- package/esm/models/errors/sdk-validation-error.js +52 -0
- package/esm/models/errors/sdk-validation-error.js.map +1 -0
- package/esm/models/health-response.d.ts +10 -0
- package/esm/models/health-response.d.ts.map +1 -0
- package/esm/models/health-response.js +14 -0
- package/esm/models/health-response.js.map +1 -0
- package/esm/models/index.d.ts +8 -0
- package/esm/models/index.d.ts.map +1 -0
- package/esm/models/index.js +11 -0
- package/esm/models/index.js.map +1 -0
- package/esm/models/issue-token-request.d.ts +31 -0
- package/esm/models/issue-token-request.d.ts.map +1 -0
- package/esm/models/issue-token-request.js +27 -0
- package/esm/models/issue-token-request.js.map +1 -0
- package/esm/models/jwk-set.d.ts +21 -0
- package/esm/models/jwk-set.d.ts.map +1 -0
- package/esm/models/jwk-set.js +26 -0
- package/esm/models/jwk-set.js.map +1 -0
- package/esm/models/operations/index.d.ts +4 -0
- package/esm/models/operations/index.d.ts.map +1 -0
- package/esm/models/operations/index.js +7 -0
- package/esm/models/operations/index.js.map +1 -0
- package/esm/models/operations/issue-fluid-token.d.ts +15 -0
- package/esm/models/operations/issue-fluid-token.d.ts.map +1 -0
- package/esm/models/operations/issue-fluid-token.js +16 -0
- package/esm/models/operations/issue-fluid-token.js.map +1 -0
- package/esm/models/operations/issue-token.d.ts +15 -0
- package/esm/models/operations/issue-token.d.ts.map +1 -0
- package/esm/models/operations/issue-token.js +16 -0
- package/esm/models/operations/issue-token.js.map +1 -0
- package/esm/models/operations/issue-user-token.d.ts +15 -0
- package/esm/models/operations/issue-user-token.d.ts.map +1 -0
- package/esm/models/operations/issue-user-token.js +16 -0
- package/esm/models/operations/issue-user-token.js.map +1 -0
- package/esm/models/token-data.d.ts +29 -0
- package/esm/models/token-data.d.ts.map +1 -0
- package/esm/models/token-data.js +30 -0
- package/esm/models/token-data.js.map +1 -0
- package/esm/models/user-token-data.d.ts +12 -0
- package/esm/models/user-token-data.d.ts.map +1 -0
- package/esm/models/user-token-data.js +23 -0
- package/esm/models/user-token-data.js.map +1 -0
- package/esm/models/user-token-request.d.ts +25 -0
- package/esm/models/user-token-request.d.ts.map +1 -0
- package/esm/models/user-token-request.js +26 -0
- package/esm/models/user-token-request.js.map +1 -0
- package/esm/sdk/index.d.ts +2 -0
- package/esm/sdk/index.d.ts.map +1 -0
- package/esm/sdk/index.js +5 -0
- package/esm/sdk/index.js.map +1 -0
- package/esm/sdk/metadata.d.ts +16 -0
- package/esm/sdk/metadata.d.ts.map +1 -0
- package/esm/sdk/metadata.js +25 -0
- package/esm/sdk/metadata.js.map +1 -0
- package/esm/sdk/sdk.d.ts +10 -0
- package/esm/sdk/sdk.d.ts.map +1 -0
- package/esm/sdk/sdk.js +17 -0
- package/esm/sdk/sdk.js.map +1 -0
- package/esm/sdk/tokens.d.ts +63 -0
- package/esm/sdk/tokens.d.ts.map +1 -0
- package/esm/sdk/tokens.js +74 -0
- package/esm/sdk/tokens.js.map +1 -0
- package/esm/types/async.d.ts +23 -0
- package/esm/types/async.d.ts.map +1 -0
- package/esm/types/async.js +28 -0
- package/esm/types/async.js.map +1 -0
- package/esm/types/blobs.d.ts +4 -0
- package/esm/types/blobs.d.ts.map +1 -0
- package/esm/types/blobs.js +25 -0
- package/esm/types/blobs.js.map +1 -0
- package/esm/types/const-date-time.d.ts +3 -0
- package/esm/types/const-date-time.d.ts.map +1 -0
- package/esm/types/const-date-time.js +10 -0
- package/esm/types/const-date-time.js.map +1 -0
- package/esm/types/default-to-zero-value.d.ts +12 -0
- package/esm/types/default-to-zero-value.d.ts.map +1 -0
- package/esm/types/default-to-zero-value.js +31 -0
- package/esm/types/default-to-zero-value.js.map +1 -0
- package/esm/types/enums.d.ts +9 -0
- package/esm/types/enums.d.ts.map +1 -0
- package/esm/types/enums.js +27 -0
- package/esm/types/enums.js.map +1 -0
- package/esm/types/fp.d.ts +31 -0
- package/esm/types/fp.d.ts.map +1 -0
- package/esm/types/fp.js +31 -0
- package/esm/types/fp.js.map +1 -0
- package/esm/types/index.d.ts +10 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +10 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/operations.d.ts +27 -0
- package/esm/types/operations.d.ts.map +1 -0
- package/esm/types/operations.js +77 -0
- package/esm/types/operations.js.map +1 -0
- package/esm/types/primitives.d.ts +11 -0
- package/esm/types/primitives.d.ts.map +1 -0
- package/esm/types/primitives.js +132 -0
- package/esm/types/primitives.js.map +1 -0
- package/esm/types/rfcdate.d.ts +21 -0
- package/esm/types/rfcdate.d.ts.map +1 -0
- package/esm/types/rfcdate.js +43 -0
- package/esm/types/rfcdate.js.map +1 -0
- package/esm/types/smart-union.d.ts +7 -0
- package/esm/types/smart-union.d.ts.map +1 -0
- package/esm/types/smart-union.js +117 -0
- package/esm/types/smart-union.js.map +1 -0
- package/esm/types/streams.d.ts +2 -0
- package/esm/types/streams.d.ts.map +1 -0
- package/esm/types/streams.js +15 -0
- package/esm/types/streams.js.map +1 -0
- package/esm/types/unrecognized.d.ts +16 -0
- package/esm/types/unrecognized.d.ts.map +1 -0
- package/esm/types/unrecognized.js +31 -0
- package/esm/types/unrecognized.js.map +1 -0
- package/examples/metadataHealthCheck.example.ts +24 -0
- package/jsr.json +27 -0
- package/package.json +62 -0
- package/src/core.ts +13 -0
- package/src/funcs/metadata-get-jwks.ts +145 -0
- package/src/funcs/metadata-health-check.ts +142 -0
- package/src/funcs/tokens-issue-fluid-token.ts +175 -0
- package/src/funcs/tokens-issue-token.ts +181 -0
- package/src/funcs/tokens-issue-user-token.ts +184 -0
- package/src/hooks/hooks.ts +132 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/registration.ts +14 -0
- package/src/hooks/types.ts +107 -0
- package/src/index.ts +9 -0
- package/src/lib/base64.ts +39 -0
- package/src/lib/config.ts +94 -0
- package/src/lib/dlv.ts +53 -0
- package/src/lib/encodings.ts +501 -0
- package/src/lib/env.ts +53 -0
- package/src/lib/files.ts +82 -0
- package/src/lib/http.ts +323 -0
- package/src/lib/is-plain-object.ts +43 -0
- package/src/lib/logger.ts +9 -0
- package/src/lib/matchers.ts +353 -0
- package/src/lib/primitives.ts +150 -0
- package/src/lib/retries.ts +218 -0
- package/src/lib/schemas.ts +94 -0
- package/src/lib/sdks.ts +406 -0
- package/src/lib/security.ts +236 -0
- package/src/lib/url.ts +33 -0
- package/src/models/error-response.ts +36 -0
- package/src/models/errors/error-response.ts +56 -0
- package/src/models/errors/fluidapi-default-error.ts +40 -0
- package/src/models/errors/fluidapi-error.ts +35 -0
- package/src/models/errors/http-client-errors.ts +62 -0
- package/src/models/errors/index.ts +10 -0
- package/src/models/errors/response-validation-error.ts +50 -0
- package/src/models/errors/sdk-validation-error.ts +54 -0
- package/src/models/health-response.ts +31 -0
- package/src/models/index.ts +11 -0
- package/src/models/issue-token-request.ts +66 -0
- package/src/models/jwk-set.ts +57 -0
- package/src/models/operations/index.ts +7 -0
- package/src/models/operations/issue-fluid-token.ts +37 -0
- package/src/models/operations/issue-token.ts +37 -0
- package/src/models/operations/issue-user-token.ts +37 -0
- package/src/models/token-data.ts +65 -0
- package/src/models/user-token-data.ts +45 -0
- package/src/models/user-token-request.ts +60 -0
- package/src/sdk/index.ts +5 -0
- package/src/sdk/metadata.ts +38 -0
- package/src/sdk/sdk.ts +19 -0
- package/src/sdk/tokens.ts +100 -0
- package/src/types/async.ts +68 -0
- package/src/types/blobs.ts +33 -0
- package/src/types/const-date-time.ts +15 -0
- package/src/types/default-to-zero-value.ts +33 -0
- package/src/types/enums.ts +45 -0
- package/src/types/fp.ts +50 -0
- package/src/types/index.ts +13 -0
- package/src/types/operations.ts +105 -0
- package/src/types/primitives.ts +168 -0
- package/src/types/rfcdate.ts +54 -0
- package/src/types/smart-union.ts +153 -0
- package/src/types/streams.ts +21 -0
- package/src/types/unrecognized.ts +35 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
|
|
7
|
+
export function constDateTime(
|
|
8
|
+
val: string,
|
|
9
|
+
): z.ZodMiniType<string, unknown> {
|
|
10
|
+
return z.custom<string>((v) => {
|
|
11
|
+
return (
|
|
12
|
+
typeof v === "string" && new Date(v).getTime() === new Date(val).getTime()
|
|
13
|
+
);
|
|
14
|
+
}, `Value must be equivalent to ${val}`);
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { type Unrecognized, unrecognized } from "./unrecognized.js";
|
|
6
|
+
|
|
7
|
+
let globalCount = 0;
|
|
8
|
+
let refCount = 0;
|
|
9
|
+
|
|
10
|
+
export function defaultToZeroValue<T>(value: T): Unrecognized<T> {
|
|
11
|
+
globalCount++;
|
|
12
|
+
return unrecognized(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function startCountingDefaultToZeroValue() {
|
|
16
|
+
refCount++;
|
|
17
|
+
const start = globalCount;
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Ends counting and returns the delta.
|
|
21
|
+
* @param delta - If provided, only this amount is added to the parent counter
|
|
22
|
+
* (used for nested unions where we only want to record the winning option's count).
|
|
23
|
+
* If not provided, records all counts since start().
|
|
24
|
+
*/
|
|
25
|
+
end: (delta?: number) => {
|
|
26
|
+
const count = globalCount - start;
|
|
27
|
+
// Reset globalCount back to start, then add only the specified delta
|
|
28
|
+
globalCount = start + (delta ?? count);
|
|
29
|
+
if (--refCount === 0) globalCount = 0;
|
|
30
|
+
return count;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { Unrecognized, unrecognized } from "./unrecognized.js";
|
|
7
|
+
|
|
8
|
+
export type ClosedEnum<T extends Readonly<Record<string, string | number>>> =
|
|
9
|
+
T[keyof T];
|
|
10
|
+
export type OpenEnum<T extends Readonly<Record<string, string | number>>> =
|
|
11
|
+
| T[keyof T]
|
|
12
|
+
| Unrecognized<T[keyof T] extends number ? number : string>;
|
|
13
|
+
|
|
14
|
+
export function inboundSchema<T extends Record<string, string>>(
|
|
15
|
+
enumObj: T,
|
|
16
|
+
): z.ZodMiniType<OpenEnum<T>, unknown> {
|
|
17
|
+
const options = Object.values(enumObj);
|
|
18
|
+
return z.union([
|
|
19
|
+
...options.map(x => z.literal(x)),
|
|
20
|
+
z.pipe(z.string(), z.transform(x => unrecognized(x))),
|
|
21
|
+
] as any);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function inboundSchemaInt<T extends Record<string, number | string>>(
|
|
25
|
+
enumObj: T,
|
|
26
|
+
): z.ZodMiniType<OpenEnum<T>, unknown> {
|
|
27
|
+
// For numeric enums, Object.values returns both numbers and string keys
|
|
28
|
+
const options = Object.values(enumObj).filter(v => typeof v === "number");
|
|
29
|
+
return z.union([
|
|
30
|
+
...options.map(x => z.literal(x)),
|
|
31
|
+
z.pipe(z.int(), z.transform(x => unrecognized(x))),
|
|
32
|
+
] as any);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function outboundSchema<T extends Record<string, string>>(
|
|
36
|
+
_: T,
|
|
37
|
+
): z.ZodMiniType<string, OpenEnum<T>> {
|
|
38
|
+
return z.string() as any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function outboundSchemaInt<T extends Record<string, number | string>>(
|
|
42
|
+
_: T,
|
|
43
|
+
): z.ZodMiniType<number, OpenEnum<T>> {
|
|
44
|
+
return z.int() as any;
|
|
45
|
+
}
|
package/src/types/fp.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A monad that captures the result of a function call or an error if it was not
|
|
7
|
+
* successful. Railway programming, enabled by this type, can be a nicer
|
|
8
|
+
* alternative to traditional exception throwing because it allows functions to
|
|
9
|
+
* declare all _known_ errors with static types and then check for them
|
|
10
|
+
* exhaustively in application code. Thrown exception have a type of `unknown`
|
|
11
|
+
* and break out of regular control flow of programs making them harder to
|
|
12
|
+
* inspect and more verbose work with due to try-catch blocks.
|
|
13
|
+
*/
|
|
14
|
+
export type Result<T, E = unknown> =
|
|
15
|
+
| { ok: true; value: T; error?: never }
|
|
16
|
+
| { ok: false; value?: never; error: E };
|
|
17
|
+
|
|
18
|
+
export function OK<V>(value: V): Result<V, never> {
|
|
19
|
+
return { ok: true, value };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ERR<E>(error: E): Result<never, E> {
|
|
23
|
+
return { ok: false, error };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* unwrap is a convenience function for extracting a value from a result or
|
|
28
|
+
* throwing if there was an error.
|
|
29
|
+
*/
|
|
30
|
+
export function unwrap<T>(r: Result<T, unknown>): T {
|
|
31
|
+
if (!r.ok) {
|
|
32
|
+
throw r.error;
|
|
33
|
+
}
|
|
34
|
+
return r.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* unwrapAsync is a convenience function for resolving a value from a Promise
|
|
39
|
+
* of a result or rejecting if an error occurred.
|
|
40
|
+
*/
|
|
41
|
+
export async function unwrapAsync<T>(
|
|
42
|
+
pr: Promise<Result<T, unknown>>,
|
|
43
|
+
): Promise<T> {
|
|
44
|
+
const r = await pr;
|
|
45
|
+
if (!r.ok) {
|
|
46
|
+
throw r.error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return r.value;
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { blobLikeSchema, isBlobLike } from "./blobs.js";
|
|
6
|
+
export * from "./default-to-zero-value.js";
|
|
7
|
+
export type { ClosedEnum, OpenEnum } from "./enums.js";
|
|
8
|
+
export type { Result } from "./fp.js";
|
|
9
|
+
export type { PageIterator, Paginator } from "./operations.js";
|
|
10
|
+
export { createPageIterator } from "./operations.js";
|
|
11
|
+
export * from "./primitives.js";
|
|
12
|
+
export { RFCDate } from "./rfcdate.js";
|
|
13
|
+
export * from "./unrecognized.js";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Result } from "./fp.js";
|
|
6
|
+
|
|
7
|
+
export type Paginator<V> = () => Promise<V & { next: Paginator<V> }> | null;
|
|
8
|
+
|
|
9
|
+
export type PageIterator<V, PageState = unknown> = V & {
|
|
10
|
+
next: Paginator<V>;
|
|
11
|
+
[Symbol.asyncIterator]: () => AsyncIterableIterator<V>;
|
|
12
|
+
"~next"?: PageState | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function createPageIterator<V>(
|
|
16
|
+
page: V & { next: Paginator<V> },
|
|
17
|
+
halt: (v: V) => boolean,
|
|
18
|
+
): {
|
|
19
|
+
[Symbol.asyncIterator]: () => AsyncIterableIterator<V>;
|
|
20
|
+
} {
|
|
21
|
+
return {
|
|
22
|
+
[Symbol.asyncIterator]: async function* paginator() {
|
|
23
|
+
yield page;
|
|
24
|
+
if (halt(page)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let p: typeof page | null = page;
|
|
29
|
+
for (p = await p.next(); p != null; p = await p.next()) {
|
|
30
|
+
yield p;
|
|
31
|
+
if (halt(p)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* This utility create a special iterator that yields a single value and
|
|
41
|
+
* terminates. It is useful in paginated SDK functions that have early return
|
|
42
|
+
* paths when things go wrong.
|
|
43
|
+
*/
|
|
44
|
+
export function haltIterator<V extends object>(
|
|
45
|
+
v: V,
|
|
46
|
+
): PageIterator<V, undefined> {
|
|
47
|
+
return {
|
|
48
|
+
...v,
|
|
49
|
+
next: () => null,
|
|
50
|
+
[Symbol.asyncIterator]: async function* paginator() {
|
|
51
|
+
yield v;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Converts an async iterator of `Result<V, E>` into an async iterator of `V`.
|
|
58
|
+
* When error results occur, the underlying error value is thrown.
|
|
59
|
+
*/
|
|
60
|
+
export async function unwrapResultIterator<V, PageState>(
|
|
61
|
+
iteratorPromise: Promise<PageIterator<Result<V, unknown>, PageState>>,
|
|
62
|
+
): Promise<PageIterator<V, PageState>> {
|
|
63
|
+
const resultIter = await iteratorPromise;
|
|
64
|
+
|
|
65
|
+
if (!resultIter.ok) {
|
|
66
|
+
throw resultIter.error;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
...resultIter.value,
|
|
71
|
+
next: unwrapPaginator(resultIter.next),
|
|
72
|
+
"~next": resultIter["~next"],
|
|
73
|
+
[Symbol.asyncIterator]: async function* paginator() {
|
|
74
|
+
for await (const page of resultIter) {
|
|
75
|
+
if (!page.ok) {
|
|
76
|
+
throw page.error;
|
|
77
|
+
}
|
|
78
|
+
yield page.value;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function unwrapPaginator<V>(
|
|
85
|
+
paginator: Paginator<Result<V, unknown>>,
|
|
86
|
+
): Paginator<V> {
|
|
87
|
+
return () => {
|
|
88
|
+
const nextResult = paginator();
|
|
89
|
+
if (nextResult == null) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return nextResult.then((res) => {
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
throw res.error;
|
|
95
|
+
}
|
|
96
|
+
const out = {
|
|
97
|
+
...res.value,
|
|
98
|
+
next: unwrapPaginator(res.next),
|
|
99
|
+
};
|
|
100
|
+
return out;
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const URL_OVERRIDE = Symbol("URL_OVERRIDE");
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { defaultToZeroValue } from "./default-to-zero-value.js";
|
|
7
|
+
import { unrecognized } from "./unrecognized.js";
|
|
8
|
+
|
|
9
|
+
export function string(): z.ZodMiniType<string> {
|
|
10
|
+
return z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
|
|
13
|
+
// Null or undefined -> ""
|
|
14
|
+
zodDefaultToZeroValue(""),
|
|
15
|
+
|
|
16
|
+
// Any other value -> String(x)
|
|
17
|
+
z.pipe(z.any(), z.transform((x) => unrecognized(JSON.stringify(x)))),
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function boolean(): z.ZodMiniType<boolean> {
|
|
22
|
+
return z.union([
|
|
23
|
+
z.boolean(),
|
|
24
|
+
|
|
25
|
+
// String "true" (case insensitive) -> true, "false" -> false
|
|
26
|
+
z.pipe(
|
|
27
|
+
z.string(),
|
|
28
|
+
z.transform((x, ctx) => {
|
|
29
|
+
const lower = x.toLowerCase();
|
|
30
|
+
if (lower === "true") return unrecognized(true);
|
|
31
|
+
if (lower === "false") return unrecognized(false);
|
|
32
|
+
ctx.issues.push({
|
|
33
|
+
input: x,
|
|
34
|
+
code: "invalid_type",
|
|
35
|
+
expected: "boolean",
|
|
36
|
+
received: "string",
|
|
37
|
+
});
|
|
38
|
+
return z.NEVER;
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
|
|
42
|
+
zodDefaultToZeroValue(false),
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function number(): z.ZodMiniType<number> {
|
|
47
|
+
return z.union([
|
|
48
|
+
z.number(),
|
|
49
|
+
|
|
50
|
+
// String -> Number
|
|
51
|
+
z.pipe(
|
|
52
|
+
z.string(),
|
|
53
|
+
z.transform((x, ctx) => {
|
|
54
|
+
const num = Number(x);
|
|
55
|
+
if (isNaN(num)) {
|
|
56
|
+
ctx.issues.push({
|
|
57
|
+
input: x,
|
|
58
|
+
code: "invalid_type",
|
|
59
|
+
expected: "number",
|
|
60
|
+
received: "string",
|
|
61
|
+
});
|
|
62
|
+
return z.NEVER;
|
|
63
|
+
}
|
|
64
|
+
return unrecognized(num);
|
|
65
|
+
}),
|
|
66
|
+
),
|
|
67
|
+
|
|
68
|
+
// Null or undefined -> 0
|
|
69
|
+
zodDefaultToZeroValue(0),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function bigint(): z.ZodMiniType<bigint> {
|
|
74
|
+
return z.union([
|
|
75
|
+
z.pipe(
|
|
76
|
+
z.string(),
|
|
77
|
+
z.transform((x, ctx) => {
|
|
78
|
+
try {
|
|
79
|
+
return BigInt(x);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
ctx.issues.push({
|
|
82
|
+
input: x,
|
|
83
|
+
code: "invalid_type",
|
|
84
|
+
expected: "bigint",
|
|
85
|
+
received: "string",
|
|
86
|
+
});
|
|
87
|
+
return z.NEVER;
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
zodDefaultToZeroValue(0n),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function date(): z.ZodMiniType<Date> {
|
|
96
|
+
return z.union([
|
|
97
|
+
z.pipe(
|
|
98
|
+
z.pipe(
|
|
99
|
+
z.union([z.string(), zodDefaultToZeroValue(0)]),
|
|
100
|
+
z.transform((x) => new Date(x)),
|
|
101
|
+
),
|
|
102
|
+
z.date(),
|
|
103
|
+
),
|
|
104
|
+
z.pipe(
|
|
105
|
+
z.number(),
|
|
106
|
+
z.transform((x, ctx) => {
|
|
107
|
+
const date = new Date(x);
|
|
108
|
+
if (isNaN(date.getTime())) {
|
|
109
|
+
ctx.issues.push({
|
|
110
|
+
input: x,
|
|
111
|
+
code: "invalid_type",
|
|
112
|
+
expected: "date",
|
|
113
|
+
received: "number",
|
|
114
|
+
});
|
|
115
|
+
return z.NEVER;
|
|
116
|
+
}
|
|
117
|
+
return unrecognized(date);
|
|
118
|
+
}),
|
|
119
|
+
),
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function literal<T extends string | number | boolean>(
|
|
124
|
+
value: T,
|
|
125
|
+
): z.ZodMiniType<T> {
|
|
126
|
+
return z.union([z.literal(value), zodDefaultToZeroValue(value)]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function literalBigInt<T extends bigint>(value: T): z.ZodMiniType<T> {
|
|
130
|
+
return z.pipe(z.literal(String(value)), z.transform((x) => BigInt(x))) as any;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function optional<T extends z.ZodMiniType>(t: T) {
|
|
134
|
+
return z.union([
|
|
135
|
+
z.undefined(),
|
|
136
|
+
|
|
137
|
+
// Null -> undefined
|
|
138
|
+
z.pipe(z.null(), z.transform(() => unrecognized(undefined))),
|
|
139
|
+
t,
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function nullable<T extends z.ZodMiniType>(t: T) {
|
|
144
|
+
return z.union([
|
|
145
|
+
z.null(),
|
|
146
|
+
|
|
147
|
+
// Undefined -> null
|
|
148
|
+
z.pipe(z.undefined(), z.transform(() => defaultToZeroValue(null))),
|
|
149
|
+
t,
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function zodDefaultToZeroValue<T>(value: T): z.ZodMiniType<T> {
|
|
154
|
+
return z.pipe(
|
|
155
|
+
z.any(),
|
|
156
|
+
z.transform((input, ctx) => {
|
|
157
|
+
if (input === undefined) return defaultToZeroValue(value);
|
|
158
|
+
if (input === null) return defaultToZeroValue(value);
|
|
159
|
+
ctx.issues.push({
|
|
160
|
+
input: input,
|
|
161
|
+
code: "invalid_type",
|
|
162
|
+
expected: "undefined",
|
|
163
|
+
received: "unknown",
|
|
164
|
+
});
|
|
165
|
+
return z.NEVER;
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const dateRE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
+
|
|
7
|
+
export class RFCDate {
|
|
8
|
+
private serialized: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new RFCDate instance using today's date.
|
|
12
|
+
*/
|
|
13
|
+
static today(): RFCDate {
|
|
14
|
+
return new RFCDate(new Date());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new RFCDate instance using the provided input.
|
|
19
|
+
* If a string is used then in must be in the format YYYY-MM-DD.
|
|
20
|
+
*
|
|
21
|
+
* @param date A Date object or a date string in YYYY-MM-DD format
|
|
22
|
+
* @example
|
|
23
|
+
* new RFCDate("2022-01-01")
|
|
24
|
+
* @example
|
|
25
|
+
* new RFCDate(new Date())
|
|
26
|
+
*/
|
|
27
|
+
constructor(date: Date | string) {
|
|
28
|
+
if (typeof date === "string" && !dateRE.test(date)) {
|
|
29
|
+
throw new RangeError(
|
|
30
|
+
"RFCDate: date strings must be in the format YYYY-MM-DD: " + date,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const value = new Date(date);
|
|
35
|
+
if (isNaN(+value)) {
|
|
36
|
+
throw new RangeError("RFCDate: invalid date provided: " + date);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.serialized = value.toISOString().slice(0, "YYYY-MM-DD".length);
|
|
40
|
+
if (!dateRE.test(this.serialized)) {
|
|
41
|
+
throw new TypeError(
|
|
42
|
+
`RFCDate: failed to build valid date with given value: ${date} serialized to ${this.serialized}`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toJSON(): string {
|
|
48
|
+
return this.toString();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toString(): string {
|
|
52
|
+
return this.serialized;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Not needed if lax mode
|
|
6
|
+
import * as z from "zod/v4-mini";
|
|
7
|
+
import { startCountingDefaultToZeroValue } from "./default-to-zero-value.js";
|
|
8
|
+
import { RFCDate } from "./rfcdate.js";
|
|
9
|
+
import { startCountingUnrecognized } from "./unrecognized.js";
|
|
10
|
+
|
|
11
|
+
interface Candidate {
|
|
12
|
+
data: unknown;
|
|
13
|
+
/** Total number of fields in the parsed data */
|
|
14
|
+
fieldCount: number;
|
|
15
|
+
/** Number of fields which only matched due to lax parsing */
|
|
16
|
+
inexactCount: number;
|
|
17
|
+
/** Number of fields which defaulted to zero values */
|
|
18
|
+
zeroDefaultCount: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Smart union parser that tries all schemas and returns the best match
|
|
23
|
+
* based on the number of populated fields.
|
|
24
|
+
*/
|
|
25
|
+
export function smartUnion<
|
|
26
|
+
Options extends readonly [z.ZodMiniType, z.ZodMiniType, ...z.ZodMiniType[]],
|
|
27
|
+
>(
|
|
28
|
+
options: Options,
|
|
29
|
+
): z.ZodMiniType<z.output<Options[number]>, z.input<Options[number]>> {
|
|
30
|
+
return z.pipe(
|
|
31
|
+
z.unknown(),
|
|
32
|
+
z.transform((input, ctx) => {
|
|
33
|
+
const candidates: Candidate[] = [];
|
|
34
|
+
const errors: z.core.$ZodIssue[][] = options.map(() => []);
|
|
35
|
+
|
|
36
|
+
const parentUnrecognizedCtr = startCountingUnrecognized();
|
|
37
|
+
const parentZeroDefaultCtr = startCountingDefaultToZeroValue();
|
|
38
|
+
|
|
39
|
+
// Filter out invalid options
|
|
40
|
+
for (const [i, option] of options.entries()) {
|
|
41
|
+
const unrecognizedCtr = startCountingUnrecognized();
|
|
42
|
+
const zeroDefaultCtr = startCountingDefaultToZeroValue();
|
|
43
|
+
const result = option.safeParse(input);
|
|
44
|
+
const inexactCount = unrecognizedCtr.end();
|
|
45
|
+
const zeroDefaultCount = zeroDefaultCtr.end();
|
|
46
|
+
if (result.success) {
|
|
47
|
+
candidates.push({
|
|
48
|
+
data: result.data,
|
|
49
|
+
inexactCount,
|
|
50
|
+
zeroDefaultCount,
|
|
51
|
+
fieldCount: -1, // We'll count this later if needed
|
|
52
|
+
});
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
errors[i]!.push(...result.error.issues);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// No valid options
|
|
59
|
+
if (candidates.length === 0) {
|
|
60
|
+
parentUnrecognizedCtr.end(0);
|
|
61
|
+
parentZeroDefaultCtr.end(0);
|
|
62
|
+
ctx.issues.push({
|
|
63
|
+
input: input,
|
|
64
|
+
code: "invalid_union",
|
|
65
|
+
errors: errors,
|
|
66
|
+
});
|
|
67
|
+
return z.NEVER;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let best = candidates[0]!;
|
|
71
|
+
|
|
72
|
+
// Find the best option
|
|
73
|
+
for (const candidate of candidates) {
|
|
74
|
+
// Minor optimization to avoid counting fields if there's only one candidate
|
|
75
|
+
if (candidates.length > 1) {
|
|
76
|
+
candidate.fieldCount = countFieldsRecursive(candidate.data);
|
|
77
|
+
}
|
|
78
|
+
best = better(candidate, best);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// The cost of this union should be the cost of the best candidate not all the candidates
|
|
82
|
+
parentUnrecognizedCtr.end(best.inexactCount);
|
|
83
|
+
parentZeroDefaultCtr.end(best.zeroDefaultCount);
|
|
84
|
+
|
|
85
|
+
return best.data;
|
|
86
|
+
}),
|
|
87
|
+
) as any;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function better(a: Candidate, b: Candidate): Candidate {
|
|
91
|
+
// First prefer exact matches over inexact ones
|
|
92
|
+
const aIsExact = a.inexactCount === 0;
|
|
93
|
+
const bIsExact = b.inexactCount === 0;
|
|
94
|
+
if (aIsExact !== bIsExact) {
|
|
95
|
+
return aIsExact ? a : b;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Then compare field counts
|
|
99
|
+
const actualFieldCountA = a.fieldCount - a.zeroDefaultCount;
|
|
100
|
+
const actualFieldCountB = b.fieldCount - b.zeroDefaultCount;
|
|
101
|
+
if (actualFieldCountA !== actualFieldCountB) {
|
|
102
|
+
return actualFieldCountA > actualFieldCountB ? a : b;
|
|
103
|
+
}
|
|
104
|
+
return a.inexactCount < b.inexactCount ? a : b;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Counts the number of fields in a parsed value recursively.
|
|
109
|
+
* @param `parsed` assumed to *not* contain cycles
|
|
110
|
+
* fieldCount: total number of fields found
|
|
111
|
+
* inexactCount: number of primitive values that are not unrecognized enum values
|
|
112
|
+
*/
|
|
113
|
+
function countFieldsRecursive(parsed: unknown): number {
|
|
114
|
+
let fieldCount = 0;
|
|
115
|
+
|
|
116
|
+
const queue: unknown[] = [parsed];
|
|
117
|
+
let index = 0;
|
|
118
|
+
|
|
119
|
+
while (index < queue.length) {
|
|
120
|
+
const value = queue[index++];
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check if it's a primitive value
|
|
126
|
+
const type = typeof value;
|
|
127
|
+
if (
|
|
128
|
+
value === null
|
|
129
|
+
|| type === "number"
|
|
130
|
+
|| type === "string"
|
|
131
|
+
|| type === "boolean"
|
|
132
|
+
|| type === "bigint"
|
|
133
|
+
|| value instanceof Date
|
|
134
|
+
|| value instanceof RFCDate
|
|
135
|
+
) {
|
|
136
|
+
fieldCount++;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Handle arrays
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
queue.push(...value);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Handle objects
|
|
147
|
+
if (type === "object") {
|
|
148
|
+
queue.push(...Object.values(value));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return fieldCount;
|
|
153
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function isReadableStream<T = Uint8Array>(
|
|
6
|
+
val: unknown,
|
|
7
|
+
): val is ReadableStream<T> {
|
|
8
|
+
if (typeof val !== "object" || val === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Check for the presence of methods specific to ReadableStream
|
|
13
|
+
const stream = val as ReadableStream<Uint8Array>;
|
|
14
|
+
|
|
15
|
+
// ReadableStream has methods like getReader, cancel, and tee
|
|
16
|
+
return (
|
|
17
|
+
typeof stream.getReader === "function" &&
|
|
18
|
+
typeof stream.cancel === "function" &&
|
|
19
|
+
typeof stream.tee === "function"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare const __brand: unique symbol;
|
|
6
|
+
export type Unrecognized<T> = T & { [__brand]: "unrecognized" };
|
|
7
|
+
|
|
8
|
+
function unrecognized<T>(value: T): Unrecognized<T> {
|
|
9
|
+
globalCount++;
|
|
10
|
+
return value as Unrecognized<T>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let globalCount = 0;
|
|
14
|
+
let refCount = 0;
|
|
15
|
+
export function startCountingUnrecognized() {
|
|
16
|
+
refCount++;
|
|
17
|
+
const start = globalCount;
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Ends counting and returns the delta.
|
|
21
|
+
* @param delta - If provided, only this amount is added to the parent counter
|
|
22
|
+
* (used for nested unions where we only want to record the winning option's count).
|
|
23
|
+
* If not provided, records all counts since start().
|
|
24
|
+
*/
|
|
25
|
+
end: (delta?: number) => {
|
|
26
|
+
const count = globalCount - start;
|
|
27
|
+
// Reset globalCount back to start, then add only the specified delta
|
|
28
|
+
globalCount = start + (delta ?? count);
|
|
29
|
+
if (--refCount === 0) globalCount = 0;
|
|
30
|
+
return count;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { unrecognized };
|