@balena/pinejs 19.7.2 → 20.0.0-build-esm-724decc895c0df04c6238f249763a742cc5efa39-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/.pinejs-cache.json +1 -1
- package/.versionbot/CHANGELOG.yml +45 -1
- package/CHANGELOG.md +8 -0
- package/{Gruntfile.ts → Gruntfile.cts} +9 -22
- package/VERSION +1 -1
- package/bin/abstract-sql-compiler.js +1 -1
- package/bin/odata-compiler.js +1 -1
- package/bin/sbvr-compiler.js +1 -1
- package/build/{browser.ts → browser.cts} +1 -1
- package/build/{config.ts → config.cts} +5 -1
- package/build/{module.ts → module.cts} +1 -1
- package/build/{server.ts → server.cts} +1 -1
- package/out/bin/abstract-sql-compiler.js +17 -19
- package/out/bin/abstract-sql-compiler.js.map +1 -1
- package/out/bin/odata-compiler.js +19 -21
- package/out/bin/odata-compiler.js.map +1 -1
- package/out/bin/sbvr-compiler.js +19 -54
- package/out/bin/sbvr-compiler.js.map +1 -1
- package/out/bin/utils.d.ts +3 -3
- package/out/bin/utils.js +21 -53
- package/out/bin/utils.js.map +1 -1
- package/out/config-loader/config-loader.d.ts +7 -7
- package/out/config-loader/config-loader.js +23 -63
- package/out/config-loader/config-loader.js.map +1 -1
- package/out/config-loader/env.d.ts +1 -1
- package/out/config-loader/env.js +24 -66
- package/out/config-loader/env.js.map +1 -1
- package/out/data-server/sbvr-server.d.ts +3 -3
- package/out/data-server/sbvr-server.js +5 -42
- package/out/data-server/sbvr-server.js.map +1 -1
- package/out/database-layer/db.d.ts +3 -3
- package/out/database-layer/db.js +37 -83
- package/out/database-layer/db.js.map +1 -1
- package/out/express-emulator/express.js.map +1 -1
- package/out/extended-sbvr-parser/extended-sbvr-parser.js +8 -11
- package/out/extended-sbvr-parser/extended-sbvr-parser.js.map +1 -1
- package/out/http-transactions/transactions.d.ts +2 -2
- package/out/http-transactions/transactions.js +4 -4
- package/out/http-transactions/transactions.js.map +1 -1
- package/out/migrator/async.d.ts +2 -2
- package/out/migrator/async.js +20 -60
- package/out/migrator/async.js.map +1 -1
- package/out/migrator/migrations.js +1 -2
- package/out/migrator/sync.d.ts +6 -6
- package/out/migrator/sync.js +20 -61
- package/out/migrator/sync.js.map +1 -1
- package/out/migrator/utils.d.ts +4 -4
- package/out/migrator/utils.js +42 -97
- package/out/migrator/utils.js.map +1 -1
- package/out/odata-metadata/odata-metadata-generator.js +7 -14
- package/out/odata-metadata/odata-metadata-generator.js.map +1 -1
- package/out/passport-pinejs/mount-login-router.d.ts +1 -1
- package/out/passport-pinejs/mount-login-router.js +4 -41
- package/out/passport-pinejs/mount-login-router.js.map +1 -1
- package/out/passport-pinejs/passport-pinejs.d.ts +3 -3
- package/out/passport-pinejs/passport-pinejs.js +11 -46
- package/out/passport-pinejs/passport-pinejs.js.map +1 -1
- package/out/pinejs-session-store/pinejs-session-store.d.ts +1 -1
- package/out/pinejs-session-store/pinejs-session-store.js +11 -48
- package/out/pinejs-session-store/pinejs-session-store.js.map +1 -1
- package/out/sbvr-api/abstract-sql.d.ts +3 -3
- package/out/sbvr-api/abstract-sql.js +22 -65
- package/out/sbvr-api/abstract-sql.js.map +1 -1
- package/out/sbvr-api/cached-compile.js +8 -15
- package/out/sbvr-api/cached-compile.js.map +1 -1
- package/out/sbvr-api/common-types.js +1 -2
- package/out/sbvr-api/control-flow.d.ts +1 -1
- package/out/sbvr-api/control-flow.js +12 -25
- package/out/sbvr-api/control-flow.js.map +1 -1
- package/out/sbvr-api/dev.js +1 -2
- package/out/sbvr-api/errors.d.ts +1 -1
- package/out/sbvr-api/errors.js +47 -95
- package/out/sbvr-api/errors.js.map +1 -1
- package/out/sbvr-api/express-extension.d.ts +2 -2
- package/out/sbvr-api/express-extension.js +1 -2
- package/out/sbvr-api/hooks.d.ts +4 -4
- package/out/sbvr-api/hooks.js +23 -35
- package/out/sbvr-api/hooks.js.map +1 -1
- package/out/sbvr-api/odata-response.d.ts +2 -2
- package/out/sbvr-api/odata-response.js +19 -29
- package/out/sbvr-api/odata-response.js.map +1 -1
- package/out/sbvr-api/permissions.d.ts +9 -9
- package/out/sbvr-api/permissions.js +106 -159
- package/out/sbvr-api/permissions.js.map +1 -1
- package/out/sbvr-api/sbvr-utils.d.ts +40 -18
- package/out/sbvr-api/sbvr-utils.js +222 -285
- package/out/sbvr-api/sbvr-utils.js.map +1 -1
- package/out/sbvr-api/translations.d.ts +1 -1
- package/out/sbvr-api/translations.js +10 -17
- package/out/sbvr-api/translations.js.map +1 -1
- package/out/sbvr-api/uri-parser.d.ts +7 -7
- package/out/sbvr-api/uri-parser.js +39 -84
- package/out/sbvr-api/uri-parser.js.map +1 -1
- package/out/sbvr-api/user.js +1 -2
- package/out/server-glue/global-ext.d.ts +0 -3
- package/out/server-glue/module.d.ts +16 -16
- package/out/server-glue/module.js +20 -59
- package/out/server-glue/module.js.map +1 -1
- package/out/server-glue/sbvr-loader.d.ts +2 -1
- package/out/server-glue/sbvr-loader.js +4 -11
- package/out/server-glue/sbvr-loader.js.map +1 -1
- package/out/server-glue/server.d.ts +2 -2
- package/out/server-glue/server.js +17 -59
- package/out/server-glue/server.js.map +1 -1
- package/out/tasks/common.d.ts +1 -1
- package/out/tasks/common.js +3 -9
- package/out/tasks/common.js.map +1 -1
- package/out/tasks/index.d.ts +8 -8
- package/out/tasks/index.js +25 -63
- package/out/tasks/index.js.map +1 -1
- package/out/tasks/tasks.js +1 -2
- package/out/tasks/worker.d.ts +3 -3
- package/out/tasks/worker.js +14 -51
- package/out/tasks/worker.js.map +1 -1
- package/out/webresource-handler/handlers/NoopHandler.d.ts +1 -1
- package/out/webresource-handler/handlers/NoopHandler.js +1 -5
- package/out/webresource-handler/handlers/NoopHandler.js.map +1 -1
- package/out/webresource-handler/handlers/index.d.ts +1 -2
- package/out/webresource-handler/handlers/index.js +1 -18
- package/out/webresource-handler/handlers/index.js.map +1 -1
- package/out/webresource-handler/index.d.ts +3 -3
- package/out/webresource-handler/index.js +37 -87
- package/out/webresource-handler/index.js.map +1 -1
- package/package.json +15 -14
- package/src/bin/abstract-sql-compiler.ts +3 -3
- package/src/bin/odata-compiler.ts +3 -3
- package/src/bin/sbvr-compiler.ts +2 -2
- package/src/bin/utils.ts +23 -15
- package/src/config-loader/config-loader.ts +12 -12
- package/src/config-loader/env.ts +3 -3
- package/src/data-server/sbvr-server.ts +4 -4
- package/src/database-layer/db.ts +18 -11
- package/src/extended-sbvr-parser/extended-sbvr-parser.ts +5 -5
- package/src/http-transactions/transactions.js +4 -4
- package/src/migrator/async.ts +5 -5
- package/src/migrator/sync.ts +8 -8
- package/src/migrator/utils.ts +7 -7
- package/src/odata-metadata/odata-metadata-generator.ts +3 -2
- package/src/passport-pinejs/mount-login-router.ts +3 -3
- package/src/passport-pinejs/passport-pinejs.ts +6 -6
- package/src/pinejs-session-store/pinejs-session-store.ts +4 -4
- package/src/sbvr-api/abstract-sql.ts +6 -6
- package/src/sbvr-api/cached-compile.ts +2 -2
- package/src/sbvr-api/control-flow.ts +1 -1
- package/src/sbvr-api/errors.ts +1 -1
- package/src/sbvr-api/express-extension.ts +2 -2
- package/src/sbvr-api/hooks.ts +5 -5
- package/src/sbvr-api/odata-response.ts +8 -4
- package/src/sbvr-api/permissions.ts +19 -19
- package/src/sbvr-api/sbvr-utils.ts +39 -33
- package/src/sbvr-api/translations.ts +1 -1
- package/src/sbvr-api/uri-parser.ts +10 -10
- package/src/server-glue/global-ext.d.ts +0 -3
- package/src/server-glue/module.ts +20 -20
- package/src/server-glue/sbvr-loader.ts +15 -27
- package/src/server-glue/server.ts +13 -24
- package/src/tasks/common.ts +1 -1
- package/src/tasks/index.ts +14 -14
- package/src/tasks/worker.ts +8 -8
- package/src/webresource-handler/handlers/NoopHandler.ts +5 -1
- package/src/webresource-handler/handlers/index.ts +1 -2
- package/src/webresource-handler/index.ts +13 -13
- package/tsconfig.dev.json +4 -2
- package/tsconfig.json +1 -1
- package/typings/lf-to-abstract-sql.d.ts +2 -2
- package/typings/memoizee.d.ts +2 -2
- package/out/webresource-handler/handlers/S3Handler.d.ts +0 -28
- package/out/webresource-handler/handlers/S3Handler.js +0 -104
- package/out/webresource-handler/handlers/S3Handler.js.map +0 -1
- package/src/webresource-handler/handlers/S3Handler.ts +0 -143
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getAbstractSqlModelFromFile, version, writeAll } from './utils';
|
1
|
+
import { getAbstractSqlModelFromFile, version, writeAll } from './utils.js';
|
2
2
|
import type {
|
3
3
|
AbstractSqlModel,
|
4
4
|
SqlResult,
|
@@ -44,7 +44,7 @@ const translateOData = async (
|
|
44
44
|
outputFile?: string,
|
45
45
|
) => {
|
46
46
|
const request = await generateAbstractSqlQuery(
|
47
|
-
getAbstractSqlModelFromFile(modelFile, program.opts().model),
|
47
|
+
await getAbstractSqlModelFromFile(modelFile, program.opts().model),
|
48
48
|
odata,
|
49
49
|
);
|
50
50
|
const json = JSON.stringify(request.abstractSqlQuery, null, 2);
|
@@ -68,7 +68,7 @@ const compileOData = async (
|
|
68
68
|
outputFile?: string,
|
69
69
|
) => {
|
70
70
|
const translatedRequest = await generateAbstractSqlQuery(
|
71
|
-
getAbstractSqlModelFromFile(modelFile, program.opts().model),
|
71
|
+
await getAbstractSqlModelFromFile(modelFile, program.opts().model),
|
72
72
|
odata,
|
73
73
|
);
|
74
74
|
const { compileRequest } = await import('../sbvr-api/abstract-sql.js');
|
package/src/bin/sbvr-compiler.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { version, writeAll, writeSqlModel } from './utils';
|
1
|
+
import { version, writeAll, writeSqlModel } from './utils.js';
|
2
2
|
import { program } from 'commander';
|
3
|
-
import
|
3
|
+
import fs from 'fs';
|
4
4
|
|
5
5
|
const getSE = (inputFile: string) => fs.readFileSync(inputFile, 'utf8');
|
6
6
|
|
package/src/bin/utils.ts
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
process.env.PINEJS_CACHE_FILE =
|
2
|
-
process.env.PINEJS_CACHE_FILE ||
|
2
|
+
process.env.PINEJS_CACHE_FILE ||
|
3
|
+
fileURLToPath(new URL('.pinejs-cache.json', import.meta.url));
|
3
4
|
|
4
5
|
import type { SqlModel } from '@balena/abstract-sql-compiler';
|
5
|
-
import type { Config, Model } from '../config-loader/config-loader';
|
6
|
-
import type * as SbvrUtils from '../sbvr-api/sbvr-utils';
|
6
|
+
import type { Config, Model } from '../config-loader/config-loader.js';
|
7
7
|
import type { AbstractSqlModel } from '@balena/abstract-sql-compiler';
|
8
8
|
|
9
|
-
import
|
10
|
-
import
|
11
|
-
import '../server-glue/sbvr-loader';
|
9
|
+
import fs from 'fs';
|
10
|
+
import path from 'path';
|
11
|
+
import '../server-glue/sbvr-loader.js';
|
12
|
+
import { fileURLToPath } from 'url';
|
13
|
+
import { loadSBVR } from '../server-glue/sbvr-loader.js';
|
12
14
|
|
13
|
-
export { version } from '../config-loader/env';
|
15
|
+
export { version } from '../config-loader/env.js';
|
14
16
|
|
15
17
|
export const writeAll = (output: string, outputFile?: string): void => {
|
16
18
|
if (outputFile) {
|
@@ -68,15 +70,21 @@ const getConfigModel = (
|
|
68
70
|
return fileContents;
|
69
71
|
};
|
70
72
|
|
71
|
-
export const getAbstractSqlModelFromFile = (
|
73
|
+
export const getAbstractSqlModelFromFile = async (
|
72
74
|
modelFile: string,
|
73
75
|
modelName: string | undefined,
|
74
|
-
): AbstractSqlModel => {
|
76
|
+
): Promise<AbstractSqlModel> => {
|
75
77
|
let fileContents: string | Model | AbstractSqlModel | Config;
|
76
78
|
try {
|
77
|
-
fileContents =
|
79
|
+
fileContents = await import(path.resolve(modelFile));
|
78
80
|
} catch {
|
79
|
-
fileContents = fs.
|
81
|
+
fileContents = await fs.promises.readFile(path.resolve(modelFile), 'utf8');
|
82
|
+
try {
|
83
|
+
// Try to parse the file as JSON
|
84
|
+
fileContents = JSON.parse(fileContents);
|
85
|
+
} catch {
|
86
|
+
// Ignore error as it's likely just a text sbvr file
|
87
|
+
}
|
80
88
|
}
|
81
89
|
let seModel: string;
|
82
90
|
if (fileContents == null) {
|
@@ -94,16 +102,16 @@ export const getAbstractSqlModelFromFile = (
|
|
94
102
|
} else if ('modelText' in configModel && configModel.modelText != null) {
|
95
103
|
seModel = configModel.modelText;
|
96
104
|
} else if ('modelFile' in configModel && configModel.modelFile != null) {
|
97
|
-
seModel =
|
105
|
+
seModel = await loadSBVR(configModel.modelFile, import.meta);
|
98
106
|
} else {
|
99
107
|
throw new Error('Unrecognized config file');
|
100
108
|
}
|
101
109
|
} else {
|
102
110
|
throw new Error('Unrecognized config file');
|
103
111
|
}
|
104
|
-
const { generateLfModel, generateAbstractSqlModel } =
|
105
|
-
|
106
|
-
|
112
|
+
const { generateLfModel, generateAbstractSqlModel } = await import(
|
113
|
+
'../sbvr-api/sbvr-utils.js'
|
114
|
+
);
|
107
115
|
let lfModel;
|
108
116
|
try {
|
109
117
|
lfModel = generateLfModel(seModel);
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import type
|
1
|
+
import type Express from 'express';
|
2
2
|
import type {
|
3
3
|
AbstractSqlModel,
|
4
4
|
Definition,
|
5
5
|
} from '@balena/abstract-sql-compiler';
|
6
|
-
import type { Database } from '../database-layer/db';
|
6
|
+
import type { Database } from '../database-layer/db.js';
|
7
7
|
import type {
|
8
8
|
AnyObject,
|
9
9
|
Dictionary,
|
10
10
|
RequiredField,
|
11
11
|
Resolvable,
|
12
|
-
} from '../sbvr-api/common-types';
|
12
|
+
} from '../sbvr-api/common-types.js';
|
13
13
|
|
14
14
|
import {
|
15
15
|
type Migration,
|
@@ -18,23 +18,23 @@ import {
|
|
18
18
|
MigrationCategories,
|
19
19
|
isSyncMigration,
|
20
20
|
isAsyncMigration,
|
21
|
-
} from '../migrator/utils';
|
21
|
+
} from '../migrator/utils.js';
|
22
22
|
|
23
|
-
import
|
23
|
+
import fs from 'fs';
|
24
24
|
import _ from 'lodash';
|
25
|
-
import
|
25
|
+
import path from 'path';
|
26
26
|
|
27
|
-
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
|
27
|
+
import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
|
28
28
|
|
29
|
-
import * as permissions from '../sbvr-api/permissions';
|
29
|
+
import * as permissions from '../sbvr-api/permissions.js';
|
30
30
|
import {
|
31
31
|
getDefaultHandler,
|
32
32
|
getUploaderMiddlware,
|
33
33
|
type WebResourceHandler,
|
34
34
|
setupUploadHooks,
|
35
35
|
setupWebresourceHandler,
|
36
|
-
} from '../webresource-handler';
|
37
|
-
import type { AliasValidNodeType } from '../sbvr-api/translations';
|
36
|
+
} from '../webresource-handler/index.js';
|
37
|
+
import type { AliasValidNodeType } from '../sbvr-api/translations.js';
|
38
38
|
|
39
39
|
export type SetupFunction = (
|
40
40
|
app: Express.Application,
|
@@ -256,7 +256,7 @@ export const setup = (app: Express.Application) => {
|
|
256
256
|
let customCode: SetupFunction;
|
257
257
|
if (typeof model.customServerCode === 'string') {
|
258
258
|
try {
|
259
|
-
customCode =
|
259
|
+
customCode = (await import(model.customServerCode)).setup;
|
260
260
|
} catch (e: any) {
|
261
261
|
e.message = `Error loading custom server code: '${e.message}'`;
|
262
262
|
throw e;
|
@@ -291,7 +291,7 @@ export const setup = (app: Express.Application) => {
|
|
291
291
|
let root: string;
|
292
292
|
let configObj: Config;
|
293
293
|
if (config == null) {
|
294
|
-
root = path.resolve(process.argv[2]) ||
|
294
|
+
root = path.resolve(process.argv[2]) || import.meta.dirname;
|
295
295
|
configObj = await loadConfigFile(path.join(root, 'config.json'));
|
296
296
|
} else if (typeof config === 'string') {
|
297
297
|
root = path.dirname(config);
|
package/src/config-loader/env.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import { promises as fs } from 'fs';
|
2
2
|
export const { version } = JSON.parse(
|
3
|
-
fs.
|
3
|
+
await fs.readFile(new URL(import.meta.resolve('../../package.json')), 'utf8'),
|
4
4
|
);
|
5
5
|
|
6
6
|
const { PINEJS_DEBUG } = process.env;
|
@@ -56,7 +56,7 @@ export const cache = {
|
|
56
56
|
|
57
57
|
import { boolVar, intVar } from '@balena/env-parsing';
|
58
58
|
import memoize from 'memoizee';
|
59
|
-
import memoizeWeak from 'memoizee/weak';
|
59
|
+
import memoizeWeak from 'memoizee/weak.js';
|
60
60
|
export const createCache = <T extends (...args: any[]) => any>(
|
61
61
|
cacheName: keyof typeof cache,
|
62
62
|
fn: T,
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import * as permissions from '../sbvr-api/permissions';
|
2
|
-
import type { Resolvable } from '../sbvr-api/common-types';
|
1
|
+
import * as permissions from '../sbvr-api/permissions.js';
|
2
|
+
import type { Resolvable } from '../sbvr-api/common-types.js';
|
3
3
|
import type { Handler } from 'express';
|
4
|
-
import type { Config, SetupFunction } from '../config-loader/config-loader';
|
5
|
-
import type { Tx } from '../database-layer/db';
|
4
|
+
import type { Config, SetupFunction } from '../config-loader/config-loader.js';
|
5
|
+
import type { Tx } from '../database-layer/db.js';
|
6
6
|
|
7
7
|
const uiModel = `\
|
8
8
|
Vocabulary: ui
|
package/src/database-layer/db.ts
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
/// <references types="websql"/>
|
2
|
-
import type
|
3
|
-
import type
|
4
|
-
import type
|
5
|
-
import type { Dictionary, Resolvable } from '../sbvr-api/common-types';
|
2
|
+
import type Mysql from 'mysql';
|
3
|
+
import type Pg from 'pg';
|
4
|
+
import type PgConnectionString from 'pg-connection-string';
|
5
|
+
import type { Dictionary, Resolvable } from '../sbvr-api/common-types.js';
|
6
6
|
|
7
7
|
import { Engines } from '@balena/abstract-sql-compiler';
|
8
8
|
import { EventEmitter } from 'eventemitter3';
|
9
9
|
import _ from 'lodash';
|
10
10
|
import { TypedError } from 'typed-error';
|
11
|
-
import * as env from '../config-loader/env';
|
12
|
-
import { fromCallback, timeout } from '../sbvr-api/control-flow';
|
11
|
+
import * as env from '../config-loader/env.js';
|
12
|
+
import { fromCallback, timeout } from '../sbvr-api/control-flow.js';
|
13
13
|
|
14
14
|
export const metrics = new EventEmitter();
|
15
15
|
|
@@ -487,8 +487,10 @@ const createTransaction = (createFunc: CreateTransactionFn): TransactionFn => {
|
|
487
487
|
};
|
488
488
|
|
489
489
|
let maybePg: typeof Pg | undefined;
|
490
|
+
let maybePgConnectionString: typeof PgConnectionString | undefined;
|
490
491
|
try {
|
491
|
-
maybePg =
|
492
|
+
maybePg = (await import('pg')).default;
|
493
|
+
maybePgConnectionString = (await import('pg-connection-string')).default;
|
492
494
|
} catch {
|
493
495
|
// Ignore errors
|
494
496
|
}
|
@@ -543,10 +545,15 @@ if (maybePg != null) {
|
|
543
545
|
let pool: Pg.Pool;
|
544
546
|
let replica: Pg.Pool;
|
545
547
|
if (typeof connectString === 'string') {
|
546
|
-
|
547
|
-
|
548
|
+
if (maybePgConnectionString == null) {
|
549
|
+
throw new Error(
|
550
|
+
'pg-connection-string is required for string connection strings',
|
551
|
+
);
|
552
|
+
}
|
548
553
|
// We have to cast because of the use of null vs undefined
|
549
|
-
const config =
|
554
|
+
const config = maybePgConnectionString.parse(
|
555
|
+
connectString,
|
556
|
+
) as Pg.PoolConfig;
|
550
557
|
pool = initPool(config);
|
551
558
|
} else {
|
552
559
|
const config = connectString;
|
@@ -728,7 +735,7 @@ if (maybePg != null) {
|
|
728
735
|
|
729
736
|
let maybeMysql: typeof Mysql | undefined;
|
730
737
|
try {
|
731
|
-
maybeMysql =
|
738
|
+
maybeMysql = (await import('mysql')).default;
|
732
739
|
} catch {
|
733
740
|
// Ignore errors
|
734
741
|
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { SBVRParser } from '@balena/sbvr-parser';
|
2
|
-
import {
|
3
|
-
import
|
4
|
-
import { version } from '../config-loader/env';
|
2
|
+
import { importSBVR } from '../server-glue/sbvr-loader.js';
|
3
|
+
import SbvrParserPackage from '@balena/sbvr-parser/package.json' with { type: 'json' };
|
4
|
+
import { version } from '../config-loader/env.js';
|
5
5
|
|
6
|
-
const Types =
|
6
|
+
const Types = await importSBVR('@balena/sbvr-types/Type.sbvr', import.meta);
|
7
7
|
|
8
8
|
export const ExtendedSBVRParser = SBVRParser._extend({
|
9
9
|
initialize() {
|
@@ -13,5 +13,5 @@ export const ExtendedSBVRParser = SBVRParser._extend({
|
|
13
13
|
this.AddBuiltInVocab(Types);
|
14
14
|
return this;
|
15
15
|
},
|
16
|
-
version:
|
16
|
+
version: SbvrParserPackage.version + '+' + version,
|
17
17
|
});
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { odataNameToSqlName } from '@balena/odata-to-abstract-sql';
|
2
|
-
import {
|
3
|
-
const transactionModel =
|
2
|
+
import { importSBVR } from '../server-glue/sbvr-loader.js';
|
3
|
+
const transactionModel = await importSBVR('./transaction.sbvr', import.meta);
|
4
4
|
|
5
|
-
/** @type {import('../config-loader/config-loader').Config} */
|
5
|
+
/** @type {import('../config-loader/config-loader.js').Config} */
|
6
6
|
export const config = {
|
7
7
|
models: [
|
8
8
|
{
|
@@ -53,7 +53,7 @@ ADD COLUMN IF NOT EXISTS "modified at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT N
|
|
53
53
|
/** @type {(modelName: string) => void} */
|
54
54
|
export let addModelHooks;
|
55
55
|
|
56
|
-
/** @type { import('../config-loader/config-loader').SetupFunction } */
|
56
|
+
/** @type { import('../config-loader/config-loader.js').SetupFunction } */
|
57
57
|
export function setup(app, sbvrUtils) {
|
58
58
|
addModelHooks = (modelName) => {
|
59
59
|
// TODO: Add checks on POST/PATCH requests as well.
|
package/src/migrator/async.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import type { Tx } from '../database-layer/db';
|
2
|
-
import type { Model } from '../config-loader/config-loader';
|
1
|
+
import type { Tx } from '../database-layer/db.js';
|
2
|
+
import type { Model } from '../config-loader/config-loader.js';
|
3
3
|
|
4
4
|
import _ from 'lodash';
|
5
|
-
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
|
5
|
+
import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
|
6
6
|
|
7
7
|
type ApiRootModel = Model & { apiRoot: string };
|
8
8
|
|
@@ -24,8 +24,8 @@ import {
|
|
24
24
|
filterAndSortPendingMigrations,
|
25
25
|
type MigrationStatus,
|
26
26
|
type BaseAsyncMigration,
|
27
|
-
} from './utils';
|
28
|
-
import { booleanToEnabledString } from '../config-loader/env';
|
27
|
+
} from './utils.js';
|
28
|
+
import { booleanToEnabledString } from '../config-loader/env.js';
|
29
29
|
|
30
30
|
export const run = async (tx: Tx, model: ApiRootModel): Promise<void> => {
|
31
31
|
const { migrations } = model;
|
package/src/migrator/sync.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type MigrationsModel from './migrations';
|
1
|
+
import type MigrationsModel from './migrations.js';
|
2
2
|
import {
|
3
3
|
type MigrationTuple,
|
4
4
|
MigrationError,
|
@@ -9,15 +9,15 @@ import {
|
|
9
9
|
type RunnableMigrations,
|
10
10
|
filterAndSortPendingMigrations,
|
11
11
|
getRunnableSyncMigrations,
|
12
|
-
} from './utils';
|
13
|
-
import type { Tx } from '../database-layer/db';
|
14
|
-
import type { Config, Model } from '../config-loader/config-loader';
|
12
|
+
} from './utils.js';
|
13
|
+
import type { Tx } from '../database-layer/db.js';
|
14
|
+
import type { Config, Model } from '../config-loader/config-loader.js';
|
15
15
|
|
16
16
|
import _ from 'lodash';
|
17
|
-
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
|
18
|
-
import {
|
17
|
+
import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
|
18
|
+
import { importSBVR } from '../server-glue/sbvr-loader.js';
|
19
19
|
|
20
|
-
const migrationsModel =
|
20
|
+
const migrationsModel = await importSBVR('./migrations.sbvr', import.meta);
|
21
21
|
|
22
22
|
type ApiRootModel = Model & { apiRoot: string };
|
23
23
|
|
@@ -137,7 +137,7 @@ const executeMigration = async (
|
|
137
137
|
}
|
138
138
|
};
|
139
139
|
|
140
|
-
declare module '../sbvr-api/sbvr-utils' {
|
140
|
+
declare module '../sbvr-api/sbvr-utils.js' {
|
141
141
|
export interface API {
|
142
142
|
[migrationModelConfig.apiRoot]: PinejsClient<MigrationsModel>;
|
143
143
|
}
|
package/src/migrator/utils.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
import type { Result, Tx } from '../database-layer/db';
|
2
|
-
import type { Resolvable } from '../sbvr-api/common-types';
|
1
|
+
import type { Result, Tx } from '../database-layer/db.js';
|
2
|
+
import type { Resolvable } from '../sbvr-api/common-types.js';
|
3
3
|
|
4
4
|
import { createHash } from 'crypto';
|
5
5
|
import { Engines } from '@balena/abstract-sql-compiler';
|
6
6
|
import _ from 'lodash';
|
7
7
|
import { TypedError } from 'typed-error';
|
8
|
-
import { migrator as migratorEnv } from '../config-loader/env';
|
9
|
-
export { migrator as migratorEnv } from '../config-loader/env';
|
10
|
-
import { PINEJS_ADVISORY_LOCK } from '../config-loader/env';
|
11
|
-
import { delay } from '../sbvr-api/control-flow';
|
8
|
+
import { migrator as migratorEnv } from '../config-loader/env.js';
|
9
|
+
export { migrator as migratorEnv } from '../config-loader/env.js';
|
10
|
+
import { PINEJS_ADVISORY_LOCK } from '../config-loader/env.js';
|
11
|
+
import { delay } from '../sbvr-api/control-flow.js';
|
12
12
|
|
13
|
-
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
|
13
|
+
import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
|
14
14
|
export enum MigrationCategories {
|
15
15
|
'sync' = 'sync',
|
16
16
|
'async' = 'async',
|
@@ -3,8 +3,9 @@ import type {
|
|
3
3
|
AbstractSqlTable,
|
4
4
|
} from '@balena/abstract-sql-compiler';
|
5
5
|
|
6
|
-
import
|
7
|
-
import {
|
6
|
+
import type { SbvrType } from '@balena/sbvr-types';
|
7
|
+
import { sbvrTypes } from '../sbvr-api/sbvr-utils.js';
|
8
|
+
import { version } from '../config-loader/env.js';
|
8
9
|
|
9
10
|
const getResourceName = (resourceName: string): string =>
|
10
11
|
resourceName
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import * as passportPinejs from './passport-pinejs';
|
1
|
+
import * as passportPinejs from './passport-pinejs.js';
|
2
2
|
import type { Express } from 'express';
|
3
|
-
import { PinejsSessionStore } from '../pinejs-session-store/pinejs-session-store';
|
4
|
-
import type { setup } from '../config-loader/config-loader';
|
3
|
+
import { PinejsSessionStore } from '../pinejs-session-store/pinejs-session-store.js';
|
4
|
+
import type { setup } from '../config-loader/config-loader.js';
|
5
5
|
|
6
6
|
export const mountLoginRouter = async (
|
7
7
|
configLoader: ReturnType<typeof setup>,
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import type
|
2
|
-
import type
|
3
|
-
import type
|
4
|
-
import type * as ConfigLoader from '../config-loader/config-loader';
|
5
|
-
import type { User } from '../sbvr-api/sbvr-utils';
|
1
|
+
import type Express from 'express';
|
2
|
+
import type Passport from 'passport';
|
3
|
+
import type PassportLocal from 'passport-local';
|
4
|
+
import type * as ConfigLoader from '../config-loader/config-loader.js';
|
5
|
+
import type { User } from '../sbvr-api/sbvr-utils.js';
|
6
6
|
|
7
|
-
import * as permissions from '../sbvr-api/permissions';
|
7
|
+
import * as permissions from '../sbvr-api/permissions.js';
|
8
8
|
|
9
9
|
// Returns a middleware that will handle logging in using `username` and `password` body properties
|
10
10
|
export let login: (
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Config } from '../config-loader/config-loader';
|
2
|
-
import type { AnyObject } from '../sbvr-api/common-types';
|
1
|
+
import type { Config } from '../config-loader/config-loader.js';
|
2
|
+
import type { AnyObject } from '../sbvr-api/common-types.js';
|
3
3
|
|
4
4
|
import { Store } from 'express-session';
|
5
|
-
import * as permissions from '../sbvr-api/permissions';
|
6
|
-
import { api } from '../sbvr-api/sbvr-utils';
|
5
|
+
import * as permissions from '../sbvr-api/permissions.js';
|
6
|
+
import { api } from '../sbvr-api/sbvr-utils.js';
|
7
7
|
|
8
8
|
export { Store };
|
9
9
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
import _ from 'lodash';
|
2
2
|
|
3
|
-
import
|
3
|
+
import AbstractSQLCompiler from '@balena/abstract-sql-compiler';
|
4
4
|
import type { BindKey } from '@balena/odata-parser';
|
5
5
|
import {
|
6
6
|
type ODataBinds,
|
7
7
|
odataNameToSqlName,
|
8
8
|
isBindReference,
|
9
9
|
} from '@balena/odata-to-abstract-sql';
|
10
|
-
import deepFreeze
|
10
|
+
import deepFreeze from 'deep-freeze';
|
11
11
|
import memoize from 'memoizee';
|
12
|
-
import * as env from '../config-loader/env';
|
13
|
-
import { BadRequestError, SqlCompilationError } from './errors';
|
14
|
-
import * as sbvrUtils from './sbvr-utils';
|
15
|
-
import type { ODataRequest } from './uri-parser';
|
12
|
+
import * as env from '../config-loader/env.js';
|
13
|
+
import { BadRequestError, SqlCompilationError } from './errors.js';
|
14
|
+
import * as sbvrUtils from './sbvr-utils.js';
|
15
|
+
import type { ODataRequest } from './uri-parser.js';
|
16
16
|
|
17
17
|
const getMemoizedCompileRule = memoize(
|
18
18
|
(engine: AbstractSQLCompiler.Engines) =>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type
|
1
|
+
import type Fs from 'fs';
|
2
2
|
|
3
3
|
import _ from 'lodash';
|
4
4
|
|
@@ -12,7 +12,7 @@ let cache: null | {
|
|
12
12
|
} = null;
|
13
13
|
let fs: undefined | typeof Fs;
|
14
14
|
try {
|
15
|
-
fs =
|
15
|
+
fs = await import('fs');
|
16
16
|
} catch {
|
17
17
|
// Ignore error
|
18
18
|
}
|
package/src/sbvr-api/errors.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
declare global {
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
5
5
|
namespace Express {
|
6
|
-
type PineUser = import('./sbvr-utils').User;
|
6
|
+
type PineUser = import('./sbvr-utils.js').User;
|
7
7
|
|
8
8
|
// Augment Express.User to include the props of our PineUser.
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
@@ -11,7 +11,7 @@ declare global {
|
|
11
11
|
|
12
12
|
interface Request {
|
13
13
|
user?: User;
|
14
|
-
apiKey?: import('./sbvr-utils').ApiKey;
|
14
|
+
apiKey?: import('./sbvr-utils.js').ApiKey;
|
15
15
|
}
|
16
16
|
}
|
17
17
|
}
|
package/src/sbvr-api/hooks.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import type { OptionalField, Resolvable } from './common-types';
|
2
|
-
import type { Result, Tx } from '../database-layer/db';
|
3
|
-
import type { ODataRequest, ParsedODataRequest } from './uri-parser';
|
1
|
+
import type { OptionalField, Resolvable } from './common-types.js';
|
2
|
+
import type { Result, Tx } from '../database-layer/db.js';
|
3
|
+
import type { ODataRequest, ParsedODataRequest } from './uri-parser.js';
|
4
4
|
import type { AnyObject } from 'pinejs-client-core';
|
5
5
|
import type { TypedError } from 'typed-error';
|
6
6
|
import type { SupportedMethod } from '@balena/odata-to-abstract-sql';
|
7
7
|
|
8
8
|
import _ from 'lodash';
|
9
|
-
import { settleMapSeries } from './control-flow';
|
9
|
+
import { settleMapSeries } from './control-flow.js';
|
10
10
|
import memoize from 'memoizee';
|
11
11
|
import {
|
12
12
|
type User,
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
getAbstractSqlModel,
|
16
16
|
api,
|
17
17
|
type Response,
|
18
|
-
} from './sbvr-utils';
|
18
|
+
} from './sbvr-utils.js';
|
19
19
|
|
20
20
|
export interface HookReq {
|
21
21
|
user?: User;
|
@@ -18,13 +18,17 @@ declare module '@balena/abstract-sql-compiler' {
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
-
import type { Result, Row } from '../database-layer/db';
|
21
|
+
import type { Result, Row } from '../database-layer/db.js';
|
22
22
|
|
23
23
|
import { sqlNameToODataName } from '@balena/odata-to-abstract-sql';
|
24
|
-
import
|
24
|
+
import type { SbvrType } from '@balena/sbvr-types';
|
25
25
|
import _ from 'lodash';
|
26
|
-
import {
|
27
|
-
|
26
|
+
import {
|
27
|
+
sbvrTypes,
|
28
|
+
resolveNavigationResource,
|
29
|
+
resolveSynonym,
|
30
|
+
} from './sbvr-utils.js';
|
31
|
+
import { getWebresourceHandler } from '../webresource-handler/index.js';
|
28
32
|
|
29
33
|
const checkForExpansion = async (
|
30
34
|
vocab: string,
|