@aidc-toolkit/app-extension 0.9.19-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 (112) hide show
  1. package/LICENSE +174 -0
  2. package/README.md +17 -0
  3. package/app-extension.iml +9 -0
  4. package/dist/app-extension.d.ts +169 -0
  5. package/dist/app-extension.d.ts.map +1 -0
  6. package/dist/app-extension.js +148 -0
  7. package/dist/app-extension.js.map +1 -0
  8. package/dist/app-utility-proxy.d.ts +66 -0
  9. package/dist/app-utility-proxy.d.ts.map +1 -0
  10. package/dist/app-utility-proxy.js +233 -0
  11. package/dist/app-utility-proxy.js.map +1 -0
  12. package/dist/descriptor.d.ts +168 -0
  13. package/dist/descriptor.d.ts.map +1 -0
  14. package/dist/descriptor.js +175 -0
  15. package/dist/descriptor.js.map +1 -0
  16. package/dist/gs1/character-set-proxy.d.ts +10 -0
  17. package/dist/gs1/character-set-proxy.d.ts.map +1 -0
  18. package/dist/gs1/character-set-proxy.js +47 -0
  19. package/dist/gs1/character-set-proxy.js.map +1 -0
  20. package/dist/gs1/check-proxy.d.ts +11 -0
  21. package/dist/gs1/check-proxy.d.ts.map +1 -0
  22. package/dist/gs1/check-proxy.js +120 -0
  23. package/dist/gs1/check-proxy.js.map +1 -0
  24. package/dist/gs1/idkey-proxy.d.ts +135 -0
  25. package/dist/gs1/idkey-proxy.d.ts.map +1 -0
  26. package/dist/gs1/idkey-proxy.js +779 -0
  27. package/dist/gs1/idkey-proxy.js.map +1 -0
  28. package/dist/gs1/index.d.ts +4 -0
  29. package/dist/gs1/index.d.ts.map +1 -0
  30. package/dist/gs1/index.js +4 -0
  31. package/dist/gs1/index.js.map +1 -0
  32. package/dist/index.d.ts +25 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +25 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/lib-proxy.d.ts +135 -0
  37. package/dist/lib-proxy.d.ts.map +1 -0
  38. package/dist/lib-proxy.js +235 -0
  39. package/dist/lib-proxy.js.map +1 -0
  40. package/dist/locale/en/locale-strings.d.ts +616 -0
  41. package/dist/locale/en/locale-strings.d.ts.map +1 -0
  42. package/dist/locale/en/locale-strings.js +616 -0
  43. package/dist/locale/en/locale-strings.js.map +1 -0
  44. package/dist/locale/fr/locale-strings.d.ts +616 -0
  45. package/dist/locale/fr/locale-strings.d.ts.map +1 -0
  46. package/dist/locale/fr/locale-strings.js +616 -0
  47. package/dist/locale/fr/locale-strings.js.map +1 -0
  48. package/dist/locale/i18n.d.ts +27 -0
  49. package/dist/locale/i18n.d.ts.map +1 -0
  50. package/dist/locale/i18n.js +39 -0
  51. package/dist/locale/i18n.js.map +1 -0
  52. package/dist/types.d.ts +127 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +13 -0
  55. package/dist/types.js.map +1 -0
  56. package/dist/utility/character-set-descriptor.d.ts +6 -0
  57. package/dist/utility/character-set-descriptor.d.ts.map +1 -0
  58. package/dist/utility/character-set-descriptor.js +28 -0
  59. package/dist/utility/character-set-descriptor.js.map +1 -0
  60. package/dist/utility/character-set-proxy.d.ts +26 -0
  61. package/dist/utility/character-set-proxy.d.ts.map +1 -0
  62. package/dist/utility/character-set-proxy.js +167 -0
  63. package/dist/utility/character-set-proxy.js.map +1 -0
  64. package/dist/utility/index.d.ts +4 -0
  65. package/dist/utility/index.d.ts.map +1 -0
  66. package/dist/utility/index.js +4 -0
  67. package/dist/utility/index.js.map +1 -0
  68. package/dist/utility/reg-exp-proxy.d.ts +7 -0
  69. package/dist/utility/reg-exp-proxy.d.ts.map +1 -0
  70. package/dist/utility/reg-exp-proxy.js +61 -0
  71. package/dist/utility/reg-exp-proxy.js.map +1 -0
  72. package/dist/utility/string-descriptor.d.ts +4 -0
  73. package/dist/utility/string-descriptor.d.ts.map +1 -0
  74. package/dist/utility/string-descriptor.js +12 -0
  75. package/dist/utility/string-descriptor.js.map +1 -0
  76. package/dist/utility/string-proxy.d.ts +8 -0
  77. package/dist/utility/string-proxy.d.ts.map +1 -0
  78. package/dist/utility/string-proxy.js +12 -0
  79. package/dist/utility/string-proxy.js.map +1 -0
  80. package/dist/utility/transformer-descriptor.d.ts +6 -0
  81. package/dist/utility/transformer-descriptor.d.ts.map +1 -0
  82. package/dist/utility/transformer-descriptor.js +24 -0
  83. package/dist/utility/transformer-descriptor.js.map +1 -0
  84. package/dist/utility/transformer-proxy.d.ts +8 -0
  85. package/dist/utility/transformer-proxy.d.ts.map +1 -0
  86. package/dist/utility/transformer-proxy.js +74 -0
  87. package/dist/utility/transformer-proxy.js.map +1 -0
  88. package/eslint.config.ts +21 -0
  89. package/package.json +37 -0
  90. package/src/app-extension.ts +244 -0
  91. package/src/app-utility-proxy.ts +266 -0
  92. package/src/descriptor.ts +314 -0
  93. package/src/gs1/character-set-proxy.ts +41 -0
  94. package/src/gs1/check-proxy.ts +122 -0
  95. package/src/gs1/idkey-proxy.ts +815 -0
  96. package/src/gs1/index.ts +3 -0
  97. package/src/index.ts +24 -0
  98. package/src/lib-proxy.ts +256 -0
  99. package/src/locale/en/locale-strings.ts +615 -0
  100. package/src/locale/fr/locale-strings.ts +615 -0
  101. package/src/locale/i18n.ts +48 -0
  102. package/src/locale/i18next.d.ts +20 -0
  103. package/src/types.ts +144 -0
  104. package/src/utility/character-set-descriptor.ts +32 -0
  105. package/src/utility/character-set-proxy.ts +185 -0
  106. package/src/utility/index.ts +3 -0
  107. package/src/utility/reg-exp-proxy.ts +51 -0
  108. package/src/utility/string-descriptor.ts +13 -0
  109. package/src/utility/string-proxy.ts +15 -0
  110. package/src/utility/transformer-descriptor.ts +27 -0
  111. package/src/utility/transformer-proxy.ts +72 -0
  112. package/tsconfig.json +6 -0
