@jonloucks/contracts-ts 0.4.0 → 1.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.
- package/api/AutoClose.d.ts +3 -3
- package/api/AutoClose.d.ts.map +1 -1
- package/api/AutoClose.js +17 -9
- package/api/AutoClose.js.map +1 -1
- package/api/AutoCloseFactory.d.ts +5 -3
- package/api/AutoCloseFactory.d.ts.map +1 -1
- package/api/AutoCloseFactory.js +14 -20
- package/api/AutoCloseFactory.js.map +1 -1
- package/api/AutoOpen.d.ts +3 -2
- package/api/AutoOpen.d.ts.map +1 -1
- package/api/AutoOpen.js +3 -3
- package/api/AutoOpen.js.map +1 -1
- package/api/BasicContract.d.ts +8 -2
- package/api/BasicContract.d.ts.map +1 -1
- package/api/BasicContract.js +35 -7
- package/api/BasicContract.js.map +1 -1
- package/api/BindStrategy.d.ts +1 -1
- package/api/BindStrategy.d.ts.map +1 -1
- package/api/BindStrategy.js +2 -2
- package/api/BindStrategy.js.map +1 -1
- package/api/Contract.d.ts +21 -12
- package/api/Contract.d.ts.map +1 -1
- package/api/Contract.js +11 -0
- package/api/Contract.js.map +1 -1
- package/api/ContractException.d.ts +7 -0
- package/api/ContractException.d.ts.map +1 -1
- package/api/ContractException.js +11 -1
- package/api/ContractException.js.map +1 -1
- package/api/ContractFactory.d.ts +8 -1
- package/api/ContractFactory.d.ts.map +1 -1
- package/api/ContractFactory.js +11 -0
- package/api/ContractFactory.js.map +1 -1
- package/api/Contracts.d.ts +10 -3
- package/api/Contracts.d.ts.map +1 -1
- package/api/Contracts.js +12 -0
- package/api/Contracts.js.map +1 -1
- package/api/ContractsFactory.d.ts +8 -1
- package/api/ContractsFactory.d.ts.map +1 -1
- package/api/ContractsFactory.js +11 -0
- package/api/ContractsFactory.js.map +1 -1
- package/api/Open.d.ts +20 -0
- package/api/Open.d.ts.map +1 -0
- package/api/Open.js +14 -0
- package/api/Open.js.map +1 -0
- package/api/Promisor.d.ts +1 -6
- package/api/Promisor.d.ts.map +1 -1
- package/api/Promisor.js +5 -27
- package/api/Promisor.js.map +1 -1
- package/api/PromisorFactory.d.ts +5 -3
- package/api/PromisorFactory.d.ts.map +1 -1
- package/api/PromisorFactory.js +14 -20
- package/api/PromisorFactory.js.map +1 -1
- package/api/RatifiedContract.d.ts +2 -2
- package/api/RatifiedContract.d.ts.map +1 -1
- package/api/RatifiedContract.js +1 -4
- package/api/RatifiedContract.js.map +1 -1
- package/api/Repository.d.ts +8 -5
- package/api/Repository.d.ts.map +1 -1
- package/api/Repository.js +9 -20
- package/api/Repository.js.map +1 -1
- package/api/RepositoryFactory.d.ts +6 -4
- package/api/RepositoryFactory.d.ts.map +1 -1
- package/api/RepositoryFactory.js +13 -20
- package/api/RepositoryFactory.js.map +1 -1
- package/api/Types.d.ts +11 -66
- package/api/Types.d.ts.map +1 -1
- package/api/Types.js +14 -105
- package/api/Types.js.map +1 -1
- package/auxiliary/AtomicBoolean.d.ts +6 -3
- package/auxiliary/AtomicBoolean.d.ts.map +1 -1
- package/auxiliary/AtomicBoolean.js +8 -20
- package/auxiliary/AtomicBoolean.js.map +1 -1
- package/auxiliary/AtomicBooleanFactory.d.ts +6 -4
- package/auxiliary/AtomicBooleanFactory.d.ts.map +1 -1
- package/auxiliary/AtomicBooleanFactory.js +13 -20
- package/auxiliary/AtomicBooleanFactory.js.map +1 -1
- package/auxiliary/AtomicInteger.d.ts +6 -3
- package/auxiliary/AtomicInteger.d.ts.map +1 -1
- package/auxiliary/AtomicInteger.js +8 -20
- package/auxiliary/AtomicInteger.js.map +1 -1
- package/auxiliary/AtomicIntegerFactory.d.ts +6 -4
- package/auxiliary/AtomicIntegerFactory.d.ts.map +1 -1
- package/auxiliary/AtomicIntegerFactory.js +13 -20
- package/auxiliary/AtomicIntegerFactory.js.map +1 -1
- package/auxiliary/AtomicReference.d.ts +6 -4
- package/auxiliary/AtomicReference.d.ts.map +1 -1
- package/auxiliary/AtomicReference.js +8 -20
- package/auxiliary/AtomicReference.js.map +1 -1
- package/auxiliary/AtomicReferenceFactory.d.ts +6 -4
- package/auxiliary/AtomicReferenceFactory.d.ts.map +1 -1
- package/auxiliary/AtomicReferenceFactory.js +13 -20
- package/auxiliary/AtomicReferenceFactory.js.map +1 -1
- package/impl/AtomicBooleanFactory.impl.js +2 -2
- package/impl/AtomicBooleanFactory.impl.js.map +1 -1
- package/impl/AtomicIntegerFactory.impl.js +2 -2
- package/impl/AtomicIntegerFactory.impl.js.map +1 -1
- package/impl/AtomicReferenceFactory.impl.js +2 -2
- package/impl/AtomicReferenceFactory.impl.js.map +1 -1
- package/impl/ContractFactory.impl.js +2 -2
- package/impl/ContractFactory.impl.js.map +1 -1
- package/impl/Contracts.impl.d.ts.map +1 -1
- package/impl/Contracts.impl.js +7 -1
- package/impl/Contracts.impl.js.map +1 -1
- package/impl/ContractsFactory.impl.js +4 -4
- package/impl/ContractsFactory.impl.js.map +1 -1
- package/impl/ContractsWrapper.impl.d.ts.map +1 -1
- package/impl/ContractsWrapper.impl.js +3 -0
- package/impl/ContractsWrapper.impl.js.map +1 -1
- package/impl/Events.d.ts +2 -2
- package/impl/Events.d.ts.map +1 -1
- package/impl/Events.impl.d.ts.map +1 -1
- package/impl/Events.impl.js +3 -0
- package/impl/Events.impl.js.map +1 -1
- package/impl/LifeCyclePromisor.impl.js +2 -2
- package/impl/LifeCyclePromisor.impl.js.map +1 -1
- package/impl/Repository.impl.d.ts.map +1 -1
- package/impl/Repository.impl.js +7 -1
- package/impl/Repository.impl.js.map +1 -1
- package/impl/RepositoryFactory.impl.js +1 -1
- package/impl/RepositoryFactory.impl.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.d.ts.map +1 -1
- package/index.js +7 -7
- package/index.js.map +1 -1
- package/package.json +3 -2
- package/version.d.ts.map +1 -1
- package/version.js +14 -8
- package/version.js.map +1 -1
- package/api/Lawyer.d.ts +0 -19
- package/api/Lawyer.d.ts.map +0 -1
- package/api/Lawyer.js +0 -3
- package/api/Lawyer.js.map +0 -1
- package/auxiliary/ClassCastException.d.ts +0 -8
- package/auxiliary/ClassCastException.d.ts.map +0 -1
- package/auxiliary/ClassCastException.js +0 -18
- package/auxiliary/ClassCastException.js.map +0 -1
package/api/AutoClose.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface AutoCloseWrapper extends AutoClose {
|
|
|
58
58
|
/**
|
|
59
59
|
* Unwrap to get the original AutoCloseType.
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
unwrapAutoCloseType(): RequiredType<AutoCloseType>;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Convert a simple runnable into an AutoClose with dispose
|
|
@@ -80,14 +80,14 @@ export declare function unwrapAutoClose(autoClose: OptionalType<AutoClose>): Opt
|
|
|
80
80
|
* @param instance the instance to check
|
|
81
81
|
* @returns true if the instance implements AutoClose, false otherwise
|
|
82
82
|
*/
|
|
83
|
-
export declare function
|
|
83
|
+
export declare function guard(instance: unknown): instance is RequiredType<AutoClose>;
|
|
84
84
|
/**
|
|
85
85
|
* Duck-typing check for object with close() method.
|
|
86
86
|
*
|
|
87
87
|
* @param instance the instance to check
|
|
88
88
|
* @returns true if the instance implements AutoClose, false otherwise
|
|
89
89
|
*/
|
|
90
|
-
export declare function isClose(instance: unknown): instance is
|
|
90
|
+
export declare function isClose(instance: unknown): instance is RequiredType<AutoClose>;
|
|
91
91
|
/**
|
|
92
92
|
* Convert an AutoCloseType to an AutoClose
|
|
93
93
|
* @param type the type to convert
|
package/api/AutoClose.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoClose.d.ts","sourceRoot":"","sources":["../../src/api/AutoClose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"AutoClose.d.ts","sourceRoot":"","sources":["../../src/api/AutoClose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAgC,MAAM,mCAAmC,CAAC;AAI7G;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC;;OAEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,SAAS;IAE9C;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS;IAE7C;;;;OAIG;IACH,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;CACnD;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SAe7B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IAEjD;;OAEG;IACH,mBAAmB,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;CACpD;AAWD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAMlF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC,CAQ/F;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,SAAS,CAAC,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,SAAS,CAAC,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAW1F"}
|
package/api/AutoClose.js
CHANGED
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AUTO_CLOSE_NONE = void 0;
|
|
4
4
|
exports.inlineAutoClose = inlineAutoClose;
|
|
5
5
|
exports.unwrapAutoClose = unwrapAutoClose;
|
|
6
|
-
exports.
|
|
6
|
+
exports.guard = guard;
|
|
7
7
|
exports.isClose = isClose;
|
|
8
8
|
exports.typeToAutoClose = typeToAutoClose;
|
|
9
9
|
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
10
|
-
const IllegalArgumentException_1 = require("@jonloucks/contracts-ts/auxiliary/IllegalArgumentException");
|
|
11
10
|
const Checks_1 = require("@jonloucks/contracts-ts/auxiliary/Checks");
|
|
11
|
+
const IllegalArgumentException_1 = require("@jonloucks/contracts-ts/auxiliary/IllegalArgumentException");
|
|
12
12
|
/**
|
|
13
13
|
* A no-op AutoClose instance that does nothing on close or dispose.
|
|
14
14
|
*/
|
|
@@ -26,6 +26,14 @@ exports.AUTO_CLOSE_NONE = {
|
|
|
26
26
|
// no-op
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Check if an instance is an AutoCloseWrapper
|
|
31
|
+
* @param instance the instance to check
|
|
32
|
+
* @returns true if the instance is an AutoCloseWrapper, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
function guardAutoCloseWrapper(instance) {
|
|
35
|
+
return (0, Types_1.guardFunctions)(instance, 'unwrapAutoCloseType');
|
|
36
|
+
}
|
|
29
37
|
/**
|
|
30
38
|
* Convert a simple runnable into an AutoClose with dispose
|
|
31
39
|
*
|
|
@@ -36,7 +44,7 @@ function inlineAutoClose(action) {
|
|
|
36
44
|
return {
|
|
37
45
|
close: action,
|
|
38
46
|
[Symbol.dispose]: action,
|
|
39
|
-
|
|
47
|
+
unwrapAutoCloseType: () => action
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
@@ -49,8 +57,8 @@ function unwrapAutoClose(autoClose) {
|
|
|
49
57
|
if ((0, Types_1.isNotPresent)(autoClose)) {
|
|
50
58
|
return autoClose;
|
|
51
59
|
}
|
|
52
|
-
if (
|
|
53
|
-
return autoClose.
|
|
60
|
+
if (guardAutoCloseWrapper(autoClose)) {
|
|
61
|
+
return autoClose.unwrapAutoCloseType();
|
|
54
62
|
}
|
|
55
63
|
return autoClose;
|
|
56
64
|
}
|
|
@@ -60,8 +68,8 @@ function unwrapAutoClose(autoClose) {
|
|
|
60
68
|
* @param instance the instance to check
|
|
61
69
|
* @returns true if the instance implements AutoClose, false otherwise
|
|
62
70
|
*/
|
|
63
|
-
function
|
|
64
|
-
return (0, Types_1.
|
|
71
|
+
function guard(instance) {
|
|
72
|
+
return (0, Types_1.guardFunctions)(instance, 'close', Symbol.dispose);
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
75
|
* Duck-typing check for object with close() method.
|
|
@@ -70,7 +78,7 @@ function isAutoClose(instance) {
|
|
|
70
78
|
* @returns true if the instance implements AutoClose, false otherwise
|
|
71
79
|
*/
|
|
72
80
|
function isClose(instance) {
|
|
73
|
-
return (0, Types_1.
|
|
81
|
+
return (0, Types_1.guardFunctions)(instance, 'close');
|
|
74
82
|
}
|
|
75
83
|
/**
|
|
76
84
|
* Convert an AutoCloseType to an AutoClose
|
|
@@ -79,7 +87,7 @@ function isClose(instance) {
|
|
|
79
87
|
*/
|
|
80
88
|
function typeToAutoClose(type) {
|
|
81
89
|
const presentType = (0, Checks_1.presentCheck)(type, "AutoClose type must be present.");
|
|
82
|
-
if (
|
|
90
|
+
if (guard(presentType)) {
|
|
83
91
|
return presentType;
|
|
84
92
|
}
|
|
85
93
|
else if (isClose(presentType)) {
|
package/api/AutoClose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoClose.js","sourceRoot":"","sources":["../../src/api/AutoClose.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AutoClose.js","sourceRoot":"","sources":["../../src/api/AutoClose.ts"],"names":[],"mappings":";;;AAyGA,0CAMC;AAQD,0CAQC;AAQD,sBAEC;AAQD,0BAEC;AAOD,0CAWC;AArKD,6DAA6G;AAC7G,qEAAwE;AACxE,yGAAsG;AAyDtG;;GAEG;AACU,QAAA,eAAe,GAAc;IAExC;;OAEG;IACH,KAAK,EAAE,GAAG,EAAE;QACV,QAAQ;IACV,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;QACrB,QAAQ;IACV,CAAC;CACF,CAAC;AAaF;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,QAAiB;IAC9C,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,MAAkB;IAChD,OAAO;QACL,KAAK,EAAE,MAAM;QACb,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM;QACxB,mBAAmB,EAAE,GAAG,EAAE,CAAC,MAAM;KAClC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,SAAkC;IAChE,IAAI,IAAA,oBAAY,EAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC,mBAAmB,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,QAAiB;IACrC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,QAAiB;IACvC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,IAAiC;IAC/D,MAAM,WAAW,GAAG,IAAA,qBAAY,EAAC,IAAI,EAAE,iCAAiC,CAAC,CAAC;IAC1E,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QACvB,OAAO,WAAW,CAAC;IACrB,CAAC;SAAM,IAAI,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;SAAM,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;QAC7C,OAAO,eAAe,CAAC,WAA4B,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,mDAAwB,CAAC,yBAAyB,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AutoClose, AutoCloseMany, AutoCloseOne, AutoCloseType } from "@jonloucks/contracts-ts/api/AutoClose";
|
|
2
2
|
import { Contract } from "@jonloucks/contracts-ts/api/Contract";
|
|
3
|
-
import { Lawyer } from "@jonloucks/contracts-ts/api/Lawyer";
|
|
4
3
|
import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
|
|
5
4
|
/**
|
|
6
5
|
* Interface for a factory that creates AutoClose instances.
|
|
@@ -29,9 +28,12 @@ export { AutoClose, AutoCloseMany, AutoCloseOne, AutoCloseType } from "@jonlouck
|
|
|
29
28
|
export { Contract } from "@jonloucks/contracts-ts/api/Contract";
|
|
30
29
|
export { OptionalType, RequiredType } from "@jonloucks/contracts-ts/api/Types";
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
31
|
+
* Type guard for AutoCloseFactory interface.
|
|
32
|
+
*
|
|
33
|
+
* @param instance the instance to check
|
|
34
|
+
* @returns true if the instance implements AutoCloseFactory
|
|
33
35
|
*/
|
|
34
|
-
export declare
|
|
36
|
+
export declare function guard(instance: unknown): instance is RequiredType<AutoCloseFactory>;
|
|
35
37
|
/**
|
|
36
38
|
* The Contract for AutoCloseFactory implementation.
|
|
37
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCloseFactory.d.ts","sourceRoot":"","sources":["../../src/api/AutoCloseFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC9G,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"AutoCloseFactory.d.ts","sourceRoot":"","sources":["../../src/api/AutoCloseFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAEhE,OAAO,EAAkB,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAE7B;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAE5E;;;;OAIG;IACH,mBAAmB,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;CACpD;AAED,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/E;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,gBAAgB,CAAC,CAEnF;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAI9C,CAAC"}
|
package/api/AutoCloseFactory.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONTRACT =
|
|
3
|
+
exports.CONTRACT = void 0;
|
|
4
|
+
exports.guard = guard;
|
|
4
5
|
const RatifiedContract_1 = require("@jonloucks/contracts-ts/api/RatifiedContract");
|
|
5
6
|
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Type guard for AutoCloseFactory interface.
|
|
9
|
+
*
|
|
10
|
+
* @param instance the instance to check
|
|
11
|
+
* @returns true if the instance implements AutoCloseFactory
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
isDeliverable(instance) {
|
|
14
|
-
return (0, Types_1.hasFunctions)(instance, 'createAutoClose', 'createAutoCloseMany', 'createAutoCloseOne');
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Lawyer.createContract override
|
|
18
|
-
*/
|
|
19
|
-
createContract(config) {
|
|
20
|
-
const copy = { ...config ?? {} };
|
|
21
|
-
copy.test ?? (copy.test = this.isDeliverable);
|
|
22
|
-
copy.typeName ?? (copy.typeName = "AutoCloseFactory");
|
|
23
|
-
return (0, RatifiedContract_1.create)(copy);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
13
|
+
function guard(instance) {
|
|
14
|
+
return (0, Types_1.guardFunctions)(instance, 'createAutoClose', 'createAutoCloseMany', 'createAutoCloseOne');
|
|
15
|
+
}
|
|
26
16
|
/**
|
|
27
17
|
* The Contract for AutoCloseFactory implementation.
|
|
28
18
|
*/
|
|
29
|
-
exports.CONTRACT =
|
|
19
|
+
exports.CONTRACT = (0, RatifiedContract_1.create)({
|
|
20
|
+
test: guard,
|
|
21
|
+
name: "AutoCloseFactory",
|
|
22
|
+
typeName: "AutoCloseFactory"
|
|
23
|
+
});
|
|
30
24
|
//# sourceMappingURL=AutoCloseFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCloseFactory.js","sourceRoot":"","sources":["../../src/api/AutoCloseFactory.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AutoCloseFactory.js","sourceRoot":"","sources":["../../src/api/AutoCloseFactory.ts"],"names":[],"mappings":";;;AA0CA,sBAEC;AA1CD,mFAAwF;AACxF,6DAAiF;AAiCjF;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,QAAiB;IACnC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;AACpG,CAAC;AAED;;GAEG;AACU,QAAA,QAAQ,GAA+B,IAAA,yBAAc,EAAC;IAC/D,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE,kBAAkB;CAC/B,CAAC,CAAC"}
|
package/api/AutoOpen.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AutoClose } from "@jonloucks/contracts-ts/api/AutoClose";
|
|
2
|
+
import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
|
|
2
3
|
/**
|
|
3
4
|
* Opt-in interface to be called once after creation, although implementations should
|
|
4
5
|
* handle this gracefully. For example, this is when threads or hooks could be added.
|
|
@@ -11,7 +12,7 @@ export interface AutoOpen {
|
|
|
11
12
|
* AutoOpen this instance
|
|
12
13
|
* @return the mechanism to shut down
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
autoOpen(): AutoClose;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Duck-typing check for AutoOpen interface.
|
|
@@ -19,5 +20,5 @@ export interface AutoOpen {
|
|
|
19
20
|
* @param instance the instance to check
|
|
20
21
|
* @returns true if the instance implements AutoOpen, false otherwise
|
|
21
22
|
*/
|
|
22
|
-
export declare function
|
|
23
|
+
export declare function guard(instance: unknown): instance is RequiredType<AutoOpen>;
|
|
23
24
|
//# sourceMappingURL=AutoOpen.d.ts.map
|
package/api/AutoOpen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoOpen.d.ts","sourceRoot":"","sources":["../../src/api/AutoOpen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"AutoOpen.d.ts","sourceRoot":"","sources":["../../src/api/AutoOpen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAkB,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IAErB;;;OAGG;IACH,QAAQ,IAAI,SAAS,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAE3E"}
|
package/api/AutoOpen.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.guard = guard;
|
|
4
4
|
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
5
5
|
/**
|
|
6
6
|
* Duck-typing check for AutoOpen interface.
|
|
@@ -8,7 +8,7 @@ const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
|
8
8
|
* @param instance the instance to check
|
|
9
9
|
* @returns true if the instance implements AutoOpen, false otherwise
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
12
|
-
return (0, Types_1.
|
|
11
|
+
function guard(instance) {
|
|
12
|
+
return (0, Types_1.guardFunctions)(instance, 'autoOpen');
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=AutoOpen.js.map
|
package/api/AutoOpen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoOpen.js","sourceRoot":"","sources":["../../src/api/AutoOpen.ts"],"names":[],"mappings":";;AAyBA,
|
|
1
|
+
{"version":3,"file":"AutoOpen.js","sourceRoot":"","sources":["../../src/api/AutoOpen.ts"],"names":[],"mappings":";;AAyBA,sBAEC;AA1BD,6DAAiF;AAkBjF;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,QAAiB;IACnC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAChD,CAAC"}
|
package/api/BasicContract.d.ts
CHANGED
|
@@ -30,13 +30,18 @@ export declare class BasicContract<T> implements Contract<T> {
|
|
|
30
30
|
*
|
|
31
31
|
* @param value the value to cast
|
|
32
32
|
* @return the checked value. Note: null is possible. The Promisor is allowed to return null
|
|
33
|
-
* @throws
|
|
33
|
+
* @throws ContractException if the value can't be cast to the return type.
|
|
34
34
|
*/
|
|
35
35
|
cast(value: unknown | null | undefined): DeliveryType<T>;
|
|
36
36
|
/**
|
|
37
37
|
* @return the contract name
|
|
38
38
|
*/
|
|
39
39
|
get name(): string;
|
|
40
|
+
/**
|
|
41
|
+
* When guarded is true the Contract throws exception if deliverable is null or undefined
|
|
42
|
+
* The default is true.
|
|
43
|
+
*/
|
|
44
|
+
get guarded(): boolean;
|
|
40
45
|
/**
|
|
41
46
|
* Note: Do not rely on this being a java class name
|
|
42
47
|
* Note: The actual class is never exposed and is by design.
|
|
@@ -62,13 +67,14 @@ export declare class BasicContract<T> implements Contract<T> {
|
|
|
62
67
|
* @param config
|
|
63
68
|
*/
|
|
64
69
|
constructor(config?: Config<T> | null);
|
|
70
|
+
private throwCastException;
|
|
65
71
|
private static ID_GENERATOR;
|
|
66
72
|
private readonly _id;
|
|
67
73
|
private readonly _name;
|
|
68
74
|
private readonly _typeName;
|
|
69
75
|
private readonly _tester;
|
|
70
|
-
private readonly _caster;
|
|
71
76
|
private readonly _replaceable;
|
|
77
|
+
private readonly _guarded;
|
|
72
78
|
}
|
|
73
79
|
type DeliveryType<T> = OptionalType<T>;
|
|
74
80
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicContract.d.ts","sourceRoot":"","sources":["../../src/api/BasicContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"BasicContract.d.ts","sourceRoot":"","sources":["../../src/api/BasicContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAgB,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAG7F;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAE9E;AAED;;;;;;;GAOG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAElD;;;;;;QAMI;IACJ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC;IAIxD;;;;;;;MAOE;IACK,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC;IAc/D;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;OAGG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;;OAKG;IACH,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED;;;;;OAKG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;;;OAIG;IACI,QAAQ,IAAI,MAAM;IAYzB;;;OAGG;gBACgB,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;IAS5C,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,MAAM,CAAC,YAAY,CAAa;IAExC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwC;IAC5D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;CACpC;AAED,KAAK,YAAY,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC"}
|
package/api/BasicContract.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BasicContract = void 0;
|
|
4
4
|
exports.create = create;
|
|
5
|
-
const
|
|
5
|
+
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
6
|
+
const ContractException_1 = require("@jonloucks/contracts-ts/api/ContractException");
|
|
6
7
|
/**
|
|
7
8
|
* Create a basic Contract
|
|
8
9
|
*
|
|
@@ -37,14 +38,22 @@ class BasicContract {
|
|
|
37
38
|
*
|
|
38
39
|
* @param value the value to cast
|
|
39
40
|
* @return the checked value. Note: null is possible. The Promisor is allowed to return null
|
|
40
|
-
* @throws
|
|
41
|
+
* @throws ContractException if the value can't be cast to the return type.
|
|
41
42
|
*/
|
|
42
43
|
cast(value) {
|
|
44
|
+
if ((0, Types_1.isNotPresent)(value)) {
|
|
45
|
+
if (this._guarded) {
|
|
46
|
+
this.throwCastException();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
if (this._tester(value)) {
|
|
44
|
-
return
|
|
53
|
+
return value;
|
|
45
54
|
}
|
|
46
55
|
else {
|
|
47
|
-
|
|
56
|
+
this.throwCastException();
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
/**
|
|
@@ -53,6 +62,13 @@ class BasicContract {
|
|
|
53
62
|
get name() {
|
|
54
63
|
return this._name;
|
|
55
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* When guarded is true the Contract throws exception if deliverable is null or undefined
|
|
67
|
+
* The default is true.
|
|
68
|
+
*/
|
|
69
|
+
get guarded() {
|
|
70
|
+
return this._guarded;
|
|
71
|
+
}
|
|
56
72
|
/**
|
|
57
73
|
* Note: Do not rely on this being a java class name
|
|
58
74
|
* Note: The actual class is never exposed and is by design.
|
|
@@ -77,7 +93,15 @@ class BasicContract {
|
|
|
77
93
|
* @returns a string representation of the contract
|
|
78
94
|
*/
|
|
79
95
|
toString() {
|
|
80
|
-
|
|
96
|
+
let text = `Contract(id=${this._id}`;
|
|
97
|
+
if (this.name.length > 0) {
|
|
98
|
+
text += `, name=${this.name}`;
|
|
99
|
+
}
|
|
100
|
+
if (this.typeName.length > 0) {
|
|
101
|
+
text += `, type=${this.typeName}`;
|
|
102
|
+
}
|
|
103
|
+
text += `)`;
|
|
104
|
+
return text;
|
|
81
105
|
}
|
|
82
106
|
/**
|
|
83
107
|
*
|
|
@@ -87,10 +111,14 @@ class BasicContract {
|
|
|
87
111
|
this._id = BasicContract.ID_GENERATOR++;
|
|
88
112
|
const candidateConfig = config ?? {};
|
|
89
113
|
this._replaceable = candidateConfig?.replaceable ?? false;
|
|
114
|
+
this._guarded = candidateConfig?.guarded ?? true;
|
|
90
115
|
this._name = candidateConfig?.name ?? "";
|
|
91
116
|
this._typeName = candidateConfig?.typeName ?? "";
|
|
92
|
-
this._tester = candidateConfig?.test ?? ((
|
|
93
|
-
|
|
117
|
+
this._tester = candidateConfig?.test ?? ((_instance) => true);
|
|
118
|
+
}
|
|
119
|
+
throwCastException() {
|
|
120
|
+
// Note: message intentionally does not include the instance value
|
|
121
|
+
throw new ContractException_1.ContractException(`Casting error. Unable to cast '${this.toString()}'.`);
|
|
94
122
|
}
|
|
95
123
|
}
|
|
96
124
|
exports.BasicContract = BasicContract;
|
package/api/BasicContract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicContract.js","sourceRoot":"","sources":["../../src/api/BasicContract.ts"],"names":[],"mappings":";;;AAUA,wBAEC;
|
|
1
|
+
{"version":3,"file":"BasicContract.js","sourceRoot":"","sources":["../../src/api/BasicContract.ts"],"names":[],"mappings":";;;AAUA,wBAEC;AAXD,6DAA6F;AAC7F,qFAAkF;AAElF;;;;;GAKG;AACH,SAAgB,MAAM,CAAI,MAAyB;IACjD,OAAO,aAAa,CAAC,MAAM,CAAI,MAAM,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAa,aAAa;IAExB;;;;;;QAMI;IACJ,MAAM,CAAC,MAAM,CAAI,MAAyB;QACxC,OAAO,IAAI,aAAa,CAAI,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;MAOE;IACK,IAAI,CAAC,KAAiC;QAC3C,IAAI,IAAA,oBAAY,EAAC,KAAK,CAAC,EAAE,CAAC;YACxB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,OAAO,KAAwB,CAAC;YAClC,CAAC;QACH,CAAC;QAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,QAAQ;QACb,IAAI,IAAI,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,IAAI,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,IAAI,IAAI,UAAU,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,GAAG,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,YAAmB,MAAyB;QAgB3B,QAAG,GAAW,aAAa,CAAC,YAAY,EAAE,CAAC;QAf1D,MAAM,eAAe,GAAc,MAAM,IAAI,EAAE,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,eAAe,EAAE,WAAW,IAAI,KAAK,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,eAAe,EAAE,OAAO,IAAI,IAAI,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,eAAe,EAAE,QAAQ,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,eAAe,EAAE,IAAI,IAAI,CAAC,CAAC,SAAkB,EAAgC,EAAE,CAAC,IAAI,CAAC,CAAC;IACvG,CAAC;IAEO,kBAAkB;QACxB,kEAAkE;QAClE,MAAM,IAAI,qCAAiB,CAAC,kCAAkC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACrF,CAAC;;AAvGH,sCAiHC;AARgB,0BAAY,GAAW,CAAC,AAAZ,CAAa"}
|
package/api/BindStrategy.d.ts
CHANGED
|
@@ -41,5 +41,5 @@ export declare function resolveBindStrategy(bindStrategy: OptionalType<BindStrat
|
|
|
41
41
|
* @param instance the value to check
|
|
42
42
|
* @returns true if value is a BindStrategy or null/undefined
|
|
43
43
|
*/
|
|
44
|
-
export declare function
|
|
44
|
+
export declare function guard(instance: unknown): instance is OptionalType<BindStrategy>;
|
|
45
45
|
//# sourceMappingURL=BindStrategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindStrategy.d.ts","sourceRoot":"","sources":["../../src/api/BindStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY;AACpB;;EAEE;AACF,QAAQ;AACR;;EAEE;AACF,cAAc;AACd;;EAEE;AACF,YAAY,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,YAA2B,CAAA;AAE/D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,CAExG;AAED;;;;GAIG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"BindStrategy.d.ts","sourceRoot":"","sources":["../../src/api/BindStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY;AACpB;;EAEE;AACF,QAAQ;AACR;;EAEE;AACF,cAAc;AACd;;EAEE;AACF,YAAY,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,YAA2B,CAAA;AAE/D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,CAExG;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,YAAY,CAAC,CAW/E"}
|
package/api/BindStrategy.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_BIND_STRATEGY = void 0;
|
|
4
4
|
exports.resolveBindStrategy = resolveBindStrategy;
|
|
5
|
-
exports.
|
|
5
|
+
exports.guard = guard;
|
|
6
6
|
/**
|
|
7
7
|
* The default binding strategy
|
|
8
8
|
*/
|
|
@@ -21,7 +21,7 @@ function resolveBindStrategy(bindStrategy) {
|
|
|
21
21
|
* @param instance the value to check
|
|
22
22
|
* @returns true if value is a BindStrategy or null/undefined
|
|
23
23
|
*/
|
|
24
|
-
function
|
|
24
|
+
function guard(instance) {
|
|
25
25
|
switch (instance) {
|
|
26
26
|
case undefined:
|
|
27
27
|
case null:
|
package/api/BindStrategy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindStrategy.js","sourceRoot":"","sources":["../../src/api/BindStrategy.ts"],"names":[],"mappings":";;;AAyCA,kDAEC;AAOD,
|
|
1
|
+
{"version":3,"file":"BindStrategy.js","sourceRoot":"","sources":["../../src/api/BindStrategy.ts"],"names":[],"mappings":";;;AAyCA,kDAEC;AAOD,sBAWC;AApCD;;GAEG;AACU,QAAA,qBAAqB,GAAiB,YAAY,CAAA;AAO/D;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,YAAwC;IACxE,OAAO,YAAY,IAAI,6BAAqB,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,QAAiB;IACnC,QAAQ,QAAQ,EAAE,CAAC;QACf,KAAK,SAAS,CAAC;QACf,KAAK,IAAI,CAAC;QACV,KAAK,QAAQ,CAAC;QACd,KAAK,cAAc,CAAC;QACpB,KAAK,YAAY;YACb,OAAO,IAAI,CAAC;QAChB;YACI,OAAO,KAAK,CAAC;IACrB,CAAC;AACL,CAAC"}
|
package/api/Contract.d.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import { OptionalType } from "@jonloucks/contracts-ts/api/Types";
|
|
1
|
+
import { OptionalType, RequiredType } from "@jonloucks/contracts-ts/api/Types";
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for a Contract
|
|
4
4
|
*
|
|
5
5
|
* @param <T> The Contract deliverable type
|
|
6
6
|
*/
|
|
7
7
|
export interface Config<T> {
|
|
8
|
-
/**
|
|
9
|
-
* Ensure an instance is of type T (or descendant)
|
|
10
|
-
*
|
|
11
|
-
* @param instance the value to cast to type T
|
|
12
|
-
* @return the value, null is allowed
|
|
13
|
-
* @throws ClassCastException when type of instance is not correct
|
|
14
|
-
*/
|
|
15
|
-
cast?: (instance: unknown) => OptionalType<T>;
|
|
16
8
|
/**
|
|
17
9
|
* the predefine test to check if instance is of type T
|
|
18
10
|
* @param instance the instance to check
|
|
19
|
-
* @returns
|
|
11
|
+
* @returns true if the instance is of type T, false otherwise
|
|
20
12
|
*/
|
|
21
|
-
test?: (instance: unknown) => instance is
|
|
13
|
+
test?: (instance: unknown) => instance is RequiredType<T>;
|
|
22
14
|
/**
|
|
23
15
|
* User defined name for this contract.
|
|
24
16
|
* Note: Do not rely on this being a java class name
|
|
@@ -45,6 +37,11 @@ export interface Config<T> {
|
|
|
45
37
|
* and must comply with RatifiedContract rules.
|
|
46
38
|
*/
|
|
47
39
|
ratified?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* When guarded is true the Contract throws exception if deliverable is null or undefined
|
|
42
|
+
* The default is true.
|
|
43
|
+
*/
|
|
44
|
+
guarded?: boolean;
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
50
47
|
* A Contract defines a deliverable type by name and type.
|
|
@@ -58,7 +55,7 @@ export interface Contract<T> {
|
|
|
58
55
|
*
|
|
59
56
|
* @param value the value to cast
|
|
60
57
|
* @return the checked value. Note: null is possible. The Promisor is allowed to return null
|
|
61
|
-
* @throws
|
|
58
|
+
* @throws ContractException if the value can't be cast to the return type.
|
|
62
59
|
*/
|
|
63
60
|
cast(value: OptionalType<unknown>): OptionalType<T>;
|
|
64
61
|
/**
|
|
@@ -79,5 +76,17 @@ export interface Contract<T> {
|
|
|
79
76
|
* @return true if replaceable
|
|
80
77
|
*/
|
|
81
78
|
get replaceable(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* When guarded is true the Contract throws exception if deliverable is null or undefined
|
|
81
|
+
* The default is true.
|
|
82
|
+
*/
|
|
83
|
+
get guarded(): boolean;
|
|
82
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Duck-typing check for Contract interface.
|
|
87
|
+
*
|
|
88
|
+
* @param instance the instance to check
|
|
89
|
+
* @returns true if the instance implements Contract, false otherwise
|
|
90
|
+
*/
|
|
91
|
+
export declare function guard<T>(instance: unknown): instance is RequiredType<Contract<T>>;
|
|
83
92
|
//# sourceMappingURL=Contract.d.ts.map
|
package/api/Contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.d.ts","sourceRoot":"","sources":["../../src/api/Contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"Contract.d.ts","sourceRoot":"","sources":["../../src/api/Contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/F;;;;GAIG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC;IAEvB;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAE1D;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC;IAEzB;;;;;;;MAOE;IACF,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAEpD;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,IAAI,WAAW,IAAI,OAAO,CAAC;IAE3B;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjF"}
|
package/api/Contract.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.guard = guard;
|
|
4
|
+
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
5
|
+
/**
|
|
6
|
+
* Duck-typing check for Contract interface.
|
|
7
|
+
*
|
|
8
|
+
* @param instance the instance to check
|
|
9
|
+
* @returns true if the instance implements Contract, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
function guard(instance) {
|
|
12
|
+
return (0, Types_1.guardFunctions)(instance, 'cast', 'name', 'typeName', 'replaceable');
|
|
13
|
+
}
|
|
3
14
|
//# sourceMappingURL=Contract.js.map
|
package/api/Contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../../src/api/Contract.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../../src/api/Contract.ts"],"names":[],"mappings":";;AAwGA,sBAEC;AA1GD,6DAA+F;AAkG/F;;;;;GAKG;AACH,SAAgB,KAAK,CAAI,QAAiB;IACxC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -17,4 +17,11 @@ export declare class ContractException extends Error {
|
|
|
17
17
|
*/
|
|
18
18
|
static rethrow(caught: unknown, message?: string): never;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard for ContractException
|
|
22
|
+
*
|
|
23
|
+
* @param value the value to check
|
|
24
|
+
* @return true if value is ContractException, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
export declare function guard(value: unknown): value is ContractException;
|
|
20
27
|
//# sourceMappingURL=ContractException.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractException.d.ts","sourceRoot":"","sources":["../../src/api/ContractException.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAE1C;;;;;OAKG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,GAAG,IAAW;IAQhE;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK;CASzD"}
|
|
1
|
+
{"version":3,"file":"ContractException.d.ts","sourceRoot":"","sources":["../../src/api/ContractException.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAE1C;;;;;OAKG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,GAAG,IAAW;IAQhE;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK;CASzD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAEhE"}
|
package/api/ContractException.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContractException = void 0;
|
|
4
|
+
exports.guard = guard;
|
|
4
5
|
const Checks_1 = require("@jonloucks/contracts-ts/auxiliary/Checks");
|
|
5
6
|
/**
|
|
6
7
|
* Runtime exception thrown for Contract related problems.
|
|
@@ -25,7 +26,7 @@ class ContractException extends Error {
|
|
|
25
26
|
* @param message the optional message to use if caught is not an ContractException
|
|
26
27
|
*/
|
|
27
28
|
static rethrow(caught, message) {
|
|
28
|
-
if (caught
|
|
29
|
+
if (guard(caught)) {
|
|
29
30
|
throw caught;
|
|
30
31
|
}
|
|
31
32
|
else if (caught instanceof Error) {
|
|
@@ -37,4 +38,13 @@ class ContractException extends Error {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
exports.ContractException = ContractException;
|
|
41
|
+
/**
|
|
42
|
+
* Type guard for ContractException
|
|
43
|
+
*
|
|
44
|
+
* @param value the value to check
|
|
45
|
+
* @return true if value is ContractException, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
function guard(value) {
|
|
48
|
+
return value instanceof ContractException;
|
|
49
|
+
}
|
|
40
50
|
//# sourceMappingURL=ContractException.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractException.js","sourceRoot":"","sources":["../../src/api/ContractException.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ContractException.js","sourceRoot":"","sources":["../../src/api/ContractException.ts"],"names":[],"mappings":";;;AA4CA,sBAEC;AA9CD,qEAAwE;AAExE;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAE1C;;;;;OAKG;IACH,YAAmB,OAAe,EAAE,UAAwB,IAAI;QAC9D,qDAAqD;QACrD,KAAK,CAAC,IAAA,qBAAY,EAAC,OAAO,CAAC,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;IAC1D,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,MAAe,EAAE,OAAgB;QAC9C,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClB,MAAM,MAAM,CAAC;QACf,CAAC;aAAM,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;YACnC,MAAM,IAAI,iBAAiB,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,iBAAiB,CAAC,OAAO,IAAI,+BAA+B,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;CACF;AA9BD,8CA8BC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,iBAAiB,CAAC;AAC5C,CAAC"}
|
package/api/ContractFactory.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ export interface ContractFactory {
|
|
|
13
13
|
* @param config the Contract configuration
|
|
14
14
|
* @return the new Contract
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
createContract<T>(config?: OptionalType<Config<T>>): RequiredType<Contract<T>>;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Type guard for ContractFactory
|
|
20
|
+
*
|
|
21
|
+
* @param value the value to check
|
|
22
|
+
* @return true if value is ContractFactory, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare function guard(value: unknown): value is RequiredType<ContractFactory>;
|
|
18
25
|
//# sourceMappingURL=ContractFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractFactory.d.ts","sourceRoot":"","sources":["../../src/api/ContractFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"ContractFactory.d.ts","sourceRoot":"","sources":["../../src/api/ContractFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAkB,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/F;;;GAGG;AACH,MAAM,WAAW,eAAe;IAE9B;;;;;;;OAOG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;CAChF;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,eAAe,CAAC,CAE5E"}
|
package/api/ContractFactory.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.guard = guard;
|
|
4
|
+
const Types_1 = require("@jonloucks/contracts-ts/api/Types");
|
|
5
|
+
/**
|
|
6
|
+
* Type guard for ContractFactory
|
|
7
|
+
*
|
|
8
|
+
* @param value the value to check
|
|
9
|
+
* @return true if value is ContractFactory, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
function guard(value) {
|
|
12
|
+
return (0, Types_1.guardFunctions)(value, 'createContract');
|
|
13
|
+
}
|
|
3
14
|
//# sourceMappingURL=ContractFactory.js.map
|