@tstdl/base 0.92.142 → 0.92.144

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 (223) hide show
  1. package/ai/ai-file.service.js +1 -1
  2. package/ai/ai.service.js +3 -3
  3. package/ai/types.d.ts +1 -1
  4. package/api/client/client.d.ts +1 -1
  5. package/api/client/client.js +10 -4
  6. package/api/server/middlewares/content-type.middleware.js +8 -7
  7. package/api/types.js +1 -1
  8. package/authentication/client/authentication.service.js +3 -3
  9. package/authentication/server/authentication-ancillary.service.d.ts +11 -1
  10. package/authentication/server/authentication-ancillary.service.js +1 -1
  11. package/authentication/server/authentication-secret-requirements.validator.js +1 -1
  12. package/authentication/server/authentication.api-controller.js +22 -10
  13. package/authentication/server/authentication.service.d.ts +11 -5
  14. package/authentication/server/authentication.service.js +97 -49
  15. package/authentication/server/drizzle.config.js +2 -2
  16. package/authentication/server/module.js +1 -1
  17. package/cancellation/token.d.ts +2 -2
  18. package/cancellation/token.js +4 -4
  19. package/cookie/cookie.js +2 -2
  20. package/document-management/api/document-management.api.d.ts +122 -24
  21. package/document-management/api/document-management.api.js +17 -0
  22. package/document-management/{server/services → authorization}/document-management-authorization.service.d.ts +7 -7
  23. package/document-management/authorization/document-management-authorization.service.js +2 -0
  24. package/document-management/authorization/index.d.ts +2 -0
  25. package/document-management/authorization/index.js +2 -0
  26. package/document-management/authorization/policies.d.ts +38 -0
  27. package/document-management/authorization/policies.js +2 -0
  28. package/document-management/index.d.ts +1 -0
  29. package/document-management/index.js +1 -0
  30. package/document-management/models/document-assignment-scope.model.d.ts +1 -0
  31. package/document-management/models/document-assignment-scope.model.js +10 -3
  32. package/document-management/models/document-assignment-task.model.d.ts +1 -0
  33. package/document-management/models/document-assignment-task.model.js +8 -2
  34. package/document-management/models/document-category.model.d.ts +1 -0
  35. package/document-management/models/document-category.model.js +7 -1
  36. package/document-management/models/document-collection-assignment.model.d.ts +1 -0
  37. package/document-management/models/document-collection-assignment.model.js +12 -4
  38. package/document-management/models/document-collection.model.d.ts +2 -0
  39. package/document-management/models/document-collection.model.js +8 -2
  40. package/document-management/models/document-management-table.d.ts +3 -1
  41. package/document-management/models/document-management-table.js +2 -2
  42. package/document-management/models/document-property-value.model.d.ts +1 -0
  43. package/document-management/models/document-property-value.model.js +9 -3
  44. package/document-management/models/document-property.model.d.ts +1 -0
  45. package/document-management/models/document-property.model.js +8 -2
  46. package/document-management/models/document-request-collection-assignment.model.d.ts +1 -0
  47. package/document-management/models/document-request-collection-assignment.model.js +12 -4
  48. package/document-management/models/document-request-template.d.ts +1 -0
  49. package/document-management/models/document-request-template.js +6 -1
  50. package/document-management/models/document-request.model.d.ts +1 -0
  51. package/document-management/models/document-request.model.js +10 -1
  52. package/document-management/models/document-requests-template.d.ts +1 -0
  53. package/document-management/models/document-requests-template.js +7 -3
  54. package/document-management/models/document-tag-assignment.model.d.ts +8 -0
  55. package/document-management/models/document-tag-assignment.model.js +40 -0
  56. package/document-management/models/document-tag.model.d.ts +6 -0
  57. package/document-management/models/{document-request-submission.model.js → document-tag.model.js} +14 -18
  58. package/document-management/models/document-type-property.model.d.ts +1 -0
  59. package/document-management/models/document-type-property.model.js +7 -2
  60. package/document-management/models/document-type-validation.model.d.ts +1 -0
  61. package/document-management/models/document-type-validation.model.js +8 -2
  62. package/document-management/models/document-type.model.d.ts +1 -0
  63. package/document-management/models/document-type.model.js +7 -2
  64. package/document-management/models/document-validation-definition.model.d.ts +1 -0
  65. package/document-management/models/document-validation-definition.model.js +7 -2
  66. package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -0
  67. package/document-management/models/document-validation-execution-related-document.model.js +10 -3
  68. package/document-management/models/document-validation-execution.model.d.ts +1 -0
  69. package/document-management/models/document-validation-execution.model.js +9 -3
  70. package/document-management/models/document-workflow.model.d.ts +4 -1
  71. package/document-management/models/document-workflow.model.js +16 -4
  72. package/document-management/models/document.model.d.ts +2 -2
  73. package/document-management/models/document.model.js +9 -8
  74. package/document-management/models/index.d.ts +2 -1
  75. package/document-management/models/index.js +2 -1
  76. package/document-management/server/api/document-management.api.d.ts +4 -1
  77. package/document-management/server/api/document-management.api.js +113 -22
  78. package/document-management/server/configure.d.ts +2 -2
  79. package/document-management/server/configure.js +7 -7
  80. package/document-management/server/drizzle/0000_parallel_mantis.sql +359 -0
  81. package/document-management/server/drizzle/meta/0000_snapshot.json +784 -260
  82. package/document-management/server/drizzle/meta/_journal.json +2 -2
  83. package/document-management/server/module.d.ts +2 -2
  84. package/document-management/server/module.js +2 -2
  85. package/document-management/server/schemas.d.ts +6 -5
  86. package/document-management/server/schemas.js +12 -11
  87. package/document-management/server/services/document-category-type.service.d.ts +19 -10
  88. package/document-management/server/services/document-category-type.service.js +34 -27
  89. package/document-management/server/services/document-collection.service.d.ts +13 -6
  90. package/document-management/server/services/document-collection.service.js +36 -12
  91. package/document-management/server/services/document-file.service.d.ts +8 -7
  92. package/document-management/server/services/document-file.service.js +28 -33
  93. package/document-management/server/services/document-management-ai.service.d.ts +5 -4
  94. package/document-management/server/services/document-management-ai.service.js +51 -28
  95. package/document-management/server/services/document-management-ancillary.service.d.ts +3 -21
  96. package/document-management/server/services/document-management-ancillary.service.js +0 -24
  97. package/document-management/server/services/document-management-observation.service.d.ts +15 -0
  98. package/document-management/server/services/document-management-observation.service.js +160 -0
  99. package/document-management/server/services/document-management.service.d.ts +6 -5
  100. package/document-management/server/services/document-management.service.js +112 -86
  101. package/document-management/server/services/document-property.service.d.ts +15 -7
  102. package/document-management/server/services/document-property.service.js +52 -20
  103. package/document-management/server/services/document-request.service.d.ts +13 -24
  104. package/document-management/server/services/document-request.service.js +39 -62
  105. package/document-management/server/services/document-tag.service.d.ts +10 -0
  106. package/document-management/server/services/document-tag.service.js +59 -0
  107. package/document-management/server/services/document-validation.service.d.ts +8 -8
  108. package/document-management/server/services/document-validation.service.js +41 -40
  109. package/document-management/server/services/document-workflow.service.d.ts +6 -5
  110. package/document-management/server/services/document-workflow.service.js +54 -43
  111. package/document-management/server/services/document.service.d.ts +12 -11
  112. package/document-management/server/services/document.service.js +66 -40
  113. package/document-management/server/services/index.d.ts +2 -1
  114. package/document-management/server/services/index.js +2 -1
  115. package/document-management/server/services/singleton.js +2 -2
  116. package/document-management/server/validators/ai-validation-executor.js +4 -4
  117. package/document-management/service-models/document-collection-metadata.service-model.d.ts +14 -0
  118. package/document-management/service-models/document-collection-metadata.service-model.js +1 -0
  119. package/document-management/service-models/document-folders.view-model.d.ts +1 -7
  120. package/document-management/service-models/document-folders.view-model.js +3 -15
  121. package/document-management/service-models/document-management.view-model.d.ts +20 -6
  122. package/document-management/service-models/document-management.view-model.js +62 -8
  123. package/document-management/service-models/document.service-model.d.ts +14 -11
  124. package/document-management/service-models/document.service-model.js +11 -2
  125. package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
  126. package/document-management/service-models/enriched/enriched-document-assignment.view.js +0 -2
  127. package/document-management/service-models/enriched/enriched-document-category.view.d.ts +11 -1
  128. package/document-management/service-models/enriched/enriched-document-category.view.js +44 -1
  129. package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +4 -2
  130. package/document-management/service-models/enriched/enriched-document-collection.view.js +13 -3
  131. package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -0
  132. package/document-management/service-models/enriched/enriched-document-management-data.view.js +4 -2
  133. package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -0
  134. package/document-management/service-models/enriched/enriched-document-request.view.js +2 -0
  135. package/document-management/service-models/enriched/enriched-document-type.view.d.ts +9 -1
  136. package/document-management/service-models/enriched/enriched-document-type.view.js +28 -1
  137. package/document-management/service-models/enriched/enriched-document.view.d.ts +7 -6
  138. package/document-management/service-models/enriched/enriched-document.view.js +29 -6
  139. package/document-management/service-models/{normalized-requests-template-data.model.d.ts → enriched/enriched-requests-template-data.model.d.ts} +6 -6
  140. package/document-management/service-models/{normalized-requests-template-data.model.js → enriched/enriched-requests-template-data.model.js} +1 -1
  141. package/document-management/service-models/enriched/index.d.ts +1 -0
  142. package/document-management/service-models/enriched/index.js +1 -0
  143. package/document-management/service-models/index.d.ts +2 -2
  144. package/document-management/service-models/index.js +2 -2
  145. package/examples/document-management/categories-and-types.d.ts +33 -31
  146. package/examples/document-management/categories-and-types.js +33 -0
  147. package/examples/document-management/main.d.ts +5 -4
  148. package/examples/document-management/main.js +13 -7
  149. package/function/log.js +2 -2
  150. package/http/server/node/module.d.ts +4 -1
  151. package/http/server/node/module.js +10 -1
  152. package/http/server/node/node-http-server.d.ts +3 -6
  153. package/http/server/node/node-http-server.js +68 -67
  154. package/injector/inject.js +6 -6
  155. package/injector/injector.js +3 -3
  156. package/jsx/is-component-class.js +1 -1
  157. package/key-value-store/key-value.store.d.ts +38 -7
  158. package/key-value-store/key-value.store.js +2 -1
  159. package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -0
  160. package/key-value-store/mongo/mongo-key-value.store.js +14 -5
  161. package/key-value-store/postgres/drizzle/0000_shocking_slipstream.sql +12 -0
  162. package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +97 -0
  163. package/key-value-store/postgres/drizzle/meta/_journal.json +13 -0
  164. package/key-value-store/postgres/drizzle.config.d.ts +2 -0
  165. package/key-value-store/postgres/drizzle.config.js +11 -0
  166. package/key-value-store/postgres/index.d.ts +2 -0
  167. package/key-value-store/postgres/index.js +2 -0
  168. package/key-value-store/postgres/key-value-store.service.d.ts +17 -0
  169. package/key-value-store/postgres/key-value-store.service.js +65 -0
  170. package/key-value-store/postgres/models/index.d.ts +2 -0
  171. package/key-value-store/postgres/models/index.js +2 -0
  172. package/key-value-store/postgres/models/key-value.model.d.ts +7 -0
  173. package/key-value-store/postgres/models/key-value.model.js +35 -0
  174. package/key-value-store/postgres/models/schemas.d.ts +3 -0
  175. package/key-value-store/postgres/models/schemas.js +4 -0
  176. package/key-value-store/postgres/module.d.ts +6 -0
  177. package/key-value-store/postgres/module.js +23 -0
  178. package/lock/web/web-lock.d.ts +0 -1
  179. package/lock/web/web-lock.js +6 -13
  180. package/orm/data-types/timestamp.js +1 -1
  181. package/orm/decorators.d.ts +37 -29
  182. package/orm/decorators.js +44 -24
  183. package/orm/entity.d.ts +1 -0
  184. package/orm/query.d.ts +10 -2
  185. package/orm/repository.types.d.ts +2 -1
  186. package/orm/schemas/json.d.ts +12 -6
  187. package/orm/schemas/json.js +12 -5
  188. package/orm/server/database.js +5 -2
  189. package/orm/server/drizzle/schema-converter.js +40 -11
  190. package/orm/server/query-converter.d.ts +2 -1
  191. package/orm/server/query-converter.js +57 -34
  192. package/orm/server/repository.d.ts +26 -43
  193. package/orm/server/repository.js +106 -39
  194. package/orm/server/transaction.d.ts +2 -1
  195. package/orm/server/transaction.js +3 -0
  196. package/orm/server/transactional.d.ts +5 -1
  197. package/orm/server/transactional.js +34 -4
  198. package/package.json +14 -11
  199. package/process/spawn.js +0 -1
  200. package/promise/deferred-promise.d.ts +4 -3
  201. package/promise/deferred-promise.js +13 -5
  202. package/queue/postgres/queue.js +8 -8
  203. package/reflection/utils.js +3 -3
  204. package/schema/decorators/class.js +0 -1
  205. package/schema/decorators/schema.js +1 -1
  206. package/schema/schemas/boolean.d.ts +1 -1
  207. package/schema/schemas/boolean.js +2 -2
  208. package/schema/schemas/number.js +3 -3
  209. package/schema/schemas/object.js +5 -6
  210. package/sse/server-sent-events-source.js +4 -1
  211. package/utils/compression.js +9 -9
  212. package/utils/date-time.d.ts +1 -0
  213. package/utils/date-time.js +18 -4
  214. package/utils/equals.d.ts +7 -0
  215. package/utils/equals.js +17 -2
  216. package/utils/function/memoize.js +10 -2
  217. package/utils/jwt.js +3 -3
  218. package/utils/object/property-name.d.ts +2 -2
  219. package/utils/timing.d.ts +2 -2
  220. package/utils/timing.js +12 -12
  221. package/document-management/models/document-request-submission.model.d.ts +0 -7
  222. package/document-management/server/drizzle/0000_moaning_luckman.sql +0 -305
  223. package/document-management/server/services/document-management-authorization.service.js +0 -28
