@technicity/data-service-generator 0.14.1 → 0.14.2

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.
Files changed (34) hide show
  1. package/dist/generation/generate.d.ts +1 -0
  2. package/dist/generation/generate.js +916 -309
  3. package/dist/runtime/Cache.js +6 -3
  4. package/dist/runtime/IRuntime.d.ts +46 -17
  5. package/dist/runtime/RuntimeMSSQL.d.ts +7 -1
  6. package/dist/runtime/RuntimeMSSQL.js +4 -4
  7. package/dist/runtime/RuntimeMySQL.d.ts +3 -1
  8. package/dist/runtime/RuntimeMySQL.js +33 -7
  9. package/dist/runtime/RuntimeSQLite.d.ts +38 -0
  10. package/dist/runtime/RuntimeSQLite.js +135 -0
  11. package/dist/runtime/lib/MSSQL.d.ts +2 -1
  12. package/dist/runtime/lib/MSSQL.js +36 -8
  13. package/dist/runtime/lib/MySQL.d.ts +1 -1
  14. package/dist/runtime/lib/MySQL.js +15 -2
  15. package/dist/runtime/lib/addNullFallbacks.test.d.ts +1 -0
  16. package/dist/runtime/lib/addNullFallbacks.test.js +206 -0
  17. package/dist/runtime/lib/getSqlAst.js +158 -121
  18. package/dist/runtime/lib/shared.d.ts +1 -2
  19. package/dist/runtime/lib/shared.js +180 -71
  20. package/dist/runtime/lib/stringifyWhere.js +39 -12
  21. package/dist/runtime/lib/stringifyWhere.test.d.ts +1 -0
  22. package/dist/runtime/lib/stringifyWhere.test.js +236 -0
  23. package/dist/runtime/lib/typeCastMSSQL.js +24 -1
  24. package/dist/traverseFieldArgs.d.ts +2 -2
  25. package/dist/traverseFieldArgs.js +8 -3
  26. package/dist/traverseFieldArgs.test.d.ts +1 -0
  27. package/dist/traverseFieldArgs.test.js +56 -0
  28. package/package.json +1 -1
  29. package/dist/ksql.d.ts +0 -15
  30. package/dist/ksql.js +0 -55
  31. package/dist/runtime/RuntimeKSQL.d.ts +0 -19
  32. package/dist/runtime/RuntimeKSQL.js +0 -446
  33. package/dist/runtime/lib/runTransforms.d.ts +0 -2
  34. package/dist/runtime/lib/runTransforms.js +0 -36
