@jonloucks/contracts-ts 1.0.0 → 1.0.2

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.
@@ -0,0 +1,87 @@
1
+ import { AutoClose, Contract, OptionalType, RequiredType } from "@jonloucks/contracts-ts";
2
+ import { PromisorType } from "@jonloucks/contracts-ts/api/Promisor";
3
+ import { BindStrategyType } from "@jonloucks/contracts-ts/api/BindStrategy";
4
+ import { Promisor } from "@jonloucks/contracts-ts/api/Promisor";
5
+ import { TransformType } from "@jonloucks/contracts-ts/api/Types";
6
+ /**
7
+ * @module Convenience
8
+ * @description
9
+ *
10
+ * This module provides convenience functions for creating types
11
+ * using the shared global CONTRACTS instance. For performance-sensitive
12
+ * applications, consider using factory instances directly to avoid the
13
+ * overhead of enforcing the factory contract on each creation.
14
+ *
15
+ * Internal Note: To avoid circular dependencies, other modules should not
16
+ * import from this module. Instead, they should import directly from the
17
+ * source modules of the types.
18
+ */
19
+ /**
20
+ * Claim a deliverable from a Contract via the shared global CONTRACTS instance.
21
+ *
22
+ * @param contract the Contract to claim from
23
+ * @returns the deliverable
24
+ */
25
+ export declare function claim<T>(contract: RequiredType<Contract<T>>): OptionalType<T>;
26
+ /**
27
+ * Enforce a deliverable from a Contract via the shared global CONTRACTS instance.
28
+ *
29
+ * @param contract the Contract to enforce from
30
+ * @returns the deliverable
31
+ */
32
+ export declare function enforce<T>(contract: RequiredType<Contract<T>>): RequiredType<T>;
33
+ /**
34
+ * Bind a Promisor to a Contract via the shared global CONTRACTS instance.
35
+ *
36
+ * @param contract the Contract to bind to
37
+ * @param promisor the PromisorType to bind
38
+ * @param bindStrategy optional BindStrategyType
39
+ * @returns an AutoClose to manage the binding lifecycle
40
+ */
41
+ export declare function bind<T>(contract: RequiredType<Contract<T>>, promisor: PromisorType<T>, bindStrategy?: BindStrategyType): RequiredType<AutoClose>;
42
+ /**
43
+ * Check if a Contract is bound via the shared global CONTRACTS instance.
44
+ *
45
+ * @param contract the Contract to check
46
+ * @returns true if the Contract is bound, false otherwise
47
+ */
48
+ export declare function isBound<T>(contract: RequiredType<Contract<T>>): boolean;
49
+ /**
50
+ * Creates a Promisor that returns the given value every time it is claimed.
51
+ *
52
+ * @param deliverable the value to return from the Promisor
53
+ * @return The new Promisor
54
+ * @param <T> the type of deliverable
55
+ */
56
+ export declare function createValue<T>(deliverable: OptionalType<T>): RequiredType<Promisor<T>>;
57
+ /**
58
+ * Creates a Promisor that only calls the source Promisor once and then always
59
+ * returns that value.
60
+ * Note: increment and decrementUsage are relayed to the source promisor.
61
+ *
62
+ * @param promisor the source Promisor
63
+ * @return The new Promisor
64
+ * @param <T> the type of deliverable
65
+ */
66
+ export declare function createSingleton<T>(promisor: PromisorType<T>): RequiredType<Promisor<T>>;
67
+ /**
68
+ * Reference counted, lazy loaded, with opt-in 'open' and 'close' invoked on deliverable.
69
+ * Note: increment and decrementUsage are relayed to the source promisor.
70
+ *
71
+ * @param promisor the source promisor
72
+ * @return the new Promisor
73
+ * @param <T> the type of deliverable
74
+ */
75
+ export declare function createLifeCycle<T>(promisor: PromisorType<T>): RequiredType<Promisor<T>>;
76
+ /**
77
+ * Extract values from the deliverable of a source Promisor.
78
+ * Note: increment and decrementUsage are relayed to the source promisor.
79
+ *
80
+ * @param promisor the source promisor
81
+ * @param extractor the function that gets an object from the deliverable. For example Person => Age
82
+ * @return the new Promisor
83
+ * @param <T> the type of deliverable
84
+ * @param <R> the new Promisor deliverable type
85
+ */
86
+ export declare function createExtractor<T, R>(promisor: PromisorType<T>, extractor: TransformType<T, R>): RequiredType<Promisor<R>>;
87
+ //# sourceMappingURL=Convenience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Convenience.d.ts","sourceRoot":"","sources":["../../src/api/Convenience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAa,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrG,OAAO,EAAE,YAAY,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AC,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEvF;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAE1H"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claim = claim;
4
+ exports.enforce = enforce;
5
+ exports.bind = bind;
6
+ exports.isBound = isBound;
7
+ exports.createValue = createValue;
8
+ exports.createSingleton = createSingleton;
9
+ exports.createLifeCycle = createLifeCycle;
10
+ exports.createExtractor = createExtractor;
11
+ const contracts_ts_1 = require("@jonloucks/contracts-ts");
12
+ const PromisorFactory_1 = require("@jonloucks/contracts-ts/api/PromisorFactory");
13
+ /**
14
+ * @module Convenience
15
+ * @description
16
+ *
17
+ * This module provides convenience functions for creating types
18
+ * using the shared global CONTRACTS instance. For performance-sensitive
19
+ * applications, consider using factory instances directly to avoid the
20
+ * overhead of enforcing the factory contract on each creation.
21
+ *
22
+ * Internal Note: To avoid circular dependencies, other modules should not
23
+ * import from this module. Instead, they should import directly from the
24
+ * source modules of the types.
25
+ */
26
+ /**
27
+ * Claim a deliverable from a Contract via the shared global CONTRACTS instance.
28
+ *
29
+ * @param contract the Contract to claim from
30
+ * @returns the deliverable
31
+ */
32
+ function claim(contract) {
33
+ return contracts_ts_1.CONTRACTS.claim(contract);
34
+ }
35
+ /**
36
+ * Enforce a deliverable from a Contract via the shared global CONTRACTS instance.
37
+ *
38
+ * @param contract the Contract to enforce from
39
+ * @returns the deliverable
40
+ */
41
+ function enforce(contract) {
42
+ return contracts_ts_1.CONTRACTS.enforce(contract);
43
+ }
44
+ /**
45
+ * Bind a Promisor to a Contract via the shared global CONTRACTS instance.
46
+ *
47
+ * @param contract the Contract to bind to
48
+ * @param promisor the PromisorType to bind
49
+ * @param bindStrategy optional BindStrategyType
50
+ * @returns an AutoClose to manage the binding lifecycle
51
+ */
52
+ function bind(contract, promisor, bindStrategy) {
53
+ return contracts_ts_1.CONTRACTS.bind(contract, promisor, bindStrategy);
54
+ }
55
+ /**
56
+ * Check if a Contract is bound via the shared global CONTRACTS instance.
57
+ *
58
+ * @param contract the Contract to check
59
+ * @returns true if the Contract is bound, false otherwise
60
+ */
61
+ function isBound(contract) {
62
+ return contracts_ts_1.CONTRACTS.isBound(contract);
63
+ }
64
+ /**
65
+ * Creates a Promisor that returns the given value every time it is claimed.
66
+ *
67
+ * @param deliverable the value to return from the Promisor
68
+ * @return The new Promisor
69
+ * @param <T> the type of deliverable
70
+ */
71
+ function createValue(deliverable) {
72
+ return enforce(PromisorFactory_1.CONTRACT).createValue(deliverable);
73
+ }
74
+ /**
75
+ * Creates a Promisor that only calls the source Promisor once and then always
76
+ * returns that value.
77
+ * Note: increment and decrementUsage are relayed to the source promisor.
78
+ *
79
+ * @param promisor the source Promisor
80
+ * @return The new Promisor
81
+ * @param <T> the type of deliverable
82
+ */
83
+ function createSingleton(promisor) {
84
+ return enforce(PromisorFactory_1.CONTRACT).createSingleton(promisor);
85
+ }
86
+ /**
87
+ * Reference counted, lazy loaded, with opt-in 'open' and 'close' invoked on deliverable.
88
+ * Note: increment and decrementUsage are relayed to the source promisor.
89
+ *
90
+ * @param promisor the source promisor
91
+ * @return the new Promisor
92
+ * @param <T> the type of deliverable
93
+ */
94
+ function createLifeCycle(promisor) {
95
+ return enforce(PromisorFactory_1.CONTRACT).createLifeCycle(promisor);
96
+ }
97
+ /**
98
+ * Extract values from the deliverable of a source Promisor.
99
+ * Note: increment and decrementUsage are relayed to the source promisor.
100
+ *
101
+ * @param promisor the source promisor
102
+ * @param extractor the function that gets an object from the deliverable. For example Person => Age
103
+ * @return the new Promisor
104
+ * @param <T> the type of deliverable
105
+ * @param <R> the new Promisor deliverable type
106
+ */
107
+ function createExtractor(promisor, extractor) {
108
+ return enforce(PromisorFactory_1.CONTRACT).createExtractor(promisor, extractor);
109
+ }
110
+ //# sourceMappingURL=Convenience.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Convenience.js","sourceRoot":"","sources":["../../src/api/Convenience.ts"],"names":[],"mappings":";;AA2BA,sBAEC;AAQD,0BAEC;AAUD,oBAEC;AAQD,0BAEC;AASD,kCAEC;AAWD,0CAEC;AAUD,0CAEC;AAYD,0CAEC;AA/GD,0DAAqG;AAGrG,iFAA2F;AAI3F;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,SAAgB,KAAK,CAAI,QAAmC;IAC1D,OAAO,wBAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAI,QAAmC;IAC5D,OAAO,wBAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,IAAI,CAAI,QAAmC,EAAE,QAAyB,EAAE,YAA+B;IACrH,OAAO,wBAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAI,QAAmC;IAC5D,OAAO,wBAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAI,WAA4B;IACzD,OAAO,OAAO,CAAC,0BAAgB,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAI,QAAyB;IAC1D,OAAO,OAAO,CAAC,0BAAgB,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAI,QAAyB;IAC1D,OAAO,OAAO,CAAC,0BAAgB,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,eAAe,CAAO,QAAyB,EAAE,SAA8B;IAC7F,OAAO,OAAO,CAAC,0BAAgB,CAAC,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACxE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Contract } from "@jonloucks/contracts-ts/api/Contract";
2
2
  import { Promisor, PromisorType } from "@jonloucks/contracts-ts/api/Promisor";
