@zimic/http 0.0.1-canary.2

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 (61) hide show
  1. package/LICENSE.md +16 -0
  2. package/README.md +230 -0
  3. package/dist/chunk-VHQRAQPQ.mjs +1371 -0
  4. package/dist/chunk-VHQRAQPQ.mjs.map +1 -0
  5. package/dist/chunk-VUDGONB5.js +1382 -0
  6. package/dist/chunk-VUDGONB5.js.map +1 -0
  7. package/dist/cli.js +116 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/cli.mjs +109 -0
  10. package/dist/cli.mjs.map +1 -0
  11. package/dist/index.d.ts +1306 -0
  12. package/dist/index.js +544 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/index.mjs +537 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/typegen.d.ts +86 -0
  17. package/dist/typegen.js +12 -0
  18. package/dist/typegen.js.map +1 -0
  19. package/dist/typegen.mjs +3 -0
  20. package/dist/typegen.mjs.map +1 -0
  21. package/index.d.ts +1 -0
  22. package/package.json +110 -0
  23. package/src/cli/cli.ts +92 -0
  24. package/src/cli/index.ts +4 -0
  25. package/src/cli/typegen/openapi.ts +24 -0
  26. package/src/formData/HttpFormData.ts +300 -0
  27. package/src/formData/types.ts +110 -0
  28. package/src/headers/HttpHeaders.ts +217 -0
  29. package/src/headers/types.ts +65 -0
  30. package/src/index.ts +55 -0
  31. package/src/pathParams/types.ts +67 -0
  32. package/src/searchParams/HttpSearchParams.ts +258 -0
  33. package/src/searchParams/types.ts +133 -0
  34. package/src/typegen/index.ts +12 -0
  35. package/src/typegen/namespace/TypegenNamespace.ts +18 -0
  36. package/src/typegen/openapi/generate.ts +168 -0
  37. package/src/typegen/openapi/transform/components.ts +481 -0
  38. package/src/typegen/openapi/transform/context.ts +67 -0
  39. package/src/typegen/openapi/transform/filters.ts +71 -0
  40. package/src/typegen/openapi/transform/imports.ts +15 -0
  41. package/src/typegen/openapi/transform/io.ts +86 -0
  42. package/src/typegen/openapi/transform/methods.ts +803 -0
  43. package/src/typegen/openapi/transform/operations.ts +120 -0
  44. package/src/typegen/openapi/transform/paths.ts +119 -0
  45. package/src/typegen/openapi/utils/types.ts +45 -0
  46. package/src/types/arrays.d.ts +4 -0
  47. package/src/types/json.ts +89 -0
  48. package/src/types/objects.d.ts +14 -0
  49. package/src/types/requests.ts +96 -0
  50. package/src/types/schema.ts +834 -0
  51. package/src/types/strings.d.ts +9 -0
  52. package/src/types/utils.ts +64 -0
  53. package/src/utils/console.ts +7 -0
  54. package/src/utils/data.ts +13 -0
  55. package/src/utils/files.ts +28 -0
  56. package/src/utils/imports.ts +12 -0
  57. package/src/utils/prettier.ts +13 -0
  58. package/src/utils/strings.ts +3 -0
  59. package/src/utils/time.ts +25 -0
  60. package/src/utils/urls.ts +52 -0
  61. package/typegen.d.ts +1 -0
