@balena/pinejs 19.7.1 → 19.7.2-build-esm-ce2a147ed7533c40f456b27f17ac4e559a0f9da8-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 (170) hide show
  1. package/.pinejs-cache.json +1 -1
  2. package/.versionbot/CHANGELOG.yml +21 -1
  3. package/CHANGELOG.md +5 -0
  4. package/{Gruntfile.ts → Gruntfile.cts} +9 -22
  5. package/VERSION +1 -1
  6. package/bin/abstract-sql-compiler.js +1 -1
  7. package/bin/odata-compiler.js +1 -1
  8. package/bin/sbvr-compiler.js +1 -1
  9. package/build/{browser.ts → browser.cts} +1 -1
  10. package/build/{config.ts → config.cts} +5 -1
  11. package/build/{module.ts → module.cts} +1 -1
  12. package/build/{server.ts → server.cts} +1 -1
  13. package/out/bin/abstract-sql-compiler.js +17 -19
  14. package/out/bin/abstract-sql-compiler.js.map +1 -1
  15. package/out/bin/odata-compiler.js +19 -21
  16. package/out/bin/odata-compiler.js.map +1 -1
  17. package/out/bin/sbvr-compiler.js +19 -54
  18. package/out/bin/sbvr-compiler.js.map +1 -1
  19. package/out/bin/utils.d.ts +3 -3
  20. package/out/bin/utils.js +16 -53
  21. package/out/bin/utils.js.map +1 -1
  22. package/out/config-loader/config-loader.d.ts +6 -6
  23. package/out/config-loader/config-loader.js +23 -63
  24. package/out/config-loader/config-loader.js.map +1 -1
  25. package/out/config-loader/env.d.ts +1 -1
  26. package/out/config-loader/env.js +24 -66
  27. package/out/config-loader/env.js.map +1 -1
  28. package/out/data-server/sbvr-server.d.ts +3 -3
  29. package/out/data-server/sbvr-server.js +5 -42
  30. package/out/data-server/sbvr-server.js.map +1 -1
  31. package/out/database-layer/db.d.ts +3 -3
  32. package/out/database-layer/db.js +37 -83
  33. package/out/database-layer/db.js.map +1 -1
  34. package/out/express-emulator/express.js.map +1 -1
  35. package/out/extended-sbvr-parser/extended-sbvr-parser.js +8 -11
  36. package/out/extended-sbvr-parser/extended-sbvr-parser.js.map +1 -1
  37. package/out/http-transactions/transactions.d.ts +2 -2
  38. package/out/http-transactions/transactions.js +4 -4
  39. package/out/http-transactions/transactions.js.map +1 -1
  40. package/out/migrator/async.d.ts +2 -2
  41. package/out/migrator/async.js +20 -60
  42. package/out/migrator/async.js.map +1 -1
  43. package/out/migrator/migrations.js +1 -2
  44. package/out/migrator/sync.d.ts +6 -6
  45. package/out/migrator/sync.js +20 -61
  46. package/out/migrator/sync.js.map +1 -1
  47. package/out/migrator/utils.d.ts +4 -4
  48. package/out/migrator/utils.js +42 -97
  49. package/out/migrator/utils.js.map +1 -1
  50. package/out/odata-metadata/odata-metadata-generator.js +7 -14
  51. package/out/odata-metadata/odata-metadata-generator.js.map +1 -1
  52. package/out/passport-pinejs/mount-login-router.d.ts +1 -1
  53. package/out/passport-pinejs/mount-login-router.js +4 -41
  54. package/out/passport-pinejs/mount-login-router.js.map +1 -1
  55. package/out/passport-pinejs/passport-pinejs.d.ts +1 -1
  56. package/out/passport-pinejs/passport-pinejs.js +11 -46
  57. package/out/passport-pinejs/passport-pinejs.js.map +1 -1
  58. package/out/pinejs-session-store/pinejs-session-store.d.ts +1 -1
  59. package/out/pinejs-session-store/pinejs-session-store.js +11 -48
  60. package/out/pinejs-session-store/pinejs-session-store.js.map +1 -1
  61. package/out/sbvr-api/abstract-sql.d.ts +2 -2
  62. package/out/sbvr-api/abstract-sql.js +22 -65
  63. package/out/sbvr-api/abstract-sql.js.map +1 -1
  64. package/out/sbvr-api/cached-compile.js +8 -15
  65. package/out/sbvr-api/cached-compile.js.map +1 -1
  66. package/out/sbvr-api/common-types.js +1 -2
  67. package/out/sbvr-api/control-flow.d.ts +1 -1
  68. package/out/sbvr-api/control-flow.js +12 -25
  69. package/out/sbvr-api/control-flow.js.map +1 -1
  70. package/out/sbvr-api/dev.js +1 -2
  71. package/out/sbvr-api/errors.d.ts +1 -1
  72. package/out/sbvr-api/errors.js +47 -95
  73. package/out/sbvr-api/errors.js.map +1 -1
  74. package/out/sbvr-api/express-extension.d.ts +2 -2
  75. package/out/sbvr-api/express-extension.js +1 -2
  76. package/out/sbvr-api/hooks.d.ts +4 -4
  77. package/out/sbvr-api/hooks.js +23 -35
  78. package/out/sbvr-api/hooks.js.map +1 -1
  79. package/out/sbvr-api/odata-response.d.ts +2 -2
  80. package/out/sbvr-api/odata-response.js +19 -29
  81. package/out/sbvr-api/odata-response.js.map +1 -1
  82. package/out/sbvr-api/permissions.d.ts +8 -8
  83. package/out/sbvr-api/permissions.js +106 -159
  84. package/out/sbvr-api/permissions.js.map +1 -1
  85. package/out/sbvr-api/sbvr-utils.d.ts +38 -16
  86. package/out/sbvr-api/sbvr-utils.js +222 -285
  87. package/out/sbvr-api/sbvr-utils.js.map +1 -1
  88. package/out/sbvr-api/translations.d.ts +1 -1
  89. package/out/sbvr-api/translations.js +10 -17
  90. package/out/sbvr-api/translations.js.map +1 -1
  91. package/out/sbvr-api/uri-parser.d.ts +6 -6
  92. package/out/sbvr-api/uri-parser.js +39 -84
  93. package/out/sbvr-api/uri-parser.js.map +1 -1
  94. package/out/sbvr-api/user.js +1 -2
  95. package/out/server-glue/global-ext.d.ts +0 -3
  96. package/out/server-glue/module.d.ts +15 -15
  97. package/out/server-glue/module.js +20 -59
  98. package/out/server-glue/module.js.map +1 -1
  99. package/out/server-glue/sbvr-loader.d.ts +2 -1
  100. package/out/server-glue/sbvr-loader.js +4 -11
  101. package/out/server-glue/sbvr-loader.js.map +1 -1
  102. package/out/server-glue/server.d.ts +2 -2
  103. package/out/server-glue/server.js +17 -59
  104. package/out/server-glue/server.js.map +1 -1
  105. package/out/tasks/common.d.ts +1 -1
  106. package/out/tasks/common.js +3 -9
  107. package/out/tasks/common.js.map +1 -1
  108. package/out/tasks/index.d.ts +8 -8
  109. package/out/tasks/index.js +25 -63
  110. package/out/tasks/index.js.map +1 -1
  111. package/out/tasks/tasks.js +1 -2
  112. package/out/tasks/worker.d.ts +3 -3
  113. package/out/tasks/worker.js +14 -51
  114. package/out/tasks/worker.js.map +1 -1
  115. package/out/webresource-handler/handlers/NoopHandler.d.ts +1 -1
  116. package/out/webresource-handler/handlers/NoopHandler.js +1 -5
  117. package/out/webresource-handler/handlers/NoopHandler.js.map +1 -1
  118. package/out/webresource-handler/handlers/S3Handler.d.ts +1 -1
  119. package/out/webresource-handler/handlers/S3Handler.js +17 -24
  120. package/out/webresource-handler/handlers/S3Handler.js.map +1 -1
  121. package/out/webresource-handler/handlers/index.d.ts +2 -2
  122. package/out/webresource-handler/handlers/index.js +2 -18
  123. package/out/webresource-handler/handlers/index.js.map +1 -1
  124. package/out/webresource-handler/index.d.ts +1 -1
  125. package/out/webresource-handler/index.js +35 -85
  126. package/out/webresource-handler/index.js.map +1 -1
  127. package/package.json +10 -10
  128. package/src/bin/abstract-sql-compiler.ts +3 -3
  129. package/src/bin/odata-compiler.ts +3 -3
  130. package/src/bin/sbvr-compiler.ts +2 -2
  131. package/src/bin/utils.ts +20 -15
  132. package/src/config-loader/config-loader.ts +11 -11
  133. package/src/config-loader/env.ts +3 -3
  134. package/src/data-server/sbvr-server.ts +4 -4
  135. package/src/database-layer/db.ts +18 -11
  136. package/src/extended-sbvr-parser/extended-sbvr-parser.ts +5 -5
  137. package/src/http-transactions/transactions.js +4 -4
  138. package/src/migrator/async.ts +5 -5
  139. package/src/migrator/sync.ts +8 -8
  140. package/src/migrator/utils.ts +7 -7
  141. package/src/odata-metadata/odata-metadata-generator.ts +3 -2
  142. package/src/passport-pinejs/mount-login-router.ts +3 -3
  143. package/src/passport-pinejs/passport-pinejs.ts +3 -3
  144. package/src/pinejs-session-store/pinejs-session-store.ts +4 -4
  145. package/src/sbvr-api/abstract-sql.ts +5 -5
  146. package/src/sbvr-api/cached-compile.ts +1 -1
  147. package/src/sbvr-api/control-flow.ts +1 -1
  148. package/src/sbvr-api/errors.ts +1 -1
  149. package/src/sbvr-api/express-extension.ts +2 -2
  150. package/src/sbvr-api/hooks.ts +5 -5
  151. package/src/sbvr-api/odata-response.ts +8 -4
  152. package/src/sbvr-api/permissions.ts +17 -17
  153. package/src/sbvr-api/sbvr-utils.ts +37 -31
  154. package/src/sbvr-api/translations.ts +1 -1
  155. package/src/sbvr-api/uri-parser.ts +9 -9
  156. package/src/server-glue/global-ext.d.ts +0 -3
  157. package/src/server-glue/module.ts +19 -19
  158. package/src/server-glue/sbvr-loader.ts +15 -27
  159. package/src/server-glue/server.ts +13 -24
  160. package/src/tasks/common.ts +1 -1
  161. package/src/tasks/index.ts +14 -14
  162. package/src/tasks/worker.ts +8 -8
  163. package/src/webresource-handler/handlers/NoopHandler.ts +5 -1
  164. package/src/webresource-handler/handlers/S3Handler.ts +1 -1
  165. package/src/webresource-handler/handlers/index.ts +2 -2
  166. package/src/webresource-handler/index.ts +8 -8
  167. package/tsconfig.dev.json +4 -2
  168. package/tsconfig.json +1 -1
  169. package/typings/lf-to-abstract-sql.d.ts +2 -2
  170. package/typings/memoizee.d.ts +1 -1