3
- import { OptionalType, RequiredType, Transform } from "@jonloucks/contracts-ts/api/Types";
3
+ import { OptionalType, RequiredType, TransformType } from "@jonloucks/contracts-ts/api/Types";
4
4
  /**
5
5
  * Helper methods for creating and chaining Promisors used for {@link Contractss#bind(Contract, Promisor)}
6
6
  */
@@ -33,7 +33,7 @@ export interface PromisorFactory {
33
33
  */
34
34
  createLifeCycle<T>(promisor: PromisorType<T>): RequiredType<Promisor<T>>;
35
35
  /**
36
- * Extract
36
+ * Extract values from the deliverable of a source Promisor.
37
37
  * Note: increment and decrementUsage are relayed to the source promisor.
38
38
  *
39
39
  * @param promisor the source promisor
@@ -42,7 +42,7 @@ export interface PromisorFactory {
42
42
  * @param <T> the type of deliverable
43
43
  * @param <R> the new Promisor deliverable type
44
44
  */
45
- createExtractor<T, R>(promisor: PromisorType<T>, extractor: Transform<T, R>): RequiredType<Promisor<R>>;
45
+ createExtractor<T, R>(promisor: PromisorType<T>, extractor: TransformType<T, R>): RequiredType<Promisor<R>>;
46
46
  }