@@ -1,446 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _RuntimeKSQL_ksql, _RuntimeKSQL_middlewareHandler, _RuntimeKSQL_dbCall, _RuntimeKSQL_formatQuery, _RuntimeKSQL_getBaseTableName, _RuntimeKSQL_getMaterializedViewName, _RuntimeKSQL_doNotUseMaterializedViews;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RuntimeKSQL = void 0;
16
- const SqlString = require("sqlstring");
17
- const async_hooks_1 = require("async_hooks");
18
- const _ = require("lodash");
19
- const graphql_relay_1 = require("graphql-relay");
20
- const shared_1 = require("./lib/shared");
21
- const ksql_1 = require("../ksql");
22
- const SDKNotFoundError_1 = require("./lib/SDKNotFoundError");
23
- const stringifyWhere_1 = require("./lib/stringifyWhere");
24
- const cursor_1 = require("./lib/cursor");
25
- const escapeId = SqlString.escapeId.bind(SqlString);
26
- class RuntimeKSQL {
27
- constructor(clientOpts, otherOpts, artifacts) {
28
- _RuntimeKSQL_ksql.set(this, void 0);
29
- _RuntimeKSQL_middlewareHandler.set(this, void 0);
30
- _RuntimeKSQL_dbCall.set(this, void 0);
31
- _RuntimeKSQL_formatQuery.set(this, void 0);
32
- _RuntimeKSQL_getBaseTableName.set(this, void 0);
33
- _RuntimeKSQL_getMaterializedViewName.set(this, void 0);
34
- _RuntimeKSQL_doNotUseMaterializedViews.set(this, void 0);
35
- __classPrivateFieldSet(this, _RuntimeKSQL_ksql, new ksql_1.KSQL(clientOpts ?? {}), "f");
36
- __classPrivateFieldSet(this, _RuntimeKSQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
37
- __classPrivateFieldSet(this, _RuntimeKSQL_dbCall, typeof otherOpts._dbCall === "function"
38
- ? (q) => otherOpts._dbCall(q).then(mapResult)
39
- : (q) => __classPrivateFieldGet(this, _RuntimeKSQL_ksql, "f").streamQuery(q).then(mapResult), "f");
40
- __classPrivateFieldSet(this, _RuntimeKSQL_getBaseTableName, otherOpts.getBaseTableName, "f");
41
- __classPrivateFieldSet(this, _RuntimeKSQL_getMaterializedViewName, otherOpts.getMaterializedViewName, "f");
42
- __classPrivateFieldSet(this, _RuntimeKSQL_doNotUseMaterializedViews, otherOpts.doNotUseMaterializedViews ?? false, "f");
43
- __classPrivateFieldSet(this, _RuntimeKSQL_formatQuery, SqlString.format.bind(SqlString), "f");
44
- }
45
- async resolve(input) {
46
- return resolve(input, __classPrivateFieldGet(this, _RuntimeKSQL_dbCall, "f").bind(this), __classPrivateFieldGet(this, _RuntimeKSQL_formatQuery, "f").bind(this), __classPrivateFieldGet(this, _RuntimeKSQL_middlewareHandler, "f"), __classPrivateFieldGet(this, _RuntimeKSQL_getBaseTableName, "f"), __classPrivateFieldGet(this, _RuntimeKSQL_getMaterializedViewName, "f"), __classPrivateFieldGet(this, _RuntimeKSQL_doNotUseMaterializedViews, "f"));
47
- }
48
- async $queryRaw(sql, values) {
49
- return __classPrivateFieldGet(this, _RuntimeKSQL_dbCall, "f").call(this, SqlString.format(sql, values ?? []));
50
- }
51
- async $use(middleware) {
52
- __classPrivateFieldGet(this, _RuntimeKSQL_middlewareHandler, "f").register(middleware);
53
- }
54
- $whereNeedsProcessing(where) {
55
- return (0, shared_1.whereNeedsProcessing)(where);
56
- }
57
- async $prepareWhere(artifacts, table, data) {
58
- return (0, shared_1._prepareWhere)(artifacts, table, data, __classPrivateFieldGet(this, _RuntimeKSQL_dbCall, "f").bind(this), __classPrivateFieldGet(this, _RuntimeKSQL_formatQuery, "f").bind(this));
59
- }
60
- async $shutdown() {
61
- // Nothing to do here, I think
62
- }
63
- }
64
- exports.RuntimeKSQL = RuntimeKSQL;
65
- _RuntimeKSQL_ksql = new WeakMap(), _RuntimeKSQL_middlewareHandler = new WeakMap(), _RuntimeKSQL_dbCall = new WeakMap(), _RuntimeKSQL_formatQuery = new WeakMap(), _RuntimeKSQL_getBaseTableName = new WeakMap(), _RuntimeKSQL_getMaterializedViewName = new WeakMap(), _RuntimeKSQL_doNotUseMaterializedViews = new WeakMap();
66
- async function resolve(input, dbCall, formatQuery, middlewareHandler, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews) {
67
- // https://github.com/prisma/prisma/blob/822198e5ba21535364d20c86901b8c3778ebf6a3/packages/client/src/runtime/getPrismaClient.ts#L1087
68
- let index = -1;
69
- if (middlewareHandler.length() > 0) {
70
- const resource = new async_hooks_1.AsyncResource("sdk-request");
71
- const params = input;
72
- const consumer = (paramsMaybeMutated) => {
73
- const nextMiddleware = middlewareHandler.get(++index);
74
- if (nextMiddleware != null) {
75
- return nextMiddleware(paramsMaybeMutated, consumer);
76
- }
77
- const paramsChanged = { ...input, ...params };
78
- return _resolve(paramsChanged, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
79
- };
80
- return resource.runInAsyncScope(() => consumer(params));
81
- }
82
- return _resolve(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
83
- }
84
- function _resolve(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews) {
85
- if (input.action === "findUnique") {
86
- return getData(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
87
- }
88
- if (input.action === "findMany") {
89
- return getData(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
90
- }
91
- if (input.action === "findManyPaginated") {
92
- return getData(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
93
- }
94
- if (input.action === "create") {
95
- throw new Error("Not implemented.");
96
- }
97
- if (input.action === "update") {
98
- throw new Error("Not implemented.");
99
- }
100
- if (input.action === "updateMany") {
101
- throw new Error("Not implemented.");
102
- }
103
- if (input.action === "delete") {
104
- throw new Error("Not implemented.");
105
- }
106
- if (input.action === "deleteMany") {
107
- throw new Error("Not implemented.");
108
- }
109
- throw new Error("Invalid action: " + input.action);
110
- }
111
- async function getData(input, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews) {
112
- const { action } = input;
113
- const grabMany = action === "findMany" ||
114
- action === "findManyPaginated" ||
115
- action === "updateMany" ||
116
- action === "deleteMany";
117
- const data = await _getData(input, grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
118
- if (data == null && !grabMany) {
119
- throw new SDKNotFoundError_1.SDKNotFoundError();
120
- }
121
- const scalarFields = input.artifacts[input.resource].scalarFields;
122
- if (action === "findManyPaginated" && data?.results != null) {
123
- (0, shared_1.postProcess)(data.results, input.fields ?? scalarFields, true);
124
- }
125
- else {
126
- (0, shared_1.postProcess)(data, input.fields ?? scalarFields, true);
127
- }
128
- return data;
129
- }
130
- async function _getData(input, grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews) {
131
- const { resource: table, artifacts, args, action } = input;
132
- const tableArtifacts = artifacts[table];
133
- const isInputFieldAnArray = Array.isArray(input.fields);
134
- let fields = input.fields;
135
- if (!Array.isArray(fields)) {
136
- fields = tableArtifacts.scalarFields;
137
- }
138
- let useMaterializedView = !doNotUseMaterializedViews &&
139
- // If fields isn't an array, we're only getting scalar fields,
140
- // so no point using the materialized view.
141
- isInputFieldAnArray &&
142
- // We're getting relation fields
143
- fields.some((x) => typeof x === "object") &&
144
- Object.values(tableArtifacts.relationFields).filter((x) => x.type === "one-to-many__many-to-one" && x.kind === "many-to-one").length > 0 &&
145
- !Object.values(tableArtifacts.relationFields).some((x) => x.type === "one-to-many__many-to-one" &&
146
- x.kind === "many-to-one" &&
147
- x.nullable === true);
148
- const getTableName = useMaterializedView
149
- ? getMaterializedViewName
150
- : getBaseTableName;
151
- let where = undefined;
152
- if (args?.$where != null) {
153
- let argsMapped = args;
154
- if (typeof argsMapped.$where === "object" &&
155
- argsMapped.$where[table] != null) {
156
- argsMapped = _.cloneDeep(argsMapped);
157
- argsMapped.$where = argsMapped.$where[table];
158
- }
159
- const whereResult = (0, stringifyWhere_1.stringifyWhere)({
160
- where: argsMapped.$where,
161
- table: escapeId(getTableName(table)),
162
- dialect: "mysql",
163
- args: argsMapped,
164
- });
165
- if (whereResult) {
166
- where = whereResult;
167
- }
168
- }
169
- let columns = [];
170
- let mappedFields = [];
171
- let relationFields = [];
172
- for (let x of fields) {
173
- if (typeof x === "string") {
174
- const mappedField = tableArtifacts.mappedFields?.[x];
175
- if (mappedField != null) {
176
- mappedFields.push(x);
177
- if (!columns.includes(mappedField.foreignKey)) {
178
- columns.push(mappedField.foreignKey);
179
- }
180
- }
181
- else {
182
- columns.push(x);
183
- }
184
- }
185
- else {
186
- const relationField = tableArtifacts.relationFields?.[x.name];
187
- if (relationField == null) {
188
- throw new Error(`Invalid relation field: ${x.name}`);
189
- }
190
- if (relationField.type === "one-to-many__many-to-one") {
191
- relationFields.push(x);
192
- if (!columns.includes(relationField.relation.foreignKey)) {
193
- columns.push(relationField.relation.foreignKey);
194
- }
195
- }
196
- else if (relationField.type === "many-to-many") {
197
- relationFields.push(x);
198
- if (!columns.includes(relationField.relations[0].referencedKey)) {
199
- columns.push(relationField.relations[0].referencedKey);
200
- }
201
- }
202
- }
203
- }
204
- if (action === "findManyPaginated") {
205
- // For cursor
206
- if (!columns.includes(tableArtifacts.primaryKey)) {
207
- columns.push(tableArtifacts.primaryKey);
208
- }
209
- }
210
- if (useMaterializedView) {
211
- relationFields = relationFields.filter((x) => {
212
- if (typeof x === "string") {
213
- return true;
214
- }
215
- const relationField = tableArtifacts.relationFields?.[x.name];
216
- if (relationField == null) {
217
- throw new Error(`Invalid relation field: ${x.name}`);
218
- }
219
- // Since we're going to use the materialized view,
220
- // filter out non-nullable many-to-one relations.
221
- return !(relationField.type === "one-to-many__many-to-one" &&
222
- relationField.kind === "many-to-one" &&
223
- relationField.nullable === false);
224
- });
225
- }
226
- let s = useMaterializedView
227
- ? formatQuery(`SELECT * FROM ??`, [getTableName(table)])
228
- : formatQuery(`SELECT ?? FROM ??`, [columns, getTableName(table)]);
229
- if (where) {
230
- s += ` WHERE ${where}`;
231
- }
232
- s += ";";
233
- return dbCall(s).then((_result) => {
234
- let result = grabMany ? _result : _result[0];
235
- if (result == null) {
236
- return null;
237
- }
238
- if (grabMany && Array.isArray(result)) {
239
- // Important: ordering must be before pagination, since pagination is done in code
240
- let orderBy;
241
- if (args == null || args.$orderBy == null) {
242
- orderBy = [{ column: tableArtifacts.primaryKey, direction: "asc" }];
243
- }
244
- else if (Array.isArray(args.$orderBy)) {
245
- orderBy = args.$orderBy.map((x) => {
246
- const [column, direction] = Object.entries(x)[0];
247
- return { column, direction };
248
- });
249
- }
250
- else {
251
- const [column, direction] = Object.entries(args.$orderBy)[0];
252
- orderBy = [{ column, direction }];
253
- }
254
- for (let x of orderBy) {
255
- if (!["asc", "desc"].includes(x.direction)) {
256
- throw new Error(`Expected \`asc\` or \`desc\` for \`direction\` but got: ${x.direction}`);
257
- }
258
- }
259
- result = _.orderBy(result, orderBy.map((x) => x.column), orderBy.map((x) => x.direction));
260
- if (action === "findManyPaginated") {
261
- result = paginate(result, args, tableArtifacts.primaryKey, action);
262
- return Promise.all(result.results.map((x) => resolveDependentFields(table, x, mappedFields, relationFields, artifacts, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => mergeSubResults(x, xx)))).then((xx) => {
263
- result.results = xx;
264
- return result;
265
- });
266
- }
267
- const limit = args?.$limit;
268
- if (typeof limit === "number") {
269
- result = result.slice(0, limit);
270
- }
271
- return Promise.all(result.map((x) => resolveDependentFields(table, x, mappedFields, relationFields, artifacts, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => mergeSubResults(x, xx))));
272
- }
273
- return resolveDependentFields(table, result, mappedFields, relationFields, artifacts, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => mergeSubResults(result, xx));
274
- });
275
- }
276
- async function resolveDependentFields(table, parentData, mappedFields, relationFields, artifacts, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews) {
277
- const tableArtifacts = artifacts[table];
278
- return Promise.all([]
279
- .concat(mappedFields.map((x) => {
280
- const mappedField = tableArtifacts.mappedFields?.[x];
281
- if (mappedField == null) {
282
- throw new Error(`Invalid mappedField: ${x}`);
283
- }
284
- if (parentData?.[mappedField.foreignKey] == null) {
285
- return { [x]: null };
286
- }
287
- const s = formatQuery(`SELECT ?? FROM ?? WHERE ?? = ?;`, [
288
- mappedField.name,
289
- getBaseTableName(mappedField.referencedTable),
290
- mappedField.referencedKey,
291
- parentData?.[mappedField.foreignKey],
292
- ]);
293
- return dbCall(s).then((xs) => ({
294
- [x]: xs?.[0]?.[mappedField.name] ?? null,
295
- }));
296
- }))
297
- .concat(relationFields.map((x) => {
298
- if (typeof x === "string") {
299
- throw new Error(`Invalid field: ${x}`);
300
- }
301
- const relationField = tableArtifacts.relationFields?.[x.name];
302
- if (relationField == null) {
303
- throw new Error("Invalid field: " + table + "." + x.name);
304
- }
305
- if (relationField.type === "many-to-many") {
306
- const junctionReferencedKey = relationField.relations[0].referencedKey;
307
- const junctionKeyValue = parentData?.[junctionReferencedKey];
308
- if (junctionKeyValue == null) {
309
- return { [x.as ?? x.name]: [] };
310
- }
311
- let whereJunction = typeof x?.args?.$where === "object" &&
312
- x.args.$where != null &&
313
- x.args.$where[relationField.junctionTable] != null
314
- ? _.cloneDeep(x.args.$where[relationField.junctionTable])
315
- : {};
316
- whereJunction = {
317
- $and: [
318
- { [relationField.relations[0].foreignKey]: junctionKeyValue },
319
- whereJunction,
320
- ],
321
- };
322
- const key = relationField.relations[1].foreignKey;
323
- const s = formatQuery(`SELECT ?? FROM ?? WHERE ${(0, stringifyWhere_1.stringifyWhere)({
324
- where: whereJunction,
325
- table: escapeId(getBaseTableName(relationField.junctionTable)),
326
- dialect: "mysql",
327
- // Since we're paginating, empty is fine
328
- args: {},
329
- })};`, [key, getBaseTableName(relationField.junctionTable)]);
330
- return dbCall(s)
331
- .then((xs) => xs.map((x) => x?.[key]))
332
- .then((keys) => {
333
- const whereDest = {
334
- [relationField.relations[1].referencedKey]: { $in: keys },
335
- };
336
- const argsMapped = x.args == null ? {} : _.cloneDeep(x.args);
337
- if (typeof argsMapped?.$where === "object" &&
338
- argsMapped.$where != null &&
339
- argsMapped.$where[relationField.table] != null) {
340
- argsMapped.$where = {
341
- $and: [whereDest, argsMapped.$where[relationField.table]],
342
- };
343
- }
344
- else if (argsMapped.$where != null) {
345
- argsMapped.$where = { $and: [whereDest, argsMapped.$where] };
346
- }
347
- else {
348
- argsMapped.$where = whereDest;
349
- }
350
- return _getData({
351
- resource: relationField.table,
352
- args: argsMapped,
353
- fields: x.fields,
354
- artifacts,
355
- action: relationField.grabMany ? "findMany" : "findUnique",
356
- }, relationField.grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => ({ [x.as ?? x.name]: xx }));
357
- });
358
- }
359
- if (relationField.type === "one-to-many__many-to-one") {
360
- const referencedKey = relationField.relation.referencedKey;
361
- const foreignKeyValue = parentData?.[relationField.relation.foreignKey];
362
- if (foreignKeyValue == null) {
363
- return { [x.as ?? x.name]: relationField.grabMany ? [] : null };
364
- }
365
- const whereRef = { [referencedKey]: foreignKeyValue };
366
- const argsMapped = x.args == null ? {} : _.cloneDeep(x.args);
367
- if (argsMapped.$where == null) {
368
- argsMapped.$where = whereRef;
369
- }
370
- else {
371
- argsMapped.$where = { $and: [whereRef, argsMapped.$where] };
372
- }
373
- return _getData({
374
- resource: relationField.table,
375
- args: argsMapped,
376
- fields: x.fields,
377
- artifacts,
378
- action: relationField.grabMany ? "findMany" : "findUnique",
379
- }, relationField.grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => ({ [x.as ?? x.name]: xx }));
380
- }
381
- throw new Error(`Invalid relationField.type`);
382
- })));
383
- }
384
- function mergeSubResults(result, subResults) {
385
- for (let x of subResults) {
386
- result = { ...result, ...x };
387
- }
388
- return result;
389
- }
390
- function paginate(data, args, primaryKey, action) {
391
- if (action === "findManyPaginated") {
392
- if (typeof args?.$paginate?.limit === "number") {
393
- const totalCount = data.length;
394
- const limit = args.$paginate.limit;
395
- const offset = args.$paginate.offset ?? 0;
396
- data = data.slice(offset, offset + limit);
397
- return {
398
- results: data,
399
- paginationInfo: { totalCount },
400
- };
401
- }
402
- if (typeof args?.$paginate?.first === "number" ||
403
- typeof args?.$paginate?.last === "number") {
404
- const totalCount = data.length;
405
- let argsMapped = args;
406
- // Convert cursor(s) for graphql-relay
407
- for (let k of ["after", "before"]) {
408
- if (args?.$paginate?.[k] != null) {
409
- argsMapped = _.cloneDeep(argsMapped);
410
- const offset = data.findIndex((x) => x[primaryKey] === (0, cursor_1.decodeCursor)(args.$paginate[k]));
411
- if (offset === -1) {
412
- throw new Error(`Invalid cursor: ${args.$paginate[k]}`);
413
- }
414
- argsMapped.$paginate[k] = (0, graphql_relay_1.offsetToCursor)(offset);
415
- }
416
- }
417
- const connection = (0, graphql_relay_1.connectionFromArray)(data, argsMapped.$paginate);
418
- const results = connection.edges.map((x) => x.node);
419
- // Convert cursors back
420
- const startKey = results[0]?.[primaryKey];
421
- const endKey = results[results.length - 1]?.[primaryKey];
422
- const startCursor = startKey == null ? null : (0, cursor_1.encodeCursor)(startKey);
423
- const endCursor = endKey == null ? null : (0, cursor_1.encodeCursor)(endKey);
424
- return {
425
- results,
426
- paginationInfo: {
427
- ...connection.pageInfo,
428
- startCursor,
429
- endCursor,
430
- totalCount,
431
- },
432
- };
433
- }
434
- }
435
- throw new Error(`Invalid pagination action: ${action}`);
436
- }
437
- function mapResult(data) {
438
- return data.map((x) => {
439
- for (let k of Object.keys(x)) {
440
- if (typeof x[k] === "string" && (k === "uuid" || k.endsWith("Uuid"))) {
441
- x[k] = x[k].toLocaleLowerCase();
442
- }
443
- }
444
- return x;
445
- });
446
- }
@@ -1,2 +0,0 @@
1
- import type { IGetSQLASTInput } from "../IRuntime";
2
- export declare function runTransforms(data: any, fields: IGetSQLASTInput["fields"]): void;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTransforms = void 0;
4
- function runTransforms(data, fields) {
5
- if (data == null) {
6
- return;
7
- }
8
- for (let x of fields) {
9
- if (typeof x === "object") {
10
- const k = x.as ?? x.name;
11
- if (Array.isArray(data)) {
12
- for (let d of data) {
13
- if (d != null) {
14
- runTransforms(d[k], x.fields);
15
- }
16
- }
17
- }
18
- else {
19
- runTransforms(data[k], x.fields);
20
- }
21
- if (typeof x.transform === "function") {
22
- if (Array.isArray(data)) {
23
- for (let d of data) {
24
- if (d != null) {
25
- d[k] = x.transform(d[k]);
26
- }
27
- }
28
- }
29
- else {
30
- data[k] = x.transform(data[k]);
31
- }
32
- }
33
- }
34
- }
35
- }
36
- exports.runTransforms = runTransforms;