@sdflc/backend-helpers 1.0.111 → 1.0.113

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 (206) hide show
  1. package/README.md +1422 -146
  2. package/build/BaseController.d.ts +20 -0
  3. package/build/BaseController.js +64 -0
  4. package/build/BaseCore.d.ts +470 -33
  5. package/build/BaseCore.js +613 -126
  6. package/build/BaseExternalApiGateway.d.ts +16 -0
  7. package/build/BaseExternalApiGateway.js +54 -0
  8. package/build/BaseGateway.d.ts +455 -17
  9. package/build/BaseGateway.js +502 -56
  10. package/build/BaseRestApiCrudController.d.ts +37 -0
  11. package/build/BaseRestApiCrudController.js +134 -0
  12. package/build/DataCache.d.ts +116 -5
  13. package/build/DataCache.js +144 -22
  14. package/build/Database.d.ts +165 -4
  15. package/build/Database.js +224 -51
  16. package/build/DbMigratorAndSeeder.d.ts +127 -26
  17. package/build/DbMigratorAndSeeder.js +180 -69
  18. package/build/RedisDataLoader.d.ts +144 -21
  19. package/build/RedisDataLoader.js +178 -49
  20. package/build/apiContext.d.ts +0 -8
  21. package/build/apiContext.js +12 -27
  22. package/build/checkItHelpers.d.ts +32 -0
  23. package/build/checkItHelpers.js +73 -7
  24. package/build/commonValidators.d.ts +107 -16
  25. package/build/commonValidators.js +211 -106
  26. package/build/configBuilder.d.ts +23 -0
  27. package/build/configBuilder.js +73 -0
  28. package/build/constants.d.ts +134 -17
  29. package/build/constants.js +95 -15
  30. package/build/dbHelpers.d.ts +89 -29
  31. package/build/dbHelpers.js +175 -86
  32. package/build/dbSeeder.d.ts +10 -1
  33. package/build/dbSeeder.js +80 -15
  34. package/build/dbTableHelpers.d.ts +122 -5
  35. package/build/dbTableHelpers.js +151 -13
  36. package/build/downloadHelpers.d.ts +24 -1
  37. package/build/downloadHelpers.js +51 -21
  38. package/build/esm/BaseController.d.ts +20 -0
  39. package/build/esm/BaseController.js +58 -0
  40. package/build/esm/BaseCore.d.ts +470 -33
  41. package/build/esm/BaseCore.js +615 -128
  42. package/build/esm/BaseExternalApiGateway.d.ts +16 -0
  43. package/build/esm/BaseExternalApiGateway.js +48 -0
  44. package/build/esm/BaseGateway.d.ts +455 -17
  45. package/build/esm/BaseGateway.js +503 -57
  46. package/build/esm/BaseRestApiCrudController.d.ts +37 -0
  47. package/build/esm/BaseRestApiCrudController.js +131 -0
  48. package/build/esm/DataCache.d.ts +116 -5
  49. package/build/esm/DataCache.js +142 -20
  50. package/build/esm/Database.d.ts +165 -4
  51. package/build/esm/Database.js +224 -51
  52. package/build/esm/DbMigratorAndSeeder.d.ts +127 -26
  53. package/build/esm/DbMigratorAndSeeder.js +184 -71
  54. package/build/esm/RedisDataLoader.d.ts +144 -21
  55. package/build/esm/RedisDataLoader.js +179 -50
  56. package/build/esm/apiContext.d.ts +0 -8
  57. package/build/esm/apiContext.js +12 -27
  58. package/build/esm/checkItHelpers.d.ts +32 -0
  59. package/build/esm/checkItHelpers.js +73 -7
  60. package/build/esm/commonValidators.d.ts +107 -16
  61. package/build/esm/commonValidators.js +209 -105
  62. package/build/esm/configBuilder.d.ts +23 -0
  63. package/build/esm/configBuilder.js +69 -0
  64. package/build/esm/constants.d.ts +134 -17
  65. package/build/esm/constants.js +94 -14
  66. package/build/esm/dbHelpers.d.ts +89 -29
  67. package/build/esm/dbHelpers.js +171 -81
  68. package/build/esm/dbSeeder.d.ts +10 -1
  69. package/build/esm/dbSeeder.js +81 -16
  70. package/build/esm/dbTableHelpers.d.ts +122 -5
  71. package/build/esm/dbTableHelpers.js +152 -14
  72. package/build/esm/downloadHelpers.d.ts +24 -1
  73. package/build/esm/downloadHelpers.js +51 -21
  74. package/build/esm/index.d.ts +5 -2
  75. package/build/esm/index.js +5 -2
  76. package/build/esm/interfaces/ApiContext.d.ts +7 -3
  77. package/build/esm/interfaces/ApiContextInterface.d.ts +1 -1
  78. package/build/esm/interfaces/BaseControllerPropsInterface.d.ts +5 -0
  79. package/build/esm/interfaces/BaseControllerPropsInterface.js +1 -0
  80. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +1 -0
  81. package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +11 -11
  82. package/build/esm/interfaces/BaseCorePropsInterface.d.ts +87 -9
  83. package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
  84. package/build/esm/interfaces/BaseExternalApiGatewayPropsInterface.d.ts +19 -0
  85. package/build/esm/interfaces/BaseExternalApiGatewayPropsInterface.js +2 -0
  86. package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +78 -3
  87. package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
  88. package/build/esm/interfaces/BaseRestApiCrudControllerPropsInterface.d.ts +28 -0
  89. package/build/esm/interfaces/BaseRestApiCrudControllerPropsInterface.js +2 -0
  90. package/build/esm/interfaces/BuildConfigOptions.d.ts +18 -0
  91. package/build/esm/interfaces/BuildConfigOptions.js +1 -0
  92. package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +22 -4
  93. package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
  94. package/build/esm/interfaces/CacheInterface.d.ts +18 -1
  95. package/build/esm/interfaces/CacheInterface.js +1 -0
  96. package/build/esm/interfaces/CoreActionInterface.d.ts +20 -0
  97. package/build/esm/interfaces/CreateUserTokenArgs.d.ts +38 -4
  98. package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
  99. package/build/esm/interfaces/DataCachePropsInterface.d.ts +21 -0
  100. package/build/esm/interfaces/DataCachePropsInterface.js +2 -0
  101. package/build/esm/interfaces/DatabaseOptions.d.ts +24 -10
  102. package/build/esm/interfaces/DatabaseOptions.js +1 -0
  103. package/build/esm/interfaces/DatabaseReadInterface.d.ts +58 -3
  104. package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
  105. package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +35 -4
  106. package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
  107. package/build/esm/interfaces/DownloadFileArgs.d.ts +21 -2
  108. package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +15 -4
  109. package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
  110. package/build/esm/interfaces/ListArgsInterface.d.ts +18 -0
  111. package/build/esm/interfaces/ListArgsInterface.js +1 -0
  112. package/build/esm/interfaces/LoaderInterface.d.ts +36 -1
  113. package/build/esm/interfaces/LoaderInterface.js +1 -0
  114. package/build/esm/interfaces/UserTokenParams.d.ts +23 -5
  115. package/build/esm/interfaces/UserTokenParams.js +1 -0
  116. package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +42 -2
  117. package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
  118. package/build/esm/interfaces/index.d.ts +4 -0
  119. package/build/esm/interfaces/index.js +4 -0
  120. package/build/esm/knexConfigBuilder.d.ts +25 -0
  121. package/build/esm/knexConfigBuilder.js +100 -36
  122. package/build/esm/parseIds.d.ts +6 -0
  123. package/build/esm/parseIds.js +13 -0
  124. package/build/esm/passwordHelpers.d.ts +22 -0
  125. package/build/esm/passwordHelpers.js +40 -8
  126. package/build/esm/redisClient.d.ts +57 -4
  127. package/build/esm/redisClient.js +40 -54
  128. package/build/esm/resolveClientIp.d.ts +15 -0
  129. package/build/esm/resolveClientIp.js +34 -0
  130. package/build/esm/resolversHelpers.d.ts +21 -1
  131. package/build/esm/resolversHelpers.js +48 -26
  132. package/build/esm/userToken.d.ts +50 -1
  133. package/build/esm/userToken.js +85 -20
  134. package/build/esm/utils.d.ts +20 -0
  135. package/build/esm/utils.js +23 -1
  136. package/build/index.d.ts +5 -2
  137. package/build/index.js +5 -2
  138. package/build/interfaces/ApiContext.d.ts +7 -3
  139. package/build/interfaces/ApiContextInterface.d.ts +1 -1
  140. package/build/interfaces/BaseControllerPropsInterface.d.ts +5 -0
  141. package/build/interfaces/BaseControllerPropsInterface.js +2 -0
  142. package/build/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +1 -0
  143. package/build/interfaces/BaseCoreDoingWhatInterface.d.ts +11 -11
  144. package/build/interfaces/BaseCorePropsInterface.d.ts +87 -9
  145. package/build/interfaces/BaseCorePropsInterface.js +1 -0
  146. package/build/interfaces/BaseExternalApiGatewayPropsInterface.d.ts +19 -0
  147. package/build/interfaces/BaseExternalApiGatewayPropsInterface.js +3 -0
  148. package/build/interfaces/BaseGatewayPropsInterface.d.ts +78 -3
  149. package/build/interfaces/BaseGatewayPropsInterface.js +1 -0
  150. package/build/interfaces/BaseRestApiCrudControllerPropsInterface.d.ts +28 -0
  151. package/build/interfaces/BaseRestApiCrudControllerPropsInterface.js +3 -0
  152. package/build/interfaces/BuildConfigOptions.d.ts +18 -0
  153. package/build/interfaces/BuildConfigOptions.js +1 -0
  154. package/build/interfaces/BuildListQueryArgsInterface.d.ts +22 -4
  155. package/build/interfaces/BuildListQueryArgsInterface.js +1 -0
  156. package/build/interfaces/CacheInterface.d.ts +18 -1
  157. package/build/interfaces/CacheInterface.js +1 -0
  158. package/build/interfaces/CoreActionInterface.d.ts +20 -0
  159. package/build/interfaces/CreateUserTokenArgs.d.ts +38 -4
  160. package/build/interfaces/CreateUserTokenArgs.js +1 -0
  161. package/build/interfaces/DataCachePropsInterface.d.ts +21 -0
  162. package/build/interfaces/DataCachePropsInterface.js +3 -0
  163. package/build/interfaces/DatabaseOptions.d.ts +24 -10
  164. package/build/interfaces/DatabaseOptions.js +1 -0
  165. package/build/interfaces/DatabaseReadInterface.d.ts +58 -3
  166. package/build/interfaces/DatabaseReadInterface.js +1 -0
  167. package/build/interfaces/DbFieldAddDefaultInterface.d.ts +35 -4
  168. package/build/interfaces/DbFieldAddDefaultInterface.js +1 -0
  169. package/build/interfaces/DownloadFileArgs.d.ts +21 -2
  170. package/build/interfaces/ExtractCredentialsArgs.d.ts +15 -4
  171. package/build/interfaces/ExtractCredentialsArgs.js +1 -0
  172. package/build/interfaces/ListArgsInterface.d.ts +18 -0
  173. package/build/interfaces/ListArgsInterface.js +1 -0
  174. package/build/interfaces/LoaderInterface.d.ts +36 -1
  175. package/build/interfaces/LoaderInterface.js +1 -0
  176. package/build/interfaces/UserTokenParams.d.ts +23 -5
  177. package/build/interfaces/UserTokenParams.js +1 -0
  178. package/build/interfaces/VerifyUserTokenArgs.d.ts +42 -2
  179. package/build/interfaces/VerifyUserTokenArgs.js +1 -0
  180. package/build/interfaces/index.d.ts +4 -0
  181. package/build/interfaces/index.js +4 -0
  182. package/build/knexConfigBuilder.d.ts +25 -0
  183. package/build/knexConfigBuilder.js +99 -35
  184. package/build/parseIds.d.ts +6 -0
  185. package/build/parseIds.js +17 -0
  186. package/build/passwordHelpers.d.ts +22 -0
  187. package/build/passwordHelpers.js +40 -8
  188. package/build/redisClient.d.ts +57 -4
  189. package/build/redisClient.js +40 -54
  190. package/build/resolveClientIp.d.ts +15 -0
  191. package/build/resolveClientIp.js +38 -0
  192. package/build/resolversHelpers.d.ts +21 -1
  193. package/build/resolversHelpers.js +48 -26
  194. package/build/userToken.d.ts +50 -1
  195. package/build/userToken.js +85 -20
  196. package/build/utils.d.ts +20 -0
  197. package/build/utils.js +23 -1
  198. package/package.json +19 -18
  199. package/build/baseController.d.ts +0 -17
  200. package/build/baseController.js +0 -63
  201. package/build/configBulder.d.ts +0 -2
  202. package/build/configBulder.js +0 -36
  203. package/build/esm/baseController.d.ts +0 -17
  204. package/build/esm/baseController.js +0 -57
  205. package/build/esm/configBulder.d.ts +0 -2
  206. package/build/esm/configBulder.js +0 -32
