@oscarpalmer/jhunal 0.23.0 → 0.25.0

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 (40) hide show
  1. package/dist/constants.d.mts +8 -5
  2. package/dist/constants.mjs +20 -23
  3. package/dist/helpers/message.helper.d.mts +11 -5
  4. package/dist/helpers/message.helper.mjs +31 -9
  5. package/dist/helpers/misc.helper.d.mts +4 -4
  6. package/dist/helpers/misc.helper.mjs +4 -4
  7. package/dist/index.d.mts +66 -78
  8. package/dist/index.mjs +100 -62
  9. package/dist/models/infer.model.d.mts +21 -21
  10. package/dist/models/misc.model.d.mts +3 -3
  11. package/dist/models/{schema.plain.model.d.mts → schematic.plain.model.d.mts} +20 -18
  12. package/dist/models/{schema.typed.model.d.mts → schematic.typed.model.d.mts} +10 -24
  13. package/dist/models/transform.model.d.mts +6 -6
  14. package/dist/models/validation.model.d.mts +13 -3
  15. package/dist/{schematic.d.mts → schema.d.mts} +18 -18
  16. package/dist/{schematic.mjs → schema.mjs} +12 -12
  17. package/dist/validator/named.handler.d.mts +1 -1
  18. package/dist/validator/named.handler.mjs +3 -2
  19. package/dist/validator/named.validator.mjs +2 -3
  20. package/dist/validator/object.validator.mjs +40 -22
  21. package/dist/validator/schematic.validator.d.mts +3 -3
  22. package/dist/validator/schematic.validator.mjs +4 -4
  23. package/package.json +1 -1
  24. package/src/constants.ts +24 -28
  25. package/src/helpers/message.helper.ts +74 -9
  26. package/src/helpers/misc.helper.ts +9 -10
  27. package/src/index.ts +4 -4
  28. package/src/models/infer.model.ts +26 -28
  29. package/src/models/misc.model.ts +3 -3
  30. package/src/models/{schema.plain.model.ts → schematic.plain.model.ts} +22 -20
  31. package/src/models/{schema.typed.model.ts → schematic.typed.model.ts} +10 -28
  32. package/src/models/transform.model.ts +6 -6
  33. package/src/models/validation.model.ts +14 -2
  34. package/src/{schematic.ts → schema.ts} +23 -23
  35. package/src/validator/named.handler.ts +16 -1
  36. package/src/validator/named.validator.ts +3 -4
  37. package/src/validator/object.validator.ts +81 -55
  38. package/src/validator/schematic.validator.ts +3 -3
  39. /package/dist/models/{schema.plain.model.mjs → schematic.plain.model.mjs} +0 -0
  40. /package/dist/models/{schema.typed.model.mjs → schematic.typed.model.mjs} +0 -0
@@ -8,12 +8,13 @@ declare const CONJUNCTION_OR_COMMA = ", or ";
8
8
  declare const CONJUNCTION_AND = " and ";
9
9
  declare const CONJUNCTION_AND_COMMA = ", and ";
10
10
  declare const MESSAGE_CONSTRUCTOR = "Expected a constructor function";
11
- declare const NAME_SCHEMATIC = "Schematic";
12
- declare const NAME_SCHEMATIC_PREFIXED = "a Schematic";
11
+ declare const NAME_SCHEMA = "Schema";
12
+ declare const NAME_SCHEMA_PREFIXED = "a Schema";
13
13
  declare const NAME_ERROR_SCHEMATIC = "SchematicError";
14
14
  declare const NAME_ERROR_VALIDATION = "ValidationError";
15
+ declare const PROPERTY_DEFAULT = "$default";
15
16
  declare const PROPERTY_REQUIRED = "$required";
16
- declare const PROPERTY_SCHEMATIC = "$schematic";
17
+ declare const PROPERTY_SCHEMA = "$schema";
17
18
  declare const PROPERTY_TYPE = "$type";
18
19
  declare const PROPERTY_VALIDATORS = "$validators";
19
20
  declare const VALIDATION_MESSAGE_INVALID_INPUT = "Expected an object as input but received <>";
@@ -27,8 +28,10 @@ declare const REPORTING_FIRST: ReportingType;
27
28
  declare const REPORTING_NONE: ReportingType;
28
29
  declare const REPORTING_THROW: ReportingType;
29
30
  declare const REPORTING_TYPES: Set<ReportingType>;
31
+ declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED = "'<>' has a default value but is not required";
32
+ declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE = "Expected default value for property '<>' to be <>";
30
33
  declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY = "Schema must have at least one property";
31
- declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED = "'<>.<>' property is not allowed for schemas in $type";
34
+ declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED = "'<>.<>' property is not allowed for plain schemas";
32
35
  declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE = "'<>' property must not be 'null' or 'undefined'";
33
36
  declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED = "'<>.$required' property must be a boolean";
34
37
  declare const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE = "'<>' property must be of a valid type";
@@ -47,4 +50,4 @@ declare const VALIDATABLE_TYPES: Set<keyof Values>;
47
50
  declare const TYPE_ALL: Set<keyof Values>;
48
51
  declare const PREFIXED_TYPES: Record<ValueName, string>;
49
52
  //#endregion
