@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,42 +1,197 @@
1
1
  import type { Nullishable } from "@aidc-toolkit/core";
2
- import type { PrefixType } from "@aidc-toolkit/gs1";
3
- import { type ParameterDescriptor, Types } from "../descriptor.js";
2
+ import {
3
+ type GCPLengthCache,
4
+ type GCPLengthData,
5
+ PrefixManager,
6
+ type PrefixType,
7
+ RemoteGCPLengthCache
8
+ } from "@aidc-toolkit/gs1";
9
+ import type { Logger } from "tslog";
10
+ import type { AppExtension } from "../app-extension.js";
11
+ import { type ExtendsParameterDescriptor, Multiplicities, type ParameterDescriptor, Types } from "../descriptor.js";
4
12
  import { LibProxy } from "../lib-proxy.js";
5
13
  import { proxy } from "../proxy.js";
6
- import type { ErrorExtends, Matrix } from "../type.js";
14
+ import type { ErrorExtends, Matrix, MatrixResult, SingletonResult } from "../type.js";
15
+ import { identifierParameterDescriptor, identifierTypeParameterDescriptor } from "./identifier-descriptor.js";
16
+ import { validateIdentifierType } from "./identifier-type.js";
7
17
 
8
18
  const prefixParameterDescriptor: ParameterDescriptor = {
9
19
  name: "prefix",
10
20
  type: Types.String,
11
- isMatrix: false,
21
+ multiplicity: Multiplicities.Singleton,
12
22
  isRequired: true
13
23
  };
14
24
 
15
25
  const prefixTypeParameterDescriptor: ParameterDescriptor = {
16
26
  name: "prefixType",
17
27
  type: Types.Number,
18
- isMatrix: false,
28
+ multiplicity: Multiplicities.Singleton,
19
29
  isRequired: false
20
30
  };
21
31
 
22
32
  const tweakFactorParameterDescriptor: ParameterDescriptor = {
23
33
  name: "tweakFactor",
24
34
  type: Types.Number,
25
- isMatrix: false,
35
+ multiplicity: Multiplicities.Singleton,
26
36
  isRequired: false
27
37
  };
28
38
 
39
+ const gcpLengthIdentifierParameterDescriptor: ExtendsParameterDescriptor = {
40
+ extendsDescriptor: identifierParameterDescriptor,
41
+ name: "gcpLengthIdentifier"
42
+ };
43
+
44
+ /**
45
+ * Application extension GCP length cache. Data is stored in application extension shared data.
46
+ */
47
+ class AppExtensionGCPLengthCache<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends RemoteGCPLengthCache {
48
+ /**
49
+ * Logger.
50
+ */
51
+ readonly #logger: Logger<object>;
52
+
53
+ /**
54
+ * Constructor.
55
+ *
56
+ * @param appExtension
57
+ * Application extension.
58
+ */
59
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
60
+ super(appExtension.sharedAppDataStorage);
61
+
62
+ this.#logger = appExtension.logger;
63
+ }
64
+
65
+ /**
66
+ * @inheritDoc
67
+ */
68
+ override get nextCheckDateTime(): Promise<Date | undefined> {
69
+ return super.nextCheckDateTime.then((nextCheckDateTime) => {
70
+ this.#logger.debug(`GS1 Company Prefix length next check date/time ${nextCheckDateTime?.toISOString()}`);
71
+
72
+ return nextCheckDateTime;
73
+ });
74
+ }
75
+
76
+ /**
77
+ * @inheritDoc
78
+ */
79
+ override get cacheDateTime(): Promise<Date | undefined> {
80
+ return super.cacheDateTime.then((cacheDateTime) => {
81
+ this.#logger.debug(`GS1 Company Prefix length cache date/time ${cacheDateTime?.toISOString()}`);
82
+
83
+ return cacheDateTime;
84
+ });
85
+ }
86
+
87
+ override get cacheData(): Promise<GCPLengthData> {
88
+ return super.cacheData.then((cacheData) => {
89
+ this.#logger.debug("GS1 Company Prefix length cache data retrieved");
90
+
91
+ return cacheData;
92
+ });
93
+ }
94
+
95
+ /**
96
+ * @inheritDoc
97
+ */
98
+ override get sourceDateTime(): Promise<Date> {
99
+ return super.sourceDateTime.then((sourceDateTime) => {
100
+ this.#logger.debug(`GS1 Company Prefix source date/time ${sourceDateTime.toISOString()}`);
101
+
102
+ return sourceDateTime;
103
+ });
104
+ }
105
+
106
+ /**
107
+ * @inheritDoc
108
+ */
109
+ override get sourceData(): Promise<GCPLengthData> {
110
+ return super.sourceData.then((sourceData) => {
111
+ this.#logger.debug("GS1 Company Prefix length source data retrieved");
112
+
113
+ return sourceData;
114
+ });
115
+ }
116
+
117
+ /**
118
+ * @inheritDoc
119
+ */
120
+ override async update(nextCheckDateTime: Date, cacheDateTime?: Date, cacheData?: GCPLengthData): Promise<void> {
121
+ return super.update(nextCheckDateTime, cacheDateTime, cacheData).then(() => {
122
+ this.#logger.trace(`GS1 Company Prefix length saved to shared data with next check date/time ${nextCheckDateTime.toISOString()}`);
123
+ });
124
+ }
125
+ }
126
+
29
127
  @proxy.describeClass(false, {
30
- namespace: "GS1"
128
+ namespace: "GS1",
129
+ category: "prefix"
31
130
  })
