remult 0.14.2 → 0.14.5

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 (70) hide show
  1. package/assign.js +1 -5
  2. package/classType.js +1 -2
  3. package/graphql.js +84 -146
  4. package/index.d.ts +13 -0
  5. package/index.js +25 -55
  6. package/inputTypes.js +9 -16
  7. package/package.json +6 -1
  8. package/postgres/index.js +1 -4
  9. package/postgres/postgres-data-provider.js +165 -364
  10. package/postgres/postgresColumnSyntax.js +4 -8
  11. package/remult-express.js +6 -10
  12. package/remult-knex/index.js +300 -720
  13. package/remult-middleware.js +24 -30
  14. package/remult-mongo.js +172 -406
  15. package/server/JsonEntityFileStorage.js +10 -15
  16. package/server/expressBridge.js +383 -569
  17. package/server/index.js +4 -11
  18. package/server/register-actions-on-server.js +12 -38
  19. package/server/register-entities-on-server.js +9 -13
  20. package/src/__EntityValueProvider.js +1 -2
  21. package/src/__RowsOfDataForTesting.js +1 -2
  22. package/src/backend-tests/backend-database-test-setup.backend-spec.js +72 -190
  23. package/src/backend-tests/my-test.backend-spec.js +45 -114
  24. package/src/column-interfaces.js +2 -6
  25. package/src/column.js +71 -113
  26. package/src/context.js +174 -330
  27. package/src/data-api.js +162 -326
  28. package/src/data-interfaces.js +7 -11
  29. package/src/data-providers/array-entity-data-provider.js +171 -286
  30. package/src/data-providers/in-memory-database.js +12 -27
  31. package/src/data-providers/json-data-provider.js +41 -77
  32. package/src/data-providers/rest-data-provider.js +102 -189
  33. package/src/data-providers/sql-database.js +223 -403
  34. package/src/data-providers/web-sql-data-provider.js +78 -139
  35. package/src/entity.js +1 -2
  36. package/src/filter/filter-consumer-bridge-to-sql-request.js +106 -248
  37. package/src/filter/filter-consumer-bridge-to-url-builder.js +1 -2
  38. package/src/filter/filter-interfaces.js +277 -440
  39. package/src/id-entity.js +8 -17
  40. package/src/remult3/RepositoryImplementation.js +1191 -2367
  41. package/src/remult3/index.js +2 -5
  42. package/src/remult3/remult3.js +1 -2
  43. package/src/server-action.js +294 -528
  44. package/src/shared-tests/db-tests-setup.js +49 -153
  45. package/src/shared-tests/db-tests.db-tests.js +660 -1566
  46. package/src/shared-tests/deleteAll.js +3 -20
  47. package/src/shared-tests/entityWithValidations.js +52 -79
  48. package/src/shared-tests/index.js +4 -6
  49. package/src/shared-tests/test-custom-id-column.spec.js +37 -85
  50. package/src/shared-tests/test-special-value.spec.js +64 -104
  51. package/src/shared-tests/test-update-with-null.spec.js +28 -49
  52. package/src/sort.js +38 -95
  53. package/src/sql-command.js +1 -2
  54. package/src/tests/Done.js +7 -13
  55. package/src/tests/TestDataApiResponse.js +15 -22
  56. package/src/tests/c.js +21 -27
  57. package/src/tests/createData.js +20 -48
  58. package/src/tests/d.js +19 -27
  59. package/src/tests/dWithPrefilter.js +31 -44
  60. package/src/tests/entityForCustomFilter.js +42 -66
  61. package/src/tests/entityWithValidationsOnColumn.js +21 -29
  62. package/src/tests/frontend-database-tests-setup.spec.js +35 -98
  63. package/src/tests/h.js +35 -44
  64. package/src/tests/remult-3-entities.js +71 -80
  65. package/src/tests/tasks.js +23 -29
  66. package/src/tests/testHelper.spec.js +170 -322
  67. package/src/tests/testModel/models.js +25 -33
  68. package/src/validators.js +32 -59
  69. package/urlBuilder.js +8 -14
  70. package/valueConverters.js +161 -160
