@aidc-toolkit/app-extension 1.0.31-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 (40) hide show
  1. package/dist/index.cjs +3446 -627
  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 +3435 -610
  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 +3 -6
  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 +82 -106
  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
package/src/proxy.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  type AbstractConstructor,
3
3
  type Constructor,
4
- getLogger,
5
- type LogLevel,
6
- LogLevels,
4
+ loggableValue,
7
5
  omit,
8
6
  type TypedAbstractConstructor
9
7
  } from "@aidc-toolkit/core";
@@ -13,7 +11,8 @@ import type {
13
11
  ClassDescriptor,
14
12
  ExtendsParameterDescriptor,
15
13
  MethodDescriptor,
16
- ParameterDescriptor
14
+ ParameterDescriptor,
15
+ ReplacementParameterDescriptor
17
16
  } from "./descriptor.js";
18
17
  import { LibProxy } from "./lib-proxy.js";
19
18
  import type { ErrorExtends } from "./type.js";
@@ -21,7 +20,7 @@ import type { ErrorExtends } from "./type.js";
21
20
  /**
22
21
  * Remaining parameters past first parameter in constructor.
23
22
  */
24
- type RemainingParameters<TConstructor extends TypedAbstractConstructor<TConstructor>> =
23
+ type RemainingConstructorParameters<TConstructor extends TypedAbstractConstructor<TConstructor>> =
25
24
  TConstructor extends abstract new (arg0: infer _P0, ...args: infer P) => InstanceType<TConstructor> ? P : never;
26
25
 
27
26
  /**
@@ -38,13 +37,13 @@ type RemainingParameters<TConstructor extends TypedAbstractConstructor<TConstruc
38
37
  * Proxy class constructor type.
39
38
  */
40
39
  type ProxyClassConstructor<
41
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
42
- 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>,
43
42
  IsAbstract extends boolean,
44
43
  TConstructor extends TypedAbstractConstructor<TConstructor>
45
44
  > = IsAbstract extends true ?
46
- AbstractConstructor<[appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, ...args: RemainingParameters<TConstructor>], T> :
47
- 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>;
48
47
 
49
48
  /**
50
49
  * Class decorator type. Defines the parameters passed to a class decorator function and the return type as identical to
@@ -63,11 +62,11 @@ type ProxyClassConstructor<
63
62
  * Narrowed proxy class constructor type.
64
63
  */
65
64
  type ClassDecorator<
66
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
67
- 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>,
68
67
  IsAbstract extends boolean,
69
68
  TConstructor extends TypedAbstractConstructor<TConstructor>,
70
- TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor>
69
+ TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, T, IsAbstract, TConstructor>
71
70
  > = (Target: TProxyClassConstructor, context: ClassDecoratorContext<TProxyClassConstructor>) => TProxyClassConstructor;
72
71
 
73
72
  /**
@@ -88,9 +87,9 @@ type InterimMethodDescriptor = Omit<MethodDescriptor, "functionName" | "namespac
88
87
  /**
89
88
  * Subset of method descriptor used in call to decorator.
90
89
  */
91
- type DecoratorMethodDescriptor = Omit<InterimMethodDescriptor, "name" | "parameterDescriptors"> & {
90
+ interface DecoratorMethodDescriptor extends Omit<InterimMethodDescriptor, "name" | "parameterDescriptors"> {
92
91
  parameterDescriptors: Array<ParameterDescriptor | ExtendsParameterDescriptor>;
93
- };
92
+ }
94
93
 
95
94
  /**
96
95
  * Subset of class descriptor used during decoration process.
@@ -101,8 +100,8 @@ type InterimClassDescriptor =
101
100
  /**
102
101
  * Subset of class descriptor used in call to decorator.
103
102
  */
