@balena/pinejs 19.7.0 → 19.7.1-build-esm-prep-83eacbb700f89dd2730c9a879b96a456503a1d2a-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.
Files changed (45) hide show
  1. package/.pinejs-cache.json +1 -1
  2. package/.versionbot/CHANGELOG.yml +45 -1
  3. package/CHANGELOG.md +9 -1
  4. package/VERSION +1 -1
  5. package/out/bin/utils.d.ts +1 -1
  6. package/out/bin/utils.js +2 -1
  7. package/out/bin/utils.js.map +1 -1
  8. package/out/config-loader/env.d.ts +2 -1
  9. package/out/config-loader/env.js +38 -3
  10. package/out/config-loader/env.js.map +1 -1
  11. package/out/data-server/sbvr-server.d.ts +16 -2
  12. package/out/data-server/sbvr-server.js.map +1 -1
  13. package/out/extended-sbvr-parser/extended-sbvr-parser.js +2 -2
  14. package/out/extended-sbvr-parser/extended-sbvr-parser.js.map +1 -1
  15. package/out/migrator/async.js +1 -1
  16. package/out/migrator/async.js.map +1 -1
  17. package/out/odata-metadata/odata-metadata-generator.d.ts +1 -1
  18. package/out/odata-metadata/odata-metadata-generator.js +2 -2
  19. package/out/odata-metadata/odata-metadata-generator.js.map +1 -1
  20. package/out/passport-pinejs/passport-pinejs.js +3 -3
  21. package/out/passport-pinejs/passport-pinejs.js.map +1 -1
  22. package/out/sbvr-api/permissions.d.ts +7 -3
  23. package/out/sbvr-api/permissions.js +8 -8
  24. package/out/sbvr-api/permissions.js.map +1 -1
  25. package/out/sbvr-api/sbvr-utils.js +5 -5
  26. package/out/sbvr-api/sbvr-utils.js.map +1 -1
  27. package/out/sbvr-api/uri-parser.js +2 -2
  28. package/out/sbvr-api/uri-parser.js.map +1 -1
  29. package/out/server-glue/module.js +4 -4
  30. package/out/server-glue/module.js.map +1 -1
  31. package/out/tasks/index.js +1 -1
  32. package/out/tasks/index.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/bin/utils.ts +1 -3
  35. package/src/config-loader/env.ts +6 -1
  36. package/src/data-server/sbvr-server.ts +3 -3
  37. package/src/extended-sbvr-parser/extended-sbvr-parser.ts +1 -1
  38. package/src/migrator/async.ts +7 -7
  39. package/src/odata-metadata/odata-metadata-generator.ts +1 -3
  40. package/src/passport-pinejs/passport-pinejs.ts +3 -6
  41. package/src/sbvr-api/permissions.ts +4 -4
  42. package/src/sbvr-api/sbvr-utils.ts +3 -3
  43. package/src/sbvr-api/uri-parser.ts +1 -1
  44. package/src/server-glue/module.ts +4 -5
  45. package/src/tasks/index.ts +1 -1
package/src/bin/utils.ts CHANGED
@@ -10,9 +10,7 @@ import * as fs from 'fs';
10
10
  import * as path from 'path';
11
11
  import '../server-glue/sbvr-loader';
12
12
 
13
- export const { version } = JSON.parse(
14
- fs.readFileSync(require.resolve('../../package.json'), 'utf8'),
15
- );
13
+ export { version } from '../config-loader/env';
16
14
 