@@ -4,21 +4,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
7
+ var _a;
8
+ var NodeHttpServer_1;
13
9
  import * as Http from 'node:http';
14
10
  import { Writable } from 'node:stream';
15
11
  import { bindNodeCallback, share } from 'rxjs';
12
+ import { match, P } from 'ts-pattern';
16
13
  import { CancellationToken } from '../../../cancellation/index.js';
17
14
  import { disposeAsync } from '../../../disposable/index.js';
18
15
  import { HttpHeaders } from '../../../http/http-headers.js';
19
16
  import { HttpQuery } from '../../../http/http-query.js';
20
- import { ResolveArg, Singleton } from '../../../injector/index.js';
17
+ import { afterResolve, inject, Singleton } from '../../../injector/index.js';
21
18
  import { Logger } from '../../../logger/index.js';
19
+ import { toArray } from '../../../utils/array/array.js';
22
20
  import { encodeUtf8 } from '../../../utils/encoding.js';
23
21
  import { FeedableAsyncIterable } from '../../../utils/feedable-async-iterable.js';
24
22
  import { Timer } from '../../../utils/timer.js';
@@ -26,71 +24,65 @@ import { cancelableTimeout } from '../../../utils/timing.js';
26
24
  import { isDefined, isNullOrUndefined, isString } from '../../../utils/type-guards.js';
