@aidc-toolkit/app-extension 1.0.28-beta → 1.0.32-beta

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 (41) hide show
  1. package/dist/index.cjs +3463 -630
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +575 -300
  4. package/dist/index.d.ts +575 -300
  5. package/dist/index.js +3452 -613
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -9
  8. package/src/app-data.ts +94 -0
  9. package/src/app-extension.ts +162 -93
  10. package/src/app-utility-proxy.ts +154 -103
  11. package/src/descriptor.ts +33 -6
  12. package/src/generator/generator.ts +13 -12
  13. package/src/generator/locale-resources-generator.ts +30 -28
  14. package/src/gs1/character-set-proxy.ts +8 -8
  15. package/src/gs1/check-proxy.ts +14 -14
  16. package/src/gs1/gtin-creator-proxy.ts +12 -25
  17. package/src/gs1/gtin-descriptor.ts +0 -21
  18. package/src/gs1/gtin-validator-proxy.ts +34 -35
  19. package/src/gs1/identifier-creator-proxy.ts +44 -32
  20. package/src/gs1/identifier-descriptor.ts +15 -0
  21. package/src/gs1/identifier-type.ts +37 -0
  22. package/src/gs1/identifier-validator-proxy.ts +52 -19
  23. package/src/gs1/index.ts +8 -0
  24. package/src/gs1/non-gtin-creator-proxy.ts +22 -22
  25. package/src/gs1/non-gtin-validator-proxy.ts +22 -22
  26. package/src/gs1/prefix-manager-proxy.ts +199 -4
  27. package/src/gs1/service-proxy.ts +56 -0
  28. package/src/gs1/variable-measure-proxy.ts +61 -0
  29. package/src/index.ts +6 -0
  30. package/src/lib-proxy.ts +112 -70
  31. package/src/locale/en/locale-resources.ts +147 -34
  32. package/src/locale/fr/locale-resources.ts +147 -34
  33. package/src/locale/i18n.ts +2 -5
  34. package/src/proxy.ts +93 -100
  35. package/src/streaming.ts +13 -0
  36. package/src/type.ts +8 -7
  37. package/src/utility/character-set-proxy.ts +33 -32
  38. package/src/utility/reg-exp-proxy.ts +7 -6
  39. package/src/utility/string-proxy.ts +3 -7
  40. package/src/utility/transformer-proxy.ts +19 -13
  41. package/tsconfig.json +1 -0
package/src/proxy.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  type AbstractConstructor,
3
3
  type Constructor,
4
- getLogger,
5
- LogLevels,
4
+ loggableValue,
6
5
  omit,
7
6
  type TypedAbstractConstructor
8
7
  } from "@aidc-toolkit/core";
@@ -12,7 +11,8 @@ import type {
12
11
  ClassDescriptor,
13
12
  ExtendsParameterDescriptor,
14
13
  MethodDescriptor,
15
- ParameterDescriptor
14
+ ParameterDescriptor,
15
+ ReplacementParameterDescriptor
16
16
  } from "./descriptor.js";
17
17
  import { LibProxy } from "./lib-proxy.js";
18
18
  import type { ErrorExtends } from "./type.js";
@@ -20,7 +20,7 @@ import type { ErrorExtends } from "./type.js";
20
20
  /**
21
21
  * Remaining parameters past first parameter in constructor.
22
22
  */
23
- type RemainingParameters<TConstructor extends TypedAbstractConstructor<TConstructor>> =
23
+ type RemainingConstructorParameters<TConstructor extends TypedAbstractConstructor<TConstructor>> =
24
24
  TConstructor extends abstract new (arg0: infer _P0, ...args: infer P) => InstanceType<TConstructor> ? P : never;
25
25
 
26
26
  /**
@@ -37,13 +37,13 @@ type RemainingParameters<TConstructor extends TypedAbstractConstructor<TConstruc
37
37
  * Proxy class constructor type.
38
38
  */
39
39
  type ProxyClassConstructor<
40
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
41
- T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>,
40
+ ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt,
41
+ T extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>,
42
42
  IsAbstract extends boolean,