47
47
  /**
48
48
  * Type guard for PromisorFactory
@@ -1 +1 @@
1
- {"version":3,"file":"PromisorFactory.d.ts","sourceRoot":"","sources":["../../src/api/PromisorFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sCAAs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,EAAE,KAAK;IACX,IAAI,EAAE,iBAAiB;IACvB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC"}
1
+ {"version":3,"file":"PromisorFactory.js","sourceRoot":"","sources":["../../src/api/PromisorFactory.ts"],"names":[],"mappings":";;;AA2DA,sBAEC;AA3DD,mFAAwF;AACxF,6DAA8G;AAkD9G;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,QAAiB;IACrC,OAAO,IAAA,sBAAc,EAAC,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAC1G,CAAC;AAED;;GAEG;AACU,QAAA,QAAQ,GAA8B,IAAA,yBAAc,EAAC;IAChE,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,iBAAiB;IACvB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC"}
package/api/Types.d.ts CHANGED
@@ -17,8 +17,16 @@ export type UnknownFunction = (...args: unknown[]) => unknown;
17
17
  * A transformation from type I to type O
18
18
  */
19
19
  export interface Transform<I, O> {
20
- transform(I: OptionalType<I>): OptionalType<O>;
20
+ transform(input: I): O;
21
21
  }