@@ -0,0 +1,9 @@
1
+ interface String {
2
+ // Using the original method signature style to correctly apply the overload.
3
+ // eslint-disable-next-line @typescript-eslint/method-signature-style
4
+ toLowerCase<Type = string>(): Lowercase<Type>;
5
+
6
+ // Using the original method signature style to correctly apply the overload.
7
+ // eslint-disable-next-line @typescript-eslint/method-signature-style
8
+ toUpperCase<Type = string>(): Uppercase<Type>;
9
+ }
@@ -0,0 +1,64 @@
1
+ export type Default<Type, IfEmpty = never> = [undefined | void] extends [Type]
2
+ ? IfEmpty
3
+ : Exclude<Type, undefined | void>;
4
+
5
+ export type DefaultNoExclude<Type, IfEmpty = never> = [undefined | void] extends Type ? IfEmpty : Type;
6
+
7
+ export type IfAny<Type, Yes, No = Type> = 0 extends 1 & Type ? Yes : No;
8
+
9
+ export type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
10
+
11
+ export type PossiblePromise<Type> = Type | PromiseLike<Type>;
12
+
13
+ export type UnionToIntersection<Union> = (Union extends unknown ? (union: Union) => void : never) extends (
14
+ intersectedUnion: infer IntersectedUnion,
15
+ ) => void
16
+ ? IntersectedUnion
17
+ : never;
18
+
19
+ type LastUnionType<Union> =
20
+ UnionToIntersection<Union extends unknown ? (union: Union) => void : never> extends (x: infer LastType) => void
21
+ ? LastType
22
+ : never;
23
+
24
+ export type UnionToTuple<Union, LastType = LastUnionType<Union>> = [Union] extends [never]
25
+ ? []
26
+ : [...UnionToTuple<Exclude<Union, LastType>>, LastType];
27
+
28
+ export type UnionHasMoreThanOneType<Union> = [UnionToIntersection<Union>] extends [never] ? true : false;
29
+
30
+ export type Prettify<Type> = {
31
+ [Key in keyof Type]: Type[Key];
32
+ };
33
+
34
+ export type ArrayItemIfArray<Type> = Type extends (infer Item)[] ? Item : Type;
35
+
36
+ type PickArrayProperties<Type> = {
37
+ [Key in keyof Type as never[] extends Type[Key] ? Key : never]: Type[Key];
38
+ };
39
+
40
+ export type ArrayKey<Type> = keyof PickArrayProperties<Type>;
41
+
42
+ export type NonArrayKey<Type> =
43
+ string | number extends ArrayKey<Type> ? keyof Type : Exclude<keyof Type, ArrayKey<Type>>;
44
+
45
+ export type NonEmptyArray<Type> = [Type, ...Type[]];
46
+
47
+ export type ReplaceBy<Type, Source, Target> = Type extends Source ? Target : Type;
48
+
49
+ export type Collection<Type> = Type[] | Set<Type>;
50
+
51
+ export type DeepPartial<Type> = Type extends (...parameters: never[]) => unknown
52
+ ? Type
53
+ : Type extends (infer ArrayItem)[]
54
+ ? DeepPartial<ArrayItem>[]
55
+ : Type extends object
56
+ ? { [Key in keyof Type]?: DeepPartial<Type[Key]> }
57
+ : Type;
58
+
59
+ export type Override<Type, OverrideType> = Omit<Type, keyof OverrideType> & OverrideType;
60
+
61
+ export interface Range<Value> {
62
+ min: Value;
63
+ max: Value;
64
+ }
@@ -0,0 +1,7 @@
1
+ import chalk from 'chalk';
2
+
3
+ export function logWithPrefix(message: string, options: { method: 'log' | 'warn' | 'error' }) {
4
+ const { method } = options;
5
+
6
+ console[method](chalk.cyan('[zimic]'), message);
7
+ }
@@ -0,0 +1,13 @@
1
+ export async function blobEquals(blob: Blob, otherBlob: Blob) {
2
+ return (
3
+ blob.type === otherBlob.type && blob.size === otherBlob.size && (await blob.text()) === (await otherBlob.text())
4
+ );
5
+ }
6
+
7
+ export function isDefined<Value>(value: Value): value is NonNullable<Value> {
8
+ return value !== undefined && value !== null;
9
+ }
10
+
11
+ export function isNonEmpty<Value>(value: Value): value is Exclude<NonNullable<Value>, ''> {
12
+ return isDefined(value) && value !== '';
13
+ }
@@ -0,0 +1,28 @@
1
+ import { blobEquals } from './data';
2
+ import { createCachedDynamicImport } from './imports';
3
+
4
+ export const importBuffer = createCachedDynamicImport(
5
+ /* istanbul ignore next -- @preserve
6
+ * Ignoring as Node.js >=20 provides a global file and the buffer import won't run. */
7
+ () => import('buffer'),
8
+ );
9
+
10
+ let FileSingleton: typeof File | undefined;
11
+
12
+ export async function importFile() {
13
+ /* istanbul ignore if -- @preserve
14
+ * Ignoring as this will only run if this function is called more than once. */
15
+ if (FileSingleton) {
16
+ return FileSingleton;
17
+ }
18
+
19
+ /* istanbul ignore next -- @preserve
20
+ * Ignoring as Node.js >=20 provides a global File and the import fallback won't run. */
21
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
22
+ FileSingleton = globalThis.File ?? (await importBuffer()).File;
23
+ return FileSingleton;
24
+ }
25
+
26
+ export async function fileEquals(file: File, otherFile: File) {
27
+ return file.name === otherFile.name && (await blobEquals(file, otherFile));
28
+ }
@@ -0,0 +1,12 @@
1
+ export function createCachedDynamicImport<ImportType>(
2
+ importModuleDynamically: () => Promise<ImportType>,
3
+ ): () => Promise<ImportType> {
4
+ let cachedImportResult: ImportType | undefined;
5
+
6
+ return async function importModuleDynamicallyWithCache() {
7
+ if (cachedImportResult === undefined) {
8
+ cachedImportResult = await importModuleDynamically();
9
+ }
10
+ return cachedImportResult;
11
+ };
12
+ }
@@ -0,0 +1,13 @@
1
+ import prettier, { Options } from 'prettier'; // eslint-disable-line import/no-extraneous-dependencies
2
+
3
+ export async function resolvedPrettierConfig(fileName: string): Promise<Options> {
4
+ const config = await prettier.resolveConfig(fileName);
5
+
6
+ /* istanbul ignore if -- @preserve
7
+ * This function is used in tests and they will fail if no config is found. */
8
+ if (config === null) {
9
+ throw new Error('Prettier config not found.');
10
+ }
11
+
12
+ return config;
13
+ }
@@ -0,0 +1,3 @@
1
+ export function convertToPascalCase(value: string) {
2
+ return value.replace(/(?:^|[^A-Za-z\d])([A-Za-z\d])/g, (_match, letter: string) => letter.toUpperCase());
3
+ }
@@ -0,0 +1,25 @@
1
+ import { PossiblePromise } from '@/types/utils';
2
+
3
+ export async function usingElapsedTime<ReturnType>(callback: () => PossiblePromise<ReturnType>) {
4
+ const startTimeInMilliseconds = performance.now();
5
+
6
+ const result = await callback();
7
+
8
+ const endTimeInMilliseconds = performance.now();
9
+ const elapsedTimeInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
10
+
11
+ return {
12
+ startTime: startTimeInMilliseconds,
13
+ elapsedTime: elapsedTimeInMilliseconds,
14
+ endTime: endTimeInMilliseconds,
15
+ result,
16
+ };
17
+ }
18
+
19
+ export function formatElapsedTime(elapsedTimeInMilliseconds: number) {
20
+ if (elapsedTimeInMilliseconds < 1000) {
21
+ return `${elapsedTimeInMilliseconds.toFixed(0)}ms`;
22
+ } else {
23
+ return `${(elapsedTimeInMilliseconds / 1000).toFixed(2)}s`;
24
+ }
25
+ }
@@ -0,0 +1,52 @@
1
+ export class InvalidURLError extends TypeError {
2
+ constructor(url: unknown) {
3
+ super(`Invalid URL: '${url}'`);
4
+ this.name = 'InvalidURL';
5
+ }
6
+ }
7
+
8
+ export interface ExtendedURL extends URL {
9
+ raw: string;
10
+ }
11
+
12
+ function createURLOrThrow(rawURL: string | URL) {
13
+ try {
14
+ const url = new URL(rawURL) as ExtendedURL;
15
+
16
+ Object.defineProperty(url, 'raw', {
17
+ value: rawURL.toString(),
18
+ writable: false,
19
+ enumerable: true,
20
+ configurable: false,
21
+ });
22
+
23
+ return url;
24
+ } catch {
25
+ throw new InvalidURLError(rawURL);
26
+ }
27
+ }
28
+
29
+ export function createURL(rawURL: string | URL): ExtendedURL {
30
+ const url = createURLOrThrow(rawURL);
31
+ return url;
32
+ }
33
+
34
+ export function createFileURL(filePath: string) {
35
+ return createURL(`file://${filePath}`);
36
+ }
37
+
38
+ function prepareURLForRegex(url: string) {
39
+ const encodedURL = encodeURI(url);
40
+ return encodedURL.replace(/([.()*?+$\\])/g, '\\$1');
41
+ }
42
+
43
+ export function createRegexFromWildcardPath(path: string, options: { prefix: string }) {
44
+ const pathWithReplacedWildcards = prepareURLForRegex(path)
45
+ .replace(/^\/+|\/+$/g, '')
46
+ .replace(/\\\*/g, '*')
47
+ .replace(/\*\*\/\*/g, '**')
48
+ .replace(/(^|[^*])\*([^*]|$)/g, '$1[^/]*$2')
49
+ .replace(/\*\*/g, '.*');
50
+
51
+ return new RegExp(`^${options.prefix}/*${pathWithReplacedWildcards}/*$`);
52
+ }
package/typegen.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/typegen';