@balena/pinejs 16.2.0-build-joshbwlng-tasks-7478568100de4cf0789edd97865827cae9041667-1 → 16.2.0-build-joshbwlng-tasks-8552b344881d795e9ce7a999cec89f98f20902b7-2

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.
@@ -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.api[request.vocabulary].logger.error(
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.api.Auth.logger.error('Error loading user permissions', err);
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.api.Auth.logger.error('Error loading api key permissions', err);
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.api.Auth.logger.error('Error checking permissions', err);
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 logger[key] === 'function' &&
686
+ typeof log[key] === 'function' &&
687
687
  !(model.logging?.[key] ?? defaultSetting)
688
688
  ) {
689
- logger[key] = _.noop;
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 { logger } = api[vocab];
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
- logger.error('Error parsing rule', rule, e);
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
- logger.error('Error compiling rule', rule, e);
887
+ log.error('Error compiling rule', rule, e);
887
888
  throw new Error(`Error compiling rule '${rule}': ${e}`);
888
889
  }
889
890
 
@@ -1023,12 +1024,18 @@ export class PinejsClient extends PinejsClientCore {
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
- api[vocabulary].logger.log('Parsing', req.method, req.url);
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 { logger } = api[request.vocabulary];
1547
+ const log = logger[request.vocabulary];
1541
1548
 
1542
1549
  if (env.DEBUG) {
1543
- logger.log('Running', req.method, req.url);
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
- logger.error(err);
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
- logger.error(err);
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
- api[vocabulary].logger.log(query, values);
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
- api[vocab].logger.log('Insert ID: ', request.resourceName, id);
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.api[request.vocabulary].logger.warn(
424
+ sbvrUtils.logger[request.vocabulary].warn(
425
425
  `Assigning a new request.values property '${prop}' however it will be ignored`,
426
426
  );
427
427
  }
@@ -51,7 +51,7 @@ type WebResourcesDbResponse = {
51
51
 
52
52
  const getLogger = (vocab?: string): Console => {
53
53
  if (vocab) {
54
- return sbvrUtils.api[vocab]?.logger ?? console;
54
+ return sbvrUtils.logger[vocab] ?? console;
55
55
  }
56
56
  return console;
57
57
  };