package/src/data-api.js CHANGED
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeError = exports.determineSort = exports.DataApi = void 0;
4
- var tslib_1 = require("tslib");
5
- var filter_interfaces_1 = require("./filter/filter-interfaces");
6
- var filter_interfaces_2 = require("./filter/filter-interfaces");
7
- var DataApi = /** @class */ (function () {
8
- function DataApi(repository, remult) {
1
+ import { customUrlToken, buildFilterFromRequestParameters } from './filter/filter-interfaces';
2
+ import { Filter } from './filter/filter-interfaces';
3
+ export class DataApi {
4
+ constructor(repository, remult) {
9
5
  this.repository = repository;
10
6
  this.remult = remult;
11
7
  }
12
- DataApi.prototype.httpGet = function (res, req) {
8
+ httpGet(res, req) {
13
9
  if (req.get("__action") == "count") {
14
10
  return this.count(res, req);
15
11
  }
16
12
  else
17
13
  return this.getArray(res, req);
18
- };
19
- DataApi.prototype.httpPost = function (res, req, body) {
14
+ }
15
+ httpPost(res, req, body) {
20
16
  switch (req.get("__action")) {
21
17
  case "get":
22
18
  return this.getArray(res, req, body);
@@ -25,327 +21,169 @@ var DataApi = /** @class */ (function () {
25
21
  default:
26
22
  return this.post(res, body);
27
23
  }
28
- };
29
- DataApi.prototype.get = function (response, id) {
30
- return tslib_1.__awaiter(this, void 0, void 0, function () {
31
- var _this = this;
32
- return tslib_1.__generator(this, function (_a) {
33
- switch (_a.label) {
34
- case 0:
35
- if (!this.repository.metadata.apiReadAllowed) {
36
- response.forbidden();
37
- return [2 /*return*/];
38
- }
39
- return [4 /*yield*/, this.doOnId(response, id, function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
40
- return [2 /*return*/, response.success(this.repository.getEntityRef(row).toApiJson())];
41
- }); }); })];
42
- case 1:
43
- _a.sent();
44
- return [2 /*return*/];
45
- }
46
- });
47
- });
48
- };
49
- DataApi.prototype.count = function (response, request, filterBody) {
50
- return tslib_1.__awaiter(this, void 0, void 0, function () {
51
- var _a, _b, _c, _d, err_1;
52
- var _e;
53
- return tslib_1.__generator(this, function (_f) {
54
- switch (_f.label) {
55
- case 0:
56
- if (!this.repository.metadata.apiReadAllowed) {
57
- response.forbidden();
58
- return [2 /*return*/];
59
- }
60
- _f.label = 1;
61
- case 1:
62
- _f.trys.push([1, 4, , 5]);
63
- _b = (_a = response).success;
64
- _e = {};
65
- _d = (_c = this.repository).count;
66
- return [4 /*yield*/, this.buildWhere(request, filterBody)];
67
- case 2: return [4 /*yield*/, _d.apply(_c, [_f.sent()])];
68
- case 3:
69
- _b.apply(_a, [(_e.count = +(_f.sent()), _e)]);
70
- return [3 /*break*/, 5];
71
- case 4:
72
- err_1 = _f.sent();
73
- response.error(err_1);
74
- return [3 /*break*/, 5];
75
- case 5: return [2 /*return*/];
76
- }
77
- });
78
- });
79
- };
80
- DataApi.prototype.getArray = function (response, request, filterBody) {
81
- return tslib_1.__awaiter(this, void 0, void 0, function () {
82
- var findOptions, _a, hasId_1, w, sort, dir, limit, err_2;
83
- var _this = this;
84
- return tslib_1.__generator(this, function (_b) {
85
- switch (_b.label) {
86
- case 0:
87
- if (!this.repository.metadata.apiReadAllowed) {
88
- response.forbidden();
89
- return [2 /*return*/];
90
- }
91
- _b.label = 1;
92
- case 1:
93
- _b.trys.push([1, 6, , 7]);
94
- findOptions = { load: function () { return []; } };
95
- _a = findOptions;
96
- return [4 /*yield*/, this.buildWhere(request, filterBody)];
97
- case 2:
98
- _a.where = _b.sent();
99
- if (!this.remult.isAllowed(this.repository.metadata.options.apiRequireId)) return [3 /*break*/, 4];
100
- hasId_1 = false;
101
- return [4 /*yield*/, filter_interfaces_2.Filter.fromEntityFilter(this.repository.metadata, findOptions.where)];
102
- case 3:
103
- w = _b.sent();
104
- if (w) {
105
- w.__applyToConsumer({
106
- containsCaseInsensitive: function () { },
107
- isDifferentFrom: function () { },
108
- isEqualTo: function (col, val) {
109
- if (_this.repository.metadata.idMetadata.isIdField(col))
110
- hasId_1 = true;
111
- },
112
- custom: function () { },
113
- databaseCustom: function () { },
114
- isGreaterOrEqualTo: function () { },
115
- isGreaterThan: function () { },
116
- isIn: function () { },
117
- isLessOrEqualTo: function () { },
118
- isLessThan: function () { },
119
- isNotNull: function () { },
120
- isNull: function () { },
121
- or: function () { }
122
- });
123
- }
124
- if (!hasId_1) {
125
- response.forbidden();
126
- return [2 /*return*/];
127
- }
128
- _b.label = 4;
129
- case 4:
130
- if (request) {
131
- sort = request.get("_sort");
132
- if (sort != undefined) {
133
- dir = request.get('_order');
134
- findOptions.orderBy = determineSort(sort, dir);
135
- }
136
- limit = +request.get("_limit");
137
- if (!limit && DataApi.defaultGetLimit)
138
- limit = DataApi.defaultGetLimit;
139
- findOptions.limit = limit;
140
- findOptions.page = +request.get("_page");
141
- }
142
- return [4 /*yield*/, this.repository.find(findOptions)
143
- .then(function (r) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
144
- var _a, _b;
145
- var _this = this;
146
- return tslib_1.__generator(this, function (_c) {
147
- switch (_c.label) {
148
- case 0:
149
- _b = (_a = response).success;
150
- return [4 /*yield*/, Promise.all(r.map(function (y) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
151
- return [2 /*return*/, this.repository.getEntityRef(y).toApiJson()];
152
- }); }); }))];
153
- case 1:
154
- _b.apply(_a, [_c.sent()]);
155
- return [2 /*return*/];
156
- }
157
- });
158
- }); })];
159
- case 5:
160
- _b.sent();
161
- return [3 /*break*/, 7];
162
- case 6:
163
- err_2 = _b.sent();
164
- response.error(err_2);
165
- return [3 /*break*/, 7];
166
- case 7: return [2 /*return*/];
167
- }
168
- });
169
- });
170
- };
171
- DataApi.prototype.buildWhere = function (request, filterBody) {
172
- return tslib_1.__awaiter(this, void 0, void 0, function () {
173
- var where, _a, _b;
174
- return tslib_1.__generator(this, function (_c) {
175
- switch (_c.label) {
176
- case 0:
177
- where = [];
178
- if (!this.repository.metadata.options.apiPrefilter) return [3 /*break*/, 3];
179
- if (!(typeof this.repository.metadata.options.apiPrefilter === "function")) return [3 /*break*/, 2];
180
- _b = (_a = where).push;
181
- return [4 /*yield*/, this.repository.metadata.options.apiPrefilter()];
182
- case 1:
183
- _b.apply(_a, [_c.sent()]);
184
- return [3 /*break*/, 3];
185
- case 2:
186
- where.push(this.repository.metadata.options.apiPrefilter);
187
- _c.label = 3;
188
- case 3:
189
- if (request) {
190
- where.push(filter_interfaces_1.buildFilterFromRequestParameters(this.repository.metadata, {
191
- get: function (key) {
192
- var result = request.get(key);
193
- if (key.startsWith(filter_interfaces_1.customUrlToken) && result)
194
- return JSON.parse(result);
195
- return result;
196
- }
197
- }));
198
- }
199
- if (filterBody)
200
- where.push(filter_interfaces_2.Filter.entityFilterFromJson(this.repository.metadata, filterBody));
201
- return [2 /*return*/, { $and: where }];
24
+ }
25
+ async get(response, id) {
26
+ if (!this.repository.metadata.apiReadAllowed) {
27
+ response.forbidden();
28
+ return;
29
+ }
30
+ await this.doOnId(response, id, async (row) => response.success(this.repository.getEntityRef(row).toApiJson()));
31
+ }
32
+ async count(response, request, filterBody) {
33
+ if (!this.repository.metadata.apiReadAllowed) {
34
+ response.forbidden();
35
+ return;
36
+ }
37
+ try {
38
+ response.success({ count: +await this.repository.count(await this.buildWhere(request, filterBody)) });
39
+ }
40
+ catch (err) {
41
+ response.error(err);
42
+ }
43
+ }
44
+ async getArray(response, request, filterBody) {
45
+ if (!this.repository.metadata.apiReadAllowed) {
46
+ response.forbidden();
47
+ return;
48
+ }
49
+ try {
50
+ let findOptions = { load: () => [] };
51
+ findOptions.where = await this.buildWhere(request, filterBody);
52
+ if (this.remult.isAllowed(this.repository.metadata.options.apiRequireId)) {
53
+ let hasId = false;
54
+ let w = await Filter.fromEntityFilter(this.repository.metadata, findOptions.where);
55
+ if (w) {
56
+ w.__applyToConsumer({
57
+ containsCaseInsensitive: () => { },
58
+ isDifferentFrom: () => { },
59
+ isEqualTo: (col, val) => {
60
+ if (this.repository.metadata.idMetadata.isIdField(col))
61
+ hasId = true;
62
+ },
63
+ custom: () => { },
64
+ databaseCustom: () => { },
65
+ isGreaterOrEqualTo: () => { },
66
+ isGreaterThan: () => { },
67
+ isIn: () => { },
68
+ isLessOrEqualTo: () => { },
69
+ isLessThan: () => { },
70
+ isNotNull: () => { },
71
+ isNull: () => { },
72
+ or: () => { }
73
+ });
202
74
  }
203
- });
204
- });
205
- };
206
- DataApi.prototype.doOnId = function (response, id, what) {
207
- return tslib_1.__awaiter(this, void 0, void 0, function () {
208
- var err_3;
209
- var _this = this;
210
- return tslib_1.__generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0:
213
- _a.trys.push([0, 2, , 3]);
214
- return [4 /*yield*/, this.repository.find({
215
- where: { $and: [this.repository.metadata.options.apiPrefilter, this.repository.metadata.idMetadata.getIdFilter(id)] }
216
- })
217
- .then(function (r) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
218
- return tslib_1.__generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0:
221
- if (!(r.length == 0)) return [3 /*break*/, 1];
222
- response.notFound();
223
- return [3 /*break*/, 4];
224
- case 1:
225
- if (!(r.length > 1)) return [3 /*break*/, 2];
226
- response.error({ message: "id is not unique" });
227
- return [3 /*break*/, 4];
228
- case 2: return [4 /*yield*/, what(r[0])];
229
- case 3:
230
- _a.sent();
231
- _a.label = 4;
232
- case 4: return [2 /*return*/];
233
- }
234
- });
235
- }); })];
236
- case 1:
237
- _a.sent();
238
- return [3 /*break*/, 3];
239
- case 2:
240
- err_3 = _a.sent();
241
- response.error(err_3);
242
- return [3 /*break*/, 3];
243
- case 3: return [2 /*return*/];
75
+ if (!hasId) {
76
+ response.forbidden();
77
+ return;
244
78
  }
