@ne1410s/codl 0.1.3 → 0.1.5

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,24 +1,24 @@
1
- import 'reflect-metadata';
2
- import { RecordKey } from '../types';
3
- export declare abstract class ReflectMetadata {
4
- /**
5
- * Retrieves the display name if provided (else the property key).
6
- * @param target The parent object.
7
- * @param key The property key.
8
- */
9
- static readonly getDisplayName: (target: Object, key: RecordKey) => string;
10
- /**
11
- * Retrieves the description.
12
- * @param target The parent object.
13
- * @param key The property key.
14
- */
15
- static readonly getDescription: (target: Object, key: RecordKey) => string;
16
- /**
17
- * Retrieves the formatted value if format provided (else the raw value).
18
- * @param target The parent object.
19
- * @param key The property key.
20
- * @param other If supplied, the formatter is applied to this value, rather
21
- * than that of the property.
22
- */
23
- static readonly getFormatted: (target: Object, key: RecordKey, other?: unknown) => string;
24
- }
1
+ import 'reflect-metadata';
2
+ import { RecordKey } from '../types';
3
+ export declare abstract class ReflectMetadata {
4
+ /**
5
+ * Retrieves the display name if provided (else the property key).
6
+ * @param target The parent object.
7
+ * @param key The property key.
8
+ */
9
+ static readonly getDisplayName: (target: Object, key: RecordKey) => string;
10
+ /**
11
+ * Retrieves the description.
12
+ * @param target The parent object.
13
+ * @param key The property key.
14
+ */
15
+ static readonly getDescription: (target: Object, key: RecordKey) => string;
16
+ /**
17
+ * Retrieves the formatted value if format provided (else the raw value).
18
+ * @param target The parent object.
19
+ * @param key The property key.
20
+ * @param other If supplied, the formatter is applied to this value, rather
21
+ * than that of the property.
22
+ */
23
+ static readonly getFormatted: (target: Object, key: RecordKey, other?: unknown) => string;
24
+ }
@@ -1 +1 @@
1
- export declare type Parser<T> = (obj: any) => T;
1
+ export declare type Parser<T> = (obj: any) => T;
@@ -1,2 +1,2 @@
1
- import { Parser } from '../models';
2
- export declare const BooleanParser: Parser<boolean>;
1
+ import { Parser } from '../models';
2
+ export declare const BooleanParser: Parser<boolean>;
@@ -1,2 +1,2 @@
1
- import { Parser } from '../models';
2
- export declare const DateParser: Parser<Date>;
1
+ import { Parser } from '../models';
2
+ export declare const DateParser: Parser<Date>;
@@ -1,2 +1,2 @@
1
- import { Parser } from '../models';
2
- export declare const IntegerParser: Parser<number>;
1
+ import { Parser } from '../models';
2
+ export declare const IntegerParser: Parser<number>;
@@ -1,2 +1,2 @@
1
- import { Parser } from '../models';
2
- export declare const NumberParser: Parser<number>;
1
+ import { Parser } from '../models';
2
+ export declare const NumberParser: Parser<number>;
@@ -1,17 +1,17 @@
1
- import 'reflect-metadata';
2
- import { RecordKey } from '../../types';
3
- import { Parser } from './models';
4
- export declare abstract class ReflectType {
5
- /**
6
- * Parses provided according to its meta type. If no type found, the original
7
- * value is returned, otherwise a value is only returned in parseable cases.
8
- * @param target The object.
9
- * @param key The property key.
10
- * @param value Optional value override to parse instead.
11
- */
12
- static parse(target: Object, key: RecordKey, value?: any): any;
13
- /** Gets the meta type of that identified by the supplied parameters. */
14
- static getType(target: Object, key: RecordKey): string;
15
- /** Gets parser for supported meta types. */
16
- static getParser(type: string): Parser<any>;
17
- }
1
+ import 'reflect-metadata';
2
+ import { RecordKey } from '../../types';
3
+ import { Parser } from './models';
4
+ export declare abstract class ReflectType {
5
+ /**
6
+ * Parses provided according to its meta type. If no type found, the original
7
+ * value is returned, otherwise a value is only returned in parseable cases.
8
+ * @param target The object.
9
+ * @param key The property key.
10
+ * @param value Optional value override to parse instead.
11
+ */
12
+ static parse(target: Object, key: RecordKey, value?: any): any;
13
+ /** Gets the meta type of that identified by the supplied parameters. */
14
+ static getType(target: Object, key: RecordKey): string;
15
+ /** Gets parser for supported meta types. */
16
+ static getParser(type: string): Parser<any>;
17
+ }
@@ -1,39 +1,39 @@
1
- import { ValidationKey } from '../../mdkeys';
2
- export interface ValidatorDef {
3
- fn: Validator;
4
- test: string;
5
- meta: ValidationKey;
6
- }
7
- export interface ValidationInstruction {
8
- navkey: string;
9
- key: string;
10
- trg: Object;
11
- proto: any;
12
- fn: Validator;
13
- tests: string[];
14
- }
15
- export interface ObjectTest {
16
- navkey: string;
17
- trg: Object;
18
- proto: any;
19
- props: PropertyTest[];
20
- }
21
- export interface PropertyTest {
22
- key: string;
23
- navkey: string;
24
- fns: Validator[];
25
- }
26
- export declare type Validator = (trg: Object, key: string, proto: any) => ValidatorOut;
27
- export interface ValidatorOut {
28
- key: string;
29
- value: unknown;
30
- valid: boolean;
31
- message?: string;
32
- }
33
- export interface ValidationResult extends ValidatorOut {
34
- navkey: string;
35
- }
36
- export interface ValidationSummary {
37
- valid: boolean;
38
- errors?: Record<string, string[]>;
39
- }
1
+ import { ValidationKey } from '../../mdkeys';
2
+ export interface ValidatorDef {
3
+ fn: Validator;
4
+ test: string;
5
+ meta: ValidationKey;
6
+ }
7
+ export interface ValidationInstruction {
8
+ navkey: string;
9
+ key: string;
10
+ trg: Object;
11
+ proto: any;
12
+ fn: Validator;
13
+ tests: string[];
14
+ }
15
+ export interface ObjectTest {
16
+ navkey: string;
17
+ trg: Object;
18
+ proto: any;
19
+ props: PropertyTest[];
20
+ }
21
+ export interface PropertyTest {
22
+ key: string;
23
+ navkey: string;
24
+ fns: Validator[];
25
+ }
26
+ export declare type Validator = (trg: Object, key: string, proto: any) => ValidatorOut;
27
+ export interface ValidatorOut {
28
+ key: string;
29
+ value: unknown;
30
+ valid: boolean;
31
+ message?: string;
32
+ }
33
+ export interface ValidationResult extends ValidatorOut {
34
+ navkey: string;
35
+ }
36
+ export interface ValidationSummary {
37
+ valid: boolean;
38
+ errors?: Record<string, string[]>;
39
+ }
@@ -1,27 +1,27 @@
1
- import 'reflect-metadata';
2
- import { Ctor } from '../../types';
3
- import { ValidationSummary } from './models';
4
- /** Reflects validation decoration. */
5
- export declare abstract class ReflectValidation {
6
- /**
7
- * Performs validation - for objects with decorated members.
8
- * @param target The object to validate.
9
- * @param type The strong type (to supply prototype data).
10
- */
11
- static validate<T extends Object>(target: Object, type?: Ctor<T>): ValidationSummary;
12
- /**
13
- * Gets all available tests and their associated validator. There is expected
14
- * duplication where one validator is used to perform multiple tests.
15
- */
16
- private static getValidators;
17
- /** Gets the validator function for a given key. */
18
- private static getValidator;
19
- /** Prepares a sequence of validation instructions. */
20
- private static getTestInstructions;
21
- /** Reduces a full set of instructions into a condensed test plan. */
22
- private static prepareTestPlan;
23
- /** Executes test plan, mapping to a result. */
24
- private static executeTestPlan;
25
- /** Summarises a sequence of results. */
26
- private static summarise;
27
- }
1
+ import 'reflect-metadata';
2
+ import { Ctor } from '../../types';
3
+ import { ValidationSummary } from './models';
4
+ /** Reflects validation decoration. */
5
+ export declare abstract class ReflectValidation {
6
+ /**
7
+ * Performs validation - for objects with decorated members.
8
+ * @param target The object to validate.
9
+ * @param type The strong type (to supply prototype data).
10
+ */
11
+ static validate<T extends Object>(target: Object, type?: Ctor<T>): ValidationSummary;
12
+ /**
13
+ * Gets all available tests and their associated validator. There is expected
14
+ * duplication where one validator is used to perform multiple tests.
15
+ */
16
+ private static getValidators;
17
+ /** Gets the validator function for a given key. */
18
+ private static getValidator;
19
+ /** Prepares a sequence of validation instructions. */
20
+ private static getTestInstructions;
21
+ /** Reduces a full set of instructions into a condensed test plan. */
22
+ private static prepareTestPlan;
23
+ /** Executes test plan, mapping to a result. */
24
+ private static executeTestPlan;
25
+ /** Summarises a sequence of results. */
26
+ private static summarise;
27
+ }
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates with a custom function. */
3
- export declare const CustValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates with a custom function. */
3
+ export declare const CustValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates forbidden items. Only null, undefined and empty strings are ok. */
3
- export declare const ForbiddenValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates forbidden items. Only null, undefined and empty strings are ok. */
3
+ export declare const ForbiddenValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates string / array length are within specified range. */
3
- export declare const LengthRangeValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates string / array length are within specified range. */
3
+ export declare const LengthRangeValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates the member value is contained within predefined options. */
3
- export declare const OptionsValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates the member value is contained within predefined options. */
3
+ export declare const OptionsValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates values are within a range. */
3
- export declare const RangeValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates values are within a range. */
3
+ export declare const RangeValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates regex using string representation of the member. */
3
- export declare const RegexValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates regex using string representation of the member. */
3
+ export declare const RegexValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates required items. 0, 0n and false are allowed */
3
- export declare const RequiredValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates required items. 0, 0n and false are allowed */
3
+ export declare const RequiredValidator: Validator;
@@ -1,3 +1,3 @@
1
- import { Validator } from '../models';
2
- /** Validates type. */
3
- export declare const TypeValidator: Validator;
1
+ import { Validator } from '../models';
2
+ /** Validates type. */
3
+ export declare const TypeValidator: Validator;
package/dist/types.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- /** A constructor. */
2
- export interface Ctor<T> {
3
- new (...args: any[]): T;
4
- }
5
- /** A record key. */
6
- export declare type RecordKey = string | symbol;
7
- /** Decorator for a function. */
8
- export declare type FunctionDecorator = (trg: Object, key: RecordKey, desc: PropertyDescriptor) => void;
9
- /** Decorator for a property accessor of a given type. */
10
- export declare type TypedAccessorDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K, desc: TypedPropertyDescriptor<P>) => void;
11
- /** Decorator for a property or field of a given type. */
12
- export declare type TypedPropertyDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K) => void;
13
- /** Decorator for a function argument of a given type. */
14
- export declare type TypedArgumentDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K, idx: number) => void;
15
- /**
16
- * Whether a value is considered as having been provided.
17
- * Certain 'falsy' values pass, including 0, 0n, NaN.
18
- */
19
- export declare const isProvided: (v: unknown) => boolean;
20
- /**
21
- * Custom validator function. The value is supplied, along with the object and
22
- * prototype information (to best retrieve other metadata if required).
23
- */
24
- export declare type CustomValidator = (val: unknown, obj: Object, proto: any) => string | boolean;
1
+ /** A constructor. */
2
+ export interface Ctor<T> {
3
+ new (...args: any[]): T;
4
+ }
5
+ /** A record key. */
6
+ export declare type RecordKey = string | symbol;
7
+ /** Decorator for a function. */
8
+ export declare type FunctionDecorator = (trg: Object, key: RecordKey, desc: PropertyDescriptor) => void;
9
+ /** Decorator for a property accessor of a given type. */
10
+ export declare type TypedAccessorDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K, desc: TypedPropertyDescriptor<P>) => void;
11
+ /** Decorator for a property or field of a given type. */
12
+ export declare type TypedPropertyDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K) => void;
13
+ /** Decorator for a function argument of a given type. */
14
+ export declare type TypedArgumentDecorator<P> = <K extends RecordKey, T extends Partial<Record<K, P>>>(target: T, key: K, idx: number) => void;
15
+ /**
16
+ * Whether a value is considered as having been provided.
17
+ * Certain 'falsy' values pass, including 0, 0n, NaN.
18
+ */
19
+ export declare const isProvided: (v: unknown) => boolean;
20
+ /**
21
+ * Custom validator function. The value is supplied, along with the object and
22
+ * prototype information (to best retrieve other metadata if required).
23
+ */
24
+ export declare type CustomValidator = (val: unknown, obj: Object, proto: any) => string | boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ne1410s/codl",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Indulge your apps with codl: a component model library",
5
5
  "main": "dist/ne14_codl.cjs.min.js",
6
6
  "module": "dist/ne14_codl.esm.min.js",
@@ -39,12 +39,12 @@
39
39
  "devDependencies": {
40
40
  "chai": "^4.3.7",
41
41
  "mocha": "^10.2.0",
42
- "prettier": "^2.8.4",
43
- "rimraf": "^4.3.1",
44
- "rollup": "^3.18.0",
45
- "rollup-plugin-typescript2": "^0.34.1",
46
- "tslib": "^2.5.0",
47
- "typescript": "^4.9.5"
42
+ "prettier": "^3.0.0",
43
+ "rimraf": "^5.0.1",
44
+ "rollup": "^3.27.0",
45
+ "rollup-plugin-typescript2": "^0.35.0",
46
+ "tslib": "^2.6.1",
47
+ "typescript": "^5.1.6"
48
48
  },
49
49
  "dependencies": {
50
50
  "reflect-metadata": "^0.1.13"