@genesislcap/foundation-utils 14.260.2 → 14.260.3

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.
@@ -2922,6 +2922,12 @@
2922
2922
  }
2923
2923
  ]
2924
2924
  },
2925
+ {
2926
+ "kind": "javascript-module",
2927
+ "path": "src/mappers/genesis-json-schema/test.ts",
2928
+ "declarations": [],
2929
+ "exports": []
2930
+ },
2925
2931
  {
2926
2932
  "kind": "javascript-module",
2927
2933
  "path": "src/mappers/genesis-json-schema/types.ts",
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mappers/genesis-json-schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,cAAc,SAAS,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,iBAAiB,EAAE;IACtD,QAAQ,EAAE,WAAW,CAAC;CACvB,GAAG,OAAO,CAAC,WAAW,CAwBtB;AAsCD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oCAAoC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;IACnE,MAAM;IACN,OAAO,CAAC,eAAe;CACxB,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,CASrB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mappers/genesis-json-schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,cAAc,SAAS,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,iBAAiB,EAAE;IACtD,QAAQ,EAAE,WAAW,CAAC;CACvB,GAAG,OAAO,CAAC,WAAW,CAwBtB;AA0DD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oCAAoC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;IACnE,MAAM;IACN,OAAO,CAAC,eAAe;CACxB,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,CASrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../../../src/mappers/genesis-json-schema/test.ts"],"names":[],"mappings":""}
@@ -21,14 +21,27 @@ export function mapGenesisJsonSchema(jsonSchemResponse) {
21
21
  throw new Error(`Schema properties don't contain 'genesisType' field`);
22
22
  return (_x = (_w = (_v = result.OUTBOUND) === null || _v === void 0 ? void 0 : _v.properties) === null || _w === void 0 ? void 0 : _w['REPLY']) === null || _x === void 0 ? void 0 : _x.items;
23
23
  }
24
+ function extractEnumValues(schema, fieldName) {
25
+ if (schema.enum) {
26
+ // If there's a top-level enum property, use it
27
+ return schema.enum;
28
+ }
29
+ if (schema.oneOf) {
30
+ // Look for enum values within the oneOf structure
31
+ const stringTypeSchema = schema.oneOf.find((s) => s.type === 'string' && Array.isArray(s.enum));
32
+ if (stringTypeSchema && stringTypeSchema.enum) {
33
+ return stringTypeSchema.enum;
34
+ }
35
+ }
36
+ throw new Error(`Could not extract enum values for field '${fieldName}'`);
37
+ }
24
38
  function mapGenesisFieldTypeToFieldInputAndType(partialData, schema) {
25
39
  switch (schema.genesisType) {
26
40
  case 'STRING':
27
41
  return Object.assign(Object.assign({}, partialData), { type: 'string', input: 'text' });
28
42
  case 'ENUM':
29
- if (!schema.enum)
30
- throw new Error('Enum type but without enum values');
31
- return Object.assign(Object.assign({}, partialData), { type: 'enum', input: 'select', values: schema.enum.reduce((acum, v) => (Object.assign(Object.assign({}, acum), { [v]: v })), {}) });
43
+ const enumVals = extractEnumValues(schema, partialData.fieldId);
44
+ return Object.assign(Object.assign({}, partialData), { type: 'enum', input: 'select', values: enumVals.reduce((acum, v) => (Object.assign(Object.assign({}, acum), { [v]: v })), {}) });
32
45
  case 'INT':
33
46
  return Object.assign(Object.assign({}, partialData), { type: 'int', input: 'number' });
34
47
  case 'SHORT':
@@ -0,0 +1,261 @@
1
+ import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
2
+ import { mapJsonSchemaFieldToExprBuilderField } from '.';
3
+ const LogicSuite = createLogicSuite('mapJsonSchemaFieldToExprBuilderField');
4
+ LogicSuite('makes all root properties on the object observable', () => {
5
+ const exampleTradeSchema = {
6
+ properties: {
7
+ TRADE_ID: {
8
+ type: 'integer',
9
+ description: '',
10
+ genesisType: 'LONG',
11
+ },
12
+ TRADED_PRICE: {
13
+ type: 'number',
14
+ description: '',
15
+ genesisType: 'DOUBLE',
16
+ },
17
+ TRADED_QUANTITY: {
18
+ type: 'integer',
19
+ description: '',
20
+ genesisType: 'INT',
21
+ },
22
+ ORDER_ID: {
23
+ type: 'integer',
24
+ description: '',
25
+ genesisType: 'LONG',
26
+ },
27
+ ORDER_DATETIME: {
28
+ oneOf: [
29
+ {
30
+ type: 'null',
31
+ },
32
+ {
33
+ type: 'integer',
34
+ },
35
+ ],
36
+ description: '',
37
+ genesisType: 'DATETIME',
38
+ },
39
+ DIRECTION: {
40
+ oneOf: [
41
+ {
42
+ type: 'null',
43
+ },
44
+ {
45
+ type: 'string',
46
+ enum: ['SELL', 'SHORT_SELL', 'BUY'],
47
+ },
48
+ ],
49
+ description: '',
50
+ genesisType: 'ENUM',
51
+ },
52
+ IS_AGENCY: {
53
+ oneOf: [
54
+ {
55
+ type: 'null',
56
+ },
57
+ {
58
+ type: 'boolean',
59
+ },
60
+ ],
61
+ description: '',
62
+ genesisType: 'BOOLEAN',
63
+ },
64
+ QUANTITY: {
65
+ oneOf: [
66
+ {
67
+ type: 'null',
68
+ },
69
+ {
70
+ type: 'integer',
71
+ },
72
+ ],
73
+ description: '',
74
+ genesisType: 'INT',
75
+ },
76
+ PRICE: {
77
+ oneOf: [
78
+ {
79
+ type: 'null',
80
+ },
81
+ {
82
+ type: 'number',
83
+ },
84
+ ],
85
+ description: '',
86
+ genesisType: 'DOUBLE',
87
+ },
88
+ ORDER_DATE: {
89
+ oneOf: [
90
+ {
91
+ type: 'null',
92
+ },
93
+ {
94
+ type: 'integer',
95
+ },
96
+ ],
97
+ description: '',
98
+ genesisType: 'DATE',
99
+ },
100
+ COUNTERPARTY_ID: {
101
+ oneOf: [
102
+ {
103
+ type: 'null',
104
+ },
105
+ {
106
+ type: 'integer',
107
+ },
108
+ ],
109
+ description: '',
110
+ genesisType: 'LONG',
111
+ },
112
+ INSTRUMENT_ID: {
113
+ oneOf: [
114
+ {
115
+ type: 'null',
116
+ },
117
+ {
118
+ type: 'integer',
119
+ },
120
+ ],
121
+ description: '',
122
+ genesisType: 'LONG',
123
+ },
124
+ COUNTERPARTY_NAME: {
125
+ oneOf: [
126
+ {
127
+ type: 'null',
128
+ },
129
+ {
130
+ type: 'string',
131
+ },
132
+ ],
133
+ description: '',
134
+ genesisType: 'STRING',
135
+ },
136
+ SYMBOL: {
137
+ oneOf: [
138
+ {
139
+ type: 'null',
140
+ },
141
+ {
142
+ type: 'string',
143
+ },
144
+ ],
145
+ description: '',
146
+ genesisType: 'STRING',
147
+ },
148
+ RECORD_ID: {
149
+ type: 'integer',
150
+ description: '',
151
+ genesisType: 'LONG',
152
+ },
153
+ TIMESTAMP: {
154
+ type: 'integer',
155
+ description: '',
156
+ genesisType: 'NANO_TIMESTAMP',
157
+ },
158
+ },
159
+ };
160
+ const expected = [
161
+ {
162
+ fieldId: 'TRADE_ID',
163
+ label: 'TRADE_ID',
164
+ type: 'long',
165
+ input: 'number',
166
+ },
167
+ {
168
+ fieldId: 'TRADED_PRICE',
169
+ label: 'TRADED_PRICE',
170
+ type: 'double',
171
+ input: 'number',
172
+ },
173
+ {
174
+ fieldId: 'TRADED_QUANTITY',
175
+ label: 'TRADED_QUANTITY',
176
+ type: 'int',
177
+ input: 'number',
178
+ },
179
+ {
180
+ fieldId: 'ORDER_ID',
181
+ label: 'ORDER_ID',
182
+ type: 'long',
183
+ input: 'number',
184
+ },
185
+ {
186
+ fieldId: 'ORDER_DATETIME',
187
+ label: 'ORDER_DATETIME',
188
+ type: 'date-time',
189
+ input: 'datetime-local',
190
+ },
191
+ {
192
+ fieldId: 'DIRECTION',
193
+ label: 'DIRECTION',
194
+ type: 'enum',
195
+ input: 'select',
196
+ values: {
197
+ SELL: 'SELL',
198
+ SHORT_SELL: 'SHORT_SELL',
199
+ BUY: 'BUY',
200
+ },
201
+ },
202
+ {
203
+ fieldId: 'IS_AGENCY',
204
+ label: 'IS_AGENCY',
205
+ type: 'boolean',
206
+ input: 'checkbox',
207
+ },
208
+ {
209
+ fieldId: 'QUANTITY',
210
+ label: 'QUANTITY',
211
+ type: 'int',
212
+ input: 'number',
213
+ },
214
+ {
215
+ fieldId: 'PRICE',
216
+ label: 'PRICE',
217
+ type: 'double',
218
+ input: 'number',
219
+ },
220
+ {
221
+ fieldId: 'ORDER_DATE',
222
+ label: 'ORDER_DATE',
223
+ type: 'date',
224
+ input: 'date',
225
+ },
226
+ {
227
+ fieldId: 'COUNTERPARTY_ID',
228
+ label: 'COUNTERPARTY_ID',
229
+ type: 'long',
230
+ input: 'number',
231
+ },
232
+ {
233
+ fieldId: 'INSTRUMENT_ID',
234
+ label: 'INSTRUMENT_ID',
235
+ type: 'long',
236
+ input: 'number',
237
+ },
238
+ {
239
+ fieldId: 'COUNTERPARTY_NAME',
240
+ label: 'COUNTERPARTY_NAME',
241
+ type: 'string',
242
+ input: 'text',
243
+ },
244
+ {
245
+ fieldId: 'SYMBOL',
246
+ label: 'SYMBOL',
247
+ type: 'string',
248
+ input: 'text',
249
+ },
250
+ {
251
+ fieldId: 'RECORD_ID',
252
+ label: 'RECORD_ID',
253
+ type: 'long',
254
+ input: 'number',
255
+ },
256
+ null,
257
+ ];
258
+ const fields = Object.entries(exampleTradeSchema.properties).map(mapJsonSchemaFieldToExprBuilderField);
259
+ assert.equal(fields, expected);
260
+ });
261
+ LogicSuite.run();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-utils",
3
3
  "description": "Genesis Foundation Utils",
4
- "version": "14.260.2",
4
+ "version": "14.260.3",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -27,19 +27,19 @@
27
27
  }
28
28
  },
29
29
  "devDependencies": {
30
- "@genesislcap/foundation-testing": "14.260.2",
31
- "@genesislcap/genx": "14.260.2",
32
- "@genesislcap/rollup-builder": "14.260.2",
33
- "@genesislcap/ts-builder": "14.260.2",
34
- "@genesislcap/uvu-playwright-builder": "14.260.2",
35
- "@genesislcap/vite-builder": "14.260.2",
36
- "@genesislcap/webpack-builder": "14.260.2",
30
+ "@genesislcap/foundation-testing": "14.260.3",
31
+ "@genesislcap/genx": "14.260.3",
32
+ "@genesislcap/rollup-builder": "14.260.3",
33
+ "@genesislcap/ts-builder": "14.260.3",
34
+ "@genesislcap/uvu-playwright-builder": "14.260.3",
35
+ "@genesislcap/vite-builder": "14.260.3",
36
+ "@genesislcap/webpack-builder": "14.260.3",
37
37
  "@types/json-schema": "^7.0.11",
38
38
  "rimraf": "^5.0.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "@genesislcap/expression-builder": "14.258.1",
42
- "@genesislcap/foundation-logger": "14.260.2",
42
+ "@genesislcap/foundation-logger": "14.260.3",
43
43
  "@microsoft/fast-components": "2.30.6",
44
44
  "@microsoft/fast-element": "1.14.0",
45
45
  "@microsoft/fast-foundation": "2.49.6",
@@ -57,5 +57,5 @@
57
57
  "access": "public"
58
58
  },
59
59
  "customElements": "dist/custom-elements.json",
60
- "gitHead": "74542c54a01f7e6bfc1902d5d26ea8475dffe0cb"
60
+ "gitHead": "8c2edfa09d71c8b6c5487873d1751da090c62480"
61
61
  }