@technicity/data-service-generator 0.12.4 → 0.13.26
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 +9 -4
- package/dist/generation/generate.d.ts +1 -0
- package/dist/generation/generate.js +403 -68
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -5
- package/dist/ksql.js +24 -1
- package/dist/runtime/Cache.js +6 -3
- package/dist/runtime/IRuntime.d.ts +4 -2
- package/dist/runtime/RuntimeKSQL.js +25 -2
- package/dist/runtime/RuntimeMySQL.js +29 -3
- package/dist/runtime/RuntimeSQLite.d.ts +38 -0
- package/dist/runtime/RuntimeSQLite.js +135 -0
- package/dist/runtime/lib/MSSQL.js +25 -2
- package/dist/runtime/lib/addNullFallbacks.test.d.ts +1 -0
- package/dist/runtime/lib/addNullFallbacks.test.js +206 -0
- package/dist/runtime/lib/getSqlAst.js +46 -21
- package/dist/runtime/lib/runTransforms.test.d.ts +1 -0
- package/dist/runtime/lib/runTransforms.test.js +112 -0
- package/dist/runtime/lib/shared.js +127 -47
- package/dist/runtime/lib/stringifyWhere.js +38 -11
- package/dist/runtime/lib/stringifyWhere.test.d.ts +1 -0
- package/dist/runtime/lib/stringifyWhere.test.js +236 -0
- package/dist/runtime/lib/typeCastMSSQL.js +24 -1
- package/dist/traverseFieldArgs.test.d.ts +1 -0
- package/dist/traverseFieldArgs.test.js +72 -0
- package/package.json +13 -12
- package/dist/getFakeData.d.ts +0 -12
- package/dist/getFakeData.js +0 -90
- package/dist/getIsList.d.ts +0 -1
- package/dist/getIsList.js +0 -7
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const stringifyWhere_1 = require("./stringifyWhere");
|
|
9
|
+
(0, globals_1.describe)("stringifyWhere", () => {
|
|
10
|
+
const table = "Usr";
|
|
11
|
+
const dialect = "mysql";
|
|
12
|
+
const args = {};
|
|
13
|
+
(0, globals_1.test)("should work", () => {
|
|
14
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
15
|
+
where: { userId: 2, text: "foo" },
|
|
16
|
+
table,
|
|
17
|
+
dialect,
|
|
18
|
+
args
|
|
19
|
+
});
|
|
20
|
+
strict_1.default.deepEqual(result, "Usr.`userId` = 2 AND Usr.`text` = 'foo'");
|
|
21
|
+
});
|
|
22
|
+
(0, globals_1.test)("should handle empty object", () => {
|
|
23
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({ where: {}, table, dialect, args });
|
|
24
|
+
strict_1.default.deepEqual(result, "");
|
|
25
|
+
});
|
|
26
|
+
(0, globals_1.test)("should handle $and", () => {
|
|
27
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
28
|
+
where: { $and: [{ valid: true }, { text: "foo" }] },
|
|
29
|
+
table,
|
|
30
|
+
dialect,
|
|
31
|
+
args
|
|
32
|
+
});
|
|
33
|
+
strict_1.default.deepEqual(result, "(Usr.`valid` = 1 AND Usr.`text` = 'foo')");
|
|
34
|
+
});
|
|
35
|
+
(0, globals_1.test)("should handle $or", () => {
|
|
36
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
37
|
+
where: { $or: [{ valid: true }, { text: "foo" }] },
|
|
38
|
+
table,
|
|
39
|
+
dialect,
|
|
40
|
+
args
|
|
41
|
+
});
|
|
42
|
+
strict_1.default.deepEqual(result, "(Usr.`valid` = 1 OR Usr.`text` = 'foo')");
|
|
43
|
+
});
|
|
44
|
+
(0, globals_1.test)("should handle null", () => {
|
|
45
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
46
|
+
where: { userId: null },
|
|
47
|
+
table,
|
|
48
|
+
dialect,
|
|
49
|
+
args
|
|
50
|
+
});
|
|
51
|
+
strict_1.default.deepEqual(result, "Usr.`userId` IS NULL");
|
|
52
|
+
});
|
|
53
|
+
(0, globals_1.test)("should handle $neq", () => {
|
|
54
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
55
|
+
where: { userId: { $neq: 2 }, text: "foo" },
|
|
56
|
+
table,
|
|
57
|
+
dialect,
|
|
58
|
+
args
|
|
59
|
+
});
|
|
60
|
+
strict_1.default.deepEqual(result, "Usr.`userId` != 2 AND Usr.`text` = 'foo'");
|
|
61
|
+
});
|
|
62
|
+
(0, globals_1.test)("should handle $gt", () => {
|
|
63
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
64
|
+
where: { userId: { $gt: 2 }, text: "foo" },
|
|
65
|
+
table,
|
|
66
|
+
dialect,
|
|
67
|
+
args
|
|
68
|
+
});
|
|
69
|
+
strict_1.default.deepEqual(result, "Usr.`userId` > 2 AND Usr.`text` = 'foo'");
|
|
70
|
+
});
|
|
71
|
+
(0, globals_1.test)("should handle $gte", () => {
|
|
72
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
73
|
+
where: { userId: { $gte: 2 }, text: "foo" },
|
|
74
|
+
table,
|
|
75
|
+
dialect,
|
|
76
|
+
args
|
|
77
|
+
});
|
|
78
|
+
strict_1.default.deepEqual(result, "Usr.`userId` >= 2 AND Usr.`text` = 'foo'");
|
|
79
|
+
});
|
|
80
|
+
(0, globals_1.test)("should handle $lt", () => {
|
|
81
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
82
|
+
where: { userId: { $lt: 2 }, text: "foo" },
|
|
83
|
+
table,
|
|
84
|
+
dialect,
|
|
85
|
+
args
|
|
86
|
+
});
|
|
87
|
+
strict_1.default.deepEqual(result, "Usr.`userId` < 2 AND Usr.`text` = 'foo'");
|
|
88
|
+
});
|
|
89
|
+
(0, globals_1.test)("should handle $lte", () => {
|
|
90
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
91
|
+
where: { userId: { $lte: 2 }, text: "foo" },
|
|
92
|
+
table,
|
|
93
|
+
dialect,
|
|
94
|
+
args
|
|
95
|
+
});
|
|
96
|
+
strict_1.default.deepEqual(result, "Usr.`userId` <= 2 AND Usr.`text` = 'foo'");
|
|
97
|
+
});
|
|
98
|
+
(0, globals_1.test)("should handle $like", () => {
|
|
99
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
100
|
+
where: { text: { $like: "%foo%" } },
|
|
101
|
+
table,
|
|
102
|
+
dialect,
|
|
103
|
+
args
|
|
104
|
+
});
|
|
105
|
+
strict_1.default.deepEqual(result, "Usr.`text` LIKE '%foo%'");
|
|
106
|
+
});
|
|
107
|
+
(0, globals_1.test)("should handle $nlike", () => {
|
|
108
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
109
|
+
where: { text: { $nlike: "%foo%" } },
|
|
110
|
+
table,
|
|
111
|
+
dialect,
|
|
112
|
+
args
|
|
113
|
+
});
|
|
114
|
+
strict_1.default.deepEqual(result, "Usr.`text` NOT LIKE '%foo%'");
|
|
115
|
+
});
|
|
116
|
+
(0, globals_1.test)("should handle $in", () => {
|
|
117
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
118
|
+
where: { userId: { $in: [1, 2] }, text: "foo" },
|
|
119
|
+
table,
|
|
120
|
+
dialect,
|
|
121
|
+
args
|
|
122
|
+
});
|
|
123
|
+
strict_1.default.deepEqual(result, "Usr.`userId` IN (1,2) AND Usr.`text` = 'foo'");
|
|
124
|
+
});
|
|
125
|
+
(0, globals_1.test)("should handle empty $in", () => {
|
|
126
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
127
|
+
where: { userId: { $in: [] }, text: "foo" },
|
|
128
|
+
table,
|
|
129
|
+
dialect,
|
|
130
|
+
args
|
|
131
|
+
});
|
|
132
|
+
strict_1.default.deepEqual(result, "(1=0) AND Usr.`text` = 'foo'");
|
|
133
|
+
});
|
|
134
|
+
(0, globals_1.test)("should handle $nin", () => {
|
|
135
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
136
|
+
where: { userId: { $nin: [1, 2] }, text: "foo" },
|
|
137
|
+
table,
|
|
138
|
+
dialect,
|
|
139
|
+
args
|
|
140
|
+
});
|
|
141
|
+
strict_1.default.deepEqual(result, "Usr.`userId` NOT IN (1,2) AND Usr.`text` = 'foo'");
|
|
142
|
+
});
|
|
143
|
+
(0, globals_1.test)("should handle empty $nin", () => {
|
|
144
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
145
|
+
where: { userId: { $nin: [] }, text: "foo" },
|
|
146
|
+
table,
|
|
147
|
+
dialect,
|
|
148
|
+
args
|
|
149
|
+
});
|
|
150
|
+
strict_1.default.deepEqual(result, "(1=1) AND Usr.`text` = 'foo'");
|
|
151
|
+
});
|
|
152
|
+
(0, globals_1.test)("should handle $btwn", () => {
|
|
153
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
154
|
+
where: { userId: { $btwn: [1, 20] }, text: "foo" },
|
|
155
|
+
table,
|
|
156
|
+
dialect,
|
|
157
|
+
args
|
|
158
|
+
});
|
|
159
|
+
strict_1.default.deepEqual(result, "Usr.`userId` BETWEEN 1 AND 20 AND Usr.`text` = 'foo'");
|
|
160
|
+
});
|
|
161
|
+
(0, globals_1.test)("should handle $nbtwn", () => {
|
|
162
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
163
|
+
where: { userId: { $nbtwn: [1, 20] }, text: "foo" },
|
|
164
|
+
table,
|
|
165
|
+
dialect,
|
|
166
|
+
args
|
|
167
|
+
});
|
|
168
|
+
strict_1.default.deepEqual(result, "Usr.`userId` NOT BETWEEN 1 AND 20 AND Usr.`text` = 'foo'");
|
|
169
|
+
});
|
|
170
|
+
(0, globals_1.test)("should handle nested $and and $or", () => {
|
|
171
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
172
|
+
where: {
|
|
173
|
+
$and: [
|
|
174
|
+
{ userId: { $gt: 2 } },
|
|
175
|
+
{ $or: [{ text: { $like: "foo" } }, { text: { $like: "bar" } }] },
|
|
176
|
+
{ $and: [{ lala: "lala" }, { oioi: "oioi" }] }
|
|
177
|
+
]
|
|
178
|
+
},
|
|
179
|
+
table,
|
|
180
|
+
dialect,
|
|
181
|
+
args
|
|
182
|
+
});
|
|
183
|
+
strict_1.default.deepEqual(result, "(Usr.`userId` > 2 AND (Usr.`text` LIKE 'foo' OR Usr.`text` LIKE 'bar') AND (Usr.`lala` = 'lala' AND Usr.`oioi` = 'oioi'))");
|
|
184
|
+
});
|
|
185
|
+
(0, globals_1.test)("should throw on invalid operator", () => {
|
|
186
|
+
strict_1.default.throws(() => (0, stringifyWhere_1.stringifyWhere)({
|
|
187
|
+
where: { foo: { $foo: 3 } },
|
|
188
|
+
table,
|
|
189
|
+
dialect,
|
|
190
|
+
args
|
|
191
|
+
}), (error) => {
|
|
192
|
+
(0, strict_1.default)(error instanceof Error);
|
|
193
|
+
(0, strict_1.default)(error.message.startsWith("Invalid operator:"));
|
|
194
|
+
return true;
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
(0, globals_1.test)("should throw on more than 1 key for $and", () => {
|
|
198
|
+
strict_1.default.throws(() => (0, stringifyWhere_1.stringifyWhere)({
|
|
199
|
+
where: { $and: [{ foo: "bar" }, { bar: "baz" }], foo: "bar" },
|
|
200
|
+
table,
|
|
201
|
+
dialect,
|
|
202
|
+
args
|
|
203
|
+
}), (error) => {
|
|
204
|
+
(0, strict_1.default)(error instanceof Error);
|
|
205
|
+
(0, strict_1.default)(error.message.startsWith("Must have 1 key:"));
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
(0, globals_1.test)("ignores undefined values", () => {
|
|
210
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
211
|
+
where: { $or: [{ foo: "bar" }, { bar: null }, { baz: undefined }] },
|
|
212
|
+
table,
|
|
213
|
+
dialect,
|
|
214
|
+
args
|
|
215
|
+
});
|
|
216
|
+
strict_1.default.deepEqual(result, "(Usr.`foo` = 'bar' OR Usr.`bar` IS NULL)");
|
|
217
|
+
});
|
|
218
|
+
(0, globals_1.test)("handles empty $and", () => {
|
|
219
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
220
|
+
where: { $and: [] },
|
|
221
|
+
table,
|
|
222
|
+
dialect,
|
|
223
|
+
args
|
|
224
|
+
});
|
|
225
|
+
strict_1.default.deepEqual(result, "");
|
|
226
|
+
});
|
|
227
|
+
(0, globals_1.test)("handles empty $or", () => {
|
|
228
|
+
const result = (0, stringifyWhere_1.stringifyWhere)({
|
|
229
|
+
where: { $or: [] },
|
|
230
|
+
table,
|
|
231
|
+
dialect,
|
|
232
|
+
args
|
|
233
|
+
});
|
|
234
|
+
strict_1.default.deepEqual(result, "");
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
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
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.typeCastMSSQL = void 0;
|
|
4
|
-
const mssql = require("mssql");
|
|
27
|
+
const mssql = __importStar(require("mssql"));
|
|
5
28
|
// TODO: see https://github.com/tediousjs/node-mssql/pull/1171
|
|
6
29
|
function typeCastMSSQL(customTypeCast) {
|
|
7
30
|
return function (result, meta) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const _1 = require(".");
|
|
9
|
+
const addWhereValidTrue_1 = require("../test/addWhereValidTrue");
|
|
10
|
+
(0, globals_1.describe)("traverseFieldArgs", () => {
|
|
11
|
+
(0, globals_1.test)("should work", () => {
|
|
12
|
+
const fields = [
|
|
13
|
+
"id",
|
|
14
|
+
"uuid",
|
|
15
|
+
{
|
|
16
|
+
name: "business",
|
|
17
|
+
fields: ["id", "uuid", "name"]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "sessionList",
|
|
21
|
+
fields: ["id", "archived", { name: "fooList", fields: ["id", "uuid"] }],
|
|
22
|
+
args: {
|
|
23
|
+
$where: { archived: false },
|
|
24
|
+
$orderBy: { id: "desc" }
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "usrList",
|
|
29
|
+
fields: ["firstName", "lastName", "password"],
|
|
30
|
+
args: {
|
|
31
|
+
$where: { valid: false, archived: false },
|
|
32
|
+
$orderBy: { id: "desc" }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
(0, _1.traverseFieldArgs)(fields, addWhereValidTrue_1.addWhereValidTrue);
|
|
37
|
+
strict_1.default.deepEqual(fields, [
|
|
38
|
+
"id",
|
|
39
|
+
"uuid",
|
|
40
|
+
{
|
|
41
|
+
name: "business",
|
|
42
|
+
fields: ["id", "uuid", "name"],
|
|
43
|
+
args: { $where: { valid: true } }
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "sessionList",
|
|
47
|
+
fields: [
|
|
48
|
+
"id",
|
|
49
|
+
"archived",
|
|
50
|
+
{
|
|
51
|
+
name: "fooList",
|
|
52
|
+
fields: ["id", "uuid"],
|
|
53
|
+
args: { $where: { valid: true } }
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
args: {
|
|
57
|
+
$where: { valid: true, archived: false },
|
|
58
|
+
$orderBy: { id: "desc" }
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "usrList",
|
|
63
|
+
fields: ["firstName", "lastName", "password"],
|
|
64
|
+
args: {
|
|
65
|
+
// Should not be overwritten
|
|
66
|
+
$where: { valid: false, archived: false },
|
|
67
|
+
$orderBy: { id: "desc" }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
});
|
package/package.json
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@technicity/data-service-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.26",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
8
8
|
"scripts": {
|
|
9
|
-
"compile": "rm -rf dist && tsc",
|
|
9
|
+
"compile": "rm -rf dist && tsc && cp -r dist/src/* dist && rm -rf dist/src && rm -rf dist/test",
|
|
10
10
|
"publish:next": "npm version prerelease --preid next",
|
|
11
11
|
"preversion": "npm run compile",
|
|
12
|
-
"
|
|
13
|
-
"test:
|
|
14
|
-
"generate": "npm run compile && concurrently \"node ./test/mysql/generate.js\" \"node ./test/mysql8/generate.js\"",
|
|
15
|
-
"test": "npm run generate && mocha ./test/addNullFallbacks.test.js && mocha ./test/stringifyWhere.test.js && npm run test:sdk",
|
|
16
|
-
"test:prepare": "docker-compose down --volumes && docker-compose up -d --build",
|
|
17
|
-
"test:sdk": "mocha --inspect=0.0.0.0:9229 ./test/test.js"
|
|
12
|
+
"test": "jest ./test/test.ts",
|
|
13
|
+
"test:unit": "jest ./src"
|
|
18
14
|
},
|
|
19
15
|
"dependencies": {
|
|
16
|
+
"@types/better-sqlite3": "^7.6.3",
|
|
17
|
+
"better-sqlite3": "^8.1.0",
|
|
20
18
|
"bluebird": "^3.7.2",
|
|
21
19
|
"change-case": "^4.1.1",
|
|
22
20
|
"fs-extra": "10.0.0",
|
|
@@ -31,21 +29,24 @@
|
|
|
31
29
|
"mysql": "^2.18.1",
|
|
32
30
|
"prettier": "^2.1.2",
|
|
33
31
|
"sqlstring": "^2.3.2",
|
|
32
|
+
"sqlstring-sqlite": "^0.1.1",
|
|
34
33
|
"tsqlstring": "^1.0.1",
|
|
35
34
|
"uuid": "^8.3.2"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
37
|
+
"@jest/globals": "^29.4.3",
|
|
38
|
+
"@swc/core": "^1.3.36",
|
|
39
|
+
"@swc/jest": "^0.2.24",
|
|
38
40
|
"@types/fs-extra": "9.0.13",
|
|
39
41
|
"@types/lodash": "4.14.177",
|
|
40
42
|
"@types/mssql": "^6.0.7",
|
|
41
|
-
"@types/node": "14.
|
|
43
|
+
"@types/node": "^18.14.1",
|
|
42
44
|
"@types/prettier": "^2.1.5",
|
|
43
45
|
"@types/sqlstring": "^2.2.1",
|
|
44
46
|
"@types/uuid": "^8.3.1",
|
|
45
|
-
"
|
|
46
|
-
"env-cmd": "^10.1.0",
|
|
47
|
-
"mocha": "9.1.3",
|
|
47
|
+
"jest": "^29.4.3",
|
|
48
48
|
"sinon": "12.0.1",
|
|
49
|
+
"testcontainers": "^9.1.3",
|
|
49
50
|
"typescript": "4.6.4"
|
|
50
51
|
}
|
|
51
52
|
}
|
package/dist/getFakeData.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type IArtifacts } from "./runtime/IRuntime";
|
|
2
|
-
export declare function getFakeData(input: {
|
|
3
|
-
model: string;
|
|
4
|
-
select?: unknown[];
|
|
5
|
-
isList: boolean;
|
|
6
|
-
artifacts: IArtifacts;
|
|
7
|
-
operation: string | null;
|
|
8
|
-
}): {
|
|
9
|
-
[k: string]: unknown;
|
|
10
|
-
} | {
|
|
11
|
-
[k: string]: unknown;
|
|
12
|
-
}[];
|
package/dist/getFakeData.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFakeData = void 0;
|
|
4
|
-
function getFakeData(input) {
|
|
5
|
-
const { model, select, isList, artifacts, operation } = input;
|
|
6
|
-
const tableMeta = artifacts[model];
|
|
7
|
-
if (tableMeta === void 0) {
|
|
8
|
-
throw new Error(`Model ${model} not found.`);
|
|
9
|
-
}
|
|
10
|
-
const { fields } = tableMeta;
|
|
11
|
-
let data = {};
|
|
12
|
-
if (select == null) {
|
|
13
|
-
data = fields.reduce((acc, x) => {
|
|
14
|
-
if (x.kind === "scalar") {
|
|
15
|
-
acc[x.name] = getValue(x.type);
|
|
16
|
-
return acc;
|
|
17
|
-
}
|
|
18
|
-
else if (x.kind === "enum") {
|
|
19
|
-
acc[x.name] = x.values[0];
|
|
20
|
-
return acc;
|
|
21
|
-
}
|
|
22
|
-
return acc;
|
|
23
|
-
}, data);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
for (let x of select) {
|
|
27
|
-
if (!(typeof x === "string" || (typeof x === "object" && x != null))) {
|
|
28
|
-
throw new Error(`Invalid select: ${x}`);
|
|
29
|
-
}
|
|
30
|
-
const name = typeof x === "string" ? x : x.name;
|
|
31
|
-
const fieldName = x.as ?? name;
|
|
32
|
-
const field = fields.find((x) => x.name === name);
|
|
33
|
-
if (field == null) {
|
|
34
|
-
throw new Error(`Field not found: ${name}`);
|
|
35
|
-
}
|
|
36
|
-
if (field.kind === "scalar") {
|
|
37
|
-
data[fieldName] = getValue(field.type);
|
|
38
|
-
}
|
|
39
|
-
else if (field.kind === "enum") {
|
|
40
|
-
data[fieldName] = field.values[0];
|
|
41
|
-
}
|
|
42
|
-
else if (field.kind === "object") {
|
|
43
|
-
if (!(typeof x === "object" && x != null)) {
|
|
44
|
-
throw new Error(`Invalid select: ${x}`);
|
|
45
|
-
}
|
|
46
|
-
data[fieldName] = getFakeData({
|
|
47
|
-
model: field.type,
|
|
48
|
-
select: x.fields,
|
|
49
|
-
artifacts,
|
|
50
|
-
isList: field.isList,
|
|
51
|
-
// Only relevant at top-level
|
|
52
|
-
operation: null
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new Error(`Unhandled kind: ${field?.kind}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
let out = isList ? [data] : data;
|
|
61
|
-
if (typeof operation === "string" && operation.endsWith("Paginated")) {
|
|
62
|
-
out = {
|
|
63
|
-
paginationInfo: {
|
|
64
|
-
hasPreviousPage: false,
|
|
65
|
-
hasNextPage: false,
|
|
66
|
-
startCursor: "STUB",
|
|
67
|
-
endCursor: "STUB",
|
|
68
|
-
totalCount: 1
|
|
69
|
-
},
|
|
70
|
-
results: out
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return out;
|
|
74
|
-
}
|
|
75
|
-
exports.getFakeData = getFakeData;
|
|
76
|
-
function getValue(type) {
|
|
77
|
-
if (type === "boolean") {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
if (type === "number") {
|
|
81
|
-
return 54.9434;
|
|
82
|
-
}
|
|
83
|
-
if (type === "integer") {
|
|
84
|
-
return 4;
|
|
85
|
-
}
|
|
86
|
-
if (type === "string") {
|
|
87
|
-
return "foo";
|
|
88
|
-
}
|
|
89
|
-
throw new Error(`Unhandled type: ${type}`);
|
|
90
|
-
}
|
package/dist/getIsList.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getIsList(operation: string): boolean;
|
package/dist/getIsList.js
DELETED