22
+ /**
23
+ * A function that transforms type I to type O
24
+ */
25
+ export type TransformFunction<I, O> = (input: I) => O;
26
+ /**
27
+ * A transformation type that can be a Transform or a function from type I to type O
28
+ */
29
+ export type TransformType<I, O> = Transform<I, O> | TransformFunction<I, O>;
22
30
  /**
23
31
  * Check iif given value is not null or undefined
24
32
  *
@@ -39,6 +47,14 @@ export declare function isNotPresent(value: unknown): value is null | undefined;
39
47
  * @returns true if value is a function and is not null or undefined
40
48
  */
41
49
  export declare function isFunction<T extends UnknownFunction>(value: unknown): value is RequiredType<T>;
50
+ /**
51
+ * Check if given value is a function with the given arity
52
+ *
53
+ * @param value the value to check
54
+ * @param arity the arity to check
55
+ * @returns true if value is a function with the given arity
56
+ */
57
+ export declare function isFunctionWithArity<T extends UnknownFunction>(value: unknown, arity: number): value is RequiredType<T>;
42
58
  /**
43
59
  * Check if given value is an object and is not null or undefined
44
60
  * @param value the value to check
@@ -91,4 +107,11 @@ export declare function isConstructor<T>(value: unknown): value is RequiredType<
91
107
  * @returns true if property is defined
92
108
  */
93
109
  export declare function guardFunctions(value: unknown, ...propertyNames: (string | symbol)[]): value is RequiredType<UnknownFunction>;
110
+ /**
111
+ * Convert a TransformType to a Transform
112
+ *
113
+ * @param transform the TransformType to convert
114
+ * @returns the Transform
115
+ */
116
+ export declare function typeToTransform<I, O>(transform: TransformType<I, O>): RequiredType<Transform<I, O>>;
94
117
  //# sourceMappingURL=Types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/api/Types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC7B,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,SAAS,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAA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ED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,MAAM,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,MAAM,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,OAAO,CAAC,CAExE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,MAAM,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAErF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,YAAY,CAAC,eAAe,CAAC,CAW5H;AAUD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CASnG"}
package/api/Types.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isPresent = isPresent;
7
7
  exports.isNotPresent = isNotPresent;
8
8
  exports.isFunction = isFunction;
9
+ exports.isFunctionWithArity = isFunctionWithArity;
9
10
  exports.isObject = isObject;
10
11
  exports.isString = isString;
11
12
  exports.isNumber = isNumber;
@@ -14,6 +15,9 @@ exports.isBoolean = isBoolean;
14
15
  exports.isBigInt = isBigInt;
15
16
  exports.isConstructor = isConstructor;
16
17
  exports.guardFunctions = guardFunctions;
