@saltcorn/data 0.6.1-beta.3 → 0.6.1
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/models/file.js +9 -2
- package/models/page.js +5 -1
- package/models/table.js +10 -2
- package/models/view.js +26 -22
- package/package.json +5 -5
package/models/file.js
CHANGED
|
@@ -50,7 +50,14 @@ class File {
|
|
|
50
50
|
* @param selectopts
|
|
51
51
|
* @returns {Promise<*>}
|
|
52
52
|
*/
|
|
53
|
-
static async find(where, selectopts) {
|
|
53
|
+
static async find(where, selectopts = {}) {
|
|
54
|
+
if (selectopts.cached) {
|
|
55
|
+
const { getState } = require("../db/state");
|
|
56
|
+
const files = Object.values(getState().files).sort((a, b) =>
|
|
57
|
+
a.filename > b.filename ? 1 : -1
|
|
58
|
+
);
|
|
59
|
+
return files.map((t) => new File(t));
|
|
60
|
+
}
|
|
54
61
|
const db_flds = await db.select("_sc_files", where, selectopts);
|
|
55
62
|
return db_flds.map((dbf) => new File(dbf));
|
|
56
63
|
}
|
|
@@ -157,7 +164,7 @@ class File {
|
|
|
157
164
|
return { error: e.message };
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
|
-
|
|
167
|
+
|
|
161
168
|
/**
|
|
162
169
|
* MIME type of the file
|
|
163
170
|
* @type {string}
|
package/models/page.js
CHANGED
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
*/
|
|
33
33
|
class Page {
|
|
34
34
|
/**
|
|
35
|
-
* @param {object} o
|
|
35
|
+
* @param {object} o
|
|
36
36
|
*/
|
|
37
37
|
constructor(o) {
|
|
38
38
|
this.name = o.name;
|
|
@@ -56,6 +56,10 @@ class Page {
|
|
|
56
56
|
* @returns {Promise<*>}
|
|
57
57
|
*/
|
|
58
58
|
static async find(where, selectopts = { orderBy: "name", nocase: true }) {
|
|
59
|
+
if (selectopts.cached) {
|
|
60
|
+
const { getState } = require("../db/state");
|
|
61
|
+
return getState().pages.map((t) => new Page(t));
|
|
62
|
+
}
|
|
59
63
|
const db_flds = await db.select("_sc_pages", where, selectopts);
|
|
60
64
|
return db_flds.map((dbf) => new Page(dbf));
|
|
61
65
|
}
|
package/models/table.js
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* @subcategory models
|
|
6
6
|
*/
|
|
7
7
|
const db = require("../db");
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
sqlsanitize,
|
|
10
|
+
mkWhere,
|
|
11
|
+
mkSelectOptions,
|
|
12
|
+
} = require("@saltcorn/db-common/internal.js");
|
|
9
13
|
const Field = require("./field");
|
|
10
14
|
const Trigger = require("./trigger");
|
|
11
15
|
const {
|
|
@@ -87,7 +91,7 @@ const normalise_error_message = (msg) =>
|
|
|
87
91
|
class Table {
|
|
88
92
|
/**
|
|
89
93
|
* Table constructor
|
|
90
|
-
* @param {object} o
|
|
94
|
+
* @param {object} o
|
|
91
95
|
*/
|
|
92
96
|
constructor(o) {
|
|
93
97
|
this.name = o.name;
|
|
@@ -141,6 +145,10 @@ class Table {
|
|
|
141
145
|
* @returns {Promise<Table[]>} table list
|
|
142
146
|
*/
|
|
143
147
|
static async find(where, selectopts = { orderBy: "name", nocase: true }) {
|
|
148
|
+
if (selectopts.cached) {
|
|
149
|
+
const { getState } = require("../db/state");
|
|
150
|
+
return getState().tables.map((t) => new Table(t));
|
|
151
|
+
}
|
|
144
152
|
const tbls = await db.select("_sc_tables", where, selectopts);
|
|
145
153
|
|
|
146
154
|
return tbls.map((t) => new Table(t));
|
package/models/view.js
CHANGED
|
@@ -28,7 +28,7 @@ const { renderForm } = require("@saltcorn/markup");
|
|
|
28
28
|
class View {
|
|
29
29
|
/**
|
|
30
30
|
* View constructor
|
|
31
|
-
* @param {object} o
|
|
31
|
+
* @param {object} o
|
|
32
32
|
*/
|
|
33
33
|
constructor(o) {
|
|
34
34
|
this.name = o.name;
|
|
@@ -55,7 +55,7 @@ class View {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* @param {object} where
|
|
58
|
+
* @param {object} where
|
|
59
59
|
* @returns {View}
|
|
60
60
|
*/
|
|
61
61
|
static findOne(where) {
|
|
@@ -78,6 +78,10 @@ class View {
|
|
|
78
78
|
* @returns {Promise<View[]>}
|
|
79
79
|
*/
|
|
80
80
|
static async find(where, selectopts = { orderBy: "name", nocase: true }) {
|
|
81
|
+
if (selectopts.cached) {
|
|
82
|
+
const { getState } = require("../db/state");
|
|
83
|
+
return getState().views.map((t) => new View(t));
|
|
84
|
+
}
|
|
81
85
|
const views = await db.select("_sc_views", where, selectopts);
|
|
82
86
|
|
|
83
87
|
return views.map((v) => new View(v));
|
|
@@ -159,7 +163,7 @@ class View {
|
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
/**
|
|
162
|
-
* @param {function} pred
|
|
166
|
+
* @param {function} pred
|
|
163
167
|
* @returns {Promise<object>}
|
|
164
168
|
*/
|
|
165
169
|
static async find_all_views_where(pred) {
|
|
@@ -182,7 +186,7 @@ class View {
|
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
/**
|
|
185
|
-
* @param {Table|object} table
|
|
189
|
+
* @param {Table|object} table
|
|
186
190
|
* @returns {Promise<View[]>}
|
|
187
191
|
*/
|
|
188
192
|
static async find_possible_links_to_table(table) {
|
|
@@ -275,7 +279,7 @@ class View {
|
|
|
275
279
|
}
|
|
276
280
|
|
|
277
281
|
/**
|
|
278
|
-
* @param {*} arg
|
|
282
|
+
* @param {*} arg
|
|
279
283
|
* @returns {Promise<object>}
|
|
280
284
|
*/
|
|
281
285
|
async authorise_post(arg) {
|
|
@@ -284,7 +288,7 @@ class View {
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
/**
|
|
287
|
-
* @param {*} arg
|
|
291
|
+
* @param {*} arg
|
|
288
292
|
* @returns {Promise<object>}
|
|
289
293
|
*/
|
|
290
294
|
async authorise_get(arg) {
|
|
@@ -334,9 +338,9 @@ class View {
|
|
|
334
338
|
}
|
|
335
339
|
|
|
336
340
|
/**
|
|
337
|
-
* @param {*} query
|
|
338
|
-
* @param {*} req
|
|
339
|
-
* @param {*} res
|
|
341
|
+
* @param {*} query
|
|
342
|
+
* @param {*} req
|
|
343
|
+
* @param {*} res
|
|
340
344
|
* @returns {Promise<object>}
|
|
341
345
|
*/
|
|
342
346
|
async run_possibly_on_page(query, req, res) {
|
|
@@ -361,8 +365,8 @@ class View {
|
|
|
361
365
|
}
|
|
362
366
|
|
|
363
367
|
/**
|
|
364
|
-
* @param {*} query
|
|
365
|
-
* @param {*} extraArgs
|
|
368
|
+
* @param {*} query
|
|
369
|
+
* @param {*} extraArgs
|
|
366
370
|
* @throws {InvalidConfiguration}
|
|
367
371
|
* @returns {Promise<object>}
|
|
368
372
|
*/
|
|
@@ -405,9 +409,9 @@ class View {
|
|
|
405
409
|
}
|
|
406
410
|
|
|
407
411
|
/**
|
|
408
|
-
* @param {*} query
|
|
409
|
-
* @param {*} body
|
|
410
|
-
* @param {*} extraArgs
|
|
412
|
+
* @param {*} query
|
|
413
|
+
* @param {*} body
|
|
414
|
+
* @param {*} extraArgs
|
|
411
415
|
* @returns {Promise<object>}
|
|
412
416
|
*/
|
|
413
417
|
async runPost(query, body, extraArgs) {
|
|
@@ -423,10 +427,10 @@ class View {
|
|
|
423
427
|
}
|
|
424
428
|
|
|
425
429
|
/**
|
|
426
|
-
* @param {*} route
|
|
427
|
-
* @param {*} body
|
|
428
|
-
* @param {*} res
|
|
429
|
-
* @param {*} extraArgs
|
|
430
|
+
* @param {*} route
|
|
431
|
+
* @param {*} body
|
|
432
|
+
* @param {*} res
|
|
433
|
+
* @param {*} extraArgs
|
|
430
434
|
* @returns {Promise<void>}
|
|
431
435
|
*/
|
|
432
436
|
async runRoute(route, body, res, extraArgs) {
|
|
@@ -444,7 +448,7 @@ class View {
|
|
|
444
448
|
}
|
|
445
449
|
|
|
446
450
|
/**
|
|
447
|
-
* @param {object} req_query
|
|
451
|
+
* @param {object} req_query
|
|
448
452
|
* @returns {object}
|
|
449
453
|
*/
|
|
450
454
|
combine_state_and_default_state(req_query) {
|
|
@@ -463,8 +467,8 @@ class View {
|
|
|
463
467
|
}
|
|
464
468
|
|
|
465
469
|
/**
|
|
466
|
-
* @param {object} query
|
|
467
|
-
* @param {object} req
|
|
470
|
+
* @param {object} query
|
|
471
|
+
* @param {object} req
|
|
468
472
|
* @returns {Promise<Form|null>}
|
|
469
473
|
*/
|
|
470
474
|
async get_state_form(query, req) {
|
|
@@ -501,7 +505,7 @@ class View {
|
|
|
501
505
|
}
|
|
502
506
|
|
|
503
507
|
/**
|
|
504
|
-
* @param {object} req
|
|
508
|
+
* @param {object} req
|
|
505
509
|
* @returns {Promise<object>}
|
|
506
510
|
*/
|
|
507
511
|
async get_config_flow(req) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/data",
|
|
3
|
-
"version": "0.6.1
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Data models for Saltcorn, open-source no-code platform",
|
|
5
5
|
"homepage": "https://saltcorn.com",
|
|
6
6
|
"scripts": {
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"main": "index.js",
|
|
12
12
|
"optionalDependencies": {
|
|
13
|
-
"@saltcorn/postgres": "0.6.1
|
|
14
|
-
"@saltcorn/sqlite": "0.6.1
|
|
13
|
+
"@saltcorn/postgres": "0.6.1",
|
|
14
|
+
"@saltcorn/sqlite": "0.6.1"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@saltcorn/markup": "0.6.1
|
|
18
|
-
"@saltcorn/db-common": "0.6.1
|
|
17
|
+
"@saltcorn/markup": "0.6.1",
|
|
18
|
+
"@saltcorn/db-common": "0.6.1",
|
|
19
19
|
"acorn": "^8.0.3",
|
|
20
20
|
"adm-zip": "0.5.5",
|
|
21
21
|
"astring": "^1.4.3",
|