@balena/pinejs 16.1.5-build-update-deps-520cd49d9b5a982fe4e8ab844931d69d27627715-1 → 16.1.6-build-logger-dict-66a8302f9e89cf553fe4e35705b253be7e990841-1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  };
@@ -676,18 +676,19 @@ export const executeModels = async (
676
676
  api[apiRoot].logger = { ...console };
677
677
  if (model.logging != null) {
678
678
  const defaultSetting = model.logging?.default ?? true;
679
- const { logger } = api[apiRoot];
679
+ const { logger: log } = api[apiRoot];
680
680
  for (const k of Object.keys(model.logging)) {
681
681
  const key = k as keyof Console;
682
682
  if (
683
683
  key !== 'Console' &&
684
- typeof logger[key] === 'function' &&
684
+ typeof log[key] === 'function' &&
685
685
  !(model.logging?.[key] ?? defaultSetting)
686
686
  ) {
687
- logger[key] = _.noop;
687
+ log[key] = _.noop;
688
688
  }
689
689
  }
690
690
  }
691
+ logger[apiRoot] = api[apiRoot].logger;
691
692
  return compiledModel;
692
693
  // Only update the dev models once all models have finished executing.
693
694
  }),
@@ -856,7 +857,7 @@ export const runRule = (() => {
856
857
  translator.addTypes(sbvrTypes);
857
858
  return async (vocab: string, rule: string) => {
858
859
  const seModel = models[vocab].se;
859
- const { logger } = api[vocab];
860
+ const log = logger[vocab];
860
861
  let lfModel: LFModel;
861
862
  let slfModel: LFModel;
862
863
  let abstractSqlModel: AbstractSQLCompiler.AbstractSqlModel;
@@ -867,7 +868,7 @@ export const runRule = (() => {
867
868
  'Process',
868
869
  );
869
870
  } catch (e) {
870
- logger.error('Error parsing rule', rule, e);
871
+ log.error('Error parsing rule', rule, e);
871
872
  throw new Error(`Error parsing rule'${rule}': ${e}`);
872
873
  }
873
874
 
@@ -881,7 +882,7 @@ export const runRule = (() => {
881
882
  translator.reset();
882
883
  abstractSqlModel = translator.match(slfModel, 'Process');
883
884
  } catch (e) {
884
- logger.error('Error compiling rule', rule, e);
885
+ log.error('Error compiling rule', rule, e);
885
886
  throw new Error(`Error compiling rule '${rule}': ${e}`);
886
887
  }
887
888
 
@@ -1021,12 +1022,18 @@ export class PinejsClient extends PinejsClientCore {
1021
1022
  }
1022
1023
  }
1023
1024
 
1025
+ /**
1026
+ * @deprecated Use `logger[vocab]` instead of `api[vocab].logger`
1027
+ */
1024
1028
  export type LoggingClient = PinejsClient & {
1025
1029
  logger: Console;
1026
1030
  };
1027
1031
  export const api: {
1028
1032
  [vocab: string]: LoggingClient;
1029
1033
  } = {};
1034
+ export const logger: {
1035
+ [vocab: string]: Console;
1036
+ } = {};
1030
1037
 
1031
1038
  // We default to guest only permissions if no req object is passed in
1032
1039
  export const runURI = async (
@@ -1224,7 +1231,7 @@ export const getModel = (vocabulary: string) => {
1224
1231
 
1225
1232
  const runODataRequest = (req: Express.Request, vocabulary: string) => {
1226
1233
  if (env.DEBUG) {
1227
- api[vocabulary].logger.log('Parsing', req.method, req.url);
1234
+ logger[vocabulary].log('Parsing', req.method, req.url);
1228
1235
  }
1229
1236
 
1230
1237
  // Get the hooks for the current method/vocabulary as we know it,
@@ -1535,10 +1542,10 @@ const runRequest = async (
1535
1542
  tx: Db.Tx,
1536
1543
  request: uriParser.ODataRequest,
1537
1544
  ): Promise<Response> => {
1538
- const { logger } = api[request.vocabulary];
1545
+ const log = logger[request.vocabulary];
1539
1546
 
1540
1547
  if (env.DEBUG) {
1541
- logger.log('Running', req.method, req.url);
1548
+ log.log('Running', req.method, req.url);
1542
1549
  }
1543
1550
  let result: Db.Result | number | undefined;
1544
1551
 
@@ -1566,7 +1573,7 @@ const runRequest = async (
1566
1573
  } catch (err: any) {
1567
1574
  if (err instanceof db.DatabaseError) {
1568
1575
  prettifyConstraintError(err, request);
1569
- logger.error(err);
1576
+ log.error(err);
1570
1577
  // Override the error message so we don't leak any internal db info
1571
1578
  err.message = 'Database error';
1572
1579
  throw err;
@@ -1580,7 +1587,7 @@ const runRequest = async (
1580
1587
  err instanceof TypeError ||
1581
1588
  err instanceof URIError
1582
1589
  ) {
1583
- logger.error(err);
1590
+ log.error(err);
1584
1591
  throw new InternalRequestError();
1585
1592
  }
1586
1593
  throw err;
@@ -1740,7 +1747,7 @@ const runQuery = async (
1740
1747
  );
1741
1748
 
1742
1749
  if (env.DEBUG) {
1743
- api[vocabulary].logger.log(query, values);
1750
+ logger[vocabulary].log(query, values);
1744
1751
  }
1745
1752
 
1746
1753
  // We only add the returning clause if it's been requested and `affectedIds` hasn't been populated yet
@@ -1848,7 +1855,7 @@ const respondPost = async (
1848
1855
  id,
1849
1856
  );
1850
1857
  if (env.DEBUG) {
1851
- api[vocab].logger.log('Insert ID: ', request.resourceName, id);
1858
+ logger[vocab].log('Insert ID: ', request.resourceName, id);
1852
1859
  }
1853
1860
 
1854
1861
  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
  };