@balena/pinejs 20.1.0-build-large-file-uploads-2-1a7d50e8660ff52fe7df8d6ef9ce8b6b707027dc-1 → 21.0.0-build-21-x-aded34a9c5c670522247399b3cc4dc7814430d5e-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 (88) hide show
  1. package/.pinejs-cache.json +1 -1
  2. package/.versionbot/CHANGELOG.yml +339 -17
  3. package/CHANGELOG.md +79 -5
  4. package/Gruntfile.cts +1 -1
  5. package/VERSION +1 -1
  6. package/build/browser.cts +0 -1
  7. package/build/module.cts +0 -1
  8. package/build/server.cts +0 -1
  9. package/out/bin/utils.js +2 -3
  10. package/out/bin/utils.js.map +1 -1
  11. package/out/config-loader/env.d.ts +0 -5
  12. package/out/config-loader/env.js +0 -7
  13. package/out/config-loader/env.js.map +1 -1
  14. package/out/database-layer/db.js.map +1 -1
  15. package/out/express-emulator/express.js +4 -1
  16. package/out/express-emulator/express.js.map +1 -1
  17. package/out/migrator/async.js +6 -7
  18. package/out/migrator/async.js.map +1 -1
  19. package/out/sbvr-api/abstract-sql.js +19 -11
  20. package/out/sbvr-api/abstract-sql.js.map +1 -1
  21. package/out/sbvr-api/cached-compile.js +2 -1
  22. package/out/sbvr-api/cached-compile.js.map +1 -1
  23. package/out/sbvr-api/control-flow.js.map +1 -1
  24. package/out/sbvr-api/errors.js +1 -1
  25. package/out/sbvr-api/errors.js.map +1 -1
  26. package/out/sbvr-api/hooks.d.ts +1 -2
  27. package/out/sbvr-api/hooks.js.map +1 -1
  28. package/out/sbvr-api/sbvr-utils.d.ts +0 -10
  29. package/out/sbvr-api/sbvr-utils.js +7 -48
  30. package/out/sbvr-api/sbvr-utils.js.map +1 -1
  31. package/out/sbvr-api/translations.js +4 -17
  32. package/out/sbvr-api/translations.js.map +1 -1
  33. package/out/sbvr-api/uri-parser.d.ts +7 -1
  34. package/out/sbvr-api/uri-parser.js +0 -2
  35. package/out/sbvr-api/uri-parser.js.map +1 -1
  36. package/out/server-glue/module.js +1 -13
  37. package/out/server-glue/module.js.map +1 -1
  38. package/out/tasks/index.d.ts +1 -1
  39. package/out/tasks/index.js +2 -2
  40. package/out/tasks/index.js.map +1 -1
  41. package/out/tasks/worker.d.ts +3 -2
  42. package/out/tasks/worker.js +2 -1
  43. package/out/tasks/worker.js.map +1 -1
  44. package/out/webresource-handler/handlers/NoopHandler.js +0 -1
  45. package/out/webresource-handler/handlers/NoopHandler.js.map +1 -1
  46. package/out/webresource-handler/index.d.ts +0 -42
  47. package/out/webresource-handler/index.js +2 -25
  48. package/out/webresource-handler/index.js.map +1 -1
  49. package/package.json +32 -32
  50. package/src/bin/utils.ts +5 -3
  51. package/src/config-loader/env.ts +0 -14
  52. package/src/database-layer/db.ts +6 -2
  53. package/src/express-emulator/express.js +4 -1
  54. package/src/migrator/async.ts +20 -21
  55. package/src/sbvr-api/abstract-sql.ts +30 -25
  56. package/src/sbvr-api/cached-compile.ts +2 -1
  57. package/src/sbvr-api/control-flow.ts +1 -1
  58. package/src/sbvr-api/errors.ts +1 -1
  59. package/src/sbvr-api/express-extension.ts +1 -1
  60. package/src/sbvr-api/hooks.ts +2 -2
  61. package/src/sbvr-api/sbvr-utils.ts +9 -58
  62. package/src/sbvr-api/translations.ts +5 -18
  63. package/src/sbvr-api/uri-parser.ts +11 -4
  64. package/src/server-glue/module.ts +1 -15
  65. package/src/tasks/index.ts +2 -2
  66. package/src/tasks/worker.ts +6 -2
  67. package/src/webresource-handler/handlers/NoopHandler.ts +3 -1
  68. package/src/webresource-handler/index.ts +1 -86
  69. package/out/data-server/sbvr-server.d.ts +0 -17
  70. package/out/data-server/sbvr-server.js +0 -350
  71. package/out/data-server/sbvr-server.js.map +0 -1
  72. package/out/http-transactions/transaction.sbvr +0 -59
  73. package/out/http-transactions/transactions.d.ts +0 -3
  74. package/out/http-transactions/transactions.js +0 -305
  75. package/out/http-transactions/transactions.js.map +0 -1
  76. package/out/webresource-handler/multipartUpload.d.ts +0 -12
  77. package/out/webresource-handler/multipartUpload.js +0 -251
  78. package/out/webresource-handler/multipartUpload.js.map +0 -1
  79. package/out/webresource-handler/webresource.d.ts +0 -42
  80. package/out/webresource-handler/webresource.js +0 -2
  81. package/out/webresource-handler/webresource.js.map +0 -1
  82. package/out/webresource-handler/webresource.sbvr +0 -60
  83. package/src/data-server/sbvr-server.ts +0 -412
  84. package/src/http-transactions/transaction.sbvr +0 -59
  85. package/src/http-transactions/transactions.js +0 -305
  86. package/src/webresource-handler/multipartUpload.ts +0 -368
  87. package/src/webresource-handler/webresource.sbvr +0 -60
  88. package/src/webresource-handler/webresource.ts +0 -48
