@aidc-toolkit/app-extension 1.0.31-beta → 1.0.33-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 (45) hide show
  1. package/dist/index.cjs +1 -3709
  2. package/dist/index.d.cts +607 -333
  3. package/dist/index.d.ts +607 -333
  4. package/dist/index.js +1 -3683
  5. package/package.json +12 -13
  6. package/src/app-extension.ts +141 -93
  7. package/src/app-helper-proxy.ts +326 -0
  8. package/src/descriptor.ts +75 -7
  9. package/src/generator/generator.ts +118 -96
  10. package/src/generator/locale-resources-generator.ts +56 -42
  11. package/src/gs1/character-set-proxy.ts +8 -8
  12. package/src/gs1/check-proxy.ts +26 -25
  13. package/src/gs1/gtin-creator-proxy.ts +14 -28
  14. package/src/gs1/gtin-descriptor.ts +2 -23
  15. package/src/gs1/gtin-validator-proxy.ts +45 -48
  16. package/src/gs1/identifier-creator-proxy.ts +63 -53
  17. package/src/gs1/identifier-descriptor.ts +15 -0
  18. package/src/gs1/identifier-type.ts +37 -0
  19. package/src/gs1/identifier-validator-proxy.ts +59 -27
  20. package/src/gs1/index.ts +8 -0
  21. package/src/gs1/non-gtin-creator-proxy.ts +22 -33
  22. package/src/gs1/non-gtin-validator-proxy.ts +22 -33
  23. package/src/gs1/prefix-definition-descriptor.ts +2 -2
  24. package/src/gs1/prefix-manager-proxy.ts +164 -9
  25. package/src/gs1/service-proxy.ts +57 -0
  26. package/src/gs1/variable-measure-proxy.ts +62 -0
  27. package/src/index.ts +6 -1
  28. package/src/lib-proxy.ts +112 -70
  29. package/src/locale/en/locale-resources.ts +173 -47
  30. package/src/locale/fr/locale-resources.ts +173 -47
  31. package/src/locale/i18n.ts +8 -10
  32. package/src/locale/i18next.d.ts +2 -0
  33. package/src/proxy.ts +140 -140
  34. package/src/streaming.ts +13 -0
  35. package/src/type.ts +8 -7
  36. package/src/utility/character-set-descriptor.ts +2 -2
  37. package/src/utility/character-set-proxy.ts +39 -38
  38. package/src/utility/reg-exp-proxy.ts +12 -11
  39. package/src/utility/string-descriptor.ts +2 -2
  40. package/src/utility/string-proxy.ts +7 -7
  41. package/src/utility/transformer-descriptor.ts +5 -5
  42. package/src/utility/transformer-proxy.ts +25 -18
  43. package/dist/index.cjs.map +0 -1
  44. package/dist/index.js.map +0 -1
  45. package/src/app-utility-proxy.ts +0 -273
