@decafhub/decaf-client-extras 0.0.4 → 0.1.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +22 -0
- package/commons/-currency.d.ts +22 -6
- package/commons/-currency.js +12 -6
- package/commons/{-date-type.d.ts → -datetype.d.ts} +2 -2
- package/commons/{-date-type.js → -datetype.js} +2 -2
- package/commons/-id.d.ts +109 -17
- package/commons/-id.js +73 -0
- package/commons/index.d.ts +4 -1
- package/commons/index.js +17 -1
- package/es/commons/-currency.d.ts +22 -6
- package/es/commons/-currency.js +12 -6
- package/es/commons/{-date-type.d.ts → -datetype.d.ts} +2 -2
- package/es/commons/{-date-type.js → -datetype.js} +1 -1
- package/es/commons/-id.d.ts +109 -17
- package/es/commons/-id.js +70 -1
- package/es/commons/index.d.ts +4 -1
- package/es/commons/index.js +4 -1
- package/es/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
- package/es/reports/valuation/-remote-valuation-report-portfolio.js +32 -32
- package/es/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
- package/es/reports/valuation/-remote-valuation-report-shared.js +29 -26
- package/es/reports/valuation/-valuation-report-consolidated.d.ts +1 -1
- package/es/reports/valuation/-valuation-report-holdings-tree/-machinery.js +6 -5
- package/es/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
- package/es/reports/valuation/-valuation-report-shared.d.ts +7 -7
- package/nix/default.nix +59 -0
- package/nix/sources.json +14 -0
- package/nix/sources.nix +194 -0
- package/package.json +16 -16
- package/reports/valuation/-remote-valuation-report-consolidated.js +1 -1
- package/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
- package/reports/valuation/-remote-valuation-report-portfolio.js +32 -32
- package/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
- package/reports/valuation/-remote-valuation-report-shared.js +28 -25
- package/reports/valuation/-valuation-report-consolidated.d.ts +1 -1
- package/reports/valuation/-valuation-report-holdings-tree/-machinery.js +14 -11
- package/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
- package/reports/valuation/-valuation-report-shared.d.ts +7 -7
- package/shell.nix +5 -20
- package/src/commons/-currency.test.ts +27 -0
- package/src/commons/-currency.ts +24 -9
- package/src/commons/-datetype.test.ts +10 -0
- package/src/commons/{-date-type.ts → -datetype.ts} +1 -1
- package/src/commons/-id.test.ts +27 -0
- package/src/commons/-id.ts +112 -17
- package/src/commons/index.ts +4 -1
- package/src/index.test.ts +34 -5
- package/src/reports/valuation/-remote-valuation-report-portfolio.ts +54 -54
- package/src/reports/valuation/-remote-valuation-report-shared.ts +34 -31
- package/src/reports/valuation/-valuation-report-holdings-tree/-machinery.ts +14 -5
- package/src/reports/valuation/-valuation-report-portfolio.ts +20 -20
- package/src/reports/valuation/-valuation-report-shared.ts +13 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.0](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.0.5...v0.1.0) (2023-01-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* The underlying types of DECAF record identifiers have been changed to a simpler, tagged type definitions. Call-sites should use `mkDecafRecordId` constructor and `unDecafRecordId` de-constructor OR direct type casting when producing and consuming such values.
|
|
9
|
+
* We are now adopting the convention that constants are defined via all-uppercase, snake-case symbols.
|
|
10
|
+
* The underlying type of CurrencyCode has been changed to a simpler, tagged type definition. Call-sites should use either of:
|
|
11
|
+
|
|
12
|
+
### Code Refactoring
|
|
13
|
+
|
|
14
|
+
* change type of CurrencyCode, use regexp for validation ([b4915aa](https://github.com/teloscube/decaf-client-javascript-extras/commit/b4915aace037ce9e56be9161ea730529a7d31536))
|
|
15
|
+
* change type of DECAF record identifiers ([a2f48c0](https://github.com/teloscube/decaf-client-javascript-extras/commit/a2f48c00525714ffa20ecdca2900b842581ede43))
|
|
16
|
+
* rename constant dateTypes to DATE_TYPES ([7801283](https://github.com/teloscube/decaf-client-javascript-extras/commit/7801283bdc72463bbb243f03c5bb10ef77c5dd7a))
|
|
17
|
+
|
|
18
|
+
## [0.0.5](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.0.4...v0.0.5) (2022-12-28)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* exclude cash holdings from total exposure calculation ([09d7133](https://github.com/teloscube/decaf-client-javascript-extras/commit/09d7133515d9670dc3c5a641dd84d1e57fa5d5ee))
|
|
24
|
+
|
|
3
25
|
## [0.0.4](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.0.3...v0.0.4) (2022-11-07)
|
|
4
26
|
|
|
5
27
|
|
package/commons/-currency.d.ts
CHANGED
|
@@ -3,18 +3,32 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { Maybe
|
|
6
|
+
import { Maybe } from '@telostat/prelude';
|
|
7
7
|
/**
|
|
8
|
-
* Type
|
|
8
|
+
* Type definition for currency code values.
|
|
9
9
|
*
|
|
10
|
-
* A currency code is (typically) defined as all-uppercase, three
|
|
10
|
+
* A currency code is (typically) defined as all-uppercase, three-letter
|
|
11
|
+
* `string`. In this library, we are particularly using the regular expression
|
|
12
|
+
* {@link REGEXP_CURRENCY_CODE} which allows any uppercase letter followed by
|
|
13
|
+
* uppercase or lowercase letters.
|
|
14
|
+
*
|
|
15
|
+
* As for the type definition: We are using a (not-so-elegant) trick called
|
|
16
|
+
* "tagged-type" to annotate the plain-vanilla `string` type to be the
|
|
17
|
+
* `CurrencyCode` (_poor man's newtype_). Note that during the runtime, all
|
|
18
|
+
* `CurrencyCode` values are simply a `string` values.
|
|
19
|
+
*/
|
|
20
|
+
export type CurrencyCode = string & {
|
|
21
|
+
readonly __tag: unique symbol;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Regular expression for currency codes in our concept.
|
|
11
25
|
*/
|
|
12
|
-
export declare
|
|
26
|
+
export declare const REGEXP_CURRENCY_CODE: RegExp;
|
|
13
27
|
/**
|
|
14
28
|
* Attempts to create a {@link CurrencyCode} value with the given currency code.
|
|
15
29
|
*
|
|
16
|
-
* This function returns a `Maybe` value. For the
|
|
17
|
-
* error, see {@link mkCurrencyCodeError}.
|
|
30
|
+
* This function returns a `Maybe` value. For the
|
|
31
|
+
* version that throws an error, see {@link mkCurrencyCodeError}.
|
|
18
32
|
*
|
|
19
33
|
* @param x A currency code represented as string.
|
|
20
34
|
* @returns If the argument has leading or trailing spaces OR it is empty,
|
|
@@ -36,6 +50,8 @@ export declare function mkCurrencyCodeError(x: string): CurrencyCode;
|
|
|
36
50
|
/**
|
|
37
51
|
* Return the currency code as a string value.
|
|
38
52
|
*
|
|
53
|
+
* In runtime, this is effectively the identity function.
|
|
54
|
+
*
|
|
39
55
|
* @param x {@link CurrencyCode} to be extracted string from.
|
|
40
56
|
* @returns Currency code as a string.
|
|
41
57
|
*/
|
package/commons/-currency.js
CHANGED
|
@@ -5,20 +5,24 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.unCurrencyCode = exports.mkCurrencyCodeError = exports.mkCurrencyCode = void 0;
|
|
8
|
+
exports.unCurrencyCode = exports.mkCurrencyCodeError = exports.mkCurrencyCode = exports.REGEXP_CURRENCY_CODE = void 0;
|
|
9
9
|
var prelude_1 = require("@telostat/prelude");
|
|
10
|
+
/**
|
|
11
|
+
* Regular expression for currency codes in our concept.
|
|
12
|
+
*/
|
|
13
|
+
exports.REGEXP_CURRENCY_CODE = /^[A-Z][a-zA-Z]*$/;
|
|
10
14
|
/**
|
|
11
15
|
* Attempts to create a {@link CurrencyCode} value with the given currency code.
|
|
12
16
|
*
|
|
13
|
-
* This function returns a `Maybe` value. For the
|
|
14
|
-
* error, see {@link mkCurrencyCodeError}.
|
|
17
|
+
* This function returns a `Maybe` value. For the
|
|
18
|
+
* version that throws an error, see {@link mkCurrencyCodeError}.
|
|
15
19
|
*
|
|
16
20
|
* @param x A currency code represented as string.
|
|
17
21
|
* @returns If the argument has leading or trailing spaces OR it is empty,
|
|
18
22
|
* `Nothing` is retured, `Just` {@link CurrencyCode} otherwise.
|
|
19
23
|
*/
|
|
20
24
|
function mkCurrencyCode(x) {
|
|
21
|
-
return
|
|
25
|
+
return exports.REGEXP_CURRENCY_CODE.test(x) ? (0, prelude_1.Just)(x) : prelude_1.Nothing;
|
|
22
26
|
}
|
|
23
27
|
exports.mkCurrencyCode = mkCurrencyCode;
|
|
24
28
|
/**
|
|
@@ -34,17 +38,19 @@ exports.mkCurrencyCode = mkCurrencyCode;
|
|
|
34
38
|
*/
|
|
35
39
|
function mkCurrencyCodeError(x) {
|
|
36
40
|
return mkCurrencyCode(x).orDefaultLazy(function () {
|
|
37
|
-
throw new Error("Invalid currency code:
|
|
41
|
+
throw new Error("Invalid currency code: ".concat(x));
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
exports.mkCurrencyCodeError = mkCurrencyCodeError;
|
|
41
45
|
/**
|
|
42
46
|
* Return the currency code as a string value.
|
|
43
47
|
*
|
|
48
|
+
* In runtime, this is effectively the identity function.
|
|
49
|
+
*
|
|
44
50
|
* @param x {@link CurrencyCode} to be extracted string from.
|
|
45
51
|
* @returns Currency code as a string.
|
|
46
52
|
*/
|
|
47
53
|
function unCurrencyCode(x) {
|
|
48
|
-
return
|
|
54
|
+
return x;
|
|
49
55
|
}
|
|
50
56
|
exports.unCurrencyCode = unCurrencyCode;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DECAF FINREA action date type type definition.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type DateType = 'commitment' | 'settlement';
|
|
5
5
|
/**
|
|
6
6
|
* Translation table for DECAF FINREA action date types.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const DATE_TYPES: {
|
|
9
9
|
label: string;
|
|
10
10
|
value: DateType;
|
|
11
11
|
}[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DATE_TYPES = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Translation table for DECAF FINREA action date types.
|
|
6
6
|
*/
|
|
7
|
-
exports.
|
|
7
|
+
exports.DATE_TYPES = [
|
|
8
8
|
{ label: 'Trade Date', value: 'commitment' },
|
|
9
9
|
{ label: 'Value Date', value: 'settlement' },
|
|
10
10
|
];
|
package/commons/-id.d.ts
CHANGED
|
@@ -1,58 +1,150 @@
|
|
|
1
|
-
import { NewTypeWithPhantom } from '@telostat/prelude';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* This module provides a collection of DECAF record identifier type
|
|
3
|
+
* definitions. It is not exhaustive and it will be improved on an ongoing
|
|
4
|
+
* basis.
|
|
5
|
+
*
|
|
6
|
+
* Typically, a DECAF record identifier is either number or string. Some DECAF
|
|
7
|
+
* API endoints can consume string values even though a number is expected. We
|
|
8
|
+
* are sticking here to the original type: No `number | string` definitions.
|
|
9
|
+
*
|
|
10
|
+
* Methodologically, we are using a type trick to emulate newtypes in this
|
|
11
|
+
* module: For example, DECAF artifact identifier type is defined as:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* export type DecafArtifactId = number & { readonly __tag: unique symbol };
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* In runtime, there is only a number. The `& { readonly __tag: unique symbol }`
|
|
18
|
+
* is provided to the compiler to distinguish in between `number` identifier
|
|
19
|
+
* values which are representing different DECAF record types.
|
|
20
|
+
*
|
|
21
|
+
* The construction and deconstruction of DECAF record identifiers are done via,
|
|
22
|
+
* respecively, `mkDecafRecordId` and `unDecafRecordId`:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
|
|
26
|
+
* const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
|
|
27
|
+
* expect(exampleDecafArtifactIdValue).toBe(42);
|
|
28
|
+
*
|
|
29
|
+
* const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
|
|
30
|
+
* const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
|
|
31
|
+
* expect(exampleDecafActionIdValue).toBe(42);
|
|
32
|
+
*
|
|
33
|
+
* const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
|
|
34
|
+
* const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
|
|
35
|
+
* expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* To re-iterate, the runtime representation is not affected by how DECAF record
|
|
39
|
+
* identifier types are defined:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* interface DecafArtifact {
|
|
43
|
+
* id: DecafArtifactId;
|
|
44
|
+
* type: DecafArtifactTypeId;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
|
|
48
|
+
* expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @module
|
|
5
52
|
*/
|
|
6
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Type definition covering all possible DECAF record identifiers based on
|
|
55
|
+
* `number` values.
|
|
56
|
+
*
|
|
57
|
+
* This type definition must be extended whenever there is a new DECAF record
|
|
58
|
+
* identifier is defined in this module.
|
|
59
|
+
*/
|
|
60
|
+
export type _DecafRecordIdFromNumber = DecafArtifactId | DecafActionId;
|
|
61
|
+
/**
|
|
62
|
+
* Type definition covering all possible DECAF record identifiers based on
|
|
63
|
+
* `string` values.
|
|
64
|
+
*
|
|
65
|
+
* This type definition must be extended whenever there is a new DECAF record
|
|
66
|
+
* identifier is defined in this module.
|
|
67
|
+
*/
|
|
68
|
+
export type _DecafRecordIdFromString = DecafArtifactTypeId;
|
|
69
|
+
export declare function mkDecafRecordId<T extends _DecafRecordIdFromNumber>(x: number): T;
|
|
70
|
+
export declare function mkDecafRecordId<T extends _DecafRecordIdFromString>(x: string): T;
|
|
71
|
+
export declare function unDecafRecordId<T extends _DecafRecordIdFromNumber>(x: T): number;
|
|
72
|
+
export declare function unDecafRecordId<K extends _DecafRecordIdFromString>(x: K): string;
|
|
7
73
|
/**
|
|
8
74
|
* Type definition for DECAF artifact identifiers.
|
|
9
75
|
*/
|
|
10
|
-
export
|
|
76
|
+
export type DecafArtifactId = number & {
|
|
77
|
+
readonly __tag: unique symbol;
|
|
78
|
+
};
|
|
11
79
|
/**
|
|
12
80
|
* Type definition for DECAF artifact type identifiers.
|
|
13
81
|
*/
|
|
14
|
-
export
|
|
82
|
+
export type DecafArtifactTypeId = string & {
|
|
83
|
+
readonly __tag: unique symbol;
|
|
84
|
+
};
|
|
15
85
|
/**
|
|
16
86
|
* Type definition for DECAF share class identifiers.
|
|
17
87
|
*/
|
|
18
|
-
export
|
|
88
|
+
export type DecafShareClassId = number & {
|
|
89
|
+
readonly __tag: unique symbol;
|
|
90
|
+
};
|
|
19
91
|
/**
|
|
20
92
|
* Type definition for DECAF principal identifiers.
|
|
21
93
|
*/
|
|
22
|
-
export
|
|
94
|
+
export type DecafPrincipalId = number & {
|
|
95
|
+
readonly __tag: unique symbol;
|
|
96
|
+
};
|
|
23
97
|
/**
|
|
24
98
|
* Type definition for DECAF institution identifiers.
|
|
25
99
|
*/
|
|
26
|
-
export
|
|
100
|
+
export type DecafInstitutionId = number & {
|
|
101
|
+
readonly __tag: unique symbol;
|
|
102
|
+
};
|
|
27
103
|
/**
|
|
28
104
|
* Type definition for DECAF team identifiers.
|
|
29
105
|
*/
|
|
30
|
-
export
|
|
106
|
+
export type DecafTeamId = number & {
|
|
107
|
+
readonly __tag: unique symbol;
|
|
108
|
+
};
|
|
31
109
|
/**
|
|
32
110
|
* Type definition for DECAF portfolio identifiers.
|
|
33
111
|
*/
|
|
34
|
-
export
|
|
112
|
+
export type DecafPortfolioId = number & {
|
|
113
|
+
readonly __tag: unique symbol;
|
|
114
|
+
};
|
|
35
115
|
/**
|
|
36
116
|
* Type definition for DECAF portfolio group identifiers.
|
|
37
117
|
*/
|
|
38
|
-
export
|
|
118
|
+
export type DecafPortfolioGroupId = number & {
|
|
119
|
+
readonly __tag: unique symbol;
|
|
120
|
+
};
|
|
39
121
|
/**
|
|
40
122
|
* Type definition for DECAF account identifiers.
|
|
41
123
|
*/
|
|
42
|
-
export
|
|
124
|
+
export type DecafAccountId = number & {
|
|
125
|
+
readonly __tag: unique symbol;
|
|
126
|
+
};
|
|
43
127
|
/**
|
|
44
128
|
* Type definition for DECAF OHLC series identifiers.
|
|
45
129
|
*/
|
|
46
|
-
export
|
|
130
|
+
export type DecafOhlcSeriesId = number & {
|
|
131
|
+
readonly __tag: unique symbol;
|
|
132
|
+
};
|
|
47
133
|
/**
|
|
48
134
|
* Type definition for DECAF share class fee schedule identifiers.
|
|
49
135
|
*/
|
|
50
|
-
export
|
|
136
|
+
export type DecafShareClassFeeScheduleId = number & {
|
|
137
|
+
readonly __tag: unique symbol;
|
|
138
|
+
};
|
|
51
139
|
/**
|
|
52
140
|
* Type definition for DECAF action identifiers.
|
|
53
141
|
*/
|
|
54
|
-
export
|
|
142
|
+
export type DecafActionId = number & {
|
|
143
|
+
readonly __tag: unique symbol;
|
|
144
|
+
};
|
|
55
145
|
/**
|
|
56
146
|
* Type definition for DECAF external valuation identifiers.
|
|
57
147
|
*/
|
|
58
|
-
export
|
|
148
|
+
export type DecafExternalValuationId = number & {
|
|
149
|
+
readonly __tag: unique symbol;
|
|
150
|
+
};
|
package/commons/-id.js
CHANGED
|
@@ -1,2 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This module provides a collection of DECAF record identifier type
|
|
4
|
+
* definitions. It is not exhaustive and it will be improved on an ongoing
|
|
5
|
+
* basis.
|
|
6
|
+
*
|
|
7
|
+
* Typically, a DECAF record identifier is either number or string. Some DECAF
|
|
8
|
+
* API endoints can consume string values even though a number is expected. We
|
|
9
|
+
* are sticking here to the original type: No `number | string` definitions.
|
|
10
|
+
*
|
|
11
|
+
* Methodologically, we are using a type trick to emulate newtypes in this
|
|
12
|
+
* module: For example, DECAF artifact identifier type is defined as:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* export type DecafArtifactId = number & { readonly __tag: unique symbol };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* In runtime, there is only a number. The `& { readonly __tag: unique symbol }`
|
|
19
|
+
* is provided to the compiler to distinguish in between `number` identifier
|
|
20
|
+
* values which are representing different DECAF record types.
|
|
21
|
+
*
|
|
22
|
+
* The construction and deconstruction of DECAF record identifiers are done via,
|
|
23
|
+
* respecively, `mkDecafRecordId` and `unDecafRecordId`:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
|
|
27
|
+
* const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
|
|
28
|
+
* expect(exampleDecafArtifactIdValue).toBe(42);
|
|
29
|
+
*
|
|
30
|
+
* const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
|
|
31
|
+
* const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
|
|
32
|
+
* expect(exampleDecafActionIdValue).toBe(42);
|
|
33
|
+
*
|
|
34
|
+
* const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
|
|
35
|
+
* const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
|
|
36
|
+
* expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* To re-iterate, the runtime representation is not affected by how DECAF record
|
|
40
|
+
* identifier types are defined:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* interface DecafArtifact {
|
|
44
|
+
* id: DecafArtifactId;
|
|
45
|
+
* type: DecafArtifactTypeId;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
|
|
49
|
+
* expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
2
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.unDecafRecordId = exports.mkDecafRecordId = void 0;
|
|
56
|
+
/**
|
|
57
|
+
* Constructor for DECAF record identifiers.
|
|
58
|
+
*
|
|
59
|
+
* @param x Value to create DECAF record identifier from.
|
|
60
|
+
* @returns DECAF record identifier of type deduced from call-site usage.
|
|
61
|
+
*/
|
|
62
|
+
function mkDecafRecordId(x) {
|
|
63
|
+
return x;
|
|
64
|
+
}
|
|
65
|
+
exports.mkDecafRecordId = mkDecafRecordId;
|
|
66
|
+
/**
|
|
67
|
+
* Deconstructor for DECAF record identifiers.
|
|
68
|
+
*
|
|
69
|
+
* @param x DECAF record identifier.
|
|
70
|
+
* @returns Value of the DECAF record identifier (deduced from call-site usage).
|
|
71
|
+
*/
|
|
72
|
+
function unDecafRecordId(x) {
|
|
73
|
+
return x;
|
|
74
|
+
}
|
|
75
|
+
exports.unDecafRecordId = unDecafRecordId;
|
package/commons/index.d.ts
CHANGED
package/commons/index.js
CHANGED
|
@@ -10,10 +10,26 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.id = exports.datetype = exports.currency = void 0;
|
|
17
30
|
__exportStar(require("./-currency"), exports);
|
|
18
|
-
|
|
31
|
+
exports.currency = __importStar(require("./-currency"));
|
|
32
|
+
__exportStar(require("./-datetype"), exports);
|
|
33
|
+
exports.datetype = __importStar(require("./-datetype"));
|
|
19
34
|
__exportStar(require("./-id"), exports);
|
|
35
|
+
exports.id = __importStar(require("./-id"));
|
|
@@ -3,18 +3,32 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { Maybe
|
|
6
|
+
import { Maybe } from '@telostat/prelude';
|
|
7
7
|
/**
|
|
8
|
-
* Type
|
|
8
|
+
* Type definition for currency code values.
|
|
9
9
|
*
|
|
10
|
-
* A currency code is (typically) defined as all-uppercase, three
|
|
10
|
+
* A currency code is (typically) defined as all-uppercase, three-letter
|
|
11
|
+
* `string`. In this library, we are particularly using the regular expression
|
|
12
|
+
* {@link REGEXP_CURRENCY_CODE} which allows any uppercase letter followed by
|
|
13
|
+
* uppercase or lowercase letters.
|
|
14
|
+
*
|
|
15
|
+
* As for the type definition: We are using a (not-so-elegant) trick called
|
|
16
|
+
* "tagged-type" to annotate the plain-vanilla `string` type to be the
|
|
17
|
+
* `CurrencyCode` (_poor man's newtype_). Note that during the runtime, all
|
|
18
|
+
* `CurrencyCode` values are simply a `string` values.
|
|
19
|
+
*/
|
|
20
|
+
export type CurrencyCode = string & {
|
|
21
|
+
readonly __tag: unique symbol;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Regular expression for currency codes in our concept.
|
|
11
25
|
*/
|
|
12
|
-
export declare
|
|
26
|
+
export declare const REGEXP_CURRENCY_CODE: RegExp;
|
|
13
27
|
/**
|
|
14
28
|
* Attempts to create a {@link CurrencyCode} value with the given currency code.
|
|
15
29
|
*
|
|
16
|
-
* This function returns a `Maybe` value. For the
|
|
17
|
-
* error, see {@link mkCurrencyCodeError}.
|
|
30
|
+
* This function returns a `Maybe` value. For the
|
|
31
|
+
* version that throws an error, see {@link mkCurrencyCodeError}.
|
|
18
32
|
*
|
|
19
33
|
* @param x A currency code represented as string.
|
|
20
34
|
* @returns If the argument has leading or trailing spaces OR it is empty,
|
|
@@ -36,6 +50,8 @@ export declare function mkCurrencyCodeError(x: string): CurrencyCode;
|
|
|
36
50
|
/**
|
|
37
51
|
* Return the currency code as a string value.
|
|
38
52
|
*
|
|
53
|
+
* In runtime, this is effectively the identity function.
|
|
54
|
+
*
|
|
39
55
|
* @param x {@link CurrencyCode} to be extracted string from.
|
|
40
56
|
* @returns Currency code as a string.
|
|
41
57
|
*/
|
package/es/commons/-currency.js
CHANGED
|
@@ -3,19 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { Just,
|
|
6
|
+
import { Just, Nothing } from '@telostat/prelude';
|
|
7
|
+
/**
|
|
8
|
+
* Regular expression for currency codes in our concept.
|
|
9
|
+
*/
|
|
10
|
+
export const REGEXP_CURRENCY_CODE = /^[A-Z][a-zA-Z]*$/;
|
|
7
11
|
/**
|
|
8
12
|
* Attempts to create a {@link CurrencyCode} value with the given currency code.
|
|
9
13
|
*
|
|
10
|
-
* This function returns a `Maybe` value. For the
|
|
11
|
-
* error, see {@link mkCurrencyCodeError}.
|
|
14
|
+
* This function returns a `Maybe` value. For the
|
|
15
|
+
* version that throws an error, see {@link mkCurrencyCodeError}.
|
|
12
16
|
*
|
|
13
17
|
* @param x A currency code represented as string.
|
|
14
18
|
* @returns If the argument has leading or trailing spaces OR it is empty,
|
|
15
19
|
* `Nothing` is retured, `Just` {@link CurrencyCode} otherwise.
|
|
16
20
|
*/
|
|
17
21
|
export function mkCurrencyCode(x) {
|
|
18
|
-
return
|
|
22
|
+
return REGEXP_CURRENCY_CODE.test(x) ? Just(x) : Nothing;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* (Unsafely) attempts to create a {@link CurrencyCode} value with the given
|
|
@@ -30,15 +34,17 @@ export function mkCurrencyCode(x) {
|
|
|
30
34
|
*/
|
|
31
35
|
export function mkCurrencyCodeError(x) {
|
|
32
36
|
return mkCurrencyCode(x).orDefaultLazy(() => {
|
|
33
|
-
throw new Error(`Invalid currency code:
|
|
37
|
+
throw new Error(`Invalid currency code: ${x}`);
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Return the currency code as a string value.
|
|
38
42
|
*
|
|
43
|
+
* In runtime, this is effectively the identity function.
|
|
44
|
+
*
|
|
39
45
|
* @param x {@link CurrencyCode} to be extracted string from.
|
|
40
46
|
* @returns Currency code as a string.
|
|
41
47
|
*/
|
|
42
48
|
export function unCurrencyCode(x) {
|
|
43
|
-
return
|
|
49
|
+
return x;
|
|
44
50
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DECAF FINREA action date type type definition.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type DateType = 'commitment' | 'settlement';
|
|
5
5
|
/**
|
|
6
6
|
* Translation table for DECAF FINREA action date types.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const DATE_TYPES: {
|
|
9
9
|
label: string;
|
|
10
10
|
value: DateType;
|
|
11
11
|
}[];
|