43
43
  TConstructor extends TypedAbstractConstructor<TConstructor>
44
44
  > = IsAbstract extends true ?
45
- AbstractConstructor<[appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, ...args: RemainingParameters<TConstructor>], T> :
46
- Constructor<[appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>], T>;
45
+ AbstractConstructor<[appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>, ...args: RemainingConstructorParameters<TConstructor>], T> :
46
+ Constructor<[appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>], T>;
47
47
 
48
48
  /**
49
49
  * Class decorator type. Defines the parameters passed to a class decorator function and the return type as identical to
@@ -62,11 +62,11 @@ type ProxyClassConstructor<
62
62
  * Narrowed proxy class constructor type.
63
63
  */
64
64
  type ClassDecorator<
65
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
66
- T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>,
65
+ ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt,
66
+ T extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>,
67
67
  IsAbstract extends boolean,
68
68
  TConstructor extends TypedAbstractConstructor<TConstructor>,
69
- TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor>
69
+ TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, T, IsAbstract, TConstructor>
70
70
  > = (Target: TProxyClassConstructor, context: ClassDecoratorContext<TProxyClassConstructor>) => TProxyClassConstructor;
71
71
 
72
72
  /**
@@ -87,9 +87,9 @@ type InterimMethodDescriptor = Omit<MethodDescriptor, "functionName" | "namespac
87
87
  /**
88
88
  * Subset of method descriptor used in call to decorator.
89
89
  */
90
- type DecoratorMethodDescriptor = Omit<InterimMethodDescriptor, "name" | "parameterDescriptors"> & {
90
+ interface DecoratorMethodDescriptor extends Omit<InterimMethodDescriptor, "name" | "parameterDescriptors"> {
91
91
  parameterDescriptors: Array<ParameterDescriptor | ExtendsParameterDescriptor>;
92
- };
92
+ }
93
93
 
94
94
  /**
95
95
  * Subset of class descriptor used during decoration process.
@@ -100,8 +100,8 @@ type InterimClassDescriptor =
100
100
  /**
101
101
  * Subset of class descriptor used in call to decorator.
102
102
  */