104
- interface DecoratorClassDescriptor extends Omit<InterimClassDescriptor, "replaceParameterDescriptors"> {
105
- readonly replaceParameterDescriptors?: ReadonlyArray<Omit<Required<ClassDescriptor>["replaceParameterDescriptors"][number], "replacement"> & {
103
+ interface DecoratorClassDescriptor extends Omit<InterimClassDescriptor, "replacementParameterDescriptors"> {
104
+ readonly replacementParameterDescriptors?: ReadonlyArray<Omit<ReplacementParameterDescriptor, "replacement"> & {
106
105
  readonly replacement: ParameterDescriptor | ExtendsParameterDescriptor;
107
106
  }>;
108
107
  }
@@ -145,10 +144,12 @@ interface Interim {
145
144
  */
146
145
  interface TargetLogger {
147
146
  /**
148
- * Log a method call.
149
- *
150
- * @param logLevel
151
- * Log level.
147
+ * Logger.
148
+ */
149
+ readonly logger: Logger<object>;
150
+
151
+ /**
152
+ * Build a function that returns a loggable value for a method call.
152
153
  *
153
154
  * @param methodName
154
155
  * Method name.
@@ -159,20 +160,13 @@ interface TargetLogger {
159
160
  * @param result
160
161
  * Output result.
161
162
  */
162
- log: (logLevel: LogLevel, methodName: string, args: unknown[], result: unknown) => void;
163
+ callBuilder: (methodName: string, args: unknown[], result: unknown) => () => unknown;
163
164
  }
164
165
 
165
166
  /**
166
167
  * Proxy class.
167
168
  */
168
169
  export class Proxy {
169
- /**
170
- * Logger.
171
- */
172
- // TODO Add configuration parameter to output JSON.
173
- // TODO Change this to LogLevels.Trace when configuration available.
174
- readonly #logger: Logger<unknown> = getLogger(LogLevels.Info);
175
-
176
170
  /**
177
171
  * Abstract class descriptors map, keyed on declaration class name. Abstract classes are not used directly by target
178
172
  * applications.
@@ -189,49 +183,6 @@ export class Proxy {
189
183
  */
190
184
  #interim: Interim | undefined = undefined;
191
185
 
192
- /**
193
- * Get the proper JSON representation of a value.
194
- *
195
- * @param value
196
- * Value.
197
- *
198
- * @returns
199
- * Replacement value.
200
- */
201
- static #jsonValue(value: unknown): unknown {
202
- let replacementValue: unknown;
203
-
204
- switch (typeof value) {
205
- case "string":
206
- case "number":
207
- case "boolean":
208
- case "undefined":
209
- replacementValue = value;
210
- break;
211
-
212
- case "bigint":
213
- // Big integers not supported in JSON.
214
- replacementValue = value >= Number.MIN_SAFE_INTEGER && value <= Number.MAX_SAFE_INTEGER ? Number(value) : value.toString(10);
215
- break;
216
-
217
- case "object":
218
- if (value === null) {
219
- replacementValue = value;
220
- } else if (Array.isArray(value)) {
221
- replacementValue = value.map(entry => Proxy.#jsonValue(entry));
222
- } else {
223
- replacementValue = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, Proxy.#jsonValue(v)]));
224
- }
225
- break;
226
-
227
- case "symbol":
228
- case "function":
229
- throw new Error(`Unsupported ${typeof value} value type`);
230
- }
231
-
232
- return replacementValue;
233
- }
234
-
235
186
  /**
236
187
  * Describe a proxy class.
237
188
  *
@@ -257,17 +208,17 @@ export class Proxy {
257
208
  * Function with which to decorate the class.
258
209
  */
259
210
  describeClass<
260
- ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt,
261
- 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>,
262
213
  IsAbstract extends boolean,
263
214
  TConstructor extends TypedAbstractConstructor<TConstructor>,
264
- TProxyClassConstructor extends ProxyClassConstructor<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor>
265
- >(isAbstract: IsAbstract, decoratorClassDescriptor: DecoratorClassDescriptor = {}): ClassDecorator<ThrowError, TError, TInvocationContext, TBigInt, T, IsAbstract, TConstructor, TProxyClassConstructor> {
266
- const interimClassDescriptor: InterimClassDescriptor = decoratorClassDescriptor.replaceParameterDescriptors === undefined ?
267
- 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") :
268
219
  {
269
220
  ...decoratorClassDescriptor,
270
- replaceParameterDescriptors: decoratorClassDescriptor.replaceParameterDescriptors.map(replaceParameterDescriptor => ({
221
+ replacementParameterDescriptors: decoratorClassDescriptor.replacementParameterDescriptors.map(replaceParameterDescriptor => ({
271
222
  ...replaceParameterDescriptor,
272
223
  replacement: expandParameterDescriptor(replaceParameterDescriptor.replacement)
273
224
  }))
@@ -318,7 +269,7 @@ export class Proxy {
318
269
 
319
270
  if (baseClassDescriptor !== undefined) {
320
271
  const baseClassMethodDescriptors = baseClassDescriptor.methodDescriptors;
321
- const replaceParameterDescriptors = decoratorClassDescriptor.replaceParameterDescriptors;
272
+ const replaceParameterDescriptors = decoratorClassDescriptor.replacementParameterDescriptors;
322
273
 
323
274
  if (replaceParameterDescriptors !== undefined) {
324
275
  const replacementParameterDescriptorsMap = new Map(replaceParameterDescriptors.map(replaceParameterDescriptor => [replaceParameterDescriptor.name, expandParameterDescriptor(replaceParameterDescriptor.replacement)]));
@@ -395,7 +346,7 @@ export class Proxy {
395
346
  // Third capture group, separated by optional period, is:
396
347
  // - single uppercase letter followed by zero or more characters (remainder of string); or
397
348
  // - zero characters (empty string).
398
- 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;
399
350
 
400
351
  if (objectNameGroups === undefined) {
401
352
  throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
@@ -419,30 +370,35 @@ export class Proxy {
419
370
 
420
371
  this.#interim = undefined;
421
372
 
422
- const logger = this.#logger;
423
-
424
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
+
425
382
  /**
426
383
  * @inheritDoc
427
384
  */
428
- log(logLevel: LogLevel, methodName: string, args: unknown[], result: unknown): void {
429
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type hierarchy is known.
430
- // const appExtension = (this as unknown as T).appExtension;
431
-
432
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Method name is known to be valid at this point.
433
- const methodDescriptor = methodDescriptorsMap.get(methodName)!;
434
-
435
- logger.log(logLevel, "", JSON.stringify({
436
- namespace: decoratorClassDescriptor.namespace,
437
- className: name,
438
- methodName,
439
- functionName: methodDescriptor.functionName,
440
- parameters: methodDescriptor.parameterDescriptors.map((parameterDescriptor, index) => ({
441
- name: parameterDescriptor.name,
442
- value: args[index]
443
- })),
444
- result: Proxy.#jsonValue(result)
445
- }, 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
+ };
446
402
  }
447
403
  };
448
404
  };
@@ -464,9 +420,14 @@ export class Proxy {
464
420
  return (target: (this: TThis, ...args: TArguments) => TReturn, context: ClassMethodDecoratorContext<TThis>): (this: TThis, ...args: TArguments) => TReturn => {
465
421
  const name = context.name;
466
422
 
467
- // Validate that method descriptor is applied within an appropriate class and has a valid name.
468
- if (this.#interim === undefined || typeof name !== "string" || context.static || context.private) {
469
- 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`);
470
431
  }
471
432
 
472
433
  let anyOptional = false;
@@ -499,10 +460,25 @@ export class Proxy {
499
460
  try {
500
461
  result = target.call(this, ...args);
501
462
 
502
- // TODO Change this to LogLevels.Trace when configuration available.
503
- targetLogger.log(LogLevels.Info, name, args, result);
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
+ }
504
480
  } catch (e: unknown) {
505
- targetLogger.log(LogLevels.Error, name, args, e instanceof Error ? `${e.name}: ${e.message}` : `Unknown exception: ${String(e)}`);
481
+ targetLogger.logger.error(targetLogger.callBuilder(name, args, e));
506
482
 
507
483
  throw e;
508
484
  }
@@ -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
  }