is-kit 1.15.1 → 1.15.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/index.d.mts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +11 -4
- package/dist/index.mjs +11 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -64,6 +64,14 @@ type StructOptions = Readonly<{
|
|
|
64
64
|
* Object schema shape preserving concrete keys.
|
|
65
65
|
*/
|
|
66
66
|
type SchemaShape<S extends object> = Readonly<{ [K in keyof S]: SchemaField; }>;
|
|
67
|
+
/**
|
|
68
|
+
* Schema shape accepted by `struct`, limited to JavaScript string and numeric keys.
|
|
69
|
+
*
|
|
70
|
+
* Numeric keys are included because JavaScript normalizes them to string property
|
|
71
|
+
* keys during enumeration. Symbol keys are excluded because `struct` does not
|
|
72
|
+
* enumerate them at runtime.
|
|
73
|
+
*/
|
|
74
|
+
type StructSchemaShape<S extends SchemaShape<S>> = Extract<keyof S, symbol> extends never ? S : never;
|
|
67
75
|
type Simplify<T> = { [K in keyof T]: T[K]; };
|
|
68
76
|
type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
|
|
69
77
|
type RequiredSchemaKeys<S extends SchemaShape<S>> = { [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? never : K; }[keyof S];
|
|
@@ -809,16 +817,18 @@ export declare function setOf<VF extends Predicate<unknown>>(valueGuard: VF): Pr
|
|
|
809
817
|
*/
|
|
810
818
|
export declare function optionalKey<G extends Predicate<unknown>>(guard: G): OptionalSchemaField<G>;
|
|
811
819
|
/**
|
|
812
|
-
* Validates an object against a field-to-guard schema.
|
|
813
|
-
*
|
|
820
|
+
* Validates an object against a field-to-guard schema with string runtime keys.
|
|
821
|
+
* Numeric schema keys are normalized to strings by JavaScript; symbol-keyed fields
|
|
822
|
+
* are not supported. Keys are required unless wrapped with `optionalKey`; optionally
|
|
814
823
|
* rejects extra keys when `exact: true`.
|
|
815
824
|
*
|
|
816
|
-
* @param schema Record of property guards.
|
|
825
|
+
* @param schema Record of string- or numeric-keyed property guards.
|
|
817
826
|
* @param options When `{ exact: true }`, disallows own enumerable string-key
|
|
818
827
|
* properties not in `schema`.
|
|
819
828
|
* @returns Predicate that narrows to the inferred struct type.
|
|
829
|
+
* @throws {TypeError} If `schema` has own symbol-keyed fields.
|
|
820
830
|
*/
|
|
821
|
-
export declare function struct<const S extends SchemaShape<S>>(schema: S
|
|
831
|
+
export declare function struct<const S extends SchemaShape<S>>(schema: StructSchemaShape<S>, options?: StructOptions): Predicate<InferSchema<S>>;
|
|
822
832
|
//#endregion
|
|
823
833
|
//#region src/core/combinators/typed-struct.d.ts
|
|
824
834
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,14 @@ type StructOptions = Readonly<{
|
|
|
64
64
|
* Object schema shape preserving concrete keys.
|
|
65
65
|
*/
|
|
66
66
|
type SchemaShape<S extends object> = Readonly<{ [K in keyof S]: SchemaField; }>;
|
|
67
|
+
/**
|
|
68
|
+
* Schema shape accepted by `struct`, limited to JavaScript string and numeric keys.
|
|
69
|
+
*
|
|
70
|
+
* Numeric keys are included because JavaScript normalizes them to string property
|
|
71
|
+
* keys during enumeration. Symbol keys are excluded because `struct` does not
|
|
72
|
+
* enumerate them at runtime.
|
|
73
|
+
*/
|
|
74
|
+
type StructSchemaShape<S extends SchemaShape<S>> = Extract<keyof S, symbol> extends never ? S : never;
|
|
67
75
|
type Simplify<T> = { [K in keyof T]: T[K]; };
|
|
68
76
|
type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
|
|
69
77
|
type RequiredSchemaKeys<S extends SchemaShape<S>> = { [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? never : K; }[keyof S];
|
|
@@ -809,16 +817,18 @@ export declare function setOf<VF extends Predicate<unknown>>(valueGuard: VF): Pr
|
|
|
809
817
|
*/
|
|
810
818
|
export declare function optionalKey<G extends Predicate<unknown>>(guard: G): OptionalSchemaField<G>;
|
|
811
819
|
/**
|
|
812
|
-
* Validates an object against a field-to-guard schema.
|
|
813
|
-
*
|
|
820
|
+
* Validates an object against a field-to-guard schema with string runtime keys.
|
|
821
|
+
* Numeric schema keys are normalized to strings by JavaScript; symbol-keyed fields
|
|
822
|
+
* are not supported. Keys are required unless wrapped with `optionalKey`; optionally
|
|
814
823
|
* rejects extra keys when `exact: true`.
|
|
815
824
|
*
|
|
816
|
-
* @param schema Record of property guards.
|
|
825
|
+
* @param schema Record of string- or numeric-keyed property guards.
|
|
817
826
|
* @param options When `{ exact: true }`, disallows own enumerable string-key
|
|
818
827
|
* properties not in `schema`.
|
|
819
828
|
* @returns Predicate that narrows to the inferred struct type.
|
|
829
|
+
* @throws {TypeError} If `schema` has own symbol-keyed fields.
|
|
820
830
|
*/
|
|
821
|
-
export declare function struct<const S extends SchemaShape<S>>(schema: S
|
|
831
|
+
export declare function struct<const S extends SchemaShape<S>>(schema: StructSchemaShape<S>, options?: StructOptions): Predicate<InferSchema<S>>;
|
|
822
832
|
//#endregion
|
|
823
833
|
//#region src/core/combinators/typed-struct.d.ts
|
|
824
834
|
/**
|
package/dist/index.js
CHANGED
|
@@ -770,16 +770,23 @@ function optionalKey(guard) {
|
|
|
770
770
|
};
|
|
771
771
|
}
|
|
772
772
|
/**
|
|
773
|
-
* Validates an object against a field-to-guard schema.
|
|
774
|
-
*
|
|
773
|
+
* Validates an object against a field-to-guard schema with string runtime keys.
|
|
774
|
+
* Numeric schema keys are normalized to strings by JavaScript; symbol-keyed fields
|
|
775
|
+
* are not supported. Keys are required unless wrapped with `optionalKey`; optionally
|
|
775
776
|
* rejects extra keys when `exact: true`.
|
|
776
777
|
*
|
|
777
|
-
* @param schema Record of property guards.
|
|
778
|
+
* @param schema Record of string- or numeric-keyed property guards.
|
|
778
779
|
* @param options When `{ exact: true }`, disallows own enumerable string-key
|
|
779
780
|
* properties not in `schema`.
|
|
780
781
|
* @returns Predicate that narrows to the inferred struct type.
|
|
782
|
+
* @throws {TypeError} If `schema` has own symbol-keyed fields.
|
|
781
783
|
*/
|
|
782
784
|
function struct(schema, options) {
|
|
785
|
+
return createStruct(schema, options);
|
|
786
|
+
}
|
|
787
|
+
/** @internal Shared implementation for string-keyed schema builders. */
|
|
788
|
+
function createStruct(schema, options) {
|
|
789
|
+
if (Object.getOwnPropertySymbols(schema).length > 0) throw new TypeError("struct schema fields cannot use symbol keys");
|
|
783
790
|
const requiredEntries = [];
|
|
784
791
|
const optionalEntries = [];
|
|
785
792
|
const schemaKeys = [];
|
|
@@ -818,7 +825,7 @@ function struct(schema, options) {
|
|
|
818
825
|
* @returns Builder that rejects missing, extra, or incompatible struct fields.
|
|
819
826
|
*/
|
|
820
827
|
function typedStruct() {
|
|
821
|
-
return (fields, options) =>
|
|
828
|
+
return (fields, options) => createStruct(fields, options);
|
|
822
829
|
}
|
|
823
830
|
//#endregion
|
|
824
831
|
//#region src/core/combinators/tuple.ts
|
package/dist/index.mjs
CHANGED
|
@@ -769,16 +769,23 @@ function optionalKey(guard) {
|
|
|
769
769
|
};
|
|
770
770
|
}
|
|
771
771
|
/**
|
|
772
|
-
* Validates an object against a field-to-guard schema.
|
|
773
|
-
*
|
|
772
|
+
* Validates an object against a field-to-guard schema with string runtime keys.
|
|
773
|
+
* Numeric schema keys are normalized to strings by JavaScript; symbol-keyed fields
|
|
774
|
+
* are not supported. Keys are required unless wrapped with `optionalKey`; optionally
|
|
774
775
|
* rejects extra keys when `exact: true`.
|
|
775
776
|
*
|
|
776
|
-
* @param schema Record of property guards.
|
|
777
|
+
* @param schema Record of string- or numeric-keyed property guards.
|
|
777
778
|
* @param options When `{ exact: true }`, disallows own enumerable string-key
|
|
778
779
|
* properties not in `schema`.
|
|
779
780
|
* @returns Predicate that narrows to the inferred struct type.
|
|
781
|
+
* @throws {TypeError} If `schema` has own symbol-keyed fields.
|
|
780
782
|
*/
|
|
781
783
|
function struct(schema, options) {
|
|
784
|
+
return createStruct(schema, options);
|
|
785
|
+
}
|
|
786
|
+
/** @internal Shared implementation for string-keyed schema builders. */
|
|
787
|
+
function createStruct(schema, options) {
|
|
788
|
+
if (Object.getOwnPropertySymbols(schema).length > 0) throw new TypeError("struct schema fields cannot use symbol keys");
|
|
782
789
|
const requiredEntries = [];
|
|
783
790
|
const optionalEntries = [];
|
|
784
791
|
const schemaKeys = [];
|
|
@@ -817,7 +824,7 @@ function struct(schema, options) {
|
|
|
817
824
|
* @returns Builder that rejects missing, extra, or incompatible struct fields.
|
|
818
825
|
*/
|
|
819
826
|
function typedStruct() {
|
|
820
|
-
return (fields, options) =>
|
|
827
|
+
return (fields, options) => createStruct(fields, options);
|
|
821
828
|
}
|
|
822
829
|
//#endregion
|
|
823
830
|
//#region src/core/combinators/tuple.ts
|
package/package.json
CHANGED