@balena/pinejs 15.3.5-build-balena-lint-v7-c288dcb3a5500c3f520474349f4584df418e0ffe-1 → 15.3.5-build-renovate-faker-js-faker-8-x-6fa882162d2f96f2e0ecabc20634287304e2d254-1
Sign up to get free protection for your applications and to get access to all the features.
- package/.versionbot/CHANGELOG.yml +5 -55
- package/CHANGELOG.md +1 -7
- package/Gruntfile.ts +1 -4
- package/out/bin/abstract-sql-compiler.js +1 -1
- package/out/bin/abstract-sql-compiler.js.map +1 -1
- package/out/bin/odata-compiler.js +1 -1
- package/out/bin/odata-compiler.js.map +1 -1
- package/out/bin/sbvr-compiler.js +1 -1
- package/out/bin/sbvr-compiler.js.map +1 -1
- package/out/bin/utils.js.map +1 -1
- package/out/config-loader/config-loader.js +1 -2
- package/out/config-loader/config-loader.js.map +1 -1
- package/out/data-server/sbvr-server.d.ts +1 -1
- package/out/data-server/sbvr-server.js +1 -3
- package/out/data-server/sbvr-server.js.map +1 -1
- package/out/database-layer/db.js +10 -10
- package/out/database-layer/db.js.map +1 -1
- package/out/express-emulator/express.js +2 -4
- package/out/express-emulator/express.js.map +1 -1
- package/out/http-transactions/transactions.d.ts +1 -1
- package/out/http-transactions/transactions.js +5 -10
- package/out/http-transactions/transactions.js.map +1 -1
- package/out/migrator/utils.d.ts +2 -2
- package/out/passport-pinejs/passport-pinejs.d.ts +1 -1
- package/out/passport-pinejs/passport-pinejs.js +1 -5
- package/out/passport-pinejs/passport-pinejs.js.map +1 -1
- package/out/pinejs-session-store/pinejs-session-store.js +6 -6
- package/out/pinejs-session-store/pinejs-session-store.js.map +1 -1
- package/out/sbvr-api/abstract-sql.js +1 -1
- package/out/sbvr-api/abstract-sql.js.map +1 -1
- package/out/sbvr-api/cached-compile.js.map +1 -1
- package/out/sbvr-api/hooks.js +4 -3
- package/out/sbvr-api/hooks.js.map +1 -1
- package/out/sbvr-api/odata-response.d.ts +1 -1
- package/out/sbvr-api/odata-response.js +2 -2
- package/out/sbvr-api/odata-response.js.map +1 -1
- package/out/sbvr-api/permissions.d.ts +5 -4
- package/out/sbvr-api/permissions.js +4 -6
- package/out/sbvr-api/permissions.js.map +1 -1
- package/out/sbvr-api/sbvr-utils.d.ts +1 -1
- package/out/sbvr-api/sbvr-utils.js +2 -4
- package/out/sbvr-api/sbvr-utils.js.map +1 -1
- package/out/sbvr-api/uri-parser.js +1 -1
- package/out/sbvr-api/uri-parser.js.map +1 -1
- package/out/server-glue/global-ext.d.ts +1 -2
- package/out/server-glue/module.js.map +1 -1
- package/out/webresource-handler/handlers/NoopHandler.d.ts +1 -1
- package/out/webresource-handler/handlers/NoopHandler.js +1 -1
- package/out/webresource-handler/handlers/NoopHandler.js.map +1 -1
- package/out/webresource-handler/index.js +4 -4
- package/out/webresource-handler/index.js.map +1 -1
- package/package.json +9 -9
- package/src/bin/abstract-sql-compiler.ts +1 -1
- package/src/bin/odata-compiler.ts +1 -1
- package/src/bin/sbvr-compiler.ts +1 -1
- package/src/bin/utils.ts +1 -1
- package/src/config-loader/config-loader.ts +1 -2
- package/src/data-server/sbvr-server.js +1 -3
- package/src/database-layer/db.ts +14 -18
- package/src/express-emulator/express.js +2 -4
- package/src/extended-sbvr-parser/extended-sbvr-parser.ts +1 -1
- package/src/http-transactions/transactions.js +5 -10
- package/src/migrator/sync.ts +1 -1
- package/src/migrator/utils.ts +2 -2
- package/src/odata-metadata/odata-metadata-generator.ts +1 -1
- package/src/passport-pinejs/passport-pinejs.ts +3 -8
- package/src/pinejs-session-store/pinejs-session-store.ts +6 -6
- package/src/sbvr-api/abstract-sql.ts +1 -1
- package/src/sbvr-api/cached-compile.ts +1 -0
- package/src/sbvr-api/express-extension.ts +2 -4
- package/src/sbvr-api/hooks.ts +4 -3
- package/src/sbvr-api/odata-response.ts +7 -10
- package/src/sbvr-api/permissions.ts +14 -20
- package/src/sbvr-api/sbvr-utils.ts +4 -8
- package/src/sbvr-api/uri-parser.ts +1 -1
- package/src/server-glue/global-ext.d.ts +1 -2
- package/src/server-glue/module.ts +0 -1
- package/src/server-glue/sbvr-loader.ts +1 -1
- package/src/server-glue/server.ts +2 -2
- package/src/webresource-handler/handlers/NoopHandler.ts +1 -1
- package/src/webresource-handler/index.ts +4 -4
- package/tsconfig.dev.json +1 -2
- package/typings/lf-to-abstract-sql.d.ts +1 -1
- package/typings/memoizee.d.ts +4 -3
package/src/database-layer/db.ts
CHANGED
@@ -168,7 +168,7 @@ const atomicExecuteSql: Database['executeSql'] = async function (
|
|
168
168
|
};
|
169
169
|
|
170
170
|
const asyncTryFn = (fn: () => any) => {
|
171
|
-
|
171
|
+
Promise.resolve().then(fn);
|
172
172
|
};
|
173
173
|
|
174
174
|
type RejectedFunctions = (message: string) => {
|
@@ -215,10 +215,7 @@ class AutomaticClose {
|
|
215
215
|
private automaticCloseTimeout: ReturnType<typeof setTimeout>;
|
216
216
|
private automaticClose: () => void;
|
217
217
|
private pending: false | number = 0;
|
218
|
-
constructor(
|
219
|
-
tx: Tx,
|
220
|
-
private stackTraceErr?: Error,
|
221
|
-
) {
|
218
|
+
constructor(tx: Tx, private stackTraceErr?: Error) {
|
222
219
|
this.automaticClose = () => {
|
223
220
|
console.error(
|
224
221
|
`Transaction still open after ${env.db.timeoutMS}ms without an execute call.`,
|
@@ -226,7 +223,7 @@ class AutomaticClose {
|
|
226
223
|
if (this.stackTraceErr) {
|
227
224
|
console.error(this.stackTraceErr.stack);
|
228
225
|
}
|
229
|
-
|
226
|
+
tx.rollback();
|
230
227
|
};
|
231
228
|
this.automaticCloseTimeout = setTimeout(
|
232
229
|
this.automaticClose,
|
@@ -403,13 +400,10 @@ export abstract class Tx {
|
|
403
400
|
protected abstract _rollback(): Promise<void>;
|
404
401
|
protected abstract _commit(): Promise<void>;
|
405
402
|
|
406
|
-
// TODO: Re-enable the lint rule once eslint properly supports abstract class base implementations
|
407
403
|
public async getTxLevelLock(
|
408
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
409
404
|
_namespaceKey: string,
|
410
405
|
_key: number,
|
411
406
|
_blocking: boolean = true,
|
412
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
413
407
|
): Promise<boolean> {
|
414
408
|
throw new Error(
|
415
409
|
'The getTxLevelLock method is not implemented for the current engine.',
|
@@ -468,6 +462,7 @@ const createTransaction = (createFunc: CreateTransactionFn): TransactionFn => {
|
|
468
462
|
|
469
463
|
let maybePg: typeof Pg | undefined;
|
470
464
|
try {
|
465
|
+
// tslint:disable-next-line:no-var-requires
|
471
466
|
maybePg = require('pg');
|
472
467
|
} catch (e) {
|
473
468
|
// Ignore errors
|
@@ -502,7 +497,7 @@ if (maybePg != null) {
|
|
502
497
|
const p = new pg.Pool(config);
|
503
498
|
if (PG_SCHEMA != null) {
|
504
499
|
p.on('connect', (client) => {
|
505
|
-
|
500
|
+
client.query({ text: `SET search_path TO "${PG_SCHEMA}"` });
|
506
501
|
});
|
507
502
|
}
|
508
503
|
p.on('connect', (client) => {
|
@@ -524,7 +519,6 @@ if (maybePg != null) {
|
|
524
519
|
let pool: Pg.Pool;
|
525
520
|
let replica: Pg.Pool;
|
526
521
|
if (typeof connectString === 'string') {
|
527
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
528
522
|
const pgConnectionString: typeof PgConnectionString = require('pg-connection-string');
|
529
523
|
// We have to cast because of the use of null vs undefined
|
530
524
|
const config = pgConnectionString.parse(connectString) as Pg.PoolConfig;
|
@@ -623,9 +617,9 @@ if (maybePg != null) {
|
|
623
617
|
);
|
624
618
|
this.db.release();
|
625
619
|
} catch (err: any) {
|
626
|
-
|
627
|
-
this.db.release(
|
628
|
-
throw
|
620
|
+
err = wrapDatabaseError(err);
|
621
|
+
this.db.release(err);
|
622
|
+
throw err;
|
629
623
|
}
|
630
624
|
}
|
631
625
|
|
@@ -692,13 +686,13 @@ if (maybePg != null) {
|
|
692
686
|
transaction: createTransaction(async (stackTraceErr) => {
|
693
687
|
const client = await pool.connect();
|
694
688
|
const tx = new PostgresTx(client, false, stackTraceErr);
|
695
|
-
|
689
|
+
tx.executeSql('START TRANSACTION;');
|
696
690
|
return tx;
|
697
691
|
}),
|
698
692
|
readTransaction: createTransaction(async (stackTraceErr) => {
|
699
693
|
const client = await replica.connect();
|
700
694
|
const tx = new PostgresTx(client, false, stackTraceErr);
|
701
|
-
|
695
|
+
tx.executeSql('START TRANSACTION READ ONLY;');
|
702
696
|
return tx.asReadOnly();
|
703
697
|
}),
|
704
698
|
...alwaysExport,
|
@@ -708,6 +702,7 @@ if (maybePg != null) {
|
|
708
702
|
|
709
703
|
let maybeMysql: typeof Mysql | undefined;
|
710
704
|
try {
|
705
|
+
// tslint:disable-next-line:no-var-requires
|
711
706
|
maybeMysql = require('mysql');
|
712
707
|
} catch (e) {
|
713
708
|
// Ignore errors
|
@@ -814,14 +809,14 @@ if (maybeMysql != null) {
|
|
814
809
|
const client = await getConnectionAsync();
|
815
810
|
const close = () => client.release();
|
816
811
|
const tx = new MySqlTx(client, close, false, stackTraceErr);
|
817
|
-
|
812
|
+
tx.executeSql('START TRANSACTION;');
|
818
813
|
return tx;
|
819
814
|
}),
|
820
815
|
readTransaction: createTransaction(async (stackTraceErr) => {
|
821
816
|
const client = await getConnectionAsync();
|
822
817
|
const close = () => client.release();
|
823
818
|
const tx = new MySqlTx(client, close, false, stackTraceErr);
|
824
|
-
|
819
|
+
tx.executeSql('START TRANSACTION READ ONLY;');
|
825
820
|
return tx.asReadOnly();
|
826
821
|
}),
|
827
822
|
...alwaysExport,
|
@@ -940,6 +935,7 @@ if (typeof window !== 'undefined' && window.openDatabase != null) {
|
|
940
935
|
// allowing us to use async calls within the API.
|
941
936
|
private asyncRecurse = () => {
|
942
937
|
let args: AsyncQuery | undefined;
|
938
|
+
// tslint:disable-next-line no-conditional-assignment
|
943
939
|
while ((args = this.queue.pop())) {
|
944
940
|
console.debug('Running', args[0]);
|
945
941
|
this.tx.executeSql(args[0], args[1], args[2], args[3]);
|
@@ -34,10 +34,10 @@ const app = (function () {
|
|
34
34
|
/** @type {string} */ match,
|
35
35
|
/** @type import('express').Handler[] */ ...middleware
|
36
36
|
) {
|
37
|
-
//
|
37
|
+
//Strip wildcard
|
38
38
|
let paramName;
|
39
39
|
match = match.toLowerCase();
|
40
|
-
const newMatch = match.replace(/[
|
40
|
+
const newMatch = match.replace(/[\/\*]*$/, '');
|
41
41
|
if (newMatch !== match) {
|
42
42
|
match = newMatch;
|
43
43
|
paramName = '*';
|
@@ -59,8 +59,6 @@ const app = (function () {
|
|
59
59
|
/** @type any */ body = '',
|
60
60
|
) {
|
61
61
|
if (!handlers[method]) {
|
62
|
-
// TODO: Consider changing this to a custom Error
|
63
|
-
// eslint-disable-next-line no-throw-literal
|
64
62
|
throw [404, null, null];
|
65
63
|
}
|
66
64
|
const req = {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { SBVRParser } from '@balena/sbvr-parser';
|
2
|
-
//
|
2
|
+
// tslint:disable-next-line:no-var-requires
|
3
3
|
const Types: string = require('@balena/sbvr-types/Type.sbvr');
|
4
4
|
import { version as sbvrParserVersion } from '@balena/sbvr-parser/package.json';
|
5
5
|
import { version } from '@balena/sbvr-parser/package.json';
|
@@ -1,10 +1,10 @@
|
|
1
|
+
import * as _ from 'lodash';
|
1
2
|
import { odataNameToSqlName } from '@balena/odata-to-abstract-sql';
|
2
|
-
// @ts-
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
3
|
+
// @ts-ignore
|
4
4
|
const transactionModel = require('./transaction.sbvr');
|
5
5
|
|
6
6
|
/** @type {import('../config-loader/config-loader').Config} */
|
7
|
-
export
|
7
|
+
export let config = {
|
8
8
|
models: [
|
9
9
|
{
|
10
10
|
apiRoot: 'transaction',
|
@@ -130,12 +130,7 @@ WHERE "conditional field"."conditional resource" = ?;`,
|
|
130
130
|
modelField.dataType === 'ForeignKey' &&
|
131
131
|
Number.isNaN(Number(fieldValue))
|
132
132
|
) {
|
133
|
-
if (
|
134
|
-
!Object.prototype.hasOwnProperty.call(
|
135
|
-
placeholders,
|
136
|
-
fieldValue,
|
137
|
-
)
|
138
|
-
) {
|
133
|
+
if (!placeholders.hasOwnProperty(fieldValue)) {
|
139
134
|
throw new Error('Cannot resolve placeholder' + fieldValue);
|
140
135
|
} else {
|
141
136
|
try {
|
@@ -175,7 +170,7 @@ WHERE "conditional resource"."transaction" = ?;\
|
|
175
170
|
resolve = $resolve;
|
176
171
|
reject = $reject;
|
177
172
|
});
|
178
|
-
// @ts-
|
173
|
+
// @ts-ignore
|
179
174
|
placeholders[placeholder] = { promise, resolve, reject };
|
180
175
|
}
|
181
176
|
}
|
package/src/migrator/sync.ts
CHANGED
@@ -15,7 +15,7 @@ import type { Config, Model } from '../config-loader/config-loader';
|
|
15
15
|
import * as _ from 'lodash';
|
16
16
|
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
|
17
17
|
|
18
|
-
//
|
18
|
+
// tslint:disable-next-line:no-var-requires
|
19
19
|
const modelText = require('./migrations.sbvr');
|
20
20
|
|
21
21
|
type ApiRootModel = Model & { apiRoot: string };
|
package/src/migrator/utils.ts
CHANGED
@@ -32,12 +32,12 @@ export type AsyncMigrationFn = (
|
|
32
32
|
sbvrUtils: SbvrUtils,
|
33
33
|
) => Resolvable<number>;
|
34
34
|
|
35
|
-
type AddFn<T extends
|
35
|
+
type AddFn<T extends {}, x extends 'sync' | 'async'> = T & {
|
36
36
|
[key in `${x}Fn`]: key extends 'syncFn' ? MigrationFn : AsyncMigrationFn;
|
37
37
|
} & {
|
38
38
|
[key in `${x}Sql`]?: undefined;
|
39
39
|
};
|
40
|
-
type AddSql<T extends
|
40
|
+
type AddSql<T extends {}, x extends 'sync' | 'async'> = T & {
|
41
41
|
[key in `${x}Fn`]?: undefined;
|
42
42
|
} & {
|
43
43
|
[key in `${x}Sql`]: string;
|
@@ -5,7 +5,7 @@ import type {
|
|
5
5
|
|
6
6
|
import sbvrTypes, { SbvrType } from '@balena/sbvr-types';
|
7
7
|
|
8
|
-
//
|
8
|
+
// tslint:disable-next-line:no-var-requires
|
9
9
|
const { version }: { version: string } = require('../../package.json');
|
10
10
|
|
11
11
|
const getResourceName = (resourceName: string): string =>
|
@@ -10,7 +10,7 @@ import * as permissions from '../sbvr-api/permissions';
|
|
10
10
|
export let login: (
|
11
11
|
fn: (
|
12
12
|
err: any,
|
13
|
-
user:
|
13
|
+
user: {} | null | false | undefined,
|
14
14
|
req: Express.Request,
|
15
15
|
res: Express.Response,
|
16
16
|
next: Express.NextFunction,
|
@@ -35,13 +35,12 @@ export const checkPassword: PassportLocal.VerifyFunction = async (
|
|
35
35
|
|
36
36
|
const setup: ConfigLoader.SetupFunction = async (app: Express.Application) => {
|
37
37
|
if (!process.browser) {
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
39
38
|
const passport: typeof Passport = require('passport');
|
40
39
|
app.use(passport.initialize());
|
41
40
|
app.use(passport.session());
|
42
41
|
|
43
42
|
const {
|
44
|
-
Strategy: LocalStrategy,
|
43
|
+
Strategy: LocalStrategy,
|
45
44
|
}: typeof PassportLocal = require('passport-local');
|
46
45
|
|
47
46
|
passport.serializeUser((user, done) => {
|
@@ -67,11 +66,7 @@ const setup: ConfigLoader.SetupFunction = async (app: Express.Application) => {
|
|
67
66
|
|
68
67
|
logout = (req, _res, next) => {
|
69
68
|
req.logout((error) => {
|
70
|
-
|
71
|
-
next(error);
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
next();
|
69
|
+
error ? next(error) : next();
|
75
70
|
});
|
76
71
|
};
|
77
72
|
} else {
|
@@ -50,7 +50,7 @@ const asCallback = async <T>(
|
|
50
50
|
|
51
51
|
export class PinejsSessionStore extends Store {
|
52
52
|
public get = ((sid, callback) => {
|
53
|
-
|
53
|
+
asCallback(
|
54
54
|
callback,
|
55
55
|
api.session
|
56
56
|
.get({
|
@@ -77,7 +77,7 @@ export class PinejsSessionStore extends Store {
|
|
77
77
|
data,
|
78
78
|
expiry_time: data?.cookie?.expires ?? null,
|
79
79
|
};
|
80
|
-
|
80
|
+
asCallback(
|
81
81
|
callback,
|
82
82
|
api.session.put({
|
83
83
|
resource: 'session',
|
@@ -91,7 +91,7 @@ export class PinejsSessionStore extends Store {
|
|
91
91
|
}) as Store['set'];
|
92
92
|
|
93
93
|
public destroy = ((sid, callback) => {
|
94
|
-
|
94
|
+
asCallback(
|
95
95
|
callback,
|
96
96
|
api.session.delete({
|
97
97
|
resource: 'session',
|
@@ -104,7 +104,7 @@ export class PinejsSessionStore extends Store {
|
|
104
104
|
}) as Store['destroy'];
|
105
105
|
|
106
106
|
public all = ((callback) => {
|
107
|
-
|
107
|
+
asCallback(
|
108
108
|
callback,
|
109
109
|
api.session
|
110
110
|
.get({
|
@@ -124,7 +124,7 @@ export class PinejsSessionStore extends Store {
|
|
124
124
|
}) as Store['all'];
|
125
125
|
|
126
126
|
public clear = ((callback) => {
|
127
|
-
|
127
|
+
asCallback(
|
128
128
|
callback,
|
129
129
|
// TODO: Use a truncate
|
130
130
|
api.session.delete({
|
@@ -137,7 +137,7 @@ export class PinejsSessionStore extends Store {
|
|
137
137
|
}) as Store['clear'];
|
138
138
|
|
139
139
|
public length = ((callback) => {
|
140
|
-
|
140
|
+
asCallback(
|
141
141
|
callback,
|
142
142
|
api.session.get({
|
143
143
|
resource: 'session/',
|
@@ -116,7 +116,7 @@ export const getAndCheckBindValues = async (
|
|
116
116
|
[dataType, value] = odataBinds[bindValue];
|
117
117
|
field = { dataType };
|
118
118
|
} else if (typeof bindValue === 'string') {
|
119
|
-
if (!
|
119
|
+
if (!odataBinds.hasOwnProperty(bindValue)) {
|
120
120
|
console.error(
|
121
121
|
`Invalid binding '${bindValue}' for binds: `,
|
122
122
|
odataBinds,
|
@@ -1,13 +1,11 @@
|
|
1
1
|
// Augment express.js with pinejs-specific attributes via declaration merging.
|
2
2
|
|
3
|
-
//
|
3
|
+
// tslint:disable-next-line:no-namespace
|
4
4
|
declare namespace Express {
|
5
5
|
type PineUser = import('./sbvr-utils').User;
|
6
6
|
|
7
|
-
//
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
7
|
+
// tslint:disable-next-line:no-empty-interface
|
9
8
|
interface User extends PineUser {}
|
10
|
-
|
11
9
|
interface Request {
|
12
10
|
user?: User;
|
13
11
|
apiKey?: import('./sbvr-utils').ApiKey;
|
package/src/sbvr-api/hooks.ts
CHANGED
@@ -101,7 +101,7 @@ class SideEffectHook<T extends HookFn> extends Hook<T> {
|
|
101
101
|
|
102
102
|
public registerRollback(fn: RollbackAction): void {
|
103
103
|
if (this.rolledBack) {
|
104
|
-
|
104
|
+
(async () => {
|
105
105
|
try {
|
106
106
|
await fn();
|
107
107
|
} catch {
|
@@ -140,7 +140,7 @@ export const rollbackRequestHooks = <T extends InstantiatedHooks>(
|
|
140
140
|
if (sideEffectHooks.length === 0) {
|
141
141
|
return;
|
142
142
|
}
|
143
|
-
|
143
|
+
settleMapSeries(sideEffectHooks, async (hook) => {
|
144
144
|
await hook.rollback();
|
145
145
|
});
|
146
146
|
};
|
@@ -391,7 +391,8 @@ const getReadOnlyArgs = <T extends keyof Hooks>(
|
|
391
391
|
// If we don't have a tx then read-only/writable is irrelevant
|
392
392
|
return args;
|
393
393
|
}
|
394
|
-
|
394
|
+
let readOnlyArgs: typeof args;
|
395
|
+
readOnlyArgs = { ...args, tx: args.tx.asReadOnly() };
|
395
396
|
if ((args as HookArgs).request != null) {
|
396
397
|
defineApi(modelName, readOnlyArgs as HookArgs);
|
397
398
|
}
|
@@ -1,11 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
AbstractSqlModel,
|
3
|
-
AbstractSqlTable,
|
4
|
-
} from '@balena/abstract-sql-compiler';
|
5
|
-
|
6
|
-
// Augment express.js with pinejs-specific attributes via declaration merging.
|
7
1
|
declare module '@balena/abstract-sql-compiler' {
|
8
|
-
|
2
|
+
interface AbstractSqlTable {
|
9
3
|
fetchProcessingFields?: {
|
10
4
|
[field: string]: NonNullable<SbvrType['fetchProcessing']>;
|
11
5
|
};
|
@@ -15,6 +9,10 @@ declare module '@balena/abstract-sql-compiler' {
|
|
15
9
|
}
|
16
10
|
}
|
17
11
|
|
12
|
+
import type {
|
13
|
+
AbstractSqlModel,
|
14
|
+
AbstractSqlTable,
|
15
|
+
} from '@balena/abstract-sql-compiler';
|
18
16
|
import type { Result, Row } from '../database-layer/db';
|
19
17
|
|
20
18
|
import { sqlNameToODataName } from '@balena/odata-to-abstract-sql';
|
@@ -146,15 +144,14 @@ export const process = async (
|
|
146
144
|
|
147
145
|
const fetchProcessingFields = getFetchProcessingFields(table);
|
148
146
|
const processedFields = fieldNames.filter((fieldName) =>
|
149
|
-
|
147
|
+
fetchProcessingFields.hasOwnProperty(fieldName),
|
150
148
|
);
|
151
149
|
|
152
150
|
const localFields = getLocalFields(table);
|
153
151
|
// We check that it's not a local field, rather than that it is a foreign key because of the case where the foreign key is on the other resource
|
154
152
|
// and hence not known to this resource
|
155
153
|
const expandableFields = fieldNames.filter(
|
156
|
-
(fieldName) =>
|
157
|
-
!Object.prototype.hasOwnProperty.call(localFields, fieldName),
|
154
|
+
(fieldName) => !localFields.hasOwnProperty(fieldName),
|
158
155
|
);
|
159
156
|
|
160
157
|
const odataIdField = sqlNameToODataName(table.idField);
|
@@ -52,7 +52,7 @@ import {
|
|
52
52
|
} from './uri-parser';
|
53
53
|
import memoizeWeak = require('memoizee/weak');
|
54
54
|
|
55
|
-
//
|
55
|
+
// tslint:disable-next-line:no-var-requires
|
56
56
|
const userModel: string = require('./user.sbvr');
|
57
57
|
|
58
58
|
const DEFAULT_ACTOR_BIND = '@__ACTOR_ID';
|
@@ -87,7 +87,7 @@ interface NestedCheckOr<T> {
|
|
87
87
|
interface NestedCheckAnd<T> {
|
88
88
|
and: NestedCheckArray<T>;
|
89
89
|
}
|
90
|
-
|
90
|
+
interface NestedCheckArray<T> extends Array<NestedCheck<T>> {}
|
91
91
|
type NestedCheck<T> =
|
92
92
|
| NestedCheckOr<T>
|
93
93
|
| NestedCheckAnd<T>
|
@@ -175,26 +175,22 @@ const isAnd = <T>(x: any): x is NestedCheckAnd<T> =>
|
|
175
175
|
typeof x === 'object' && 'and' in x;
|
176
176
|
const isOr = <T>(x: any): x is NestedCheckOr<T> =>
|
177
177
|
typeof x === 'object' && 'or' in x;
|
178
|
-
export function nestedCheck<I extends
|
179
|
-
check:
|
178
|
+
export function nestedCheck<I extends {}, O>(
|
179
|
+
check: string,
|
180
180
|
stringCallback: (s: string) => O,
|
181
181
|
): O;
|
182
|
-
export function nestedCheck<I extends
|
183
|
-
check:
|
182
|
+
export function nestedCheck<I extends {}, O>(
|
183
|
+
check: boolean,
|
184
184
|
stringCallback: (s: string) => O,
|
185
185
|
): boolean;
|
186
|
-
export function nestedCheck<I extends
|
186
|
+
export function nestedCheck<I extends {}, O>(
|
187
187
|
check: NestedCheck<I>,
|
188
188
|
stringCallback: (s: string) => O,
|
189
189
|
): Exclude<I, string> | O | MappedNestedCheck<typeof check, I, O>;
|
190
|
-
export function nestedCheck<I extends
|
191
|
-
check: NestedCheck<I
|
190
|
+
export function nestedCheck<I extends {}, O>(
|
191
|
+
check: NestedCheck<I>,
|
192
192
|
stringCallback: (s: string) => O,
|
193
|
-
):
|
194
|
-
| boolean
|
195
|
-
| Exclude<I, string>
|
196
|
-
| O
|
197
|
-
| MappedNestedCheck<Exclude<typeof check, string | boolean>, I, O> {
|
193
|
+
): boolean | Exclude<I, string> | O | MappedNestedCheck<typeof check, I, O> {
|
198
194
|
if (typeof check === 'string') {
|
199
195
|
return stringCallback(check);
|
200
196
|
}
|
@@ -232,11 +228,10 @@ export function nestedCheck<I extends object, O>(
|
|
232
228
|
}
|
233
229
|
const checkType = checkTypes[0];
|
234
230
|
switch (checkType.toUpperCase()) {
|
235
|
-
case 'AND':
|
231
|
+
case 'AND':
|
236
232
|
const and = (check as NestedCheckAnd<I>)[checkType as 'and'];
|
237
233
|
return nestedCheck(and, stringCallback);
|
238
|
-
|
239
|
-
case 'OR': {
|
234
|
+
case 'OR':
|
240
235
|
const or = (check as NestedCheckOr<I>)[checkType as 'or'];
|
241
236
|
let results: any[] = [];
|
242
237
|
for (const subcheck of or) {
|
@@ -260,7 +255,6 @@ export function nestedCheck<I extends object, O>(
|
|
260
255
|
};
|
261
256
|
}
|
262
257
|
return false;
|
263
|
-
}
|
264
258
|
default:
|
265
259
|
throw new Error('Cannot parse required checking logic: ' + checkType);
|
266
260
|
}
|
@@ -431,7 +425,7 @@ const convertToLambda = (filter: AnyObject, identifier: string) => {
|
|
431
425
|
}
|
432
426
|
}
|
433
427
|
|
434
|
-
if (
|
428
|
+
if (object.hasOwnProperty('name')) {
|
435
429
|
object.property = { ...object };
|
436
430
|
object.name = identifier;
|
437
431
|
delete object.lambda;
|
@@ -727,7 +721,7 @@ const deepFreezeExceptDefinition = (obj: AnyObject) => {
|
|
727
721
|
// We skip the definition because we know it's a property we've defined that will throw an error in some cases
|
728
722
|
if (
|
729
723
|
prop !== 'definition' &&
|
730
|
-
|
724
|
+
obj.hasOwnProperty(prop) &&
|
731
725
|
obj[prop] !== null &&
|
732
726
|
!['object', 'function'].includes(typeof obj[prop])
|
733
727
|
) {
|
@@ -3,9 +3,7 @@ import type * as Db from '../database-layer/db';
|
|
3
3
|
import type { Model } from '../config-loader/config-loader';
|
4
4
|
import type { AnyObject, RequiredField } from './common-types';
|
5
5
|
|
6
|
-
// Augment the Express typings
|
7
6
|
declare global {
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
9
7
|
namespace Express {
|
10
8
|
export interface Request {
|
11
9
|
tx?: Db.Tx;
|
@@ -40,7 +38,7 @@ import * as asyncMigrator from '../migrator/async';
|
|
40
38
|
import * as syncMigrator from '../migrator/sync';
|
41
39
|
import { generateODataMetadata } from '../odata-metadata/odata-metadata-generator';
|
42
40
|
|
43
|
-
//
|
41
|
+
// tslint:disable-next-line:no-var-requires
|
44
42
|
const devModel = require('./dev.sbvr');
|
45
43
|
import * as permissions from './permissions';
|
46
44
|
import {
|
@@ -251,14 +249,13 @@ const prettifyConstraintError = (
|
|
251
249
|
err.message,
|
252
250
|
);
|
253
251
|
break;
|
254
|
-
case 'postgres':
|
252
|
+
case 'postgres':
|
255
253
|
const resourceName = resolveSynonym(request);
|
256
254
|
const abstractSqlModel = getFinalAbstractSqlModel(request);
|
257
255
|
matches = new RegExp(
|
258
256
|
'"' + abstractSqlModel.tables[resourceName].name + '_(.*?)_key"',
|
259
257
|
).exec(err.message);
|
260
258
|
break;
|
261
|
-
}
|
262
259
|
}
|
263
260
|
// We know it's the right error type, so if matches exists just throw a generic error message, since we have failed to get the info for a more specific one.
|
264
261
|
if (matches == null) {
|
@@ -285,7 +282,7 @@ const prettifyConstraintError = (
|
|
285
282
|
err.message,
|
286
283
|
);
|
287
284
|
break;
|
288
|
-
case 'postgres':
|
285
|
+
case 'postgres':
|
289
286
|
const resourceName = resolveSynonym(request);
|
290
287
|
const abstractSqlModel = getFinalAbstractSqlModel(request);
|
291
288
|
const tableName = abstractSqlModel.tables[resourceName].name;
|
@@ -304,7 +301,6 @@ const prettifyConstraintError = (
|
|
304
301
|
).exec(err.message);
|
305
302
|
}
|
306
303
|
break;
|
307
|
-
}
|
308
304
|
}
|
309
305
|
// We know it's the right error type, so if no matches exists just throw a generic error message,
|
310
306
|
// since we have failed to get the info for a more specific one.
|
@@ -987,7 +983,7 @@ export class PinejsClient extends PinejsClientCore<PinejsClient> {
|
|
987
983
|
req?: permissions.PermissionReq;
|
988
984
|
custom?: AnyObject;
|
989
985
|
}) {
|
990
|
-
return (await runURI(method, url, body, tx, req, custom)) as
|
986
|
+
return (await runURI(method, url, body, tx, req, custom)) as {};
|
991
987
|
}
|
992
988
|
}
|
993
989
|
|
@@ -416,7 +416,7 @@ export const translateUri = <
|
|
416
416
|
request = { ...request };
|
417
417
|
request.values = new Proxy(request.values, {
|
418
418
|
set: (obj: ODataRequest['values'], prop: string, value) => {
|
419
|
-
if (!
|
419
|
+
if (!obj.hasOwnProperty(prop)) {
|
420
420
|
sbvrUtils.api[request.vocabulary].logger.warn(
|
421
421
|
`Assigning a new request.values property '${prop}' however it will be ignored`,
|
422
422
|
);
|
@@ -66,7 +66,6 @@ export const init = async <T extends string>(
|
|
66
66
|
const promises: Array<Promise<void>> = [];
|
67
67
|
if (process.env.SBVR_SERVER_ENABLED) {
|
68
68
|
const sbvrServer = await import('../data-server/sbvr-server');
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
70
69
|
const transactions = require('../http-transactions/transactions');
|
71
70
|
promises.push(cfgLoader.loadConfig(sbvrServer.config));
|
72
71
|
promises.push(
|
@@ -15,7 +15,7 @@ if (!process.browser) {
|
|
15
15
|
global.nodeRequire = require;
|
16
16
|
}
|
17
17
|
// Register a .sbvr loader
|
18
|
-
//
|
18
|
+
// tslint:disable-next-line:no-var-requires
|
19
19
|
const fs: typeof Fs = require('fs');
|
20
20
|
nodeRequire.extensions['.sbvr'] = (module: NodeModule, filename: string) =>
|
21
21
|
(module.exports = fs.readFileSync(filename, 'utf8'));
|
@@ -27,7 +27,7 @@ switch (app.get('env')) {
|
|
27
27
|
}
|
28
28
|
|
29
29
|
if (!process.browser) {
|
30
|
-
|
30
|
+
// tslint:disable:no-var-requires
|
31
31
|
const passport: typeof Passport = require('passport');
|
32
32
|
const path: typeof Path = require('path');
|
33
33
|
const compression: typeof Compression = require('compression');
|
@@ -36,7 +36,7 @@ if (!process.browser) {
|
|
36
36
|
const bodyParser: typeof BodyParser = require('body-parser');
|
37
37
|
const methodOverride: typeof MethodOverride = require('method-override');
|
38
38
|
const expressSession: typeof ExpressSession = require('express-session');
|
39
|
-
|
39
|
+
// tslint:enable:no-var-requires
|
40
40
|
|
41
41
|
app.use(compression());
|
42
42
|
|