18
+ exports.typeToTransform = typeToTransform;
19
+ const Checks_1 = require("@jonloucks/contracts-ts/auxiliary/Checks");
20
+ const IllegalArgumentException_1 = require("@jonloucks/contracts-ts/auxiliary/IllegalArgumentException");
17
21
  /**
18
22
  * Check iif given value is not null or undefined
19
23
  *
@@ -40,6 +44,16 @@ function isNotPresent(value) {
40
44
  function isFunction(value) {
41
45
  return isPresent(value) && typeof value === "function";
42
46
  }
47
+ /**
48
+ * Check if given value is a function with the given arity
49
+ *
50
+ * @param value the value to check
51
+ * @param arity the arity to check
52
+ * @returns true if value is a function with the given arity
53
+ */
54
+ function isFunctionWithArity(value, arity) {
55
+ return isFunction(value) && value.length === arity;
56
+ }
43
57
  /**
44
58
  * Check if given value is an object and is not null or undefined
45
59
  * @param value the value to check
@@ -117,4 +131,28 @@ function guardFunctions(value, ...propertyNames) {
117
131
  }
118
132
  return true;
119
133
  }
134
+ function guardTransform(transform) {
135
+ return guardFunctions(transform, 'transform');
136
+ }
137
+ function guardTransformFunction(transform) {
138
+ return isFunctionWithArity(transform, 1);
139
+ }
140
+ /**
141
+ * Convert a TransformType to a Transform
142
+ *
143
+ * @param transform the TransformType to convert
144
+ * @returns the Transform
145
+ */
146
+ function typeToTransform(transform) {
147
+ const validTransformType = (0, Checks_1.presentCheck)(transform, "TransformType must be present.");
148
+ if (guardTransform(validTransformType)) {
149
+ return validTransformType;
150
+ }
151
+ else if (guardTransformFunction(validTransformType)) {
152
+ return { transform: validTransformType };
153
+ }
154
+ else {
155
+ throw new IllegalArgumentException_1.IllegalArgumentException("TransformType must be a Transform or a function taking one argument.");
156
+ }
157
+ }
120
158
  //# sourceMappingURL=Types.js.map
