@aidc-toolkit/app-extension 1.0.25-beta → 1.0.27-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.
package/src/lib-proxy.ts CHANGED
@@ -1,25 +1,28 @@
1
1
  import { mapIterable } from "@aidc-toolkit/utility";
2
- import type { AppExtension } from "./app-extension";
3
- import { i18nextAppExtension } from "./locale/i18n";
4
- import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "./type";
2
+ import type { AppExtension } from "./app-extension.js";
3
+ import { i18nextAppExtension } from "./locale/i18n.js";
4
+ import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "./type.js";
5
5
 
6
6
  /**
7
7
  * Library proxy.
8
8
  *
9
- * @template TBigInt
10
- * Type to which big integer is mapped.
11
- *
12
9
  * @template ThrowError
13
10
  * If true, errors are reported through the throw/catch mechanism.
14
11
  *
15
12
  * @template TError
16
13
  * Error type.
14
+ *
15
+ * @template TInvocationContext
16
+ * Application-specific invocation context type.
17
+ *
18
+ * @template TBigInt
19
+ * Type to which big integer is mapped.
17
20
  */
18
21
  export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> {
19
22
  /**
20
23
  * Application extension.
21
24
  */
22
- private readonly _appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>;
25
+ readonly #appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>;
23
26
 
24
27
  /**
25
28
  * Constructor.
@@ -28,14 +31,14 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
28
31
  * Application extension.
29
32
  */
30
33
  constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
31
- this._appExtension = appExtension;
34
+ this.#appExtension = appExtension;
32
35
  }
33
36
 
34
37
  /**
35
38
  * Get the application extension.
36
39
  */
37
40
  protected get appExtension(): AppExtension<ThrowError, TError, TInvocationContext, TBigInt> {
38
- return this._appExtension;
41
+ return this.#appExtension;
39
42
  }
40
43
 
41
44
  /**
@@ -48,7 +51,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
48
51
  * Mapped big integer value.
49
52
  */
50
53
  mapBigInt(value: bigint): ResultError<TBigInt, ThrowError, TError> {
51
- return this._appExtension.mapBigInt(value);
54
+ return this.#appExtension.mapBigInt(value);
52
55
  }
53
56
 
54
57
  /**
@@ -60,13 +63,13 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
60
63
  * @returns
61
64
  * Error if errors are not thrown.
62
65
  */
