@carbonorm/carbonnode 3.7.19 → 3.7.21
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/dist/api/executors/HttpExecutor.d.ts +1 -0
- package/dist/index.cjs.js +22 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +22 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/binaryHex.e2e.test.ts +19 -38
- package/src/__tests__/fixtures/c6.fixture.ts +30 -0
- package/src/__tests__/httpExecutorSingular.e2e.test.ts +12 -1
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/__tests__/sqlBuilders.test.ts +30 -2
- package/src/api/executors/HttpExecutor.ts +19 -6
- package/src/api/orm/builders/ConditionBuilder.ts +2 -1
|
@@ -4,7 +4,7 @@ import { SelectQueryBuilder } from '../api/orm/queries/SelectQueryBuilder';
|
|
|
4
4
|
import { PostQueryBuilder } from '../api/orm/queries/PostQueryBuilder';
|
|
5
5
|
import { UpdateQueryBuilder } from '../api/orm/queries/UpdateQueryBuilder';
|
|
6
6
|
import { DeleteQueryBuilder } from '../api/orm/queries/DeleteQueryBuilder';
|
|
7
|
-
import { buildTestConfig, buildBinaryTestConfig } from './fixtures/c6.fixture';
|
|
7
|
+
import { buildTestConfig, buildBinaryTestConfig, buildBinaryTestConfigFqn } from './fixtures/c6.fixture';
|
|
8
8
|
|
|
9
9
|
describe('SQL Builders', () => {
|
|
10
10
|
it('builds SELECT with JOIN, WHERE, GROUP BY, HAVING and default LIMIT', () => {
|
|
@@ -178,5 +178,33 @@ describe('SQL Builders', () => {
|
|
|
178
178
|
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
179
179
|
expect((buf as Buffer).length).toBe(16);
|
|
180
180
|
});
|
|
181
|
-
});
|
|
182
181
|
|
|
182
|
+
it('converts hex to Buffer for BINARY when TYPE_VALIDATION uses fully-qualified key (INSERT)', () => {
|
|
183
|
+
const config = buildBinaryTestConfigFqn();
|
|
184
|
+
const qb = new PostQueryBuilder(config as any, {
|
|
185
|
+
[C6C.INSERT]: {
|
|
186
|
+
'binary_test.bin_col': '0123456789abcdef0123456789abcdef'
|
|
187
|
+
}
|
|
188
|
+
} as any, false);
|
|
189
|
+
|
|
190
|
+
const { params } = qb.build('binary_test');
|
|
191
|
+
const buf = (params as any[])[0];
|
|
192
|
+
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
193
|
+
expect((buf as Buffer).length).toBe(16);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('converts hex to Buffer for BINARY when TYPE_VALIDATION uses fully-qualified key (UPDATE)', () => {
|
|
197
|
+
const config = buildBinaryTestConfigFqn();
|
|
198
|
+
const qb = new UpdateQueryBuilder(config as any, {
|
|
199
|
+
[C6C.UPDATE]: {
|
|
200
|
+
'binary_test.bin_col': 'ffffffffffffffffffffffffffffffff'
|
|
201
|
+
},
|
|
202
|
+
WHERE: { 'binary_test.id': [C6C.EQUAL, 1] }
|
|
203
|
+
} as any, false);
|
|
204
|
+
|
|
205
|
+
const { params } = qb.build('binary_test');
|
|
206
|
+
const buf = (params as any[])[0];
|
|
207
|
+
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
208
|
+
expect((buf as Buffer).length).toBe(16);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -25,6 +25,15 @@ export class HttpExecutor<
|
|
|
25
25
|
>
|
|
26
26
|
extends Executor<G> {
|
|
27
27
|
|
|
28
|
+
private stripTableNameFromKeys(obj: Record<string, any>) {
|
|
29
|
+
const columns = (this.config.restModel as any).COLUMNS || {};
|
|
30
|
+
return Object.keys(obj || {}).reduce((acc: Record<string, any>, key) => {
|
|
31
|
+
const shortKey = columns[key] || key.split('.').pop();
|
|
32
|
+
acc[shortKey] = obj[key];
|
|
33
|
+
return acc;
|
|
34
|
+
}, {} as Record<string, any>);
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
public putState(
|
|
29
38
|
response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>,
|
|
30
39
|
request: RequestQueryBody<
|
|
@@ -35,11 +44,12 @@ export class HttpExecutor<
|
|
|
35
44
|
>,
|
|
36
45
|
callback: () => void
|
|
37
46
|
) {
|
|
47
|
+
const normalized = this.stripTableNameFromKeys(request as Record<string, any>);
|
|
38
48
|
this.config.reactBootstrap?.updateRestfulObjectArrays<G['RestTableInterface']>({
|
|
39
49
|
callback,
|
|
40
50
|
dataOrCallback: [
|
|
41
51
|
removeInvalidKeys<G['RestTableInterface']>({
|
|
42
|
-
...
|
|
52
|
+
...normalized,
|
|
43
53
|
...response?.data?.rest,
|
|
44
54
|
}, this.config.C6.TABLES)
|
|
45
55
|
],
|
|
@@ -76,15 +86,16 @@ export class HttpExecutor<
|
|
|
76
86
|
this.config.reactBootstrap?.updateRestfulObjectArrays<G['RestTableInterface']>({
|
|
77
87
|
callback,
|
|
78
88
|
dataOrCallback: undefined !== request.dataInsertMultipleRows
|
|
79
|
-
? request.dataInsertMultipleRows.map((
|
|
89
|
+
? request.dataInsertMultipleRows.map((row, index) => {
|
|
90
|
+
const normalizedRow = this.stripTableNameFromKeys(row);
|
|
80
91
|
return removeInvalidKeys<G['RestTableInterface']>({
|
|
81
|
-
...
|
|
92
|
+
...normalizedRow,
|
|
82
93
|
...(index === 0 ? response?.data?.rest : {}),
|
|
83
94
|
}, this.config.C6.TABLES)
|
|
84
95
|
})
|
|
85
96
|
: [
|
|
86
97
|
removeInvalidKeys<G['RestTableInterface']>({
|
|
87
|
-
...request,
|
|
98
|
+
...this.stripTableNameFromKeys(request as Record<string, any>),
|
|
88
99
|
...response?.data?.rest,
|
|
89
100
|
}, this.config.C6.TABLES)
|
|
90
101
|
],
|
|
@@ -103,10 +114,11 @@ export class HttpExecutor<
|
|
|
103
114
|
>,
|
|
104
115
|
callback: () => void
|
|
105
116
|
) {
|
|
117
|
+
const normalized = this.stripTableNameFromKeys(request as Record<string, any>);
|
|
106
118
|
this.config.reactBootstrap?.deleteRestfulObjectArrays<G['RestTableInterface']>({
|
|
107
119
|
callback,
|
|
108
120
|
dataOrCallback: [
|
|
109
|
-
|
|
121
|
+
removeInvalidKeys<G['RestTableInterface']>(normalized, this.config.C6.TABLES),
|
|
110
122
|
],
|
|
111
123
|
stateKey: this.config.restModel.TABLE_NAME,
|
|
112
124
|
uniqueObjectId: this.config.restModel.PRIMARY_SHORT as (keyof G['RestTableInterface'])[]
|
|
@@ -571,7 +583,8 @@ export class HttpExecutor<
|
|
|
571
583
|
switch (requestMethod) {
|
|
572
584
|
case GET:
|
|
573
585
|
response.data && reactBootstrap.updateRestfulObjectArrays<G['RestTableInterface']>({
|
|
574
|
-
dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest]
|
|
586
|
+
dataOrCallback: (Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest])
|
|
587
|
+
.map(r => this.stripTableNameFromKeys(r)),
|
|
575
588
|
stateKey: this.config.restModel.TABLE_NAME,
|
|
576
589
|
uniqueObjectId: this.config.restModel.PRIMARY_SHORT as (keyof G['RestTableInterface'])[],
|
|
577
590
|
callback
|
|
@@ -104,7 +104,8 @@ export abstract class ConditionBuilder<
|
|
|
104
104
|
if (typeof column === 'string' && column.includes('.')) {
|
|
105
105
|
const [tableName, colName] = column.split('.', 2);
|
|
106
106
|
const table = this.config.C6?.TABLES?.[tableName];
|
|
107
|
-
|
|
107
|
+
// Support both short-keyed and fully-qualified TYPE_VALIDATION entries
|
|
108
|
+
columnDef = table?.TYPE_VALIDATION?.[colName] ?? table?.TYPE_VALIDATION?.[`${tableName}.${colName}`];
|
|
108
109
|
}
|
|
109
110
|
const val = convertHexIfBinary(column, value, columnDef);
|
|
110
111
|
|