@tstdl/base 0.93.139 → 0.93.141

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 (218) hide show
  1. package/README.md +166 -0
  2. package/ai/genkit/multi-region.plugin.js +5 -3
  3. package/ai/genkit/tests/multi-region.test.d.ts +1 -0
  4. package/ai/genkit/tests/multi-region.test.js +5 -2
  5. package/ai/parser/parser.js +2 -2
  6. package/ai/prompts/build.js +1 -0
  7. package/ai/prompts/instructions-formatter.d.ts +15 -2
  8. package/ai/prompts/instructions-formatter.js +36 -31
  9. package/ai/prompts/prompt-builder.js +5 -5
  10. package/ai/prompts/steering.d.ts +3 -2
  11. package/ai/prompts/steering.js +3 -1
  12. package/ai/tests/instructions-formatter.test.js +1 -0
  13. package/api/README.md +403 -0
  14. package/api/client/client.js +7 -13
  15. package/api/client/tests/api-client.test.js +10 -10
  16. package/api/default-error-handlers.js +1 -1
  17. package/api/response.d.ts +2 -2
  18. package/api/response.js +22 -33
  19. package/api/server/api-controller.d.ts +1 -1
  20. package/api/server/api-controller.js +3 -3
  21. package/api/server/api-request-token.provider.d.ts +1 -0
  22. package/api/server/api-request-token.provider.js +1 -0
  23. package/api/server/middlewares/allowed-methods.middleware.js +2 -1
  24. package/api/server/middlewares/content-type.middleware.js +2 -1
  25. package/api/types.d.ts +3 -2
  26. package/application/README.md +240 -0
  27. package/application/application.d.ts +1 -1
  28. package/application/application.js +3 -3
  29. package/application/providers.d.ts +20 -2
  30. package/application/providers.js +34 -7
  31. package/audit/README.md +267 -0
  32. package/audit/module.d.ts +5 -0
  33. package/audit/module.js +9 -1
  34. package/authentication/README.md +288 -0
  35. package/authentication/client/authentication.service.d.ts +12 -11
  36. package/authentication/client/authentication.service.js +21 -21
  37. package/authentication/client/http-client.middleware.js +2 -2
  38. package/authentication/server/module.d.ts +5 -0
  39. package/authentication/server/module.js +9 -1
  40. package/authentication/tests/authentication.api-controller.test.js +1 -1
  41. package/authentication/tests/authentication.api-request-token.provider.test.js +1 -1
  42. package/authentication/tests/authentication.client-error-handling.test.js +2 -1
  43. package/authentication/tests/authentication.client-service-refresh.test.js +5 -3
  44. package/authentication/tests/authentication.client-service.test.js +1 -1
  45. package/browser/README.md +401 -0
  46. package/cancellation/README.md +156 -0
  47. package/cancellation/tests/coverage.test.d.ts +1 -0
  48. package/cancellation/tests/coverage.test.js +49 -0
  49. package/cancellation/tests/leak.test.js +24 -29
  50. package/cancellation/tests/token.test.d.ts +1 -0
  51. package/cancellation/tests/token.test.js +136 -0
  52. package/cancellation/token.d.ts +53 -177
  53. package/cancellation/token.js +132 -208
  54. package/circuit-breaker/postgres/module.d.ts +1 -0
  55. package/circuit-breaker/postgres/module.js +5 -1
  56. package/context/README.md +174 -0
  57. package/cookie/README.md +161 -0
  58. package/css/README.md +157 -0
  59. package/data-structures/README.md +320 -0
  60. package/decorators/README.md +140 -0
  61. package/distributed-loop/README.md +231 -0
  62. package/distributed-loop/distributed-loop.js +1 -1
  63. package/document-management/README.md +403 -0
  64. package/document-management/server/configure.js +5 -1
  65. package/document-management/server/module.d.ts +1 -1
  66. package/document-management/server/module.js +1 -1
  67. package/document-management/server/services/document-management-ancillary.service.js +1 -1
  68. package/document-management/server/services/document-management.service.js +9 -7
  69. package/document-management/tests/ai-config-hierarchy.test.js +0 -5
  70. package/document-management/tests/document-management-ai-overrides.test.js +0 -1
  71. package/document-management/tests/document-management-core.test.js +2 -7
  72. package/document-management/tests/document-management.api.test.js +6 -7
  73. package/document-management/tests/document-statistics.service.test.js +11 -12
  74. package/document-management/tests/document-validation-ai-overrides.test.js +0 -1
  75. package/document-management/tests/document.service.test.js +3 -3
  76. package/document-management/tests/enum-helpers.test.js +2 -3
  77. package/dom/README.md +213 -0
  78. package/enumerable/README.md +259 -0
  79. package/enumeration/README.md +121 -0
  80. package/errors/README.md +267 -0
  81. package/examples/document-management/main.d.ts +1 -0
  82. package/examples/document-management/main.js +14 -11
  83. package/file/README.md +191 -0
  84. package/formats/README.md +210 -0
  85. package/function/README.md +144 -0
  86. package/http/README.md +318 -0
  87. package/http/client/adapters/undici.adapter.js +1 -1
  88. package/http/client/http-client-request.d.ts +6 -5
  89. package/http/client/http-client-request.js +8 -9
  90. package/http/server/node/node-http-server.js +1 -2
  91. package/image-service/README.md +137 -0
  92. package/injector/README.md +491 -0
  93. package/intl/README.md +113 -0
  94. package/json-path/README.md +182 -0
  95. package/jsx/README.md +154 -0
  96. package/key-value-store/README.md +191 -0
  97. package/key-value-store/postgres/module.d.ts +1 -0
  98. package/key-value-store/postgres/module.js +5 -1
  99. package/lock/README.md +249 -0
  100. package/lock/postgres/module.d.ts +1 -0
  101. package/lock/postgres/module.js +5 -1
  102. package/lock/web/web-lock.js +119 -47
  103. package/logger/README.md +287 -0
  104. package/mail/README.md +256 -0
  105. package/mail/module.d.ts +5 -1
  106. package/mail/module.js +11 -6
  107. package/memory/README.md +144 -0
  108. package/message-bus/README.md +244 -0
  109. package/message-bus/message-bus-base.js +1 -1
  110. package/module/README.md +182 -0
  111. package/module/module.d.ts +1 -1
  112. package/module/module.js +77 -17
  113. package/module/modules/web-server.module.js +3 -4
  114. package/notification/server/module.d.ts +1 -0
  115. package/notification/server/module.js +5 -1
  116. package/notification/tests/notification-flow.test.js +2 -2
  117. package/notification/tests/notification-type.service.test.js +24 -15
  118. package/object-storage/README.md +300 -0
  119. package/openid-connect/README.md +274 -0
  120. package/orm/README.md +423 -0
  121. package/orm/decorators.d.ts +5 -1
  122. package/orm/decorators.js +1 -1
  123. package/orm/server/drizzle/schema-converter.js +17 -30
  124. package/orm/server/encryption.d.ts +0 -1
  125. package/orm/server/encryption.js +1 -4
  126. package/orm/server/index.d.ts +1 -6
  127. package/orm/server/index.js +1 -6
  128. package/orm/server/migration.d.ts +19 -0
  129. package/orm/server/migration.js +72 -0
  130. package/orm/server/repository.d.ts +1 -1
  131. package/orm/server/transaction.d.ts +5 -10
  132. package/orm/server/transaction.js +22 -26
  133. package/orm/server/transactional.js +3 -3
  134. package/orm/tests/database-migration.test.d.ts +1 -0
  135. package/orm/tests/database-migration.test.js +82 -0
  136. package/orm/tests/encryption.test.js +3 -4
  137. package/orm/utils.d.ts +17 -2
  138. package/orm/utils.js +49 -1
  139. package/package.json +9 -6
  140. package/password/README.md +164 -0
  141. package/pdf/README.md +246 -0
  142. package/polyfills.js +1 -0
  143. package/pool/README.md +198 -0
  144. package/process/README.md +237 -0
  145. package/promise/README.md +252 -0
  146. package/promise/cancelable-promise.js +1 -1
  147. package/random/README.md +193 -0
  148. package/rate-limit/postgres/module.d.ts +1 -0
  149. package/rate-limit/postgres/module.js +5 -1
  150. package/reflection/README.md +305 -0
  151. package/reflection/decorator-data.js +11 -12
  152. package/rpc/README.md +386 -0
  153. package/rxjs-utils/README.md +262 -0
  154. package/schema/README.md +342 -0
  155. package/serializer/README.md +342 -0
  156. package/signals/implementation/README.md +134 -0
  157. package/sse/README.md +278 -0
  158. package/task-queue/README.md +293 -0
  159. package/task-queue/postgres/drizzle/{0000_simple_invisible_woman.sql → 0000_wakeful_sunspot.sql} +22 -14
  160. package/task-queue/postgres/drizzle/meta/0000_snapshot.json +160 -82
  161. package/task-queue/postgres/drizzle/meta/_journal.json +2 -2
  162. package/task-queue/postgres/module.d.ts +1 -0
  163. package/task-queue/postgres/module.js +5 -1
  164. package/task-queue/postgres/schemas.d.ts +9 -6
  165. package/task-queue/postgres/schemas.js +4 -3
  166. package/task-queue/postgres/task-queue.d.ts +4 -13
  167. package/task-queue/postgres/task-queue.js +462 -355
  168. package/task-queue/postgres/task.model.d.ts +12 -5
  169. package/task-queue/postgres/task.model.js +51 -25
  170. package/task-queue/task-context.d.ts +2 -2
  171. package/task-queue/task-context.js +8 -8
  172. package/task-queue/task-queue.d.ts +53 -19
  173. package/task-queue/task-queue.js +121 -55
  174. package/task-queue/tests/cascading-cancellations.test.d.ts +1 -0
  175. package/task-queue/tests/cascading-cancellations.test.js +38 -0
  176. package/task-queue/tests/complex.test.js +45 -229
  177. package/task-queue/tests/coverage-branch.test.d.ts +1 -0
  178. package/task-queue/tests/coverage-branch.test.js +407 -0
  179. package/task-queue/tests/coverage-enhancement.test.d.ts +1 -0
  180. package/task-queue/tests/coverage-enhancement.test.js +144 -0
  181. package/task-queue/tests/dag-dependencies.test.d.ts +1 -0
  182. package/task-queue/tests/dag-dependencies.test.js +41 -0
  183. package/task-queue/tests/dependencies.test.js +28 -26
  184. package/task-queue/tests/extensive-dependencies.test.js +64 -139
  185. package/task-queue/tests/fan-out-spawning.test.d.ts +1 -0
  186. package/task-queue/tests/fan-out-spawning.test.js +53 -0
  187. package/task-queue/tests/idempotent-replacement.test.d.ts +1 -0
  188. package/task-queue/tests/idempotent-replacement.test.js +61 -0
  189. package/task-queue/tests/missing-idempotent-tasks.test.d.ts +1 -0
  190. package/task-queue/tests/missing-idempotent-tasks.test.js +38 -0
  191. package/task-queue/tests/queue.test.js +128 -8
  192. package/task-queue/tests/worker.test.js +39 -16
  193. package/task-queue/tests/zombie-parent.test.d.ts +1 -0
  194. package/task-queue/tests/zombie-parent.test.js +45 -0
  195. package/task-queue/tests/zombie-recovery.test.d.ts +1 -0
  196. package/task-queue/tests/zombie-recovery.test.js +51 -0
  197. package/templates/README.md +287 -0
  198. package/test5.js +5 -5
  199. package/testing/README.md +157 -0
  200. package/testing/integration-setup.d.ts +4 -4
  201. package/testing/integration-setup.js +54 -29
  202. package/text/README.md +346 -0
  203. package/text/localization.service.js +2 -2
  204. package/threading/README.md +238 -0
  205. package/types/README.md +311 -0
  206. package/utils/README.md +322 -0
  207. package/utils/async-iterable-helpers/observable-iterable.d.ts +1 -1
  208. package/utils/async-iterable-helpers/observable-iterable.js +4 -8
  209. package/utils/async-iterable-helpers/take-until.js +4 -4
  210. package/utils/backoff.js +89 -30
  211. package/utils/file-reader.js +1 -2
  212. package/utils/retry-with-backoff.js +1 -1
  213. package/utils/timer.d.ts +1 -1
  214. package/utils/timer.js +5 -7
  215. package/utils/timing.d.ts +1 -1
  216. package/utils/timing.js +2 -4
  217. package/utils/z-base32.d.ts +1 -0
  218. package/utils/z-base32.js +1 -0
