@balena/pinejs 19.7.1 → 19.7.2-build-esm-ce2a147ed7533c40f456b27f17ac4e559a0f9da8-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 +21 -1
- package/CHANGELOG.md +5 -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 +16 -53
- package/out/bin/utils.js.map +1 -1
- package/out/config-loader/config-loader.d.ts +6 -6
- 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 +1 -1
- 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 +2 -2
- 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 +8 -8
- 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 +38 -16
- 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 +6 -6
- 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 +15 -15
- 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/S3Handler.d.ts +1 -1
- package/out/webresource-handler/handlers/S3Handler.js +17 -24
- package/out/webresource-handler/handlers/S3Handler.js.map +1 -1
- package/out/webresource-handler/handlers/index.d.ts +2 -2
- package/out/webresource-handler/handlers/index.js +2 -18
- package/out/webresource-handler/handlers/index.js.map +1 -1
- package/out/webresource-handler/index.d.ts +1 -1
- package/out/webresource-handler/index.js +35 -85
- package/out/webresource-handler/index.js.map +1 -1
- package/package.json +10 -10
- 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 +20 -15
- package/src/config-loader/config-loader.ts +11 -11
- 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 +3 -3
- package/src/pinejs-session-store/pinejs-session-store.ts +4 -4
- package/src/sbvr-api/abstract-sql.ts +5 -5
- package/src/sbvr-api/cached-compile.ts +1 -1
- 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 +17 -17
- package/src/sbvr-api/sbvr-utils.ts +37 -31
- package/src/sbvr-api/translations.ts +1 -1
- package/src/sbvr-api/uri-parser.ts +9 -9
- package/src/server-glue/global-ext.d.ts +0 -3
- package/src/server-glue/module.ts +19 -19
- 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/S3Handler.ts +1 -1
- package/src/webresource-handler/handlers/index.ts +2 -2
- package/src/webresource-handler/index.ts +8 -8
- 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 +1 -1
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/pinejs",
|
3
|
-
"version": "19.7.1",
|
3
|
+
"version": "19.7.2-build-esm-ce2a147ed7533c40f456b27f17ac4e559a0f9da8-1",
|
4
4
|
"main": "out/server-glue/module",
|
5
|
-
"type": "
|
5
|
+
"type": "module",
|
6
6
|
"repository": "git@github.com:balena-io/pinejs.git",
|
7
7
|
"license": "Apache-2.0",
|
8
8
|
"bin": {
|
@@ -13,17 +13,17 @@
|
|
13
13
|
"scripts": {
|
14
14
|
"prepublish": "require-npm4-to-publish",
|
15
15
|
"prepare": "node -e \"try { (await import('husky')).default() } catch (e) { if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e }\" --input-type module && npm run build",
|
16
|
-
"build": "grunt build",
|
17
|
-
"webpack-browser": "grunt browser",
|
18
|
-
"webpack-module": "grunt module",
|
19
|
-
"webpack-server": "grunt server",
|
16
|
+
"build": "grunt --preload ts-node/register/transpile-only --gruntfile Gruntfile.cts build",
|
17
|
+
"webpack-browser": "grunt --preload ts-node/register/transpile-only --gruntfile Gruntfile.cts browser",
|
18
|
+
"webpack-module": "grunt --preload ts-node/register/transpile-only --gruntfile Gruntfile.cts module",
|
19
|
+
"webpack-server": "grunt --preload ts-node/register/transpile-only --gruntfile Gruntfile.cts server",
|
20
20
|
"webpack-build": "npm run webpack-browser && npm run webpack-module && npm run webpack-server",
|
21
|
-
"lint": "balena-lint -t tsconfig.dev.json -e js -e ts src build typings Gruntfile.
|
21
|
+
"lint": "balena-lint -t tsconfig.dev.json -e js -e ts src build typings Gruntfile.cts && npx tsc --project tsconfig.dev.json --noEmit",
|
22
22
|
"test": "npm run lint && npm run build && npm run webpack-build && npm run test:compose && npm run test:generated-types",
|
23
23
|
"test:compose": "trap 'docker compose -f docker-compose.npm-test.yml down ; echo Stopped ; exit 0' INT; docker compose -f docker-compose.npm-test.yml up -d && sleep 2 && DATABASE_URL=postgres://docker:docker@localhost:5431/postgres PINEJS_WEBRESOURCE_MAXFILESIZE=1000000000 S3_ENDPOINT=http://localhost:43680 S3_ACCESS_KEY=USERNAME S3_SECRET_KEY=PASSWORD S3_STORAGE_ADAPTER_BUCKET=balena-pine-web-resources S3_REGION=us-east-1 PINEJS_QUEUE_CONCURRENCY=1 TZ=UTC npm run mocha",
|
24
24
|
"test:generated-types": "npm run generate-types && git diff --exit-code ./src/sbvr-api/user.ts ./src/migrator/migrations.ts ./src/sbvr-api/dev.ts",
|
25
25
|
"mocha": "TS_NODE_FILES=true mocha",
|
26
|
-
"lint-fix": "balena-lint -t tsconfig.dev.json -e js -e ts --fix src test build typings Gruntfile.
|
26
|
+
"lint-fix": "balena-lint -t tsconfig.dev.json -e js -e ts --fix src test build typings Gruntfile.cts",
|
27
27
|
"generate-types": "node ./bin/sbvr-compiler.js generate-types ./src/sbvr-api/user.sbvr ./src/sbvr-api/user.ts && node ./bin/sbvr-compiler.js generate-types ./src/migrator/migrations.sbvr ./src/migrator/migrations.ts && node ./bin/sbvr-compiler.js generate-types ./src/sbvr-api/dev.sbvr ./src/sbvr-api/dev.ts && node ./bin/sbvr-compiler.js generate-types ./src/tasks/tasks.sbvr ./src/tasks/tasks.ts && balena-lint -t tsconfig.dev.json --fix ./src/sbvr-api/user.ts ./src/migrator/migrations.ts ./src/sbvr-api/dev.ts"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
@@ -141,12 +141,12 @@
|
|
141
141
|
"extension": [
|
142
142
|
".test.ts"
|
143
143
|
],
|
144
|
-
"
|
144
|
+
"loader": "ts-node/esm/transpile-only",
|
145
145
|
"exit": true,
|
146
146
|
"timeout": 60000,
|
147
147
|
"recursive": true
|
148
148
|
},
|
149
149
|
"versionist": {
|
150
|
-
"publishedAt": "2024-12-
|
150
|
+
"publishedAt": "2024-12-30T17:58:43.501Z"
|
151
151
|
}
|
152
152
|
}
|
@@ -3,13 +3,13 @@ import {
|
|
3
3
|
version,
|
4
4
|
writeAll,
|
5
5
|
writeSqlModel,
|
6
|
-
} from './utils';
|
6
|
+
} from './utils.js';
|
7
7
|
|
8
8
|
import { program } from 'commander';
|
9
9
|
|
10
10
|
const runCompile = async (inputFile: string, outputFile?: string) => {
|
11
11
|
const { generateSqlModel } = await import('../sbvr-api/sbvr-utils.js');
|
12
|
-
const abstractSql = getAbstractSqlModelFromFile(
|
12
|
+
const abstractSql = await getAbstractSqlModelFromFile(
|
13
13
|
inputFile,
|
14
14
|
program.opts().model,
|
15
15
|
);
|
@@ -28,7 +28,7 @@ const generateTypes = async (
|
|
28
28
|
const { abstractSqlToTypescriptTypes } = await import(
|
29
29
|
'@balena/abstract-sql-to-typescript/generate'
|
30
30
|
);
|
31
|
-
const abstractSql = getAbstractSqlModelFromFile(
|
31
|
+
const abstractSql = await getAbstractSqlModelFromFile(
|
32
32
|
inputFile,
|
33
33
|
program.opts().model,
|
34
34
|
);
|
@@ -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,18 @@ 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(
|
82
|
+
new URL(import.meta.resolve(modelFile)),
|
83
|
+
'utf8',
|
84
|
+
);
|
80
85
|
}
|
81
86
|
let seModel: string;
|
82
87
|
if (fileContents == null) {
|
@@ -94,16 +99,16 @@ export const getAbstractSqlModelFromFile = (
|
|
94
99
|
} else if ('modelText' in configModel && configModel.modelText != null) {
|
95
100
|
seModel = configModel.modelText;
|
96
101
|
} else if ('modelFile' in configModel && configModel.modelFile != null) {
|
97
|
-
seModel =
|
102
|
+
seModel = await loadSBVR(configModel.modelFile, import.meta);
|
98
103
|
} else {
|
99
104
|
throw new Error('Unrecognized config file');
|
100
105
|
}
|
101
106
|
} else {
|
102
107
|
throw new Error('Unrecognized config file');
|
103
108
|
}
|
104
|
-
const { generateLfModel, generateAbstractSqlModel } =
|
105
|
-
|
106
|
-
|
109
|
+
const { generateLfModel, generateAbstractSqlModel } = await import(
|
110
|
+
'../sbvr-api/sbvr-utils.js'
|
111
|
+
);
|
107
112
|
let lfModel;
|
108
113
|
try {
|
109
114
|
lfModel = generateLfModel(seModel);
|
@@ -3,13 +3,13 @@ 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
1
|
import type * as Express from 'express';
|
2
2
|
import type * as Passport from 'passport';
|
3
3
|
import type * as PassportLocal from 'passport-local';
|
4
|
-
import type * as ConfigLoader from '../config-loader/config-loader';
|
5
|
-
import type { User } from '../sbvr-api/sbvr-utils';
|
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
|
|
@@ -7,12 +7,12 @@ import {
|
|
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) =>
|
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,
|