@@ -1,4 +1,4 @@
1
- import type AuthModel from './user';
1
+ import type AuthModel from './user.js';
2
2
  import type {
3
3
  AbstractSqlModel,
4
4
  AbstractSqlQuery,
@@ -14,16 +14,16 @@ import type {
14
14
  SelectNode,
15
15
  SelectQueryNode,
16
16
  } from '@balena/abstract-sql-compiler';
17
- import './express-extension';
17
+ import './express-extension.js';
18
18
  import type * as Express from 'express';
19
19
  import type {
20
20
  ODataBinds,
21
21
  ODataQuery,
22
22
  SupportedMethod,
23
23
  } from '@balena/odata-parser';
24
- import type { Tx } from '../database-layer/db';
25
- import type { ApiKey, User } from '../sbvr-api/sbvr-utils';
26
- import type { AnyObject, Dictionary } from './common-types';
24
+ import type { Tx } from '../database-layer/db.js';
25
+ import type { ApiKey, User } from '../sbvr-api/sbvr-utils.js';
26
+ import type { AnyObject, Dictionary } from './common-types.js';
27
27
 
28
28
  import {
29
29
  isBindReference,
@@ -36,28 +36,28 @@ import * as ODataParser from '@balena/odata-parser';
36
36
 
37
37
  import _ from 'lodash';
38
38
  import memoize from 'memoizee';
39
- import * as randomstring from 'randomstring';
40
- import * as env from '../config-loader/env';
41
- import * as sbvrUtils from '../sbvr-api/sbvr-utils';
42
- import { type HookReq, addPureHook, addHook } from './hooks';
39
+ import randomstring from 'randomstring';
40
+ import * as env from '../config-loader/env.js';
41
+ import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
42
+ import { type HookReq, addPureHook, addHook } from './hooks.js';
43
43
  import {
44
44
  BadRequestError,
45
45
  PermissionError,
46
46
  PermissionParsingError,
47
- } from './errors';
47
+ } from './errors.js';
48
48
  import {
49
49
  memoizedGetOData2AbstractSQL,
50
50
  memoizedParseOdata,
51
51
  metadataEndpoints,
52
52
  type ODataRequest,
53
- } from './uri-parser';
54
- import memoizeWeak from 'memoizee/weak';
55
- import type { Config } from '../config-loader/config-loader';
53
+ } from './uri-parser.js';
54
+ import memoizeWeak from 'memoizee/weak.js';
55
+ import type { Config } from '../config-loader/config-loader.js';
56
56
  import type { ODataOptions } from 'pinejs-client-core';