package/api/Types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Types.js","sourceRoot":"","sources":["../../src/api/Types.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA8BH,8BAEC;AAQD,oCAEC;AAOD,gCAEC;AAOD,4BAEC;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M,GAAG,KAAyC,CAAC;IACzD,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAO,SAAkB;IAC9C,OAAO,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,sBAAsB,CAAO,SAAkB;IACtD,OAAO,mBAAmB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAO,SAA8B;IAClE,MAAM,kBAAkB,GAAG,IAAA,qBAAY,EAAC,SAAS,EAAE,gCAAgC,CAAC,CAAC;IACrF,IAAI,cAAc,CAAO,kBAAkB,CAAC,EAAE,CAAC;QAC7C,OAAO,kBAAkB,CAAC;IAC5B,CAAC;SAAM,IAAI,sBAAsB,CAAO,kBAAkB,CAAC,EAAE,CAAC;QAC5D,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,mDAAwB,CAAC,sEAAsE,CAAC,CAAC;IAC7G,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
2
+ import { AtomicBoolean } from "@jonloucks/contracts-ts/auxiliary/AtomicBoolean";
3
+ import { AtomicReference } from "@jonloucks/contracts-ts/auxiliary/AtomicReference";
4
+ import { AtomicInteger } from "@jonloucks/contracts-ts/auxiliary/AtomicInteger";
5
+ export { AtomicBoolean } from "@jonloucks/contracts-ts/auxiliary/AtomicBoolean";
6
+ export { AtomicReference } from "@jonloucks/contracts-ts/auxiliary/AtomicReference";
7
+ export { AtomicInteger } from "@jonloucks/contracts-ts/auxiliary/AtomicInteger";
8
+ /**
9
+ * @module Convenience
10
+ * @description
11
+ *
12
+ * This module provides convenience functions for creating auxiliary types
13
+ * using the shared global CONTRACTS instance. For performance-sensitive
14
+ * applications, consider using factory instances directly to avoid the
15
+ * overhead of enforcing the factory contract on each creation.
16
+ *
17
+ * Internal Note: To avoid circular dependencies, other modules should not
18
+ * import from this module. Instead, they should import directly from the
19
+ * source modules of the auxiliary types.
20
+ */
21
+ /**
22
+ * Create an AtomicBoolean via the shared global CONTRACTS instance.
23
+ *
24
+ * @param initialValue the initial boolean value
25
+ * @returns the AtomicBoolean instance
26
+ */
27
+ export declare function createAtomicBoolean(initialValue: boolean): RequiredType<AtomicBoolean>;
28
+ /**
29
+ * Create an AtomicReference via the shared global CONTRACTS instance.
30
+ *
31
+ * @param initialValue the initial reference value
32
+ * @returns the AtomicReference instance
33
+ */
34
+ export declare function createAtomicReference<T>(initialValue: T): RequiredType<AtomicReference<T>>;
35
+ /**
36
+ * Create an AtomicInteger via the shared global CONTRACTS instance.
37
+ *
38
+ * @param initialValue the initial integer value
39
+ * @returns the AtomicInteger instance
40
+ */
41
+ export declare function createAtomicInteger(initialValue: number): RequiredType<AtomicInteger>;
42
+ //# sourceMappingURL=Convenience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Convenience.d.ts","sourceRoot":"","sources":["../../src/auxiliary/Convenience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAKjE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,CAEtF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAE1F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAErF"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAtomicBoolean = createAtomicBoolean;
4
+ exports.createAtomicReference = createAtomicReference;
5
+ exports.createAtomicInteger = createAtomicInteger;
6
+ const contracts_ts_1 = require("@jonloucks/contracts-ts");
7
+ const AtomicBooleanFactory_1 = require("@jonloucks/contracts-ts/auxiliary/AtomicBooleanFactory");
8
+ const AtomicReferenceFactory_1 = require("@jonloucks/contracts-ts/auxiliary/AtomicReferenceFactory");
9
+ const AtomicIntegerFactory_1 = require("@jonloucks/contracts-ts/auxiliary/AtomicIntegerFactory");
10
+ /**
11
+ * @module Convenience
12
+ * @description
13
+ *
14
+ * This module provides convenience functions for creating auxiliary types
15
+ * using the shared global CONTRACTS instance. For performance-sensitive
16
+ * applications, consider using factory instances directly to avoid the
17
+ * overhead of enforcing the factory contract on each creation.
18
+ *
19
+ * Internal Note: To avoid circular dependencies, other modules should not
20
+ * import from this module. Instead, they should import directly from the
21
+ * source modules of the auxiliary types.
22
+ */
23
+ /**
24
+ * Create an AtomicBoolean via the shared global CONTRACTS instance.
25
+ *
26
+ * @param initialValue the initial boolean value
27
+ * @returns the AtomicBoolean instance
28
+ */
29
+ function createAtomicBoolean(initialValue) {
30
+ return contracts_ts_1.CONTRACTS.enforce(AtomicBooleanFactory_1.CONTRACT).createAtomicBoolean(initialValue);
31
+ }
32
+ /**
33
+ * Create an AtomicReference via the shared global CONTRACTS instance.
34
+ *
35
+ * @param initialValue the initial reference value
36
+ * @returns the AtomicReference instance
37
+ */
38
+ function createAtomicReference(initialValue) {
39
+ return contracts_ts_1.CONTRACTS.enforce(AtomicReferenceFactory_1.CONTRACT).createAtomicReference(initialValue);
40
+ }
41
+ /**
42
+ * Create an AtomicInteger via the shared global CONTRACTS instance.
43
+ *
44
+ * @param initialValue the initial integer value
45
+ * @returns the AtomicInteger instance
46
+ */
47
+ function createAtomicInteger(initialValue) {
48
+ return contracts_ts_1.CONTRACTS.enforce(AtomicIntegerFactory_1.CONTRACT).createAtomicInteger(initialValue);
49
+ }
50
+ //# sourceMappingURL=Convenience.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Convenience.js","sourceRoot":"","sources":["../../src/auxiliary/Convenience.ts"],"names":[],"mappings":";;AAiCA,kDAEC;AAQD,sDAEC;AAQD,kDAEC;AAtDD,0DAAoD;AACpD,iGAAqG;AACrG,qGAAyG;AACzG,iGAAqG;AASrG;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,YAAqB;IACvD,OAAO,wBAAS,CAAC,OAAO,CAAC,+BAAe,CAAC,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAI,YAAe;IACtD,OAAO,wBAAS,CAAC,OAAO,CAAC,iCAAiB,CAAC,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAClF,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,YAAoB;IACtD,OAAO,wBAAS,CAAC,OAAO,CAAC,+BAAe,CAAC,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC9E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExtractorPromisor.impl.d.ts","sourceRoot":"","sources":["../../src/impl/ExtractorPromisor.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAgB,YAAY,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE1F;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEzG"}
1
+ {"version":3,"file":"ExtractorPromisor.impl.d.ts","sourceRoot":"","sources":["../../src/impl/ExtractorPromisor.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAA8B,YAAY,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAExG;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEzG"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
4
  const Checks_1 = require("@jonloucks/contracts-ts/auxiliary/Checks");
5
+ const Types_1 = require("@jonloucks/contracts-ts/api/Types");
5
6
  /**
6
7
  * Factory method to create an ExtractPromisorImpl which is extraction promisor
7
8
  *
@@ -25,7 +26,13 @@ class ExtractorPromisorImpl {
25
26
  * Promisor.demand override.
26
27
  */
27
28
  demand() {
28
- return this.transform.transform(this.referent.demand());
29
+ const referentValue = this.referent.demand();
30
+ if ((0, Types_1.isNotPresent)(referentValue)) {
31
+ return referentValue;
32
+ }
33
+ else {
34
+ return this.transform.transform(referentValue);
35
+ }
29
36
  }
30
37
  /**
31
38
  * Promisor.incrementUsage override.
@@ -1 +1 @@
1
- {"version":3,"file":"ExtractorPromisor.impl.js","sourceRoot":"","sources":["../../src/impl/ExtractorPromisor.impl.ts"],"names":[],"mappings":";;AAaA,wBAEC;AAfD,qEAAuF;AAIvF;;;;;;;;GAQG;AACH,SAAgB,MAAM,CAAO,QAAqB,EAAE,SAA0B;IAC5E,OAAO,qBAAqB,CAAC,cAAc,CAAO,QAAQ,EAAE,SAAS,CAAC,CAAC;AACzE,CAAC;AAED,yCAAyC;AAEzC;;;;GAIG;AACH,MAAM,qBAAqB;IAEzB;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,cAAc,CAAO,QAAqB,EAAE,SAA0B;QAC3E,OAAO,IAAI,qBAAqB,CAAO,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,YAAoB,QAAqB,EAAE,SAA0B;QACnE,IAAI,CAAC,QAAQ,GAAG,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAA,qBAAY,EAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;IACzE,CAAC;CAIF"}
1
+ {"version":3,"file":"ExtractorPromisor.impl.js","sourceRoot":"","sources":["../../src/impl/ExtractorPromisor.impl.ts"],"names":[],"mappings":";;AAaA,wBAEC;AAfD,qEAAuF;AAEvF,6DAAwG;AAExG;;;;;;;;GAQG;AACH,SAAgB,MAAM,CAAO,QAAqB,EAAE,SAA0B;IAC5E,OAAO,qBAAqB,CAAC,cAAc,CAAO,QAAQ,EAAE,SAAS,CAAC,CAAC;AACzE,CAAC;AAED,yCAAyC;AAEzC;;;;GAIG;AACH,MAAM,qBAAqB;IAEzB;;OAEG;IACH,MAAM;QACJ,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC7C,IAAI,IAAA,oBAAY,EAAC,aAAa,CAAC,EAAE,CAAC;YAChC,OAAO,aAAa,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,cAAc,CAAO,QAAqB,EAAE,SAA0B;QAC3E,OAAO,IAAI,qBAAqB,CAAO,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,YAAoB,QAAqB,EAAE,SAA0B;QACnE,IAAI,CAAC,QAAQ,GAAG,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAA,qBAAY,EAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;IACzE,CAAC;CAIF"}
@@ -1 +1 @@
1
- {"version":3,"file":"PromisorFactory.impl.d.ts","sourceRoot":"","sources":["../../src/impl/PromisorFactory.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAgB,YAAY,EAAa,MAAM,mCAAmC,CAAC;AAM1F;;;;GAIG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,CAEtD"}
1
+ {"version":3,"file":"PromisorFactory.impl.d.ts","sourceRoot":"","sources":["../../src/impl/PromisorFactory.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAgB,YAAY,EAAkC,MAAM,mCAAmC,CAAC;AAM/G;;;;GAIG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,CAEtD"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
4
  const Promisor_1 = require("@jonloucks/contracts-ts/api/Promisor");
5
+ const Types_1 = require("@jonloucks/contracts-ts/api/Types");
5
6
  const ExtractorPromisor_impl_1 = require("./ExtractorPromisor.impl");
6
7
  const LifeCyclePromisor_impl_1 = require("./LifeCyclePromisor.impl");
7
8
  const SingletonPromisor_impl_1 = require("./SingletonPromisor.impl");
@@ -41,7 +42,7 @@ class PromisorsImpl {
41
42
  * PromisorFactory.createExtractor override.
42
43
  */
43
44
  createExtractor(promisor, extractor) {
44
- return (0, ExtractorPromisor_impl_1.create)((0, Promisor_1.typeToPromisor)(promisor), extractor);
45
+ return (0, ExtractorPromisor_impl_1.create)((0, Promisor_1.typeToPromisor)(promisor), (0, Types_1.typeToTransform)(extractor));
45
46
  }
46
47
  static internalCreate() {
47
48
  return new PromisorsImpl();
@@ -1 +1 @@
1
- {"version":3,"file":"PromisorFactory.impl.js","sourceRoot":"","sources":["../../src/impl/PromisorFactory.impl.ts"],"names":[],"mappings":";;AAaA,wBAEC;AAfD,mEAA8F;AAG9F,qEAAqE;AACrE,qEAAqE;AACrE,qEAAqE;AACrE,6DAA6D;AAE7D;;;;GAIG;AACH,SAAgB,MAAM;IACpB,OAAO,aAAa,CAAC,cAAc,EAAE,CAAC;AACxC,CAAC;AAED,yCAAyC;AAEzC;;GAEG;AACH,MAAM,aAAa;IAEjB;;OAEG;IACH,WAAW,CAAI,WAA4B;QACzC,OAAO,IAAA,2BAAW,EAAI,WAAW,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,eAAe,CAAI,QAAyB;QA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QAAQ,CAAC,EAAE,IAAA,uBAAe,EAAC,SAAS,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,CAAC,cAAc;QACnB,OAAO,IAAI,aAAa,EAAE,CAAC;IAC7B,CAAC;IAED;IACA,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jonloucks/contracts-ts",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Typescript Dependency Contracts for dependency inversion",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -46,6 +46,8 @@
46
46
  "badges": "npx tsx ./src/never-publish/generate-badges.ts",
47
47
  "clean": "rm -rf dist",
48
48
  "compile": "tsc",
49
+ "postversion": "npm run applyversion",
50
+ "applyversion": "npx tsx ./src/never-publish/apply-version.ts",
49
51
  "pack-package": "npm run before:publish && cd dist && npm pack && npm run after:publish"
50
52
  },
51
53
  "keywords": [
package/version.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export declare const NAME: string;
1
2
  export declare const VERSION: string;
2
3
  //# sourceMappingURL=version.d.ts.map
package/version.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,EAAE,MAalB,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,IAAI,EAAE,MAAkC,CAAC;AACtD,eAAO,MAAM,OAAO,EAAE,MAAgB,CAAC"}
package/version.js CHANGED
@@ -1,23 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const DEVELOPMENT_PATH = (0, path_1.join)(__dirname, "..", "package.json");
7
- const PRODUCTION_PATH = (0, path_1.resolve)(__dirname, 'package.json');
8
- exports.VERSION = (() => {
9
- for (const path of [PRODUCTION_PATH, DEVELOPMENT_PATH]) {
10
- try {
11
- const parsedJson = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
12
- const { version } = parsedJson;
13
- if (version !== undefined && version !== null) {
14
- return version;
15
- }
16
- }
17
- catch (_error) {
18
- // continue to next path
19
- }
20
- }
21
- return "unknown";
22
- })();
3
+ exports.VERSION = exports.NAME = void 0;
4
+ // generated file - do not edit
5
+ exports.NAME = "@jonloucks/contracts-ts";
6
+ exports.VERSION = "1.0.2";
23
7
  //# sourceMappingURL=version.js.map
package/version.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAAqC;AAErC,MAAM,gBAAgB,GAAW,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AACvE,MAAM,eAAe,GAAW,IAAA,cAAO,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAEtD,QAAA,OAAO,GAAW,CAAC,GAAW,EAAE;IAC3C,KAAK,MAAM,IAAI,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,MAAM,UAAU,GAAY,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;YACnE,MAAM,EAAE,OAAO,EAAE,GAAG,UAAkC,CAAC;YACvD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC9C,OAAO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,wBAAwB;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAClB,QAAA,IAAI,GAAW,yBAAyB,CAAC;AACzC,QAAA,OAAO,GAAW,OAAO,CAAC"}