@@ -1,4 +1,4 @@
1
- import { type CancellationSignal } from '../../cancellation/index.js';
1
+ import { type CancellationSignal, type CancellationSource } from '../../cancellation/index.js';
2
2
  import type { OneOrMany, Record, TypedOmit, UndefinableJson, UndefinableJsonObject } from '../../types/index.js';
3
3
  import { HttpForm, type HttpFormObject } from '../http-form.js';
4
4
  import { HttpHeaders, type HttpHeadersObject } from '../http-headers.js';
@@ -23,7 +23,7 @@ export type HttpRequestAuthorization = {
23
23
  };
24
24
  export type HttpFormDataObjectValue = string | number | boolean | Uint8Array<ArrayBuffer> | Blob;
25
25
  export type HttpFormDataObject = Record<string, OneOrMany<HttpFormDataObjectValue>>;
26
- export type HttpClientRequestOptions = Partial<TypedOmit<HttpClientRequest, 'url' | 'method' | 'abortSignal' | 'abort' | 'headers' | 'query' | 'body'>> & {
26
+ export type HttpClientRequestOptions = Partial<TypedOmit<HttpClientRequest, 'url' | 'method' | 'cancellationSignal' | 'abort' | 'headers' | 'query' | 'body'>> & {
27
27
  urlParameter?: HttpUrlParametersObject | HttpUrlParameters;
28
28
  headers?: HttpHeadersObject | HttpHeaders;
29
29
  query?: HttpQueryObject | HttpQuery;
@@ -33,7 +33,7 @@ export type HttpClientRequestOptions = Partial<TypedOmit<HttpClientRequest, 'url
33
33
  form?: HttpFormObject | HttpForm;
34
34
  formData?: HttpFormDataObject | FormData;
35
35
  };
36
- abortSignal?: CancellationSignal;
36
+ cancellationSignal?: CancellationSource;
37
37
  priority?: RequestPriority;
38
38
  };
