@zimic/http 0.1.0-canary.7 → 0.1.0

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 (47) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +111 -177
  3. package/dist/{chunk-6UNIPPBC.mjs → chunk-C5GWXTO5.mjs} +117 -140
  4. package/dist/chunk-C5GWXTO5.mjs.map +1 -0
  5. package/dist/{chunk-343XY3VF.js → chunk-KDDZRZK6.js} +117 -140
  6. package/dist/chunk-KDDZRZK6.js.map +1 -0
  7. package/dist/cli.js +9 -9
  8. package/dist/cli.js.map +1 -1
  9. package/dist/cli.mjs +3 -3
  10. package/dist/cli.mjs.map +1 -1
  11. package/dist/index.d.ts +22 -37
  12. package/dist/index.js +17 -19
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +17 -19
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/typegen.js +2 -2
  17. package/dist/typegen.mjs +1 -1
  18. package/package.json +12 -11
  19. package/src/formData/HttpFormData.ts +2 -2
  20. package/src/formData/types.ts +1 -1
  21. package/src/headers/HttpHeaders.ts +12 -10
  22. package/src/headers/types.ts +1 -1
  23. package/src/pathParams/types.ts +1 -1
  24. package/src/searchParams/HttpSearchParams.ts +1 -1
  25. package/src/searchParams/types.ts +1 -1
  26. package/src/typegen/openapi/generate.ts +1 -2
  27. package/src/typegen/openapi/transform/components.ts +2 -3
  28. package/src/typegen/openapi/transform/filters.ts +3 -3
  29. package/src/typegen/openapi/transform/io.ts +3 -5
  30. package/src/typegen/openapi/transform/methods.ts +4 -5
  31. package/src/typegen/openapi/transform/operations.ts +2 -3
  32. package/src/typegen/openapi/transform/paths.ts +2 -3
  33. package/src/types/requests.ts +2 -1
  34. package/src/types/schema.ts +14 -32
  35. package/src/utils/console.ts +1 -1
  36. package/src/utils/files.ts +4 -24
  37. package/src/utils/prettier.ts +1 -1
  38. package/src/utils/time.ts +1 -1
  39. package/dist/chunk-343XY3VF.js.map +0 -1
  40. package/dist/chunk-6UNIPPBC.mjs.map +0 -1
  41. package/src/types/arrays.d.ts +0 -4
  42. package/src/types/objects.d.ts +0 -14
  43. package/src/types/strings.d.ts +0 -9
  44. package/src/types/utils.ts +0 -40
  45. package/src/utils/data.ts +0 -13
  46. package/src/utils/imports.ts +0 -12
  47. package/src/utils/urls.ts +0 -52
package/dist/index.d.ts CHANGED
@@ -381,9 +381,9 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
381
381
  declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> extends Headers {
382
382
  constructor(init?: HttpHeadersInit<Schema>);
383
383
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/set MDN Reference} */
384
- set<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]>): void;
384
+ set<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]> & string): void;
385
385
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/append MDN Reference} */
386
- append<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]>): void;
386
+ append<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]> & string): void;
387
387
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/get MDN Reference} */
388
388
  get<Name extends HttpHeadersSchemaName<Schema>>(name: Name): ReplaceBy<Schema[Name], undefined, null>;
389
389
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
@@ -392,16 +392,19 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
392
392
  has<Name extends HttpHeadersSchemaName<Schema>>(name: Name): boolean;
393
393
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/delete MDN Reference} */
394
394
  delete<Name extends HttpHeadersSchemaName<Schema>>(name: Name): void;
395
- forEach<This extends HttpHeaders<Schema>>(callback: <Key extends HttpHeadersSchemaName<Schema>>(value: NonNullable<Schema[Key]>, key: Key, parent: Headers) => void, thisArg?: This): void;
395
+ forEach<This extends HttpHeaders<Schema>>(callback: <Key extends HttpHeadersSchemaName<Schema>>(value: NonNullable<Schema[Key]> & string, key: Key, parent: Headers) => void, thisArg?: This): void;
396
396
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/keys MDN Reference} */
397
397
  keys(): HeadersIterator<HttpHeadersSchemaName<Schema>>;
