From e764471ec96a693164af92924fdfb3adf8f453ae Mon Sep 17 00:00:00 2001 From: Sebastian Nemeth <157464438+holvi-sebastian@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:04:13 +0200 Subject: [PATCH 1/2] explicitly define separate .d.cts file for commonjs usages --- package.json | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 521e819e..c51c4bab 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,15 @@ "module": "dist/main.mjs", "unpkg": "dist/bundle.js", "exports": { - ".": { - "types": "./index.d.ts", - "import": "./dist/main.mjs", - "require": "./dist/main.cjs", + ".": { + "import": { + "types": "./index.d.ts", + "default": "./dist/main.mjs" + }, + "require": { + "types": "./index.d.cts", + "default": "./dist/main.cjs" + }, "browser": "./dist/bundle.js" } }, From 796736b0beaaf84b2c73a287fde140ac3d36d3ff Mon Sep 17 00:00:00 2001 From: Sebastian Nemeth <157464438+holvi-sebastian@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:05:24 +0200 Subject: [PATCH 2/2] add copy of index.d.ts that is used in commonjs imports --- index.d.cts | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 index.d.cts diff --git a/index.d.cts b/index.d.cts new file mode 100644 index 00000000..fc29bcc4 --- /dev/null +++ b/index.d.cts @@ -0,0 +1,84 @@ +import type { JsonValue, JsonObject } from 'type-fest'; +import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema'; + +export type Schema = JSONSchema4 | JSONSchema6 | JSONSchema7; + +export interface JSONSchemaFakerOptions { + defaultInvalidTypeProduct?: boolean; + defaultRandExpMax?: number; + pruneProperties?: string[]; + ignoreProperties?: string[]; + ignoreMissingRefs?: boolean; + failOnInvalidTypes?: boolean; + failOnInvalidFormat?: boolean; + alwaysFakeOptionals?: boolean; + optionalsProbability?: number | false; + fixedProbabilities?: boolean; + useExamplesValue?: boolean; + useDefaultValue?: boolean; + requiredOnly?: boolean; + omitNulls?: boolean; + minItems?: number; + maxItems?: number; + minLength?: number; + maxLength?: number; + resolveJsonPath?: boolean; + reuseProperties?: boolean; + sortProperties?: boolean; + fillProperties?: boolean; + replaceEmptyByRandomValue?: boolean; + random?: () => number | number; + minDateTime?: Date | string | number; + maxDateTime?: Date | string | number; + renderTitle?: boolean; + renderDescription?: boolean; + renderComment?: boolean; + refDepthMax?: number; + refDepthMin?: number; +} + +export type JSONSchemaFakerRefs = Schema[] | { [k: string]: Schema }; + +export interface JSONSchemaFakerDefine { + (value: JsonValue, schema: JsonObject, property: string, rootSchema: Schema, propertyPath: string[]): JsonValue; +} + +export interface JSONSchemaFakerFormat { + (opts: { [k: string]: (value: Schema) => unknown }): void; + (name: string, callback: (value: Schema) => unknown): void; +} + +declare function JSONSchemaFakerOption(opts: JSONSchemaFakerOptions): void; +declare function JSONSchemaFakerOption(name: keyof JSONSchemaFakerOptions, value: any): void; +declare namespace JSONSchemaFakerOption { + var getDefaults: () => JSONSchemaFakerOptions; +} + +type JSONSchemaFakerObject = { + VERSION: string; + format: JSONSchemaFakerFormat; + option: typeof JSONSchemaFakerOption; + generate: (schema: Schema, refs?: JSONSchemaFakerRefs) => JsonValue; + generateYAML: (schema: Schema, refs?: JSONSchemaFakerRefs) => string; + resolve: (schema: Schema, refs?: JSONSchemaFakerRefs, cwd?: string) => Promise; + resolveYAML: (schema: Schema, refs?: JSONSchemaFakerRefs, cwd?: string) => Promise; + random: { + date(step?: 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years'): number | Date; + pick(list: any[]): any; + shuffle(list: any[]): any[]; + number(min?: number, max?: number, defMin?: number, defMax?: number, hasPrecision?: boolean): number; + randexp(expr: string): string; + }; + extend: (name: string, cb: (generator: any) => any) => typeof JSONSchemaFaker; + define: (name: string, cb: JSONSchemaFakerDefine) => typeof JSONSchemaFaker; + reset: (name: string) => typeof JSONSchemaFaker; + locate: (name: string) => any; +} + +export declare const JSONSchemaFaker: JSONSchemaFakerObject; + +/** @deprecated The default export is deprecated; use the named export. See https://github.com/json-schema-faker/json-schema-faker/blob/master/docs/DEPRECATED.md */ +declare const jsf: JSONSchemaFakerObject & { + (schema: Schema, refs?: JSONSchemaFakerRefs, cwd?: string): JsonValue +}; +export default jsf;