103
- interface DecoratorClassDescriptor extends Omit<InterimClassDescriptor, "replaceParameterDescriptors"> {
104
- readonly replaceParameterDescriptors?: ReadonlyArray<Omit<Required<ClassDescriptor>["replaceParameterDescriptors"][number], "replacement"> & {
103
+ interface DecoratorClassDescriptor extends Omit<InterimClassDescriptor, "replacementParameterDescriptors"> {
104
+ readonly replacementParameterDescriptors?: ReadonlyArray<Omit<ReplacementParameterDescriptor, "replacement"> & {
105
105
  readonly replacement: ParameterDescriptor | ExtendsParameterDescriptor;
106
106
  }>;
107
107
  }
@@ -144,7 +144,12 @@ interface Interim {
144
144
  */
145
145
  interface TargetLogger {
146
146
  /**
147
- * Log a method call.
147
+ * Logger.
148
+ */
149
+ readonly logger: Logger<object>;
150
+
151
+ /**
152
+ * Build a function that returns a loggable value for a method call.
148
153
  *
149
154
  * @param methodName
150
155
  * Method name.
@@ -155,18 +160,13 @@ interface TargetLogger {
155
160
  * @param result
156
161
  * Output result.
157
162
  */
158
- log: (methodName: string, args: unknown[], result: unknown) => void;
163
+ callBuilder: (methodName: string, args: unknown[], result: unknown) => () => unknown;
159
164
  }
160
165
 
161
166
  /**
162
167
  * Proxy class.
163
168
  */
164
169
  export class Proxy {
165
- /**
166
- * Logger.
167
- */
168
- readonly #logger: Logger<unknown> = getLogger(LogLevels.Info);
169
-
170
170
  /**
171
171
  * Abstract class descriptors map, keyed on declaration class name. Abstract classes are not used directly by target
172
172
  * applications.
@@ -183,49 +183,6 @@ export class Proxy {
183
183
  */
184
184
  #interim: Interim | undefined = undefined;
185
185
 
186
- /**
187
- * Get the proper JSON representation of a value.
188
- *
189
- * @param value
190
- * Value.
191
- *
192
- * @returns
193
- * Replacement value.
194
- */
195
- static #jsonValue(value: unknown): unknown {
196
- let replacementValue: unknown;
197
-
198
- switch (typeof value) {
199
- case "string":
200
- case "number":
201
- case "boolean":
202
- case "undefined":
203
- replacementValue = value;
204
- break;
205
-
206
- case "bigint":
207
- // Big integers not supported in JSON.
208
- replacementValue = value >= Number.MIN_SAFE_INTEGER && value <= Number.MAX_SAFE_INTEGER ? Number(value) : value.toString(10);
209
- break;
210
-
211
- case "object":
212
- if (value === null) {
213
- replacementValue = value;
214
- } else if (Array.isArray(value)) {
215
- replacementValue = value.map(entry => Proxy.#jsonValue(entry));
216
- } else {
217
- replacementValue = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, Proxy.#jsonValue(v)]));
218
- }
219
- break;
220
-
221
- case "symbol":
222
- case "function":
223
- throw new Error(`Unsupported ${typeof value} value type`);
224
- }
225
-
226
- return replacementValue;
227
- }
228
-
229
186
  /**
230
187
  * Describe a proxy class.
231
188
  *
@@ -251,17 +208,17 @@ export class Proxy {
251
208
  * Function with which to decorate the class.
252
209
  */
253
210
  describeClass<
254
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
255
- T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>,
211
+ ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt,
212
+ T extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>,
256
213
  IsAbstract extends boolean,
257
214
  TConstructor extends TypedAbstractConstructor<TConstructor>,
258
- TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor>
259
- >(isAbstract: IsAbstract, decoratorClassDescriptor: DecoratorClassDescriptor = {}): ClassDecorator<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor, TProxyClassConstructor> {
260
- const interimClassDescriptor: InterimClassDescriptor = decoratorClassDescriptor.replaceParameterDescriptors === undefined ?
261
- omit(decoratorClassDescriptor, "replaceParameterDescriptors") :
215
+ TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, T, IsAbstract, TConstructor>
216
+ >(isAbstract: IsAbstract, decoratorClassDescriptor: DecoratorClassDescriptor = {}): ClassDecorator<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, T, IsAbstract, TConstructor, TProxyClassConstructor> {
217
+ const interimClassDescriptor: InterimClassDescriptor = decoratorClassDescriptor.replacementParameterDescriptors === undefined ?
218
+ omit(decoratorClassDescriptor, "replacementParameterDescriptors") :
262
219
  {
263
220
  ...decoratorClassDescriptor,
264
- replaceParameterDescriptors: decoratorClassDescriptor.replaceParameterDescriptors.map(replaceParameterDescriptor => ({
221
+ replacementParameterDescriptors: decoratorClassDescriptor.replacementParameterDescriptors.map(replaceParameterDescriptor => ({
265
222
  ...replaceParameterDescriptor,
266
223
  replacement: expandParameterDescriptor(replaceParameterDescriptor.replacement)
267
224
  }))
@@ -312,7 +269,7 @@ export class Proxy {
312
269
 
313
270
  if (baseClassDescriptor !== undefined) {
314
271
  const baseClassMethodDescriptors = baseClassDescriptor.methodDescriptors;
315
- const replaceParameterDescriptors = decoratorClassDescriptor.replaceParameterDescriptors;
272
+ const replaceParameterDescriptors = decoratorClassDescriptor.replacementParameterDescriptors;
316
273
 
317
274
  if (replaceParameterDescriptors !== undefined) {
318
275
  const replacementParameterDescriptorsMap = new Map(replaceParameterDescriptors.map(replaceParameterDescriptor => [replaceParameterDescriptor.name, expandParameterDescriptor(replaceParameterDescriptor.replacement)]));
@@ -389,7 +346,7 @@ export class Proxy {
389
346
  // Third capture group, separated by optional period, is:
390
347
  // - single uppercase letter followed by zero or more characters (remainder of string); or
391
348
  // - zero characters (empty string).
392
- const objectNameGroups = /^(?<namespaceFirstWord>[A-Z]+[0-9]*|[A-Z][^A-Z.]*)(?<namespaceRemaining>[A-Z][^.]*|)\.?(?<className>[A-Z].*|)$/.exec(namespaceClassName)?.groups;
349
+ const objectNameGroups = /^(?<namespaceFirstWord>[A-Z]+[0-9]*|[A-Z][^A-Z.]*)(?<namespaceRemaining>[A-Z][^.]*|)\.?(?<className>[A-Z].*|)$/u.exec(namespaceClassName)?.groups;
393
350
 
394
351
  if (objectNameGroups === undefined) {
395
352
  throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
@@ -413,30 +370,35 @@ export class Proxy {
413
370
 
414
371
  this.#interim = undefined;
415
372
 
416
- const logger = this.#logger;
417
-
418
373
  return class extends Target implements TargetLogger {
374
+ /**
375
+ * Get the logger.
376
+ */
377
+ get logger(): Logger<object> {
378
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type hierarchy is known.
379
+ return (this as unknown as T).appExtension.logger;
380
+ }
381
+
419
382
  /**
420
383
  * @inheritDoc
421
384
  */
422
- log(methodName: string, args: unknown[], result: unknown): void {
423
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type hierarchy is known.
424
- // const appExtension = (this as unknown as T).appExtension;
425
-
426
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Method name is known to be valid at this point.
427
- const methodDescriptor = methodDescriptorsMap.get(methodName)!;
428
-
429
- logger.info(JSON.stringify({
430
- namespace: decoratorClassDescriptor.namespace,
431
- className: name,
432
- methodName,
433
- functionName: methodDescriptor.functionName,
434
- parameters: methodDescriptor.parameterDescriptors.map((parameterDescriptor, index) => ({
435
- name: parameterDescriptor.name,
436
- value: args[index]
437
- })),
438
- result: Proxy.#jsonValue(result)
439
- }, null, 2));
385
+ callBuilder(methodName: string, args: unknown[], result: unknown): () => unknown {
386
+ return () => {
387
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Method name is known to be valid at this point.
388
+ const methodDescriptor = methodDescriptorsMap.get(methodName)!;
389
+
390
+ return {
391
+ namespace: decoratorClassDescriptor.namespace,
392
+ className: name,
393
+ methodName,
394
+ functionName: methodDescriptor.functionName,
395
+ parameters: methodDescriptor.parameterDescriptors.map((parameterDescriptor, index) => ({
396
+ name: parameterDescriptor.name,
397
+ value: loggableValue(args[index])
398
+ })),
399
+ result: loggableValue(result)
400
+ };
401
+ };
440
402
  }
441
403
  };
442
404
  };
@@ -458,9 +420,14 @@ export class Proxy {
458
420
  return (target: (this: TThis, ...args: TArguments) => TReturn, context: ClassMethodDecoratorContext<TThis>): (this: TThis, ...args: TArguments) => TReturn => {
459
421
  const name = context.name;
460
422
 
461
- // Validate that method descriptor is applied within an appropriate class and has a valid name.
462
- if (this.#interim === undefined || typeof name !== "string" || context.static || context.private) {
463
- throw new Error(`${String(name)} is not defined within a supported class, has an invalid name, is static, or is private`);
423
+ // Validate that method descriptor is applied within an appropriate class.
424
+ if (this.#interim === undefined) {
425
+ throw new Error(`Class for method ${String(name)} does not have a descriptor`);
426
+ }
427
+
428
+ // Validate that method descriptor has a valid name and is neither static nor private.
429
+ if (typeof name !== "string" || context.static || context.private) {
430
+ throw new Error(`Method ${String(name)} has an invalid name, is static, or is private`);
464
431
  }
465
432
 
466
433
  let anyOptional = false;
@@ -485,10 +452,36 @@ export class Proxy {
485
452
  });
486
453
 
487
454
  return function methodProxy(this: TThis, ...args: TArguments): TReturn {
488
- const result = target.call(this, ...args);
489
-
490
455
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Class has been modified to add log method.
491
- (this as TargetLogger).log(name, args, result);
456
+ const targetLogger = this as TargetLogger;
457
+
458
+ let result: TReturn;
459
+
460
+ try {
461
+ result = target.call(this, ...args);
462
+
463
+ // Stream methods are responsible for their own logging.
464
+ if (decoratorMethodDescriptor.isStream !== true) {
465
+ if (!(result instanceof Promise)) {
466
+ targetLogger.logger.trace(targetLogger.callBuilder(name, args, result));
467
+ } else {
468
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Promise interception pattern.
469
+ result = result.then((promisedResult: unknown) => {
470
+ targetLogger.logger.trace(targetLogger.callBuilder(name, args, promisedResult));
471
+
472
+ return promisedResult;
473
+ }).catch((e: unknown) => {
474
+ targetLogger.logger.error(targetLogger.callBuilder(name, args, e));
475
+
476
+ throw e;
477
+ }) as TReturn;
478
+ }
479
+ }
480
+ } catch (e: unknown) {
481
+ targetLogger.logger.error(targetLogger.callBuilder(name, args, e));
482
+
483
+ throw e;
484
+ }
492
485
 
493
486
  return result;
494
487
  };
@@ -0,0 +1,13 @@
1
+ import type { ErrorExtends, MatrixResult } from "./type.js";
2
+
3
+ /**
4
+ * Streaming consumer callback, returned by application extension implementation.
5
+ */
6
+ export type StreamingConsumerCallback<TResult, ThrowError extends boolean, TError extends ErrorExtends<ThrowError>> =
7
+ (result: MatrixResult<TResult, ThrowError, TError>) => void;
8
+
9
+ /**
10
+ * Streaming cancelled callback, passed to application extension implementation.
11
+ */
12
+ export type StreamingCancelledCallback =
13
+ () => void;
package/src/type.ts CHANGED
@@ -68,8 +68,9 @@ export interface SheetRange extends Sheet, Range {
68
68
  export type Matrix<T> = T[][];
69
69
 
70
70
  /**
71
- * Function result, possibly including an error result. If the application framework reports errors through the return
72
- * value, the result is the union of the result type and the error type; otherwise, it's just the result type.
71
+ * Function singleton return, possibly including an error return. If the application extension reports errors through
72
+ * the return value, the result is the union of the return type and the error type; otherwise, it's just the return
73
+ * type.
73
74
  *
74
75
  * @template TResult
75
76
  * Result type.
@@ -80,12 +81,12 @@ export type Matrix<T> = T[][];
80
81
  * @template TError
81
82
  * Error type.
82
83
  */
83
- export type ResultError<TResult, ThrowError extends boolean, TError extends ErrorExtends<ThrowError>> = ThrowError extends false ? TResult | TError : TResult;
84
+ export type SingletonResult<TResult, ThrowError extends boolean, TError extends ErrorExtends<ThrowError>> = ThrowError extends false ? TResult | TError : TResult;
84
85
 
85
86
  /**
86
- * Function result as matrix, possibly including an error result in each element. If the application framework reports
87
- * errors through the return value, the individual element result is the union of the result type and the error type;
88
- * otherwise, it's just the result type.
87
+ * Function matrix return, possibly including an error return in each element. If the application extension reports
88
+ * errors through the return value, the individual element result is the union of the return type and the error type;
89
+ * otherwise, it's just the return type.
89
90
  *
90
91
  * @template TResult
91
92
  * Result type.
@@ -96,4 +97,4 @@ export type ResultError<TResult, ThrowError extends boolean, TError extends Erro
96
97
  * @template TError
97
98
  * Error type.
98
99
  */
99
- export type MatrixResultError<TResult, ThrowError extends boolean, TError extends ErrorExtends<ThrowError>> = Matrix<ResultError<TResult, ThrowError, TError>>;
100
+ export type MatrixResult<TResult, ThrowError extends boolean, TError extends ErrorExtends<ThrowError>> = Matrix<SingletonResult<TResult, ThrowError, TError>>;
@@ -11,14 +11,9 @@ import {
11
11
  Sequence
12
12
  } from "@aidc-toolkit/utility";
13
13
  import type { AppExtension } from "../app-extension.js";
14
- import {
15
- type ExtendsParameterDescriptor,
16
- type ParameterDescriptor,
17
- Types
18
- } from "../descriptor.js";
19
- import { LibProxy } from "../lib-proxy.js";
14
+ import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
20
15
  import { expandParameterDescriptor, proxy } from "../proxy.js";
21
- import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
16
+ import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
22
17
  import {
23
18
  exclusionAnyParameterDescriptor,
24
19
  exclusionFirstZeroParameterDescriptor,
@@ -46,10 +41,10 @@ const valueForSParameterDescriptor: ExtendsParameterDescriptor = {
46
41
  };
47
42
 
48
43
  @proxy.describeClass(true)
49
- export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
44
+ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
50
45
  readonly #characterSetValidator: CharacterSetValidator;
51
46
 
52
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetValidator: CharacterSetValidator) {
47
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>, characterSetValidator: CharacterSetValidator) {
53
48
  super(appExtension);
54
49
 
55
50
  this.#characterSetValidator = characterSetValidator;
@@ -60,7 +55,7 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
60
55
  isMatrix: true,
61
56
  parameterDescriptors: [validateSParameterDescriptor, exclusionNoneParameterDescriptor]
62
57
  })
63
- validate(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>): MatrixResultError<string, ThrowError, TError> {
58
+ validate(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>): Matrix<string> {
64
59
  return this.validateString(this.#characterSetValidator, matrixSs, {
65
60
  exclusion: exclusion ?? undefined
66
61
  } satisfies CharacterSetValidation);
@@ -71,16 +66,16 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
71
66
  isMatrix: true,
72
67
  parameterDescriptors: [validateSParameterDescriptor, exclusionNoneParameterDescriptor]
73
68
  })
74
- isValid(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>): MatrixResultError<boolean, ThrowError, TError> {
69
+ isValid(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>): Matrix<boolean> {
75
70
  return this.isValidString(this.validate(matrixSs, exclusion));
76
71
  }
77
72
  }
78
73
 
79
74
  @proxy.describeClass(true)
80
- export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
75
+ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
81
76
  readonly #characterSetCreator: CharacterSetCreator;
82
77
 
83
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetCreator: CharacterSetCreator) {
78
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>, characterSetCreator: CharacterSetCreator) {
84
79
  super(appExtension, characterSetCreator);
85
80
 
86
81
  this.#characterSetCreator = characterSetCreator;
@@ -91,11 +86,13 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
91
86
  isMatrix: true,
92
87
  parameterDescriptors: [lengthParameterDescriptor, valueParameterDescriptor, exclusionNoneParameterDescriptor, tweakParameterDescriptor]
93
88
  })
94
- create(length: number, matrixValues: Matrix<number | bigint>, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): MatrixResultError<string, ThrowError, TError> {
89
+ create(length: number, matrixValues: Matrix<number | bigint>, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): MatrixResult<string, ThrowError, TError> {
95
90
  const exclusionOrUndefined = exclusion ?? undefined;
96
91
  const tweakOrUndefined = tweak ?? undefined;
97
92
 
98
- return this.mapMatrix(matrixValues, value => this.#characterSetCreator.create(length, value, exclusionOrUndefined, tweakOrUndefined));
93
+ return this.matrixResult(matrixValues, value =>
94
+ this.#characterSetCreator.create(length, value, exclusionOrUndefined, tweakOrUndefined)
95
+ );
99
96
  }
100
97
 
101
98
  @proxy.describeMethod({
@@ -104,13 +101,15 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
104
101
  isMatrix: true,
105
102
  parameterDescriptors: [lengthParameterDescriptor, startValueParameterDescriptor, countParameterDescriptor, exclusionNoneParameterDescriptor, tweakParameterDescriptor]
106
103
  })
107
- createSequence(length: number, startValue: number, count: number, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): Matrix<string> {
108
- this.appExtension.validateSequenceCount(count);
109
-
104
+ createSequence(length: number, startValue: number, count: number, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): MatrixResult<string, ThrowError, TError> {
110
105
  const exclusionOrUndefined = exclusion ?? undefined;
111
106
  const tweakOrUndefined = tweak ?? undefined;
112
107
 
113
- return LibProxy.matrixResult(this.#characterSetCreator.create(length, new Sequence(startValue, count), exclusionOrUndefined, tweakOrUndefined));
108
+ return this.iterableResult(() => {
109
+ this.appExtension.validateSequenceCount(count);
110
+
111
+ return this.#characterSetCreator.create(length, new Sequence(startValue, count), exclusionOrUndefined, tweakOrUndefined);
112
+ });
114
113
  }
115
114
 
116
115
  @proxy.describeMethod({
@@ -118,40 +117,42 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
118
117
  isMatrix: true,
119
118
  parameterDescriptors: [valueForSParameterDescriptor, exclusionNoneParameterDescriptor, tweakParameterDescriptor]
120
119
  })
121
- valueFor(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): MatrixResultError<ResultError<TBigInt, ThrowError, TError>, ThrowError, TError> {
120
+ valueFor(matrixSs: Matrix<string>, exclusion: Nullishable<Exclusion>, tweak: Nullishable<number | bigint>): MatrixResult<TBigInt, ThrowError, TError> {
122
121
  const exclusionOrUndefined = exclusion ?? undefined;
123
122
  const tweakOrUndefined = tweak ?? undefined;
124
123
 
125
- return this.mapMatrix(matrixSs, s => this.mapBigInt(this.#characterSetCreator.valueFor(s, exclusionOrUndefined, tweakOrUndefined)));
124
+ return this.matrixResult(matrixSs, s =>
125
+ this.mapBigInt(this.#characterSetCreator.valueFor(s, exclusionOrUndefined, tweakOrUndefined))
126
+ );
126
127
  }
127
128
  }
128
129
 
129
130
  @proxy.describeClass(false, {
130
131
  methodInfix: "Numeric",
131
- replaceParameterDescriptors: [
132
+ replacementParameterDescriptors: [
132
133
  {
133
134
  name: expandParameterDescriptor(exclusionNoneParameterDescriptor).name,
134
135
  replacement: exclusionFirstZeroParameterDescriptor
135
136
  }
136
137
  ]
137
138
  })
138
- export class NumericProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
139
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
139
+ export class NumericProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
140
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
140
141
  super(appExtension, NUMERIC_CREATOR);
141
142
  }
142
143
  }
143
144
 
144
145
  @proxy.describeClass(false, {
145
146
  methodInfix: "Hexadecimal",
146
- replaceParameterDescriptors: [
147
+ replacementParameterDescriptors: [
147
148
  {
148
149
  name: expandParameterDescriptor(exclusionNoneParameterDescriptor).name,
149
150
  replacement: exclusionAnyParameterDescriptor
150
151
  }
151
152
  ]
152
153
  })
153
- export class HexadecimalProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
154
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
154
+ export class HexadecimalProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
155
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
155
156
  super(appExtension, HEXADECIMAL_CREATOR);
156
157
  }
157
158
  }
@@ -159,23 +160,23 @@ export class HexadecimalProxy<ThrowError extends boolean, TError extends ErrorEx
159
160
  @proxy.describeClass(false, {
160
161
  methodInfix: "Alphabetic"
161
162
  })
162
- export class AlphabeticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
163
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
163
+ export class AlphabeticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
164
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
164
165
  super(appExtension, ALPHABETIC_CREATOR);
165
166
  }
166
167
  }
167
168
 
168
169
  @proxy.describeClass(false, {
169
170
  methodInfix: "Alphanumeric",
170
- replaceParameterDescriptors: [
171
+ replacementParameterDescriptors: [
171
172
  {
172
173
  name: expandParameterDescriptor(exclusionNoneParameterDescriptor).name,
173
174
  replacement: exclusionAnyParameterDescriptor
174
175
  }
175
176
  ]
176
177
  })
177
- export class AlphanumericProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
178
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
178
+ export class AlphanumericProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
179
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
179
180
  super(appExtension, ALPHANUMERIC_CREATOR);
180
181
  }
181
182
  }
@@ -2,7 +2,7 @@ import type { Nullishable } from "@aidc-toolkit/core";
2
2
  import { RegExpValidator } from "@aidc-toolkit/utility";
3
3
  import { type ParameterDescriptor, Types } from "../descriptor.js";
4
4
  import { proxy } from "../proxy.js";
5
- import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
5
+ import type { ErrorExtends, Matrix } from "../type.js";
6
6
  import { validateSParameterDescriptor } from "./string-descriptor.js";
7
7
  import { StringProxy } from "./string-proxy.js";
8
8
 
@@ -23,18 +23,19 @@ const errorMessageParameterDescriptor: ParameterDescriptor = {
23
23
  @proxy.describeClass(false, {
24
24
  methodInfix: "RegExp"
25
25
  })
26
- export class RegExpProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
26
+ export class RegExpProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
27
27
  @proxy.describeMethod({
28
28
  type: Types.String,
29
29
  isMatrix: true,
30
30
  parameterDescriptors: [regExpParameterDescriptor, validateSParameterDescriptor, errorMessageParameterDescriptor]
31
31
  })
32
- validate(regExp: string, matrixSs: Matrix<string>, errorMessage: Nullishable<string>): MatrixResultError<string, ThrowError, TError> {
32
+ validate(regExp: string, matrixSs: Matrix<string>, errorMessage: Nullishable<string>): Matrix<string> {
33
33
  return this.validateString(new class extends RegExpValidator {
34
34
  protected override createErrorMessage(s: string): string {
35
- return errorMessage ?? super.createErrorMessage(s);
35
+ // Replace {{s}} with the invalid string.
36
+ return errorMessage?.replace(/\{\{s\}\}/ug, s) ?? super.createErrorMessage(s);
36
37
  }
37
- }(new RegExp(regExp)), matrixSs);
38
+ }(new RegExp(regExp, "u")), matrixSs);
38
39
  }
39
40
 
40
41
  @proxy.describeMethod({
@@ -42,7 +43,7 @@ export class RegExpProxy<ThrowError extends boolean, TError extends ErrorExtends
42
43
  isMatrix: true,
43
44
  parameterDescriptors: [regExpParameterDescriptor, validateSParameterDescriptor]
44
45
  })
45
- isValid(regExp: string, matrixSs: Matrix<string>): MatrixResultError<boolean, ThrowError, TError> {
46
+ isValid(regExp: string, matrixSs: Matrix<string>): Matrix<boolean> {
46
47
  return this.isValidString(this.validate(regExp, matrixSs, undefined));
47
48
  }
48
49
  }
@@ -1,15 +1,11 @@
1
1
  import type { StringValidation, StringValidator } from "@aidc-toolkit/utility";
2
2
  import { LibProxy } from "../lib-proxy.js";
3
- import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
3
+ import type { ErrorExtends, Matrix } from "../type.js";
4
4
 
5
- export abstract class StringProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
5
+ export abstract class StringProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
6
6
  protected validateString<TStringValidation extends StringValidation>(validator: StringValidator<TStringValidation>, matrixSs: Matrix<string>, validation?: TStringValidation): Matrix<string> {
7
- return LibProxy.mapMatrixRangeError(matrixSs, (s) => {
7
+ return this.matrixErrorResult(matrixSs, (s) => {
8
8
  validator.validate(s, validation);
9
9
  });
10
10
  }
11
-
12
- protected isValidString(matrixValidateResults: MatrixResultError<string, ThrowError, TError>): MatrixResultError<boolean, ThrowError, TError> {
13
- return this.mapMatrix(matrixValidateResults, validateResult => validateResult === "");
14
- }
15
11
  }