@oscarpalmer/jhunal 0.15.0 → 0.16.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.
- package/dist/constants.d.mts +27 -0
- package/dist/{constants.js → constants.mjs} +2 -0
- package/{types/helpers.d.ts → dist/helpers.d.mts} +8 -4
- package/dist/{helpers.js → helpers.mjs} +3 -1
- package/dist/index.d.mts +553 -0
- package/dist/{jhunal.full.js → index.mjs} +27 -66
- package/{types/models.d.ts → dist/models.d.mts} +102 -127
- package/dist/{models.js → models.mjs} +3 -1
- package/dist/schematic.d.mts +36 -0
- package/dist/{schematic.js → schematic.mjs} +7 -5
- package/dist/validation/property.validation.d.mts +7 -0
- package/dist/validation/{property.validation.js → property.validation.mjs} +6 -4
- package/dist/validation/value.validation.d.mts +6 -0
- package/dist/validation/{value.validation.js → value.validation.mjs} +4 -2
- package/package.json +53 -48
- package/src/constants.ts +1 -2
- package/src/validation/property.validation.ts +1 -1
- package/dist/index.js +0 -4
- package/types/constants.d.ts +0 -22
- package/types/index.d.ts +0 -3
- package/types/schematic.d.ts +0 -32
- package/types/validation/property.validation.d.ts +0 -3
- package/types/validation/value.validation.d.ts +0 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { EXPRESSION_PROPERTY, MESSAGE_SCHEMA_INVALID_EMPTY, MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, MESSAGE_VALIDATOR_INVALID_KEY, MESSAGE_VALIDATOR_INVALID_TYPE, MESSAGE_VALIDATOR_INVALID_VALUE, PROPERTY_REQUIRED, PROPERTY_TYPE, PROPERTY_VALIDATORS, TEMPLATE_PATTERN_KEY, TEMPLATE_PATTERN_PROPERTY, TYPE_ALL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES } from "../constants.
|
|
2
|
-
import { instanceOf, isSchematic } from "../helpers.
|
|
3
|
-
import { SchematicError } from "../models.
|
|
1
|
+
import { EXPRESSION_PROPERTY, MESSAGE_SCHEMA_INVALID_EMPTY, MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED, MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED, MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE, MESSAGE_VALIDATOR_INVALID_KEY, MESSAGE_VALIDATOR_INVALID_TYPE, MESSAGE_VALIDATOR_INVALID_VALUE, PROPERTY_REQUIRED, PROPERTY_TYPE, PROPERTY_VALIDATORS, TEMPLATE_PATTERN_KEY, TEMPLATE_PATTERN_PROPERTY, TYPE_ALL, TYPE_OBJECT, TYPE_UNDEFINED, VALIDATABLE_TYPES } from "../constants.mjs";
|
|
2
|
+
import { instanceOf, isSchematic } from "../helpers.mjs";
|
|
3
|
+
import { SchematicError } from "../models.mjs";
|
|
4
4
|
import { isConstructor, isPlainObject } from "@oscarpalmer/atoms/is";
|
|
5
|
-
import { join } from "@oscarpalmer/atoms/string
|
|
5
|
+
import { join } from "@oscarpalmer/atoms/string";
|
|
6
|
+
//#region src/validation/property.validation.ts
|
|
6
7
|
function getDisallowedProperty(obj) {
|
|
7
8
|
if ("$required" in obj) return PROPERTY_REQUIRED;
|
|
8
9
|
if ("$type" in obj) return PROPERTY_TYPE;
|
|
@@ -87,4 +88,5 @@ function getValidators(original) {
|
|
|
87
88
|
}
|
|
88
89
|
return validators;
|
|
89
90
|
}
|
|
91
|
+
//#endregion
|
|
90
92
|
export { getProperties };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { isSchematic } from "../helpers.
|
|
1
|
+
import { isSchematic } from "../helpers.mjs";
|
|
2
2
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
//#region src/validation/value.validation.ts
|
|
3
4
|
function validateObject(obj, properties) {
|
|
4
5
|
if (!isPlainObject(obj)) return false;
|
|
5
6
|
const propertiesLength = properties.length;
|
|
@@ -25,7 +26,7 @@ function validateValue(type, property, value) {
|
|
|
25
26
|
default: return validators[type](value) && (property.validators[type]?.every((validator) => validator(value)) ?? true);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
const validators = {
|
|
29
30
|
array: Array.isArray,
|
|
30
31
|
bigint: (value) => typeof value === "bigint",
|
|
31
32
|
boolean: (value) => typeof value === "boolean",
|
|
@@ -38,4 +39,5 @@ var validators = {
|
|
|
38
39
|
symbol: (value) => typeof value === "symbol",
|
|
39
40
|
undefined: (value) => value === void 0
|
|
40
41
|
};
|
|
42
|
+
//#endregion
|
|
41
43
|
export { validateObject };
|
package/package.json
CHANGED
|
@@ -1,49 +1,54 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
"name": "@oscarpalmer/jhunal",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "Flies free beneath the glistening moons…",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"schema",
|
|
7
|
+
"validation"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Oscar Palmér",
|
|
12
|
+
"url": "https://oscarpalmer.se"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/oscarpalmer/jhunal.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"module": "./dist/index.mjs",
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"default": "./dist/index.mjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "npx vp pack && npm run tsdown:build",
|
|
34
|
+
"tsdown:build": "npx tsdown -c ./tsdown.config.ts",
|
|
35
|
+
"tsdown:watch": "npx tsdown -c ./tsdown.config.ts --watch",
|
|
36
|
+
"test": "npx vp test run --coverage",
|
|
37
|
+
"test:leak": "npx vp test run --detect-async-leaks --coverage",
|
|
38
|
+
"watch": "npx vite build --watch"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@oscarpalmer/atoms": "^0.166"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^25.5",
|
|
45
|
+
"@vitest/coverage-istanbul": "^4.1",
|
|
46
|
+
"jsdom": "^29.0",
|
|
47
|
+
"tsdown": "^0.21",
|
|
48
|
+
"typescript": "^5.9",
|
|
49
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
|
50
|
+
"vite-plus": "latest",
|
|
51
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "npm@11.11.1"
|
|
54
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -11,8 +11,7 @@ export const MESSAGE_SCHEMA_INVALID_EMPTY = 'Schema must have at least one prope
|
|
|
11
11
|
export const MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED =
|
|
12
12
|
"'<key>.<property>' property is not allowed for schemas in $type";
|
|
13
13
|
|
|
14
|
-
export const MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED =
|
|
15
|
-
"'<>.$required' property must be a boolean";
|
|
14
|
+
export const MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED = "'<>.$required' property must be a boolean";
|
|
16
15
|
|
|
17
16
|
export const MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE = "'<>' property must be of a valid type";
|
|
18
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {isConstructor, isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
2
|
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
3
|
-
import {join} from '@oscarpalmer/atoms/string
|
|
3
|
+
import {join} from '@oscarpalmer/atoms/string';
|
|
4
4
|
import {
|
|
5
5
|
EXPRESSION_PROPERTY,
|
|
6
6
|
MESSAGE_SCHEMA_INVALID_EMPTY,
|
package/dist/index.js
DELETED
package/types/constants.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare const ERROR_NAME = "SchematicError";
|
|
2
|
-
export declare const EXPRESSION_PROPERTY: RegExp;
|
|
3
|
-
export declare const MESSAGE_CONSTRUCTOR = "Expected a constructor function";
|
|
4
|
-
export declare const MESSAGE_SCHEMA_INVALID_EMPTY = "Schema must have at least one property";
|
|
5
|
-
export declare const MESSAGE_SCHEMA_INVALID_PROPERTY_DISALLOWED = "'<key>.<property>' property is not allowed for schemas in $type";
|
|
6
|
-
export declare const MESSAGE_SCHEMA_INVALID_PROPERTY_REQUIRED = "'<>.$required' property must be a boolean";
|
|
7
|
-
export declare const MESSAGE_SCHEMA_INVALID_PROPERTY_TYPE = "'<>' property must be of a valid type";
|
|
8
|
-
export declare const MESSAGE_SCHEMA_INVALID_TYPE = "Schema must be an object";
|
|
9
|
-
export declare const MESSAGE_VALIDATOR_INVALID_KEY = "Validator '<>' does not exist";
|
|
10
|
-
export declare const MESSAGE_VALIDATOR_INVALID_TYPE = "Validators must be an object";
|
|
11
|
-
export declare const MESSAGE_VALIDATOR_INVALID_VALUE = "Validator '<>' must be a function or an array of functions";
|
|
12
|
-
export declare const PROPERTY_REQUIRED = "$required";
|
|
13
|
-
export declare const PROPERTY_TYPE = "$type";
|
|
14
|
-
export declare const PROPERTY_VALIDATORS = "$validators";
|
|
15
|
-
export declare const SCHEMATIC_NAME = "$schematic";
|
|
16
|
-
export declare const TEMPLATE_PATTERN = "<>";
|
|
17
|
-
export declare const TEMPLATE_PATTERN_KEY = "<key>";
|
|
18
|
-
export declare const TEMPLATE_PATTERN_PROPERTY = "<property>";
|
|
19
|
-
export declare const TYPE_OBJECT = "object";
|
|
20
|
-
export declare const TYPE_UNDEFINED = "undefined";
|
|
21
|
-
export declare const VALIDATABLE_TYPES: Set<keyof import("./models").Values>;
|
|
22
|
-
export declare const TYPE_ALL: Set<keyof import("./models").Values>;
|
package/types/index.d.ts
DELETED
package/types/schematic.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import { type Infer, type Schema, type TypedSchema, type ValidatedProperty } from './models';
|
|
3
|
-
/**
|
|
4
|
-
* A schematic for validating objects
|
|
5
|
-
*/
|
|
6
|
-
export declare class Schematic<Model> {
|
|
7
|
-
#private;
|
|
8
|
-
private readonly $schematic;
|
|
9
|
-
constructor(properties: ValidatedProperty[]);
|
|
10
|
-
/**
|
|
11
|
-
* Does the value match the schema?
|
|
12
|
-
* @param value - Value to validate
|
|
13
|
-
* @returns `true` if the value matches the schema, otherwise `false`
|
|
14
|
-
*/
|
|
15
|
-
is(value: unknown): value is Model;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create a schematic from a schema
|
|
19
|
-
* @template Model - Schema type
|
|
20
|
-
* @param schema - Schema to create the schematic from
|
|
21
|
-
* @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
|
|
22
|
-
* @returns A schematic for the given schema
|
|
23
|
-
*/
|
|
24
|
-
export declare function schematic<Model extends Schema>(schema: Model): Schematic<Infer<Model>>;
|
|
25
|
-
/**
|
|
26
|
-
* Create a schematic from a typed schema
|
|
27
|
-
* @template Model - Existing type
|
|
28
|
-
* @param schema - Typed schema to create the schematic from
|
|
29
|
-
* @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
|
|
30
|
-
* @returns A schematic for the given typed schema
|
|
31
|
-
*/
|
|
32
|
-
export declare function schematic<Model extends PlainObject>(schema: TypedSchema<Model>): Schematic<Model>;
|