245
- });
246
- });
247
- };
248
- DataApi.prototype.put = function (response, id, body) {
249
- return tslib_1.__awaiter(this, void 0, void 0, function () {
250
- var _this = this;
251
- return tslib_1.__generator(this, function (_a) {
252
- switch (_a.label) {
253
- case 0: return [4 /*yield*/, this.doOnId(response, id, function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
254
- var ref;
255
- return tslib_1.__generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0:
258
- ref = this.repository.getEntityRef(row);
259
- return [4 /*yield*/, ref._updateEntityBasedOnApi(body)];
260
- case 1:
261
- _a.sent();
262
- if (!ref.apiUpdateAllowed) {
263
- response.forbidden();
264
- return [2 /*return*/];
265
- }
266
- return [4 /*yield*/, this.repository.getEntityRef(row).save()];
267
- case 2:
268
- _a.sent();
269
- response.success(this.repository.getEntityRef(row).toApiJson());
270
- return [2 /*return*/];
271
- }
272
- });
273
- }); })];
274
- case 1:
275
- _a.sent();
276
- return [2 /*return*/];
79
+ }
80
+ if (request) {
81
+ let sort = request.get("_sort");
82
+ if (sort != undefined) {
83
+ let dir = request.get('_order');
84
+ findOptions.orderBy = determineSort(sort, dir);
277
85
  }
86
+ let limit = +request.get("_limit");
87
+ if (!limit && DataApi.defaultGetLimit)
88
+ limit = DataApi.defaultGetLimit;
89
+ findOptions.limit = limit;
90
+ findOptions.page = +request.get("_page");
91
+ }
92
+ await this.repository.find(findOptions)
93
+ .then(async (r) => {
94
+ response.success(await Promise.all(r.map(async (y) => this.repository.getEntityRef(y).toApiJson())));
278
95
  });