50
- export { COMMA, CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, MESSAGE_CONSTRUCTOR, NAME_ERROR_SCHEMATIC, NAME_ERROR_VALIDATION, NAME_SCHEMATIC, NAME_SCHEMATIC_PREFIXED, PREFIXED_TYPES, PROPERTY_REQUIRED, PROPERTY_SCHEMATIC, PROPERTY_TYPE, PROPERTY_VALIDATORS, REPORTING_ALL, REPORTING_FIRST, REPORTING_NONE, REPORTING_THROW, REPORTING_TYPES, SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_KEY, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_VALUE, TEMPLATE_PATTERN, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS };
53
+ export { COMMA, CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, MESSAGE_CONSTRUCTOR, NAME_ERROR_SCHEMATIC, NAME_ERROR_VALIDATION, NAME_SCHEMA, NAME_SCHEMA_PREFIXED, PREFIXED_TYPES, PROPERTY_DEFAULT, PROPERTY_REQUIRED, PROPERTY_SCHEMA, PROPERTY_TYPE, PROPERTY_VALIDATORS, REPORTING_ALL, REPORTING_FIRST, REPORTING_NONE, REPORTING_THROW, REPORTING_TYPES, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_KEY, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_VALUE, TEMPLATE_PATTERN, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS };
@@ -5,12 +5,13 @@ const CONJUNCTION_OR_COMMA = ", or ";
5
5
  const CONJUNCTION_AND = " and ";
6
6
  const CONJUNCTION_AND_COMMA = ", and ";
7
7
  const MESSAGE_CONSTRUCTOR = "Expected a constructor function";
8
- const NAME_SCHEMATIC = "Schematic";
9
- const NAME_SCHEMATIC_PREFIXED = "a Schematic";
8
+ const NAME_SCHEMA = "Schema";
9
+ const NAME_SCHEMA_PREFIXED = "a Schema";
10
10
  const NAME_ERROR_SCHEMATIC = "SchematicError";
11
11
  const NAME_ERROR_VALIDATION = "ValidationError";
12
+ const PROPERTY_DEFAULT = "$default";
12
13
  const PROPERTY_REQUIRED = "$required";
13
- const PROPERTY_SCHEMATIC = "$schematic";
14
+ const PROPERTY_SCHEMA = "$schema";
14
15
  const PROPERTY_TYPE = "$type";
15
16
  const PROPERTY_VALIDATORS = "$validators";
16
17
  const VALIDATION_MESSAGE_INVALID_INPUT = "Expected an object as input but received <>";
@@ -29,8 +30,10 @@ const REPORTING_TYPES = new Set([
29
30
  REPORTING_NONE,
30
31
  REPORTING_THROW
31
32
  ]);
33
+ const SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED = "'<>' has a default value but is not required";
34
+ const SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE = "Expected default value for property '<>' to be <>";
32
35
  const SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY = "Schema must have at least one property";
33
- const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED = "'<>.<>' property is not allowed for schemas in $type";
36
+ const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED = "'<>.<>' property is not allowed for plain schemas";
34
37
  const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE = "'<>' property must not be 'null' or 'undefined'";
35
38
  const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED = "'<>.$required' property must be a boolean";
36
39
  const SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE = "'<>' property must be of a valid type";
@@ -40,27 +43,21 @@ const SCHEMATIC_MESSAGE_VALIDATOR_INVALID_TYPE = "Validators must be an object";
40
43
  const SCHEMATIC_MESSAGE_VALIDATOR_INVALID_VALUE = "Validator '<>' must be a function or an array of functions";
41
44
  const TEMPLATE_PATTERN = "<>";
42
45
  const TYPE_ARRAY = "array";
43
- const TYPE_BIGINT = "bigint";
44
- const TYPE_BOOLEAN = "boolean";
45
- const TYPE_DATE = "date";
46
46
  const TYPE_FUNCTION = "function";
47
47
  const TYPE_FUNCTION_RESULT = "a validated value";
48
48
  const TYPE_NULL = "null";
49
- const TYPE_NUMBER = "number";
50
49
  const TYPE_OBJECT = "object";
51
- const TYPE_STRING = "string";
52
- const TYPE_SYMBOL = "symbol";
53
50
  const TYPE_UNDEFINED = "undefined";
54
51
  const VALIDATABLE_TYPES = new Set([
55
52
  TYPE_ARRAY,
56
- TYPE_BIGINT,
57
- TYPE_BOOLEAN,
58
- TYPE_DATE,
53
+ "bigint",
54
+ "boolean",
55
+ "date",
59
56
  TYPE_FUNCTION,
60
- TYPE_NUMBER,
57
+ "number",
61
58
  TYPE_OBJECT,
62
- TYPE_STRING,
63
- TYPE_SYMBOL
59
+ "string",
60
+ "symbol"
64
61
  ]);
