@saltcorn/data 0.6.3-beta.0 → 0.6.3-beta.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.
Files changed (69) hide show
  1. package/dist/base-plugin/fieldviews.d.ts.map +1 -1
  2. package/dist/base-plugin/fieldviews.js +2 -0
  3. package/dist/base-plugin/fieldviews.js.map +1 -1
  4. package/dist/base-plugin/index.d.ts +26 -26
  5. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  6. package/dist/base-plugin/viewtemplates/show.js +6 -1
  7. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  8. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +2 -1
  9. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  10. package/dist/base-plugin/viewtemplates/viewable_fields.js +29 -9
  11. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  12. package/dist/db/connect.d.ts.map +1 -1
  13. package/dist/db/connect.js +8 -2
  14. package/dist/db/connect.js.map +1 -1
  15. package/dist/db/index.d.ts +6 -0
  16. package/dist/db/index.d.ts.map +1 -1
  17. package/dist/db/index.js +6 -0
  18. package/dist/db/index.js.map +1 -1
  19. package/dist/db/state.js +4 -4
  20. package/dist/db/state.js.map +1 -1
  21. package/dist/migrate.js +1 -1
  22. package/dist/migrate.js.map +1 -1
  23. package/dist/migrations/202112282254.d.ts +3 -0
  24. package/dist/migrations/202112282254.d.ts.map +1 -0
  25. package/dist/migrations/202112282254.js +5 -0
  26. package/dist/migrations/202112282254.js.map +1 -0
  27. package/dist/models/backup.d.ts +3 -1
  28. package/dist/models/backup.d.ts.map +1 -1
  29. package/dist/models/backup.js +59 -61
  30. package/dist/models/backup.js.map +1 -1
  31. package/dist/models/field.d.ts +8 -7
  32. package/dist/models/field.d.ts.map +1 -1
  33. package/dist/models/field.js +13 -17
  34. package/dist/models/field.js.map +1 -1
  35. package/dist/models/fieldrepeat.d.ts +22 -20
  36. package/dist/models/fieldrepeat.d.ts.map +1 -1
  37. package/dist/models/fieldrepeat.js +6 -14
  38. package/dist/models/fieldrepeat.js.map +1 -1
  39. package/dist/models/form.d.ts +69 -50
  40. package/dist/models/form.d.ts.map +1 -1
  41. package/dist/models/form.js +49 -51
  42. package/dist/models/form.js.map +1 -1
  43. package/dist/models/role.d.ts +9 -0
  44. package/dist/models/role.d.ts.map +1 -1
  45. package/dist/models/role.js +6 -1
  46. package/dist/models/role.js.map +1 -1
  47. package/dist/models/table.d.ts +17 -5
  48. package/dist/models/table.d.ts.map +1 -1
  49. package/dist/models/table.js +69 -8
  50. package/dist/models/table.js.map +1 -1
  51. package/dist/models/view.d.ts +109 -98
  52. package/dist/models/view.d.ts.map +1 -1
  53. package/dist/models/view.js +105 -80
  54. package/dist/models/view.js.map +1 -1
  55. package/dist/models/workflow.d.ts +23 -21
  56. package/dist/models/workflow.d.ts.map +1 -1
  57. package/dist/models/workflow.js +9 -17
  58. package/dist/models/workflow.js.map +1 -1
  59. package/dist/plugin-helper.d.ts.map +1 -1
  60. package/dist/plugin-helper.js +30 -12
  61. package/dist/plugin-helper.js.map +1 -1
  62. package/dist/tests/table.test.js +50 -2
  63. package/dist/tests/table.test.js.map +1 -1
  64. package/dist/tsconfig.ref.tsbuildinfo +1 -1
  65. package/package.json +8 -5
  66. package/dist/common_types.d.ts +0 -28
  67. package/dist/common_types.d.ts.map +0 -1
  68. package/dist/common_types.js +0 -16
  69. package/dist/common_types.js.map +0 -1