398
398
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/values MDN Reference} */
399
- values(): HeadersIterator<NonNullable<Schema[HttpHeadersSchemaName<Schema>]>>;
399
+ values(): HeadersIterator<NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string>;
400
400
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/entries MDN Reference} */
401
- entries(): HeadersIterator<[HttpHeadersSchemaName<Schema>, NonNullable<Schema[HttpHeadersSchemaName<Schema>]>]>;
401
+ entries(): HeadersIterator<[
402
+ HttpHeadersSchemaName<Schema>,
403
+ NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string
404
+ ]>;
402
405
  [Symbol.iterator](): HeadersIterator<[
403
406
  HttpHeadersSchemaName<Schema>,
404
- NonNullable<Schema[HttpHeadersSchemaName<Schema>]>
407
+ NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string
405
408
  ]>;
406
409
  /**
407
410
  * Checks if this headers object is equal to another set of headers. Equality is defined as having the same keys and
@@ -639,7 +642,7 @@ type HttpMethod = (typeof HTTP_METHODS)[number];
639
642
  /**
640
643
  * A schema representing the structure of an HTTP request.
641
644
  *
642
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
645
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
643
646
  */
644
647
  interface HttpRequestSchema {
645
648
  headers?: HttpHeadersSchema.Loose;
@@ -652,7 +655,7 @@ type ConvertToStrictHttpRequestSchema<Schema> = {
652
655
  /**
653
656
  * A schema representing the structure of an HTTP response.
654
657
  *
655
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
658
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
656
659
  */
657
660
  interface HttpResponseSchema {
658
661
  headers?: HttpHeadersSchema.Loose;
@@ -728,7 +731,7 @@ declare namespace HttpResponseSchemaByStatusCode {
728
731
  /**
729
732
  * A schema representing the structure of HTTP responses by status code.
730
733
  *
731
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
734
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
732
735
  */
733
736
  type HttpResponseSchemaByStatusCode = HttpResponseSchemaByStatusCode.ConvertToStrict<HttpResponseSchemaByStatusCode.Loose>;
734
737
  type ConvertToStrictHttpResponseSchemaByStatusCode<Schema> = {
@@ -737,13 +740,13 @@ type ConvertToStrictHttpResponseSchemaByStatusCode<Schema> = {
737
740
  /**
738
741
  * Extracts the status codes used in a response schema by status code.
739
742
  *
740
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
743
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
741
744
  */
742
745
  type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends HttpResponseSchemaByStatusCode> = keyof ResponseSchemaByStatusCode & HttpStatusCode;
743
746
  /**
744
747
  * A schema representing the structure of an HTTP request and response for a given method.
745
748
  *
746
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
749
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
747
750
  */
748
751
  interface HttpMethodSchema {
749
752
  request?: HttpRequestSchema;
@@ -770,7 +773,7 @@ type ConvertToStrictMethod<Schema> = {
770
773
  /**
771
774
  * A schema representing the structure of HTTP request and response by method.
772
775
  *
773
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
776
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
774
777
  */
775
778
  interface HttpMethodsSchema {
776
779
  GET?: HttpMethodSchema.NoRequestBody;
@@ -793,9 +796,6 @@ type ConvertToStrictHttpSchema<Schema extends HttpSchema> = {
793
796
  /**
794
797
  * Declares an HTTP service schema.
795
798
  *
796
- * **IMPORTANT**: the input of `HttpSchema` and all of its internal types, except bodies, must be declared inline or as
797
- * a type aliases (`type`). Types other than bodies cannot be interfaces.
798
- *
799
799
  * @example
800
800
  * import { type HttpSchema } from '@zimic/http';
801
801
  *
@@ -826,16 +826,13 @@ type ConvertToStrictHttpSchema<Schema extends HttpSchema> = {
826
826
  * };
827
827
  * }>;
828
828
  *
829
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
829
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
830
830
  */
831
831
  type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = ConvertToStrictHttpSchema<Schema>;
832
832
  declare namespace HttpSchema {
833
833
  /**
834
834
  * Declares an HTTP service methods schema.
835
835
  *
836
- * **IMPORTANT**: the input of `HttpSchema.Methods` and all of its internal types, except bodies, must be declared
837
- * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces.
838
- *
839
836
  * @example
840
837
  * import { type HttpSchema } from '@zimic/http';
841
838
  *
@@ -855,9 +852,6 @@ declare namespace HttpSchema {
855
852
  /**
856
853
  * Declares an HTTP service method schema.
857
854
  *
858
- * **IMPORTANT**: the input of `HttpSchema.Method` and all of its internal types, except bodies, must be declared
859
- * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces.
860
- *
861
855
  * @example
862
856
  * import { type HttpSchema } from '@zimic/http';
863
857
  *
@@ -877,9 +871,6 @@ declare namespace HttpSchema {
877
871
  /**
878
872
  * Declares an HTTP service request schema.
879
873
  *
880
- * **IMPORTANT**: the input of `HttpSchema.Request` and all of its internal types, except bodies, must be declared
881
- * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces.
882
- *
883
874
  * @example
884
875
  * import { type HttpSchema } from '@zimic/http';
885
876
  *
@@ -903,9 +894,6 @@ declare namespace HttpSchema {
903
894
  /**
904
895
  * Declares an HTTP service response schema by status code.
905
896
  *
906
- * **IMPORTANT**: the input of `HttpSchema.ResponseByStatusCode` and all of its internal types, except bodies, must be
907
- * declared inline or as a type aliases (`type`). Types other than bodies cannot be interfaces.
908
- *
909
897
  * @example
910
898
  * import { type HttpSchema } from '@zimic/http';
911
899
  *
@@ -926,9 +914,6 @@ declare namespace HttpSchema {
926
914
  /**
927
915
  * Declares an HTTP service response schema.
928
916
  *
929
- * **IMPORTANT**: the input of `HttpSchema.Response` and all of its internal types, except bodies, must be declared
930
- * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces.
931
- *
932
917
  * @example
933
918
  * import { type HttpSchema } from '@zimic/http';
934
919
  *
@@ -1078,7 +1063,7 @@ declare namespace HttpSchema {
1078
1063
  /**
1079
1064
  * Extracts the methods from an HTTP service schema.
1080
1065
  *
1081
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
1066
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
1082
1067
  */
1083
1068
  type HttpSchemaMethod<Schema extends HttpSchema> = IfAny<Schema, any, // eslint-disable-line @typescript-eslint/no-explicit-any
1084
1069
  // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -1110,7 +1095,7 @@ type AllowAnyStringInPathParams<Path extends string> = Path extends `${infer Pre
1110
1095
  * type GetPath = HttpSchemaPath<Schema, 'GET'>;
1111
1096
  * // "/users"
1112
1097
  *
1113
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
1098
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
1114
1099
  */
1115
1100
  declare namespace HttpSchemaPath {
1116
1101
  type LooseLiteral<Schema extends HttpSchema, Method extends HttpMethod = HttpMethod> = {
@@ -1142,7 +1127,7 @@ declare namespace HttpSchemaPath {
1142
1127
  * type LiteralGetPath = HttpSchemaPath.Literal<Schema, 'GET'>;
1143
1128
  * // "/users"
1144
1129
  *
1145
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
1130
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
1146
1131
  */
1147
1132
  export type Literal<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>> = LooseLiteral<Schema, Method>;
1148
1133
  /**
@@ -1171,7 +1156,7 @@ declare namespace HttpSchemaPath {
1171
1156
  * type NonLiteralGetPath = HttpSchemaPath.NonLiteral<Schema, 'GET'>;
1172
1157
  * // "/users"
1173
1158
  *
1174
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http‐schemas Declaring HTTP interceptor schemas}
1159
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
1175
1160
  */
1176
1161
  export type NonLiteral<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>> = AllowAnyStringInPathParams<Literal<Schema, Method>>;
1177
1162
  export { };
@@ -1196,7 +1181,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
1196
1181
  * @example
1197
1182
  * import { HttpSchema, InferPathParams } from '@zimic/http';
1198
1183
  *
1199
- * type MySchema = HttpSchema<{
1184
+ * type Schema = HttpSchema<{
1200
1185
  * '/users/:userId': {
1201
1186
  * GET: {
1202
1187
  * response: { 200: { body: User } };
@@ -1205,7 +1190,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
1205
1190
  * }>;
1206
1191
  *
1207
1192
  * // Using a schema to validate the path (recommended):
1208
- * type PathParams = InferPathParams<MySchema, '/users/:userId'>;
1193
+ * type PathParams = InferPathParams<Schema, '/users/:userId'>;
1209
1194
  * // { userId: string }
1210
1195
  *
1211
1196
  * @example
package/dist/index.js CHANGED
@@ -3,27 +3,25 @@
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
5
 
6
- // src/utils/data.ts
6
+ // ../zimic-utils/dist/chunk-PAWJFY3S.mjs
7
+ var __defProp2 = Object.defineProperty;
8
+ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
9
+
10
+ // ../zimic-utils/dist/chunk-HVLEF6VF.mjs
7
11
  async function blobEquals(blob, otherBlob) {
8
12
  return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
9
13
  }
10
14
  __name(blobEquals, "blobEquals");
15
+ __name2(blobEquals, "blobEquals");
16
+ var blobEquals_default = blobEquals;
11
17
 
12
- // src/utils/imports.ts
13
- function createCachedDynamicImport(importModuleDynamically) {
14
- let cachedImportResult;
15
- return /* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
16
- if (cachedImportResult === undefined) {
17
- cachedImportResult = await importModuleDynamically();
18
- }
19
- return cachedImportResult;
20
- }, "importModuleDynamicallyWithCache");
21
- }
22
- __name(createCachedDynamicImport, "createCachedDynamicImport");
18
+ // ../zimic-utils/dist/data/fileEquals.mjs
23
19
  async function fileEquals(file, otherFile) {
24
- return file.name === otherFile.name && await blobEquals(file, otherFile);
20
+ return file.name === otherFile.name && await blobEquals_default(file, otherFile);
25
21
  }
26
22
  __name(fileEquals, "fileEquals");
23
+ __name2(fileEquals, "fileEquals");
24
+ var fileEquals_default = fileEquals;
27
25
 
28
26
  // src/formData/HttpFormData.ts
29
27
  var HttpFormData = class extends FormData {
@@ -31,14 +29,14 @@ var HttpFormData = class extends FormData {
31
29
  __name(this, "HttpFormData");
32
30
  }
33
31
  set(name, blobOrValue, fileName) {
34
- if (fileName === undefined) {
32
+ if (fileName === void 0) {
35
33
  super.set(name, blobOrValue);
36
34
  } else {
37
35
  super.set(name, blobOrValue, fileName);
38
36
  }
39
37
  }
40
38
  append(name, blobOrValue, fileName) {
41
- if (fileName === undefined) {
39
+ if (fileName === void 0) {
42
40
  super.append(name, blobOrValue);
43
41
  } else {
44
42
  super.append(name, blobOrValue, fileName);
@@ -111,7 +109,7 @@ var HttpFormData = class extends FormData {
111
109
  }
112
110
  let valueExists = false;
113
111
  for (const value of values) {
114
- if (value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals(value, otherValue)) {
112
+ if (value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals_default(value, otherValue)) {
115
113
  valueExists = true;
116
114
  break;
117
115
  }
@@ -145,7 +143,7 @@ var HttpFormData = class extends FormData {
145
143
  }
146
144
  let valueExists = false;
147
145
  for (const value of values) {
148
- if (value === otherValue || typeof value === "string" && typeof otherValue === "string" && value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals(value, otherValue)) {
146
+ if (value === otherValue || typeof value === "string" && typeof otherValue === "string" && value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals_default(value, otherValue)) {
149
147
  valueExists = true;
150
148
  break;
151
149
  }
@@ -202,7 +200,7 @@ var HttpFormData_default = HttpFormData;
202
200
  // src/headers/HttpHeaders.ts
203
201
  function pickPrimitiveProperties(schema) {
204
202
  return Object.entries(schema).reduce((accumulated, [key, value]) => {
205
- if (value !== undefined) {
203
+ if (value !== void 0) {
206
204
  accumulated[key] = value;
207
205
  }
208
206
  return accumulated;
@@ -353,7 +351,7 @@ var HttpHeaders_default = HttpHeaders;
353
351
  function pickPrimitiveProperties2(schema) {
354
352
  const schemaWithPrimitiveProperties = Object.entries(schema).reduce(
355
353
  (accumulated, [key, value]) => {
356
- if (value !== undefined && !Array.isArray(value)) {
354
+ if (value !== void 0 && !Array.isArray(value)) {
357
355
  accumulated[key] = value;
358
356
  }
359
357
  return accumulated;