@@ -0,0 +1,3 @@
1
+ export * from "./character-set-proxy.js";
2
+ export * from "./check-proxy.js";
3
+ export * from "./idkey-proxy.js";
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
3
+ * contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from "./locale/i18n.js";
18
+ export * from "./types.js";
19
+ export * from "./app-extension.js";
20
+ export * from "./lib-proxy.js";
21
+ export * from "./descriptor.js";
22
+ export * from "./app-utility-proxy.js";
23
+ export * from "./utility/index.js";
24
+ export * as GS1 from "./gs1/index.js";
@@ -0,0 +1,256 @@
1
+ import { mapIterable } from "@aidc-toolkit/utility";
2
+ import type { AppExtension } from "./app-extension.js";
3
+ import { i18nextAppExtension } from "./locale/i18n.js";
4
+ import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "./types.js";
5
+
6
+ /**
7
+ * Library proxy.
8
+ *
9
+ * @template TBigInt
10
+ * Type to which big integer is mapped.
11
+ *
12
+ * @template ThrowError
13
+ * If true, errors are reported through the throw/catch mechanism.
14
+ *
15
+ * @template TError
16
+ * Error type.
17
+ */
18
+ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> {
19
+ /**
20
+ * Application extension.
21
+ */
22
+ private readonly _appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>;
23
+
24
+ /**
25
+ * Constructor.
26
+ *
27
+ * @param appExtension
28
+ * Application extension.
29
+ */
30
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
31
+ this._appExtension = appExtension;
32
+ }
33
+
34
+ /**
35
+ * Get the application extension.
36
+ */
37
+ protected get appExtension(): AppExtension<ThrowError, TError, TInvocationContext, TBigInt> {
38
+ return this._appExtension;
39
+ }
40
+
41
+ /**
42
+ * Map big integer to another type if necessary.
43
+ *
44
+ * @param value
45
+ * Big integer value to map.
46
+ *
47
+ * @returns
48
+ * Mapped big integer value.
49
+ */
50
+ mapBigInt(value: bigint): ResultError<TBigInt, ThrowError, TError> {
51
+ return this._appExtension.mapBigInt(value);
52
+ }
53
+
54
+ /**
55
+ * Handle an error thrown by a function call.
56
+ *
57
+ * @param e
58
+ * Error.
59
+ *
60
+ * @returns
61
+ * Error if errors are not thrown.
62
+ */
63
+ private handleError<TResult>(e: unknown): ResultError<TResult, ThrowError, TError> {
64
+ let result: ResultError<TResult, ThrowError, TError>;
65
+
66
+ if (e instanceof RangeError) {
67
+ const error = this._appExtension.mapRangeError(e);
68
+
69
+ if (this._appExtension.throwError) {
70
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by application mapping.
71
+ throw error as Error;
72
+ }
73
+
74
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled above.
75
+ result = error as ResultError<TResult, ThrowError, TError>;
76
+ } else {
77
+ // Unknown error; pass up the stack.
78
+ // eslint-disable-next-line @typescript-eslint/only-throw-error -- Error is being passed on from elsewhere.
79
+ throw e;
80
+ }
81
+
82
+ return result;
83
+ }
84
+
85
+ /**
86
+ * Do the callback for a simple return.
87
+ *
88
+ * @param value
89
+ * Value.
90
+ *
91
+ * @param callback
92
+ * Callback.
93
+ *
94
+ * @returns
95
+ * Callback result or error if errors are not thrown.
96
+ */
97
+ private doCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult): ResultError<TResult, ThrowError, TError> {
98
+ let result: ResultError<TResult, ThrowError, TError>;
99
+
100
+ try {
101
+ result = callback(value);
102
+ } catch (e: unknown) {
103
+ result = this.handleError(e);
104
+ }
105
+
106
+ return result;
107
+ }
108
+
109
+ /**
110
+ * Map a matrix of values using a callback.
111
+ *
112
+ * @param matrixValues
113
+ * Matrix of values.
114
+ *
115
+ * @param callback
116
+ * Callback.
117
+ *
118
+ * @returns
119
+ * Matrix of callback results and errors if errors are not thrown.
120
+ */
121
+ 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)));
123
+ }
124
+
125
+ /**
126
+ * Do the callback for an array return.
127
+ *
128
+ * @param value
129
+ * Value.
130
+ *
131
+ * @param callback
132
+ * Callback.
133
+ *
134
+ * @returns
135
+ * Callback result or error as array if errors are not thrown.
136
+ */
137
+ private doArrayCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult[]): Array<ResultError<TResult, ThrowError, TError>> {
138
+ const result = this.doCallback(value, callback);
139
+
140
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled.
141
+ return result instanceof Array ? result : [result as ResultError<TResult, ThrowError, TError>];
142
+ }
143
+
144
+ /**
145
+ * Map a one-dimensional matrix of values using a callback.
146
+ *
147
+ * @param matrixValues
148
+ * Matrix of values.
149
+ *
150
+ * @param callback
151
+ * Callback.
152
+ *
153
+ * @returns
154
+ * Matrix of callback results and errors if errors are not thrown.
155
+ */
156
+ protected mapArray<TValue, TResult>(matrixValues: Matrix<TValue>, callback: (value: TValue) => TResult[]): MatrixResultError<TResult, ThrowError, TError> {
157
+ let matrixResultError: MatrixResultError<TResult, ThrowError, TError>;
158
+
159
+ if (matrixValues.length === 0) {
160
+ // Special case; unlikely to occur.
161
+ matrixResultError = [[]];
162
+ } else if (matrixValues.length === 1) {
163
+ matrixResultError = [];
164
+
165
+ matrixValues[0].forEach((value, columnIndex) => {
166
+ const arrayResultError = this.doArrayCallback(value, callback);
167
+
168
+ arrayResultError.forEach((resultError, rowIndex) => {
169
+ if (matrixResultError.length <= rowIndex) {
170
+ matrixResultError.push([]);
171
+ }
172
+
173
+ // Assignment will automatically expand array.
174
+ matrixResultError[rowIndex][columnIndex] = resultError;
175
+ });
176
+ });
177
+ } else {
178
+ matrixResultError = matrixValues.map((rowValue) => {
179
+ let arrayResultError: Array<ResultError<TResult, ThrowError, TError>>;
180
+
181
+ if (rowValue.length === 0) {
182
+ // Special case; unlikely to occur.
183
+ arrayResultError = [];
184
+ } else if (rowValue.length === 1) {
185
+ arrayResultError = this.doArrayCallback(rowValue[0], callback);
186
+ } else {
187
+ arrayResultError = [this.handleError(new RangeError(i18nextAppExtension.t("Proxy.matrixMustBeArray")))];
188
+ }
189
+
190
+ return arrayResultError;
191
+ });
192
+ }
193
+
194
+ return matrixResultError;
195
+ }
196
+
197
+ /**
198
+ * Map a matrix of values to a matrix of strings via a callback that either returns or throws a range error. If the
199
+ * callback returns, the result for that element is the empty string; otherwise, if it's a range error, the result
200
+ * for that element is the error message.
201
+ *
202
+ * @param matrixValues
203
+ * Matrix to map.
204
+ *
205
+ * @param callback
206
+ * Callback that either returns or throws an exception.
207
+ *
208
+ * @returns
209
+ * Matrix of strings.
210
+ *
211
+ * @template TValue
212
+ * Value type.
213
+ */
214
+ protected static mapMatrixRangeError<TValue>(matrixValues: Matrix<TValue>, callback: (value: TValue) => void): Matrix<string> {
215
+ return matrixValues.map(rowValues => rowValues.map((value) => {
216
+ let result: string;
217
+
218
+ try {
219
+ callback(value);
220
+
221
+ // No error; return empty string.
222
+ result = "";
223
+ } catch (e: unknown) {
224
+ if (e instanceof RangeError) {
225
+ // Library error; return error message.
226
+ result = e.message;
227
+ } else {
228
+ // Unknown error; pass up the stack.
229
+ throw e instanceof Error ?
230
+ e :
231
+ new Error("Unknown error", {
232
+ cause: e
233
+ });
234
+ }
235
+ }
236
+
237
+ return result;
238
+ }));
239
+ }
240
+
241
+ /**
242
+ * Convert an iterable result of a callback to a matrix result. Although the natural approach would be to map to a
243
+ * single-element array containing an array of *N* results (i.e., [[r0, r1, r2, ..., r*N*]]), this is rendered
244
+ * visually as a single row. The more readable approach is as a single column, so the mapping is to an *N*-element
245
+ * array of single-element result arrays (i.e., [[r0], [r1], [r2], ..., [r*N*]]).
246
+ *
247
+ * @param iterableResult
248
+ * Iterable result.
249
+ *
250
+ * @returns
251
+ * Matrix of callback results.
252
+ */
253
+ protected static matrixResult<TResult>(iterableResult: Iterable<TResult>): Matrix<TResult> {
254
+ return Array.from(mapIterable(iterableResult, result => [result]));
255
+ }
256
+ }