279
- });
280
- };
281
- DataApi.prototype.delete = function (response, id) {
282
- return tslib_1.__awaiter(this, void 0, void 0, function () {
283
- var _this = this;
284
- return tslib_1.__generator(this, function (_a) {
285
- switch (_a.label) {
286
- case 0: return [4 /*yield*/, this.doOnId(response, id, function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
287
- return tslib_1.__generator(this, function (_a) {
288
- switch (_a.label) {
289
- case 0:
290
- if (!this.repository.getEntityRef(row).apiDeleteAllowed) {
291
- response.forbidden();
292
- return [2 /*return*/];
293
- }
294
- return [4 /*yield*/, this.repository.getEntityRef(row).delete()];
295
- case 1:
296
- _a.sent();
297
- response.deleted();
298
- return [2 /*return*/];
299
- }
300
- });
301
- }); })];
302
- case 1:
303
- _a.sent();
304
- return [2 /*return*/];
96
+ }
97
+ catch (err) {
98
+ response.error(err);
99
+ }
100
+ }
101
+ async buildWhere(request, filterBody) {
102
+ var where = [];
103
+ if (this.repository.metadata.options.apiPrefilter) {
104
+ if (typeof this.repository.metadata.options.apiPrefilter === "function")
105
+ where.push(await this.repository.metadata.options.apiPrefilter());
106
+ else
107
+ where.push(this.repository.metadata.options.apiPrefilter);
108
+ }
109
+ if (request) {
110
+ where.push(buildFilterFromRequestParameters(this.repository.metadata, {
111
+ get: key => {
112
+ let result = request.get(key);
113
+ if (key.startsWith(customUrlToken) && result)
114
+ return JSON.parse(result);
115
+ return result;
305
116
  }
117
+ }));
118
+ }
119
+ if (filterBody)
120
+ where.push(Filter.entityFilterFromJson(this.repository.metadata, filterBody));
121
+ return { $and: where };
122
+ }
123
+ async doOnId(response, id, what) {
124
+ try {
125
+ await this.repository.find({
126
+ where: { $and: [this.repository.metadata.options.apiPrefilter, this.repository.metadata.idMetadata.getIdFilter(id)] }
127
+ })
128
+ .then(async (r) => {
129
+ if (r.length == 0)
130
+ response.notFound();
131
+ else if (r.length > 1)
132
+ response.error({ message: "id is not unique" });
133
+ else
134
+ await what(r[0]);
306
135
  });
136
+ }
137
+ catch (err) {
138
+ response.error(err);
139
+ }
140
+ }
141
+ async put(response, id, body) {
142
+ await this.doOnId(response, id, async (row) => {
143
+ let ref = this.repository.getEntityRef(row);
144
+ await ref._updateEntityBasedOnApi(body);
145
+ if (!ref.apiUpdateAllowed) {
146
+ response.forbidden();
147
+ return;
148
+ }
149
+ await this.repository.getEntityRef(row).save();
150
+ response.success(this.repository.getEntityRef(row).toApiJson());
307
151
  });
308
- };
309
- DataApi.prototype.post = function (response, body) {
310
- return tslib_1.__awaiter(this, void 0, void 0, function () {
311
- var newr, err_4;
312
- return tslib_1.__generator(this, function (_a) {
313
- switch (_a.label) {
314
- case 0:
315
- _a.trys.push([0, 3, , 4]);
316
- newr = this.repository.create();
317
- return [4 /*yield*/, this.repository.getEntityRef(newr)._updateEntityBasedOnApi(body)];
318
- case 1:
319
- _a.sent();
320
- if (!this.repository.getEntityRef(newr).apiInsertAllowed) {
321
- response.forbidden();
322
- return [2 /*return*/];
323
- }
324
- return [4 /*yield*/, this.repository.getEntityRef(newr).save()];
325
- case 2:
326
- _a.sent();
327
- response.created(this.repository.getEntityRef(newr).toApiJson());
328
- return [3 /*break*/, 4];
329
- case 3:
330
- err_4 = _a.sent();
331
- response.error(err_4);
332
- return [3 /*break*/, 4];
333
- case 4: return [2 /*return*/];
334
- }
335
- });
152
+ }
153
+ async delete(response, id) {
154
+ await this.doOnId(response, id, async (row) => {
155
+ if (!this.repository.getEntityRef(row).apiDeleteAllowed) {
156
+ response.forbidden();
157
+ return;
158
+ }
159
+ await this.repository.getEntityRef(row).delete();
160
+ response.deleted();
336
161
  });
337
- };
338
- DataApi.defaultGetLimit = 0;
339
- return DataApi;
340
- }());
341
- exports.DataApi = DataApi;
342
- function determineSort(sortUrlParm, dirUrlParam) {
343
- var dirItems = [];
162
+ }
163
+ async post(response, body) {
164
+ try {
165
+ let newr = this.repository.create();
166
+ await this.repository.getEntityRef(newr)._updateEntityBasedOnApi(body);
167
+ if (!this.repository.getEntityRef(newr).apiInsertAllowed) {
168
+ response.forbidden();
169
+ return;
170
+ }
171
+ await this.repository.getEntityRef(newr).save();
172
+ response.created(this.repository.getEntityRef(newr).toApiJson());
173
+ }
174
+ catch (err) {
175
+ response.error(err);
176
+ }
177
+ }
178
+ }
179
+ DataApi.defaultGetLimit = 0;
180
+ export function determineSort(sortUrlParm, dirUrlParam) {
181
+ let dirItems = [];
344
182
  if (dirUrlParam)
345
183
  dirItems = dirUrlParam.split(',');
346
- var result = {};
347
- sortUrlParm.split(',').map(function (name, i) {
348
- var key = name.trim();
184
+ let result = {};
185
+ sortUrlParm.split(',').map((name, i) => {
186
+ let key = name.trim();
349
187
  if (i < dirItems.length && dirItems[i].toLowerCase().trim().startsWith("d"))
350
188
  return result[key] = "desc";
351
189
  else
@@ -353,16 +191,14 @@ function determineSort(sortUrlParm, dirUrlParam) {
353
191
  });
354
192
  return result;
355
193
  }
356
- exports.determineSort = determineSort;
357
- function serializeError(data) {
194
+ export function serializeError(data) {
358
195
  if (data instanceof TypeError) {
359
196
  data = { message: data.message, stack: data.stack };
360
197
  }
361
- var x = JSON.parse(JSON.stringify(data));
198
+ let x = JSON.parse(JSON.stringify(data));
362
199
  if (!x.message && !x.modelState)
363
200
  data = { message: data.message, stack: data.stack };
364
201
  if (typeof x === 'string')
365
202
  data = { message: x };
366
203
  return data;
367
204
  }
368
- exports.serializeError = serializeError;
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractSort = void 0;
4
- var sort_1 = require("./sort");
5
- function extractSort(sort) {
6
- if (sort instanceof sort_1.Sort)
1
+ import { Sort } from './sort';
2
+ export function extractSort(sort) {
3
+ if (sort instanceof Sort)
7
4
  return sort;
8
5
  if (sort instanceof Array) {
9
- var r_1 = new sort_1.Sort();
10
- sort.forEach(function (i) {
11
- r_1.Segments.push(i);
6
+ let r = new Sort();
7
+ sort.forEach(i => {
8
+ r.Segments.push(i);
12
9
  });
13
- return r_1;
10
+ return r;
14
11
  }
15
12
  }
16
- exports.extractSort = extractSort;