57
- import type { Permission } from './user';
58
- import { requireSBVR } from '../server-glue/sbvr-loader';
57
+ import type { Permission } from './user.js';
58
+ import { importSBVR } from '../server-glue/sbvr-loader.js';
59
59
 
60
- const userModel = requireSBVR('./user.sbvr', require);
60
+ const userModel = await importSBVR('./user.sbvr', import.meta);
61
61
 
62
62
  const DEFAULT_ACTOR_BIND = '@__ACTOR_ID';
63
63
  const DEFAULT_ACTOR_BIND_REGEX = new RegExp(
@@ -1779,7 +1779,7 @@ export const addPermissions = async (
1779
1779
  }
1780
1780
  };
1781
1781
 
1782
- declare module './sbvr-utils' {
1782
+ declare module './sbvr-utils.js' {
1783
1783
  export interface API {
1784
1784
  [authModelConfig.apiRoot]: PinejsClient<AuthModel>;
1785
1785
  }
@@ -1,7 +1,7 @@
1
1
  import type * as Express from 'express';
2
- import type * as Db from '../database-layer/db';
3
- import type { Model } from '../config-loader/config-loader';
4
- import type { AnyObject, RequiredField } from './common-types';
2
+ import type * as Db from '../database-layer/db.js';
3
+ import type { Model } from '../config-loader/config-loader.js';
4
+ import type { AnyObject, RequiredField } from './common-types.js';
5
5
  import type {
6
6
  PickDeferred,
7
7
  Resource,
@@ -21,12 +21,14 @@ declare global {
21
21
  import _ from 'lodash';
22
22
 
23
23
  import type { TypedError } from 'typed-error';
24
- import { cachedCompile } from './cached-compile';
24
+ import { cachedCompile } from './cached-compile.js';
25
25
 
26
26
  type LFModel = any[];
27
27
  import * as AbstractSQLCompiler from '@balena/abstract-sql-compiler';
28
- import { version as AbstractSQLCompilerVersion } from '@balena/abstract-sql-compiler/package.json';
29
- import * as LF2AbstractSQL from '@balena/lf-to-abstract-sql';
28
+ import AbstractSqlCompilerPackage from '@balena/abstract-sql-compiler/package.json' with { type: 'json' };
29
+ const { version: AbstractSQLCompilerVersion } = AbstractSqlCompilerPackage;
30
+
31
+ import LF2AbstractSQL from '@balena/lf-to-abstract-sql';
30
32
 
31
33
  import {
32
34
  type ODataBinds,
@@ -34,21 +36,22 @@ import {
34
36
  sqlNameToODataName,
35
37
  type SupportedMethod,
36
38
  } from '@balena/odata-to-abstract-sql';
37
- import sbvrTypes from '@balena/sbvr-types';
38
- import deepFreeze = require('deep-freeze');
39
+ import $sbvrTypes from '@balena/sbvr-types';
40
+ const { default: sbvrTypes } = $sbvrTypes;
41
+ import deepFreeze from 'deep-freeze';
39
42
  import type { ODataOptions, Params } from 'pinejs-client-core';
40
43
  import { PinejsClientCore, type PromiseResultTypes } from 'pinejs-client-core';
41
44
 
42
- import { ExtendedSBVRParser } from '../extended-sbvr-parser/extended-sbvr-parser';
45
+ import { ExtendedSBVRParser } from '../extended-sbvr-parser/extended-sbvr-parser.js';
43
46
 
44
- import * as asyncMigrator from '../migrator/async';
45
- import * as syncMigrator from '../migrator/sync';
46
- import { generateODataMetadata } from '../odata-metadata/odata-metadata-generator';
47
- import { requireSBVR } from '../server-glue/sbvr-loader';
47
+ import * as asyncMigrator from '../migrator/async.js';
48
+ import * as syncMigrator from '../migrator/sync.js';
49
+ import { generateODataMetadata } from '../odata-metadata/odata-metadata-generator.js';
50
+ import { importSBVR } from '../server-glue/sbvr-loader.js';
48
51
 
49
- import type DevModel from './dev';
50
- const devModel = requireSBVR('./dev.sbvr', require);
51
- import * as permissions from './permissions';
52
+ import type DevModel from './dev.js';
53
+ const devModel = await importSBVR('./dev.sbvr', import.meta);
54
+ import * as permissions from './permissions.js';
52
55
  import {
53
56
  BadRequestError,
54
57
  ConflictError,
@@ -63,9 +66,9 @@ import {
63
66
  statusCodeToError,
64
67
  TranslationError,
65
68
  UnauthorizedError,
66
- } from './errors';
67
- import * as uriParser from './uri-parser';
68
- export type { ODataRequest } from './uri-parser';
69
+ } from './errors.js';
70
+ import * as uriParser from './uri-parser.js';
71
+ export type { ODataRequest } from './uri-parser.js';
69
72
  import {
70
73
  type HookReq,
71
74
  type HookArgs,
@@ -73,7 +76,7 @@ import {
73
76
  getHooks,
74
77
  runHooks,
75
78
  type InstantiatedHooks,
76
- } from './hooks';
79
+ } from './hooks.js';
77
80
  export {
78
81
  type HookReq,
79
82
  type HookArgs,
@@ -81,30 +84,33 @@ export {
81
84
  type Hooks,
82
85
  addPureHook,
83
86
  addSideEffectHook,
84
- } from './hooks';
87
+ } from './hooks.js';
85
88
 
86
- import memoizeWeak from 'memoizee/weak';
87
- import * as controlFlow from './control-flow';
89
+ import memoizeWeak from 'memoizee/weak.js';
90
+ import * as controlFlow from './control-flow.js';
88
91
 
89
92
  export let db = undefined as any as Db.Database;
90
93
 
91
94
  export { sbvrTypes };
92
95
 
93
- import { version as LF2AbstractSQLVersion } from '@balena/lf-to-abstract-sql/package.json';
94
- import { version as sbvrTypesVersion } from '@balena/sbvr-types/package.json';
96
+ import LF2AbstractSQLPackage from '@balena/lf-to-abstract-sql/package.json' with { type: 'json' };
97
+ const { version: LF2AbstractSQLVersion } = LF2AbstractSQLPackage;
98
+ import SbvrTypesPackage from '@balena/sbvr-types/package.json' with { type: 'json' };
99
+ const { version: sbvrTypesVersion } = SbvrTypesPackage;
100
+
95
101
  import {
96
102
  compileRequest,
97
103
  getAndCheckBindValues,
98
104
  isRuleAffected,
99
- } from './abstract-sql';
100
- export { resolveOdataBind } from './abstract-sql';
101
- import * as odataResponse from './odata-response';
102
- import { env } from '../server-glue/module';
103
- import { translateAbstractSqlModel } from './translations';
105
+ } from './abstract-sql.js';
106
+ export { resolveOdataBind } from './abstract-sql.js';
107
+ import * as odataResponse from './odata-response.js';
108
+ import { env } from '../server-glue/module.js';
109
+ import { translateAbstractSqlModel } from './translations.js';
104
110
  import {
105
111
  type MigrationExecutionResult,
106
112
  setExecutedMigrations,
107
- } from '../migrator/utils';
113
+ } from '../migrator/utils.js';
108
114
 
109
115
  const LF2AbstractSQLTranslator = LF2AbstractSQL.createTranslator(sbvrTypes);
110
116
  const LF2AbstractSQLTranslatorVersion = `${LF2AbstractSQLVersion}+${sbvrTypesVersion}`;
@@ -14,7 +14,7 @@ import type {
14
14
  UnknownTypeNodes,
15
15
  NullNode,
16
16
  } from '@balena/abstract-sql-compiler';
17
- import type { Dictionary } from './common-types';
17
+ import type { Dictionary } from './common-types.js';
18
18
 
19
19
  export type AliasValidNodeType =
20
20
  | ReferencedFieldNode
@@ -5,26 +5,26 @@ import type {
5
5
  ODataQuery,
6
6
  SupportedMethod,
7
7
  } from '@balena/odata-parser';
8
- import type { Tx } from '../database-layer/db';
9
- import type { InstantiatedHooks } from './hooks';
10
- import type { AnyObject } from './common-types';
8
+ import type { Tx } from '../database-layer/db.js';
9
+ import type { InstantiatedHooks } from './hooks.js';
10
+ import type { AnyObject } from './common-types.js';
11
11
 
12
- import * as ODataParser from '@balena/odata-parser';
12
+ import 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 from 'memoizee/weak';
16
+ import memoizeWeak from 'memoizee/weak.js';
17
17
 
18
- export { BadRequestError, ParsingError, TranslationError } from './errors';
18
+ export { BadRequestError, ParsingError, TranslationError } from './errors.js';
19
19
  import deepFreeze from 'deep-freeze';
20
- import * as env from '../config-loader/env';
20
+ import * as env from '../config-loader/env.js';
21
21
  import {
22
22
  BadRequestError,
23
23
  ParsingError,
24
24
  PermissionError,
25
25
  TranslationError,
26
- } from './errors';
27
- import * as sbvrUtils from './sbvr-utils';
26
+ } from './errors.js';
27
+ import * as sbvrUtils from './sbvr-utils.js';
28
28
 
29
29
  export type OdataBinds = ODataBinds;
30
30
 
@@ -5,7 +5,4 @@ declare namespace NodeJS {
5
5
  export interface Process {
6
6
  browser: boolean;
7
7
  }
8
- export interface Global {
9
- nodeRequire: NodeRequire;
10
- }
11
8
  }
@@ -1,27 +1,27 @@
1
1
  import type * as Express from 'express';
2
2
 
3
- import './sbvr-loader';
3
+ import './sbvr-loader.js';
4
4
 
5
- import * as dbModule from '../database-layer/db';
6
- import * as configLoader from '../config-loader/config-loader';
7
- import * as migrator from '../migrator/sync';
8
- import type * as migratorUtils from '../migrator/utils';
9
- import * as tasks from '../tasks';
5
+ import * as dbModule from '../database-layer/db.js';
6
+ import * as configLoader from '../config-loader/config-loader.js';
7
+ import * as migrator from '../migrator/sync.js';
8
+ import type * as migratorUtils from '../migrator/utils.js';
9
+ import * as tasks from '../tasks/index.js';
10
10
 
11
- import * as sbvrUtils from '../sbvr-api/sbvr-utils';
12
- import { PINEJS_ADVISORY_LOCK } from '../config-loader/env';
11
+ import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
12
+ import { PINEJS_ADVISORY_LOCK } from '../config-loader/env.js';
13
13
 
14
- export * as dbModule from '../database-layer/db';
15
- export { PinejsSessionStore } from '../pinejs-session-store/pinejs-session-store';
16
- export { mountLoginRouter } from '../passport-pinejs/mount-login-router';
17
- export * as sbvrUtils from '../sbvr-api/sbvr-utils';
18
- export * as permissions from '../sbvr-api/permissions';
19
- export * as errors from '../sbvr-api/errors';
20
- export * as env from '../config-loader/env';
21
- export * as types from '../sbvr-api/common-types';
22
- export * as hooks from '../sbvr-api/hooks';
23
- export * as tasks from '../tasks';
24
- export * as webResourceHandler from '../webresource-handler';
14
+ export * as dbModule from '../database-layer/db.js';
15
+ export { PinejsSessionStore } from '../pinejs-session-store/pinejs-session-store.js';
16
+ export { mountLoginRouter } from '../passport-pinejs/mount-login-router.js';
17
+ export * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
18
+ export * as permissions from '../sbvr-api/permissions.js';
19
+ export * as errors from '../sbvr-api/errors.js';
20
+ export * as env from '../config-loader/env.js';
21
+ export * as types from '../sbvr-api/common-types.js';
22
+ export * as hooks from '../sbvr-api/hooks.js';
23
+ export * as tasks from '../tasks/index.js';
24
+ export * as webResourceHandler from '../webresource-handler/index.js';
25
25
  export type { configLoader as ConfigLoader };
26
26
  export type { migratorUtils as Migrator };
27
27
 
@@ -1,35 +1,23 @@
1
- import type * as Fs from 'fs';
2
-
3
- if (!process.browser) {
4
- if (typeof nodeRequire === 'undefined' || nodeRequire == null) {
5
- // `nodeRequire` is a special variable we use to bypass webpack's resolving of `require`
6
- // statements on build for the cases where we need to always use the nodejs require, eg
7
- // in the config-loader which dynamically loads code at runtime, and for adding custom
8
- // filetype handlers - it works by being replaced with `require` after the webpack build
9
- // finishes.
10
- // In the case of `nodeRequire` being undefined it means we're being run in a nodejs
11
- // environment directly, without a webpack build, and have to manually create it as an
12
- // alias for the nodejs require so that things continue to work.
13
-
14
- // Alias require as nodeRequire for the config-loader hack.
15
- global.nodeRequire = require;
16
- }
17
- // Register a .sbvr loader
18
- // eslint-disable-next-line @typescript-eslint/no-var-requires
19
- const fs: typeof Fs = require('fs');
20
- nodeRequire.extensions['.sbvr'] = (module: NodeModule, filename: string) =>
21
- (module.exports = fs.readFileSync(filename, 'utf8'));
1
+ /**
2
+ *
3
+ * @param filePath The module to load
4
+ * @param parentUrl Use import.meta.url
5
+ * @returns
6
+ */
7
+ export async function loadSBVR(filePath: string, meta: ImportMeta) {
8
+ return await (
9
+ await import('fs')
10
+ ).promises.readFile(new URL(meta.resolve(filePath)), 'utf8');
22
11
  }
23
12
 
24
13
  /**
25
14
  *
26
15
  * @param filePath The module to load
27
- * @param parentUrl Use `require`
16
+ * @param parentUrl Use `import.meta.url`
28
17
  * @returns The sbvr file contents
29
18
  */
30
- export function requireSBVR(filePath: string, require: NodeRequire) {
31
- return (require('fs') as typeof import('fs')).readFileSync(
32
- require.resolve(filePath),
33
- 'utf8',
34
- );
19
+ export async function importSBVR(filePath: string, meta: ImportMeta) {
20
+ return await (
21
+ await import('fs')
22
+ ).promises.readFile(new URL(meta.resolve(filePath)), 'utf8');
35
23
  }
@@ -1,18 +1,9 @@
1
- import type BodyParser from 'body-parser';
2
- import type Compression from 'compression';
3
- import type CookieParser from 'cookie-parser';
4
- import type ExpressSession from 'express-session';
5
- import type MethodOverride from 'method-override';
6
- import type * as Passport from 'passport';
7
- import type * as Path from 'path';
8
- import type ServeStatic from 'serve-static';
1
+ import * as Pinejs from './module.js';
2
+ export { sbvrUtils, PinejsSessionStore } from './module.js';
9
3
 
10
- import * as Pinejs from './module';
11
- export { sbvrUtils, PinejsSessionStore } from './module';
4
+ export { ExtendedSBVRParser } from '../extended-sbvr-parser/extended-sbvr-parser.js';
12
5
 
13
- export { ExtendedSBVRParser } from '../extended-sbvr-parser/extended-sbvr-parser';
14
-
15
- import { mountLoginRouter } from '../passport-pinejs/mount-login-router';
6
+ import { mountLoginRouter } from '../passport-pinejs/mount-login-router.js';
16
7
 
17
8
  import express from 'express';
18
9
 
@@ -27,20 +18,18 @@ switch (app.get('env')) {
27
18
  }
28
19
 
29
20
  if (!process.browser) {
30
- /* eslint-disable @typescript-eslint/no-var-requires */
31
- const passport: typeof Passport = require('passport');
32
- const path: typeof Path = require('path');
33
- const compression: typeof Compression = require('compression');
34
- const serveStatic: typeof ServeStatic = require('serve-static');
35
- const cookieParser: typeof CookieParser = require('cookie-parser');
36
- const bodyParser: typeof BodyParser = require('body-parser');
37
- const methodOverride: typeof MethodOverride = require('method-override');
38
- const expressSession: typeof ExpressSession = require('express-session');
39
- /* eslint-enable @typescript-eslint/no-var-requires */
21
+ const { default: passport } = await import('passport');
22
+ const { default: path } = await import('path');
23
+ const { default: compression } = await import('compression');
24
+ const { default: serveStatic } = await import('serve-static');
25
+ const { default: cookieParser } = await import('cookie-parser');
26
+ const { default: bodyParser } = await import('body-parser');
27
+ const { default: methodOverride } = await import('method-override');
28
+ const { default: expressSession } = await import('express-session');
40
29
 
41
30
  app.use(compression());
42
31
 
43
- const root = process.argv[2] || __dirname;
32
+ const root = process.argv[2] || import.meta.dirname;
44
33
  app.use('/', serveStatic(path.join(root, 'static')));
45
34
 
46
35
  app.use(cookieParser());
@@ -3,4 +3,4 @@ import Ajv from 'ajv';
3
3
  // Root path for the tasks API
4
4
  export const apiRoot = 'tasks';
5
5
 
6
- export const ajv = new Ajv();
6
+ export const ajv = new Ajv.default();
@@ -1,20 +1,20 @@
1
1
  import type { Schema } from 'ajv';
2
- import * as cronParser from 'cron-parser';
3
- import { tasks as tasksEnv } from '../config-loader/env';
4
- import { addPureHook } from '../sbvr-api/hooks';
5
- import * as sbvrUtils from '../sbvr-api/sbvr-utils';
6
- import type { ConfigLoader } from '../server-glue/module';
7
- import { ajv, apiRoot } from './common';
8
- import type { TaskHandler } from './worker';
9
- import { Worker } from './worker';
10
- import type TasksModel from './tasks';
11
- import type { Task } from './tasks';
2
+ import cronParser from 'cron-parser';
3
+ import { tasks as tasksEnv } from '../config-loader/env.js';
4
+ import { addPureHook } from '../sbvr-api/hooks.js';
5
+ import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
6
+ import type { ConfigLoader } from '../server-glue/module.js';
7
+ import { ajv, apiRoot } from './common.js';
8
+ import type { TaskHandler } from './worker.js';
9
+ import { Worker } from './worker.js';
10
+ import type TasksModel from './tasks.js';
11
+ import type { Task } from './tasks.js';
12
12
  import type { FromSchema } from 'json-schema-to-ts';
13
- import { requireSBVR } from '../server-glue/sbvr-loader';
13
+ import { importSBVR } from '../server-glue/sbvr-loader.js';
14
14
 
15
- export type * from './tasks';
15
+ export type * from './tasks.js';
16
16
 
17
- const modelText = requireSBVR('./tasks.sbvr', require);
17
+ const modelText = await importSBVR('./tasks.sbvr', import.meta);
18
18
 
19
19
  // Create index for polling tasks table
20
20
  const initSql = `
@@ -25,7 +25,7 @@ CREATE INDEX IF NOT EXISTS idx_task_poll ON task USING btree (
25
25
  ) WHERE status = 'queued';
26
26
  `;
27
27
 
28
- declare module '../sbvr-api/sbvr-utils' {
28
+ declare module '../sbvr-api/sbvr-utils.js' {
29
29
  export interface API {
30
30
  [apiRoot]: PinejsClient<TasksModel>;
31
31
  }
@@ -1,14 +1,14 @@
1
1
  import type { ValidateFunction } from 'ajv';
2
2
  import { setTimeout } from 'node:timers/promises';
3
3
  import type { AnyObject } from 'pinejs-client-core';
4
- import { tasks as tasksEnv } from '../config-loader/env';
5
- import type * as Db from '../database-layer/db';
6
- import * as permissions from '../sbvr-api/permissions';
7
- import { PinejsClient } from '../sbvr-api/sbvr-utils';
8
- import { sbvrUtils } from '../server-glue/module';
9
- import { ajv } from './common';
10
- import type { Task } from './tasks';
11
- import type TasksModel from './tasks';
4
+ import { tasks as tasksEnv } from '../config-loader/env.js';
5
+ import type * as Db from '../database-layer/db.js';
6
+ import * as permissions from '../sbvr-api/permissions.js';
7
+ import { PinejsClient } from '../sbvr-api/sbvr-utils.js';
8
+ import { sbvrUtils } from '../server-glue/module.js';
9
+ import { ajv } from './common.js';
10
+ import type { Task } from './tasks.js';
11
+ import type TasksModel from './tasks.js';
12
12
 
13
13
  interface TaskArgs<T = AnyObject> {
14
14
  api: PinejsClient;
@@ -1,5 +1,9 @@
1
1
  import type { WebResourceType as WebResource } from '@balena/sbvr-types';
2
- import type { IncomingFile, UploadResponse, WebResourceHandler } from '..';
2
+ import type {
3
+ IncomingFile,
4
+ UploadResponse,
5
+ WebResourceHandler,
6
+ } from '../index.js';
3
7
 
4
8
  export class NoopHandler implements WebResourceHandler {
5
9
  public async handleFile(resource: IncomingFile): Promise<UploadResponse> {
@@ -5,7 +5,7 @@ import {
5
5
  type UploadResponse,
6
6
  WebResourceError,
7
7
  type WebResourceHandler,
8
- } from '..';
8
+ } from '../index.js';
9
9
  import {
10
10
  S3Client,
11
11
  type S3ClientConfig,
@@ -1,2 +1,2 @@
1
- export * from './NoopHandler';
2
- export * from './S3Handler';
1
+ export * from './NoopHandler.js';
2
+ export * from './S3Handler.js';
@@ -1,21 +1,21 @@
1
1
  import type * as Express from 'express';
2
2
  import busboy from 'busboy';
3
3
  import type * as stream from 'node:stream';
4
- import * as uriParser from '../sbvr-api/uri-parser';
5
- import * as sbvrUtils from '../sbvr-api/sbvr-utils';
6
- import type { HookArgs } from '../sbvr-api/hooks';
7
- import { getApiRoot, getModel } from '../sbvr-api/sbvr-utils';
8
- import { checkPermissions } from '../sbvr-api/permissions';
9
- import { NoopHandler } from './handlers/NoopHandler';
4
+ import * as uriParser from '../sbvr-api/uri-parser.js';
5
+ import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
6
+ import type { HookArgs } from '../sbvr-api/hooks.js';
7
+ import { getApiRoot, getModel } from '../sbvr-api/sbvr-utils.js';
8
+ import { checkPermissions } from '../sbvr-api/permissions.js';
9
+ import { NoopHandler } from './handlers/NoopHandler.js';
10
10
  import {
11
11
  odataNameToSqlName,
12
12
  sqlNameToODataName,
13
13
  } from '@balena/odata-to-abstract-sql';
14
- import { errors, permissions } from '../server-glue/module';
14
+ import { errors, permissions } from '../server-glue/module.js';
15
15
  import type { WebResourceType as WebResource } from '@balena/sbvr-types';
16
16
  import { TypedError } from 'typed-error';
17
17
 
18
- export * from './handlers';
18
+ export * from './handlers/index.js';
19
19
 
20
20
  export interface IncomingFile {
21
21
  fieldname: string;
package/tsconfig.dev.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "."
4
+ "rootDir": ".",
5
+ "allowImportingTsExtensions": true
5
6
  },
6
7
  "include": [
7
8
  "build/**/*",
9
+ "bin/**/*",
8
10
  "src/**/*",
9
11
  "test/**/*",
10
12
  "typings/**/*.d.ts",
11
- "Gruntfile.ts"
13
+ "Gruntfile.cts"
12
14
  ]
13
15
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "Node16",
3
+ "module": "NodeNext",
4
4
  "strict": true,
5
5
  "strictFunctionTypes": false,
6
6
  "noImplicitThis": false,
@@ -5,7 +5,7 @@ declare module '@balena/lf-to-abstract-sql' {
5
5
  export const LF2AbstractSQL: {
6
6
  createInstance: () => {
7
7
  match: (lfModel: LFModel, rule: 'Process') => AbstractSqlModel;
8
- addTypes: (types: typeof sbvrTypes) => void;
8
+ addTypes: (types: typeof sbvrTypes.default) => void;
9
9
  reset: () => void;
10
10
  };
11
11
  };
@@ -14,6 +14,6 @@ declare module '@balena/lf-to-abstract-sql' {
14
14
  _extend(obj: object): typeof LF2AbstractSQLPrep;
15
15
  };
16
16
  export const createTranslator: (
17
- types: typeof sbvrTypes,
17
+ types: typeof sbvrTypes.default,
18
18
  ) => (lfModel: LFModel, rule: 'Process') => AbstractSqlModel;
19
19
  }
@@ -1,4 +1,4 @@
1
- declare module 'memoizee/weak' {
1
+ declare module 'memoizee/weak.js' {
2
2
  import type * as Memoize from 'memoizee';
3
3
 
4
4
  type FirstArg<T> = T extends (arg1: infer U) => any ? U : any;