17
15
  export const writeAll = (output: string, outputFile?: string): void => {
18
16
  if (outputFile) {
@@ -1,3 +1,8 @@
1
+ import * as fs from 'fs';
2
+ export const { version } = JSON.parse(
3
+ fs.readFileSync(require.resolve('../../package.json'), 'utf8'),
4
+ );
5
+
1
6
  const { PINEJS_DEBUG } = process.env;
2
7
  if (![undefined, '', '0', '1'].includes(PINEJS_DEBUG)) {
3
8
  throw new Error(`Invalid value for PINEJS_DEBUG '${PINEJS_DEBUG}'`);
@@ -51,7 +56,7 @@ export const cache = {
51
56
 
52
57
  import { boolVar, intVar } from '@balena/env-parsing';
53
58
  import memoize from 'memoizee';
54
- import memoizeWeak = require('memoizee/weak');
59
+ import memoizeWeak from 'memoizee/weak';
55
60
  export const createCache = <T extends (...args: any[]) => any>(
56
61
  cacheName: keyof typeof cache,
57
62
  fn: T,
@@ -207,7 +207,7 @@ export const setup: SetupFunction = async (app, sbvrUtils, db) => {
207
207
  console.warn(
208
208
  'DEL /cleardb is very destructive and should really be followed by a full restart/reload.',
209
209
  );
210
- await sbvrUtils.executeModels(tx, exports.config.models);
210
+ await sbvrUtils.executeModels(tx, config.models);
211
211
  await setupModels(tx);
212
212
  });
213
213
  res.status(200).end();
@@ -377,7 +377,7 @@ export const setup: SetupFunction = async (app, sbvrUtils, db) => {
377
377
  await db.transaction(setupModels);
378
378
  };
379
379
 
380
- export const config: Config = {
380
+ export const config = {
381
381
  models: [
382
382
  {
383
383
  modelName: 'ui',
@@ -409,4 +409,4 @@ ADD COLUMN IF NOT EXISTS "modified at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT N
409
409
  },
410
410
  },
411
411
  ],
412
- };
412
+ } satisfies Config;
@@ -2,7 +2,7 @@ import { SBVRParser } from '@balena/sbvr-parser';
2
2
  // eslint-disable-next-line @typescript-eslint/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
- import { version } from '@balena/sbvr-parser/package.json';
5
+ import { version } from '../config-loader/env';
6
6
 
7
7
  export const ExtendedSBVRParser = SBVRParser._extend({
8
8
  initialize() {
@@ -27,13 +27,6 @@ import {
27
27
  } from './utils';
28
28
  import { booleanToEnabledString } from '../config-loader/env';
29
29
 
30
- // log the startup condition of the async migration
31
- (sbvrUtils.logger?.migrations?.info ?? console.info)(
32
- `Async migration execution is ${booleanToEnabledString(
33
- migratorEnv.asyncMigrationIsEnabled,
34
- )}`,
35
- );
36
-
37
30
  export const run = async (tx: Tx, model: ApiRootModel): Promise<void> => {
38
31
  const { migrations } = model;
39
32
  if (migrations == null || _.isEmpty(migrations)) {
@@ -188,6 +181,13 @@ const $run = async (
188
181
  // created. When the transaction fails, the setup async migration entries in the DB will be
189
182
  // rolled back automatically.
190
183
  setupTx.on('end', () => {
184
+ // log the startup condition of the async migration
185
+ (sbvrUtils.logger?.migrations?.info ?? console.info)(
186
+ `Async migration execution is ${booleanToEnabledString(
187
+ migratorEnv.asyncMigrationIsEnabled,
188
+ )}`,
189
+ );
190
+
191
191
  for (const {
192
192
  key,
193
193
  initMigrationState,
@@ -4,9 +4,7 @@ import type {
4
4
  } from '@balena/abstract-sql-compiler';
5
5
 
6
6
  import sbvrTypes, { type SbvrType } from '@balena/sbvr-types';
7
-
8
- // eslint-disable-next-line @typescript-eslint/no-var-requires
9
- const { version }: { version: string } = require('../../package.json');
7
+ import { version } from '../config-loader/env';
10
8
 
11
9
  const getResourceName = (resourceName: string): string =>
12
10
  resourceName
@@ -33,16 +33,13 @@ export const checkPassword: PassportLocal.VerifyFunction = async (
33
33
  }
34
34
  };
35
35
 
36
- const setup: ConfigLoader.SetupFunction = (app: Express.Application) => {
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
- const passport: typeof Passport = require('passport');
38
+ const { default: passport } = await import('passport');
40
39
  app.use(passport.initialize());
41
40
  app.use(passport.session());
42
41
 
43
- const {
44
- Strategy: LocalStrategy, // eslint-disable-next-line @typescript-eslint/no-var-requires
45
- }: typeof PassportLocal = require('passport-local');
42
+ const { Strategy: LocalStrategy } = await import('passport-local');
46
43
 
47
44
  passport.serializeUser((user, done) => {
48
45
  done(null, user);
@@ -51,7 +51,7 @@ import {
51
51
  metadataEndpoints,
52
52
  type ODataRequest,
53
53
  } from './uri-parser';
54
- import memoizeWeak = require('memoizee/weak');
54
+ import memoizeWeak from 'memoizee/weak';
55
55
  import type { Config } from '../config-loader/config-loader';
56
56
  import type { ODataOptions } from 'pinejs-client-core';
57
57
  import type { Permission } from './user';
@@ -1787,7 +1787,7 @@ declare module './sbvr-utils' {
1787
1787
  const authModelConfig = {
1788
1788
  apiRoot: 'Auth',
1789
1789
  modelText: userModel,
1790
- customServerCode: exports,
1790
+ customServerCode: { setup },
1791
1791
  migrations: {
1792
1792
  '11.0.0-modified-at': `
1793
1793
  ALTER TABLE "actor"
@@ -1826,7 +1826,7 @@ const authModelConfig = {
1826
1826
  export const config = {
1827
1827
  models: [authModelConfig],
1828
1828
  } satisfies Config;
1829
- export const setup = () => {
1829
+ export function setup() {
1830
1830
  addHook('all', 'all', 'all', {
1831
1831
  sideEffects: false,
1832
1832
  readOnlyTx: true,
@@ -1924,4 +1924,4 @@ export const setup = () => {
1924
1924
  id: request.values.actor,
1925
1925
  }),
1926
1926
  });
1927
- };
1927
+ }
@@ -83,7 +83,7 @@ export {
83
83
  addSideEffectHook,
84
84
  } from './hooks';
85
85
 
86
- import memoizeWeak = require('memoizee/weak');
86
+ import memoizeWeak from 'memoizee/weak';
87
87
  import * as controlFlow from './control-flow';
88
88
 
89
89
  export let db = undefined as any as Db.Database;
@@ -2069,7 +2069,7 @@ export const setup = async (
2069
2069
  _app: Express.Application,
2070
2070
  $db: Db.Database,
2071
2071
  ): Promise<void> => {
2072
- exports.db = db = $db;
2072
+ db = $db;
2073
2073
  try {
2074
2074
  await db.transaction(async (tx) => {
2075
2075
  await executeStandardModels(tx);
@@ -2092,7 +2092,7 @@ export const postSetup = async (
2092
2092
  _app: Express.Application,
2093
2093
  $db: Db.Database,
2094
2094
  ): Promise<void> => {
2095
- exports.db = db = $db;
2095
+ db = $db;
2096
2096
  try {
2097
2097
  await db.transaction(async (tx) => {
2098
2098
  await postExecuteModels(tx);
@@ -13,7 +13,7 @@ import * as ODataParser from '@balena/odata-parser';
13
13
  export const SyntaxError = ODataParser.SyntaxError;
14
14
  import { OData2AbstractSQL } from '@balena/odata-to-abstract-sql';
15
15
  import _ from 'lodash';
16
- import memoizeWeak = require('memoizee/weak');
16
+ import memoizeWeak from 'memoizee/weak';
17
17
 
18
18
  export { BadRequestError, ParsingError, TranslationError } from './errors';
19
19
  import deepFreeze from 'deep-freeze';
@@ -70,13 +70,12 @@ export const init = async <T extends string>(
70
70
  const promises: Array<Promise<void>> = [];
71
71
  if (process.env.SBVR_SERVER_ENABLED) {
72
72
  const sbvrServer = await import('../data-server/sbvr-server.js');
73
- // eslint-disable-next-line @typescript-eslint/no-var-requires
74
- const transactions = require('../http-transactions/transactions');
73
+ const transactions = await import('../http-transactions/transactions.js');
75
74
  promises.push(cfgLoader.loadConfig(sbvrServer.config));
76
75
  promises.push(
77
- cfgLoader
78
- .loadConfig(transactions.config)
79
- .then(() => transactions.addModelHooks('data')),
76
+ cfgLoader.loadConfig(transactions.config).then(() => {
77
+ transactions.addModelHooks('data');
78
+ }),
80
79
  );
81
80
  }
82
81
  if (!process.env.CONFIG_LOADER_DISABLED) {
@@ -37,7 +37,7 @@ export const config: ConfigLoader.Config = {
37
37
  modelName: apiRoot,
38
38
  apiRoot,
39
39
  modelText,
40
- customServerCode: exports,
40
+ customServerCode: { setup },
41
41
  initSql,
42
42
  },
43
43
  ],