@carbonorm/carbonnode 3.7.6 → 3.7.8
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/README.md +2 -1
- package/dist/api/orm/builders/AggregateBuilder.d.ts +1 -0
- package/dist/api/types/ormInterfaces.d.ts +2 -2
- package/dist/api/utils/cacheManager.d.ts +1 -1
- package/dist/api/utils/normalizeSingularRequest.d.ts +10 -0
- package/dist/index.cjs.js +182 -32
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +183 -34
- package/dist/index.esm.js.map +1 -1
- package/package.json +11 -6
- package/scripts/assets/handlebars/C6.test.ts.handlebars +55 -80
- package/scripts/assets/handlebars/C6.ts.handlebars +28 -2
- package/scripts/generateRestBindings.cjs +17 -6
- package/scripts/generateRestBindings.ts +22 -8
- package/src/__tests__/fixtures/c6.fixture.ts +74 -0
- package/src/__tests__/normalizeSingularRequest.test.ts +105 -0
- package/src/__tests__/sakila-db/C6.js +1487 -0
- package/src/__tests__/sakila-db/C6.test.ts +63 -0
- package/src/__tests__/sakila-db/C6.ts +2206 -0
- package/src/__tests__/sakila-db/sakila-data.sql +46444 -0
- package/src/__tests__/sakila-db/sakila-schema.sql +686 -0
- package/src/__tests__/sakila-db/sakila.mwb +0 -0
- package/src/__tests__/sakila.generated.test.ts +46 -0
- package/src/__tests__/sqlBuilders.complex.test.ts +134 -0
- package/src/__tests__/sqlBuilders.test.ts +121 -0
- package/src/api/convertForRequestBody.ts +1 -1
- package/src/api/executors/HttpExecutor.ts +14 -3
- package/src/api/executors/SqlExecutor.ts +14 -1
- package/src/api/orm/builders/AggregateBuilder.ts +3 -0
- package/src/api/orm/builders/ConditionBuilder.ts +34 -11
- package/src/api/orm/builders/PaginationBuilder.ts +10 -4
- package/src/api/orm/queries/SelectQueryBuilder.ts +3 -0
- package/src/api/orm/queries/UpdateQueryBuilder.ts +2 -1
- package/src/api/types/ormInterfaces.ts +3 -4
- package/src/api/utils/cacheManager.ts +1 -1
- package/src/api/utils/normalizeSingularRequest.ts +144 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import mysql from 'mysql2/promise';
|
|
2
|
+
import {
|
|
3
|
+
checkAllRequestsComplete,
|
|
4
|
+
} from '@carbonorm/carbonnode';
|
|
5
|
+
import {
|
|
6
|
+
C6,
|
|
7
|
+
GLOBAL_REST_PARAMETERS,
|
|
8
|
+
} from './C6.js';
|
|
9
|
+
import {
|
|
10
|
+
describe,
|
|
11
|
+
it,
|
|
12
|
+
expect,
|
|
13
|
+
beforeAll,
|
|
14
|
+
afterAll,
|
|
15
|
+
} from 'vitest';
|
|
16
|
+
|
|
17
|
+
function toPascalCase(name) {
|
|
18
|
+
return name.replace(/(^|_)([a-z])/g, (_, __, c) => c.toUpperCase());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function waitForRequests(timeout = 10000) {
|
|
22
|
+
const start = Date.now();
|
|
23
|
+
while (!checkAllRequestsComplete()) {
|
|
24
|
+
if (Date.now() - start > timeout) {
|
|
25
|
+
throw new Error('pending requests did not settle');
|
|
26
|
+
}
|
|
27
|
+
await new Promise((res) => setTimeout(res, 1000));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('sakila-db generated C6 bindings', () => {
|
|
32
|
+
let pool;
|
|
33
|
+
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
pool = mysql.createPool({
|
|
36
|
+
host: '127.0.0.1',
|
|
37
|
+
user: 'root',
|
|
38
|
+
password: 'password',
|
|
39
|
+
database: 'sakila',
|
|
40
|
+
});
|
|
41
|
+
GLOBAL_REST_PARAMETERS.mysqlPool = pool;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterAll(async () => {
|
|
45
|
+
await pool.end();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
for (const [shortName] of Object.entries(C6.TABLES)) {
|
|
49
|
+
const restBinding = C6.ORM[toPascalCase(shortName)];
|
|
50
|
+
if (!restBinding) continue;
|
|
51
|
+
|
|
52
|
+
it(`[${shortName}] GET`, async () => {
|
|
53
|
+
const result = await restBinding.Get({
|
|
54
|
+
SELECT: ['*'],
|
|
55
|
+
[C6.PAGINATION]: { [C6.LIMIT]: 1 },
|
|
56
|
+
} as any);
|
|
57
|
+
const data = result?.data ?? result;
|
|
58
|
+
expect(Array.isArray(data?.rest)).toBe(true);
|
|
59
|
+
await waitForRequests();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|