39
39
  export type HttpRequestCredentials = 'omit' | 'same-origin' | 'include';
@@ -110,9 +110,10 @@ export declare class HttpClientRequest implements Disposable {
110
110
  */
111
111
  context: Record;
112
112
  /**
113
- * Can be used to cancel the request. Throws HttpError
113
+ * Can be used to cancel the request.
114
+ * Must throw HttpError.
114
115
  */
115
- get abortSignal(): CancellationSignal;
116
+ get cancellationSignal(): CancellationSignal;
116
117
  constructor(url: string, method?: HttpMethod, options?: HttpClientRequestOptions);
117
118
  constructor(requestObject: HttpClientRequestObject);
118
119
  [Symbol.dispose](): void;
@@ -7,7 +7,7 @@ import { HttpHeaders } from '../http-headers.js';
7
7
  import { HttpQuery } from '../http-query.js';
8
8
  import { HttpUrlParameters } from '../http-url-parameters.js';
9
9
  export class HttpClientRequest {
10
- #abortToken;
10
+ #cancellationToken;
11
11
  url;
12
12
  method;
13
13
  headers;
@@ -75,10 +75,11 @@ export class HttpClientRequest {
75
75
  */
76
76
  context;
77
77
  /**
78
- * Can be used to cancel the request. Throws HttpError
78
+ * Can be used to cancel the request.
79
+ * Must throw HttpError.
79
80
  */
80
- get abortSignal() {
81
- return this.#abortToken.signal;
81
+ get cancellationSignal() {
82
+ return this.#cancellationToken.signal;
82
83
  }
83
84
  constructor(urlOrObject, method, options = {}) {
84
85
  if (isString(urlOrObject)) {
@@ -106,16 +107,14 @@ export class HttpClientRequest {
106
107
  this.timeout = requestOptions.timeout ?? 30000;
107
108
  this.throwOnNon200 = requestOptions.throwOnNon200 ?? true;
108
109
  this.context = requestOptions.context ?? {};
109
- this.#abortToken = requestOptions.abortSignal?.createChild() ?? new CancellationToken();
110
+ this.#cancellationToken = new CancellationToken(requestOptions.cancellationSignal);
110
111
  }
111
112
  [Symbol.dispose]() {
112
- this.#abortToken.set();
113
- this.#abortToken.complete();
113
+ this.#cancellationToken[Symbol.dispose]();
114
114
  }
115
115
  /** Abort the request */
116
116
  abort() {
117
- this.#abortToken.set();
118
- this.#abortToken.complete();
117
+ this.#cancellationToken.set();
119
118
  }
120
119
  clone() {
121
120
  const request = new HttpClientRequest(this);
@@ -10,7 +10,6 @@ import * as Http from 'node:http';
10
10
  import { Writable } from 'node:stream';
11
11
  import { bindNodeCallback, share } from 'rxjs';
12
12
  import { match, P } from 'ts-pattern';
13
- import { CancellationToken } from '../../../cancellation/index.js';
14
13
  import { HttpHeaders } from '../../../http/http-headers.js';
15
14
  import { HttpQuery } from '../../../http/http-query.js';
16
15
  import { afterResolve, inject, Singleton } from '../../../injector/index.js';
@@ -88,7 +87,7 @@ let NodeHttpServer = NodeHttpServer_1 = class NodeHttpServer extends HttpServer
88
87
  }
89
88
  if (connections > 0) {
90
89
  this.#logger.info(`Waiting for ${connections} connections to end`);
91
- await cancelableTimeout(250, CancellationToken.from(close$));
90
+ await cancelableTimeout(250, close$);
92
91
  }
93
92
  }
94
93
  this.#requestIterable.end();
@@ -0,0 +1,137 @@
1
+ # Image Service
2
+
3
+ A robust module for generating signed, manipulated image URLs, providing an abstract interface for image processing services with a concrete implementation for [imgproxy](https://imgproxy.net/).
4
+
5
+ ## Table of Contents
6
+
7
+ - [✨ Features](#-features)
8
+ - [Core Concepts](#core-concepts)
9
+ - [🚀 Basic Usage](#-basic-usage)
10
+ - [🔧 Advanced Topics](#-advanced-topics)
11
+ - [Image Options](#image-options)
12
+ - [Manual Instantiation](#manual-instantiation)
13
+ - [📚 API](#-api)
14
+
15
+ ## ✨ Features
16
+
17
+ - **Abstract Interface**: `ImageService` base class allows for dependency injection and easy swapping of image providers.
18
+ - **Imgproxy Support**: Full implementation for generating signed imgproxy URLs.
19
+ - **Secure Signing**: Automatically handles HMAC-SHA256 signature generation using your key and salt.
20
+ - **Rich Manipulations**: Supports resizing, cropping (gravity/origin), formatting, quality adjustment, and cache busting.
21
+ - **Type-Safe Options**: Fully typed configuration and options using TypeScript enums and classes.
22
+
23
+ ## Core Concepts
24
+
25
+ The module revolves around the `ImageService` abstract class. By depending on this abstraction in your application, you decouple your code from the specific image processing backend.
26
+
27
+ The primary implementation provided is `ImgproxyImageService`. It generates URLs that point to an imgproxy server. These URLs include:
28
+
29
+ 1. **Processing Options**: Instructions for resizing, formatting, etc.
30
+ 2. **Encoded Source URL**: The original image URL, Base64 encoded.
31
+ 3. **Signature**: A cryptographic signature ensuring the URL parameters haven't been tampered with, preventing denial-of-service attacks via image processing.
32
+
33
+ ## 🚀 Basic Usage
34
+
35
+ ### 1. Configuration
36
+
37
+ First, configure the service during your application bootstrap. This registers `ImgproxyImageService` as the implementation for `ImageService` in the dependency injection container.
38
+
39
+ ```ts
40
+ import { configureImgproxyImageService } from '@tstdl/base/image-service';
41
+
42
+ // In your bootstrap or configuration file
43
+ configureImgproxyImageService({
44
+ endpoint: 'https://images.yourdomain.com',
45
+ key: 'your-hex-encoded-key',
46
+ salt: 'your-hex-encoded-salt',
47
+ signatureSize: 32,
48
+ });
49
+ ```
50
+
51
+ ### 2. Generating URLs
52
+
53
+ Inject the `ImageService` and use `getUrl` to generate signed URLs for your images.
54
+
55
+ ```ts
56
+ import { ImageService, ImageResizeMode } from '@tstdl/base/image-service';
57
+ import { inject } from '@tstdl/base/injector';
58
+
59
+ class UserProfileController {
60
+ // Inject the abstract service
61
+ readonly #imageService = inject(ImageService);
62
+
63
+ async getAvatarUrl(originalUrl: string): Promise<string> {
64
+ // Generate a signed URL
65
+ const signedUrl = await this.#imageService.getUrl(originalUrl, {
66
+ width: 150,
67
+ height: 150,
68
+ resizeMode: ImageResizeMode.Fill,
69
+ });
70
+
71
+ return signedUrl;
72
+ // Output example:
73
+ // https://images.yourdomain.com/SIGNATURE/rs:fill:150:150/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## 🔧 Advanced Topics
79
+
80
+ ### Image Options
81
+
82
+ The `ImageOptions` class provides granular control over the output image.
83
+
84
+ ```ts
85
+ import { ImageService, ImageResizeMode, ImageOrigin, ImageFormat } from '@tstdl/base/image-service';
86
+ import { inject } from '@tstdl/base/injector';
87
+
88
+ const imageService = inject(ImageService);
89
+
90
+ const url = await imageService.getUrl('https://example.com/banner.png', {
91
+ // Resize strategy
92
+ resizeMode: ImageResizeMode.Fit, // 'fit' or 'fill'
93
+ width: 800,
94
+ height: 400,
95
+
96
+ // Gravity / Origin (where to focus when cropping)
97
+ origin: ImageOrigin.Smart, // Uses smart detection if supported, or center
98
+
99
+ // Output format and quality
100
+ format: ImageFormat.Webp,
101
+ quality: 80,
102
+
103
+ // Cache busting string (appended to processing options)
104
+ cacheBuster: 'v1.2.3',
105
+ });
106
+ ```
107
+
108
+ ### Manual Instantiation
109
+
110
+ If you need to instantiate `ImgproxyImageService` directly (outside of the DI container) or manage multiple instances with different configurations:
111
+
112
+ ```ts
113
+ import { ImgproxyImageService } from '@tstdl/base/image-service';
114
+
115
+ const imgproxy = new ImgproxyImageService(
116
+ 'https://img.example.com', // endpoint
117
+ 'aabbcc...', // key (hex)
118
+ '112233...', // salt (hex)
119
+ 32, // signature size
120
+ );
121
+
122
+ const url = await imgproxy.getUrl('http://source.com/img.jpg', { width: 100 });
123
+ ```
124
+
125
+ ## 📚 API
126
+
127
+ | Export | Type | Description |
128
+ | :------------------------------ | :--------------- | :----------------------------------------------------------------------------------------- |
129
+ | `ImageService` | `abstract class` | The base contract for image services. Defines `getUrl`. |
130
+ | `ImgproxyImageService` | `class` | Concrete implementation for imgproxy. |
131
+ | `configureImgproxyImageService` | `function` | Helper to register the imgproxy service and config in the injector. |
132
+ | `ImageOptions` | `class` | Configuration object for image manipulation (width, height, etc.). |
133
+ | `ImageResizeMode` | `enum` | Resize strategies: `Fit`, `Fill`. |
134
+ | `ImageFormat` | `enum` | Output formats: `Png`, `Jpg`, `Webp`, `Avif`, etc. |
135
+ | `ImageOrigin` | `enum` | Gravity/Origin for cropping: `Center`, `Smart`, `Top`, `TopLeft`, etc. |
136
+ | `IMGPROXY_IMAGE_SERVICE_CONFIG` | `InjectionToken` | Token used to inject the configuration object. |
137
+ | `ImgproxyImageServiceConfig` | `type` | Type definition for the configuration object (`endpoint`, `key`, `salt`, `signatureSize`). |