@final-hill/decorator-contracts 0.25.3 → 2.0.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 (46) hide show
  1. package/README.md +580 -542
  2. package/dist/AssertionError.d.mts +52 -8
  3. package/dist/Contracted.d.mts +29 -21
  4. package/dist/admissibility.d.mts +81 -0
  5. package/dist/assert.d.mts +73 -8
  6. package/dist/decorator.d.mts +12 -0
  7. package/dist/demands.d.mts +54 -0
  8. package/dist/ensures.d.mts +39 -0
  9. package/dist/iff.d.mts +24 -6
  10. package/dist/implies.d.mts +22 -6
  11. package/dist/index.d.mts +11 -13
  12. package/dist/index.mjs +1 -2
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/invariant.d.mts +27 -0
  15. package/dist/read-only.d.mts +45 -0
  16. package/dist/rescue.d.mts +61 -0
  17. package/dist/standard-schema.d.mts +46 -0
  18. package/dist/types.d.mts +7 -0
  19. package/package.json +33 -18
  20. package/dist/Contract.d.mts +0 -39
  21. package/dist/Messages.d.mts +0 -16
  22. package/dist/index.mjs.LICENSE.txt +0 -6
  23. package/dist/lib/ClassRegistration.d.mts +0 -23
  24. package/dist/lib/ClassType.d.mts +0 -10
  25. package/dist/lib/Feature.d.mts +0 -26
  26. package/dist/lib/assertDemands.d.mts +0 -9
  27. package/dist/lib/assertEnsures.d.mts +0 -10
  28. package/dist/lib/assertInvariants.d.mts +0 -9
  29. package/dist/lib/classRegistry.d.mts +0 -12
  30. package/dist/lib/deepFreeze.d.mts +0 -8
  31. package/dist/lib/index.d.mts +0 -18
  32. package/dist/lib/takeWhile.d.mts +0 -8
  33. package/dist/lib/unChecked.d.mts +0 -9
  34. package/dist/tests/Contract.test.d.mts +0 -7
  35. package/dist/tests/Stack.test.d.mts +0 -7
  36. package/dist/tests/assert.test.d.mts +0 -7
  37. package/dist/tests/deepFreeze.test.d.mts +0 -7
  38. package/dist/tests/demands.test.d.mts +0 -7
  39. package/dist/tests/ensures.test.d.mts +0 -7
  40. package/dist/tests/factoryPattern.test.d.mts +0 -7
  41. package/dist/tests/iff.test.d.mts +0 -7
  42. package/dist/tests/implies.test.d.mts +0 -7
  43. package/dist/tests/invariant.test.d.mts +0 -7
  44. package/dist/tests/public-properties.test.d.mts +0 -7
  45. package/dist/tests/rescue.test.d.mts +0 -7
  46. package/dist/tests/within.test.d.mts +0 -7
