exact-mirror 1.0.0 → 1.0.1

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.
@@ -35,7 +35,7 @@ interface BaseSchema {
35
35
  type AnySchema = TSchema & BaseSchema;
36
36
  export declare const mergeObjectIntersection: (schema: AnySchema) => AnySchema;
37
37
  type MaybeArray<T> = T | T[];
38
- export interface Instruction {
38
+ export interface Instruction<Emit extends boolean = false> {
39
39
  optionals: string[];
40
40
  optionalsInArray: string[][];
41
41
  parentIsOptional: boolean;
@@ -44,6 +44,7 @@ export interface Instruction {
44
44
  unionKeys: Record<string, 1>;
45
45
  sanitize: MaybeArray<(v: string) => string> | undefined;
46
46
  fromUnion?: boolean;
47
+ emit?: Emit;
47
48
  /**
48
49
  * TypeCompiler is required when using Union
49
50
  *
@@ -72,5 +73,9 @@ export interface Instruction {
72
73
  removeUnknownUnionType: boolean;
73
74
  }
74
75
  export declare function deepClone<T>(source: T, weak?: WeakMap<object, any>): T;
75
- export declare const createMirror: <T extends TSchema>(schema: T, { Compile, modules, definitions, sanitize, recursionLimit, removeUnknownUnionType }?: Partial<Pick<Instruction, "Compile" | "definitions" | "sanitize" | "modules" | "recursionLimit" | "removeUnknownUnionType">>) => ((v: Static<T>) => Static<T>);
76
+ export interface Manifest {
77
+ unions: Validator<any, TSchema, unknown, unknown>[][];
78
+ hof?: Record<string, Function>;
79
+ }
80
+ export declare const createMirror: <T extends TSchema, Emit extends boolean = false>(schema: T, { Compile, modules, definitions, sanitize, recursionLimit, removeUnknownUnionType, emit }?: Partial<Pick<Instruction<Emit>, "Compile" | "definitions" | "sanitize" | "modules" | "recursionLimit" | "removeUnknownUnionType" | "emit">>) => Emit extends true ? Manifest : (v: Static<T>) => Static<T>;
76
81
  export default createMirror;
package/dist/cjs/index.js CHANGED
@@ -353,7 +353,8 @@ var createMirror = (schema, {
353
353
  definitions,
354
354
  sanitize: sanitize2,
355
355
  recursionLimit = 8,
356
- removeUnknownUnionType = false
356
+ removeUnknownUnionType = false,
357
+ emit
357
358
  } = {}) => {
358
359
  const unions = [];
359
360
  if (typeof sanitize2 === "function") sanitize2 = [sanitize2];
@@ -373,19 +374,29 @@ var createMirror = (schema, {
373
374
  recursionLimit,
374
375
  removeUnknownUnionType
375
376
  });
376
- if (!unions.length && !sanitize2?.length) return Function("v", f);
377
+ if (!unions.length && !sanitize2?.length) {
378
+ if (emit) return { unions, hof: void 0 };
379
+ return Function("v", f);
380
+ }
377
381
  let hof;
378
382
  if (sanitize2?.length) {
379
383
  hof = {};
380
384
  for (let i = 0; i < sanitize2.length; i++) hof[`h${i}`] = sanitize2[i];
381
385
  }
386
+ if (emit)
387
+ return {
388
+ unions,
389
+ hof
390
+ };
382
391
  return Function(
383
392
  "d",
384
393
  `return function mirror(v){${f}}`
385
- )({
386
- unions,
387
- ...hof
388
- });
394
+ )(
395
+ hof ? unions ? {
396
+ unions,
397
+ ...hof
398
+ } : hof : unions ? { unions } : void 0
399
+ );
389
400
  };
390
401
  var index_default = createMirror;
391
402
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ interface BaseSchema {
35
35
  type AnySchema = TSchema & BaseSchema;
36
36
  export declare const mergeObjectIntersection: (schema: AnySchema) => AnySchema;
37
37
  type MaybeArray<T> = T | T[];
38
- export interface Instruction {
38
+ export interface Instruction<Emit extends boolean = false> {
39
39
  optionals: string[];
40
40
  optionalsInArray: string[][];
41
41
  parentIsOptional: boolean;
@@ -44,6 +44,7 @@ export interface Instruction {
44
44
  unionKeys: Record<string, 1>;
45
45
  sanitize: MaybeArray<(v: string) => string> | undefined;
46
46
  fromUnion?: boolean;
47
+ emit?: Emit;
47
48
  /**
48
49
  * TypeCompiler is required when using Union
49
50
  *
@@ -72,5 +73,9 @@ export interface Instruction {
72
73
  removeUnknownUnionType: boolean;
73
74
  }
74
75
  export declare function deepClone<T>(source: T, weak?: WeakMap<object, any>): T;
75
- export declare const createMirror: <T extends TSchema>(schema: T, { Compile, modules, definitions, sanitize, recursionLimit, removeUnknownUnionType }?: Partial<Pick<Instruction, "Compile" | "definitions" | "sanitize" | "modules" | "recursionLimit" | "removeUnknownUnionType">>) => ((v: Static<T>) => Static<T>);
76
+ export interface Manifest {
77
+ unions: Validator<any, TSchema, unknown, unknown>[][];
78
+ hof?: Record<string, Function>;
79
+ }
80
+ export declare const createMirror: <T extends TSchema, Emit extends boolean = false>(schema: T, { Compile, modules, definitions, sanitize, recursionLimit, removeUnknownUnionType, emit }?: Partial<Pick<Instruction<Emit>, "Compile" | "definitions" | "sanitize" | "modules" | "recursionLimit" | "removeUnknownUnionType" | "emit">>) => Emit extends true ? Manifest : (v: Static<T>) => Static<T>;
76
81
  export default createMirror;
package/dist/index.mjs CHANGED
@@ -326,7 +326,8 @@ var createMirror = (schema, {
326
326
  definitions,
327
327
  sanitize: sanitize2,
328
328
  recursionLimit = 8,
329
- removeUnknownUnionType = false
329
+ removeUnknownUnionType = false,
330
+ emit
330
331
  } = {}) => {
331
332
  const unions = [];
332
333
  if (typeof sanitize2 === "function") sanitize2 = [sanitize2];
@@ -346,19 +347,29 @@ var createMirror = (schema, {
346
347
  recursionLimit,
347
348
  removeUnknownUnionType
348
349
  });
349
- if (!unions.length && !sanitize2?.length) return Function("v", f);
350
+ if (!unions.length && !sanitize2?.length) {
351
+ if (emit) return { unions, hof: void 0 };
352
+ return Function("v", f);
353
+ }
350
354
  let hof;
351
355
  if (sanitize2?.length) {
352
356
  hof = {};
353
357
  for (let i = 0; i < sanitize2.length; i++) hof[`h${i}`] = sanitize2[i];
354
358
  }
359
+ if (emit)
360
+ return {
361
+ unions,
362
+ hof
363
+ };
355
364
  return Function(
356
365
  "d",
357
366
  `return function mirror(v){${f}}`
358
- )({
359
- unions,
360
- ...hof
361
- });
367
+ )(
368
+ hof ? unions ? {
369
+ unions,
370
+ ...hof
371
+ } : hof : unions ? { unions } : void 0
372
+ );
362
373
  };
363
374
  var index_default = createMirror;
364
375
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exact-mirror",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Mirror exact value to TypeBox/OpenAPI model",
5
5
  "license": "MIT",
6
6
  "scripts": {