@aidc-toolkit/gs1 1.0.40-beta → 1.0.42-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 (39) hide show
  1. package/README.md +2 -19
  2. package/dist/gcp-length-cache.d.ts +6 -1
  3. package/dist/gcp-length-cache.d.ts.map +1 -1
  4. package/dist/gcp-length-cache.js +7 -2
  5. package/dist/gcp-length-cache.js.map +1 -1
  6. package/dist/gcp-length-tree.d.ts +33 -0
  7. package/dist/gcp-length-tree.d.ts.map +1 -0
  8. package/dist/gcp-length-tree.js +13 -0
  9. package/dist/gcp-length-tree.js.map +1 -0
  10. package/dist/gcp-length.d.ts +63 -49
  11. package/dist/gcp-length.d.ts.map +1 -1
  12. package/dist/gcp-length.js +319 -262
  13. package/dist/gcp-length.js.map +1 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/locale/en/locale-resources.d.ts +2 -0
  19. package/dist/locale/en/locale-resources.d.ts.map +1 -1
  20. package/dist/locale/en/locale-resources.js +3 -1
  21. package/dist/locale/en/locale-resources.js.map +1 -1
  22. package/dist/locale/fr/locale-resources.d.ts +2 -0
  23. package/dist/locale/fr/locale-resources.d.ts.map +1 -1
  24. package/dist/locale/fr/locale-resources.js +3 -1
  25. package/dist/locale/fr/locale-resources.js.map +1 -1
  26. package/dist/prefix-manager.d.ts +0 -35
  27. package/dist/prefix-manager.d.ts.map +1 -1
  28. package/dist/prefix-manager.js +0 -56
  29. package/dist/prefix-manager.js.map +1 -1
  30. package/package.json +4 -4
  31. package/src/gcp-length-cache.ts +7 -2
  32. package/src/gcp-length-tree.ts +39 -0
  33. package/src/gcp-length.ts +348 -297
  34. package/src/index.ts +3 -1
  35. package/src/locale/en/locale-resources.ts +3 -1
  36. package/src/locale/fr/locale-resources.ts +3 -1
  37. package/src/prefix-manager.ts +0 -65
  38. package/test/gcp-length.test.ts +39 -31
  39. package/tsconfig-src.tsbuildinfo +1 -1