63
- private handleError<TResult>(e: unknown): ResultError<TResult, ThrowError, TError> {
66
+ #handleError<TResult>(e: unknown): ResultError<TResult, ThrowError, TError> {
64
67
  let result: ResultError<TResult, ThrowError, TError>;
65
68
 
66
69
  if (e instanceof RangeError) {
67
- const error = this._appExtension.mapRangeError(e);
70
+ const error = this.#appExtension.mapRangeError(e);
68
71
 
69
- if (this._appExtension.throwError) {
72
+ if (this.#appExtension.throwError) {
70
73
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by application mapping.
71
74
  throw error as Error;
72
75
  }
@@ -94,13 +97,13 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
94
97
  * @returns
95
98
  * Callback result or error if errors are not thrown.
96
99
  */
97
- private doCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult): ResultError<TResult, ThrowError, TError> {
100
+ #doCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult): ResultError<TResult, ThrowError, TError> {
98
101
  let result: ResultError<TResult, ThrowError, TError>;
99
102
 
100
103
  try {
101
104
  result = callback(value);
102
105
  } catch (e: unknown) {
103
- result = this.handleError(e);
106
+ result = this.#handleError(e);
104
107
  }
105
108
 
106
109
  return result;
@@ -119,7 +122,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
119
122
  * Matrix of callback results and errors if errors are not thrown.
120
123
  */
121
124
  protected mapMatrix<TValue, TResult>(matrixValues: Matrix<TValue>, callback: (value: TValue) => TResult): MatrixResultError<TResult, ThrowError, TError> {
122
- return matrixValues.map(rowValues => rowValues.map(value => this.doCallback(value, callback)));
125
+ return matrixValues.map(rowValues => rowValues.map(value => this.#doCallback(value, callback)));
123
126
  }
124
127
 
125
128
  /**
@@ -134,8 +137,8 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
134
137
  * @returns
135
138
  * Callback result or error as array if errors are not thrown.
136
139
  */
137
- private doArrayCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult[]): Array<ResultError<TResult, ThrowError, TError>> {
138
- const result = this.doCallback(value, callback);
140
+ #doArrayCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult[]): Array<ResultError<TResult, ThrowError, TError>> {
141
+ const result = this.#doCallback(value, callback);
139
142
 
140
143
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled.
141
144
  return result instanceof Array ? result : [result as ResultError<TResult, ThrowError, TError>];
@@ -163,7 +166,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
163
166
  matrixResultError = [];
164
167
 
165
168
  matrixValues[0].forEach((value, columnIndex) => {
166
- const arrayResultError = this.doArrayCallback(value, callback);
169
+ const arrayResultError = this.#doArrayCallback(value, callback);
167
170
 
168
171
  arrayResultError.forEach((resultError, rowIndex) => {
169
172
  if (matrixResultError.length <= rowIndex) {
@@ -182,9 +185,9 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
182
185
  // Special case; unlikely to occur.
183
186
  arrayResultError = [];
184
187
  } else if (rowValue.length === 1) {
185
- arrayResultError = this.doArrayCallback(rowValue[0], callback);
188
+ arrayResultError = this.#doArrayCallback(rowValue[0], callback);
186
189
  } else {
187
- arrayResultError = [this.handleError(new RangeError(i18nextAppExtension.t("Proxy.matrixMustBeArray")))];
190
+ arrayResultError = [this.#handleError(new RangeError(i18nextAppExtension.t("Proxy.matrixMustBeArray")))];
188
191
  }
189
192
 
190
193
  return arrayResultError;
@@ -2,8 +2,8 @@ import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
2
2
  import { gs1Resources, i18nGS1Init } from "@aidc-toolkit/gs1";
3
3
  import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
4
4
  import i18next, { type i18n, type Resource } from "i18next";
5
- import enLocaleResources from "./en/locale-resources";
6
- import frLocaleResources from "./fr/locale-resources";
5
+ import enLocaleResources from "./en/locale-resources.js";
6
+ import frLocaleResources from "./fr/locale-resources.js";
7
7
 
8
8
  export const appExtensionNS = "aidct_app_extension";
9
9
 
@@ -24,7 +24,7 @@ export const appExtensionResources: Resource = {
24
24
  }
25
25
  };
26
26
 
27
- // Explicit type is necessary to work around bug in type discovery with linked packages.
27
+ // Explicit type is necessary because type can't be inferred without additional references.
28
28
  export const i18nextAppExtension: i18n = i18next.createInstance();
29
29
 
30
30
  /**
@@ -1,6 +1,6 @@
1
1
  import type { GS1LocaleResources } from "@aidc-toolkit/gs1";
2
2
  import type { UtilityLocaleResources } from "@aidc-toolkit/utility";
3
- import type { AppExtensionLocaleResources } from "./i18n";
3
+ import type { AppExtensionLocaleResources } from "./i18n.js";
4
4
 
5
5
  /**
6
6
  * Internationalization module.
@@ -1,4 +1,4 @@
1
- import { type ParameterDescriptor, Types } from "../descriptor";
1
+ import { type ParameterDescriptor, Types } from "../descriptor.js";
2
2
 
3
3
  const exclusionParameterDescriptor: ParameterDescriptor = {
4
4
  name: "exclusion",
@@ -10,7 +10,7 @@ import {
10
10
  NUMERIC_CREATOR,
11
11
  Sequence
12
12
  } from "@aidc-toolkit/utility";
13
- import type { AppExtension } from "../app-extension";
13
+ import type { AppExtension } from "../app-extension.js";
14
14
  import {
15
15
  expandParameterDescriptor,
16
16
  type ParameterDescriptor,
@@ -18,22 +18,22 @@ import {
18
18
  ProxyMethod,
19
19
  ProxyParameter,
20
20
  Types
21
- } from "../descriptor";
22
- import { LibProxy } from "../lib-proxy";
23
- import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type";
21
+ } from "../descriptor.js";
22
+ import { LibProxy } from "../lib-proxy.js";
23
+ import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
24
24
  import {
25
25
  exclusionAnyParameterDescriptor,
26
26
  exclusionFirstZeroParameterDescriptor,
27
27
  exclusionNoneParameterDescriptor
28
- } from "./character-set-descriptor";
29
- import { sParameterDescriptor, validateSParameterDescriptor } from "./string-descriptor";
30
- import { StringProxy } from "./string-proxy";
28
+ } from "./character-set-descriptor.js";
29
+ import { sParameterDescriptor, validateSParameterDescriptor } from "./string-descriptor.js";
30
+ import { StringProxy } from "./string-proxy.js";
31
31
  import {
32
32
  countParameterDescriptor,
33
33
  startValueParameterDescriptor,
34
34
  tweakParameterDescriptor,
35
35
  valueParameterDescriptor
36
- } from "./transformer-descriptor";
36
+ } from "./transformer-descriptor.js";
37
37
 
38
38
  const lengthParameterDescriptor: ParameterDescriptor = {
39
39
  name: "length",
@@ -48,12 +48,12 @@ const valueForSParameterDescriptor: ParameterDescriptor = {
48
48
  };
49
49
 
50
50
  export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
51
- private readonly _characterSetValidator: CharacterSetValidator;
51
+ readonly #characterSetValidator: CharacterSetValidator;
52
52
 
53
53
  protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetValidator: CharacterSetValidator) {
54
54
  super(appExtension);
55
55
 
56
- this._characterSetValidator = characterSetValidator;
56
+ this.#characterSetValidator = characterSetValidator;
57
57
  }
58
58
 
59
59
  @ProxyMethod({
@@ -64,7 +64,7 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
64
64
  @ProxyParameter(validateSParameterDescriptor) matrixSs: Matrix<string>,
65
65
  @ProxyParameter(exclusionNoneParameterDescriptor) exclusion: Nullishable<Exclusion>
66
66
  ): MatrixResultError<string, ThrowError, TError> {
67
- return this.validateString(this._characterSetValidator, matrixSs, {
67
+ return this.validateString(this.#characterSetValidator, matrixSs, {
68
68
  exclusion: exclusion ?? undefined
69
69
  } satisfies CharacterSetValidation);
70
70
  }
@@ -82,12 +82,12 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
82
82
  }
83
83
 
84
84
  export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
85
- private readonly _characterSetCreator: CharacterSetCreator;
85
+ readonly #characterSetCreator: CharacterSetCreator;
86
86
 
87
87
  protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetCreator: CharacterSetCreator) {
88
88
  super(appExtension, characterSetCreator);
89
89
 
90
- this._characterSetCreator = characterSetCreator;
90
+ this.#characterSetCreator = characterSetCreator;
91
91
  }
92
92
 
93
93
  @ProxyMethod({
@@ -103,7 +103,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
103
103
  const exclusionOrUndefined = exclusion ?? undefined;
104
104
  const tweakOrUndefined = tweak ?? undefined;
105
105
 
106
- return this.mapMatrix(matrixValues, value => this._characterSetCreator.create(length, value, exclusionOrUndefined, tweakOrUndefined));
106
+ return this.mapMatrix(matrixValues, value => this.#characterSetCreator.create(length, value, exclusionOrUndefined, tweakOrUndefined));
107
107
  }
108
108
 
109
109
  @ProxyMethod({
@@ -123,7 +123,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
123
123
  const exclusionOrUndefined = exclusion ?? undefined;
124
124
  const tweakOrUndefined = tweak ?? undefined;
125
125
 
126
- return LibProxy.matrixResult(this._characterSetCreator.create(length, new Sequence(startValue, count), exclusionOrUndefined, tweakOrUndefined));
126
+ return LibProxy.matrixResult(this.#characterSetCreator.create(length, new Sequence(startValue, count), exclusionOrUndefined, tweakOrUndefined));
127
127
  }
128
128
 
129
129
  @ProxyMethod({
@@ -138,7 +138,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
138
138
  const exclusionOrUndefined = exclusion ?? undefined;
139
139
  const tweakOrUndefined = tweak ?? undefined;
140
140
 
141
- return this.mapMatrix(matrixSs, s => this.mapBigInt(this._characterSetCreator.valueFor(s, exclusionOrUndefined, tweakOrUndefined)));
141
+ return this.mapMatrix(matrixSs, s => this.mapBigInt(this.#characterSetCreator.valueFor(s, exclusionOrUndefined, tweakOrUndefined)));
142
142
  }
143
143
  }
144
144
 
@@ -1,3 +1,3 @@
1
- export * from "./transformer-proxy";
2
- export * from "./reg-exp-proxy";
3
- export * from "./character-set-proxy";
1
+ export * from "./transformer-proxy.js";
2
+ export * from "./reg-exp-proxy.js";
3
+ export * from "./character-set-proxy.js";
@@ -1,9 +1,9 @@
1
1
  import type { Nullishable } from "@aidc-toolkit/core";
2
2
  import { RegExpValidator } from "@aidc-toolkit/utility";
3
- import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor";
4
- import type { ErrorExtends, Matrix, MatrixResultError } from "../type";
5
- import { validateSParameterDescriptor } from "./string-descriptor";
6
- import { StringProxy } from "./string-proxy";
3
+ import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor.js";
4
+ import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
5
+ import { validateSParameterDescriptor } from "./string-descriptor.js";
6
+ import { StringProxy } from "./string-proxy.js";
7
7
 
8
8
  const regExpParameterDescriptor: ParameterDescriptor = {
9
9
  name: "regExp",
@@ -1,4 +1,4 @@
1
- import { type ParameterDescriptor, Types } from "../descriptor";
1
+ import { type ParameterDescriptor, Types } from "../descriptor.js";
2
2
 
3
3
  export const sParameterDescriptor: ParameterDescriptor = {
4
4
  name: "s",
@@ -1,6 +1,6 @@
1
1
  import type { StringValidation, StringValidator } from "@aidc-toolkit/utility";
2
- import { LibProxy } from "../lib-proxy";
3
- import type { ErrorExtends, Matrix, MatrixResultError } from "../type";
2
+ import { LibProxy } from "../lib-proxy.js";
3
+ import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
4
4
 
5
5
  export abstract class StringProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
6
6
  protected validateString<TStringValidation extends StringValidation>(validator: StringValidator<TStringValidation>, matrixSs: Matrix<string>, validation?: TStringValidation): Matrix<string> {
@@ -1,4 +1,4 @@
1
- import { type ParameterDescriptor, Types } from "../descriptor";
1
+ import { type ParameterDescriptor, Types } from "../descriptor.js";
2
2
 
3
3
  export const valueParameterDescriptor: ParameterDescriptor = {
4
4
  name: "value",
@@ -1,14 +1,14 @@
1
1
  import type { Nullishable } from "@aidc-toolkit/core";
2
2
  import { mapIterable, Sequence, Transformer } from "@aidc-toolkit/utility";
3
- import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor";
4
- import { LibProxy } from "../lib-proxy";
5
- import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type";
3
+ import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor.js";
4
+ import { LibProxy } from "../lib-proxy.js";
5
+ import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
6
6
  import {
7
7
  countParameterDescriptor,
8
8
  startValueParameterDescriptor,
9
9
  tweakParameterDescriptor,
10
10
  valueParameterDescriptor
11
- } from "./transformer-descriptor";
11
+ } from "./transformer-descriptor.js";
12
12
 
13
13
  const domainParameterDescriptor: ParameterDescriptor = {
14
14
  name: "domain",
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "files": ["./eslint.config.ts", "./tsup.config.ts"]
4
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "include": ["./src/**/*"],
4
+ "compilerOptions": {
5
+ // Emit.
6
+ "outDir": "dist",
7
+
8
+ // Language and environment.
9
+ "experimentalDecorators": true
10
+ }
11
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
- "extends": "@aidc-toolkit/dev/tsconfig.json",
3
- "compilerOptions": {
4
- "experimentalDecorators": true
5
- }
2
+ "include": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig-src.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig-config.json"
9
+ }
10
+ ]
6
11
  }
package/tsup.config.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { tsupConfigAIDCToolkit } from "@aidc-toolkit/dev";
1
+ import { tsupConfig } from "@aidc-toolkit/dev";
2
+ import { defineConfig } from "tsup";
2
3
 
3
- export default tsupConfigAIDCToolkit;
4
+ export default defineConfig(tsupConfig);