@@ -1,39 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- declare const checkedMode: unique symbol, invariant: unique symbol, extend: unique symbol;
8
- type AnyObject = Record<PropertyKey, any>;
9
- type AnyFunc = (...args: any[]) => any;
10
- type NonFunctionPropertyNames<T extends AnyObject> = {
11
- [K in keyof T]: T[K] extends AnyFunc ? never : K;
12
- }[keyof T];
13
- export type Properties<T extends AnyObject> = Pick<T, NonFunctionPropertyNames<T>>;
14
- export type Invariant<T extends AnyObject> = (self: T) => boolean;
15
- export type Demands<T extends AnyObject, F extends T[any]> = (self: T, ...args: Parameters<F>) => boolean;
16
- export type Ensures<T extends AnyObject, F extends T[any]> = (self: T, old: Properties<T>, ...args: Parameters<F>) => boolean;
17
- export type Rescue<T extends AnyObject, F extends T[any]> = (self: T, error: Error, args: F extends AnyFunc ? Parameters<F> : [F], retry: F extends AnyFunc ? (...args: Parameters<F>) => any : (value: F) => void) => void;
18
- export type ContractOptions<T extends AnyObject> = {
19
- [extend]: Contract<T>;
20
- [invariant]: Invariant<T>;
21
- [checkedMode]: boolean;
22
- } & {
23
- [K in keyof T]?: FeatureOption<T, T[K]>;
24
- };
25
- export interface FeatureOption<T extends AnyObject, F extends T[any]> {
26
- demands?: Demands<T, F>;
27
- ensures?: Ensures<T, F>;
28
- rescue?: Rescue<T, F>;
29
- within?: number;
30
- }
31
- export declare class Contract<T extends AnyObject> {
32
- #private;
33
- [checkedMode]: boolean;
34
- readonly [extend]?: Contract<T>;
35
- readonly assertions: ContractOptions<T>;
36
- constructor(assertions?: Partial<ContractOptions<T>>);
37
- get [invariant](): Invariant<T>;
38
- }
39
- export { checkedMode, extend, invariant };
@@ -1,16 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export declare enum Messages {
8
- AssertionFailed = "Assertion failure",
9
- MsgNoProperties = "Public properties are forbidden",
10
- MsgNotContracted = "The current class or one of its ancestors must declare @Contracted(...)",
11
- MsgMissingFeature = "The requested feature is not registered",
12
- MsgSingleContract = "Only a single @Contracted decorator is allowed per class",
13
- MsgSingleRetry = "retry can only be called once",
14
- MsgInvalidContext = "A contracted feature can not be applied to objects of a different base class",
15
- MsgBadSubcontract = "A sub contract must extend a base contract"
16
- }
@@ -1,6 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
@@ -1,23 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { Contract } from '../index.mjs';
8
- import { ClassType, Feature } from './index.mjs';
9
- declare class ClassRegistration {
10
- #private;
11
- readonly Class: ClassType<any>;
12
- contract: Contract<any>;
13
- contractsChecked: boolean;
14
- constructor(Class: ClassType<any>);
15
- get features(): Feature[];
16
- get ParentClass(): ClassType<any> | null;
17
- get parentRegistration(): ClassRegistration | null;
18
- ancestry(): ClassRegistration[];
19
- ancestryFeatures(): Feature[];
20
- bindContract<T extends Contract<any>>(contract: T): void;
21
- findFeature(propertyKey: PropertyKey): Feature | undefined;
22
- }
23
- export default ClassRegistration;
@@ -1,10 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- type Constructor<T> = new (...args: any[]) => T;
8
- type AbstractConstructor<T> = abstract new (...args: any[]) => T;
9
- type ClassType<T> = Constructor<T> | AbstractConstructor<T>;
10
- export { Constructor, AbstractConstructor, ClassType };
@@ -1,26 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import ClassRegistration from './ClassRegistration.mjs';
8
- declare class Feature {
9
- #private;
10
- readonly classRegistration: ClassRegistration;
11
- readonly name: PropertyKey;
12
- constructor(classRegistration: ClassRegistration, name: PropertyKey, descriptor: PropertyDescriptor);
13
- get ancestorFeature(): Feature | null;
14
- get getter(): (() => any) | undefined;
15
- get hasGetter(): boolean;
16
- get hasSetter(): boolean;
17
- get isProperty(): boolean;
18
- get isMethod(): boolean;
19
- get isAccessor(): boolean;
20
- get memberType(): 'method' | 'property' | 'accessor';
21
- get setter(): ((v: any) => void) | undefined;
22
- get value(): any;
23
- get descriptor(): PropertyDescriptor;
24
- set descriptor(desc: PropertyDescriptor);
25
- }
26
- export default Feature;
@@ -1,9 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { Contract } from '../index.mjs';
8
- declare function assertDemands<U extends object>(ctx: U, contract: Contract<U>, className: string, featureName: PropertyKey, args: any[]): void;
9
- export default assertDemands;
@@ -1,10 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { Properties } from '../Contract.mjs';
8
- import { Contract } from '../index.mjs';
9
- declare function assertEnsures<U extends Properties<any>>(ctx: U, contract: Contract<any>, className: string, featureName: PropertyKey, old: U, args: any[]): void;
10
- export default assertEnsures;
@@ -1,9 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { Contract } from '../index.mjs';
8
- declare function assertInvariants<U>(ctx: U, contract: Contract<any>): void;
9
- export default assertInvariants;
@@ -1,12 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { ClassRegistration, ClassType } from './index.mjs';
8
- declare class ClassRegistry extends WeakMap<ClassType<any>, ClassRegistration> {
9
- getOrCreate(Class: ClassType<any>): ClassRegistration;
10
- }
11
- declare const _default: ClassRegistry;
12
- export default _default;
@@ -1,8 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- declare function deepFreeze(object: Record<PropertyKey, any>): void;
8
- export default deepFreeze;
@@ -1,18 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import assertDemands from './assertDemands.mjs';
8
- import assertEnsures from './assertEnsures.mjs';
9
- import assertInvariants from './assertInvariants.mjs';
10
- import classRegistry from './classRegistry.mjs';
11
- import ClassRegistration from './ClassRegistration.mjs';
12
- import { type ClassType } from './ClassType.mjs';
13
- import deepFreeze from './deepFreeze.mjs';
14
- import Feature from './Feature.mjs';
15
- import takeWhile from './takeWhile.mjs';
16
- import unChecked from './unChecked.mjs';
17
- declare const fnTrue: () => boolean;
18
- export { assertDemands, assertEnsures, assertInvariants, classRegistry, ClassRegistration, ClassType, deepFreeze, Feature, fnTrue, takeWhile, unChecked };
@@ -1,8 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export declare function takeWhile<T>(xs: T[], pred: (x: T) => boolean): T[];
8
- export default takeWhile;
@@ -1,9 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- import { Contract } from '../index.mjs';
8
- declare const unChecked: (contract: Contract<any>, fn: () => any) => void;
9
- export default unChecked;
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /*!
2
- * @license
3
- * Copyright (C) 2024 Final Hill LLC
4
- * SPDX-License-Identifier: AGPL-3.0-only
5
- * @see <https://spdx.org/licenses/AGPL-3.0-only.html>
6
- */
7
- export {};