package/README.md CHANGED
@@ -300,23 +300,6 @@ The [`verifiedByGS1()`](https://aidc-toolkit.com/v1.0/api/GS1/functions/verified
300
300
 
301
301
  #### GS1 Company Prefix Length Determination
302
302
 
303
- GS1 Company Prefix length determination is required when encoding a GS1 identifier as an EPC URN. Though this is typically done by the GS1 Company Prefix licensee (who knows the length), it's occasionally required by downstream trading partners such as distributors.
303
+ GS1 Company Prefix length determination is required when encoding a GS1 identifier as an EPC URN. Although this is typically done by the GS1 Company Prefix licensee (who knows the length), it's occasionally required by downstream trading partners such as distributors.
304
304
 
305
- This functionality part of the [`PrefixManager`](https://aidc-toolkit.com/v1.0/api/GS1/classes/PrefixManager.html) class.
306
-
307
- The first step is to load the GS1 Company Prefix length data. This is done using [`loadGCPLengthData()`](https://aidc-toolkit.com/v1.0/api/GS1/classes/PrefixManager.html#loadgcplengthdata) static method, which takes a [`GCPLengthCache`](https://aidc-toolkit.com/v1.0/api/GS1/classes/GCPLengthCache.html) object. The cache object is used to store the data so that it can be shared across multiple instances of the prefix manager.
308
-
309
- The `loadGCPLengthData()` method works as follows:
310
-
311
- - If the next check date/time is in the future, the method returns immediately, regardless of whether any data is available. It does this to prevent a large number of requests to the source in the event of a failure.
312
- - Otherwise, if the cache date/time is undefined or less than the source date/time, it loads from the source, converts the data if necessary, and updates the cache.
313
- - Otherwise, it continues with the cached data.
314
- - The next check date/time is updated to the later of the source date/time plus one week and the current date/time plus one day.
315
-
316
- The base class implementation of the `GCPLengthCache` manages only the cache itself, and it requires an application-provided [`AppDataStorage`](https://aidc-toolkit.com/v1.0/api/Core/classes/AppDataStorage.html) storage implementation. The source is expected to be either a [`GCPLengthData`](https://aidc-toolkit.com/v1.0/api/GS1/interfaces/GCPLengthData.html) object (created via another cache implementation) or a [`GCPLengthSourceJSON`](https://aidc-toolkit.com/v1.0/api/GS1/interfaces/GCPLengthSourceJSON.html) object, which is the format of the file provided by GS1.
317
-
318
- The [`RemoteGCPLengthCache`](https://aidc-toolkit.com/v1.0/api/GS1/classes/RemoteGCPLengthCache.html) class provides access to the data from a remote source, by default the AIDC Toolkit website. If any error occurs, the next check date/time is set to the current date/time plus ten minutes to prevent the network from being overloaded.
319
-
320
- The data on the AIDC Toolkit website is updated regularly with the data provided by GS1, and it's stored in binary format for faster retrieval.
321
-
322
- Once the data is loaded, the [`gcpLength()`](https://aidc-toolkit.com/v1.0/api/GS1/classes/PrefixManager.html#gcplength) method can be used to get the length of a GS1 Company Prefix for a given identifier type.
305
+ This functionality is provided by the [`GCPLength`](https://aidc-toolkit.com/v1.0/api/GS1/classes/GCPLength.html) class.
@@ -50,7 +50,12 @@ export declare abstract class GCPLengthCache extends Cache<GCPLengthData, GCPLen
50
50
  update(nextCheckDateTime: Date, _cacheDateTime?: Date, cacheData?: GCPLengthData): Promise<void>;
51
51
  }
52
52
  /**
53
- * GS1 Company Prefix length cache with remote source.
53
+ * GS1 Company Prefix length cache with remote source. This class provides access to the data from a remote source, by
54
+ * default the AIDC Toolkit website. If any error occurs, the next check date/time is set to the current date/time plus
55
+ * ten minutes to prevent the network from being overloaded.
56
+ *
57
+ * The data on the AIDC Toolkit website is updated regularly with the data provided by GS1, and it's stored in binary
58
+ * format for faster retrieval.
54
59
  */
55
60
  export declare class RemoteGCPLengthCache extends GCPLengthCache {
56
61
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"gcp-length-cache.d.ts","sourceRoot":"","sources":["../src/gcp-length-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,cAAc,EACnB,KAAK,EAIR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEH,KAAK,aAAa,EAElB,KAAK,mBAAmB,EAG3B,MAAM,sBAAsB,CAAC;AAG9B;;GAEG;AACH,8BAAsB,cAAe,SAAQ,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,mBAAmB,CAAC;;IAClG;;OAEG;IACH,MAAM,CAAC,oBAAoB,SAAgB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AAe,SAAQ,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,mBAAmB,CAAC;;IAClG;;OAEG;IACH,MAAM,CAAC,oBAAoB,SAAgB;IAE3C;;OAEG;IACH,MAAM,CAAC,gCAAgC,SAAqC;IAE5E;;OAEG;IACH,MAAM,CAAC,kBAAkB,SAAuB;IAEhD;;OAEG;IACH,MAAM,CAAC,gBAAgB,SAAqB;IAY5C;;;;;OAKG;gBACS,cAAc,EAAE,cAAc,CAAC,OAAO,CAAC;IAMnD;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAAC,OAAO,CAAC,CAE5C;IA6CD;;OAEG;IACH,IAAa,iBAAiB,IAAI,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAE1D;IAED;;OAEG;IACH,IAAa,aAAa,IAAI,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAEtD;IAED;;OAEG;IACH,IAAa,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAS/C;IAED;;OAEG;IACY,MAAM,CAAC,iBAAiB,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBlH;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,cAAc;;IACpD;;OAEG;IACH,MAAM,CAAC,gBAAgB,SAA8B;IAYrD;;;;;;;;;OASG;gBACS,cAAc,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,GAAE,MAA8C;IA0C5G;;OAEG;IACH,IAAa,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAY3C;IAED;;OAEG;IACH,IAAa,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAmBhD;CACJ"}
@@ -133,7 +133,12 @@ export class GCPLengthCache extends Cache {
133
133
  }
134
134
  _a = GCPLengthCache;
135
135
  /**
136
- * GS1 Company Prefix length cache with remote source.
136
+ * GS1 Company Prefix length cache with remote source. This class provides access to the data from a remote source, by
137
+ * default the AIDC Toolkit website. If any error occurs, the next check date/time is set to the current date/time plus
138
+ * ten minutes to prevent the network from being overloaded.
139
+ *
140
+ * The data on the AIDC Toolkit website is updated regularly with the data provided by GS1, and it's stored in binary
141
+ * format for faster retrieval.
137
142
  */
138
143
  export class RemoteGCPLengthCache extends GCPLengthCache {
139
144
  /**
@@ -181,7 +186,7 @@ export class RemoteGCPLengthCache extends GCPLengthCache {
181
186
  async #getRemoteAppData(pathKey, asBinary, callback) {
182
187
  return this.#remoteAppDataStorage.read(pathKey, asBinary).then((appData) => {
183
188
  if (appData === undefined) {
184
- throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixLengthDataFileNotFound", {
189
+ throw new RangeError(i18nextGS1.t("GCPLength.gs1CompanyPrefixLengthDataFileNotFound", {
185
190
  key: pathKey
186
191
  }));
187
192
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gcp-length-cache.js","sourceRoot":"","sources":["../src/gcp-length-cache.ts"],"names":[],"mappings":";AAAA,OAAO,EAGH,KAAK,EACL,IAAI,EACJ,oBAAoB,EACpB,gBAAgB,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKH,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAgB,cAAe,SAAQ,KAAyD;IAClG;;OAEG;IACH,MAAM,CAAC,oBAAoB,GAAG,YAAY,CAAC;IAE3C;;OAEG;IACH,MAAM,CAAC,gCAAgC,GAAG,iCAAiC,CAAC;IAE5E;;OAEG;IACH,MAAM,CAAC,kBAAkB,GAAG,mBAAmB,CAAC;IAEhD;;OAEG;IACH,MAAM,CAAC,gBAAgB,GAAG,iBAAiB,CAAC;IAE5C;;OAEG;IACM,eAAe,CAA0B;IAElD;;OAEG;IACH,sBAAsB,CAAgC;IAEtD;;;;;OAKG;IACH,YAAY,cAAuC;QA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oBAAoB,CAAC,kBAAkB,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE;YACtF,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC9B,gDAAgD;gBAChD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAChE,CAAC;YAED,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC;YAEtC,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,IAAa,UAAU;QACnB,OAAO,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YACnF,MAAM,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC;YAEpD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;gBAChC,gDAAgD;gBAChD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACnE,CAAC;YAED,IAAI,CAAC,CAAC,OAAO,YAAY,UAAU,CAAC,EAAE,CAAC;gBACnC,gDAAgD;gBAChD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC9D,CAAC;YAED,OAAO;gBACH,GAAG,eAAe;gBAClB,IAAI,EAAE,OAAO;aAChB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { GCPLengthHeader } from "./gcp-length-data.js";
2
+ /**
3
+ * Leaf of GS1 Company Prefix length tree.
4
+ */
5
+ export interface Leaf {
6
+ readonly length: number;
7
+ }
8
+ /**
9
+ * Branch of GS1 Company Prefix length tree.
10
+ */
11
+ export interface Branch {
12
+ readonly childNodes: ReadonlyArray<Node | undefined>;
13
+ }
14
+ /**
15
+ * Root of GS1 Company Prefix length tree.
16
+ */
17
+ export interface Root extends GCPLengthHeader, Branch {
18
+ }
19
+ /**
20
+ * Node in GS1 Company Prefix length tree.
21
+ */
22
+ export type Node = Branch | Leaf;
23
+ /**
24
+ * Determine if a node is a leaf.
25
+ *
26
+ * @param node
27
+ * Node.
28
+ *
29
+ * @returns
30
+ * True if node is a leaf.
31
+ */
32
+ export declare function isLeaf(node: Node): node is Leaf;
33
+ //# sourceMappingURL=gcp-length-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcp-length-tree.d.ts","sourceRoot":"","sources":["../src/gcp-length-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,IAAI;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;CACxD;AAED;;GAEG;AACH,MAAM,WAAW,IAAK,SAAQ,eAAe,EAAE,MAAM;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;AAEjC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,IAAI,CAE/C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Determine if a node is a leaf.
3
+ *
4
+ * @param node
5
+ * Node.
6
+ *
7
+ * @returns
8
+ * True if node is a leaf.
9
+ */
10
+ export function isLeaf(node) {
11
+ return "length" in node;
12
+ }
13
+ //# sourceMappingURL=gcp-length-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcp-length-tree.js","sourceRoot":"","sources":["../src/gcp-length-tree.ts"],"names":[],"mappings":"AA2BA;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAC,IAAU;IAC7B,OAAO,QAAQ,IAAI,IAAI,CAAC;AAC5B,CAAC"}
@@ -1,61 +1,75 @@
1
1
  import type { GCPLengthCache } from "./gcp-length-cache.js";
2
- import { type GCPLengthHeader } from "./gcp-length-data.js";
2
+ import * as GCPLengthTree from "./gcp-length-tree.js";
3
3
  import { type IdentifierType } from "./identifier-type.js";
4
4
  /**
5
- * Leaf of GS1 Company Prefix length tree.
5
+ * Interim branch of GS1 Company Prefix length tree with writeable child nodes.
6
6
  */
7
- export interface Leaf {
8
- length: number;
7
+ export interface InterimBranch {
8
+ readonly childNodes: Array<InterimBranch | GCPLengthTree.Leaf | undefined>;
9
9
  }
10
10
  /**
11
- * Branch of GS1 Company Prefix length tree.
12
- */
13
- export interface Branch {
14
- childNodes: Array<Node | undefined>;
15
- }
16
- /**
17
- * Root of GS1 Company Prefix length tree.
18
- */
19
- export interface Root extends GCPLengthHeader, Branch {
20
- }
21
- /**
22
- * Node in GS1 Company Prefix length tree.
23
- */
24
- export type Node = Root | Branch | Leaf;
25
- /**
26
- * Determine if a node is a leaf.
11
+ * GS1 Company Prefix length service. The constructor takes a {@linkcode GCPLengthCache} object, which is responsible
12
+ * for managing the cache and source.
27
13
  *
28
- * @param node
29
- * Node.
14
+ * The first step is to load the GS1 Company Prefix length data. This is done using the
15
+ * {@linkcode GCPLength.load | load()} method, which works as follows:
30
16
  *
31
- * @returns
32
- * True if node is a leaf.
33
- */
34
- export declare function isLeaf(node: Node): node is Leaf;
35
- /**
36
- * Load the GS1 Company Prefix length data.
37
- *
38
- * @param gcpLengthCache
39
- * GS1 Company Prefix length cache.
40
- *
41
- * @returns
42
- * Root of tree.
43
- */
44
- export declare function loadData(gcpLengthCache: GCPLengthCache): Promise<Root | undefined>;
45
- /**
46
- * Get the length of a GS1 Company Prefix for an identifier.
47
- *
48
- * @param root
49
- * Root of tree.
17
+ * - If the next check date/time is in the future, the method returns immediately, regardless of whether any data is
18
+ * available. It does this to prevent a large number of requests to the source in the event of a failure.
19
+ * - Otherwise, if the cache date/time is undefined or less than the source date/time, it loads from the source,
20
+ * converts the data if necessary, and updates the cache.
21
+ * - Otherwise, it continues with the cached data.
22
+ * - The next check date/time is updated to the later of the source date/time plus one week and the current date/time
23
+ * plus one day.
50
24
  *
51
- * @param identifierType
52
- * Identifier type.
25
+ * The base class implementation of the `GCPLengthCache` manages only the cache itself, and it requires an
26
+ * application-provided storage implementation. The source is expected to be either a {@linkcode GCPLengthData} object
27
+ * (created via another cache implementation) or a {@linkcode GCPLengthSourceJSON} object, which is the format of the
28
+ * file provided by GS1.
53
29
  *
54
- * @param identifier
55
- * Identifier.
56
- *
57
- * @returns
58
- * Length of GS1 Company Prefix, 0 if not a GS1 Company Prefix, or -1 if not found.
30
+ * Once the data is loaded, the {@linkcode GCPLength.lengthOf | lengthOf()} method can be used to get the length of a
31
+ * GS1 Company Prefix for an identifier type and identifier.
59
32
  */
60
- export declare function getFor(root: Root, identifierType: IdentifierType, identifier: string): number;
33
+ export declare class GCPLength {
34
+ #private;
35
+ /**
36
+ * Constructor.
37
+ *
38
+ * @param gcpLengthCache
39
+ * GS1 Company Prefix length cache.
40
+ */
41
+ constructor(gcpLengthCache: GCPLengthCache);
42
+ /**
43
+ * Get the GS1 Company Prefix length tree root.
44
+ *
45
+ * @returns
46
+ * GS1 Company Prefix length tree root.
47
+ */
48
+ get root(): GCPLengthTree.Root;
49
+ /**
50
+ * Get the date/time the GS1 Company Prefix length data was last updated.
51
+ */
52
+ get dateTime(): Date;
53
+ /**
54
+ * Get the disclaimer for the GS1 Company Prefix length data.
55
+ */
56
+ get disclaimer(): string;
57
+ /**
58
+ * Load the GS1 Company Prefix length data.
59
+ */
60
+ load(): Promise<void>;
61
+ /**
62
+ * Get the length of a GS1 Company Prefix for an identifier.
63
+ *
64
+ * @param identifierType
65
+ * Identifier type.
66
+ *
67
+ * @param identifier
68
+ * Identifier.
69
+ *
70
+ * @returns
71
+ * Length of GS1 Company Prefix, 0 if not a GS1 Company Prefix, or -1 if not found.
72
+ */
73
+ lengthOf(identifierType: IdentifierType, identifier: string): number;
74
+ }
61
75
  //# sourceMappingURL=gcp-length.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gcp-length.d.ts","sourceRoot":"","sources":["../src/gcp-length.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAsB,KAAK,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AAGjG,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAI5E;;GAEG;AACH,MAAM,WAAW,IAAI;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,UAAU,EAAE,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,IAAK,SAAQ,eAAe,EAAE,MAAM;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,IAAI,CAE/C;AAmMD;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAyFxF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAwB7F"}
1
+ {"version":3,"file":"gcp-length.d.ts","sourceRoot":"","sources":["../src/gcp-length.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAK5E;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,UAAU,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