@balena/pinejs 16.2.0-build-joshbwlng-tasks-f9c7bcd03b9bd8e872adf95baf22d38db59a224c-3 → 16.2.0-build-joshbwlng-tasks-8552b344881d795e9ce7a999cec89f98f20902b7-2
Sign up to get free protection for your applications and to get access to all the features.
- package/.versionbot/CHANGELOG.yml +1883 -3
- package/CHANGELOG.md +717 -1
- package/out/http-transactions/transactions.js +2 -2
- package/out/http-transactions/transactions.js.map +1 -1
- package/out/migrator/async.js +8 -9
- package/out/migrator/async.js.map +1 -1
- package/out/migrator/sync.js +6 -6
- package/out/migrator/sync.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/permissions.js +3 -3
- package/out/sbvr-api/permissions.js.map +1 -1
- package/out/sbvr-api/sbvr-utils.d.ts +4 -1
- package/out/sbvr-api/sbvr-utils.js +16 -14
- 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/webresource-handler/index.js +1 -1
- package/out/webresource-handler/index.js.map +1 -1
- package/package.json +36 -36
- package/src/http-transactions/transactions.js +2 -2
- package/src/migrator/async.ts +10 -11
- package/src/migrator/sync.ts +6 -6
- package/src/sbvr-api/abstract-sql.ts +1 -1
- package/src/sbvr-api/permissions.ts +3 -3
- package/src/sbvr-api/sbvr-utils.ts +21 -14
- package/src/sbvr-api/uri-parser.ts +1 -1
- package/src/webresource-handler/index.ts +1 -1
@@ -49,7 +49,7 @@ export const compileRequest = (request: ODataRequest) => {
|
|
49
49
|
request.sqlQuery = sqlQuery;
|
50
50
|
request.modifiedFields = modifiedFields;
|
51
51
|
} catch (err: any) {
|
52
|
-
sbvrUtils.
|
52
|
+
sbvrUtils.logger[request.vocabulary].error(
|
53
53
|
'Failed to compile abstract sql: ',
|
54
54
|
request.abstractSqlQuery,
|
55
55
|
err,
|
@@ -1268,7 +1268,7 @@ export const getUserPermissions = async (
|
|
1268
1268
|
try {
|
1269
1269
|
return await $getUserPermissions(userId, tx);
|
1270
1270
|
} catch (err: any) {
|
1271
|
-
sbvrUtils.
|
1271
|
+
sbvrUtils.logger.Auth.error('Error loading user permissions', err);
|
1272
1272
|
throw err;
|
1273
1273
|
}
|
1274
1274
|
};
|
@@ -1396,7 +1396,7 @@ export const getApiKeyPermissions = async (
|
|
1396
1396
|
try {
|
1397
1397
|
return await $getApiKeyPermissions(apiKey, tx);
|
1398
1398
|
} catch (err: any) {
|
1399
|
-
sbvrUtils.
|
1399
|
+
sbvrUtils.logger.Auth.error('Error loading api key permissions', err);
|
1400
1400
|
throw err;
|
1401
1401
|
}
|
1402
1402
|
};
|
@@ -1577,7 +1577,7 @@ export const checkPermissionsMiddleware =
|
|
1577
1577
|
);
|
1578
1578
|
}
|
1579
1579
|
} catch (err: any) {
|
1580
|
-
sbvrUtils.
|
1580
|
+
sbvrUtils.logger.Auth.error('Error checking permissions', err);
|
1581
1581
|
res.status(503).end();
|
1582
1582
|
}
|
1583
1583
|
};
|
@@ -678,18 +678,19 @@ export const executeModels = async (
|
|
678
678
|
api[apiRoot].logger = { ...console };
|
679
679
|
if (model.logging != null) {
|
680
680
|
const defaultSetting = model.logging?.default ?? true;
|
681
|
-
const { logger } = api[apiRoot];
|
681
|
+
const { logger: log } = api[apiRoot];
|
682
682
|
for (const k of Object.keys(model.logging)) {
|
683
683
|
const key = k as keyof Console;
|
684
684
|
if (
|
685
685
|
key !== 'Console' &&
|
686
|
-
typeof
|
686
|
+
typeof log[key] === 'function' &&
|
687
687
|
!(model.logging?.[key] ?? defaultSetting)
|
688
688
|
) {
|
689
|
-
|
689
|
+
log[key] = _.noop;
|
690
690
|
}
|
691
691
|
}
|
692
692
|
}
|
693
|
+
logger[apiRoot] = api[apiRoot].logger;
|
693
694
|
return compiledModel;
|
694
695
|
// Only update the dev models once all models have finished executing.
|
695
696
|
}),
|
@@ -858,7 +859,7 @@ export const runRule = (() => {
|
|
858
859
|
translator.addTypes(sbvrTypes);
|
859
860
|
return async (vocab: string, rule: string) => {
|
860
861
|
const seModel = models[vocab].se;
|
861
|
-
const
|
862
|
+
const log = logger[vocab];
|
862
863
|
let lfModel: LFModel;
|
863
864
|
let slfModel: LFModel;
|
864
865
|
let abstractSqlModel: AbstractSQLCompiler.AbstractSqlModel;
|
@@ -869,7 +870,7 @@ export const runRule = (() => {
|
|
869
870
|
'Process',
|
870
871
|
);
|
871
872
|
} catch (e) {
|
872
|
-
|
873
|
+
log.error('Error parsing rule', rule, e);
|
873
874
|
throw new Error(`Error parsing rule'${rule}': ${e}`);
|
874
875
|
}
|
875
876
|
|
@@ -883,7 +884,7 @@ export const runRule = (() => {
|
|
883
884
|
translator.reset();
|
884
885
|
abstractSqlModel = translator.match(slfModel, 'Process');
|
885
886
|
} catch (e) {
|
886
|
-
|
887
|
+
log.error('Error compiling rule', rule, e);
|
887
888
|
throw new Error(`Error compiling rule '${rule}': ${e}`);
|
888
889
|
}
|
889
890
|
|
@@ -1001,7 +1002,7 @@ export type Passthrough = AnyObject & {
|
|
1001
1002
|
tx?: Db.Tx;
|
1002
1003
|
};
|
1003
1004
|
|
1004
|
-
export class PinejsClient extends PinejsClientCore
|
1005
|
+
export class PinejsClient extends PinejsClientCore {
|
1005
1006
|
// @ts-expect-error This is actually assigned by `super` so it is always declared but that isn't detected here
|
1006
1007
|
public passthrough: Passthrough;
|
1007
1008
|
public async _request({
|
@@ -1023,12 +1024,18 @@ export class PinejsClient extends PinejsClientCore<PinejsClient> {
|
|
1023
1024
|
}
|
1024
1025
|
}
|
1025
1026
|
|
1027
|
+
/**
|
1028
|
+
* @deprecated Use `logger[vocab]` instead of `api[vocab].logger`
|
1029
|
+
*/
|
1026
1030
|
export type LoggingClient = PinejsClient & {
|
1027
1031
|
logger: Console;
|
1028
1032
|
};
|
1029
1033
|
export const api: {
|
1030
1034
|
[vocab: string]: LoggingClient;
|
1031
1035
|
} = {};
|
1036
|
+
export const logger: {
|
1037
|
+
[vocab: string]: Console;
|
1038
|
+
} = {};
|
1032
1039
|
|
1033
1040
|
// We default to guest only permissions if no req object is passed in
|
1034
1041
|
export const runURI = async (
|
@@ -1226,7 +1233,7 @@ export const getModel = (vocabulary: string) => {
|
|
1226
1233
|
|
1227
1234
|
const runODataRequest = (req: Express.Request, vocabulary: string) => {
|
1228
1235
|
if (env.DEBUG) {
|
1229
|
-
|
1236
|
+
logger[vocabulary].log('Parsing', req.method, req.url);
|
1230
1237
|
}
|
1231
1238
|
|
1232
1239
|
// Get the hooks for the current method/vocabulary as we know it,
|
@@ -1537,10 +1544,10 @@ const runRequest = async (
|
|
1537
1544
|
tx: Db.Tx,
|
1538
1545
|
request: uriParser.ODataRequest,
|
1539
1546
|
): Promise<Response> => {
|
1540
|
-
const
|
1547
|
+
const log = logger[request.vocabulary];
|
1541
1548
|
|
1542
1549
|
if (env.DEBUG) {
|
1543
|
-
|
1550
|
+
log.log('Running', req.method, req.url);
|
1544
1551
|
}
|
1545
1552
|
let result: Db.Result | number | undefined;
|
1546
1553
|
|
@@ -1568,7 +1575,7 @@ const runRequest = async (
|
|
1568
1575
|
} catch (err: any) {
|
1569
1576
|
if (err instanceof db.DatabaseError) {
|
1570
1577
|
prettifyConstraintError(err, request);
|
1571
|
-
|
1578
|
+
log.error(err);
|
1572
1579
|
// Override the error message so we don't leak any internal db info
|
1573
1580
|
err.message = 'Database error';
|
1574
1581
|
throw err;
|
@@ -1582,7 +1589,7 @@ const runRequest = async (
|
|
1582
1589
|
err instanceof TypeError ||
|
1583
1590
|
err instanceof URIError
|
1584
1591
|
) {
|
1585
|
-
|
1592
|
+
log.error(err);
|
1586
1593
|
throw new InternalRequestError();
|
1587
1594
|
}
|
1588
1595
|
throw err;
|
@@ -1742,7 +1749,7 @@ const runQuery = async (
|
|
1742
1749
|
);
|
1743
1750
|
|
1744
1751
|
if (env.DEBUG) {
|
1745
|
-
|
1752
|
+
logger[vocabulary].log(query, values);
|
1746
1753
|
}
|
1747
1754
|
|
1748
1755
|
// We only add the returning clause if it's been requested and `affectedIds` hasn't been populated yet
|
@@ -1850,7 +1857,7 @@ const respondPost = async (
|
|
1850
1857
|
id,
|
1851
1858
|
);
|
1852
1859
|
if (env.DEBUG) {
|
1853
|
-
|
1860
|
+
logger[vocab].log('Insert ID: ', request.resourceName, id);
|
1854
1861
|
}
|
1855
1862
|
|
1856
1863
|
let result: AnyObject = { d: [{ id }] };
|
@@ -421,7 +421,7 @@ export const translateUri = <
|
|
421
421
|
request.values = new Proxy(request.values, {
|
422
422
|
set: (obj: ODataRequest['values'], prop: string, value) => {
|
423
423
|
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
|
424
|
-
sbvrUtils.
|
424
|
+
sbvrUtils.logger[request.vocabulary].warn(
|
425
425
|
`Assigning a new request.values property '${prop}' however it will be ignored`,
|
426
426
|
);
|
427
427
|
}
|