32
- export class PrefixManagerProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
131
+ export class PrefixManagerProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
132
+ readonly #gcpLengthCache: GCPLengthCache;
133
+
134
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
135
+ super(appExtension);
136
+
137
+ this.#gcpLengthCache = new AppExtensionGCPLengthCache(appExtension);
138
+ }
139
+
33
140
  @proxy.describeMethod({
34
141
  type: Types.Any,
35
- isMatrix: true,
142
+ multiplicity: Multiplicities.SingletonArray,
36
143
  parameterDescriptors: [prefixParameterDescriptor, prefixTypeParameterDescriptor, tweakFactorParameterDescriptor]
37
144
  })
38
145
  definePrefix(prefix: string, prefixType: Nullishable<PrefixType>, tweakFactor: Nullishable<number>): Matrix<unknown> {
39
146
  // Parameters will be validated by IdentifierCreatorProxy.getCreator().
40
147
  return [[prefix, prefixType, tweakFactor]];
41
148
  }
149
+
150
+ /**
151
+ * Load GS1 Company Prefix length data.
152
+ *
153
+ * @returns
154
+ * Void promise.
155
+ */
156
+ async #loadGCPLengthData(): Promise<void> {
157
+ return PrefixManager.loadGCPLengthData(this.#gcpLengthCache).catch((e: unknown) => {
158
+ // Log and swallow error.
159
+ this.appExtension.logger.error("Load GS1 Company Prefix length data failed", e);
160
+ });
161
+ }
162
+
163
+ @proxy.describeMethod({
164
+ type: Types.Number,
165
+ multiplicity: Multiplicities.Matrix,
166
+ parameterDescriptors: [identifierTypeParameterDescriptor, gcpLengthIdentifierParameterDescriptor]
167
+ })
168
+ async gcpLength(identifierType: string, matrixIdentifiers: Matrix<string>): Promise<MatrixResult<number, ThrowError, TError>> {
169
+ return this.#loadGCPLengthData().then(() => this.setUpMatrixResult(
170
+ () => validateIdentifierType(identifierType),
171
+ matrixIdentifiers,
172
+ (validatedIdentifierType, identifier) => PrefixManager.gcpLength(validatedIdentifierType, identifier)
173
+ ));
174
+ }
175
+
176
+ @proxy.describeMethod({
177
+ type: Types.String,
178
+ multiplicity: Multiplicities.Singleton,
179
+ parameterDescriptors: []
180
+ })
181
+ async gcpLengthDateTime(): Promise<SingletonResult<string, ThrowError, TError>> {
182
+ return this.#loadGCPLengthData().then(() =>
183
+ this.singletonResult(() => PrefixManager.gcpLengthDateTime().toISOString())
184
+ );
185
+ }
186
+
187
+ @proxy.describeMethod({
188
+ type: Types.String,
189
+ multiplicity: Multiplicities.Singleton,
190
+ parameterDescriptors: []
191
+ })
192
+ async gcpLengthDisclaimer(): Promise<SingletonResult<string, ThrowError, TError>> {
193
+ return this.#loadGCPLengthData().then(() =>
194
+ this.singletonResult(() => PrefixManager.gcpLengthDisclaimer())
195
+ );
196
+ }
42
197
  }
