exact-mirror 1.0.0 → 1.0.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.
- package/dist/cjs/index.d.ts +10 -2
- package/dist/cjs/index.js +22 -7
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +22 -7
- package/package.json +1 -1
package/dist/cjs/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,12 @@ 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
|
|
76
|
+
export interface Manifest {
|
|
77
|
+
source: string;
|
|
78
|
+
externals: {
|
|
79
|
+
unions: Validator<any, TSchema, unknown, unknown>[][];
|
|
80
|
+
hof?: Record<string, Function>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
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
84
|
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,33 @@ var createMirror = (schema, {
|
|
|
373
374
|
recursionLimit,
|
|
374
375
|
removeUnknownUnionType
|
|
375
376
|
});
|
|
376
|
-
if (!unions.length && !sanitize2?.length)
|
|
377
|
+
if (!unions.length && !sanitize2?.length) {
|
|
378
|
+
if (emit) return { source: f, externals: 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
|
+
const source = `return function mirror(v){${f}}`;
|
|
387
|
+
if (emit)
|
|
388
|
+
return {
|
|
389
|
+
source,
|
|
390
|
+
externals: {
|
|
391
|
+
unions,
|
|
392
|
+
hof
|
|
393
|
+
}
|
|
394
|
+
};
|
|
382
395
|
return Function(
|
|
383
396
|
"d",
|
|
384
|
-
|
|
385
|
-
)(
|
|
386
|
-
unions
|
|
387
|
-
|
|
388
|
-
|
|
397
|
+
source
|
|
398
|
+
)(
|
|
399
|
+
hof ? unions ? {
|
|
400
|
+
unions,
|
|
401
|
+
...hof
|
|
402
|
+
} : hof : unions ? { unions } : void 0
|
|
403
|
+
);
|
|
389
404
|
};
|
|
390
405
|
var index_default = createMirror;
|
|
391
406
|
// 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,12 @@ 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
|
|
76
|
+
export interface Manifest {
|
|
77
|
+
source: string;
|
|
78
|
+
externals: {
|
|
79
|
+
unions: Validator<any, TSchema, unknown, unknown>[][];
|
|
80
|
+
hof?: Record<string, Function>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
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
84
|
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,33 @@ var createMirror = (schema, {
|
|
|
346
347
|
recursionLimit,
|
|
347
348
|
removeUnknownUnionType
|
|
348
349
|
});
|
|
349
|
-
if (!unions.length && !sanitize2?.length)
|
|
350
|
+
if (!unions.length && !sanitize2?.length) {
|
|
351
|
+
if (emit) return { source: f, externals: 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
|
+
const source = `return function mirror(v){${f}}`;
|
|
360
|
+
if (emit)
|
|
361
|
+
return {
|
|
362
|
+
source,
|
|
363
|
+
externals: {
|
|
364
|
+
unions,
|
|
365
|
+
hof
|
|
366
|
+
}
|
|
367
|
+
};
|
|
355
368
|
return Function(
|
|
356
369
|
"d",
|
|
357
|
-
|
|
358
|
-
)(
|
|
359
|
-
unions
|
|
360
|
-
|
|
361
|
-
|
|
370
|
+
source
|
|
371
|
+
)(
|
|
372
|
+
hof ? unions ? {
|
|
373
|
+
unions,
|
|
374
|
+
...hof
|
|
375
|
+
} : hof : unions ? { unions } : void 0
|
|
376
|
+
);
|
|
362
377
|
};
|
|
363
378
|
var index_default = createMirror;
|
|
364
379
|
export {
|