@@ -1,118 +1,135 @@
1
- export = View;
1
+ /**
2
+ * View Data Access Layer
3
+ * @category saltcorn-data
4
+ * @module models/view
5
+ * @subcategory models
6
+ */
7
+ import Form from "./form";
8
+ import type { ViewTemplate, FieldLike, Tablely, RunExtra } from "@saltcorn/types/base_types";
9
+ import type Table from "./table";
10
+ import type { Where, SelectOptions } from "@saltcorn/db-common/internal";
11
+ import type Workflow from "./workflow";
2
12
  /**
3
13
  * View Class
4
14
  * @category saltcorn-data
5
15
  */
6
16
  declare class View {
17
+ name: string;
18
+ id?: number;
19
+ table_id?: number;
20
+ viewtemplate: string;
21
+ min_role: number;
22
+ viewtemplateObj?: ViewTemplate;
23
+ default_render_page?: string;
24
+ exttable_name?: string;
25
+ description?: string;
26
+ table_name?: string;
27
+ configuration?: any;
28
+ table?: Table;
29
+ slug?: any;
30
+ /**
31
+ * View constructor
32
+ * @param {object} o
33
+ */
34
+ constructor(o: ViewCfg | View);
7
35
  /**
8
36
  * @param {object} where
9
37
  * @returns {View}
10
38
  */
11
- static findOne(where: object): View;
39
+ static findOne(where: Where): View | undefined;
12
40
  /**
13
41
  * @param where
14
42
  * @param selectopts
15
43
  * @returns {Promise<View[]>}
16
44
  */
17
- static find(where: any, selectopts?: {
18
- orderBy: string;
19
- nocase: boolean;
20
- }): Promise<View[]>;
45
+ static find(where: Where, selectopts?: SelectOptions): Promise<Array<View>>;
46
+ /**
47
+ * @returns {Promise<object[]>}
48
+ */
49
+ get_state_fields(): Promise<Array<FieldLike>>;
50
+ /**
51
+ * Get menu label
52
+ * @type {string|undefined}
53
+ */
54
+ get menu_label(): string | undefined;
21
55
  /**
22
56
  * @param table
23
57
  * @param pred
24
58
  * @returns {Promise<object[]>}
25
59
  */
26
- static find_table_views_where(table: any, pred: any): Promise<object[]>;
60
+ static find_table_views_where(table: number | Tablely | string, pred: FindViewsPred): Promise<Array<View>>;
61
+ /**
62
+ * @type {object}
63
+ */
64
+ get select_option(): any;
27
65
  /**
28
66
  * @param {function} pred
29
67
  * @returns {Promise<object>}
30
68
  */
31
- static find_all_views_where(pred: Function): Promise<object>;
69
+ static find_all_views_where(pred: FindViewsPred): Promise<Array<View>>;
32
70
  /**
33
71
  * @param {Table|object} table
34
72
  * @returns {Promise<View[]>}
35
73
  */
36
- static find_possible_links_to_table(table: Table | object): Promise<View[]>;
74
+ static find_possible_links_to_table(table: number | Tablely | string): Promise<Array<View>>;
37
75
  /**
38
76
  * Create view in database
39
77
  * @param v
40
78
  * @returns {Promise<View>}
41
79
  */
42
- static create(v: any): Promise<View>;
80
+ static create(v: ViewCfg): Promise<View>;
81
+ /**
82
+ * Clone View
83
+ * @returns {Promise<View>}
84
+ */
85
+ clone(): Promise<View>;
86
+ /**
87
+ * Delete current view from db
88
+ * @returns {Promise<void>}
89
+ */
90
+ delete(): Promise<void>;
43
91
  /**
44
92
  * Delete list of views
45
93
  * @param where - condition
46
94
  * @returns {Promise<void>}
47
95
  */
48
- static delete(where: any): Promise<void>;
96
+ static delete(where: Where): Promise<void>;
49
97
  /**
50
98
  * Update View description
51
99
  * @param v - view name
52
100
  * @param id - id
53
101
  * @returns {Promise<void>}
54
102
  */
55
- static update(v: any, id: any): Promise<void>;
56
- /**
57
- * View constructor
58
- * @param {object} o
59
- */
60
- constructor(o: object);
61
- name: any;
62
- id: any;
63
- viewtemplate: any;
64
- exttable_name: any;
65
- description: any;
66
- table_id: any;
67
- table_name: any;
68
- configuration: any;
69
- min_role: number;
70
- viewtemplateObj: any;
71
- default_render_page: any;
72
- /**
73
- * @returns {Promise<object[]>}
74
- */
75
- get_state_fields(): Promise<object[]>;
76
- /**
77
- * Get menu label
78
- * @type {string|undefined}
79
- */
80
- get menu_label(): string | undefined;
81
- /**
82
- * @type {object}
83
- */
84
- get select_option(): object;
85
- /**
86
- * Clone View
87
- * @returns {Promise<View>}
88
- */
89
- clone(): Promise<View>;
90
- /**
91
- * Delete current view from db
92
- * @returns {Promise<void>}
93
- */
94
- delete(): Promise<void>;
103
+ static update(v: any, id: number): Promise<void>;
95
104
  /**
96
105
  * @param {*} arg
97
106
  * @returns {Promise<object>}
98
107
  */
99
- authorise_post(arg: any): Promise<object>;
108
+ authorise_post(arg: {
109
+ body: any;
110
+ table_id: number;
111
+ req: NonNullable<any>;
112
+ }): Promise<boolean>;
100
113
  /**
101
114
  * @param {*} arg
102
115
  * @returns {Promise<object>}
103
116
  */
104
- authorise_get(arg: any): Promise<object>;
117
+ authorise_get(arg: {
118
+ query: any;
119
+ table_id: number;
120
+ req: NonNullable<any>;
121
+ }): Promise<boolean>;
105
122
  /**
106
123
  * @returns {string}
107
124
  */
108
- getStringsForI18n(): string;
125
+ getStringsForI18n(): string[];
109
126
  /**
110
127
  * Run (Execute) View
111
128
  * @param query
112
129
  * @param extraArgs
113
130
  * @returns {Promise<*>}
114
131
  */
115
- run(query: any, extraArgs: any): Promise<any>;
132
+ run(query: any, extraArgs: RunExtra): Promise<any>;
116
133
  /**
117
134
  * @throws {InvalidConfiguration}
118
135
  */
@@ -123,21 +140,24 @@ declare class View {
123
140
  * @param {*} res
124
141
  * @returns {Promise<object>}
125
142
  */
126
- run_possibly_on_page(query: any, req: any, res: any): Promise<object>;
143
+ run_possibly_on_page(query: NonNullable<any>, req: NonNullable<any>, res: NonNullable<any>): Promise<string>;
127
144
  /**
128
145
  * @param {*} query
129
146
  * @param {*} extraArgs
130
147
  * @throws {InvalidConfiguration}
131
148
  * @returns {Promise<object>}
132
149
  */
133
- runMany(query: any, extraArgs: any): Promise<object>;
150
+ runMany(query: string, extraArgs: RunExtra): Promise<string[] | Array<{
151
+ html: string;
152
+ row: any;
153
+ }>>;
134
154
  /**
135
155
  * @param {*} query
136
156
  * @param {*} body
137
157
  * @param {*} extraArgs
138
158
  * @returns {Promise<object>}
139
159
  */
140
- runPost(query: any, body: any, extraArgs: any): Promise<object>;
160
+ runPost(query: string, body: string, extraArgs: RunExtra): Promise<any>;
141
161
  /**
142
162
  * @param {*} route
143
163
  * @param {*} body
@@ -145,60 +165,51 @@ declare class View {
145
165
  * @param {*} extraArgs
146
166
  * @returns {Promise<void>}
147
167
  */
148
- runRoute(route: any, body: any, res: any, extraArgs: any): Promise<void>;
168
+ runRoute(route: string, body: any, res: NonNullable<any>, extraArgs: RunExtra): Promise<any>;
149
169
  /**
150
170
  * @param {object} req_query
151
171
  * @returns {object}
152
172
  */
153
- combine_state_and_default_state(req_query: object): object;
173
+ combine_state_and_default_state(req_query: any): any;
154
174
  /**
155
175
  * @param {object} query
156
176
  * @param {object} req
157
177
  * @returns {Promise<Form|null>}
158
178
  */
159
- get_state_form(query: object, req: object): Promise<Form | null>;
179
+ get_state_form(query: any, req: ReqFunction): Promise<Form | null>;
160
180
  /**
161
181
  * @param {object} req
162
182
  * @returns {Promise<object>}
163
183
  */
164
- get_config_flow(req: object): Promise<object>;
184
+ get_config_flow(req: ReqFunction): Promise<Workflow>;
185
+ rewrite_query_from_slug(query: any, params: any): void;
165
186
  }
187
+ declare type ReqFunction = {
188
+ __: (arg0: string) => string;
189
+ };
166
190
  declare namespace View {
167
- namespace contract {
168
- namespace variables {
169
- const name: any;
170
- const id: any;
171
- const table_id: any;
172
- const viewtemplate: any;
173
- const min_role: any;
174
- const viewtemplateObj: any;
175
- const default_render_page: any;
176
- }
177
- namespace methods {
178
- export const get_state_fields: any;
179
- export const get_state_form: any;
180
- export const get_config_flow: any;
181
- const _delete: any;
182
- export { _delete as delete };
183
- export const menu_label: any;
184
- export const run: any;
185
- export const runPost: any;
186
- export const runRoute: any;
187
- export const runMany: any;
188
- export const combine_state_and_default_state: any;
189
- }
190
- namespace static_methods {
191
- export const find: any;
192
- export const findOne: any;
193
- export const create: any;
194
- export const update: any;
195
- const _delete_1: any;
196
- export { _delete_1 as delete };
197
- export const find_possible_links_to_table: any;
198
- export const find_all_views_where: any;
199
- export const find_table_views_where: any;
200
- }
201
- }
191
+ type ViewCfg = {
192
+ name: string;
193
+ id?: number;
194
+ viewtemplate: string;
195
+ table_id?: number;
196
+ table?: Table;
197
+ exttable_name?: string;
198
+ description?: string;
199
+ table_name?: string;
200
+ configuration?: string | any;
201
+ min_role?: number;
202
+ is_public?: boolean;
203
+ default_render_page?: string;
204
+ slug?: any;
205
+ };
206
+ type FindViewsPred = (arg0: {
207
+ viewrow: View;
208
+ viewtemplate?: ViewTemplate;
209
+ state_fields: Array<FieldLike>;
210
+ }) => boolean;
202
211
  }
203
- import Form = require("../models/form");
212
+ declare type ViewCfg = View.ViewCfg;
213
+ declare type FindViewsPred = View.FindViewsPred;
214
+ export = View;
204
215
  //# sourceMappingURL=view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../models/view.js"],"names":[],"mappings":";AAuBA;;;GAGG;AACH;IA6BE;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAchB;IAED;;;;OAIG;IACH;;;QAFa,QAAQ,IAAI,EAAE,CAAC,CAU3B;IA0BD;;;;OAIG;IACH,sDAFa,QAAQ,MAAM,EAAE,CAAC,CA8B7B;IAkBD;;;OAGG;IACH,6CAFa,QAAQ,MAAM,CAAC,CAmB3B;IAED;;;OAGG;IACH,2CAHW,QAAM,MAAM,GACV,QAAQ,IAAI,EAAE,CAAC,CAM3B;IAED;;;;OAIG;IAEH,uBAHa,QAAQ,IAAI,CAAC,CAczB;IA2CD;;;;OAIG;IACH,2BAFa,QAAQ,IAAI,CAAC,CAKzB;IAED;;;;;OAKG;IACH,gCAFa,QAAQ,IAAI,CAAC,CAOzB;IA1PD;;;OAGG;IACH,eAFW,MAAM,EAwBhB;IArBC,UAAkB;IAClB,QAAc;IACd,kBAAkC;IAClC,mBAAoC;IACpC,iBAAgC;IAChB,cAA0B;IAIxB,gBAA8B;IAChD,mBAAkD;IAClD,iBAKiB;IAEjB,qBAAkE;IAClE,yBAAgD;IAqClD;;OAEG;IACH,oBAFa,QAAQ,MAAM,EAAE,CAAC,CAU7B;IAED;;;OAGG;IACH,qCAKC;IAqCD;;OAEG;IACH,4BAWC;IAsDD;;;OAGG;IACH,SAFa,QAAQ,IAAI,CAAC,CAkBzB;IAED;;;OAGG;IACH,UAFa,QAAQ,IAAI,CAAC,CAezB;IAyBD;;;OAGG;IACH,0BAFa,QAAQ,MAAM,CAAC,CAK3B;IAED;;;OAGG;IACH,yBAFa,QAAQ,MAAM,CAAC,CAK3B;IAED;;OAEG;IACH,qBAFa,MAAM,CAMlB;IAED;;;;;OAKG;IACH,iCAFa,YAAU,CAgBtB;IAED;;OAEG;IACH,2BAKC;IAED;;;;;OAKG;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,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;AAC5B,aAAK,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;AAExC,SAAS,IAAI,CAAC"}
@@ -5,14 +5,37 @@
5
5
  * @module models/view
6
6
  * @subcategory models
7
7
  */
8
- const db = require("../db");
9
- const Form = require("../models/form");
10
- const { contract, is } = require("contractis");
11
- const { fieldlike, is_viewtemplate, is_tablely } = require("../contracts");
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ const db_1 = __importDefault(require("../db"));
31
+ const form_1 = __importDefault(require("./form"));
12
32
  const { removeEmptyStrings, numberToBool, stringToJSON, InvalidConfiguration, satisfies, structuredClone, } = require("../utils");
13
33
  const { remove_from_menu } = require("./config");
14
- const { div } = require("@saltcorn/markup/tags");
15
- const { renderForm } = require("@saltcorn/markup");
34
+ const tags_1 = __importDefault(require("@saltcorn/markup/tags"));
35
+ const { div } = tags_1.default;
36
+ const markup_1 = __importDefault(require("@saltcorn/markup"));
37
+ const { renderForm } = markup_1.default;
38
+ const common_types_1 = require("@saltcorn/types/common_types");
16
39
  /**
17
40
  * View Class
18
41
  * @category saltcorn-data
@@ -36,8 +59,11 @@ class View {
36
59
  if (o.table_name)
37
60
  this.table_name = o.table_name;
38
61
  this.configuration = stringToJSON(o.configuration);
62
+ if (!o.min_role && !o.is_public) {
63
+ throw new InvalidConfiguration(`Unable to build view ${this.name}, neither 'min_role' or 'is_public' is given.`);
64
+ }
39
65
  this.min_role =
40
- !o.min_role && typeof o.is_public !== "undefined"
66
+ !o.min_role && typeWithDefinedMember(o, "is_public")
41
67
  ? o.is_public
42
68
  ? 10
43
69
  : 8
@@ -45,7 +71,8 @@ class View {
45
71
  const { getState } = require("../db/state");
46
72
  this.viewtemplateObj = getState().viewtemplates[this.viewtemplate];
47
73
  this.default_render_page = o.default_render_page;
48
- contract.class(this);
74
+ this.table = o.table;
75
+ this.slug = stringToJSON(o.slug);
49
76
  }
50
77
  /**
51
78
  * @param {object} where
@@ -72,14 +99,16 @@ class View {
72
99
  const { getState } = require("../db/state");
73
100
  return getState().views.map((t) => new View(t));
74
101
  }
75
- const views = await db.select("_sc_views", where, selectopts);
102
+ const views = await db_1.default.select("_sc_views", where, selectopts);
76
103
  return views.map((v) => new View(v));
77
104
  }
78
105
  /**
79
106
  * @returns {Promise<object[]>}
80
107
  */
81
108
  async get_state_fields() {
82
- if (this.viewtemplateObj && this.viewtemplateObj.get_state_fields) {
109
+ if (this.viewtemplateObj &&
110
+ this.viewtemplateObj.get_state_fields &&
111
+ this.table_id) {
83
112
  return await this.viewtemplateObj.get_state_fields(this.table_id, this.name, this.configuration);
84
113
  }
85
114
  else
@@ -102,11 +131,11 @@ class View {
102
131
  */
103
132
  static async find_table_views_where(table, pred) {
104
133
  var link_view_opts = [];
105
- const link_views = await View.find(table.id
134
+ const link_views = await View.find(typeWithDefinedMember(table, "id")
106
135
  ? {
107
136
  table_id: table.id,
108
137
  }
109
- : table.name
138
+ : typeWithDefinedMember(table, "name")
110
139
  ? { exttable_name: table.name }
111
140
  : typeof table === "string"
112
141
  ? { exttable_name: table }
@@ -174,8 +203,9 @@ class View {
174
203
  v.min_role = v.is_public ? 10 : 8;
175
204
  delete v.is_public;
176
205
  }
206
+ const { table, ...row } = v;
177
207
  // insert view defintion into _sc_views
178
- const id = await db.insert("_sc_views", v);
208
+ const id = await db_1.default.insert("_sc_views", row);
179
209
  // refresh views list cache
180
210
  await require("../db/state").getState().refresh_views();
181
211
  return new View({ id, ...v });
@@ -207,10 +237,13 @@ class View {
207
237
  * @returns {Promise<void>}
208
238
  */
209
239
  async delete() {
210
- if (this.viewtemplateObj && this.viewtemplateObj.on_delete)
240
+ if (this.viewtemplateObj &&
241
+ this.viewtemplateObj.on_delete &&
242
+ this.table_id &&
243
+ this.configuration)
211
244
  await this.viewtemplateObj.on_delete(this.table_id, this.name, this.configuration);
212
245
  // delete view from _sc_view
213
- await db.deleteWhere("_sc_views", { id: this.id });
246
+ await db_1.default.deleteWhere("_sc_views", { id: this.id });
214
247
  // remove view from menu
215
248
  await remove_from_menu({ name: this.name, type: "View" });
216
249
  // fresh view list cache
@@ -234,7 +267,7 @@ class View {
234
267
  */
235
268
  static async update(v, id) {
236
269
  // update view description
237
- await db.update("_sc_views", v, id);
270
+ await db_1.default.update("_sc_views", v, id);
238
271
  // fresh view list cache
239
272
  await require("../db/state").getState().refresh_views();
240
273
  }
@@ -243,7 +276,7 @@ class View {
243
276
  * @returns {Promise<object>}
244
277
  */
245
278
  async authorise_post(arg) {
246
- if (!this.viewtemplateObj.authorise_post)
279
+ if (!this.viewtemplateObj?.authorise_post)
247
280
  return false;
248
281
  return await this.viewtemplateObj.authorise_post(arg);
249
282
  }
@@ -252,7 +285,7 @@ class View {
252
285
  * @returns {Promise<object>}
253
286
  */
254
287
  async authorise_get(arg) {
255
- if (!this.viewtemplateObj.authorise_get)
288
+ if (!this.viewtemplateObj?.authorise_get)
256
289
  return false;
257
290
  return await this.viewtemplateObj.authorise_get(arg);
258
291
  }
@@ -272,8 +305,11 @@ class View {
272
305
  */
273
306
  async run(query, extraArgs) {
274
307
  this.check_viewtemplate();
308
+ const table_id = this.exttable_name || this.table_id;
309
+ if (!table_id)
310
+ throw new InvalidConfiguration(`Cannot run viewtemplate ${this.viewtemplate} in view ${this.name}. 'exttable_name' and 'table_id' are missing.`);
275
311
  try {
276
- return await this.viewtemplateObj.run(this.exttable_name || this.table_id, this.name, this.configuration, removeEmptyStrings(query), extraArgs);
312
+ return await this.viewtemplateObj.run(table_id, this.name, this.configuration, removeEmptyStrings(query), extraArgs);
277
313
  }
278
314
  catch (error) {
279
315
  error.message = `In ${this.name} view (${this.viewtemplate} viewtemplate):\n${error.message}`;
@@ -319,17 +355,26 @@ class View {
319
355
  async runMany(query, extraArgs) {
320
356
  this.check_viewtemplate();
321
357
  try {
322
- if (this.viewtemplateObj.runMany)
358
+ if (this.viewtemplateObj?.runMany) {
359
+ if (!this.table_id) {
360
+ throw new InvalidConfiguration(`Unable to call runMany, ${this.viewtemplate} is missing 'table_id'.`);
361
+ }
323
362
  return await this.viewtemplateObj.runMany(this.table_id, this.name, this.configuration, query, extraArgs);
324
- if (this.viewtemplateObj.renderRows) {
325
- const Table = require("./table");
326
- const { stateFieldsToWhere } = require("../plugin-helper");
363
+ }
364
+ if (this.viewtemplateObj?.renderRows) {
365
+ const Table = (await Promise.resolve().then(() => __importStar(require("./table")))).default;
366
+ const { stateFieldsToWhere } = await Promise.resolve().then(() => __importStar(require("../plugin-helper")));
327
367
  const tbl = await Table.findOne({ id: this.table_id });
368
+ if (!tbl)
369
+ throw new Error(`Unable to find table with id ${this.table_id}`);
328
370
  const fields = await tbl.getFields();
329
371
  const qstate = await stateFieldsToWhere({ fields, state: query });
330
372
  const rows = await tbl.getRows(qstate);
331
373
  const rendered = await this.viewtemplateObj.renderRows(tbl, this.name, this.configuration, extraArgs, rows);
332
- return rendered.map((html, ix) => ({ html, row: rows[ix] }));
374
+ return rendered.map((html, ix) => ({
375
+ html,
376
+ row: rows[ix],
377
+ }));
333
378
  }
334
379
  }
335
380
  catch (error) {
@@ -346,6 +391,10 @@ class View {
346
391
  */
347
392
  async runPost(query, body, extraArgs) {
348
393
  this.check_viewtemplate();
394
+ if (!this.viewtemplateObj.runPost)
395
+ throw new InvalidConfiguration(`Unable to call runPost, ${this.viewtemplate} is missing 'runPost'.`);
396
+ if (!this.table_id)
397
+ throw new InvalidConfiguration(`Unable to call runPost, ${this.viewtemplate} is missing 'table_id'.`);
349
398
  return await this.viewtemplateObj.runPost(this.table_id, this.name, this.configuration, removeEmptyStrings(query), removeEmptyStrings(body), extraArgs);
350
399
  }
351
400
  /**
@@ -357,6 +406,10 @@ class View {
357
406
  */
358
407
  async runRoute(route, body, res, extraArgs) {
359
408
  this.check_viewtemplate();
409
+ if (!this.viewtemplateObj.routes)
410
+ throw new InvalidConfiguration(`Unable to call runRoute of view '${this.name}', ${this.viewtemplate} is missing 'routes'.`);
411
+ if (!this.table_id)
412
+ throw new InvalidConfiguration(`Unable to call runRoute, of view '${this.name}', this.table_id is not set.`);
360
413
  const result = await this.viewtemplateObj.routes[route](this.table_id, this.name, this.configuration, body, extraArgs);
361
414
  if (result && result.json)
362
415
  res.json(result.json);
@@ -399,13 +452,15 @@ class View {
399
452
  f.required = false;
400
453
  if (f.label === "Anywhere" && f.name === "_fts")
401
454
  f.label = req.__(f.label);
402
- if (f.type && f.type.name === "Bool")
455
+ if ((0, common_types_1.instanceOfType)(f.type) && f.type.name === "Bool")
403
456
  f.fieldview = "tristate";
404
- if (f.type && f.type.read && typeof query[f.name] !== "undefined") {
457
+ if ((0, common_types_1.instanceOfType)(f.type) &&
458
+ f.type.read &&
459
+ typeof query[f.name] !== "undefined") {
405
460
  query[f.name] = f.type.read(query[f.name]);
406
461
  }
407
462
  });
408
- const form = new Form({
463
+ const form = new form_1.default({
409
464
  methodGET: true,
410
465
  action: `/view/${encodeURIComponent(this.name)}`,
411
466
  fields,
@@ -426,6 +481,8 @@ class View {
426
481
  */
427
482
  async get_config_flow(req) {
428
483
  this.check_viewtemplate();
484
+ if (!this.id)
485
+ throw new InvalidConfiguration(`Unable to execute 'get_config_flow' of view '${this.name}', 'this.name' must be set.`);
429
486
  const configFlow = this.viewtemplateObj.configuration_workflow(req);
430
487
  configFlow.action = `/viewedit/config/${encodeURIComponent(this.name)}`;
431
488
  const oldOnDone = configFlow.onDone || ((c) => c);
@@ -439,59 +496,27 @@ class View {
439
496
  };
440
497
  return configFlow;
441
498
  }
499
+ rewrite_query_from_slug(query, params) {
500
+ let pix = 0;
501
+ if (this.slug && this.slug.steps && this.slug.steps.length > 0) {
502
+ for (const step of this.slug.steps) {
503
+ if (step.unique) {
504
+ query[step.field] = step.transform
505
+ ? { [step.transform]: params[pix] }
506
+ : params[pix];
507
+ return;
508
+ }
509
+ pix += 1;
510
+ }
511
+ }
512
+ }
513
+ }
514
+ function typeWithDefinedMember(object, member) {
515
+ return (typeof object === "object" &&
516
+ object &&
517
+ member in object &&
518
+ object[member] !== undefined &&
519
+ object[member] !== null);
442
520
  }
443
- View.contract = {
444
- variables: {
445
- name: is.str,
446
- id: is.maybe(is.posint),
447
- table_id: is.maybe(is.posint),
448
- viewtemplate: is.str,
449
- min_role: is.posint,
450
- viewtemplateObj: is.maybe(is_viewtemplate),
451
- default_render_page: is.maybe(is.str),
452
- },
453
- methods: {
454
- get_state_fields: is.fun([], is.promise(is.array(fieldlike))),
455
- get_state_form: is.fun([is.obj(), is.obj({ __: is.fun(is.str, is.str) })], is.promise(is.maybe(is.class("Form")))),
456
- get_config_flow: is.fun(is.obj({ __: is.fun(is.str, is.str) }), is.promise(is.class("Workflow"))),
457
- delete: is.fun([], is.promise(is.undefined)),
458
- menu_label: is.getter(is.maybe(is.str)),
459
- run: is.fun([is.obj(), is.obj({ req: is.defined, res: is.defined })], is.promise(is.any)),
460
- runPost: is.fun([is.obj(), is.obj(), is.obj({ req: is.defined, res: is.defined })], is.promise(is.any)),
461
- runRoute: is.fun([
462
- is.str,
463
- is.obj(),
464
- is.obj(),
465
- is.obj({ req: is.defined, res: is.defined }),
466
- ], is.promise(is.any)),
467
- runMany: is.fun([is.obj(), is.obj({ req: is.defined, res: is.defined })], is.promise(is.array(is.obj({ html: is.defined, row: is.obj() })))),
468
- combine_state_and_default_state: is.fun(is.obj(), is.obj()),
469
- },
470
- static_methods: {
471
- find: is.fun([is.maybe(is.obj()), is.maybe(is.obj())], is.promise(is.array(is.class("View")))),
472
- findOne: is.fun(is.obj(), is.maybe(is.class("View"))),
473
- create: is.fun(is.obj({
474
- name: is.str,
475
- table_id: is.maybe(is.posint),
476
- viewtemplate: is.str,
477
- }), is.promise(is.class("View"))),
478
- update: is.fun([is.obj(), is.posint], is.promise(is.undefined)),
479
- delete: is.fun(is.obj(), is.promise(is.undefined)),
480
- find_possible_links_to_table: is.fun(is.or(is.posint, is_tablely, is.str), is.promise(is.array(is.class("View")))),
481
- find_all_views_where: is.fun(is.fun(is.obj({
482
- viewrow: is.class("View"),
483
- viewtemplate: is.obj(),
484
- state_fields: is.array(fieldlike),
485
- }), is.bool), is.promise(is.array(is.class("View")))),
486
- find_table_views_where: is.fun([
487
- is.or(is.posint, is_tablely, is.str),
488
- is.fun(is.obj({
489
- viewrow: is.class("View"),
490
- viewtemplate: is.obj(),
491
- state_fields: is.array(fieldlike),
492
- }), is.bool),
493
- ], is.promise(is.array(is.class("View")))),
494
- },
495
- };
496
521
  module.exports = View;
497
522
  //# sourceMappingURL=view.js.map