@technicity/data-service-generator 0.14.1 → 0.14.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.
- package/README.md +2 -0
- package/dist/generation/generate.d.ts +1 -0
- package/dist/generation/generate.js +916 -309
- package/dist/runtime/Cache.js +6 -3
- package/dist/runtime/IRuntime.d.ts +46 -17
- package/dist/runtime/RuntimeMSSQL.d.ts +7 -1
- package/dist/runtime/RuntimeMSSQL.js +4 -4
- package/dist/runtime/RuntimeMySQL.d.ts +3 -1
- package/dist/runtime/RuntimeMySQL.js +33 -7
- package/dist/runtime/RuntimeSQLite.d.ts +38 -0
- package/dist/runtime/RuntimeSQLite.js +135 -0
- package/dist/runtime/lib/MSSQL.d.ts +2 -1
- package/dist/runtime/lib/MSSQL.js +36 -8
- package/dist/runtime/lib/MySQL.d.ts +1 -1
- package/dist/runtime/lib/MySQL.js +15 -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 +158 -121
- package/dist/runtime/lib/shared.d.ts +1 -2
- package/dist/runtime/lib/shared.js +180 -71
- package/dist/runtime/lib/stringifyWhere.js +39 -12
- 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.d.ts +2 -2
- package/dist/traverseFieldArgs.js +8 -3
- package/dist/traverseFieldArgs.test.d.ts +1 -0
- package/dist/traverseFieldArgs.test.js +56 -0
- package/package.json +3 -6
- package/dist/ksql.d.ts +0 -15
- package/dist/ksql.js +0 -55
- package/dist/runtime/RuntimeKSQL.d.ts +0 -19
- package/dist/runtime/RuntimeKSQL.js +0 -446
- package/dist/runtime/lib/runTransforms.d.ts +0 -2
- package/dist/runtime/lib/runTransforms.js +0 -36
|
@@ -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) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IArgs,
|
|
2
|
-
export declare function traverseFieldArgs(fields:
|
|
1
|
+
import { IArgs, TSelect } from "./runtime/IRuntime";
|
|
2
|
+
export declare function traverseFieldArgs(fields: TSelect, cb: (args: IArgs | undefined) => IArgs): void;
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.traverseFieldArgs = void 0;
|
|
4
4
|
function traverseFieldArgs(fields, cb) {
|
|
5
|
-
|
|
5
|
+
const values = Object.values(fields);
|
|
6
|
+
for (let x of values) {
|
|
6
7
|
if (typeof x !== "object") {
|
|
7
8
|
continue;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const fields = x.$fields;
|
|
11
|
+
if (fields == null) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
cb(x);
|
|
15
|
+
traverseFieldArgs(fields, cb);
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
exports.traverseFieldArgs = traverseFieldArgs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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: true,
|
|
14
|
+
uuid: true,
|
|
15
|
+
business: { $fields: { id: true, uuid: true, name: true } },
|
|
16
|
+
sessionList: {
|
|
17
|
+
$fields: {
|
|
18
|
+
id: true,
|
|
19
|
+
archived: true,
|
|
20
|
+
fooList: { $fields: { id: true, uuid: true } }
|
|
21
|
+
},
|
|
22
|
+
$where: { archived: false },
|
|
23
|
+
$orderBy: { id: "desc" }
|
|
24
|
+
},
|
|
25
|
+
usrList: {
|
|
26
|
+
$fields: { firstName: true, lastName: true, password: true },
|
|
27
|
+
$where: { valid: false, archived: false },
|
|
28
|
+
$orderBy: { id: "desc" }
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
(0, _1.traverseFieldArgs)(fields, addWhereValidTrue_1.addWhereValidTrue);
|
|
32
|
+
strict_1.default.deepEqual(fields, {
|
|
33
|
+
id: true,
|
|
34
|
+
uuid: true,
|
|
35
|
+
business: {
|
|
36
|
+
$fields: { id: true, uuid: true, name: true },
|
|
37
|
+
$where: { valid: true }
|
|
38
|
+
},
|
|
39
|
+
sessionList: {
|
|
40
|
+
$fields: {
|
|
41
|
+
id: true,
|
|
42
|
+
archived: true,
|
|
43
|
+
fooList: { $fields: { id: true, uuid: true }, $where: { valid: true } }
|
|
44
|
+
},
|
|
45
|
+
$where: { valid: true, archived: false },
|
|
46
|
+
$orderBy: { id: "desc" }
|
|
47
|
+
},
|
|
48
|
+
usrList: {
|
|
49
|
+
$fields: { firstName: true, lastName: true, password: true },
|
|
50
|
+
// Should not be overwritten
|
|
51
|
+
$where: { valid: false, archived: false },
|
|
52
|
+
$orderBy: { id: "desc" }
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@technicity/data-service-generator",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"json-schema-to-typescript": "10.1.5",
|
|
26
26
|
"lodash": "^4.17.20",
|
|
27
27
|
"loglevel": "^1.8.1",
|
|
28
|
-
"mssql": "
|
|
28
|
+
"mssql": "10.0.0",
|
|
29
29
|
"mysql": "^2.18.1",
|
|
30
30
|
"prettier": "^2.1.2",
|
|
31
31
|
"sqlstring": "^2.3.2",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@swc/jest": "^0.2.24",
|
|
40
40
|
"@types/fs-extra": "9.0.13",
|
|
41
41
|
"@types/lodash": "4.14.177",
|
|
42
|
-
"@types/mssql": "
|
|
42
|
+
"@types/mssql": "8.1.2",
|
|
43
43
|
"@types/node": "^18.14.1",
|
|
44
44
|
"@types/prettier": "^2.1.5",
|
|
45
45
|
"@types/sqlstring": "^2.2.1",
|
|
@@ -48,8 +48,5 @@
|
|
|
48
48
|
"sinon": "12.0.1",
|
|
49
49
|
"testcontainers": "^9.1.3",
|
|
50
50
|
"typescript": "4.6.4"
|
|
51
|
-
},
|
|
52
|
-
"resolutions": {
|
|
53
|
-
"xml2js": "0.5.0"
|
|
54
51
|
}
|
|
55
52
|
}
|
package/dist/ksql.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare type THeaders = {
|
|
2
|
-
[k: string]: any;
|
|
3
|
-
};
|
|
4
|
-
export declare class KSQL {
|
|
5
|
-
hostname: string;
|
|
6
|
-
port: number;
|
|
7
|
-
headers?: THeaders;
|
|
8
|
-
constructor(options: {
|
|
9
|
-
hostname: string;
|
|
10
|
-
port: number;
|
|
11
|
-
headers?: THeaders;
|
|
12
|
-
});
|
|
13
|
-
streamQuery(s: string): Promise<any[]>;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/dist/ksql.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KSQL = void 0;
|
|
4
|
-
const http2 = require("http2");
|
|
5
|
-
class KSQL {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.hostname = options.hostname;
|
|
8
|
-
this.port = options.port;
|
|
9
|
-
this.headers = options.headers;
|
|
10
|
-
}
|
|
11
|
-
async streamQuery(s) {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const reqBody = JSON.stringify({
|
|
14
|
-
sql: s,
|
|
15
|
-
properties: {
|
|
16
|
-
"ksql.streams.auto.offset.reset": "earliest",
|
|
17
|
-
"ksql.query.pull.table.scan.enabled": true,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
const client = http2.connect(`https://${this.hostname}:${this.port}`);
|
|
21
|
-
const req = client.request({
|
|
22
|
-
[http2.constants.HTTP2_HEADER_SCHEME]: "https",
|
|
23
|
-
"Content-Type": "application/json",
|
|
24
|
-
"Content-Length": reqBody.length,
|
|
25
|
-
":method": "POST",
|
|
26
|
-
":path": `/query-stream`,
|
|
27
|
-
...this.headers,
|
|
28
|
-
});
|
|
29
|
-
req.setEncoding("utf8");
|
|
30
|
-
let columnNames = [];
|
|
31
|
-
let rows = [];
|
|
32
|
-
req.on("data", (d) => {
|
|
33
|
-
const resData = JSON.parse(d);
|
|
34
|
-
if (resData.error_code) {
|
|
35
|
-
return reject(new Error(resData.message));
|
|
36
|
-
}
|
|
37
|
-
if (resData.columnNames) {
|
|
38
|
-
columnNames = resData.columnNames;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
let out = {};
|
|
42
|
-
resData.forEach((rd, i) => {
|
|
43
|
-
out[columnNames[i]] = rd;
|
|
44
|
-
});
|
|
45
|
-
rows.push(out);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
req.on("close", () => resolve(rows));
|
|
49
|
-
req.on("error", (error) => reject(error));
|
|
50
|
-
req.write(reqBody);
|
|
51
|
-
req.end();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.KSQL = KSQL;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, TDbCall } from "./IRuntime";
|
|
2
|
-
import { KSQL } from "../ksql";
|
|
3
|
-
declare type TGetTableName = (table: string) => string;
|
|
4
|
-
export declare class RuntimeKSQL implements IRuntime {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(clientOpts: ConstructorParameters<typeof KSQL>[0], otherOpts: {
|
|
7
|
-
getBaseTableName: TGetTableName;
|
|
8
|
-
getMaterializedViewName: TGetTableName;
|
|
9
|
-
doNotUseMaterializedViews?: boolean;
|
|
10
|
-
_dbCall: TDbCall;
|
|
11
|
-
}, artifacts: IArtifacts);
|
|
12
|
-
resolve(input: TResolveParams): Promise<any>;
|
|
13
|
-
$queryRaw(sql: string, values?: any[]): Promise<any>;
|
|
14
|
-
$use(middleware: TMiddleware): Promise<void>;
|
|
15
|
-
$whereNeedsProcessing(where: any): boolean;
|
|
16
|
-
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
17
|
-
$shutdown(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export {};
|