adminforth 1.1.73 → 1.1.75

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 (122) hide show
  1. package/auth.ts +14 -0
  2. package/dataConnectors/baseConnector.ts +107 -0
  3. package/dataConnectors/mongo.ts +6 -12
  4. package/dataConnectors/postgres.ts +17 -37
  5. package/dataConnectors/sqlite.ts +44 -55
  6. package/dist/auth.js +7 -0
  7. package/dist/dataConnectors/baseConnector.js +90 -0
  8. package/dist/dataConnectors/mongo.js +6 -12
  9. package/dist/dataConnectors/postgres.js +12 -33
  10. package/dist/dataConnectors/sqlite.js +67 -83
  11. package/dist/index.js +125 -66
  12. package/dist/modules/codeInjector.js +29 -15
  13. package/dist/plugins/AuditLogPlugin/index.js +2 -17
  14. package/dist/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  15. package/dist/plugins/S3UploadPlugin/index.js +103 -0
  16. package/dist/plugins/S3UploadPlugin/package-lock.json +431 -0
  17. package/dist/plugins/S3UploadPlugin/package.json +15 -0
  18. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  19. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  20. package/dist/plugins/TwoFactorsAuthPlugin/index.js +150 -0
  21. package/dist/plugins/TwoFactorsAuthPlugin/types.js +1 -0
  22. package/dist/spa/index.html +1 -1
  23. package/dist/spa/package-lock.json +111 -0
  24. package/dist/spa/package.json +1 -0
  25. package/dist/spa/src/App.vue +178 -133
  26. package/dist/spa/src/components/MenuLink.vue +3 -3
  27. package/dist/spa/src/components/ResourceForm.vue +96 -96
  28. package/dist/spa/src/components/ResourceListTable.vue +69 -84
  29. package/dist/spa/src/components/ValueRenderer.vue +2 -3
  30. package/dist/spa/src/composables/useStores.ts +24 -11
  31. package/dist/spa/src/main.ts +1 -1
  32. package/dist/spa/src/router/index.ts +0 -1
  33. package/dist/spa/src/utils.ts +1 -1
  34. package/dist/spa/src/views/CreateView.vue +1 -9
  35. package/dist/spa/src/views/EditView.vue +1 -9
  36. package/dist/spa/src/views/ListView.vue +12 -3
  37. package/dist/spa/src/views/LoginView.vue +6 -1
  38. package/dist/spa/src/views/ResourceParent.vue +1 -2
  39. package/dist/spa/src/views/ShowView.vue +6 -14
  40. package/dist/spa/tailwind.config.js +3 -1
  41. package/index.ts +103 -36
  42. package/modules/codeInjector.ts +38 -27
  43. package/package.json +2 -1
  44. package/plugins/AuditLogPlugin/index.ts +4 -20
  45. package/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  46. package/plugins/S3UploadPlugin/index.ts +112 -0
  47. package/plugins/S3UploadPlugin/package-lock.json +431 -0
  48. package/plugins/S3UploadPlugin/package.json +15 -0
  49. package/plugins/S3UploadPlugin/types.ts +76 -0
  50. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  51. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue +0 -0
  52. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  53. package/plugins/TwoFactorsAuthPlugin/index.ts +150 -0
  54. package/plugins/TwoFactorsAuthPlugin/types.ts +10 -0
  55. package/servers/express.ts +1 -0
  56. package/spa/src/App.vue +154 -121
  57. package/spa/src/components/ResourceForm.vue +91 -91
  58. package/spa/src/router/index.ts +0 -1
  59. package/spa/src/utils.ts +1 -1
  60. package/spa/src/views/CreateView.vue +0 -1
  61. package/spa/src/views/LoginView.vue +4 -1
  62. package/types/AdminForthConfig.ts +166 -5
  63. package/dist/plugins/AuditLog/index.js +0 -13
  64. package/dist/spa/spa/.eslintrc.cjs +0 -14
  65. package/dist/spa/spa/.vscode/extensions.json +0 -6
  66. package/dist/spa/spa/README.md +0 -39
  67. package/dist/spa/spa/env.d.ts +0 -1
  68. package/dist/spa/spa/index.html +0 -23
  69. package/dist/spa/spa/package-lock.json +0 -4470
  70. package/dist/spa/spa/package.json +0 -48
  71. package/dist/spa/spa/postcss.config.js +0 -6
  72. package/dist/spa/spa/public/assets/favicon.png +0 -0
  73. package/dist/spa/spa/src/App.vue +0 -283
  74. package/dist/spa/spa/src/assets/logo.svg +0 -19
  75. package/dist/spa/spa/src/components/AcceptModal.vue +0 -45
  76. package/dist/spa/spa/src/components/Breadcrumbs.vue +0 -40
  77. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  78. package/dist/spa/spa/src/components/CustomDatePicker.vue +0 -174
  79. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +0 -218
  80. package/dist/spa/spa/src/components/CustomRangePicker.vue +0 -148
  81. package/dist/spa/spa/src/components/Dropdown.vue +0 -168
  82. package/dist/spa/spa/src/components/Filters.vue +0 -211
  83. package/dist/spa/spa/src/components/HelloWorld.vue +0 -17
  84. package/dist/spa/spa/src/components/MenuLink.vue +0 -24
  85. package/dist/spa/spa/src/components/ResourceForm.vue +0 -265
  86. package/dist/spa/spa/src/components/ResourceListTable.vue +0 -404
  87. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +0 -13
  88. package/dist/spa/spa/src/components/Toast.vue +0 -66
  89. package/dist/spa/spa/src/components/ValueRenderer.vue +0 -59
  90. package/dist/spa/spa/src/components/icons/IconCalendar.vue +0 -5
  91. package/dist/spa/spa/src/components/icons/IconCommunity.vue +0 -7
  92. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +0 -7
  93. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +0 -7
  94. package/dist/spa/spa/src/components/icons/IconSupport.vue +0 -7
  95. package/dist/spa/spa/src/components/icons/IconTime.vue +0 -5
  96. package/dist/spa/spa/src/components/icons/IconTooling.vue +0 -19
  97. package/dist/spa/spa/src/composables/useFrontendApi.ts +0 -26
  98. package/dist/spa/spa/src/composables/useStores.ts +0 -126
  99. package/dist/spa/spa/src/index.scss +0 -26
  100. package/dist/spa/spa/src/main.ts +0 -18
  101. package/dist/spa/spa/src/router/index.ts +0 -64
  102. package/dist/spa/spa/src/spa_types/core.ts +0 -51
  103. package/dist/spa/spa/src/stores/core.ts +0 -144
  104. package/dist/spa/spa/src/stores/filters.ts +0 -22
  105. package/dist/spa/spa/src/stores/modal.ts +0 -48
  106. package/dist/spa/spa/src/stores/toast.ts +0 -15
  107. package/dist/spa/spa/src/stores/user.ts +0 -54
  108. package/dist/spa/spa/src/utils.ts +0 -101
  109. package/dist/spa/spa/src/views/CreateView.vue +0 -156
  110. package/dist/spa/spa/src/views/EditView.vue +0 -157
  111. package/dist/spa/spa/src/views/ListView.vue +0 -266
  112. package/dist/spa/spa/src/views/LoginView.vue +0 -136
  113. package/dist/spa/spa/src/views/ResourceParent.vue +0 -17
  114. package/dist/spa/spa/src/views/ShowView.vue +0 -180
  115. package/dist/spa/spa/tailwind.config.js +0 -17
  116. package/dist/spa/spa/tsconfig.app.json +0 -14
  117. package/dist/spa/spa/tsconfig.json +0 -11
  118. package/dist/spa/spa/tsconfig.node.json +0 -19
  119. package/dist/spa/spa/vite.config.ts +0 -49
  120. /package/dist/plugins/{AuditLog → S3UploadPlugin}/types.js +0 -0
  121. /package/dist/{spa/spa/src/assets/base.css → plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue} +0 -0
  122. /package/dist/spa/{spa/src → src}/components/SkeleteLoader.vue +0 -0