@@ -1,60 +0,0 @@
1
- Vocabulary: webresource
2
-
3
- Term: actor
4
- Concept Type: Integer (Type)
5
- Term: expiry date
6
- Concept Type: Date Time (Type)
7
- Term: uuid
8
- Concept Type: Short Text (Type)
9
- Term: resource name
10
- Concept Type: Short Text (Type)
11
- Term: field name
12
- Concept Type: Short Text (Type)
13
- Term: resource id
14
- Concept Type: Integer (Type)
15
- Term: upload id
16
- Concept Type: Short Text (Type)
17
- Term: file key
18
- Concept Type: Short Text (Type)
19
- Term: status
20
- Concept Type: Short Text (Type)
21
- Term: filename
22
- Concept Type: Short Text (Type)
23
- Term: content type
24
- Concept Type: Short Text (Type)
25
- Term: size
26
- Concept Type: Integer (Type)
27
- Term: chunk size
28
- Concept Type: Integer (Type)
29
- Term: valid until date
30
- Concept Type: Date Time (Type)
31
-
32
- Term: multipart upload
33
- Fact type: multipart upload has uuid
34
- Necessity: each multipart upload has exactly one uuid
35
- Necessity: each uuid is of exactly one multipart upload
36
- Fact type: multipart upload has resource name
37
- Necessity: each multipart upload has exactly one resource name
38
- Fact type: multipart upload has field name
39
- Necessity: each multipart upload has exactly one field name
40
- Fact type: multipart upload has resource id
41
- Necessity: each multipart upload has exactly one resource id
42
- Fact type: multipart upload has upload id
43
- Necessity: each multipart upload has exactly one upload id
44
- Fact type: multipart upload has file key
45
- Necessity: each multipart upload has exactly one file key
46
- Fact type: multipart upload has status
47
- Necessity: each multipart upload has exactly one status
48
- Definition: "pending" or "completed" or "cancelled"
49
- Fact type: multipart upload has filename
50
- Necessity: each multipart upload has exactly one filename
51
- Fact type: multipart upload has content type
52
- Necessity: each multipart upload has exactly one content type
53
- Fact type: multipart upload has size
54
- Necessity: each multipart upload has exactly one size
55
- Fact type: multipart upload has chunk size
56
- Necessity: each multipart upload has exactly one chunk size
57
- Fact type: multipart upload has expiry date
58
- Necessity: each multipart upload has exactly one expiry date
59
- Fact type: multipart upload is created by actor
60
- Necessity: each multipart upload is created by at most one actor
@@ -1,412 +0,0 @@
1
- import * as permissions from '../sbvr-api/permissions.js';
2
- import type { Resolvable } from '../sbvr-api/common-types.js';
3
- import type { Handler } from 'express';
4
- import type { Config, SetupFunction } from '../config-loader/config-loader.js';
5
- import type { Tx } from '../database-layer/db.js';
6
-
7
- const uiModel = `\
8
- Vocabulary: ui
9
-
10
- Term: text
11
- Concept type: Text (Type)
12
- Term: name
13
- Concept type: Short Text (Type)
14
- Term: textarea
15
- --Database id Field: name
16
- Reference Scheme: text
17
- Fact type: textarea is disabled
18
- Fact type: textarea has name
19
- Necessity: Each textarea has exactly 1 name
20
- Necessity: Each name is of exactly 1 textarea
21
- Fact type: textarea has text
22
- Necessity: Each textarea has exactly 1 text`;
23
-
24
- // Middleware
25
- const isServerOnAir = (() => {
26
- let resolve: ((thenableOrResult?: Resolvable<boolean>) => void) | undefined;
27
- let promise = new Promise<boolean>(($resolve) => {
28
- resolve = $resolve;
29
- });
30
- return (value?: boolean) => {
31
- if (value != null) {
32
- if (resolve != null) {
33
- resolve(value);
34
- resolve = undefined;
35
- } else {
36
- promise = Promise.resolve(value);
37
- }
38
- }
39
- return promise;
40
- };
41
- })();
42
-
43
- const serverIsOnAir: Handler = async (_req, _res, next) => {
44
- const onAir = await isServerOnAir();
45
- if (onAir) {
46
- next();
47
- } else {
48
- next('route');
49
- }
50
- };
51
-
52
- export const setup: SetupFunction = async (app, sbvrUtils, db) => {
53
- const uiApi = sbvrUtils.api.ui;
54
- const devApi = sbvrUtils.api.dev;
55
- const setupModels = async (tx: Tx) => {
56
- try {
57
- const uiApiTx = uiApi.clone({
58
- passthrough: {
59
- tx,
60
- req: permissions.root,
61
- },
62
- });
63
- await uiApiTx
64
- .get({
65
- resource: 'textarea',
66
- id: {
67
- name: 'model_area',
68
- },
69
- options: {
70
- $select: 'id',
71
- },
72
- })
73
- .then(async (result) => {
74
- if (result == null) {
75
- // Add a model_area entry if it doesn't already exist.
76
- return await uiApiTx.post({
77
- resource: 'textarea',
78
- body: {
79
- name: 'model_area',
80
- text: ' ',
81
- },
82
- });
83
- }
84
- });
85
- await devApi
86
- .get({
87
- resource: 'model',
88
- passthrough: {
89
- tx,
90
- req: permissions.rootRead,
91
- },
92
- options: {
93
- $select: ['is_of__vocabulary', 'model_value'],
94
- $filter: {
95
- model_type: 'se',
96
- is_of__vocabulary: 'data',
97
- },
98
- },
99
- })
100
- .then(async (result) => {
101
- if (result.length === 0) {
102
- throw new Error('No SE data model found');
103
- }
104
- const instance = result[0];
105
- const modelValue = instance.model_value as { [key: string]: string };
106
- await sbvrUtils.executeModel(tx, {
107
- apiRoot: instance.is_of__vocabulary,
108
- modelText: modelValue.value,
109
- });
110
- });
111
- await isServerOnAir(true);
112
- } catch {
113
- await isServerOnAir(false);
114
- }
115
- };
116
-
117
- app.get('/onAir', async (_req, res) => {
118
- const onAir = await isServerOnAir();
119
- res.json(onAir);
120
- });
121
-
122
- app.post(
123
- '/update',
124
- permissions.checkPermissionsMiddleware('all'),
125
- serverIsOnAir,
126
- (_req, res) => {
127
- res.status(404).end();
128
- },
129
- );
130
-
131
- app.post(
132
- '/execute',
133
- permissions.checkPermissionsMiddleware('all'),
134
- async (_req, res) => {
135
- try {
136
- await uiApi
137
- .get({
138
- resource: 'textarea',
139
- passthrough: { req: permissions.rootRead },
140
- id: {
141
- name: 'model_area',
142
- },
143
- options: {
144
- $select: 'text',
145
- },
146
- })
147
- .then(async (result) => {
148
- if (result == null) {
149
- throw new Error('Could not find the model to execute');
150
- }
151
- const modelText = result.text;
152
- await db.transaction(async (tx) => {
153
- await sbvrUtils.executeModel(tx, {
154
- apiRoot: 'data',
155
- modelText,
156
- });
157
- await uiApi.patch({
158
- resource: 'textarea',
159
- passthrough: {
160
- tx,
161
- req: permissions.root,
162
- },
163
- id: {
164
- name: 'model_area',
165
- },
166
- body: {
167
- is_disabled: true,
168
- },
169
- });
170
- });
171
- });
172
- await isServerOnAir(true);
173
- res.status(200).end();
174
- } catch (err) {
175
- await isServerOnAir(false);
176
- res.status(404).json(err);
177
- }
178
- },
179
- );
180
- app.post(
181
- '/validate',
182
- permissions.checkPermissionsMiddleware('read'),
183
- async (req, res) => {
184
- try {
185
- const results = await sbvrUtils.runRule('data', req.body.rule);
186
- res.json(results);
187
- } catch (err) {
188
- console.log('Error validating', err);
189
- res.status(404).end();
190
- }
191
- },
192
- );
193
- app.delete(
194
- '/cleardb',
195
- permissions.checkPermissionsMiddleware('delete'),
196
- async (_req, res) => {
197
- try {
198
- await db.transaction(async (tx) => {
199
- const result = await tx.tableList();
200
-
201
- await Promise.all(
202
- result.rows.map((table) => tx.dropTable(table.name)),
203
- );
204
- await sbvrUtils.executeStandardModels(tx);
205
- // TODO: HACK: This is usually done by config-loader and should be done there
206
- // In general cleardb is very destructive and should really go through a full "reboot" procedure to set everything up again.
207
- console.warn(
208
- 'DEL /cleardb is very destructive and should really be followed by a full restart/reload.',
209
- );
210
- await sbvrUtils.executeModels(tx, config.models);
211
- await setupModels(tx);
212
- });
213
- res.status(200).end();
214
- } catch (err) {
215
- console.error('Error clearing db', err);
216
- res.status(503).end();
217
- }
218
- },
219
- );
220
- app.put(
221
- '/importdb',
222
- permissions.checkPermissionsMiddleware({
223
- and: ['create', 'update', 'delete'],
224
- }),
225
- async (req, res) => {
226
- try {
227
- const queries = req.body.split(';');
228
- await db.transaction(async (tx) => {
229
- for (let query of queries) {
230
- query = query.trim();
231
- if (query.length > 0) {
232
- try {
233
- await tx.executeSql(query);
234
- } catch (err) {
235
- // TODO: Consider changing this to a custom Error
236
- // eslint-disable-next-line no-throw-literal
237
- throw [query, err];
238
- }
239
- }
240
- }
241
- });
242
- res.status(200).end();
243
- } catch (err) {
244
- console.error('Error importing db', err);
245
- res.status(404).end();
246
- }
247
- },
248
- );
249
- app.get(
250
- '/exportdb',
251
- permissions.checkPermissionsMiddleware('read'),
252
- async (_req, res) => {
253
- try {
254
- let exported = '';
255
- await db.transaction(async (tx) => {
256
- const tables = await tx.tableList("name NOT LIKE '%_buk'");
257
- await Promise.all(
258
- tables.rows.map(async (table) => {
259
- const tableName = table.name;
260
- exported += 'DROP TABLE IF EXISTS "' + tableName + '";\n';
261
- exported += table.sql + ';\n';
262
- const result = await tx.executeSql(
263
- 'SELECT * FROM "' + tableName + '";',
264
- );
265
- let insQuery = '';
266
- for (const currRow of result.rows) {
267
- let notFirst = false;
268
- insQuery += 'INSERT INTO "' + tableName + '" (';
269
- let valQuery = '';
270
- for (const propName of Object.keys(currRow)) {
271
- if (notFirst) {
272
- insQuery += ',';
273
- valQuery += ',';
274
- } else {
275
- notFirst = true;
276
- }
277
- insQuery += '"' + propName + '"';
278
- valQuery += "'" + currRow[propName] + "'";
279
- }
280
- insQuery += ') values (' + valQuery + ');\n';
281
- }
282
- exported += insQuery;
283
- }),
284
- );
285
- });
286
- res.json(exported);
287
- } catch (err) {
288
- console.error('Error exporting db', err);
289
- res.status(503).end();
290
- }
291
- },
292
- );
293
- app.post(
294
- '/backupdb',
295
- permissions.checkPermissionsMiddleware('all'),
296
- serverIsOnAir,
297
- async (_req, res) => {
298
- try {
299
- await db.transaction(async (tx) => {
300
- const result = await tx.tableList("name NOT LIKE '%_buk'");
301
- await Promise.all(
302
- result.rows.map(async (currRow) => {
303
- const tableName = currRow.name;
304
- await tx.dropTable(tableName + '_buk', true);
305
-
306
- await tx.executeSql(
307
- 'ALTER TABLE "' +
308
- tableName +
309
- '" RENAME TO "' +
310
- tableName +
311
- '_buk";',
312
- );
313
- }),
314
- );
315
- });
316
- res.status(200).end();
317
- } catch (err) {
318
- console.error('Error backing up db', err);
319
- res.status(404).end();
320
- }
321
- },
322
- );
323
- app.post(
324
- '/restoredb',
325
- permissions.checkPermissionsMiddleware('all'),
326
- serverIsOnAir,
327
- async (_req, res) => {
328
- try {
329
- await db.transaction(async (tx) => {
330
- const result = await tx.tableList("name LIKE '%_buk'");
331
- await Promise.all(
332
- result.rows.map(async (currRow) => {
333
- const tableName = currRow.name;
334
- await tx.dropTable(tableName.slice(0, -4), true);
335
- await tx.executeSql(
336
- 'ALTER TABLE "' +
337
- tableName +
338
- '" RENAME TO "' +
339
- tableName.slice(0, -4) +
340
- '";',
341
- );
342
- }),
343
- );
344
- });
345
- res.status(200).end();
346
- } catch (err) {
347
- console.error('Error restoring db', err);
348
- res.status(404).end();
349
- }
350
- },
351
- );
352
-
353
- app.all('/data/*', serverIsOnAir, sbvrUtils.handleODataRequest);
354
- app.get('/Auth/*', serverIsOnAir, sbvrUtils.handleODataRequest);
355
- app.merge('/ui/*', sbvrUtils.handleODataRequest);
356
- app.patch('/ui/*', sbvrUtils.handleODataRequest);
357
-
358
- app.delete('/', serverIsOnAir, async (_req, res) => {
359
- await Promise.all([
360
- uiApi.patch({
361
- resource: 'textarea',
362
- passthrough: { req: permissions.root },
363
- id: {
364
- name: 'model_area',
365
- },
366
- body: {
367
- text: '',
368
- is_disabled: false,
369
- },
370
- }),
371
- sbvrUtils.deleteModel('data'),
372
- ]);
373
- await isServerOnAir(false);
374
- res.status(200).end();
375
- });
376
-
377
- await db.transaction(setupModels);
378
- };
379
-
380
- export const config = {
381
- models: [
382
- {
383
- modelName: 'ui',
384
- modelText: uiModel,
385
- apiRoot: 'ui',
386
- customServerCode: { setup },
387
- migrations: {
388
- '11.0.0-modified-at': `\
389
- ALTER TABLE "textarea"
390
- ADD COLUMN IF NOT EXISTS "modified at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\
391
- `,
392
- '15.0.0-data-types': async (tx, sbvrUtils) => {
393
- switch (sbvrUtils.db.engine) {
394
- case 'mysql':
395
- await tx.executeSql(`\
396
- ALTER TABLE "textarea"
397
- MODIFY "is disabled" BOOLEAN NOT NULL;`);
398
- break;
399
- case 'postgres':
400
- await tx.executeSql(`\
401
- ALTER TABLE "textarea"
402
- ALTER COLUMN "is disabled" DROP DEFAULT,
403
- ALTER COLUMN "is disabled" SET DATA TYPE BOOLEAN USING "is disabled"::BOOLEAN,
404
- ALTER COLUMN "is disabled" SET DEFAULT FALSE;`);
405
- break;
406
- // No need to migrate for websql
407
- }
408
- },
409
- },
410
- },
411
- ],
412
- } satisfies Config;
@@ -1,59 +0,0 @@
1
- Vocabulary: transaction
2
-
3
- Term: resource id
4
- Concept type: Text (Type)
5
- Term: resource type
6
- Concept type: Text (Type)
7
- Term: field name
8
- Concept type: Text (Type)
9
- Term: field value
10
- Concept type: Text (Type)
11
- Term: placeholder
12
- Concept type: Short Text (Type)
13
-
14
- Term: resource
15
- Reference Scheme: resource id
16
- Fact type: resource has resource id
17
- Necessity: Each resource has exactly 1 resource id.
18
- Fact type: resource has resource type
19
- Necessity: Each resource has exactly 1 resource type.
20
-
21
- Term: transaction
22
-
23
- Term: lock
24
- Fact type: lock is exclusive
25
- Fact type: lock belongs to transaction
26
- Necessity: Each lock belongs to exactly 1 transaction.
27
- Fact type: resource is under lock
28
- Synonymous Form: lock is on resource
29
- Rule: It is obligatory that each resource that is under a lock that is exclusive, is under at most 1 lock.
30
-
31
- Term: conditional type
32
- Concept Type: Short Text (Type)
33
- Definition: "ADD", "EDIT" or "DELETE"
34
-
35
- Term: conditional resource
36
- Fact type: conditional resource belongs to transaction
37
- Necessity: Each conditional resource belongs to exactly 1 transaction.
38
- Fact type: conditional resource has lock
39
- Necessity: Each conditional resource has at most 1 lock.
40
- Fact type: conditional resource has resource type
41
- Necessity: Each conditional resource has exactly 1 resource type.
42
- Fact type: conditional resource has conditional type
43
- Necessity: Each conditional resource has exactly 1 conditional type.
44
- Fact type: conditional resource has placeholder
45
- Necessity: Each conditional resource has at most 1 placeholder.
46
- --Rule: It is obligatory that each conditional resource that has a placeholder, has a conditional type that is of "ADD".
47
-
48
- Term: conditional field
49
- Reference Scheme: field name
50
- Fact type: conditional field has field name
51
- Necessity: Each conditional field has exactly 1 field name.
52
- Fact type: conditional field has field value
53
- Necessity: Each conditional field has at most 1 field value.
54
- Fact type: conditional field is of conditional resource
55
- Necessity: Each conditional field is of exactly 1 conditional resource.
56
-
57
- --Rule: It is obligatory that each conditional resource that has a conditional type that is of "EDIT" or "DELETE", has a lock that is exclusive
58
- Rule: It is obligatory that each conditional resource that has a lock, has a resource type that is of a resource that the lock is on.
59
- Rule: It is obligatory that each conditional resource that has a lock, belongs to a transaction that the lock belongs to.