65
62
  const TYPE_ALL = new Set([
66
63
  ...VALIDATABLE_TYPES,
@@ -69,16 +66,16 @@ const TYPE_ALL = new Set([
69
66
  ]);
70
67
  const PREFIXED_TYPES = {
71
68
  [TYPE_ARRAY]: `an ${TYPE_ARRAY}`,
72
- [TYPE_BIGINT]: `a ${TYPE_BIGINT}`,
73
- [TYPE_BOOLEAN]: `a ${TYPE_BOOLEAN}`,
74
- [TYPE_DATE]: `a ${TYPE_DATE}`,
69
+ bigint: `a bigint`,
70
+ boolean: `a boolean`,
71
+ date: `a date`,
75
72
  [TYPE_FUNCTION]: `a ${TYPE_FUNCTION}`,
76
73
  [TYPE_NULL]: TYPE_NULL,
77
- [TYPE_NUMBER]: `a ${TYPE_NUMBER}`,
78
- [TYPE_STRING]: `a ${TYPE_STRING}`,
79
- [TYPE_SYMBOL]: `a ${TYPE_SYMBOL}`,
74
+ number: `a number`,
75
+ string: `a string`,
76
+ symbol: `a symbol`,
80
77
  [TYPE_OBJECT]: `an ${TYPE_OBJECT}`,
81
78
  [TYPE_UNDEFINED]: TYPE_UNDEFINED
82
79
  };
83
80
  //#endregion
84
- export { COMMA, CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, MESSAGE_CONSTRUCTOR, NAME_ERROR_SCHEMATIC, NAME_ERROR_VALIDATION, NAME_SCHEMATIC, NAME_SCHEMATIC_PREFIXED, PREFIXED_TYPES, PROPERTY_REQUIRED, PROPERTY_SCHEMATIC, PROPERTY_TYPE, PROPERTY_VALIDATORS, REPORTING_ALL, REPORTING_FIRST, REPORTING_NONE, REPORTING_THROW, REPORTING_TYPES, SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_KEY, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_VALUE, TEMPLATE_PATTERN, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS };
81
+ export { COMMA, CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, MESSAGE_CONSTRUCTOR, NAME_ERROR_SCHEMATIC, NAME_ERROR_VALIDATION, NAME_SCHEMA, NAME_SCHEMA_PREFIXED, PREFIXED_TYPES, PROPERTY_DEFAULT, PROPERTY_REQUIRED, PROPERTY_SCHEMA, PROPERTY_TYPE, PROPERTY_VALIDATORS, REPORTING_ALL, REPORTING_FIRST, REPORTING_NONE, REPORTING_THROW, REPORTING_TYPES, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_EMPTY, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_KEY, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_TYPE, SCHEMATIC_MESSAGE_VALIDATOR_INVALID_VALUE, TEMPLATE_PATTERN, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS };
@@ -2,10 +2,16 @@ import { ValidatorType } from "../models/validation.model.mjs";
2
2
  import { ValueName } from "../models/misc.model.mjs";
3
3
 
4
4
  //#region src/helpers/message.helper.d.ts
5
- declare function getInvalidInputMessage(actual: unknown): string;
6
- declare function getInvalidMissingMessage(key: string, types: ValidatorType[]): string;
7
- declare function getInvalidTypeMessage(key: string, types: ValidatorType[], actual: unknown): string;
8
- declare function getInvalidValidatorMessage(key: string, type: ValueName, index: number, length: number): string;
5
+ declare function getDefaultRequiredMessage(key: string): string;
6
+ declare function getDefaultTypeMessage(key: string, types: ValidatorType[]): string;
7
+ declare function getDisallowedMessage(key: string, property: string): string;
8
+ declare function getInputTypeMessage(actual: unknown): string;
9
+ declare function getInputPropertyMissingMessage(key: string, types: ValidatorType[]): string;
10
+ declare function getInputPropertyTypeMessage(key: string, types: ValidatorType[], actual: unknown): string;
11
+ declare function getInputPropertyValidatorMessage(key: string, type: ValueName, index: number, length: number): string;
12
+ declare function getSchematicPropertyNullableMessage(key: string): string;
13
+ declare function getSchematicPropertyTypeMessage(key: string): string;
14
+ declare function getRequiredMessage(key: string): string;
9
15
  declare function getUnknownKeysMessage(keys: string[]): string;
10
16
  //#endregion
11
- export { getInvalidInputMessage, getInvalidMissingMessage, getInvalidTypeMessage, getInvalidValidatorMessage, getUnknownKeysMessage };
17
+ export { getDefaultRequiredMessage, getDefaultTypeMessage, getDisallowedMessage, getInputPropertyMissingMessage, getInputPropertyTypeMessage, getInputPropertyValidatorMessage, getInputTypeMessage, getRequiredMessage, getSchematicPropertyNullableMessage, getSchematicPropertyTypeMessage, getUnknownKeysMessage };
@@ -1,26 +1,45 @@
1
- import { CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, PREFIXED_TYPES, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS } from "../constants.mjs";
1
+ import { CONJUNCTION_AND, CONJUNCTION_AND_COMMA, CONJUNCTION_OR, CONJUNCTION_OR_COMMA, PREFIXED_TYPES, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, TYPE_ALL, TYPE_ARRAY, TYPE_FUNCTION_RESULT, TYPE_NULL, TYPE_OBJECT, VALIDATION_MESSAGE_INVALID_INPUT, VALIDATION_MESSAGE_INVALID_REQUIRED, VALIDATION_MESSAGE_INVALID_TYPE, VALIDATION_MESSAGE_INVALID_VALUE, VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX, VALIDATION_MESSAGE_UNKNOWN_KEYS } from "../constants.mjs";
2
2
  import { isConstructor, isPlainObject } from "@oscarpalmer/atoms/is";
3
3
  //#region src/helpers/message.helper.ts
4
- function getInvalidInputMessage(actual) {
4
+ function getDefaultRequiredMessage(key) {
5
+ return SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_REQUIRED.replace("<>", key);
6
+ }
7
+ function getDefaultTypeMessage(key, types) {
8
+ let message = SCHEMATIC_MESSAGE_SCHEMA_INVALID_DEFAULT_TYPE.replace("<>", key);
9
+ message = message.replace("<>", renderTypes(types));
10
+ return message;
11
+ }
12
+ function getDisallowedMessage(key, property) {
13
+ let message = SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED.replace("<>", key);
14
+ message = message.replace("<>", property);
15
+ return message;
16
+ }
17
+ function getInputTypeMessage(actual) {
5
18
  return VALIDATION_MESSAGE_INVALID_INPUT.replace("<>", getValueType(actual));
6
19
  }
7
- function getInvalidMissingMessage(key, types) {
20
+ function getInputPropertyMissingMessage(key, types) {
8
21
  let message = VALIDATION_MESSAGE_INVALID_REQUIRED.replace("<>", renderTypes(types));
9
22
  message = message.replace("<>", key);
10
23
  return message;
11
24
  }
12
- function getInvalidTypeMessage(key, types, actual) {
25
+ function getInputPropertyTypeMessage(key, types, actual) {
13
26
  let message = VALIDATION_MESSAGE_INVALID_TYPE.replace("<>", renderTypes(types));
14
27
  message = message.replace("<>", key);
15
28
  message = message.replace("<>", getValueType(actual));
16
29
  return message;
17
30
  }
18
- function getInvalidValidatorMessage(key, type, index, length) {
31
+ function getInputPropertyValidatorMessage(key, type, index, length) {
19
32
  let message = VALIDATION_MESSAGE_INVALID_VALUE.replace("<>", key);
20
33
  message = message.replace("<>", type);
21
34
  if (length > 1) message += VALIDATION_MESSAGE_INVALID_VALUE_SUFFIX.replace("<>", String(index));
22
35
  return message;
23
36
  }
37
+ function getSchematicPropertyNullableMessage(key) {
38
+ return SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_NULLABLE.replace("<>", key);
39
+ }
40
+ function getSchematicPropertyTypeMessage(key) {
41
+ return SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE.replace("<>", key);
42
+ }
24
43
  function getPropertyType(type) {
25
44
  switch (true) {
26
45
  case typeof type === "function": return isConstructor(type) ? type.name : TYPE_FUNCTION_RESULT;
@@ -28,9 +47,6 @@ function getPropertyType(type) {
28
47
  default: return PREFIXED_TYPES[TYPE_OBJECT];
29
48
  }
30
49
  }
31
- function getUnknownKeysMessage(keys) {
32
- return VALIDATION_MESSAGE_UNKNOWN_KEYS.replace("<>", renderKeys(keys));
33
- }
34
50
  function getValueType(value) {
35
51
  const valueType = typeof value;
36
52
  switch (true) {
@@ -66,5 +82,11 @@ function renderTypes(types) {
66
82
  }
67
83
  return renderParts(parts, CONJUNCTION_OR, CONJUNCTION_OR_COMMA);
68
84
  }
85
+ function getRequiredMessage(key) {
86
+ return SCHEMATIC_MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED.replace("<>", key);
87
+ }
88
+ function getUnknownKeysMessage(keys) {
89
+ return VALIDATION_MESSAGE_UNKNOWN_KEYS.replace("<>", renderKeys(keys));
90
+ }
69
91
  //#endregion
70
- export { getInvalidInputMessage, getInvalidMissingMessage, getInvalidTypeMessage, getInvalidValidatorMessage, getUnknownKeysMessage };
92
+ export { getDefaultRequiredMessage, getDefaultTypeMessage, getDisallowedMessage, getInputPropertyMissingMessage, getInputPropertyTypeMessage, getInputPropertyValidatorMessage, getInputTypeMessage, getRequiredMessage, getSchematicPropertyNullableMessage, getSchematicPropertyTypeMessage, getUnknownKeysMessage };
@@ -1,10 +1,10 @@
1
1
  import { ReportingInformation, ValidatorParameters } from "../models/validation.model.mjs";
2
- import { Schematic } from "../schematic.mjs";
2
+ import { Schema } from "../schema.mjs";
3
3
  import { Constructor } from "@oscarpalmer/atoms/models";
4
4
 
5
5
  //#region src/helpers/misc.helper.d.ts
6
6
  declare function getParameters(input?: unknown): ValidatorParameters;
7
- declare function getReporting(value: unknown): ReportingInformation;
7
+ declare function getReporting(value?: unknown): ReportingInformation;
8
8
  /**
9
9
  * Creates a validator function for a given constructor
10
10
  * @param constructor - Constructor to check against
@@ -17,6 +17,6 @@ declare function instanceOf<Instance>(constructor: Constructor<Instance>): (valu
17
17
  * @param value Value to check
18
18
  * @returns `true` if the value is a schematic, `false` otherwise
19
19
  */
20
- declare function isSchematic(value: unknown): value is Schematic<never>;
20
+ declare function isSchema(value: unknown): value is Schema<never>;
21
21
  //#endregion
22
- export { getParameters, getReporting, instanceOf, isSchematic };
22
+ export { getParameters, getReporting, instanceOf, isSchema };
@@ -5,7 +5,7 @@ function getParameters(input) {
5
5
  if (typeof input === "boolean") return {
6
6
  clone: true,
7
7
  output: {},
8
- reporting: getReporting(REPORTING_NONE),
8
+ reporting: getReporting(),
9
9
  strict: input
10
10
  };
11
11
  if (REPORTING_TYPES.has(input)) return {
@@ -49,8 +49,8 @@ function instanceOf(constructor) {
49
49
  * @param value Value to check
50
50
  * @returns `true` if the value is a schematic, `false` otherwise
51
51
  */
52
- function isSchematic(value) {
53
- return typeof value === "object" && value !== null && "$schematic" in value && value["$schematic"] === true;
52
+ function isSchema(value) {
53
+ return typeof value === "object" && value !== null && "$schema" in value && value["$schema"] === true;
54
54
  }
55
55
  //#endregion
56
- export { getParameters, getReporting, instanceOf, isSchematic };
56
+ export { getParameters, getReporting, instanceOf, isSchema };
package/dist/index.d.mts CHANGED
@@ -1,42 +1,43 @@
1
1
  import { Constructor, GenericCallback, PlainObject, Simplify } from "@oscarpalmer/atoms/models";
2
2
  import { Result } from "@oscarpalmer/atoms/result/models";
3
3
 
4
- //#region src/models/schema.plain.model.d.ts
4
+ //#region src/models/schematic.plain.model.d.ts
5
5
  /**
6
- * A generic schema allowing nested schemas, {@link SchemaEntry} values, or arrays of {@link SchemaEntry} as values
6
+ * A generic schematic allowing nested schematics, {@link SchematicEntry} values, or arrays of {@link SchematicEntry} as values
7
7
  */
8
- type PlainSchema = {
9
- [key: string]: PlainSchema | SchemaEntry | SchemaEntry[] | undefined;
8
+ type PlainSchematic = {
9
+ [key: string]: PlainSchematic | SchematicEntry | SchematicEntry[] | undefined;
10
10
  } & {
11
+ $default?: never;
11
12
  $required?: never;
12
13
  $type?: never;
13
14
  $validators?: never;
14
15
  };
15
16
  /**
16
- * A schema for validating objects
17
+ * A schematic for validating objects
17
18
  *
18
19
  * @example
19
20
  * ```ts
20
- * const schema: Schema = {
21
+ * const schematic = {
21
22
  * name: 'string',
22
23
  * age: 'number',
23
24
  * tags: ['string', 'number'],
24
- * };
25
+ * } satisfies Schematic;
25
26
  * ```
26
27
  */
27
- type Schema = PlainSchema;
28
+ type Schematic = PlainSchematic;
28
29
  /**
29
- * A union of all valid types for a single schema entry
30
+ * A union of all valid types for a single schematic entry
30
31
  *
31
- * Can be a {@link Constructor}, {@link PlainSchema}, {@link SchemaProperty}, {@link Schematic}, {@link ValueName} string, or a custom validator function
32
+ * Can be a {@link Constructor}, {@link PlainSchematic}, {@link SchematicProperty}, {@link Schema}, {@link ValueName}, or a custom validator function
32
33
  */
33
- type SchemaEntry = Constructor | PlainSchema | SchemaProperty | Schematic<unknown> | ValueName | ((value: unknown) => boolean);
34
+ type SchematicEntry = Constructor | PlainSchematic | Schema<unknown> | SchematicProperty | ValueName | ((value: unknown) => boolean);
34
35
  /**
35
36
  * A property definition with explicit type(s), an optional requirement flag, and optional validators
36
37
  *
37
38
  * @example
38
39
  * ```ts
39
- * const prop: SchemaProperty = {
40
+ * const prop: SchematicProperty = {
40
41
  * $required: false,
41
42
  * $type: ['string', 'number'],
42
43
  * $validators: {
@@ -46,7 +47,8 @@ type SchemaEntry = Constructor | PlainSchema | SchemaProperty | Schematic<unknow
46
47
  * };
47
48
  * ```
48
49
  */
49
- type SchemaProperty = {
50
+ type SchematicProperty = {
51
+ $default?: unknown;
50
52
  /**
51
53
  * Whether the property is required _(defaults to `true`)_
52
54
  */
@@ -61,11 +63,11 @@ type SchemaProperty = {
61
63
  $validators?: PropertyValidators<SchemaPropertyType | SchemaPropertyType[]>;
62
64
  };
63
65
  /**
64
- * A union of valid types for a {@link SchemaProperty}'s `$type` field
66
+ * A union of valid types for a {@link SchematicProperty}'s `$type` field
65
67
  *
66
- * Can be a {@link Constructor}, {@link PlainSchema}, {@link Schematic}, {@link ValueName} string, or a custom validator function
68
+ * Can be a {@link Constructor}, {@link PlainSchematic}, {@link Schema}, {@link ValueName} string, or a custom validator function
67
69
  */
68
- type SchemaPropertyType = Constructor | PlainSchema | Schematic<unknown> | ValueName | ((value: unknown) => boolean);
70
+ type SchemaPropertyType = Constructor | PlainSchematic | Schema<unknown> | ValueName | ((value: unknown) => boolean);
69
71
  /**
70
72
  * A map of optional validator functions keyed by {@link ValueName}, used to add custom validation to {@link SchemaProperty} definitions
71
73
  *
@@ -111,11 +113,11 @@ type ExtractValueNames<Value> = Value extends ValueName ? Value : Value extends
111
113
  /**
112
114
  * Determines whether a schema entry is optional
113
115
  *
114
- * Returns `true` if the entry is a {@link SchemaProperty} with `$required` set to `false`; otherwise returns `false`
116
+ * Returns `true` if the entry is a {@link SchematicProperty} with `$required` set to `false`; otherwise returns `false`
115
117
  *
116
118
  * @template Value Schema entry to check
117
119
  */
118
- type IsOptionalProperty<Value> = Value extends SchemaProperty ? Value['$required'] extends false ? true : false : false;
120
+ type IsOptionalProperty<Value> = Value extends SchematicProperty ? Value['$required'] extends false ? true : false : false;
119
121
  /**
120
122
  * Extracts the last member from a union type by leveraging contravariance of function parameter types
121
123
  *
@@ -225,31 +227,31 @@ type Values = {
225
227
  //#endregion
226
228
  //#region src/models/infer.model.d.ts
227
229
  /**
228
- * Infers the TypeScript type from a {@link Schema} definition
230
+ * Infers the TypeScript type from a {@link Schematic} definition
229
231
  *
230
- * @template Model Schema to infer types from
232
+ * @template Model Schematic to infer types from
231
233
  *
232
234
  * @example
233
235
  * ```ts
234
- * const userSchema = {
236
+ * const userSchematic = {
235
237
  * name: 'string',
236
238
  * age: 'number',
237
239
  * address: { $required: false, $type: 'string' },
238
- * } satisfies Schema;
240
+ * } satisfies Schematic;
239
241
  *
240
- * type User = Infer<typeof userSchema>;
242
+ * type User = Infer<typeof userSchematic>;
241
243
  * // { name: string; age: number; address?: string }
242
244
  * ```
243
245
  */
244
- type Infer<Model extends Schema> = Simplify<{ [Key in InferRequiredKeys<Model>]: InferSchemaEntry<Model[Key]> } & { [Key in InferOptionalKeys<Model>]?: InferSchemaEntry<Model[Key]> }>;
246
+ type Infer<Model extends Schematic> = Simplify<{ [Key in InferRequiredKeys<Model>]: InferSchemaEntry<Model[Key]> } & { [Key in InferOptionalKeys<Model>]?: InferSchemaEntry<Model[Key]> }>;
245
247
  /**
246
- * Extracts keys from a {@link Schema} whose entries are optional _(i.e., `$required` is `false`)_
248
+ * Extracts keys from a {@link Schematic} whose entries are optional _(i.e., `$required` is `false`)_
247
249
  *
248
- * @template Model - {@link Schema} to extract optional keys from
250
+ * @template Model - {@link Schematic} to extract optional keys from
249
251
  */
250
- type InferOptionalKeys<Model extends Schema> = keyof { [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? Key : never]: never };
252
+ type InferOptionalKeys<Model extends Schematic> = keyof { [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? Key : never]: never };
251
253
  /**
252
- * Infers the TypeScript type from a {@link SchemaProperty}'s `$type` field
254
+ * Infers the TypeScript type from a {@link SchematicProperty}'s `$type` field
253
255
  *
254
256
  * @template Value `$type` value _(single or array)_
255
257
  */
@@ -257,31 +259,31 @@ type InferPropertyType<Value> = Value extends (infer Item)[] ? InferPropertyValu
257
259
  /**
258
260
  * Maps a single `$type` definition to its TypeScript equivalent
259
261
  *
260
- * Resolves, in order: {@link Constructor} instances, {@link Schematic} models, {@link ValueName} strings, and nested {@link PlainSchema} objects
262
+ * Resolves, in order: {@link Constructor}s, {@link Schema} instances, {@link ValueName} values, and nested {@link PlainSchematic} objects
261
263
  *
262
264
  * @template Value single type definition
263
265
  */
264
- type InferPropertyValue<Value> = Value extends Constructor<infer Instance> ? Instance : Value extends Schematic<infer Model> ? Model : Value extends ValueName ? Values[Value & ValueName] : Value extends Schema ? Infer<Value> : never;
266
+ type InferPropertyValue<Value> = Value extends Constructor<infer Instance> ? Instance : Value extends Schema<infer Model> ? Model : Value extends ValueName ? Values[Value & ValueName] : Value extends PlainSchematic ? Infer<Value> : never;
265
267
  /**
266
- * Extracts keys from a {@link Schema} whose entries are required _(i.e., `$required` is not `false`)_
268
+ * Extracts keys from a {@link Schematic} whose entries are required _(i.e., `$required` is not `false`)_
267
269
  *
268
- * @template Model Schema to extract required keys from
270
+ * @template Model Schematic to extract required keys from
269
271
  */
270
- type InferRequiredKeys<Model extends Schema> = keyof { [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? never : Key]: never };
272
+ type InferRequiredKeys<Model extends Schematic> = keyof { [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? never : Key]: never };
271
273
  /**
272
- * Infers the TypeScript type from a top-level {@link Schema} entry
274
+ * Infers the TypeScript type from a top-level {@link Schematic} entry
273
275
  *
274
- * @template Value Schema entry value _(single or array)_
276
+ * @template Value Schematic entry value _(single or array)_
275
277
  */
276
278
  type InferSchemaEntry<Value> = Value extends (infer Item)[] ? InferSchemaEntryValue<Item> : InferSchemaEntryValue<Value>;
277
279
  /**
278
280
  * Maps a single top-level schema entry to its TypeScript type
279
281
  *
280
- * Resolves, in order: {@link Constructor} instances, {@link Schematic} models, {@link SchemaProperty} objects, {@link PlainSchema} objects, and {@link ValueName} strings
282
+ * Resolves, in order: {@link Constructor}s, {@link Schema} instances, {@link SchemaProperty} objects, {@link PlainSchematic} objects, and {@link ValueName} values
281
283
  *
282
284
  * @template Value single schema entry
283
285
  */
284
- type InferSchemaEntryValue<Value> = Value extends Constructor<infer Instance> ? Instance : Value extends Schematic<infer Model> ? Model : Value extends SchemaProperty ? InferPropertyType<Value['$type']> : Value extends PlainSchema ? Infer<Value & Schema> : Value extends ValueName ? Values[Value & ValueName] : Value extends Schema ? Infer<Value> : never;
286
+ type InferSchemaEntryValue<Value> = Value extends Constructor<infer Instance> ? Instance : Value extends Schema<infer Model> ? Model : Value extends SchematicProperty ? InferPropertyType<Value['$type']> : Value extends PlainSchematic ? Infer<Value & Schematic> : Value extends ValueName ? Values[Value & ValueName] : never;
285
287
  //#endregion
286
288
  //#region src/models/transform.model.d.ts
287
289
  /**
@@ -305,11 +307,11 @@ type ToSchemaPropertyType<Value> = UnwrapSingle<DeduplicateTuple<MapToSchemaProp
305
307
  /**
306
308
  * Converts a single type to its schema property equivalent
307
309
  *
308
- * Plain objects become {@link TypedSchema}; primitives go through {@link ToValueType}
310
+ * Plain objects become {@link TypedSchematic}; primitives go through {@link ToValueType}
309
311
  *
310
312
  * @template Value Type to convert
311
313
  */
312
- type ToSchemaPropertyTypeEach<Value> = Value extends PlainObject ? TypedSchema<Value> : ToValueType<Value>;
314
+ type ToSchemaPropertyTypeEach<Value> = Value extends PlainObject ? TypedSchematic<Value> : ToValueType<Value>;
313
315
  /**
314
316
  * Converts a TypeScript type to its {@link ValueName} representation, suitable for use as a top-level schema entry
315
317
  *
@@ -319,7 +321,7 @@ type ToSchemaType<Value> = UnwrapSingle<DeduplicateTuple<MapToValueTypes<UnionTo
319
321
  /**
320
322
  * Maps a type to its {@link ValueName} string equivalent
321
323
  *
322
- * Resolves {@link Schematic} types as-is, then performs a reverse-lookup against {@link Values} _(excluding `'object'`)_ to find a matching key. If no match is found, `object` types resolve to `'object'` or a type-guard function, and all other unrecognised types resolve to a type-guard function
324
+ * Resolves {@link Schema} types as-is, then performs a reverse-lookup against {@link Values} _(excluding `'object'`)_ to find a matching key. If no match is found, `object` types resolve to `'object'` or a type-guard function, and all other unrecognised types resolve to a type-guard function
323
325
  *
324
326
  * @template Value Type to map
325
327
  *
@@ -330,11 +332,11 @@ type ToSchemaType<Value> = UnwrapSingle<DeduplicateTuple<MapToValueTypes<UnionTo
330
332
  * // ToValueType<Date> => 'date'
331
333
  * ```
332
334
  */
333
- type ToValueType<Value> = Value extends Schematic<any> ? Value : { [Key in keyof Omit<Values, 'object'>]: Value extends Values[Key] ? Key : never }[keyof Omit<Values, 'object'>] extends infer Match ? [Match] extends [never] ? Value extends object ? 'object' | ((value: unknown) => value is Value) : (value: unknown) => value is Value : Match : never;
335
+ type ToValueType<Value> = Value extends Schema<any> ? Value : { [Key in keyof Omit<Values, 'object'>]: Value extends Values[Key] ? Key : never }[keyof Omit<Values, 'object'>] extends infer Match ? [Match] extends [never] ? Value extends object ? 'object' | ((value: unknown) => value is Value) : (value: unknown) => value is Value : Match : never;
334
336
  //#endregion
335
- //#region src/models/schema.typed.model.d.ts
337
+ //#region src/models/schematic.typed.model.d.ts
336
338
  /**
337
- * A typed optional property definition generated by {@link TypedSchema} for optional keys, with `$required` set to `false` and excludes `undefined` from the type
339
+ * A typed optional property definition generated by {@link TypedSchematic} for optional keys, with `$required` set to `false` and excludes `undefined` from the type
338
340
  *
339
341
  * @template Value Property's type _(including `undefined`)_
340
342
  *
@@ -346,12 +348,13 @@ type ToValueType<Value> = Value extends Schematic<any> ? Value : { [Key in keyof
346
348
  * ```
347
349
  */
348
350
  type TypedPropertyOptional<Value> = {
351
+ $default?: never;
349
352
  $required: false;
350
353
  $type: ToSchemaPropertyType<Exclude<Value, undefined>>;
351
354
  $validators?: PropertyValidators<ToSchemaPropertyType<Exclude<Value, undefined>>>;
352
355
  };
353
356
  /**
354
- * A typed required property definition generated by {@link TypedSchema} for required keys, with `$required` defaulting to `true`
357
+ * A typed required property definition generated by {@link TypedSchematic} for required keys, with `$required` defaulting to `true`
355
358
  *
356
359
  * @template Value Property's type
357
360
  *
@@ -363,6 +366,7 @@ type TypedPropertyOptional<Value> = {
363
366
  * ```
364
367
  */
365
368
  type TypedPropertyRequired<Value> = {
369
+ $default?: unknown;
366
370
  $required?: true;
367
371
  $type: ToSchemaPropertyType<Value>;
368
372
  $validators?: PropertyValidators<ToSchemaPropertyType<Value>>;
@@ -370,7 +374,7 @@ type TypedPropertyRequired<Value> = {
370
374
  /**
371
375
  * Creates a schema type constrained to match a TypeScript type
372
376
  *
373
- * Required keys map to {@link ToSchemaType} or {@link TypedPropertyRequired}; plain object values may also use {@link Schematic}. Optional keys map to {@link TypedPropertyOptional} or, for plain objects, {@link TypedSchemaOptional}
377
+ * Required keys map to {@link ToSchemaType} or {@link TypedPropertyRequired}; plain object values may also use {@link Schema}
374
378
  *
375
379
  * @template Model Object type to generate a schema for
376
380
  *
@@ -385,31 +389,15 @@ type TypedPropertyRequired<Value> = {
385
389
  * };
386
390
  * ```
387
391
  */
388
- type TypedSchema<Model extends PlainObject> = Simplify<{ [Key in RequiredKeys<Model>]: Model[Key] extends PlainObject ? TypedSchemaRequired<Model[Key]> | Schematic<Model[Key]> : ToSchemaType<Model[Key]> | TypedPropertyRequired<Model[Key]> } & { [Key in OptionalKeys<Model>]: Exclude<Model[Key], undefined> extends PlainObject ? TypedSchemaOptional<Exclude<Model[Key], undefined>> | Schematic<Exclude<Model[Key], undefined>> : TypedPropertyOptional<Model[Key]> }>;
389
- /**
390
- * A {@link TypedSchema} variant for optional nested objects, with `$required` fixed to `false`
391
- *
392
- * @template Model Nested object type
393
- */
394
- type TypedSchemaOptional<Model extends PlainObject> = {
395
- $required: false;
396
- } & TypedSchema<Model>;
397
- /**
398
- * A {@link TypedSchema} variant for required nested objects, with `$required` defaulting to `true`
399
- *
400
- * @template Model Nested object type
401
- */
402
- type TypedSchemaRequired<Model extends PlainObject> = {
403
- $required?: true;
404
- } & TypedSchema<Model>;
392
+ type TypedSchematic<Model extends PlainObject> = Simplify<{ [Key in RequiredKeys<Model>]: Model[Key] extends PlainObject ? Schema<Model[Key]> : ToSchemaType<Model[Key]> | TypedPropertyRequired<Model[Key]> } & { [Key in OptionalKeys<Model>]: Exclude<Model[Key], undefined> extends PlainObject ? Schema<Exclude<Model[Key], undefined>> : TypedPropertyOptional<Model[Key]> }>;
405
393
  //#endregion
406
- //#region src/schematic.d.ts
394
+ //#region src/schema.d.ts
407
395
  /**
408
- * A schematic for validating objects
396
+ * A schema for validating objects
409
397
  */
410
- declare class Schematic<Model> {
398
+ declare class Schema<Model> {
411
399
  #private;
412
- private readonly $schematic;
400
+ private readonly $schema;
413
401
  constructor(validator: Validator);
414
402
  /**
415
403
  * Parse a value according to the schema
@@ -557,21 +545,21 @@ declare class Schematic<Model> {
557
545
  is(value: unknown, strict?: true): value is Model;
558
546
  }
559
547
  /**
560
- * Create a schematic from a schema
548
+ * Create a schema from a schematic
561
549
  * @template Model Schema type
562
- * @param schema Schema to create the schematic from
563
- * @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
564
- * @returns A schematic for the given schema
550
+ * @param schema Schematic to create the schema from
551
+ * @throws Throws {@link SchematicError} if the schematic can not be converted into a schema
552
+ * @returns A schema for the given schematic
565
553
  */
566
- declare function schematic<Model extends Schema>(schema: Model): Schematic<Infer<Model>>;
554
+ declare function schema<Model extends Schematic>(schema: Model): Schema<Infer<Model>>;
567
555
  /**
568
- * Create a schematic from a typed schema
556
+ * Create a schema from a typed schematic
569
557
  * @template Model Existing type
570
- * @param schema Typed schema to create the schematic from
571
- * @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
572
- * @returns A schematic for the given typed schema
558
+ * @param schema Typed schematic to create the schema from
559
+ * @throws Throws {@link SchematicError} if the schematic can not be converted into a schema
560
+ * @returns A schema for the given typed schematic
573
561
  */
574
- declare function schematic<Model extends PlainObject>(schema: TypedSchema<Model>): Schematic<Model>;
562
+ declare function schema<Model extends PlainObject>(schema: TypedSchematic<Model>): Schema<Model>;
575
563
  //#endregion
576
564
  //#region src/models/validation.model.d.ts
577
565
  type ReportingInformation = Record<ReportingType, boolean> & {
@@ -660,6 +648,6 @@ declare function instanceOf<Instance>(constructor: Constructor<Instance>): (valu
660
648
  * @param value Value to check
661
649
  * @returns `true` if the value is a schematic, `false` otherwise
662
650
  */
663
- declare function isSchematic(value: unknown): value is Schematic<never>;
651
+ declare function isSchema(value: unknown): value is Schema<never>;
664
652
  //#endregion
665
- export { type GetOptions, type IsOptions, type Schema, type Schematic, SchematicError, type TypedSchema, ValidationError, instanceOf, isSchematic, schematic };
653
+ export { type GetOptions, type IsOptions, type Schema, type Schematic, SchematicError, type TypedSchematic, ValidationError, instanceOf, isSchema, schema };