@@ -0,0 +1,57 @@
1
+ import { isNullish, type Nullishable } from "@aidc-toolkit/core";
2
+ import { verifiedByGS1 } from "@aidc-toolkit/gs1";
3
+ import { type ExtendsParameterDescriptor, Multiplicities, type ParameterDescriptor, Types } from "../descriptor.js";
4
+ import { LibProxy } from "../lib-proxy.js";
5
+ import { proxy } from "../proxy.js";
6
+ import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
7
+ import { identifierParameterDescriptor, identifierTypeParameterDescriptor } from "./identifier-descriptor.js";
8
+ import { validateIdentifierType } from "./identifier-type.js";
9
+
10
+ const hyperlinkIdentifierParameterDescriptor: ExtendsParameterDescriptor = {
11
+ extendsDescriptor: identifierParameterDescriptor,
12
+ name: "hyperlinkIdentifier"
13
+ };
14
+
15
+ const hyperlinkTextParameterDescriptor: ParameterDescriptor = {
16
+ name: "hyperlinkText",
17
+ type: Types.String,
18
+ multiplicity: Multiplicities.Singleton,
19
+ isRequired: false
20
+ };
21
+
22
+ const hyperlinkDetailsParameterDescriptor: ParameterDescriptor = {
23
+ name: "hyperlinkDetails",
24
+ type: Types.String,
25
+ multiplicity: Multiplicities.Singleton,
26
+ isRequired: false
27
+ };
28
+
29
+ @proxy.describeClass(false, {
30
+ namespace: "GS1",
31
+ category: "service"
32
+ })
33
+ export class ServiceProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
34
+ @proxy.describeMethod({
35
+ type: Types.Any,
36
+ multiplicity: Multiplicities.Matrix,
37
+ requiresContext: true,
38
+ parameterDescriptors: [
39
+ identifierTypeParameterDescriptor,
40
+ hyperlinkIdentifierParameterDescriptor,
41
+ hyperlinkTextParameterDescriptor,
42
+ hyperlinkDetailsParameterDescriptor
43
+ ]
44
+ })
45
+ async verifiedByGS1(identifierType: string, matrixIdentifiers: Matrix<string>, text: Nullishable<string>, details: Nullishable<string>, invocationContext: Nullishable<TInvocationContext>): Promise<MatrixResult<unknown, ThrowError, TError>> {
46
+ if (isNullish(invocationContext)) {
47
+ // Application error; no localization necessary.
48
+ throw new Error("Invocation context not provided by application");
49
+ }
50
+
51
+ return this.appExtension.mapHyperlinkResults(invocationContext, this.setUpMatrixResult(() =>
52
+ validateIdentifierType(identifierType),
53
+ matrixIdentifiers, (validatedIdentifierType, identifier) =>
54
+ verifiedByGS1(validatedIdentifierType, identifier, text ?? undefined, details ?? undefined)
55
+ ));
56
+ }
57
+ }
@@ -0,0 +1,62 @@
1
+ import { VariableMeasure } from "@aidc-toolkit/gs1";
2
+ import { Multiplicities, type ParameterDescriptor, Types } from "../descriptor.js";
3
+ import { LibProxy } from "../lib-proxy.js";
4
+ import { proxy } from "../proxy.js";
5
+ import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
6
+
7
+ const rcnFormatParameterDescriptor: ParameterDescriptor = {
8
+ name: "rcnFormat",
9
+ type: Types.String,
10
+ multiplicity: Multiplicities.Singleton,
11
+ isRequired: true
12
+ };
13
+
14
+ const rcnParameterDescriptor: ParameterDescriptor = {
15
+ name: "rcn",
16
+ type: Types.String,
17
+ multiplicity: Multiplicities.Array,
18
+ isRequired: true
19
+ };
20
+
21
+ const rcnItemReferenceParameterDescriptor: ParameterDescriptor = {
22
+ name: "rcnItemReference",
23
+ type: Types.Number,
24
+ multiplicity: Multiplicities.Singleton,
25
+ isRequired: true
26
+ };
27
+
28
+ const rcnPriceOrWeightParameterDescriptor: ParameterDescriptor = {
29
+ name: "rcnPriceOrWeight",
30
+ type: Types.Number,
31
+ multiplicity: Multiplicities.Matrix,
32
+ isRequired: true
33
+ };
34
+
35
+ @proxy.describeClass(false, {
36
+ namespace: "GS1",
37
+ category: "variableMeasure"
38
+ })
39
+ export class VariableMeasureProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
40
+ @proxy.describeMethod({
41
+ type: Types.Number,
42
+ multiplicity: Multiplicities.Matrix,
43
+ parameterDescriptors: [rcnFormatParameterDescriptor, rcnParameterDescriptor]
44
+ })
45
+ parseVariableMeasureRCN(format: string, matrixRCNs: Matrix<string>): MatrixResult<number, ThrowError, TError> {
46
+ return this.arrayResult(matrixRCNs, (rcn) => {
47
+ const rcnReference = VariableMeasure.parseRCN(format, rcn);
48
+
49
+ return [rcnReference.itemReference, rcnReference.priceOrWeight];
50
+ });
51
+ }
52
+
53
+ @proxy.describeMethod({
54
+ type: Types.String,
55
+ multiplicity: Multiplicities.Matrix,
56
+ ignoreInfix: true,
57
+ parameterDescriptors: [rcnFormatParameterDescriptor, rcnItemReferenceParameterDescriptor, rcnPriceOrWeightParameterDescriptor]
58
+ })
59
+ createVariableMeasureRCN(format: string, itemReference: number, matrixPricesOrWeights: Matrix<number>): MatrixResult<string, ThrowError, TError> {
60
+ return this.matrixResult(matrixPricesOrWeights, priceOrWeight => VariableMeasure.createRCN(format, itemReference, priceOrWeight));
61
+ }
62
+ }
package/src/index.ts CHANGED
@@ -15,12 +15,17 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  export * from "./locale/i18n.js";
18
+
18
19
  export type * from "./type.js";
20
+
21
+ export type * from "./streaming.js";
19
22
  export * from "./app-extension.js";
20
23
  export * from "./lib-proxy.js";
24
+
21
25
  export * from "./descriptor.js";
22
- export * from "./app-utility-proxy.js";
26
+ export * from "./app-helper-proxy.js";
23
27
  export * from "./utility/index.js";
24
28
  export * as GS1 from "./gs1/index.js";
29
+
25
30
  export * from "./generator/index.js";
26
31
  export { expandParameterDescriptor } from "./proxy.js";