@@ -1,273 +0,0 @@
1
- import { isNullish, type NonNullishable, type Nullishable } from "@aidc-toolkit/core";
2
- import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "./descriptor.js";
3
- import { LibProxy } from "./lib-proxy.js";
4
- import { i18nextAppExtension } from "./locale/i18n.js";
5
- import { proxy } from "./proxy.js";
6
- import type { ErrorExtends, Matrix } from "./type.js";
7
-
8
- const spillMatrix: ParameterDescriptor = {
9
- name: "spillMatrix",
10
- type: Types.Any,
11
- isMatrix: true,
12
- isRequired: true
13
- };
14
-
15
- const spillMaximumParameterDescriptor: ParameterDescriptor = {
16
- name: "spillMaximum",
17
- type: Types.Number,
18
- isMatrix: false,
19
- isRequired: false
20
- };
21
-
22
- const spillMaximumWidthParameterDescriptor: ExtendsParameterDescriptor = {
23
- extendsDescriptor: spillMaximumParameterDescriptor,
24
- sortOrder: 0,
25
- name: "spillMaximumWidth"
26
- };
27
-
28
- const spillMaximumHeightParameterDescriptor: ExtendsParameterDescriptor = {
29
- extendsDescriptor: spillMaximumParameterDescriptor,
30
- sortOrder: 1,
31
- name: "spillMaximumHeight"
32
- };
33
-
34
- /**
35
- * Maximum dimensions.
36
- */
37
- interface MaximumDimensions {
38
- /**
39
- * Optional maximum width.
40
- */
41
- width: Nullishable<number>;
42
-
43
- /**
44
- * Optional maximum height.
45
- */
46
- height: Nullishable<number>;
47
- }
48
-
49
- /**
50
- * Application utilities.
51
- *
52
- *@template ThrowError
53
- * If true, errors are reported through the throw/catch mechanism.
54
- *
55
- * @template TError
56
- * Error type.
57
- *
58
- * @template TInvocationContext
59
- * Application-specific invocation context type.
60
- *
61
- * @template TBigInt
62
- * Type to which big integer is mapped.
63
- */
64
- @proxy.describeClass(false)
65
- export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
66
- /**
67
- * Get the version.
68
- *
69
- * @returns
70
- * Version.
71
- */
72
- @proxy.describeMethod({
73
- type: Types.String,
74
- isMatrix: false,
75
- parameterDescriptors: []
76
- })
77
- version(): string {
78
- return this.appExtension.version;
79
- }
80
-
81
- /**
82
- * Provide default values for maximum width and height if required.
83
- *
84
- * @param maximumDimensions
85
- * Maximum dimensions provided to function.
86
- *
87
- * @param invocationContext
88
- * Invocation context.
89
- *
90
- * @returns
91
- * Array of maximum width and maximum height.
92
- */
93
- async #defaultMaximums(maximumDimensions: MaximumDimensions, invocationContext: Nullishable<TInvocationContext>): Promise<NonNullishable<MaximumDimensions>> {
94
- if (isNullish(invocationContext)) {
95
- // Application error; no localization necessary.
96
- throw new Error("Invocation context not provided by application");
97
- }
98
-
99
- const maximumWidth = maximumDimensions.width;
100
- const maximumHeight = maximumDimensions.height;
101
-
102
- let definedMaximumWidth: number;
103
- let definedMaximumHeight: number;
104
-
105
- // Skip any extra work if both values are provided.
106
- if (isNullish(maximumWidth) || isNullish(maximumHeight)) {
107
- const sheetAddress = await this.appExtension.getSheetAddress(invocationContext);
108
-
109
- definedMaximumWidth = maximumWidth ?? await this.appExtension.maximumWidth() - sheetAddress.columnIndex;
110
- definedMaximumHeight = maximumHeight ?? await this.appExtension.maximumHeight() - sheetAddress.rowIndex;
111
- } else {
112
- definedMaximumWidth = maximumWidth;
113
- definedMaximumHeight = maximumHeight;
114
- }
115
-
116
- return {
117
- width: definedMaximumWidth,
118
- height: definedMaximumHeight
119
- };
120
- }
121
-
122
- /**
123
- * Spill a horizontal matrix vertically to fit within a maximum width and height.
124
- *
125
- * @param hMatrixValues
126
- * Horizontal matrix values. Matrix has length 1 and contains a single array with the values.
127
- *
128
- * @param maximumWidth
129
- * Maximum width.
130
- *
131
- * @param maximumHeight
132
- * Maximum height.
133
- *
134
- * @param invocationContext
135
- * Invocation context.
136
- *
137
- * @returns
138
- * Matrix spilled within maximum width and maximum height.
139
- */
140
- @proxy.describeMethod({
141
- requiresContext: true,
142
- type: Types.Any,
143
- isMatrix: true,
144
- parameterDescriptors: [spillMatrix, spillMaximumWidthParameterDescriptor, spillMaximumHeightParameterDescriptor]
145
- })
146
- async vSpill(hMatrixValues: Matrix<unknown>, maximumWidth: Nullishable<number>, maximumHeight: Nullishable<number>, invocationContext: Nullishable<TInvocationContext>): Promise<Matrix<unknown>> {
147
- let result: Matrix<unknown>;
148
-
149
- if (hMatrixValues.length !== 1) {
150
- throw new RangeError(i18nextAppExtension.t("Proxy.vSpillMustBeHorizontalArray"));
151
- }
152
-
153
- const maximumDimensions = await this.#defaultMaximums({
154
- width: maximumWidth,
155
- height: maximumHeight
156
- }, invocationContext);
157
-
158
- const hArrayValues = hMatrixValues[0];
159
- const hLength = hArrayValues.length;
160
- const maximumArea = maximumDimensions.width * maximumDimensions.height;
161
-
162
- // Lengths 0 and 1 are valid and require no special processing.
163
- if (hLength > 1 && hLength <= maximumArea) {
164
- // Make spill as square as possible.
165
- let spillWidth = Math.min(Math.ceil(Math.sqrt(maximumArea)), maximumDimensions.width);
166
-
167
- // Array that has a length of a power of 10 is treated specially.
168
- if (Number.isInteger(Math.log10(hLength))) {
169
- // Try spill width that is a power of 10.
170
- const spillWidth10 = 10 ** Math.floor(Math.log10(spillWidth));
171
-
172
- // Keep default if not enough space for power of 10 matrix.
173
- if (hLength / spillWidth10 <= maximumDimensions.height) {
174
- spillWidth = spillWidth10;
175
- }
176
- }
177
-
178
- result = [];
179
-
180
- let hStartIndex = 0;
181
-
182
- do {
183
- const hEndIndex = hStartIndex + spillWidth;
184
-
185
- result.push(hArrayValues.slice(hStartIndex, hEndIndex));
186
-
187
- hStartIndex = hEndIndex;
188
- } while (hStartIndex < hLength);
189
- } else {
190
- // Return matrix unmodified and let application handle spill error if any.
191
- result = hMatrixValues;
192
- }
193
-
194
- return result;
195
- }
196
-
197
- /**
198
- * Spill a vertical matrix horizontally to fit within a maximum width and height.
199
- *
200
- * @param vMatrixValues
201
- * Vertical matrix values. Matrix contains arrays of length 1 with the values.
202
- *
203
- * @param maximumHeight
204
- * Maximum height.
205
- *
206
- * @param maximumWidth
207
- * Maximum width.
208
- *
209
- * @param invocationContext
210
- * Invocation context.
211
- *
212
- * @returns
213
- * Matrix spilled within maximum height and maximum width.
214
- */
215
- @proxy.describeMethod({
216
- requiresContext: true,
217
- type: Types.Any,
218
- isMatrix: true,
219
- parameterDescriptors: [spillMatrix, spillMaximumHeightParameterDescriptor, spillMaximumWidthParameterDescriptor]
220
- })
221
- async hSpill(vMatrixValues: Matrix<unknown>, maximumHeight: Nullishable<number>, maximumWidth: Nullishable<number>, invocationContext: Nullishable<TInvocationContext>): Promise<Matrix<unknown>> {
222
- let result: Matrix<unknown>;
223
-
224
- for (const hArrayValues of vMatrixValues) {
225
- // This test should be necessary only once but account for zero-size matrix and misuse of method.
226
- if (hArrayValues.length !== 1) {
227
- throw new RangeError(i18nextAppExtension.t("Proxy.hSpillMustBeVerticalArray"));
228
- }
229
- }
230
-
231
- const maximumDimensions = await this.#defaultMaximums({
232
- width: maximumWidth,
233
- height: maximumHeight
234
- }, invocationContext);
235
-
236
- const vLength = vMatrixValues.length;
237
- const maximumArea = maximumDimensions.width * maximumDimensions.height;
238
-
239
- // Lengths 0 and 1 are valid and require no special processing.
240
- if (vLength > 1 && vLength <= maximumArea) {
241
- // Make spill as square as possible.
242
- let spillHeight = Math.min(Math.ceil(Math.sqrt(maximumArea)), maximumDimensions.height);
243
-
244
- // Array that has a length of a power of 10 is treated specially.
245
- if (Number.isInteger(Math.log10(vLength))) {
246
- // Try spill height that is a power of 10.
247
- const spillHeight10 = 10 ** Math.floor(Math.log10(spillHeight));
248
-
249
- // Keep default if not enough space for power of 10 matrix.
250
- if (vLength / spillHeight10 <= maximumDimensions.width) {
251
- spillHeight = spillHeight10;
252
- }
253
- }
254
-
255
- result = [];
256
-
257
- for (let rowIndex = 0; rowIndex < spillHeight; rowIndex++) {
258
- const row = new Array<unknown>();
259
-
260
- for (let cellIndex = rowIndex; cellIndex < vLength; cellIndex++) {
261
- row.push(vMatrixValues[cellIndex][0]);
262
- }
263
-
264
- result.push(row);
265
- }
266
- } else {
267
- // Return matrix unmodified and let application handle spill error if any.
268
- result = vMatrixValues;
269
- }
270
-
271
- return result;
272
- }
273
- }