@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.
@@ -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.js";
2
- import { instanceOf, isSchematic } from "../helpers.js";
3
- import { SchematicError } from "../models.js";
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/misc";
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 };
@@ -0,0 +1,6 @@
1
+ import { ValidatedProperty } from "../models.mjs";
2
+
3
+ //#region src/validation/value.validation.d.ts
4
+ declare function validateObject(obj: unknown, properties: ValidatedProperty[]): boolean;
5
+ //#endregion
6
+ export { validateObject };
@@ -1,5 +1,6 @@
1
- import { isSchematic } from "../helpers.js";
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
- var validators = {
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
- "author": {
3
- "name": "Oscar Palmér",
4
- "url": "https://oscarpalmer.se"
5
- },
6
- "dependencies": {
7
- "@oscarpalmer/atoms": "^0.141.2"
8
- },
9
- "description": "Flies free beneath the glistening moons…",
10
- "devDependencies": {
11
- "@types/node": "^25.3",
12
- "@vitest/coverage-istanbul": "^4",
13
- "jsdom": "^28.1",
14
- "oxfmt": "^0.35",
15
- "oxlint": "^1.50",
16
- "rolldown": "1.0.0-rc.5",
17
- "tslib": "^2.8",
18
- "typescript": "^5.9",
19
- "vite": "8.0.0-beta.15",
20
- "vitest": "^4"
21
- },
22
- "exports": {
23
- "./package.json": "./package.json",
24
- ".": {
25
- "types": "./types/index.d.ts",
26
- "default": "./dist/index.js"
27
- }
28
- },
29
- "files": ["dist", "src", "types"],
30
- "keywords": ["schema", "validation"],
31
- "license": "MIT",
32
- "module": "./dist/index.js",
33
- "name": "@oscarpalmer/jhunal",
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/oscarpalmer/jhunal.git"
37
- },
38
- "scripts": {
39
- "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc",
40
- "clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
41
- "rolldown:build": "npx rolldown -c",
42
- "rolldown:watch": "npx rolldown -c ./rolldown.config.js --watch",
43
- "test": "npx vitest --coverage",
44
- "watch": "npx vite build --watch"
45
- },
46
- "type": "module",
47
- "types": "./types/index.d.ts",
48
- "version": "0.15.0"
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/misc';
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
@@ -1,4 +0,0 @@
1
- import { instanceOf, isSchematic } from "./helpers.js";
2
- import { SchematicError } from "./models.js";
3
- import { schematic } from "./schematic.js";
4
- export { SchematicError, instanceOf, isSchematic, schematic };
@@ -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
@@ -1,3 +0,0 @@
1
- export { instanceOf, isSchematic } from './helpers';
2
- export { SchematicError, type Schema, type TypedSchema } from './models';
3
- export { schematic, type Schematic } from './schematic';
@@ -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>;
@@ -1,3 +0,0 @@
1
- import type { PlainObject } from '@oscarpalmer/atoms/models';
2
- import { type ValidatedProperty } from '../models';
3
- export declare function getProperties(original: PlainObject, prefix?: string, fromType?: boolean): ValidatedProperty[];
@@ -1,2 +0,0 @@
1
- import type { ValidatedProperty } from '../models';
2
- export declare function validateObject(obj: unknown, properties: ValidatedProperty[]): boolean;