27
25
  import { HttpServerRequest } from '../http-server-request.js';
28
26
  import { HttpServer } from '../http-server.js';
29
- let NodeHttpServer = class NodeHttpServer extends HttpServer {
30
- httpServer;
31
- sockets;
32
- requestIterable;
33
- logger;
27
+ import { NodeHttpServerConfiguration } from './module.js';
28
+ let NodeHttpServer = NodeHttpServer_1 = class NodeHttpServer extends HttpServer {
29
+ #configuration = inject(NodeHttpServerConfiguration);
30
+ #httpServer = new Http.Server();
31
+ #sockets = new Set();
32
+ #requestIterable = new FeedableAsyncIterable();
33
+ #logger = inject(Logger, NodeHttpServer_1.name);
34
34
  untrackConnectedSockets;
35
35
  get connectedSocketsCount() {
36
- return this.sockets.size;
37
- }
38
- constructor(logger) {
39
- super();
40
- this.logger = logger;
41
- this.httpServer = new Http.Server();
42
- this.sockets = new Set();
43
- this.requestIterable = new FeedableAsyncIterable();
44
- this.httpServer.on('request', (request, response) => {
45
- this.logger.verbose(`${request.method} from "${request.socket.remoteAddress}" to "${request.url}"`);
46
- this.requestIterable.feed({ request, response });
47
- });
36
+ return this.#sockets.size;
37
+ }
38
+ [afterResolve]() {
39
+ this.#httpServer.on('request', (request, response) => this.#requestIterable.feed({ request, response }));
48
40
  }
49
41
  async [disposeAsync]() {
50
- if (this.httpServer.listening) {
42
+ if (this.#httpServer.listening) {
51
43
  await this.close(3000);
52
- this.requestIterable.end();
44
+ this.#requestIterable.end();
53
45
  }
54
46
  }
55
47
  async listen(port) {
56
- if (this.httpServer.listening) {
48
+ if (this.#httpServer.listening) {
57
49
  throw new Error('http server is already listening');
58
50
  }
59
- this.httpServer.listen(port);
60
- return new Promise((resolve, reject) => {
51
+ this.#httpServer.listen(port);
52
+ await new Promise((resolve, reject) => {
61
53
  let listeningListener;
62
- let errorListener; // eslint-disable-line prefer-const
54
+ let errorListener;
63
55
  listeningListener = () => {
64
- this.logger.info(`Listening on port ${port}`);
65
- this.untrackConnectedSockets = trackConnectedSockets(this.httpServer, this.sockets);
66
- this.httpServer.removeListener('error', errorListener);
56
+ this.#logger.info(`Listening on port ${port}`);
57
+ this.untrackConnectedSockets = trackConnectedSockets(this.#httpServer, this.#sockets);
58
+ this.#httpServer.removeListener('error', errorListener);
67
59
  resolve();
68
60
  };
69
61
  errorListener = (error) => {
70
- this.httpServer.removeListener('listening', listeningListener);
62
+ this.#httpServer.removeListener('listening', listeningListener);
71
63
  reject(error);
72
64
  };
73
- this.httpServer.once('listening', listeningListener);
74
- this.httpServer.once('error', errorListener);
65
+ this.#httpServer.once('listening', listeningListener);
66
+ this.#httpServer.once('error', errorListener);
75
67
  });
76
68
  }
77
69
  async close(timeout) {
78
- this.logger.info('Closing http server');
70
+ this.#logger.info('Closing http server');
79
71
  const timer = new Timer(true);
80
- const close$ = bindNodeCallback(this.httpServer.close.bind(this.httpServer))().pipe(share());
72
+ const close$ = bindNodeCallback(this.#httpServer.close.bind(this.#httpServer))().pipe(share());
81
73
  close$.subscribe();
82
74
  while (true) {
83
- const connections = await getConnectionsCount(this.httpServer);
75
+ const connections = await getConnectionsCount(this.#httpServer);
84
76
  if (connections == 0) {
85
77
  break;
86
78
  }
87
79
  if (timer.milliseconds >= timeout) {
88
- this.logger.info(`Force closing of ${connections} remaining sockets after waiting for ${timeout} milliseconds`);
89
- destroySockets(this.sockets);
80
+ this.#logger.info(`Force closing of ${connections} remaining sockets after waiting for ${timeout} milliseconds`);
81
+ destroySockets(this.#sockets);
90
82
  break;
91
83
  }
92
84
  if (connections > 0) {
93
- this.logger.info(`Waiting for ${connections} connections to end`);
85
+ this.#logger.info(`Waiting for ${connections} connections to end`);
94
86
  await cancelableTimeout(250, CancellationToken.from(close$));
95
87
  }
96
88
  }
@@ -98,7 +90,7 @@ let NodeHttpServer = class NodeHttpServer extends HttpServer {
98
90
  this.untrackConnectedSockets = undefined;
99
91
  }
100
92
  async *[Symbol.asyncIterator]() {
101
- for await (const { request, response } of this.requestIterable) {
93
+ for await (const { request, response } of this.#requestIterable) {
102
94
  yield this.handleRequest(request, response);
103
95
  }
104
96
  }
@@ -108,37 +100,35 @@ let NodeHttpServer = class NodeHttpServer extends HttpServer {
108
100
  const headers = new HttpHeaders(request.headers);
109
101
  const query = HttpQuery.fromURLSearchParams(url.searchParams);
110
102
  const context = { nodeRequest: request, nodeResponse: response };
103
+ const clientIp = getClientIp(request.socket, headers, this.#configuration);
104
+ this.#logger.verbose(`${request.method} from "${clientIp}" to "${request.url}"`);
111
105
  const httpRequest = new HttpServerRequest({
112
106
  url,
113
107
  method,
114
108
  headers,
115
109
  query,
116
- ip: request.socket.remoteAddress,
117
- body: request
110
+ ip: clientIp,
111
+ body: request,
118
112
  });
119
113
  const item = {
120
114
  request: httpRequest,
121
115
  respond: getResponder(response),
122
116
  context,
123
117
  async close() {
124
- return new Promise((resolve) => response.end(resolve));
125
- }
118
+ await new Promise((resolve) => response.end(resolve));
119
+ },
126
120
  };
127
121
  return item;
128
122
  }
129
123
  };
130
- NodeHttpServer = __decorate([
131
- Singleton(),
132
- __param(0, ResolveArg('NodeHttpServer')),
133
- __metadata("design:paramtypes", [Logger])
124
+ NodeHttpServer = NodeHttpServer_1 = __decorate([
125
+ Singleton()
134
126
  ], NodeHttpServer);
135
127
  export { NodeHttpServer };
136
- // eslint-disable-next-line max-lines-per-function
137
128
  function getResponder(httpResponse) {
138
- // eslint-disable-next-line max-statements
139
129
  async function respond(response) {
140
130
  writeHeaders(response, httpResponse);
141
- return writeResponseBody(response, httpResponse);
131
+ await writeResponseBody(response, httpResponse);
142
132
  }
143
133
  return respond;
144
134
  }
@@ -154,14 +144,16 @@ function writeHeaders(response, httpResponse) {
154
144
  }
155
145
  }
156
146
  async function writeResponseBody(response, httpResponse) {
157
- const simpleData = isDefined(response.body?.json) ? JSON.stringify(response.body.json)
158
- : isDefined(response.body?.text) ? response.body.text
159
- : isDefined(response.body?.buffer) ? response.body.buffer
160
- : undefined;
161
- const streamData = isDefined(simpleData) ? undefined
162
- : isDefined(response.body?.stream) ? response.body.stream
163
- : isDefined(response.body?.events) ? response.body.events.readable
164
- : undefined;
147
+ const simpleData = match(response.body)
148
+ .with({ json: P.select(P.nonNullable) }, (json) => JSON.stringify(json))
149
+ .with({ text: P.select(P.nonNullable) }, (text) => text)
150
+ .with({ buffer: P.select(P.nonNullable) }, (buffer) => buffer)
151
+ .otherwise(() => undefined);
152
+ const streamData = match(response.body)
153
+ .when(() => isDefined(simpleData), () => undefined)
154
+ .with({ stream: P.select(P.nonNullable) }, (stream) => stream)
155
+ .with({ events: P.select(P.nonNullable) }, (events) => events.readable)
156
+ .otherwise(() => undefined);
165
157
  if (isDefined(simpleData)) {
166
158
  const bytes = isString(simpleData) ? encodeUtf8(simpleData) : simpleData;
167
159
  if (!httpResponse.hasHeader('Content-Length')) {
@@ -173,12 +165,10 @@ async function writeResponseBody(response, httpResponse) {
173
165
  const responseStream = Writable.toWeb(httpResponse);
174
166
  await streamData.pipeTo(responseStream);
175
167
  }
176
- return new Promise((resolve) => {
177
- httpResponse.end(resolve);
178
- });
168
+ await new Promise((resolve) => httpResponse.end(resolve));
179
169
  }
180
170
  async function write(httpResponse, bytes) {
181
- return new Promise((resolve, reject) => {
171
+ await new Promise((resolve, reject) => {
182
172
  httpResponse.write(bytes, (error) => {
183
173
  if (isNullOrUndefined(error)) {
184
174
  resolve();
@@ -202,7 +192,7 @@ function trackConnectedSockets(server, sockets) {
202
192
  return () => server.removeListener('connection', connectionListener);
203
193
  }
204
194
  async function getConnectionsCount(server) {
205
- return new Promise((resolve, reject) => {
195
+ return await new Promise((resolve, reject) => {
206
196
  server.getConnections((error, count) => {
207
197
  if (error != undefined) {
208
198
  reject(error);
@@ -217,3 +207,14 @@ function destroySockets(sockets) {
217
207
  socket.destroy();
218
208
  }
219
209
  }
210
+ function getClientIp(socket, headers, configuration) {
211
+ if (configuration.trustedProxiesCount <= 0) {
212
+ return socket.remoteAddress;
213
+ }
214
+ const xForwardedForHeader = headers.tryGet('X-Forwarded-For');
215
+ if (isNullOrUndefined(xForwardedForHeader)) {
216
+ return socket.remoteAddress;
217
+ }
218
+ const ips = toArray(xForwardedForHeader).flatMap((value) => value.split(',').map((ip) => ip.trim()).filter((ip) => ip.length > 0));
219
+ return ips.at(-configuration.trustedProxiesCount) ?? socket.remoteAddress;
220
+ }
@@ -13,7 +13,7 @@ export function injectMany(...tokens) {
13
13
  return getCurrentInjectionContext(injectMany, true).injectMany(...tokens);
14
14
  }
15
15
  export async function injectAsync(token, argument, options) {
16
- return getCurrentInjectionContext(injectAsync, true).injectAsync(token, argument, options);
16
+ return await getCurrentInjectionContext(injectAsync, true).injectAsync(token, argument, options);
17
17
  }
18
18
  /**
19
19
  * Resolves tokens using the {@link Injector} of the current injection context
@@ -21,7 +21,7 @@ export async function injectAsync(token, argument, options) {
21
21
  * @param token tokens to resolve
22
22
  */
23
23
  export async function injectManyAsync(...tokens) {
24
- return getCurrentInjectionContext(injectManyAsync, true).injectManyAsync(...tokens);
24
+ return await getCurrentInjectionContext(injectManyAsync, true).injectManyAsync(...tokens);
25
25
  }
26
26
  /**
27
27
  * Resolves a token using the {@link Injector} of the current injection context
@@ -41,7 +41,7 @@ export function injectAll(token, argument, options) {
41
41
  * @param options resolve options
42
42
  */
43
43
  export async function injectAllAsync(token, argument, options) {
44
- return getCurrentInjectionContext(injectAllAsync, true).injectAllAsync(token, argument, options);
44
+ return await getCurrentInjectionContext(injectAllAsync, true).injectAllAsync(token, argument, options);
45
45
  }
46
46
  /**
47
47
  * Injects the resolve argument from the current resolution
@@ -84,9 +84,9 @@ export function runInInjectionContext(injectorOrContext, fn) {
84
84
  inject(token, argument, options) { return injectorOrContext.resolve(token, argument, options); },
85
85
  injectAll(token, argument, options) { return injectorOrContext.resolveAll(token, argument, options); },
86
86
  injectMany(...tokens) { return injectorOrContext.resolveMany(...tokens); },
87
- async injectAsync(token, argument, options) { return injectorOrContext.resolveAsync(token, argument, options); },
88
- async injectAllAsync(token, argument, options) { return injectorOrContext.resolveAllAsync(token, argument, options); },
89
- async injectManyAsync(...tokens) { return injectorOrContext.resolveManyAsync(...tokens); },
87
+ async injectAsync(token, argument, options) { return await injectorOrContext.resolveAsync(token, argument, options); },
88
+ async injectAllAsync(token, argument, options) { return await injectorOrContext.resolveAllAsync(token, argument, options); },
89
+ async injectManyAsync(...tokens) { return await injectorOrContext.resolveManyAsync(...tokens); },
90
90
  }
91
91
  : injectorOrContext;
92
92
  const previousContext = setCurrentInjectionContext(context);
@@ -486,9 +486,9 @@ export class Injector {
486
486
  inject: (token, argument, options) => this.resolveInjection(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
487
487
  injectAll: (token, argument, options) => this.resolveInjectionAll(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
488
488
  injectMany: (...tokens) => this.resolveMany(...tokens),
489
- injectAsync: async (token, argument, options) => this.resolveInjectionAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
490
- injectAllAsync: async (token, argument, options) => this.resolveInjectionAllAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
491
- injectManyAsync: async (...tokens) => this.resolveManyAsync(...tokens),
489
+ injectAsync: async (token, argument, options) => await this.resolveInjectionAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
490
+ injectAllAsync: async (token, argument, options) => await this.resolveInjectionAllAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
491
+ injectManyAsync: async (...tokens) => await this.resolveManyAsync(...tokens),
492
492
  };
493
493
  return context;
494
494
  }
@@ -1,5 +1,5 @@
1
1
  import { Component } from 'preact';
2
- import { typeExtends } from '../utils/index.js';
2
+ import { typeExtends } from '../utils/type/index.js';
3
3
  export function isComponentClass(template) {
4
4
  return typeExtends(template, Component);
5
5
  }
@@ -6,18 +6,49 @@ export declare abstract class KeyValueStore<KV extends StringMap> implements Res
6
6
  readonly module: string;
7
7
  readonly [resolveArgumentType]: KeyValueStoreArgument;
8
8
  constructor(module: string);
9
- /** Get value of key */
9
+ /**
10
+ * Gets the value of a key.
11
+ * @param key The key to get.
12
+ * @returns The value of the key or undefined if the key doesn't exist.
13
+ */
10
14
  abstract get<K extends keyof KV>(key: K): Promise<KV[K] | undefined>;
11
- /** Get value of key */
15
+ /**
16
+ * Gets the value of a key.
17
+ * @param key The key to get.
18
+ * @param defaultValue The default value to return if the key doesn't exist.
19
+ * @returns The value of the key or the default value if the key doesn't exist.
20
+ */
12
21
  abstract get<K extends keyof KV, D>(key: K, defaultValue: D): Promise<KV[K] | D>;
13
- /** Set key */
22
+ /**
23
+ * Sets the value of a key.
24
+ * @param key The key to set.
25
+ * @param value The value to set.
26
+ */
14
27
  abstract set<K extends keyof KV>(key: K, value: KV[K]): Promise<void>;
15
- /** Set multiple keys */
28
+ /**
29
+ * Get the value of a key or set it if it doesn't exist.
30
+ * @param key The key to get or set.
31
+ * @param value The value to set if the key doesn't exist.
32
+ */
33
+ abstract getOrSet<K extends keyof KV>(key: K, value: KV[K]): Promise<KV[K]>;
34
+ /**
35
+ * Sets multiple key-value pairs.
36
+ * @param keyValues The key-value pairs to set.
37
+ */
16
38
  abstract setMany(keyValues: Partial<KV>): Promise<void>;
17
- /** Delete key */
39
+ /**
40
+ * Deletes a key.
41
+ * @param key The key to delete.
42
+ * @returns True if the key was deleted, false otherwise.
43
+ */
18
44
  abstract delete(key: keyof KV): Promise<boolean>;
19
- /** Delete multiple keys */
45
+ /**
46
+ * Deletes multiple keys.
47
+ * @param keys The keys to delete.
48
+ */
20
49
  abstract deleteMany(keys: (keyof KV)[]): Promise<void>;
21
- /** Delete all keys */
50
+ /**
51
+ * Clears all key-value pairs.
52
+ */
22
53
  abstract clear(): Promise<void>;
23
54
  }
@@ -1,6 +1,7 @@
1
+ import { injectArgument } from '../injector/inject.js';
1
2
  import { resolveArgumentType } from '../injector/interfaces.js';
2
3
  export class KeyValueStore {
3
- module;
4
+ module = injectArgument(this);
4
5
  constructor(module) {
5
6
  this.module = module;
6
7
  }
@@ -7,6 +7,7 @@ export declare class MongoKeyValueStore<KV extends StringMap> extends KeyValueSt
7
7
  get<K extends keyof KV>(key: K): Promise<KV[K] | undefined>;
8
8
  get<K extends keyof KV, D>(key: K, defaultValue: D): Promise<D | KV[K]>;
9
9
  set<K extends keyof KV>(key: K, value: KV[K]): Promise<void>;
10
+ getOrSet<K extends keyof KV>(key: K, value: KV[K]): Promise<KV[K]>;
10
11
  setMany(keyValues: Partial<KV>): Promise<void>;
11
12
  delete(key: keyof KV): Promise<boolean>;
12
13
  deleteMany(keys: (keyof KV)[]): Promise<void>;
@@ -32,24 +32,33 @@ let MongoKeyValueStore = class MongoKeyValueStore extends KeyValueStore {
32
32
  const timestamp = currentTimestamp();
33
33
  const update = {
34
34
  $set: { value, updated: timestamp },
35
- $setOnInsert: { _id: getNewId() }
35
+ $setOnInsert: { _id: getNewId() },
36
36
  };
37
37
  await this.keyValueRepository.baseRepository.update({ module: this.module, key: key }, update, { upsert: true });
38
38
  }
39
+ async getOrSet(key, value) {
40
+ await this.keyValueRepository.baseRepository.insertIfNotExistsByFilter({
41
+ module: this.module,
42
+ key: key,
43
+ value,
44
+ }, { id: getNewId(), module: this.module, key: key, value, updated: currentTimestamp() });
45
+ const result = await this.get(key);
46
+ return result;
47
+ }
39
48
  async setMany(keyValues) {
40
49
  const timestamp = currentTimestamp();
41
50
  const bulk = this.keyValueRepository.baseRepository.bulk();
42
51
  for (const [key, value] of objectEntries(keyValues)) {
43
52
  const update = {
44
53
  $set: { value, updated: timestamp },
45
- $setOnInsert: { _id: getNewId() }
54
+ $setOnInsert: { _id: getNewId() },
46
55
  };
47
56
  bulk.update({ module: this.module, key }, update, { upsert: true });
48
57
  }
49
58
  await bulk.execute();
50
59
  }
51
60
  async delete(key) {
52
- return this.keyValueRepository.deleteByFilter({ module: this.module, key: key });
61
+ return await this.keyValueRepository.deleteByFilter({ module: this.module, key: key });
53
62
  }
54
63
  async deleteMany(keys) {
55
64
  await this.keyValueRepository.deleteManyByFilter({ module: this.module, key: { $in: keys } });
@@ -65,8 +74,8 @@ MongoKeyValueStore = __decorate([
65
74
  const provider = context.resolve(MongoKeyValueStoreProvider);
66
75
  assertString(argument, 'Missing or invalid argument (KV-Store module)');
67
76
  return provider.get(argument);
68
- }
69
- }
77
+ },
78
+ },
70
79
  }),
71
80
  __metadata("design:paramtypes", [MongoKeyValueRepository, String])
72
81
  ], MongoKeyValueStore);
@@ -0,0 +1,12 @@
1
+ CREATE TABLE "key_value_store"."key_value" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "module" text NOT NULL,
4
+ "key" text NOT NULL,
5
+ "value" jsonb NOT NULL,
6
+ "revision" integer NOT NULL,
7
+ "revision_timestamp" timestamp with time zone NOT NULL,
8
+ "create_timestamp" timestamp with time zone NOT NULL,
9
+ "delete_timestamp" timestamp with time zone,
10
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
11
+ CONSTRAINT "key_value_module_key_unique" UNIQUE("module","key")
12
+ );
@@ -0,0 +1,97 @@
1
+ {
2
+ "id": "9aad7b6a-d248-42fa-90ca-a7119748e2e4",
3
+ "prevId": "00000000-0000-0000-0000-000000000000",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "key_value_store.key_value": {
8
+ "name": "key_value",
9
+ "schema": "key_value_store",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "module": {
19
+ "name": "module",
20
+ "type": "text",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "key": {
25
+ "name": "key",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "value": {
31
+ "name": "value",
32
+ "type": "jsonb",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "revision": {
37
+ "name": "revision",
38
+ "type": "integer",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ },
42
+ "revision_timestamp": {
43
+ "name": "revision_timestamp",
44
+ "type": "timestamp with time zone",
45
+ "primaryKey": false,
46
+ "notNull": true
47
+ },
48
+ "create_timestamp": {
49
+ "name": "create_timestamp",
50
+ "type": "timestamp with time zone",
51
+ "primaryKey": false,
52
+ "notNull": true
53
+ },
54
+ "delete_timestamp": {
55
+ "name": "delete_timestamp",
56
+ "type": "timestamp with time zone",
57
+ "primaryKey": false,
58
+ "notNull": false
59
+ },
60
+ "attributes": {
61
+ "name": "attributes",
62
+ "type": "jsonb",
63
+ "primaryKey": false,
64
+ "notNull": true,
65
+ "default": "'{}'::jsonb"
66
+ }
67
+ },
68
+ "indexes": {},
69
+ "foreignKeys": {},
70
+ "compositePrimaryKeys": {},
71
+ "uniqueConstraints": {
72
+ "key_value_module_key_unique": {
73
+ "name": "key_value_module_key_unique",
74
+ "nullsNotDistinct": false,
75
+ "columns": [
76
+ "module",
77
+ "key"
78
+ ]
79
+ }
80
+ },
81
+ "policies": {},
82
+ "checkConstraints": {},
83
+ "isRLSEnabled": false
84
+ }
85
+ },
86
+ "enums": {},
87
+ "schemas": {},
88
+ "sequences": {},
89
+ "roles": {},
90
+ "policies": {},
91
+ "views": {},
92
+ "_meta": {
93
+ "columns": {},
94
+ "schemas": {},
95
+ "tables": {}
96
+ }
97
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1749405256053,
9
+ "tag": "0000_shocking_slipstream",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("drizzle-kit").Config;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { relative, resolve } from 'node:path';
2
+ import { defineConfig } from 'drizzle-kit';
3
+ export default defineConfig({
4
+ dialect: 'postgresql',
5
+ out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
+ schema: resolve(__dirname, './models/schemas.js'),
7
+ migrations: {
8
+ schema: 'key_value_store',
9
+ table: '_migrations',
10
+ },
11
+ });
@@ -0,0 +1,2 @@
1
+ export * from './key-value-store.service.js';
2
+ export * from './module.js';
@@ -0,0 +1,2 @@
1
+ export * from './key-value-store.service.js';
2
+ export * from './module.js';
@@ -0,0 +1,17 @@
1
+ import { type resolveArgumentType } from '../../injector/index.js';
2
+ import { Transactional } from '../../orm/server/index.js';
3
+ import type { Record } from '../../types.js';
4
+ import { KeyValueStore, type KeyValueStoreArgument } from '../key-value.store.js';
5
+ export declare class PostgresKeyValueStore<KV extends Record<string, unknown>> extends Transactional implements KeyValueStore<KV> {
6
+ #private;
7
+ readonly module: string;
8
+ readonly [resolveArgumentType]: KeyValueStoreArgument;
9
+ get<K extends keyof KV>(key: K): Promise<KV[K] | undefined>;
10
+ get<K extends keyof KV, D>(key: K, defaultValue: D): Promise<KV[K] | D>;
11
+ set<K extends keyof KV>(key: K, value: KV[K]): Promise<void>;
12
+ getOrSet<K extends keyof KV>(key: K, value: KV[K]): Promise<KV[K]>;
13
+ setMany(keyValues: Partial<KV>): Promise<void>;
14
+ delete(key: keyof KV): Promise<boolean>;
15
+ deleteMany(keys: (keyof KV)[]): Promise<void>;
16
+ clear(): Promise<void>;
17
+ }