@@ -84,7 +84,7 @@ class MongoConnector {
84
84
  }
85
85
  return value;
86
86
  }
87
- getRecordByPrimaryKey(resource, key) {
87
+ getRecordByPrimaryKeyWithOriginalTypes(resource, key) {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
89
  const tableName = resource.table;
90
90
  const collection = this.db.db().collection(tableName);
@@ -99,7 +99,7 @@ class MongoConnector {
99
99
  continue; // should I continue or throw an error?
100
100
  throw new Error(`Resource '${resource.table}' has no column '${key_1}' defined`);
101
101
  }
102
- newRow[key_1] = this.getFieldValue(dbKey, value);
102
+ newRow[key_1] = value;
103
103
  }
104
104
  console.log('newRow', newRow);
105
105
  return newRow;
@@ -124,7 +124,7 @@ class MongoConnector {
124
124
  }
125
125
  return value;
126
126
  }
127
- getData(_a) {
127
+ getDataWithOriginalTypes(_a) {
128
128
  return __awaiter(this, arguments, void 0, function* ({ resource, limit, offset, sort, filters }) {
129
129
  // const columns = resource.dataSourceColumns.filter(c=> !c.virtual).map((col) => col.name).join(', ');
130
130
  const tableName = resource.table;
@@ -142,7 +142,7 @@ class MongoConnector {
142
142
  return { data: result, total };
143
143
  });
144
144
  }
145
- getMinMaxForColumns(_a) {
145
+ getMinMaxForColumnsWithOriginalTypes(_a) {
146
146
  return __awaiter(this, arguments, void 0, function* ({ resource, columns }) {
147
147
  const tableName = resource.table;
148
148
  const collection = this.db.db().collection(tableName);
@@ -164,19 +164,13 @@ class MongoConnector {
164
164
  const columns = Object.keys(record);
165
165
  const newRecord = {};
166
166
  for (const colName of columns) {
167
- const col = resource.dataSourceColumns.find((col) => col.name == colName);
168
- if (col) {
169
- newRecord[colName] = this.setFieldValue(col, record[colName]);
170
- }
171
- else {
172
- newRecord[colName] = record[colName];
173
- }
167
+ newRecord[colName] = record[colName];
174
168
  }
175
169
  yield collection.insertOne(newRecord);
176
170
  });
177
171
  }
178
172
  updateRecord(_a) {
179
- return __awaiter(this, arguments, void 0, function* ({ resource, recordId, record, newValues }) {
173
+ return __awaiter(this, arguments, void 0, function* ({ resource, recordId, newValues }) {
180
174
  const collection = this.db.db().collection(resource.table);
181
175
  yield collection.updateOne({ [this.getPrimaryKey(resource)]: recordId }, { $set: newValues });
182
176
  });
@@ -10,9 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import dayjs from 'dayjs';
11
11
  import pkg from 'pg';
12
12
  import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from '../types/AdminForthConfig.js';
13
+ import AdminForthBaseConnector from './baseConnector.js';
13
14
  const { Client } = pkg;
14
- class PostgresConnector {
15
+ class PostgresConnector extends AdminForthBaseConnector {
15
16
  constructor({ url }) {
17
+ super();
16
18
  this.OperatorsMap = {
17
19
  [AdminForthFilterOperators.EQ]: '=',
18
20
  [AdminForthFilterOperators.NE]: '!=',
@@ -152,14 +154,7 @@ class PostgresConnector {
152
154
  }
153
155
  return value;
154
156
  }
155
- getPrimaryKey(resource) {
156
- for (const col of resource.dataSourceColumns) {
157
- if (col.primaryKey) {
158
- return col.name;
159
- }
160
- }
161
- }
162
- getRecordByPrimaryKey(resource, key) {
157
+ getRecordByPrimaryKeyWithOriginalTypes(resource, key) {
163
158
  return __awaiter(this, void 0, void 0, function* () {
164
159
  const tableName = resource.table;
165
160
  const columns = resource.dataSourceColumns.map((col) => `"${col.name}"`).join(', ');
@@ -170,7 +165,7 @@ class PostgresConnector {
170
165
  }
171
166
  const newRow = {};
172
167
  for (const [key_1, value] of Object.entries(row)) {
173
- newRow[key_1] = this.getFieldValue(resource.dataSourceColumns.find((col_1) => col_1.name == key_1), value);
168
+ newRow[key_1] = value;
174
169
  }
175
170
  return newRow;
176
171
  });
@@ -192,7 +187,7 @@ class PostgresConnector {
192
187
  }
193
188
  return value;
194
189
  }
195
- getData(_a) {
190
+ getDataWithOriginalTypes(_a) {
196
191
  return __awaiter(this, arguments, void 0, function* ({ resource, limit, offset, sort, filters }) {
197
192
  const columns = resource.dataSourceColumns.map((col) => `"${col.name}"`).join(', ');
198
193
  const tableName = resource.table;
@@ -220,13 +215,7 @@ class PostgresConnector {
220
215
  const filterValues = [];
221
216
  filters.length ? filters.forEach((f) => {
222
217
  // for arrays do set in map
223
- let v;
224
- if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
225
- v = f.value.map((val) => this.setFieldValue(resource.dataSourceColumns.find((col) => col.name == f.field), val));
226
- }
227
- else {
228
- v = this.setFieldValue(resource.dataSourceColumns.find((col) => col.name == f.field), f.value);
229
- }
218
+ let v = f.value;
230
219
  if (f.operator == AdminForthFilterOperators.LIKE || f.operator == AdminForthFilterOperators.ILIKE) {
231
220
  filterValues.push(`%${v}%`);
232
221
  }
@@ -247,12 +236,11 @@ class PostgresConnector {
247
236
  const stmt = yield this.db.query(selectQuery, d);
248
237
  const rows = stmt.rows;
249
238
  const total = (yield this.db.query(`SELECT COUNT(*) FROM ${tableName} ${where}`, filterValues)).rows[0].count;
250
- // run all fields via getFieldValue
251
239
  return {
252
240
  data: rows.map((row) => {
253
241
  const newRow = {};
254
242
  for (const [key, value] of Object.entries(row)) {
255
- newRow[key] = this.getFieldValue(resource.dataSourceColumns.find((col) => col.name == key), value);
243
+ newRow[key] = value;
256
244
  }
257
245
  return newRow;
258
246
  }),
@@ -260,7 +248,7 @@ class PostgresConnector {
260
248
  };
261
249
  });
262
250
  }
263
- getMinMaxForColumns(_a) {
251
+ getMinMaxForColumnsWithOriginalTypes(_a) {
264
252
  return __awaiter(this, arguments, void 0, function* ({ resource, columns }) {
265
253
  const tableName = resource.table;
266
254
  const result = {};
@@ -268,8 +256,7 @@ class PostgresConnector {
268
256
  const stmt = yield this.db.query(`SELECT MIN(${col.name}) as min, MAX(${col.name}) as max FROM ${tableName}`);
269
257
  const { min, max } = stmt.rows[0];
270
258
  result[col.name] = {
271
- min: this.getFieldValue(col, min),
272
- max: this.getFieldValue(col, max),
259
+ min, max,
273
260
  };
274
261
  })));
275
262
  return result;
@@ -280,15 +267,7 @@ class PostgresConnector {
280
267
  const tableName = resource.table;
281
268
  const columns = Object.keys(record);
282
269
  const placeholders = columns.map((_, i) => `$${i + 1}`).join(', ');
283
- const values = columns.map((colName) => {
284
- const col = resource.dataSourceColumns.find((col) => col.name == colName);
285
- if (col) {
286
- return this.setFieldValue(col, record[colName]);
287
- }
288
- else {
289
- return record[colName];
290
- }
291
- });
270
+ const values = columns.map((colName) => record[colName]);
292
271
  for (let i = 0; i < columns.length; i++) {
293
272
  columns[i] = `"${columns[i]}"`;
294
273
  }
@@ -296,7 +275,7 @@ class PostgresConnector {
296
275
  });
297
276
  }
298
277
  updateRecord(_a) {
299
- return __awaiter(this, arguments, void 0, function* ({ resource, recordId, record, newValues }) {
278
+ return __awaiter(this, arguments, void 0, function* ({ resource, recordId, newValues }) {
300
279
  const values = [...Object.values(newValues), recordId];
301
280
  const columnsWithPlaceholders = Object.keys(newValues).map((col, i) => `"${col}" = $${i + 1}`).join(', ');
302
281
  yield this.db.query(`UPDATE ${resource.table} SET ${columnsWithPlaceholders} WHERE "${this.getPrimaryKey(resource)}" = $${values.length}`, values);
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import betterSqlite3 from 'better-sqlite3';
11
11
  import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from '../types/AdminForthConfig.js';
12
+ import AdminForthBaseConnector from './baseConnector.js';
12
13
  import dayjs from 'dayjs';
13
- class SQLiteConnector {
14
+ class SQLiteConnector extends AdminForthBaseConnector {
14
15
  constructor({ url }) {
15
- // create connection here
16
+ super();
16
17
  this.OperatorsMap = {
17
18
  [AdminForthFilterOperators.EQ]: '=',
18
19
  [AdminForthFilterOperators.NE]: '!=',
@@ -29,6 +30,7 @@ class SQLiteConnector {
29
30
  [AdminForthSortDirections.asc]: 'ASC',
30
31
  [AdminForthSortDirections.desc]: 'DESC',
31
32
  };
33
+ // create connection here
32
34
  this.db = betterSqlite3(url.replace('sqlite://', ''));
33
35
  }
34
36
  discoverFields(resource) {
@@ -85,13 +87,6 @@ class SQLiteConnector {
85
87
  return fieldTypes;
86
88
  });
87
89
  }
88
- getPrimaryKey(resource) {
89
- for (const col of resource.dataSourceColumns) {
90
- if (col.primaryKey) {
91
- return col.name;
92
- }
93
- }
94
- }
95
90
  getFieldValue(field, value) {
96
91
  if (field.type == AdminForthDataTypes.DATETIME) {
97
92
  if (!value) {
@@ -118,7 +113,7 @@ class SQLiteConnector {
118
113
  }
119
114
  return value;
120
115
  }
121
- getRecordByPrimaryKey(resource, key) {
116
+ getRecordByPrimaryKeyWithOriginalTypes(resource, key) {
122
117
  return __awaiter(this, void 0, void 0, function* () {
123
118
  const columns = resource.dataSourceColumns.map((col) => col.name).join(', ');
124
119
  const tableName = resource.table;
@@ -129,7 +124,7 @@ class SQLiteConnector {
129
124
  }
130
125
  const newRow = {};
131
126
  for (const [key, value] of Object.entries(row)) {
132
- newRow[key] = this.getFieldValue(resource.dataSourceColumns.find((col) => col.name == key), value);
127
+ newRow[key] = value;
133
128
  }
134
129
  return newRow;
135
130
  });
@@ -153,65 +148,60 @@ class SQLiteConnector {
153
148
  }
154
149
  return value;
155
150
  }
156
- getData({ resource, limit, offset, sort, filters }) {
157
- const columns = resource.dataSourceColumns.map((col) => col.name).join(', ');
158
- const tableName = resource.table;
159
- const where = filters.length ? `WHERE ${filters.map((f, i) => {
160
- let placeholder = '?';
161
- let field = f.field;
162
- let operator = this.OperatorsMap[f.operator];
163
- if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
164
- placeholder = `(${f.value.map(() => '?').join(', ')})`;
165
- }
166
- else if (f.operator == AdminForthFilterOperators.ILIKE) {
167
- placeholder = `LOWER(?)`;
168
- field = `LOWER(${f.field})`;
169
- operator = 'LIKE';
170
- }
171
- return `${field} ${operator} ${placeholder}`;
172
- }).join(' AND ')}` : '';
173
- const filterValues = [];
174
- filters.length ? filters.forEach((f) => {
175
- // for arrays do set in map
176
- let v;
177
- if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
178
- v = f.value.map((val) => this.setFieldValue(resource.dataSourceColumns.find((col) => col.name == f.field), val));
179
- }
180
- else {
181
- v = this.setFieldValue(resource.dataSourceColumns.find((col) => col.name == f.field), f.value);
182
- }
183
- if (f.operator == AdminForthFilterOperators.LIKE || f.operator == AdminForthFilterOperators.ILIKE) {
184
- filterValues.push(`%${v}%`);
185
- }
186
- else if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
187
- filterValues.push(...v);
188
- }
189
- else {
190
- filterValues.push(v);
191
- }
192
- }) : [];
193
- const orderBy = sort.length ? `ORDER BY ${sort.map((s) => `${s.field} ${this.SortDirectionsMap[s.direction]}`).join(', ')}` : '';
194
- const q = `SELECT ${columns} FROM ${tableName} ${where} ${orderBy} LIMIT ? OFFSET ?`;
195
- const stmt = this.db.prepare(q);
196
- const d = [...filterValues, limit, offset];
197
- if (process.env.HEAVY_DEBUG) {
198
- console.log('🪲 SQLITE Query', q, 'params:', d);
199
- }
200
- const rows = stmt.all(d);
201
- const total = this.db.prepare(`SELECT COUNT(*) FROM ${tableName} ${where}`).get([...filterValues])['COUNT(*)'];
202
- // run all fields via getFieldValue
203
- return {
204
- data: rows.map((row) => {
205
- const newRow = {};
206
- for (const [key, value] of Object.entries(row)) {
207
- newRow[key] = this.getFieldValue(resource.dataSourceColumns.find((col) => col.name == key), value);
151
+ getDataWithOriginalTypes(_a) {
152
+ return __awaiter(this, arguments, void 0, function* ({ resource, limit, offset, sort, filters }) {
153
+ const columns = resource.dataSourceColumns.map((col) => col.name).join(', ');
154
+ const tableName = resource.table;
155
+ const where = filters.length ? `WHERE ${filters.map((f, i) => {
156
+ let placeholder = '?';
157
+ let field = f.field;
158
+ let operator = this.OperatorsMap[f.operator];
159
+ if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
160
+ placeholder = `(${f.value.map(() => '?').join(', ')})`;
208
161
  }
209
- return newRow;
210
- }),
211
- total,
212
- };
162
+ else if (f.operator == AdminForthFilterOperators.ILIKE) {
163
+ placeholder = `LOWER(?)`;
164
+ field = `LOWER(${f.field})`;
165
+ operator = 'LIKE';
166
+ }
167
+ return `${field} ${operator} ${placeholder}`;
168
+ }).join(' AND ')}` : '';
169
+ const filterValues = [];
170
+ filters.length ? filters.forEach((f) => {
171
+ // for arrays do set in map
172
+ const v = f.value;
173
+ if (f.operator == AdminForthFilterOperators.LIKE || f.operator == AdminForthFilterOperators.ILIKE) {
174
+ filterValues.push(`%${v}%`);
175
+ }
176
+ else if (f.operator == AdminForthFilterOperators.IN || f.operator == AdminForthFilterOperators.NIN) {
177
+ filterValues.push(...v);
178
+ }
179
+ else {
180
+ filterValues.push(v);
181
+ }
182
+ }) : [];
183
+ const orderBy = sort.length ? `ORDER BY ${sort.map((s) => `${s.field} ${this.SortDirectionsMap[s.direction]}`).join(', ')}` : '';
184
+ const q = `SELECT ${columns} FROM ${tableName} ${where} ${orderBy} LIMIT ? OFFSET ?`;
185
+ const stmt = this.db.prepare(q);
186
+ const d = [...filterValues, limit, offset];
187
+ if (process.env.HEAVY_DEBUG) {
188
+ console.log('🪲 SQLITE Query', q, 'params:', d);
189
+ }
190
+ const rows = yield stmt.all(d);
191
+ const total = (yield this.db.prepare(`SELECT COUNT(*) FROM ${tableName} ${where}`).get([...filterValues]))['COUNT(*)'];
192
+ return {
193
+ data: rows.map((row) => {
194
+ const newRow = {};
195
+ for (const [key, value] of Object.entries(row)) {
196
+ newRow[key] = value;
197
+ }
198
+ return newRow;
199
+ }),
200
+ total,
201
+ };
202
+ });
213
203
  }
214
- getMinMaxForColumns(_a) {
204
+ getMinMaxForColumnsWithOriginalTypes(_a) {
215
205
  return __awaiter(this, arguments, void 0, function* ({ resource, columns }) {
216
206
  const tableName = resource.table;
217
207
  const result = {};
@@ -219,8 +209,7 @@ class SQLiteConnector {
219
209
  const stmt = yield this.db.prepare(`SELECT MIN(${col.name}) as min, MAX(${col.name}) as max FROM ${tableName}`);
220
210
  const { min, max } = stmt.get();
221
211
  result[col.name] = {
222
- min: this.getFieldValue(col, min),
223
- max: this.getFieldValue(col, max),
212
+ min, max,
224
213
  };
225
214
  })));
226
215
  return result;
@@ -231,28 +220,23 @@ class SQLiteConnector {
231
220
  const tableName = resource.table;
232
221
  const columns = Object.keys(record);
233
222
  const placeholders = columns.map(() => '?').join(', ');
234
- const values = columns.map((colName) => {
235
- const col = resource.dataSourceColumns.find((col) => col.name == colName);
236
- if (col) {
237
- return this.setFieldValue(col, record[colName]);
238
- }
239
- else {
240
- return record[colName];
241
- }
242
- });
243
- this.db.prepare(`INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${placeholders})`).run(values);
223
+ const values = columns.map((colName) => record[colName]);
224
+ const q = this.db.prepare(`INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${placeholders})`);
225
+ yield q.run(values);
244
226
  });
245
227
  }
246
228
  updateRecord(_a) {
247
- return __awaiter(this, arguments, void 0, function* ({ resource, recordId, record, newValues }) {
229
+ return __awaiter(this, arguments, void 0, function* ({ resource, recordId, newValues }) {
248
230
  const columnsWithPlaceholders = Object.keys(newValues).map((col) => `${col} = ?`);
249
231
  const values = [...Object.values(newValues), recordId];
250
- this.db.prepare(`UPDATE ${resource.table} SET ${columnsWithPlaceholders} WHERE ${this.getPrimaryKey(resource)} = ?`).run(values);
232
+ const q = this.db.prepare(`UPDATE ${resource.table} SET ${columnsWithPlaceholders} WHERE ${this.getPrimaryKey(resource)} = ?`);
233
+ yield q.run(values);
251
234
  });
252
235
  }
253
236
  deleteRecord(_a) {
254
237
  return __awaiter(this, arguments, void 0, function* ({ resource, recordId }) {
255
- this.db.prepare(`DELETE FROM ${resource.table} WHERE ${this.getPrimaryKey(resource)} = ?`).run(recordId);
238
+ const q = this.db.prepare(`DELETE FROM ${resource.table} WHERE ${this.getPrimaryKey(resource)} = ?`);
239
+ yield q.run(recordId);
256
240
  });
257
241
  }
258
242
  close() {