@@ -5,7 +5,7 @@ export interface ApiContextInterface {
5
5
  gateways: any;
6
6
  req: any;
7
7
  res: any;
8
- requestId: any;
8
+ requestId?: string;
9
9
  getCoreContext?(args: any): Promise<BaseCorePropsInterface>;
10
10
  getGatewayContext?(args: any): Promise<BaseGatewayPropsInterface>;
11
11
  extendContext?(args: any): any;
@@ -0,0 +1,5 @@
1
+ import { Logger } from '@sdflc/utils';
2
+ export interface BaseControllerPropsInterface {
3
+ onResponse?: (req: any, res: any, next: any) => Promise<void> | void;
4
+ logger?: Logger;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -9,4 +9,5 @@ export interface BaseCoreDoAuthOnActionInterface {
9
9
  set?: boolean;
10
10
  remove?: boolean;
11
11
  removeMany?: boolean;
12
+ [key: string]: boolean | undefined;
12
13
  }
@@ -1,13 +1,13 @@
1
1
  export interface BaseCoreDoingWhatInterface {
2
- list: string;
3
- get: string;
4
- getMany: string;
5
- create: string;
6
- createMany: string;
7
- update: string;
8
- updateMany: string;
9
- set: string;
10
- remove: string;
11
- removeMany: string;
12
- [key: string]: string;
2
+ list?: string;
3
+ get?: string;
4
+ getMany?: string;
5
+ create?: string;
6
+ createMany?: string;
7
+ update?: string;
8
+ updateMany?: string;
9
+ set?: string;
10
+ remove?: string;
11
+ removeMany?: string;
12
+ [key: string]: string | undefined;
13
13
  }
@@ -1,6 +1,5 @@
1
1
  import { Logger } from '@sdflc/utils';
2
2
  import { Database } from '../Database';
3
- import { BaseGateway } from '../BaseGateway';
4
3
  import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
5
4
  import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
6
5
  import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
@@ -9,29 +8,108 @@ import { ID_TYPES } from '../constants';
9
8
  import { BaseCoreDoAuthOnActionInterface } from './BaseCoreDoAuthOnActionInterface';
10
9
  export interface BaseCorePropsInterface {
11
10
  /**
12
- * Application API context with all necessary information about request
11
+ * Full request-scoped ApiContext. Required — cores use it to access
12
+ * userId, spaceId, gateways, requestId, headers, etc.
13
13
  */
14
14
  context: ApiContext;
15
15
  /**
16
- * Database instance to handle queries to DB within one request
16
+ * Database instance for transaction management and raw query access.
17
+ * Required — used by runAction() for startTransaction, commit, rollback,
18
+ * and by exceptionFailure() for isDbError() checks.
17
19
  */
18
20
  db: Database;
19
21
  /**
20
- * Name of a gateway that will perform default CRUD operations, it should be initialized in the API context
22
+ * Name of the default gateway in context.gateways used for CRUD operations.
23
+ * Optional — some cores orchestrate other cores or always specify the
24
+ * gateway name explicitly via getGateway(name).
25
+ */
26
+ gatewayName?: string;
27
+ /**
28
+ * Optional — available to subclasses that vary behaviour between
29
+ * production and non-production environments (e.g. verbose error messages).
30
+ */
31
+ isProduction?: boolean;
32
+ /**
33
+ * Optional — falls back to a module-level Logger({ level: ERROR }) if not
34
+ * provided or if the value fails the isLogger() duck-type check.
35
+ * Duck-typed to avoid instanceof failures across package versions.
36
+ */
37
+ logger?: Logger;
38
+ /**
39
+ * Human-readable name for this core. Used as the default `doingWhat`
40
+ * string in log messages and error reports when doingWhat is not set.
21
41
  */
22
- gatewayName: string;
23
- isProduction: boolean;
24
- logger: Logger;
25
42
  name?: string;
26
- doAuth: boolean;
43
+ /**
44
+ * Master auth switch. When true, all actions require authentication
45
+ * unless overridden per-action via doAuthOnAction.
46
+ * Optional — defaults to false (no auth required).
47
+ */
48
+ doAuth?: boolean;
49
+ /**
50
+ * Per-action auth overrides. Each action independently enables or disables
51
+ * auth. Falls back to doAuth if not set for a specific action.
52
+ *
53
+ * Example — require auth globally but allow public list:
54
+ * { doAuth: true, doAuthOnAction: { list: false } }
55
+ */
27
56
  doAuthOnAction?: BaseCoreDoAuthOnActionInterface;
57
+ /**
58
+ * Custom doingWhat strings for log messages per action.
59
+ * e.g. { create: 'creating a user account', remove: 'deleting a user' }
60
+ * Falls back to `name` then to a built-in default string if not set.
61
+ */
28
62
  doingWhat?: BaseCoreDoingWhatInterface;
63
+ /**
64
+ * Custom validator map. If not provided, getValidators() returns the
65
+ * default validators (validateGet, validateGetMany, validateRemove,
66
+ * validateRemoveMany, and no-op defaults for mutations).
67
+ */
29
68
  validators?: BaseCoreValidatorsInterface;
30
- spaceGw?: BaseGateway;
69
+ /**
70
+ * Gateway used to resolve the current space by spaceId.
71
+ * Typed structurally rather than as BaseGateway to avoid instanceof
72
+ * coupling across package versions — any object with a get() method works.
73
+ *
74
+ * Used by findSpace() to look up space config (tokenSecret, apiKey, etc.)
75
+ * when context.space is not already populated.
76
+ */
77
+ spaceGw?: {
78
+ get(id: string): Promise<any>;
79
+ };
80
+ /**
81
+ * Shared secret for service-to-service API calls.
82
+ * When context.apiKey matches this value, authentication is bypassed
83
+ * and the request is treated as a trusted interservice call.
84
+ */
31
85
  interserviceApiKey?: string;
86
+ /**
87
+ * JWT secret used to verify user tokens.
88
+ * Can be overridden per-space via getJwtTokenSecretAndSettings().
89
+ */
32
90
  jwtSecret?: string;
91
+ /**
92
+ * Additional options passed to the JWT verification function.
93
+ * e.g. algorithms, audience, issuer, clockTolerance.
94
+ * Merged with defaults in getJwtTokenSecretAndSettings().
95
+ */
33
96
  verifyTokenArgs?: VerifyUserTokenArgs;
97
+ /**
98
+ * When true, create() automatically calculates and sets the orderNo
99
+ * field before inserting. Uses getFilterToSetOrderNo() to scope the
100
+ * sequence and getGatewayToSetOrerNo() to query the current max.
101
+ */
34
102
  hasOrderNo?: boolean;
103
+ /**
104
+ * Controls the orderNo strategy when hasOrderNo is true.
105
+ * true — numeric ordering (10, 20, 30...)
106
+ * false — lexicographic string ordering via StrOrderHelpers
107
+ */
35
108
  orderNoAsDecimal?: boolean;
109
+ /**
110
+ * The ID type this core operates with (UUID, integer, etc.).
111
+ * Used by consumers that need to validate or coerce ID formats.
112
+ * Defaults to ID_TYPES.UNKNOWN if not set.
113
+ */
36
114
  idType?: ID_TYPES;
37
115
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/BaseCorePropsInterface.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ export interface BaseExternalApiGatewayPropsInterface {
2
+ /**
3
+ * Optional credentials — a plain API key string or a structured object
4
+ * with whatever keys the external service requires.
5
+ * Can also be set later via setCredentials() once resolved at runtime.
6
+ */
7
+ credentials?: string | Record<string, any>;
8
+ /**
9
+ * Base URL of the external API.
10
+ * Can be overridden in the subclass if it never changes.
11
+ */
12
+ baseUrl?: string;
13
+ /**
14
+ * Timeout in milliseconds for outbound requests.
15
+ * Defaults to 10000.
16
+ */
17
+ timeoutMs?: number;
18
+ logger?: any;
19
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // ./src/interfaces/BaseExternalApiGatewayPropsInterface.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,12 +4,33 @@ import { CacheInterface } from '..';
4
4
  import { LoaderInterface } from './LoaderInterface';
5
5
  import { SortItemInterface } from './SortItemInterface';
6
6
  export interface BaseGatewayPropsInterface extends CacheInterface {
7
+ /**
8
+ * The full request-scoped ApiContext. Required — gateways use it to
9
+ * access userId, spaceId, requestId, other gateways, and usedKeyPrefixes.
10
+ */
7
11
  context: ApiContext;
8
12
  table?: string;
13
+ /**
14
+ * Primary key field name used for SELECT and loader operations.
15
+ * Defaults to the global ID_FIELD constant.
16
+ */
9
17
  idField?: string;
18
+ /**
19
+ * Field name used in UPDATE/DELETE WHERE clauses.
20
+ * Separate from idField for tables where the write target differs
21
+ * from the read key. Defaults to idField → ID_FIELD.
22
+ */
10
23
  idFieldUpdateRemove?: string;
11
24
  idFieldAs?: string;
25
+ /**
26
+ * Conflict target field(s) for the set() upsert operation.
27
+ * Passed to .onConflict(). Defaults to idFieldUpdateRemove.
28
+ */
12
29
  setFields?: string[] | string;
30
+ /**
31
+ * Explicit list of fields to include in the ON CONFLICT MERGE clause.
32
+ * If not set, all keys across all objects are used (minus skipFields).
33
+ */
13
34
  mergeFields?: string[];
14
35
  hasStatus?: boolean;
15
36
  hasCreatedBy?: boolean;
@@ -17,23 +38,77 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
17
38
  hasRemovedBy?: boolean;
18
39
  hasCreatedAt?: boolean;
19
40
  hasUpdatedAt?: boolean;
41
+ /**
42
+ * Enables soft-delete behaviour. When true, remove() issues an UPDATE
43
+ * with removedAt set instead of a DELETE.
44
+ */
20
45
  hasRemovedAt?: boolean;
46
+ /**
47
+ * When true, also writes a formatted string timestamp to removedAtStr.
48
+ * Useful for building composite keys that encode the removal time.
49
+ */
21
50
  hasRemovedAtStr?: boolean;
51
+ /**
52
+ * When true, scopes reads and writes to the current spaceId from context.
53
+ */
22
54
  hasSpace?: boolean;
55
+ /**
56
+ * Enables optimistic locking via a version field.
57
+ * update() checks version in the WHERE clause and increments it on success.
58
+ */
23
59
  hasVersion?: boolean;
24
60
  hasLang?: boolean;
25
61
  hasUserId?: boolean;
62
+ /**
63
+ * Field name used to build a composite id for localised records.
64
+ * Combined with the lang field: buildKey([params[localizationForField], params.lang]).
65
+ */
26
66
  localizationForField?: string;
27
67
  defaultSorting?: SortItemInterface[];
68
+ /**
69
+ * Field to apply keyword (ILIKE) search against when filterParams.keyword is set.
70
+ */
28
71
  fieldForKeyword?: string;
72
+ /**
73
+ * Field name to scope list queries to the current userId from context.
74
+ * e.g. 'userId' → WHERE userId = context.userId
75
+ */
29
76
  filterByUserField?: string;
77
+ /**
78
+ * Number of records per INSERT batch. Defaults to 2500.
79
+ * Prevents hitting DB parameter limits on large inserts.
80
+ */
30
81
  insertChunkSize?: number;
82
+ /**
83
+ * When true, remove() issues a hard DELETE regardless of hasRemovedAt.
84
+ */
31
85
  hardRemove?: boolean;
86
+ /**
87
+ * Custom loader implementing LoaderInterface (load + loadMany).
88
+ * Defaults to DataCache (DataLoader-backed in-memory cache).
89
+ */
32
90
  loader?: LoaderInterface;
91
+ /**
92
+ * When true, bypasses the loader cache and fetches directly from the DB.
93
+ */
33
94
  noCache?: boolean;
95
+ /**
96
+ * Columns to include in RETURNING clauses. Defaults to ['*'].
97
+ */
34
98
  returnFields?: any[];
99
+ /**
100
+ * Status values considered "active" for list filtering.
101
+ * Used when no explicit status filter is provided. Defaults to [STATUSES.ACTIVE].
102
+ */
35
103
  activeStatuses?: number[];
36
- logger: Logger;
37
- isProduction: boolean;
38
- usedKeyPrefixes?: any;
104
+ /**
105
+ * Optional — falls back to a new Logger({ level: WARNING }) if not provided
106
+ * or if the value fails the isLogger() duck-type check.
107
+ */
108
+ logger?: Logger;
109
+ /**
110
+ * Optional — available to subclasses that need to vary behaviour
111
+ * between production and non-production environments.
112
+ */
113
+ isProduction?: boolean;
39
114
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/BaseGatewayPropsInterface.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ export interface BaseRestApiCrudControllerPropsInterface {
2
+ /**
3
+ * The prefix used to derive the core name, e.g. "user" → "userCore".
4
+ * Ignored if `core` is provided explicitly.
5
+ */
6
+ prefix?: string;
7
+ /**
8
+ * Explicit core name in context.cores to use.
9
+ * Defaults to `${prefix}Core`.
10
+ */
11
+ core?: string;
12
+ /**
13
+ * Factory that produces the ApiContext for a given request.
14
+ * Required — controllers need context to reach cores.
15
+ */
16
+ getContext: (req: any) => Promise<any> | any;
17
+ onResponse?: (req: any, res: any, next: any) => Promise<void> | void;
18
+ logger?: any;
19
+ disableList?: boolean;
20
+ disableGet?: boolean;
21
+ disableGetMany?: boolean;
22
+ disableCreate?: boolean;
23
+ disableCreateMany?: boolean;
24
+ disableUpdate?: boolean;
25
+ disableUpdateMany?: boolean;
26
+ disableRemove?: boolean;
27
+ disableRemoveMany?: boolean;
28
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // ./src/interfaces/BaseRestApiCrudControllerPropsInterface.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,24 @@
1
1
  export interface BuildConfigOptions {
2
+ /**
3
+ * Path to the .env file, relative to the `dirName` passed to `buildConfig()`.
4
+ * Defaults to '.env'.
5
+ */
2
6
  envFile?: string;
7
+ /**
8
+ * Path to the .env example/template file, relative to `dirName`.
9
+ * Used by dotenv-safe to verify all required variables are present.
10
+ * Defaults to '.env.example'.
11
+ */
3
12
  envFileExample?: string;
13
+ /**
14
+ * Value to use for NODE_ENV if it is not set in the environment.
15
+ * Defaults to 'development'.
16
+ */
4
17
  defaultNodeEnv?: string;
18
+ /**
19
+ * When true, dotenv-safe will not throw if variables declared in the
20
+ * example file are present but have empty values in the .env file.
21
+ * Defaults to true.
22
+ */
5
23
  allowEmptyValues?: boolean;
6
24
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/BuildConfigOptions.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,24 @@
1
1
  export interface BuildListQueryArgsInterface {
2
- filter: any;
3
- params: any;
4
- fieldsToUse: any;
5
- useCache: boolean;
2
+ /**
3
+ * Filter params passed to onListFilter().
4
+ * Optional — buildListQuery() itself does not apply filters;
5
+ * it only selects fields. onListFilter() receives filter separately.
6
+ */
7
+ filter?: any;
8
+ /**
9
+ * Pagination and sorting params (limit, offset, sortBy).
10
+ * Optional — subclasses that build joins or computed columns
11
+ * may need params to scope the query.
12
+ */
13
+ params?: any;
14
+ /**
15
+ * Columns to SELECT. When useCache is true this will be just the id field;
16
+ * when false it will be selectFields from config or '*'.
17
+ */
18
+ fieldsToUse?: any;
19
+ /**
20
+ * Whether the list result will be hydrated through the loader cache.
21
+ * Passed so subclasses can adjust query shape based on cache strategy.
22
+ */
23
+ useCache?: boolean;
6
24
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/BuildListQueryArgsInterface.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,29 @@
1
1
  import { Database } from '../Database';
2
2
  export interface CacheInterface {
3
3
  db: Database;
4
+ /**
5
+ * Namespace prefix for DataLoader cache keys.
6
+ * Resolved in BaseGateway as: context.keyPrefix → config.keyPrefix → table name.
7
+ * Uniqueness within a request is enforced by usedKeyPrefixes on ApiContext.
8
+ */
4
9
  keyPrefix?: string;
5
- context?: any;
10
+ /**
11
+ * Note: context is intentionally omitted here — it is declared as
12
+ * `context: ApiContext` (required, strongly typed) on BaseGatewayPropsInterface
13
+ * which extends this interface. Declaring it here as `any` would conflict
14
+ * with the stronger type and cause ambiguity.
15
+ */
6
16
  table?: string;
7
17
  idField?: string;
8
18
  idFieldAs?: string;
19
+ /**
20
+ * Columns fetched when useCache is false in list().
21
+ * Defaults to '*' if not set.
22
+ */
9
23
  selectFields?: any[];
24
+ /**
25
+ * When true, the loader pre-fetches all records on first access.
26
+ */
10
27
  readAll?: boolean;
11
28
  redisClient?: any;
12
29
  cacheTtl?: number;
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/CacheInterface.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,6 +3,22 @@ export interface CoreActionInterface {
3
3
  args: any;
4
4
  actionName?: string;
5
5
  doAuth?: boolean;
6
+ /**
7
+ * When true, attempts authentication but does not fail if it does not succeed.
8
+ * If a valid JWT is present, context will be populated with accountId, userId,
9
+ * roleId, etc. as normal. If no token is present or verification fails, the
10
+ * request continues unauthenticated with no error returned.
11
+ *
12
+ * Use for public endpoints that behave differently for authenticated users
13
+ * (e.g. personalised content, showing ownership state, soft-gating features).
14
+ *
15
+ * Runs before `requireSpace` — if soft auth populates the context, space
16
+ * verification will have the enriched context available.
17
+ *
18
+ * Mutually exclusive intent with `doAuth` — if `doAuth` is true, this flag
19
+ * is ignored since a hard auth failure is already enforced.
20
+ */
21
+ tryAuth?: boolean;
6
22
  accessRights?: any[];
7
23
  roles?: string[];
8
24
  validate?(args: any, opt: BaseCoreActionsInterface): Promise<any[]> | any[];
@@ -12,5 +28,9 @@ export interface CoreActionInterface {
12
28
  onException?(params: any, opt?: BaseCoreActionsInterface): Promise<any | undefined | null>;
13
29
  shouldLogArgs?: boolean;
14
30
  requireSpace?: boolean;
31
+ /**
32
+ * When true, lets runAction skip the action result check that decides
33
+ * whether to commit or rollback the DB transaction.
34
+ */
15
35
  skipCheckResult?: boolean;
16
36
  }
@@ -1,11 +1,45 @@
1
1
  export interface CreateUserTokenArgs {
2
- algorithm?: any;
2
+ /**
3
+ * JWT signing algorithm. Defaults to the module-level defaultJwtAlgorithm
4
+ * (HS256 unless overridden via setDefaultJwtAlgorithm()).
5
+ */
6
+ algorithm?: string;
7
+ /**
8
+ * JWT audience claim. Verified during token validation.
9
+ * Accepts a single string or array of strings.
10
+ */
3
11
  audience?: string | string[];
12
+ /**
13
+ * JWT issuer claim. Defaults to the module-level defaultIssuer.
14
+ */
4
15
  issuer?: string;
16
+ /**
17
+ * JWT ID claim. Defaults to a generated UUID v4 if not provided.
18
+ */
5
19
  jwtid?: string;
20
+ /**
21
+ * When true, omits the `iat` (issued-at) claim from the token.
22
+ * Defaults to false.
23
+ */
6
24
  noTimestamp?: boolean;
7
- header?: any;
8
- keyid?: any;
9
- expiresIn?: number;
25
+ /**
26
+ * Additional JWT header fields to include.
27
+ */
28
+ header?: Record<string, any>;
29
+ /**
30
+ * JWT `kid` (key ID) header parameter.
31
+ * Used to identify which key was used to sign the token.
32
+ */
33
+ keyid?: string;
34
+ /**
35
+ * Token expiry as a number of seconds or a string duration (e.g. '2h', '7d').
36
+ * If not provided, the token does not expire.
37
+ */
38
+ expiresIn?: number | string;
39
+ /**
40
+ * When true, generates a UUID fingerprint and embeds it in the token payload.
41
+ * The fingerprint should be stored in a secure cookie and passed to
42
+ * verifyUserToken() to mitigate token theft.
43
+ */
10
44
  useFingerprint?: boolean;
11
45
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/CreateUserTokenArgs.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { CacheInterface } from './CacheInterface';
2
+ /**
3
+ * Props for DataCache. Extends CacheInterface with request-scoped context,
4
+ * which is used to resolve the keyPrefix and passed through to custom
5
+ * loaderFn implementations.
6
+ *
7
+ * Kept separate from CacheInterface so that CacheInterface itself remains
8
+ * a clean, context-free storage config — usable without a request context.
9
+ * BaseGatewayPropsInterface declares context as ApiContext (strongly typed)
10
+ * separately.
11
+ */
12
+ export interface DataCachePropsInterface extends CacheInterface {
13
+ /**
14
+ * Optional request-scoped context. Used to read context.keyPrefix for
15
+ * DataLoader cache key namespacing, and passed through to custom loaderFn
16
+ * implementations that may need request-level data (userId, spaceId, etc.).
17
+ * Typed as `any` since DataCache is a lower-level class that should not
18
+ * depend on ApiContext directly.
19
+ */
20
+ context?: any;
21
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // ./src/interfaces/DataCachePropsInterface.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,26 +1,40 @@
1
- import { Logger } from '@sdflc/utils';
2
1
  /**
3
- * Interface to initialize Database object
2
+ * Options for initialising a Database instance.
3
+ *
4
+ * Connection pool deduplication:
5
+ * Database instances sharing the same host/port/user/database/schema
6
+ * combination reuse a single underlying Knex connection pool. Creating
7
+ * a new Database instance does not open a new pool if one already exists.
4
8
  */
5
9
  export interface DatabaseOptions {
6
10
  /**
7
- * Knex configuration object
11
+ * Knex configuration object. Required — must include at minimum a
12
+ * `client` and `connection` property.
13
+ * See: https://knexjs.org/guide/#configuration-options
8
14
  */
9
15
  knexConfig: any;
10
16
  /**
11
- * Database type: pg, msql, etc
17
+ * Database driver type (e.g. 'pg', 'mysql2', 'sqlite3').
18
+ * Optional — falls back to `knexConfig.client` if not provided.
12
19
  */
13
- dbType: string;
20
+ dbType?: string;
14
21
  /**
15
- * Name of database schema
22
+ * Database schema name to scope all queries via withSchema().
23
+ * Optional — if not provided, no schema scoping is applied and
24
+ * queries run against the default schema for the connection.
16
25
  */
17
- dbSchema: string;
26
+ dbSchema?: string;
18
27
  /**
19
- * Knex transaction object
28
+ * An existing Knex transaction object to use for all queries on this
29
+ * instance. Optional — if not provided, queries run outside a transaction
30
+ * until `startTransaction()` is called.
20
31
  */
21
32
  trx?: any;
22
33
  /**
23
- * Logger for debugging/logging
34
+ * Logger for debug/error output. Optional — falls back to a new Logger
35
+ * at ERROR level if not provided or if the value fails the isLogger()
36
+ * duck-type check. Typed as `any` to avoid instanceof failures when the
37
+ * consuming app has a different installed version of @sdflc/utils.
24
38
  */
25
- logger?: Logger;
39
+ logger?: any;
26
40
  }
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ./src/interfaces/DatabaseOptions.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });