@aidc-toolkit/app-extension 1.0.48-beta → 1.0.49

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 (181) hide show
  1. package/dist/character-set-proxy-BOW94WCe.d.cts +473 -0
  2. package/dist/character-set-proxy-BOW94WCe.d.ts +473 -0
  3. package/dist/chunk-22IRLVWO.js +1 -0
  4. package/dist/chunk-MR63TJ3B.js +1 -0
  5. package/dist/chunk-TWX7TPRC.js +1 -0
  6. package/dist/{descriptor.d.ts → descriptor-D6tZH-vc.d.cts} +13 -13
  7. package/dist/descriptor-D6tZH-vc.d.ts +185 -0
  8. package/dist/generator/index.cjs +17 -0
  9. package/dist/generator/index.d.cts +240 -0
  10. package/dist/generator/index.d.ts +239 -17
  11. package/dist/generator/index.js +1 -2
  12. package/dist/gs1/index.cjs +1 -0
  13. package/dist/gs1/index.d.cts +185 -0
  14. package/dist/gs1/index.d.ts +185 -11
  15. package/dist/gs1/index.js +1 -11
  16. package/dist/index.cjs +17 -0
  17. package/dist/{locale/en/locale-resources.d.ts → index.d.cts} +113 -2
  18. package/dist/index.d.ts +862 -21
  19. package/dist/index.js +1 -7
  20. package/package.json +5 -5
  21. package/src/app-extension.ts +29 -0
  22. package/src/app-helper-proxy.ts +45 -7
  23. package/src/generator/functions-generator.ts +292 -0
  24. package/src/generator/generator.ts +9 -29
  25. package/src/generator/index.ts +1 -0
  26. package/src/generator/locale-resources-generator.ts +9 -7
  27. package/src/gs1/check-proxy.ts +3 -3
  28. package/src/gs1/gtin-validator-proxy.ts +2 -2
  29. package/src/gs1/identifier-validator-proxy.ts +2 -2
  30. package/src/locale/fr/locale-resources.ts +2 -2
  31. package/src/locale/i18n.ts +5 -5
  32. package/src/version.ts +4 -0
  33. package/tsconfig-src.tsbuildinfo +1 -1
  34. package/dist/app-extension.d.ts +0 -198
  35. package/dist/app-extension.d.ts.map +0 -1
  36. package/dist/app-extension.js +0 -133
  37. package/dist/app-extension.js.map +0 -1
  38. package/dist/app-helper-proxy.d.ts +0 -61
  39. package/dist/app-helper-proxy.d.ts.map +0 -1
  40. package/dist/app-helper-proxy.js +0 -333
  41. package/dist/app-helper-proxy.js.map +0 -1
  42. package/dist/descriptor.d.ts.map +0 -1
  43. package/dist/descriptor.js +0 -44
  44. package/dist/descriptor.js.map +0 -1
  45. package/dist/generator/generator.d.ts +0 -124
  46. package/dist/generator/generator.d.ts.map +0 -1
  47. package/dist/generator/generator.js +0 -198
  48. package/dist/generator/generator.js.map +0 -1
  49. package/dist/generator/index.d.ts.map +0 -1
  50. package/dist/generator/index.js.map +0 -1
  51. package/dist/generator/locale-resources-generator.d.ts +0 -2
  52. package/dist/generator/locale-resources-generator.d.ts.map +0 -1
  53. package/dist/generator/locale-resources-generator.js +0 -312
  54. package/dist/generator/locale-resources-generator.js.map +0 -1
  55. package/dist/gs1/character-set-proxy.d.ts +0 -13
  56. package/dist/gs1/character-set-proxy.d.ts.map +0 -1
  57. package/dist/gs1/character-set-proxy.js +0 -126
  58. package/dist/gs1/character-set-proxy.js.map +0 -1
  59. package/dist/gs1/check-proxy.d.ts +0 -11
  60. package/dist/gs1/check-proxy.d.ts.map +0 -1
  61. package/dist/gs1/check-proxy.js +0 -163
  62. package/dist/gs1/check-proxy.js.map +0 -1
  63. package/dist/gs1/gcp-length-proxy.d.ts +0 -11
  64. package/dist/gs1/gcp-length-proxy.d.ts.map +0 -1
  65. package/dist/gs1/gcp-length-proxy.js +0 -187
  66. package/dist/gs1/gcp-length-proxy.js.map +0 -1
  67. package/dist/gs1/gtin-creator-proxy.d.ts +0 -10
  68. package/dist/gs1/gtin-creator-proxy.d.ts.map +0 -1
  69. package/dist/gs1/gtin-creator-proxy.js +0 -85
  70. package/dist/gs1/gtin-creator-proxy.js.map +0 -1
  71. package/dist/gs1/gtin-descriptor.d.ts +0 -3
  72. package/dist/gs1/gtin-descriptor.d.ts.map +0 -1
  73. package/dist/gs1/gtin-descriptor.js +0 -8
  74. package/dist/gs1/gtin-descriptor.js.map +0 -1
  75. package/dist/gs1/gtin-validator-proxy.d.ts +0 -26
  76. package/dist/gs1/gtin-validator-proxy.d.ts.map +0 -1
  77. package/dist/gs1/gtin-validator-proxy.js +0 -256
  78. package/dist/gs1/gtin-validator-proxy.js.map +0 -1
  79. package/dist/gs1/identifier-creator-proxy.d.ts +0 -30
  80. package/dist/gs1/identifier-creator-proxy.d.ts.map +0 -1
  81. package/dist/gs1/identifier-creator-proxy.js +0 -318
  82. package/dist/gs1/identifier-creator-proxy.js.map +0 -1
  83. package/dist/gs1/identifier-descriptor.d.ts +0 -4
  84. package/dist/gs1/identifier-descriptor.d.ts.map +0 -1
  85. package/dist/gs1/identifier-descriptor.js +0 -14
  86. package/dist/gs1/identifier-descriptor.js.map +0 -1
  87. package/dist/gs1/identifier-type.d.ts +0 -22
  88. package/dist/gs1/identifier-type.d.ts.map +0 -1
  89. package/dist/gs1/identifier-type.js +0 -34
  90. package/dist/gs1/identifier-type.js.map +0 -1
  91. package/dist/gs1/identifier-validator-proxy.d.ts +0 -29
  92. package/dist/gs1/identifier-validator-proxy.d.ts.map +0 -1
  93. package/dist/gs1/identifier-validator-proxy.js +0 -212
  94. package/dist/gs1/identifier-validator-proxy.js.map +0 -1
  95. package/dist/gs1/index.d.ts.map +0 -1
  96. package/dist/gs1/index.js.map +0 -1
  97. package/dist/gs1/non-gtin-creator-proxy.d.ts +0 -38
  98. package/dist/gs1/non-gtin-creator-proxy.d.ts.map +0 -1
  99. package/dist/gs1/non-gtin-creator-proxy.js +0 -301
  100. package/dist/gs1/non-gtin-creator-proxy.js.map +0 -1
  101. package/dist/gs1/non-gtin-validator-proxy.d.ts +0 -37
  102. package/dist/gs1/non-gtin-validator-proxy.d.ts.map +0 -1
  103. package/dist/gs1/non-gtin-validator-proxy.js +0 -302
  104. package/dist/gs1/non-gtin-validator-proxy.js.map +0 -1
  105. package/dist/gs1/prefix-definition-descriptor.d.ts +0 -4
  106. package/dist/gs1/prefix-definition-descriptor.d.ts.map +0 -1
  107. package/dist/gs1/prefix-definition-descriptor.js +0 -16
  108. package/dist/gs1/prefix-definition-descriptor.js.map +0 -1
  109. package/dist/gs1/prefix-manager-proxy.d.ts +0 -8
  110. package/dist/gs1/prefix-manager-proxy.d.ts.map +0 -1
  111. package/dist/gs1/prefix-manager-proxy.js +0 -94
  112. package/dist/gs1/prefix-manager-proxy.js.map +0 -1
  113. package/dist/gs1/variable-measure-proxy.d.ts +0 -7
  114. package/dist/gs1/variable-measure-proxy.d.ts.map +0 -1
  115. package/dist/gs1/variable-measure-proxy.js +0 -114
  116. package/dist/gs1/variable-measure-proxy.js.map +0 -1
  117. package/dist/gs1/verified-by-gs1-proxy.d.ts +0 -7
  118. package/dist/gs1/verified-by-gs1-proxy.d.ts.map +0 -1
  119. package/dist/gs1/verified-by-gs1-proxy.js +0 -106
  120. package/dist/gs1/verified-by-gs1-proxy.js.map +0 -1
  121. package/dist/index.d.ts.map +0 -1
  122. package/dist/index.js.map +0 -1
  123. package/dist/lib-proxy.d.ts +0 -135
  124. package/dist/lib-proxy.d.ts.map +0 -1
  125. package/dist/lib-proxy.js +0 -276
  126. package/dist/lib-proxy.js.map +0 -1
  127. package/dist/locale/en/locale-resources.d.ts.map +0 -1
  128. package/dist/locale/en/locale-resources.js +0 -754
  129. package/dist/locale/en/locale-resources.js.map +0 -1
  130. package/dist/locale/fr/locale-resources.d.ts +0 -755
  131. package/dist/locale/fr/locale-resources.d.ts.map +0 -1
  132. package/dist/locale/fr/locale-resources.js +0 -754
  133. package/dist/locale/fr/locale-resources.js.map +0 -1
  134. package/dist/locale/i18n.d.ts +0 -27
  135. package/dist/locale/i18n.d.ts.map +0 -1
  136. package/dist/locale/i18n.js +0 -36
  137. package/dist/locale/i18n.js.map +0 -1
  138. package/dist/proxy.d.ts +0 -136
  139. package/dist/proxy.d.ts.map +0 -1
  140. package/dist/proxy.js +0 -291
  141. package/dist/proxy.js.map +0 -1
  142. package/dist/streaming.d.ts +0 -10
  143. package/dist/streaming.d.ts.map +0 -1
  144. package/dist/streaming.js +0 -2
  145. package/dist/streaming.js.map +0 -1
  146. package/dist/type.d.ts +0 -91
  147. package/dist/type.d.ts.map +0 -1
  148. package/dist/type.js +0 -2
  149. package/dist/type.js.map +0 -1
  150. package/dist/utility/character-set-descriptor.d.ts +0 -6
  151. package/dist/utility/character-set-descriptor.d.ts.map +0 -1
  152. package/dist/utility/character-set-descriptor.js +0 -28
  153. package/dist/utility/character-set-descriptor.js.map +0 -1
  154. package/dist/utility/character-set-proxy.d.ts +0 -31
  155. package/dist/utility/character-set-proxy.d.ts.map +0 -1
  156. package/dist/utility/character-set-proxy.js +0 -278
  157. package/dist/utility/character-set-proxy.js.map +0 -1
  158. package/dist/utility/index.d.ts +0 -4
  159. package/dist/utility/index.d.ts.map +0 -1
  160. package/dist/utility/index.js +0 -4
  161. package/dist/utility/index.js.map +0 -1
  162. package/dist/utility/reg-exp-proxy.d.ts +0 -8
  163. package/dist/utility/reg-exp-proxy.d.ts.map +0 -1
  164. package/dist/utility/reg-exp-proxy.js +0 -103
  165. package/dist/utility/reg-exp-proxy.js.map +0 -1
  166. package/dist/utility/string-descriptor.d.ts +0 -4
  167. package/dist/utility/string-descriptor.d.ts.map +0 -1
  168. package/dist/utility/string-descriptor.js +0 -12
  169. package/dist/utility/string-descriptor.js.map +0 -1
  170. package/dist/utility/string-proxy.d.ts +0 -7
  171. package/dist/utility/string-proxy.d.ts.map +0 -1
  172. package/dist/utility/string-proxy.js +0 -63
  173. package/dist/utility/string-proxy.js.map +0 -1
  174. package/dist/utility/transformer-descriptor.d.ts +0 -6
  175. package/dist/utility/transformer-descriptor.d.ts.map +0 -1
  176. package/dist/utility/transformer-descriptor.js +0 -24
  177. package/dist/utility/transformer-descriptor.js.map +0 -1
  178. package/dist/utility/transformer-proxy.d.ts +0 -9
  179. package/dist/utility/transformer-proxy.d.ts.map +0 -1
  180. package/dist/utility/transformer-proxy.js +0 -111
  181. package/dist/utility/transformer-proxy.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import{a as b}from"./chunk-MR63TJ3B.js";import{A as y,B as S,C,D as I,E as v,i as c,j as l,k as n,l as p,m as T,n as u,o as E,u as h,w as x,z as d}from"./chunk-22IRLVWO.js";import{getLogger as m,LogLevels as a,MemoryTransport as g}from"@aidc-toolkit/core";var i=class e{static APPLICATION_NAME="AIDCToolkit";static VERSION_NAME=`${e.APPLICATION_NAME}.version`;static#i=120;static#s=100;#t;#r;#o;#e;#n;#a=new WeakMap;constructor(t,r,s){this.#t=t,this.#r=r,this.#o=s;let o=!t.includes("-");this.#e=m(o?a.Info:a.Debug,{type:o?"hidden":"pretty"}),this.#n=new g(this.#e,e.#i,e.#s)}async initialize(){await this.getDocumentProperty(e.VERSION_NAME)!==this.#t&&await this.setDocumentProperty(e.VERSION_NAME,this.#t)}get version(){return this.#t}get throwError(){return this.#o}get logger(){return this.#e}get memoryTransport(){return this.#n}getProxy(t){let r=this.#a.get(t);return r===void 0&&(r=new t(this),this.#a.set(t,r)),r}validateSequenceCount(t){let r=Math.abs(t);if(r>this.#r)throw new RangeError(n.t("AppExtension.sequenceCountMustBeLessThanOrEqualTo",{sequenceCount:r,maximumSequenceCount:this.#r}))}};export{I as AlphabeticProxy,v as AlphanumericProxy,i as AppExtension,b as AppHelperProxy,y as CharacterSetCreatorProxy,d as CharacterSetValidatorProxy,C as HexadecimalProxy,T as LibProxy,E as Multiplicities,S as NumericProxy,x as RegExpProxy,h as TransformerProxy,u as Types,c as appExtensionNS,l as appExtensionResourceBundle,p as i18nAppExtensionInit,n as i18nextAppExtension};
1
2
  /*!
2
3
  * Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
3
4
  * contributors
@@ -14,10 +15,3 @@
14
15
  * See the License for the specific language governing permissions and
15
16
  * limitations under the License.
16
17
  */
17
- export * from "./locale/i18n.js";
18
- export * from "./app-extension.js";
19
- export * from "./lib-proxy.js";
20
- export * from "./descriptor.js";
21
- export * from "./app-helper-proxy.js";
22
- export * from "./utility/index.js";
23
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/app-extension",
3
- "version": "1.0.48-beta",
3
+ "version": "1.0.49",
4
4
  "description": "Application extension framework for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,11 +34,11 @@
34
34
  "generate-locale-resources": "tsx src/generator/locale-resources-generator.ts"
35
35
  },
36
36
  "devDependencies": {
37
- "@aidc-toolkit/dev": "1.0.42-beta"
37
+ "@aidc-toolkit/dev": "^1.0.43"
38
38
  },
39
39
  "dependencies": {
40
- "@aidc-toolkit/core": "1.0.43-beta",
41
- "@aidc-toolkit/gs1": "1.0.45-beta",
42
- "@aidc-toolkit/utility": "1.0.44-beta"
40
+ "@aidc-toolkit/core": "^1.0.44",
41
+ "@aidc-toolkit/gs1": "^1.0.46",
42
+ "@aidc-toolkit/utility": "^1.0.45"
43
43
  }
44
44
  }
@@ -8,6 +8,7 @@ import {
8
8
  type Promisable
9
9
  } from "@aidc-toolkit/core";
10
10
  import type { Logger } from "tslog";
11
+ import type { LibProxy } from "./lib-proxy.js";
11
12
  import { i18nextAppExtension } from "./locale/i18n.js";
12
13
  import type { StreamingCancelledCallback, StreamingConsumerCallback } from "./streaming.js";
13
14
  import type { ErrorExtends, MatrixResult, SheetAddress, SheetRange, SingletonResult } from "./type.js";
@@ -76,6 +77,11 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
76
77
  */
77
78
  readonly #memoryTransport: MemoryTransport<object>;
78
79
 
80
+ /**
81
+ * Proxies map for lazy loading and memory management.
82
+ */
83
+ readonly #proxiesMap = new WeakMap<object, LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>>();
84
+
79
85
  /**
80
86
  * Constructor.
81
87
  *
@@ -155,6 +161,29 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
155
161
  */
156
162
  abstract get maximumHeight(): number;
157
163
 
164
+ /**
165
+ * Get a proxy instance. The use of a weak map ensures that proxies are loaded only as needed and may be garbage
166
+ * collected if required.
167
+ *
168
+ * @param ProxyConstructor
169
+ * Proxy constructor.
170
+ *
171
+ * @returns
172
+ * Proxy instance.
173
+ */
174
+ getProxy<T extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>>(ProxyConstructor: new (appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) => T): T {
175
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is managed in this method.
176
+ let proxy = this.#proxiesMap.get(ProxyConstructor) as T | undefined;
177
+
178
+ if (proxy === undefined) {
179
+ proxy = new ProxyConstructor(this);
180
+
181
+ this.#proxiesMap.set(ProxyConstructor, proxy);
182
+ }
183
+
184
+ return proxy;
185
+ }
186
+
158
187
  /**
159
188
  * Get the sheet address from an invocation context.
160
189
  *
@@ -31,6 +31,13 @@ const spillMaximumHeightParameterDescriptor: ExtendsParameterDescriptor = {
31
31
  name: "spillMaximumHeight"
32
32
  };
33
33
 
34
+ const logLevelParameterDescriptor: ParameterDescriptor = {
35
+ name: "logLevel",
36
+ type: Types.String,
37
+ multiplicity: Multiplicities.Singleton,
38
+ isRequired: false
39
+ };
40
+
34
41
  /**
35
42
  * Maximum dimensions.
36
43
  */
@@ -257,6 +264,42 @@ export class AppHelperProxy<ThrowError extends boolean, TError extends ErrorExte
257
264
  return result;
258
265
  }
259
266
 
267
+ /**
268
+ * Get the logger messages. This is a snapshot, with the option to change the log level for the next call.
269
+ *
270
+ * @param logLevelString
271
+ * Log level as string.
272
+ *
273
+ * @returns
274
+ * Logger messages.
275
+ */
276
+ @proxy.describeMethod({
277
+ type: Types.String,
278
+ multiplicity: Multiplicities.Array,
279
+ isHidden: true,
280
+ parameterDescriptors: [logLevelParameterDescriptor]
281
+ })
282
+ loggerMessages(logLevelString: Nullishable<string>): MatrixResult<string, ThrowError, TError> {
283
+ const appExtension = this.appExtension;
284
+
285
+ let logLevel: LogLevel | undefined = undefined;
286
+
287
+ if (!isNullish(logLevelString)) {
288
+ try {
289
+ logLevel = logLevelOf(logLevelString);
290
+ } catch {
291
+ // Ignore error.
292
+ }
293
+ }
294
+
295
+ // Set log level if required.
296
+ if (logLevel !== undefined) {
297
+ appExtension.logger.settings.minLevel = logLevel;
298
+ }
299
+
300
+ return appExtension.memoryTransport.messages.map(message => [message]);
301
+ }
302
+
260
303
  /**
261
304
  * Get the logger messages as a stream.
262
305
  *
@@ -271,14 +314,9 @@ export class AppHelperProxy<ThrowError extends boolean, TError extends ErrorExte
271
314
  multiplicity: Multiplicities.Array,
272
315
  isHidden: true,
273
316
  isStream: true,
274
- parameterDescriptors: [{
275
- name: "logLevel",
276
- type: Types.String,
277
- multiplicity: Multiplicities.Singleton,
278
- isRequired: false
279
- }]
317
+ parameterDescriptors: [logLevelParameterDescriptor]
280
318
  })
281
- loggerMessages(logLevelString: Nullishable<string>, streamingInvocationContext: Nullishable<TStreamingInvocationContext>): void {
319
+ loggerStream(logLevelString: Nullishable<string>, streamingInvocationContext: Nullishable<TStreamingInvocationContext>): void {
282
320
  if (isNullish(streamingInvocationContext)) {
283
321
  // Application error; no localization necessary.
284
322
  throw new Error("Streaming invocation context not provided by application");
@@ -0,0 +1,292 @@
1
+ import {
2
+ type ClassDescriptor,
3
+ type MethodDescriptor,
4
+ type ParameterDescriptor,
5
+ type Type,
6
+ Types
7
+ } from "../descriptor.js";
8
+ import { type FunctionLocalization, Generator, type Localization } from "./generator.js";
9
+
10
+ /**
11
+ * Class type alias.
12
+ */
13
+ export interface ClassTypeAlias {
14
+ /**
15
+ * Name.
16
+ */
17
+ readonly name: string;
18
+
19
+ /**
20
+ * Getter function.
21
+ */
22
+ readonly getter: string;
23
+
24
+ /**
25
+ * Declaration associating name with implementation type and creating getter function.
26
+ */
27
+ readonly declaration: string[];
28
+ }
29
+
30
+ /**
31
+ * Function implementation.
32
+ */
33
+ export interface FunctionImplementation {
34
+ /**
35
+ * Function name.
36
+ */
37
+ readonly functionName: string;
38
+
39
+ /**
40
+ * Parameter localizations with JavaScript type and parameter descriptor.
41
+ */
42
+ readonly parameterLocalizations: ReadonlyArray<Localization & {
43
+ /**
44
+ * JavaScript type.
45
+ */
46
+ javaScriptType: string;
47
+
48
+ /**
49
+ * Parameter descriptor.
50
+ */
51
+ parameterDescriptor?: ParameterDescriptor;
52
+ }>;
53
+
54
+ /**
55
+ * Declaration.
56
+ */
57
+ readonly declaration: string[];
58
+ }
59
+
60
+ /**
61
+ * Generator with helpers for writing TypeScript functions file.
62
+ */
63
+ export abstract class FunctionsGenerator extends Generator {
64
+ /**
65
+ * Mapping of descriptor types to JavaScript types.
66
+ */
67
+ static readonly #DESCRIPTOR_TYPE_STRINGS: Readonly<Record<Type, string>> = {
68
+ [Types.String]: "string",
69
+ [Types.Number]: "number",
70
+ [Types.Boolean]: "boolean",
71
+ [Types.Any]: "any"
72
+ };
73
+
74
+ protected static readonly BASE_IMPORTS = [
75
+ "import * as AppExtension from \"@aidc-toolkit/app-extension\";",
76
+ "import { appExtension } from \"./app-extension.js\";"
77
+ ];
78
+
79
+ /**
80
+ * If true, functions are declared inline rather than using `function`.
81
+ */
82
+ readonly #inline: boolean;
83
+
84
+ /**
85
+ * If true, application extension supports context.
86
+ */
87
+ readonly #supportsContext: boolean;
88
+
89
+ /**
90
+ * Invocation context type name.
91
+ */
92
+ readonly #invocationContextTypeName: string;
93
+
94
+ /**
95
+ * Streaming invocation context type name.
96
+ */
97
+ readonly #streamingInvocationContextTypeName: string;
98
+
99
+ /**
100
+ * Template declaration for type alias.
101
+ */
102
+ readonly #templateDeclaration: string;
103
+
104
+ /**
105
+ * Current class type alias.
106
+ */
107
+ #classTypeAlias!: ClassTypeAlias;
108
+
109
+ /**
110
+ * Constructor.
111
+ *
112
+ * @param version
113
+ * Package version.
114
+ *
115
+ * @param inline
116
+ * If true, functions are declared inline rather than using `function`.
117
+ *
118
+ * @param throwError
119
+ * If true, errors are reported through the throw/catch mechanism.
120
+ *
121
+ * @param errorTypeName
122
+ * Error type name.
123
+ *
124
+ * @param supportsContext
125
+ * If true, application extension supports context.
126
+ *
127
+ * Big integer type name.
128
+ * @param invocationContextTypeName
129
+ * Invocation context type name.
130
+ *
131
+ * @param streamingInvocationContextTypeName
132
+ * Streaming invocation context type name.
133
+ *
134
+ * @param bigIntTypeName
135
+ * Big integer type name.
136
+ */
137
+ constructor(version: string, inline: boolean, throwError: boolean, errorTypeName: string, supportsContext: boolean, invocationContextTypeName: string, streamingInvocationContextTypeName: string, bigIntTypeName: string) {
138
+ super(version, true);
139
+
140
+ this.#inline = inline;
141
+
142
+ this.#supportsContext = supportsContext;
143
+ this.#invocationContextTypeName = invocationContextTypeName;
144
+ this.#streamingInvocationContextTypeName = streamingInvocationContextTypeName;
145
+
146
+ this.#templateDeclaration = `<${throwError}, ${errorTypeName}, ${invocationContextTypeName}, ${streamingInvocationContextTypeName}, ${bigIntTypeName}>`;
147
+ }
148
+
149
+ /**
150
+ * Get the class type alias.
151
+ */
152
+ get classTypeAlias(): ClassTypeAlias {
153
+ return this.#classTypeAlias;
154
+ }
155
+
156
+ /**
157
+ * Get the import statement for a namespace.
158
+ *
159
+ * @param namespace
160
+ * Namespace.
161
+ *
162
+ * @returns
163
+ * Import statement.
164
+ */
165
+ protected getNamespaceImport(namespace: string): string {
166
+ return `import * as AppExtension${namespace} from "@aidc-toolkit/app-extension/${namespace.toLowerCase()}";`;
167
+ }
168
+
169
+ /**
170
+ * @inheritDoc
171
+ */
172
+ protected override createClassProxy(classDescriptor: ClassDescriptor): void {
173
+ const classDescriptorNamespace = classDescriptor.namespace ?? "";
174
+ const name = `${classDescriptorNamespace}${classDescriptor.name}`;
175
+ const getter = `get${name}()`;
176
+ const implementation = `AppExtension${classDescriptorNamespace}.${classDescriptor.name}${this.#templateDeclaration}`;
177
+
178
+ this.#classTypeAlias = {
179
+ name,
180
+ getter,
181
+ declaration: [
182
+ "",
183
+ "/**",
184
+ " * Class type alias name.",
185
+ " */",
186
+ `type ${name} = ${implementation};`,
187
+ "",
188
+ "/**",
189
+ " * Getter function to get an instance of the class.",
190
+ " *",
191
+ " * @returns",
192
+ " * Class instance.",
193
+ " */",
194
+ `function ${getter}: ${name} {`,
195
+ ` return appExtension.getProxy(${implementation});`,
196
+ "}"
197
+ ]
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Get a function implementation.
203
+ *
204
+ * @param methodDescriptor
205
+ * Method descriptor.
206
+ *
207
+ * @param functionNamePrefix
208
+ * Function name prefix.
209
+ *
210
+ * @param functionLocalization
211
+ * Function localization. May be undefined for hidden functions, in which case generated
212
+ *
213
+ * @param parameterCallback
214
+ * Callback to modify parameter in implementation function call.
215
+ *
216
+ * @returns
217
+ * Function implementation.
218
+ */
219
+ protected getFunctionImplementation(methodDescriptor: MethodDescriptor, functionNamePrefix: string, functionLocalization: FunctionLocalization | undefined, parameterCallback?: (name: string, parameterDescriptor: ParameterDescriptor) => string): FunctionImplementation {
220
+ const methodType = `${this.classTypeAlias.name}["${methodDescriptor.name}"]`;
221
+
222
+ const parameterDescriptors = methodDescriptor.parameterDescriptors;
223
+
224
+ const parameterLocalizations: Array<FunctionImplementation["parameterLocalizations"][number]> = parameterDescriptors.map((parameterDescriptor) => {
225
+ const parameterLocalization = functionLocalization?.parametersMap.get(parameterDescriptor.name) ?? {
226
+ name: parameterDescriptor.name,
227
+ description: "*** NO LOCALIZATION ***"
228
+ };
229
+
230
+ return {
231
+ ...parameterLocalization,
232
+ javaScriptType: FunctionsGenerator.#DESCRIPTOR_TYPE_STRINGS[parameterDescriptor.type],
233
+ parameterDescriptor
234
+ };
235
+ });
236
+
237
+ const dummyParameters: string[] = [];
238
+
239
+ if (this.#supportsContext) {
240
+ if (methodDescriptor.requiresContext === true) {
241
+ parameterLocalizations.push({
242
+ name: "invocationContext",
243
+ description: "Invocation context.",
244
+ javaScriptType: this.#invocationContextTypeName
245
+ });
246
+ }
247
+
248
+ if (methodDescriptor.isStream === true) {
249
+ parameterLocalizations.push({
250
+ name: "streamingInvocationContext",
251
+ description: "Streaming invocation context.",
252
+ javaScriptType: this.#streamingInvocationContextTypeName
253
+ });
254
+ }
255
+ } else {
256
+ if (methodDescriptor.requiresContext === true) {
257
+ // Invocation context type name represents a literal dummy value.
258
+ dummyParameters.push(this.#invocationContextTypeName);
259
+ }
260
+
261
+ if (methodDescriptor.isStream === true) {
262
+ // Streaming invocation context type name represents a literal dummy value.
263
+ dummyParameters.push(this.#streamingInvocationContextTypeName);
264
+ }
265
+ }
266
+
267
+ const asyncQualifier = methodDescriptor.isAsync === true ? "async " : "";
268
+ const functionName = functionNamePrefix === "" ?
269
+ functionLocalization?.name ?? methodDescriptor.name :
270
+ `${functionNamePrefix}${functionLocalization?.titleCaseName ?? methodDescriptor.name.replace(/^[a-z]/u, c => c.toUpperCase())}`;
271
+
272
+ return {
273
+ functionName,
274
+ parameterLocalizations,
275
+ declaration: [
276
+ `${
277
+ !this.#inline ?
278
+ `export ${asyncQualifier}function ${functionName}` :
279
+ asyncQualifier
280
+ }(${parameterLocalizations.map((parameterLocalization, index) =>
281
+ `${parameterLocalization.name}: Parameters<${methodType}>[${index}]`
282
+ ).join(", ")}): ReturnType<${methodType}> ${!this.#inline ? "{" : "=>"}`,
283
+ ` ${!this.#inline ? "return " : ""}${(this.classTypeAlias.getter)}.${methodDescriptor.name}(${[...parameterLocalizations.map(parameterLocalization =>
284
+ parameterCallback === undefined || parameterLocalization.parameterDescriptor === undefined ?
285
+ parameterLocalization.name :
286
+ parameterCallback(parameterLocalization.name, parameterLocalization.parameterDescriptor)
287
+ ), ...dummyParameters].join(", ")})${(!this.#inline ? ";" : "")}`,
288
+ ...!this.#inline ? ["}"] : []
289
+ ]
290
+ };
291
+ }
292
+ }
@@ -1,4 +1,4 @@
1
- import { ALPHA_URL, getLogger, I18nEnvironments, type Promisable, websiteURL } from "@aidc-toolkit/core";
1
+ import { ALPHA_URL, getLogger, I18nLanguageDetectors, type Promisable, websiteURL } from "@aidc-toolkit/core";
2
2
  import type { DefaultNamespace, ParseKeys } from "i18next";
3
3
  import type { Logger } from "tslog";
4
4
  import { AppHelperProxy } from "../app-helper-proxy.js";
@@ -155,18 +155,15 @@ export abstract class Generator {
155
155
  protected abstract createCategory(namespace: string | undefined, category: string, categoryLocalizationsMap: ReadonlyMap<string, string>): void;
156
156
 
157
157
  /**
158
- * Create a proxy object for a class.
159
- *
160
- * @param objectName
161
- * Object name, derived from namespace and class name.
158
+ * Create a proxy for a class.
162
159
  *
163
160
  * @param classDescriptor
164
161
  * Class descriptor.
165
162
  */
166
- protected abstract createProxyObject(objectName: string, classDescriptor: ClassDescriptor): void;
163
+ protected abstract createClassProxy(classDescriptor: ClassDescriptor): void;
167
164
 
168
165
  /**
169
- * Create a proxy function for a class and method.
166
+ * Create a proxy for a method.
170
167
  *
171
168
  * @param classDescriptor
172
169
  * Class descriptor.
@@ -177,7 +174,7 @@ export abstract class Generator {
177
174
  * @param functionLocalizationsMap
178
175
  * Function localizations map.
179
176
  */
180
- protected abstract createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor, functionLocalizationsMap: ReadonlyMap<string, FunctionLocalization>): void;
177
+ protected abstract createMethodProxy(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor, functionLocalizationsMap: ReadonlyMap<string, FunctionLocalization>): void;
181
178
 
182
179
  /**
183
180
  * Finalize the generation of the output.
@@ -228,7 +225,7 @@ export abstract class Generator {
228
225
  async generate(): Promise<void> {
229
226
  let success = false;
230
227
 
231
- await i18nAppExtensionInit(I18nEnvironments.CLI);
228
+ await i18nAppExtensionInit(I18nLanguageDetectors.CLI);
232
229
 
233
230
  const documentationBaseURL = websiteURL(this.version, true, await ALPHA_URL);
234
231
 
@@ -293,31 +290,14 @@ export abstract class Generator {
293
290
 
294
291
  namespaceClassNamesSet.add(namespaceClassName);
295
292
 
296
- // First capture group is:
297
- // - one or more uppercase letters followed by zero or more numbers; or
298
- // - single uppercase letter followed by zero or more characters except uppercase letters or period.
299
- //
300
- // Second capture group is:
301
- // - single uppercase letter followed by zero or more characters except period; or
302
- // - zero characters (empty string).
303
- //
304
- // Third capture group, separated by optional period, is:
305
- // - single uppercase letter followed by zero or more characters (remainder of string); or
306
- // - zero characters (empty string).
307
- const objectNameGroups = /^(?<namespaceFirstWord>[A-Z]+[0-9]*|[A-Z][^A-Z.]*)(?<namespaceRemaining>[A-Z][^.]*|)\.?(?<className>[A-Z].*|)$/u.exec(namespaceClassName)?.groups;
308
-
309
- if (objectNameGroups === undefined) {
310
- throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
311
- }
312
-
313
- this.createProxyObject(`${objectNameGroups["namespaceFirstWord"].toLowerCase()}${objectNameGroups["namespaceRemaining"]}${objectNameGroups["className"]}`, classDescriptor);
293
+ this.createClassProxy(classDescriptor);
314
294
 
315
295
  for (const methodDescriptor of classDescriptor.methodDescriptors) {
316
296
  const functionLocalizationsMap = new Map(methodDescriptor.isHidden !== true ?
317
297
  this.locales.map(locale =>
318
298
  [locale, Generator.#generateLocalization<FunctionLocalization>(locale, `Functions.${namespacePrefix}${methodDescriptor.functionName}`, (locale, localization) => ({
319
299
  ...localization,
320
- titleCaseName: localization.titleCaseName ?? `${localization.name.substring(0, 1).toUpperCase()}${localization.name.substring(1)}`,
300
+ titleCaseName: localization.titleCaseName ?? localization.name.replace(/^[a-z]/u, c => c.toUpperCase()),
321
301
  documentationURL: `${documentationBaseURL}/${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
322
302
  parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
323
303
  // eslint-disable-next-line max-nested-callbacks -- Callback is empty.
@@ -329,7 +309,7 @@ export abstract class Generator {
329
309
  []
330
310
  );
331
311
 
332
- this.createProxyFunction(classDescriptor, methodDescriptor, functionLocalizationsMap);
312
+ this.createMethodProxy(classDescriptor, methodDescriptor, functionLocalizationsMap);
333
313
  }
334
314
  }
335
315
  }
@@ -16,3 +16,4 @@
16
16
  */
17
17
 
18
18
  export * from "./generator.js";
19
+ export * from "./functions-generator.js";
@@ -1,13 +1,13 @@
1
1
  import type { LocaleResources } from "@aidc-toolkit/core";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
- import packageConfiguration from "../../package.json" with { type: "json" };
5
4
  import type {
6
5
  ClassDescriptor,
7
6
  ExtendsParameterDescriptor,
8
7
  MethodDescriptor,
9
8
  ParameterDescriptor
10
9
  } from "../descriptor.js";
10
+ import { VERSION } from "../version.js";
11
11
  import { Generator } from "./generator.js";
12
12
 
13
13
  /**
@@ -91,7 +91,7 @@ class LocaleResourcesGenerator extends Generator {
91
91
  * Constructor.
92
92
  */
93
93
  constructor() {
94
- super(packageConfiguration.version, false);
94
+ super(VERSION, false);
95
95
  }
96
96
 
97
97
  /**
@@ -115,7 +115,7 @@ class LocaleResourcesGenerator extends Generator {
115
115
  /**
116
116
  * @inheritDoc
117
117
  */
118
- protected override createProxyObject(): void {
118
+ protected override createClassProxy(): void {
119
119
  }
120
120
 
121
121
  /**
@@ -193,7 +193,7 @@ class LocaleResourcesGenerator extends Generator {
193
193
  /**
194
194
  * @inheritDoc
195
195
  */
196
- protected override createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor): void {
196
+ protected override createMethodProxy(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor): void {
197
197
  // Hidden functions aren't localized.
198
198
  if (methodDescriptor.isHidden !== true) {
199
199
  // Add any parameters that are not already known.
@@ -255,15 +255,17 @@ class LocaleResourcesGenerator extends Generator {
255
255
  * Merged locale resources.
256
256
  */
257
257
  #merge(logChanges: boolean, parentKey: string, sourceLocaleResources: LocaleResources, destinationLocaleResources: LocaleResources, addMissing: boolean): LocaleResources {
258
- // Some entries at the top are not part of the generator output.
259
- const deleteMissing = parentKey.length !== 0;
258
+ // Some entries at the root are not part of the generator output.
259
+ const atRoot = parentKey === "";
260
+
261
+ const atFunction = parentKey.startsWith("Functions.");
260
262
 
261
263
  const newDestinationLocaleResources: LocaleResources = {};
262
264
 
263
265
  // Copy over or delete any destination keys that are not in source.
264
266
  for (const [key, destinationValue] of Object.entries(destinationLocaleResources)) {
265
267
  if (!(key in sourceLocaleResources)) {
266
- if (!deleteMissing) {
268
+ if (atRoot || (atFunction && key === "titleCaseName")) {
267
269
  newDestinationLocaleResources[key] = destinationValue;
268
270
  } else if (logChanges) {
269
271
  this.logger.info(`Deleting ${parentKey}${key}...`);
@@ -67,7 +67,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
67
67
  }
68
68
 
69
69
  @proxy.describeMethod({
70
- type: Types.String,
70
+ type: Types.Boolean,
71
71
  multiplicity: Multiplicities.Matrix,
72
72
  parameterDescriptors: [numericSWithCheckDigitParameterDescriptor]
73
73
  })
@@ -85,7 +85,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
85
85
  }
86
86
 
87
87
  @proxy.describeMethod({
88
- type: Types.String,
88
+ type: Types.Boolean,
89
89
  multiplicity: Multiplicities.Singleton,
90
90
  parameterDescriptors: [{
91
91
  ...numericSFourOrFiveDigitsParameterDescriptor,
@@ -106,7 +106,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
106
106
  }
107
107
 
108
108
  @proxy.describeMethod({
109
- type: Types.String,
109
+ type: Types.Boolean,
110
110
  multiplicity: Multiplicities.Matrix,
111
111
  parameterDescriptors: [ai82SWithCheckCharacterPairParameterDescriptor]
112
112
  })
@@ -128,7 +128,7 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
128
128
  }
129
129
 
130
130
  @proxy.describeMethod({
131
- type: Types.String,
131
+ type: Types.Boolean,
132
132
  multiplicity: Multiplicities.Matrix,
133
133
  parameterDescriptors: [validateGTINParameterDescriptor, gtinLevelParameterDescriptor]
134
134
  })
@@ -148,7 +148,7 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
148
148
  }
149
149
 
150
150
  @proxy.describeMethod({
151
- type: Types.String,
151
+ type: Types.Boolean,
152
152
  multiplicity: Multiplicities.Matrix,
153
153
  parameterDescriptors: [validateGTIN14ParameterDescriptor]
154
154
  })
@@ -61,7 +61,7 @@ abstract class NumericIdentifierValidatorProxy<ThrowError extends boolean, TErro
61
61
  }
62
62
 
63
63
  @proxy.describeMethod({
64
- type: Types.String,
64
+ type: Types.Boolean,
65
65
  multiplicity: Multiplicities.Matrix,
66
66
  parameterDescriptors: [validateIdentifierParameterDescriptor]
67
67
  })
@@ -109,7 +109,7 @@ export abstract class NonNumericIdentifierValidatorProxy<ThrowError extends bool
109
109
  }
110
110
 
111
111
  @proxy.describeMethod({
112
- type: Types.String,
112
+ type: Types.Boolean,
113
113
  multiplicity: Multiplicities.Matrix,
114
114
  parameterDescriptors: [validateIdentifierParameterDescriptor, exclusionAllNumericParameterDescriptor]
115
115
  })