@gcmdev/faxios 0.2.1 → 0.2.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.
Files changed (131) hide show
  1. package/dist/index.d.ts +3 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/adapters/fetch-helpers.d.ts +1 -1
  6. package/dist/lib/adapters/fetch-helpers.d.ts.map +1 -1
  7. package/dist/lib/adapters/fetch.d.ts +4 -1
  8. package/dist/lib/adapters/fetch.d.ts.map +1 -1
  9. package/dist/lib/adapters/fetch.js +210 -92
  10. package/dist/lib/adapters/fetch.js.map +1 -1
  11. package/dist/lib/cancel/CanceledError.d.ts +1 -1
  12. package/dist/lib/cancel/CanceledError.d.ts.map +1 -1
  13. package/dist/lib/core/Faxios.d.ts +3 -3
  14. package/dist/lib/core/Faxios.d.ts.map +1 -1
  15. package/dist/lib/core/Faxios.js +8 -4
  16. package/dist/lib/core/Faxios.js.map +1 -1
  17. package/dist/lib/core/FaxiosError.d.ts +2 -2
  18. package/dist/lib/core/FaxiosError.d.ts.map +1 -1
  19. package/dist/lib/core/FaxiosHeaders.d.ts +8 -8
  20. package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -1
  21. package/dist/lib/core/FaxiosHeaders.js +31 -7
  22. package/dist/lib/core/FaxiosHeaders.js.map +1 -1
  23. package/dist/lib/core/define.d.ts +3 -3
  24. package/dist/lib/core/define.d.ts.map +1 -1
  25. package/dist/lib/core/dispatchRequest.d.ts +1 -1
  26. package/dist/lib/core/dispatchRequest.d.ts.map +1 -1
  27. package/dist/lib/core/dispatchRequest.js +6 -1
  28. package/dist/lib/core/dispatchRequest.js.map +1 -1
  29. package/dist/lib/core/mergeConfig.d.ts +2 -2
  30. package/dist/lib/core/mergeConfig.d.ts.map +1 -1
  31. package/dist/lib/core/mergeConfig.js +40 -2
  32. package/dist/lib/core/mergeConfig.js.map +1 -1
  33. package/dist/lib/core/route.d.ts +1 -1
  34. package/dist/lib/core/route.d.ts.map +1 -1
  35. package/dist/lib/core/route.js +2 -5
  36. package/dist/lib/core/route.js.map +1 -1
  37. package/dist/lib/core/transformData.d.ts +2 -2
  38. package/dist/lib/core/transformData.d.ts.map +1 -1
  39. package/dist/lib/core/validateSchema.d.ts +2 -2
  40. package/dist/lib/core/validateSchema.d.ts.map +1 -1
  41. package/dist/lib/env/data.d.ts +1 -1
  42. package/dist/lib/env/data.js +1 -1
  43. package/dist/lib/faxios.d.ts +50 -50
  44. package/dist/lib/faxios.d.ts.map +1 -1
  45. package/dist/lib/helpers/cloneConfig.d.ts +0 -1
  46. package/dist/lib/helpers/cloneConfig.d.ts.map +1 -1
  47. package/dist/lib/helpers/cloneConfig.js +2 -2
  48. package/dist/lib/helpers/cloneConfig.js.map +1 -1
  49. package/dist/lib/helpers/cookies.d.ts +1 -1
  50. package/dist/lib/helpers/cookies.d.ts.map +1 -1
  51. package/dist/lib/helpers/formDataToJSON.d.ts +1 -1
  52. package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -1
  53. package/dist/lib/helpers/formDataToJSON.js +1 -1
  54. package/dist/lib/helpers/formDataToJSON.js.map +1 -1
  55. package/dist/lib/helpers/parseHeaders.d.ts +1 -1
  56. package/dist/lib/helpers/parseHeaders.d.ts.map +1 -1
  57. package/dist/lib/helpers/progressEventReducer.d.ts.map +1 -1
  58. package/dist/lib/helpers/progressEventReducer.js +14 -1
  59. package/dist/lib/helpers/progressEventReducer.js.map +1 -1
  60. package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -1
  61. package/dist/lib/helpers/substitutePathParams.js +11 -3
  62. package/dist/lib/helpers/substitutePathParams.js.map +1 -1
  63. package/dist/lib/helpers/toFormData.d.ts.map +1 -1
  64. package/dist/lib/helpers/toFormData.js +16 -20
  65. package/dist/lib/helpers/toFormData.js.map +1 -1
  66. package/dist/lib/helpers/trackStream.d.ts.map +1 -1
  67. package/dist/lib/helpers/trackStream.js +27 -3
  68. package/dist/lib/helpers/trackStream.js.map +1 -1
  69. package/dist/lib/helpers/validator.d.ts +1 -1
  70. package/dist/lib/helpers/validator.d.ts.map +1 -1
  71. package/dist/lib/platform.d.ts.map +1 -1
  72. package/dist/lib/plugins/authBearer.d.ts +9 -5
  73. package/dist/lib/plugins/authBearer.d.ts.map +1 -1
  74. package/dist/lib/plugins/authBearer.js +6 -0
  75. package/dist/lib/plugins/authBearer.js.map +1 -1
  76. package/dist/lib/plugins/definePlugin.d.ts +3 -3
  77. package/dist/lib/plugins/definePlugin.d.ts.map +1 -1
  78. package/dist/lib/plugins/retry.d.ts +23 -23
  79. package/dist/lib/plugins/retry.d.ts.map +1 -1
  80. package/dist/lib/plugins/timing.d.ts +8 -8
  81. package/dist/lib/plugins/timing.d.ts.map +1 -1
  82. package/dist/lib/types/standard-schema.d.ts +6 -6
  83. package/dist/lib/types/standard-schema.d.ts.map +1 -1
  84. package/dist/lib/types.d.ts +106 -92
  85. package/dist/lib/types.d.ts.map +1 -1
  86. package/dist/lib/utils.d.ts +4 -3
  87. package/dist/lib/utils.d.ts.map +1 -1
  88. package/dist/lib/utils.js +18 -5
  89. package/dist/lib/utils.js.map +1 -1
  90. package/package.json +7 -4
  91. package/skills/configure-requests/SKILL.md +14 -8
  92. package/skills/configure-requests/references/axios-differences.md +1 -1
  93. package/skills/configure-requests/references/plugins.md +37 -6
  94. package/src/index.ts +15 -15
  95. package/src/lib/adapters/fetch-helpers.ts +3 -3
  96. package/src/lib/adapters/fetch.ts +263 -144
  97. package/src/lib/cancel/CanceledError.ts +1 -1
  98. package/src/lib/core/Faxios.ts +17 -13
  99. package/src/lib/core/FaxiosError.ts +3 -3
  100. package/src/lib/core/FaxiosHeaders.ts +50 -23
  101. package/src/lib/core/define.ts +7 -7
  102. package/src/lib/core/dispatchRequest.ts +8 -3
  103. package/src/lib/core/mergeConfig.ts +42 -4
  104. package/src/lib/core/prepareRequest.ts +1 -1
  105. package/src/lib/core/route.ts +3 -6
  106. package/src/lib/core/transformData.ts +2 -2
  107. package/src/lib/core/validateSchema.ts +4 -4
  108. package/src/lib/defaults/index.ts +1 -1
  109. package/src/lib/env/data.ts +1 -1
  110. package/src/lib/faxios.ts +55 -55
  111. package/src/lib/helpers/HttpStatusCode.ts +1 -1
  112. package/src/lib/helpers/cloneConfig.ts +2 -3
  113. package/src/lib/helpers/composeSignals.ts +4 -4
  114. package/src/lib/helpers/cookies.ts +3 -3
  115. package/src/lib/helpers/formDataToJSON.ts +4 -4
  116. package/src/lib/helpers/parseHeaders.ts +2 -2
  117. package/src/lib/helpers/progressEventReducer.ts +15 -2
  118. package/src/lib/helpers/sanitizeHeaderValue.ts +1 -1
  119. package/src/lib/helpers/substitutePathParams.ts +13 -3
  120. package/src/lib/helpers/throttle.ts +1 -1
  121. package/src/lib/helpers/toFormData.ts +26 -28
  122. package/src/lib/helpers/trackStream.ts +40 -12
  123. package/src/lib/helpers/validator.ts +3 -3
  124. package/src/lib/platform.ts +4 -4
  125. package/src/lib/plugins/authBearer.ts +14 -9
  126. package/src/lib/plugins/definePlugin.ts +3 -3
  127. package/src/lib/plugins/retry.ts +27 -27
  128. package/src/lib/plugins/timing.ts +5 -5
  129. package/src/lib/types/standard-schema.ts +6 -6
  130. package/src/lib/types.ts +139 -125
  131. package/src/lib/utils.ts +30 -15
@@ -5,7 +5,7 @@ import { VERSION } from "../env/data.js";
5
5
 
6
6
  export type ValidatorFn = (value: unknown, opt?: string, opts?: unknown) => boolean | string;
7
7
 
8
- const validators: Record<string, ValidatorFn | undefined> = {};
8
+ const validators: Record<string, undefined | ValidatorFn> = {};
9
9
 
10
10
  [ "object", "boolean", "number", "function", "string", "symbol" ].forEach((type, i) => {
11
11
  validators[type] = function validator(thing: unknown): boolean | string {
@@ -24,7 +24,7 @@ const deprecatedWarnings: Record<string, boolean | undefined> = {};
24
24
  *
25
25
  * @returns {function}
26
26
  */
27
- (validators as Record<string, unknown>)["transitional"] = function transitional(validator: ValidatorFn | false | undefined, version?: string, message?: string): ValidatorFn {
27
+ (validators as Record<string, unknown>)["transitional"] = function transitional(validator: false | undefined | ValidatorFn, version?: string, message?: string): ValidatorFn {
28
28
  function formatMessage(opt: string, desc: string): string {
29
29
  return (
30
30
  "[Faxios v" +
@@ -80,7 +80,7 @@ const deprecatedWarnings: Record<string, boolean | undefined> = {};
80
80
  * @returns {object}
81
81
  */
82
82
 
83
- function assertOptions(options: unknown, schema: Record<string, ValidatorFn | undefined>, allowUnknown: boolean): void {
83
+ function assertOptions(options: unknown, schema: Record<string, undefined | ValidatorFn>, allowUnknown: boolean): void {
84
84
  if (typeof options !== "object") {
85
85
  throw new FaxiosError("options must be an object", FaxiosError.ERR_BAD_OPTION_VALUE);
86
86
  }
@@ -3,13 +3,13 @@
3
3
  import FaxiosURLSearchParams from "./helpers/FaxiosURLSearchParams.js";
4
4
 
5
5
  const _globalThis = globalThis as {
6
- window?: { location?: { href?: string; }; };
6
+ Blob?: new (...args: Array<unknown>) => object;
7
7
  document?: unknown;
8
+ FormData?: new () => object;
8
9
  navigator?: { product?: string; userAgent?: string; };
9
- WorkerGlobalScope?: unknown;
10
10
  self?: { importScripts?: unknown; };
11
- FormData?: new () => object;
12
- Blob?: new (...args: Array<unknown>) => object;
11
+ window?: { location?: { href?: string; }; };
12
+ WorkerGlobalScope?: unknown;
13
13
  };
14
14
 
15
15
  const hasBrowserEnv = typeof _globalThis.window !== "undefined" && typeof _globalThis.document !== "undefined";
@@ -13,10 +13,6 @@ import { definePlugin } from "./definePlugin.js";
13
13
  export type AuthBearerCapability = { auth: { getToken: () => Promise<string>; }; };
14
14
 
15
15
  export type AuthBearerOptions = {
16
- /** Replace a header the request already has. Default `false`: an explicit header is kept. */
17
- overwrite?: boolean;
18
- /** Put before the token, separated by a space. Default `"Bearer"`; `""` sends the bare token. */
19
- scheme?: string;
20
16
  /** The header to set. Default `"Authorization"`. */
21
17
  header?: string;
22
18
  /**
@@ -24,6 +20,10 @@ export type AuthBearerOptions = {
24
20
  * with an absolute `baseURL`, only its origin; otherwise only relative request URLs.
25
21
  */
26
22
  origins?: Array<string>;
23
+ /** Replace a header the request already has. Default `false`: an explicit header is kept. */
24
+ overwrite?: boolean;
25
+ /** Put before the token, separated by a space. Default `"Bearer"`; `""` sends the bare token. */
26
+ scheme?: string;
27
27
  };
28
28
 
29
29
  // A header name is a token (RFC 9110 §5.6.2).
@@ -31,7 +31,7 @@ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
31
31
 
32
32
  // A bare origin, optionally with a trailing slash. A path would look like a narrower limit than
33
33
  // the origin the token is really sent to.
34
- function originOf(value: unknown): string | null {
34
+ function originOf(value: unknown): null | string {
35
35
  if (typeof value !== "string") return null;
36
36
  try {
37
37
  const { origin } = new URL(value);
@@ -56,7 +56,7 @@ const own = <T extends object, K extends keyof T>(source: T, key: K): T[K] | und
56
56
  // that leaves the page (`//host`, `/\host`) is told apart from one that stays on it.
57
57
  const SAME_ORIGIN = "https://same-origin.invalid";
58
58
 
59
- function resolvedOrigin(url: string, base: string | undefined): string | null {
59
+ function resolvedOrigin(url: string, base: string | undefined): null | string {
60
60
  try {
61
61
  return new URL(url, base).origin;
62
62
  }
@@ -72,7 +72,7 @@ function pageHref(): string | undefined {
72
72
  return undefined;
73
73
  }
74
74
 
75
- function sendsTokenTo(config: InternalFaxiosRequestConfig, origins: ReadonlyArray<string> | null): boolean {
75
+ function sendsTokenTo(config: InternalFaxiosRequestConfig, origins: null | ReadonlyArray<string>): boolean {
76
76
  const baseURL = own(config, "baseURL");
77
77
  const url = buildFullPath(baseURL, own(config, "url"), own(config, "allowAbsoluteUrls"), config);
78
78
  if (origins) {
@@ -91,8 +91,12 @@ function sendsTokenTo(config: InternalFaxiosRequestConfig, origins: ReadonlyArra
91
91
  * can ask for a token too. A header the request already has is kept unless `overwrite` is set.
92
92
  * The token goes only to the `baseURL` origin when `baseURL` is absolute, otherwise only to
93
93
  * relative request URLs; `origins` replaces that rule.
94
+ *
95
+ * When `getToken` gives anything other than a non-empty string (`null`, `undefined`, `""`, a
96
+ * number, an object), the request is sent without the header, so a signed-out state never sends
97
+ * `Bearer null`. The parameter type stays `string`: the guard is for JavaScript callers and casts.
94
98
  */
95
- export function authBearer(getToken: () => string | Promise<string>, options: AuthBearerOptions = {}): FaxiosPlugin<{ provides: AuthBearerCapability; }> {
99
+ export function authBearer(getToken: () => Promise<string> | string, options: AuthBearerOptions = {}): FaxiosPlugin<{ provides: AuthBearerCapability; }> {
96
100
  if (typeof getToken !== "function") {
97
101
  throw new FaxiosError("authBearer: getToken must be a function", FaxiosError.ERR_BAD_OPTION_VALUE);
98
102
  }
@@ -112,7 +116,8 @@ export function authBearer(getToken: () => string | Promise<string>, options: Au
112
116
  provides: { auth },
113
117
  middleware: async (ctx, next) => {
114
118
  if ((!overwrite && ctx.config.headers.has(header)) || !sendsTokenTo(ctx.config, origins)) return next(ctx);
115
- const token = await auth.getToken();
119
+ const token: unknown = await auth.getToken();
120
+ if (typeof token !== "string" || token === "") return next(ctx);
116
121
  // On a copy: middleware that calls next() again (retry installed before this plugin) comes
117
122
  // back through here without the header, so every try asks for a fresh token.
118
123
  const headers = new FaxiosHeaders(ctx.config.headers).set(header, scheme ? `${scheme} ${token}` : token, true);
@@ -19,15 +19,15 @@ type RequiredCapabilities<TCapabilities, TProvides> = [keyof TProvides] extends
19
19
  */
20
20
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- `{}`: no capabilities or options, as in FaxiosContext
21
21
  export function definePlugin<TProvides = {}, TOptions = {}, TCapabilities = TProvides>(plugin: {
22
+ middleware: FaxiosMiddleware<TOptions, TCapabilities>;
22
23
  name: string;
23
24
  // The middleware reads the capabilities it provides from ctx too, so they must have the types
24
25
  // its context declares. NoInfer: TProvides is inferred from the value alone.
25
26
  provides?: TProvides & NoInfer<Pick<TCapabilities, keyof TProvides & keyof TCapabilities>>;
26
- middleware: FaxiosMiddleware<TOptions, TCapabilities>;
27
27
  }): FaxiosPlugin<{
28
- requires: RequiredCapabilities<TCapabilities, TProvides>;
29
- provides: Slot<TProvides>;
30
28
  options: Slot<TOptions>;
29
+ provides: Slot<TProvides>;
30
+ requires: RequiredCapabilities<TCapabilities, TProvides>;
31
31
  }> {
32
32
  // Only the types change: use() reads the fields at install time, as it does for any plugin.
33
33
  return plugin as never;
@@ -55,37 +55,36 @@ function assertRetryOptions(value: unknown, config?: InternalFaxiosRequestConfig
55
55
  export type RetryOptions = {
56
56
  /** Total tries, counting the first request. Default 3. */
57
57
  attempts?: number;
58
- /**
59
- * Whether the try that just failed should be retried. `attempt` counts from 1.
60
- * Default: network errors, timeouts and the `statuses`; never a cancellation. A custom `retryOn`
61
- * replaces that whole predicate, so `statuses` is ignored when both are set. retryOn decides
62
- * only within `methods`; to retry POST, list it in `methods`.
63
- */
64
- retryOn?: (error: unknown, attempt: number) => boolean;
65
- /**
66
- * Response statuses the default predicate retries. Default 408, 429, 500, 502, 503 and 504.
67
- * Ignored when `retryOn` is set.
68
- */
69
- statuses?: ReadonlyArray<number>;
70
58
  /**
71
59
  * Milliseconds to wait before the next try, or a function of the try that failed. Default 100ms,
72
60
  * doubling. Capped at `maxDelay`, then jittered. A 429 or 503 with a `Retry-After` header waits
73
61
  * that long instead, unless `respectRetryAfter` is `false`.
74
62
  */
75
- delay?: number | ((attempt: number, error: unknown) => number);
76
- /** The most the computed backoff waits, in milliseconds. Default 30 000. Doesn't apply to `Retry-After`. */
77
- maxDelay?: number;
63
+ delay?: ((attempt: number, error: unknown) => number) | number;
78
64
  /**
79
65
  * `"full"` (default) waits a random time between 0 and the capped backoff, so clients that failed
80
66
  * together don't retry together; `"none"` waits the capped backoff. Doesn't apply to `Retry-After`.
81
67
  */
82
68
  jitter?: "full" | "none";
69
+ /** The most the computed backoff waits, in milliseconds. Default 30 000. Doesn't apply to `Retry-After`. */
70
+ maxDelay?: number;
83
71
  /**
84
72
  * The longest `Retry-After` (seconds or an HTTP date, on a 429 or 503) to wait, in milliseconds.
85
73
  * Default 300 000 (5 minutes). A longer one rejects with the response's error instead of retrying.
86
74
  * Ignored when `respectRetryAfter` is `false`.
87
75
  */
88
76
  maxRetryAfter?: number;
77
+ /**
78
+ * HTTP methods that may be retried, in any case. Default: GET, HEAD, OPTIONS, PUT, DELETE and
79
+ * QUERY. POST and PATCH aren't idempotent, so add them only if your API dedupes repeats. A request
80
+ * whose method isn't listed is never retried, whatever `retryOn` or `statuses` say.
81
+ */
82
+ methods?: ReadonlyArray<Method>;
83
+ /**
84
+ * Called before each wait with the error, the try that failed and the wait in milliseconds. If it
85
+ * throws, the request rejects with that error and stops retrying.
86
+ */
87
+ onRetry?: (error: unknown, attempt: number, delayMs: number) => void;
89
88
  /**
90
89
  * Whether a 429 or 503's `Retry-After` header sets the wait. Default `true`. With `false`, every
91
90
  * retry waits the computed backoff and `maxRetryAfter` doesn't apply; which requests retry doesn't
@@ -93,20 +92,21 @@ export type RetryOptions = {
93
92
  */
94
93
  respectRetryAfter?: boolean;
95
94
  /**
96
- * Called before each wait with the error, the try that failed and the wait in milliseconds. If it
97
- * throws, the request rejects with that error and stops retrying.
95
+ * Whether the try that just failed should be retried. `attempt` counts from 1.
96
+ * Default: network errors, timeouts and the `statuses`; never a cancellation. A custom `retryOn`
97
+ * replaces that whole predicate, so `statuses` is ignored when both are set. retryOn decides
98
+ * only within `methods`; to retry POST, list it in `methods`.
98
99
  */
99
- onRetry?: (error: unknown, attempt: number, delayMs: number) => void;
100
+ retryOn?: (error: unknown, attempt: number) => boolean;
100
101
  /**
101
- * HTTP methods that may be retried, in any case. Default: GET, HEAD, OPTIONS, PUT, DELETE and
102
- * QUERY. POST and PATCH aren't idempotent, so add them only if your API dedupes repeats. A request
103
- * whose method isn't listed is never retried, whatever `retryOn` or `statuses` say.
102
+ * Response statuses the default predicate retries. Default 408, 429, 500, 502, 503 and 504.
103
+ * Ignored when `retryOn` is set.
104
104
  */
105
- methods?: ReadonlyArray<Method>;
105
+ statuses?: ReadonlyArray<number>;
106
106
  };
107
107
 
108
108
  /** Per-request override: `false` turns retries off, an object overrides the plugin's options. */
109
- export type RetryRequestOptions = { retry?: RetryOptions | false; };
109
+ export type RetryRequestOptions = { retry?: false | RetryOptions; };
110
110
 
111
111
  function retryByDefault(error: unknown, statuses: ReadonlyArray<number>): boolean {
112
112
  if (isCancel(error) || !(error instanceof FaxiosError)) return false;
@@ -164,13 +164,13 @@ function retriesMethod(config: InternalFaxiosRequestConfig, perRequest: RetryOpt
164
164
 
165
165
  type Policy = {
166
166
  attempts: number;
167
- retryOn: (error: unknown, attempt: number) => boolean;
168
- delay: number | ((attempt: number, error: unknown) => number);
169
- maxDelay: number;
167
+ delay: ((attempt: number, error: unknown) => number) | number;
170
168
  jitter: "full" | "none";
169
+ maxDelay: number;
171
170
  maxRetryAfter: number;
172
- respectRetryAfter: boolean;
173
171
  onRetry: ((error: unknown, attempt: number, delayMs: number) => void) | undefined;
172
+ respectRetryAfter: boolean;
173
+ retryOn: (error: unknown, attempt: number) => boolean;
174
174
  };
175
175
 
176
176
  // Per field, request first: no merged object, and only own properties count.
@@ -11,17 +11,17 @@ import { definePlugin } from "./definePlugin.js";
11
11
  * headers or body, so an event is safe to log.
12
12
  */
13
13
  export type TimingEvent = {
14
- /** The request method, upper-cased (`"GET"`). */
15
- method: string;
16
- /** The full request URL without its query string and fragment. */
17
- url: string;
18
14
  /**
19
15
  * The try number from `retry`: each try's when installed after it, the final try's when
20
16
  * installed before it. Absent without `retry`.
21
17
  */
22
18
  attempt?: number;
23
19
  durationMs: number;
24
- } & ({ status: number; error?: undefined; } | { status?: undefined; error: unknown; });
20
+ /** The request method, upper-cased (`"GET"`). */
21
+ method: string;
22
+ /** The full request URL without its query string and fragment. */
23
+ url: string;
24
+ } & ({ error: unknown; status?: undefined; } | { error?: undefined; status: number; });
25
25
 
26
26
  const now = () => (typeof performance === "undefined" ? Date.now() : performance.now());
27
27
 
@@ -13,12 +13,12 @@ export interface StandardSchemaV1<Input = unknown, Output = Input> {
13
13
 
14
14
  export declare namespace StandardSchemaV1 {
15
15
  interface Props<Input = unknown, Output = Input> {
16
- readonly version: 1;
17
- readonly vendor: string;
18
16
  readonly types?: Types<Input, Output>;
19
17
  readonly validate: (
20
18
  value: unknown
21
- ) => Result<Output> | Promise<Result<Output>>;
19
+ ) => Promise<Result<Output>> | Result<Output>;
20
+ readonly vendor: string;
21
+ readonly version: 1;
22
22
  }
23
23
 
24
24
  interface Types<Input = unknown, Output = Input> {
@@ -26,11 +26,11 @@ export declare namespace StandardSchemaV1 {
26
26
  readonly output: Output;
27
27
  }
28
28
 
29
- type Result<Output> = SuccessResult<Output> | FailureResult;
29
+ type Result<Output> = FailureResult | SuccessResult<Output>;
30
30
 
31
31
  interface SuccessResult<Output> {
32
- readonly value: Output;
33
32
  readonly issues?: undefined;
33
+ readonly value: Output;
34
34
  }
35
35
 
36
36
  interface FailureResult {
@@ -40,7 +40,7 @@ export declare namespace StandardSchemaV1 {
40
40
  interface Issue {
41
41
  readonly message: string;
42
42
  readonly path?:
43
- | ReadonlyArray<PropertyKey | PathSegment>
43
+ | ReadonlyArray<PathSegment | PropertyKey>
44
44
  | undefined;
45
45
  }
46
46