@kontur.candy/tools 2.253.0 → 2.255.0

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 (85) hide show
  1. package/README.md +0 -16
  2. package/distr/Common/AsyncUtils.js +7 -0
  3. package/distr/Common/AsyncUtils.js.map +1 -1
  4. package/distr/Common/CandyApiClient/CandyApiClient.js +37 -5
  5. package/distr/Common/CandyApiClient/CandyApiClient.js.map +1 -1
  6. package/distr/Common/CandyApiClient/ClientDraftInfo/ClientDraftInfoResponse.js.map +1 -1
  7. package/distr/Common/CandyApiClient/FakeCandyApiClient.js +20 -0
  8. package/distr/Common/CandyApiClient/FakeCandyApiClient.js.map +1 -1
  9. package/distr/Common/CandyApiClient/ICandyApiClient.js.map +1 -1
  10. package/distr/Common/CommonConstants/DefaultServicesUrls.js +3 -1
  11. package/distr/Common/CommonConstants/DefaultServicesUrls.js.map +1 -1
  12. package/distr/Common/IntRangeUtils.js +4 -0
  13. package/distr/Common/IntRangeUtils.js.map +1 -1
  14. package/distr/Common/KCLangRuntimeUtils.js +7 -1
  15. package/distr/Common/KCLangRuntimeUtils.js.map +1 -1
  16. package/distr/Common/TypingUtils.js +4 -0
  17. package/distr/Common/TypingUtils.js.map +1 -1
  18. package/distr/Common/async/Channel.js +64 -0
  19. package/distr/Common/async/Channel.js.map +1 -0
  20. package/distr/Common/async/pool/AsyncPool.js +145 -0
  21. package/distr/Common/async/pool/AsyncPool.js.map +1 -0
  22. package/distr/Common/async/pool/FixedPool.js +29 -0
  23. package/distr/Common/async/pool/FixedPool.js.map +1 -0
  24. package/distr/Common/async/pool/LimitedPool.js +81 -0
  25. package/distr/Common/async/pool/LimitedPool.js.map +1 -0
  26. package/distr/Common/async/pool/Registry.js +73 -0
  27. package/distr/Common/async/pool/Registry.js.map +1 -0
  28. package/distr/Common/async/pool/index.js +13 -0
  29. package/distr/Common/async/pool/index.js.map +1 -0
  30. package/distr/Common/ds/LinkedList.js +64 -0
  31. package/distr/Common/ds/LinkedList.js.map +1 -0
  32. package/distr/Common/multithread/ThreadPool.js +74 -0
  33. package/distr/Common/multithread/ThreadPool.js.map +1 -0
  34. package/distr/Tools/src/BuildTasks/Form/GenerateForm.js +2 -1
  35. package/distr/Tools/src/BuildTasks/Form/GenerateForm.js.map +1 -1
  36. package/distr/Tools/src/BuildTasks/Form/NullFormGenerator.js +0 -3
  37. package/distr/Tools/src/BuildTasks/Form/NullFormGenerator.js.map +1 -1
  38. package/distr/Tools/src/BuildTasks/Generator/AcquirePublishedGeneratorTask.js +1 -1
  39. package/distr/Tools/src/BuildTasks/Generator/AcquirePublishedGeneratorTask.js.map +1 -1
  40. package/distr/Tools/src/BuildTasks/Generator/BuildGeneratorFromSourcesTask.js +13 -4
  41. package/distr/Tools/src/BuildTasks/Generator/BuildGeneratorFromSourcesTask.js.map +1 -1
  42. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/CreateAsyncGenerator.js +29 -107
  43. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/CreateAsyncGenerator.js.map +1 -1
  44. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/GeneratorPool.js +62 -0
  45. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/GeneratorPool.js.map +1 -0
  46. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/GeneratorRequireUtils.js +29 -36
  47. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/GeneratorRequireUtils.js.map +1 -1
  48. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/ReadSourcesAndProcessSugarWorker.js +28 -35
  49. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/ReadSourcesAndProcessSugarWorker.js.map +1 -1
  50. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/TypedThreadWorker.js +14 -0
  51. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/TypedThreadWorker.js.map +1 -0
  52. package/distr/Tools/src/BuildTasks/ResolveFormInfo.js +1 -1
  53. package/distr/Tools/src/BuildTasks/ResolveFormInfo.js.map +1 -1
  54. package/distr/Tools/src/CLICommands/BuildForms/BuildFormsOptions.js +0 -10
  55. package/distr/Tools/src/CLICommands/BuildForms/BuildFormsOptions.js.map +1 -1
  56. package/distr/Tools/src/CLICommands/BuildForms/RunBuildForms.js +2 -6
  57. package/distr/Tools/src/CLICommands/BuildForms/RunBuildForms.js.map +1 -1
  58. package/distr/Tools/src/CLICommands/BuildServer/BuildServerServerOptions.js +0 -22
  59. package/distr/Tools/src/CLICommands/BuildServer/BuildServerServerOptions.js.map +1 -1
  60. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/BuildServerBuildFormsController.js +1 -3
  61. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/BuildServerBuildFormsController.js.map +1 -1
  62. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/BuildServerFormInfoController.js +1 -1
  63. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/BuildServerFormInfoController.js.map +1 -1
  64. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/DevServers/BuildFormDevServer.js +2 -5
  65. package/distr/Tools/src/CLICommands/BuildServer/ResourcesControllers/DevServers/BuildFormDevServer.js.map +1 -1
  66. package/distr/Tools/src/CLICommands/DevBuild/DevBuildOptions.js +0 -10
  67. package/distr/Tools/src/CLICommands/DevBuild/DevBuildOptions.js.map +1 -1
  68. package/distr/Tools/src/CLICommands/DevBuild/RunDevBuild.js +35 -6
  69. package/distr/Tools/src/CLICommands/DevBuild/RunDevBuild.js.map +1 -1
  70. package/distr/Tools/src/CLICommands/Localization/RunLocalization.js +1 -1
  71. package/distr/Tools/src/CLICommands/Localization/RunLocalization.js.map +1 -1
  72. package/distr/Tools/src/CLICommands/SugarExtractor/Utils.js +1 -1
  73. package/distr/Tools/src/CLICommands/SugarExtractor/Utils.js.map +1 -1
  74. package/distr/Tools/src/LocalServerFrontEndDist/enhancedClient.js +1 -1
  75. package/distr/Tools/src/LocalServerFrontEndDist/index.js +1 -1
  76. package/distr/Tools/src/LocalServerFrontEndDist/index.js.map +1 -1
  77. package/distr/Tools/src/StaticFilesForProductionResourcesDir/client.js +14 -13
  78. package/distr/Tools/src/StaticFilesForProductionResourcesDir/client.js.map +1 -1
  79. package/distr/Tools/src/StaticFilesForProductionResourcesDir/client.min.js +14 -13
  80. package/distr/Tools/src/StaticFilesForProductionResourcesDir/client.min.js.map +1 -1
  81. package/package.json +1 -1
  82. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/RequireUncached.js +0 -40
  83. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/RequireUncached.js.map +0 -1
  84. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/TypedProcessWorker.js +0 -19
  85. package/distr/Tools/src/BuildTasks/Generator/GeneratorWorker/TypedProcessWorker.js.map +0 -1
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AsyncPool = void 0;
7
+ var _TypingUtils = require("../../TypingUtils");
8
+ var _Channel = require("../Channel");
9
+ var _Registry = require("./Registry");
10
+ /**
11
+ * Базовый пул, предоставляющий:
12
+ * - `exec` - безопасный доступ к элементу
13
+ * - `add` - расширение
14
+ * - `evict` - сокращение
15
+ * - `dispose` - уничтожение
16
+ */
17
+ class AsyncPool {
18
+ constructor() {
19
+ this.disposed = false;
20
+ this.registry = new _Registry.Registry();
21
+ this.idles = new _Channel.Channel();
22
+ this.running = 0;
23
+ this.destroying = new Set();
24
+ this.shutdownSignal = Promise.withResolvers();
25
+ }
26
+ /**
27
+ * Добавляет элемент в пул и делает его немедленно доступным.
28
+ *
29
+ * @throws если `item` уже присутствует в пуле.
30
+ */
31
+ add(item) {
32
+ this.ensureAlive();
33
+ this.registry.add(item);
34
+ this.idles.write(item);
35
+ }
36
+
37
+ /**
38
+ * Уменьшает ёмкость пула на один элемент.
39
+ *
40
+ * - Если есть свободный элемент — удаляет его немедленно.
41
+ * - Если все элементы заняты — помечает один из них `Doomed`:
42
+ * при следующем `release` он будет отброшен, а не возвращён в пул.
43
+ * - Если пул пуст — не делает ничего.
44
+ *
45
+ * @returns `true`, если ёмкость была уменьшена; `false`, если пул уже пуст.
46
+ */
47
+ evict() {
48
+ this.ensureAlive();
49
+ const idle = this.idles.readSync();
50
+ if (idle !== undefined) {
51
+ this.destroy(idle);
52
+ return true;
53
+ }
54
+ const busy = this.registry.findBusy();
55
+ if (busy) {
56
+ this.registry.doom(busy);
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+
62
+ /**
63
+ * Захватывает свободный элемент пула, вызывает `await fn(item)` и возвращает элемент обратно.
64
+ *
65
+ * - Если нет свободного элемента — ожидает появления (блокирует вызов).
66
+ * - Ожидающие вызовы получают элемент в порядке FIFO.
67
+ * - Ошибка внутри `fn` пробрасывается вызывающей стороне.
68
+ *
69
+ * @remarks
70
+ * Подразумевается, что `fn` всегда `await`-ит I/O-bound операцию,
71
+ * что разрывает цепочку микрозадач и даёт event loop провернуться.
72
+ * Поэтому оборачивание в `setTimeout(resolve, 0)` не производится.
73
+ *
74
+ * @warn
75
+ * Вложенный `exec` на пуле размера 1, вызванный из `fn` с `await`,
76
+ * приведёт к дедлоку: outer ждёт inner, inner ждёт освобождения outer.
77
+ */
78
+ async exec(fn) {
79
+ this.ensureAlive();
80
+ const item = await this.capture();
81
+ try {
82
+ this.running++;
83
+ return await fn(item);
84
+ } finally {
85
+ this.release(item);
86
+ this.running--;
87
+ if (this.disposed && this.running === 0) {
88
+ this.shutdownSignal.resolve();
89
+ }
90
+ }
91
+ }
92
+ async dispose() {
93
+ if (!this.disposed) {
94
+ this.disposed = true;
95
+ this.idles.close("Pool disposed");
96
+ this.releaseAll();
97
+ }
98
+ await this.shutdown();
99
+ }
100
+ releaseAll() {
101
+ const idles = this.registry.doomAll();
102
+ idles.forEach(i => this.release(i));
103
+ }
104
+ async shutdown() {
105
+ if (this.running > 0) {
106
+ await this.shutdownSignal.promise;
107
+ }
108
+ await Promise.allSettled(this.destroying);
109
+ }
110
+ async capture() {
111
+ const item = await this.idles.read();
112
+ return this.registry.capture(item);
113
+ }
114
+ release(item) {
115
+ const state = this.registry.stateOf(item);
116
+ switch (state) {
117
+ case _Registry.State.Busy:
118
+ return this.free(item);
119
+ case _Registry.State.Doomed:
120
+ return this.destroy(item);
121
+ case _Registry.State.Idle:
122
+ throw new Error("Pool: release not captured");
123
+ default:
124
+ return (0, _TypingUtils.ensureNever)(state);
125
+ }
126
+ }
127
+ free(item) {
128
+ this.registry.free(item);
129
+ this.idles.write(item);
130
+ }
131
+ destroy(item) {
132
+ this.registry.remove(item);
133
+ const promise = Promise.try(() => item.dispose());
134
+ this.destroying.add(promise);
135
+ // в destroying нужны лишь незавершенные item.dispose
136
+ promise.catch(_TypingUtils.noop).finally(() => this.destroying.delete(promise));
137
+ }
138
+ ensureAlive() {
139
+ if (this.disposed) {
140
+ throw new Error("Pool: interaction on disposed");
141
+ }
142
+ }
143
+ }
144
+ exports.AsyncPool = AsyncPool;
145
+ //# sourceMappingURL=AsyncPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncPool.js","names":["_TypingUtils","require","_Channel","_Registry","AsyncPool","constructor","disposed","registry","Registry","idles","Channel","running","destroying","Set","shutdownSignal","Promise","withResolvers","add","item","ensureAlive","write","evict","idle","readSync","undefined","destroy","busy","findBusy","doom","exec","fn","capture","release","resolve","dispose","close","releaseAll","shutdown","doomAll","forEach","i","promise","allSettled","read","state","stateOf","State","Busy","free","Doomed","Idle","Error","ensureNever","remove","try","catch","noop","finally","delete","exports"],"sources":["../../../../../Common/async/pool/AsyncPool.ts"],"sourcesContent":["import { ensureNever, noop } from \"../../TypingUtils\";\nimport { Channel } from \"../Channel\";\n\nimport { Registry, State } from \"./Registry\";\n\nexport interface Disposable extends NonNullable<unknown> {\n dispose: () => Promise<void>;\n}\n\n/**\n * Базовый пул, предоставляющий:\n * - `exec` - безопасный доступ к элементу\n * - `add` - расширение\n * - `evict` - сокращение\n * - `dispose` - уничтожение\n */\nexport class AsyncPool<Item extends Disposable> {\n private disposed = false;\n private readonly registry = new Registry<Item>();\n private readonly idles = new Channel<Item>();\n private running = 0;\n private readonly destroying = new Set<Promise<void>>();\n private readonly shutdownSignal = Promise.withResolvers<void>();\n\n /**\n * Добавляет элемент в пул и делает его немедленно доступным.\n *\n * @throws если `item` уже присутствует в пуле.\n */\n public add(item: Item): void {\n this.ensureAlive();\n this.registry.add(item);\n this.idles.write(item);\n }\n\n /**\n * Уменьшает ёмкость пула на один элемент.\n *\n * - Если есть свободный элемент — удаляет его немедленно.\n * - Если все элементы заняты — помечает один из них `Doomed`:\n * при следующем `release` он будет отброшен, а не возвращён в пул.\n * - Если пул пуст — не делает ничего.\n *\n * @returns `true`, если ёмкость была уменьшена; `false`, если пул уже пуст.\n */\n public evict(): boolean {\n this.ensureAlive();\n const idle = this.idles.readSync();\n if (idle !== undefined) {\n this.destroy(idle);\n return true;\n }\n const busy = this.registry.findBusy();\n if (busy) {\n this.registry.doom(busy);\n return true;\n }\n return false;\n }\n\n /**\n * Захватывает свободный элемент пула, вызывает `await fn(item)` и возвращает элемент обратно.\n *\n * - Если нет свободного элемента — ожидает появления (блокирует вызов).\n * - Ожидающие вызовы получают элемент в порядке FIFO.\n * - Ошибка внутри `fn` пробрасывается вызывающей стороне.\n *\n * @remarks\n * Подразумевается, что `fn` всегда `await`-ит I/O-bound операцию,\n * что разрывает цепочку микрозадач и даёт event loop провернуться.\n * Поэтому оборачивание в `setTimeout(resolve, 0)` не производится.\n *\n * @warn\n * Вложенный `exec` на пуле размера 1, вызванный из `fn` с `await`,\n * приведёт к дедлоку: outer ждёт inner, inner ждёт освобождения outer.\n */\n public async exec<R>(fn: (item: Item) => Promise<R>): Promise<R> {\n this.ensureAlive();\n const item = await this.capture();\n try {\n this.running++;\n return await fn(item);\n } finally {\n this.release(item);\n this.running--;\n if (this.disposed && this.running === 0) {\n this.shutdownSignal.resolve();\n }\n }\n }\n\n public async dispose(): Promise<void> {\n if (!this.disposed) {\n this.disposed = true;\n this.idles.close(\"Pool disposed\");\n this.releaseAll();\n }\n await this.shutdown();\n }\n\n private releaseAll() {\n const idles = this.registry.doomAll();\n idles.forEach(i => this.release(i));\n }\n\n private async shutdown(): Promise<void> {\n if (this.running > 0) {\n await this.shutdownSignal.promise;\n }\n await Promise.allSettled(this.destroying);\n }\n\n private async capture(): Promise<Item> {\n const item = await this.idles.read();\n return this.registry.capture(item);\n }\n\n private release(item: Item): void {\n const state = this.registry.stateOf(item);\n switch (state) {\n case State.Busy:\n return this.free(item);\n case State.Doomed:\n return this.destroy(item);\n case State.Idle:\n throw new Error(\"Pool: release not captured\");\n default:\n return ensureNever(state);\n }\n }\n\n private free(item: Item) {\n this.registry.free(item);\n this.idles.write(item);\n }\n\n private destroy(item: Item) {\n this.registry.remove(item);\n const promise = Promise.try(() => item.dispose());\n this.destroying.add(promise);\n // в destroying нужны лишь незавершенные item.dispose\n promise.catch(noop).finally(() => this.destroying.delete(promise));\n }\n\n private ensureAlive() {\n if (this.disposed) {\n throw new Error(\"Pool: interaction on disposed\");\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,SAAS,CAA0B;EAAAC,YAAA;IAAA,KACpCC,QAAQ,GAAG,KAAK;IAAA,KACPC,QAAQ,GAAG,IAAIC,kBAAQ,CAAO,CAAC;IAAA,KAC/BC,KAAK,GAAG,IAAIC,gBAAO,CAAO,CAAC;IAAA,KACpCC,OAAO,GAAG,CAAC;IAAA,KACFC,UAAU,GAAG,IAAIC,GAAG,CAAgB,CAAC;IAAA,KACrCC,cAAc,GAAGC,OAAO,CAACC,aAAa,CAAO,CAAC;EAAA;EAE/D;AACJ;AACA;AACA;AACA;EACWC,GAAGA,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C;EACJ;EAEQI,IAAIA,CAAC9B,IAAU,EAAE;IACrB,IAAI,CAACX,QAAQ,CAACyC,IAAI,CAAC9B,IAAI,CAAC;IACxB,IAAI,CAACT,KAAK,CAACW,KAAK,CAACF,IAAI,CAAC;EAC1B;EAEQO,OAAOA,CAACP,IAAU,EAAE;IACxB,IAAI,CAACX,QAAQ,CAAC8C,MAAM,CAACnC,IAAI,CAAC;IAC1B,MAAMuB,OAAO,GAAG1B,OAAO,CAACuC,GAAG,CAAC,MAAMpC,IAAI,CAACgB,OAAO,CAAC,CAAC,CAAC;IACjD,IAAI,CAACtB,UAAU,CAACK,GAAG,CAACwB,OAAO,CAAC;IAC5B;IACAA,OAAO,CAACc,KAAK,CAACC,iBAAI,CAAC,CAACC,OAAO,CAAC,MAAM,IAAI,CAAC7C,UAAU,CAAC8C,MAAM,CAACjB,OAAO,CAAC,CAAC;EACtE;EAEQtB,WAAWA,CAAA,EAAG;IAClB,IAAI,IAAI,CAACb,QAAQ,EAAE;MACf,MAAM,IAAI6C,KAAK,CAAC,+BAA+B,CAAC;IACpD;EACJ;AACJ;AAACQ,OAAA,CAAAvD,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FixedPool = void 0;
7
+ var _LimitedPool = require("./LimitedPool");
8
+ class FixedPool {
9
+ constructor({
10
+ size,
11
+ fabric
12
+ }) {
13
+ this.pool = void 0;
14
+ /** Прокси на {@link LimitedPool.exec} */
15
+ this.exec = void 0;
16
+ /** Прокси на {@link LimitedPool.dispose} */
17
+ this.dispose = void 0;
18
+ this.pool = new _LimitedPool.LimitedPool({
19
+ min: size,
20
+ max: size,
21
+ size: size,
22
+ fabric: fabric
23
+ });
24
+ this.exec = this.pool.exec.bind(this.pool);
25
+ this.dispose = this.pool.dispose.bind(this.pool);
26
+ }
27
+ }
28
+ exports.FixedPool = FixedPool;
29
+ //# sourceMappingURL=FixedPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FixedPool.js","names":["_LimitedPool","require","FixedPool","constructor","size","fabric","pool","exec","dispose","LimitedPool","min","max","bind","exports"],"sources":["../../../../../Common/async/pool/FixedPool.ts"],"sourcesContent":["import type { Disposable } from \"./AsyncPool\";\nimport { LimitedPool } from \"./LimitedPool\";\n\ninterface Options<Item> {\n size: number;\n fabric: () => Item;\n}\n\nexport class FixedPool<Item extends Disposable> {\n private readonly pool: LimitedPool<Item>;\n\n public constructor({ size, fabric }: Options<Item>) {\n this.pool = new LimitedPool({ min: size, max: size, size: size, fabric: fabric });\n this.exec = this.pool.exec.bind(this.pool);\n this.dispose = this.pool.dispose.bind(this.pool);\n }\n\n /** Прокси на {@link LimitedPool.exec} */\n public exec: LimitedPool<Item>[\"exec\"];\n\n /** Прокси на {@link LimitedPool.dispose} */\n public dispose: LimitedPool<Item>[\"dispose\"];\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAOO,MAAMC,SAAS,CAA0B;EAGrCC,WAAWA,CAAC;IAAEC,IAAI;IAAEC;EAAsB,CAAC,EAAE;IAAA,KAFnCC,IAAI;IAQrB;IAAA,KACOC,IAAI;IAEX;IAAA,KACOC,OAAO;IATV,IAAI,CAACF,IAAI,GAAG,IAAIG,wBAAW,CAAC;MAAEC,GAAG,EAAEN,IAAI;MAAEO,GAAG,EAAEP,IAAI;MAAEA,IAAI,EAAEA,IAAI;MAAEC,MAAM,EAAEA;IAAO,CAAC,CAAC;IACjF,IAAI,CAACE,IAAI,GAAG,IAAI,CAACD,IAAI,CAACC,IAAI,CAACK,IAAI,CAAC,IAAI,CAACN,IAAI,CAAC;IAC1C,IAAI,CAACE,OAAO,GAAG,IAAI,CAACF,IAAI,CAACE,OAAO,CAACI,IAAI,CAAC,IAAI,CAACN,IAAI,CAAC;EACpD;AAOJ;AAACO,OAAA,CAAAX,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LimitedPool = void 0;
7
+ var _IntRangeUtils = require("../../IntRangeUtils");
8
+ var _AsyncPool = require("./AsyncPool");
9
+ /**
10
+ * Создаёт пул ограниченной ёмкости, удерживая кол-во элементов в установленных лимитах.
11
+ *
12
+ * @param options.min нижняя граница ёмкости;
13
+ * @param options.max верхняя граница ёмкости;
14
+ * @param options.size начальная ёмкость;
15
+ * @param options.fabric фабрика элементов; вызывается ровно `size` раз при создании.
16
+ *
17
+ * @throws если `size < min` или `size > max`.
18
+ */
19
+ class LimitedPool {
20
+ constructor(options) {
21
+ this.size = void 0;
22
+ this.min = void 0;
23
+ this.max = void 0;
24
+ this.pool = void 0;
25
+ /** Прокси на {@link AsyncPool.exec} */
26
+ this.exec = void 0;
27
+ /** Прокси на {@link AsyncPool.dispose} */
28
+ this.dispose = void 0;
29
+ const {
30
+ size,
31
+ min,
32
+ max,
33
+ fabric
34
+ } = this.validateOptions(options);
35
+ this.size = size;
36
+ this.min = min;
37
+ this.max = max;
38
+ this.pool = new _AsyncPool.AsyncPool();
39
+ this.exec = this.pool.exec.bind(this.pool);
40
+ this.dispose = this.pool.dispose.bind(this.pool);
41
+ this.init(this.pool, size, fabric);
42
+ }
43
+ /**
44
+ * Добавляет элемент в пул, если текущая ёмкость ниже `max`.
45
+ */
46
+ add(item) {
47
+ if (this.size < this.max) {
48
+ this.pool.add(item);
49
+ this.size++;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Уменьшает ёмкость пула на один элемент, если текущая ёмкость выше `min`.
55
+ *
56
+ * @returns `true`, если ёмкость была уменьшена; `false`, если пул уже на минимуме.
57
+ */
58
+ evict() {
59
+ const aboveTheLimit = this.size > this.min;
60
+ if (aboveTheLimit && this.pool.evict()) {
61
+ this.size--;
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+ validateOptions(options) {
67
+ if ((0, _IntRangeUtils.inRange)(options.size, options.min, options.max)) {
68
+ return options;
69
+ } else {
70
+ throw new Error("LimitedPool: size must be between min and max");
71
+ }
72
+ }
73
+ init(pool, size, fabric) {
74
+ const initial = Array.from({
75
+ length: size
76
+ }, fabric);
77
+ initial.forEach(i => pool.add(i));
78
+ }
79
+ }
80
+ exports.LimitedPool = LimitedPool;
81
+ //# sourceMappingURL=LimitedPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LimitedPool.js","names":["_IntRangeUtils","require","_AsyncPool","LimitedPool","constructor","options","size","min","max","pool","exec","dispose","fabric","validateOptions","AsyncPool","bind","init","add","item","evict","aboveTheLimit","inRange","Error","initial","Array","from","length","forEach","i","exports"],"sources":["../../../../../Common/async/pool/LimitedPool.ts"],"sourcesContent":["import { inRange } from \"../../IntRangeUtils\";\n\nimport type { Disposable } from \"./AsyncPool\";\nimport { AsyncPool } from \"./AsyncPool\";\n\ninterface Options<Item> {\n min: number;\n max: number;\n size: number;\n fabric: () => Item;\n}\n\n/**\n * Создаёт пул ограниченной ёмкости, удерживая кол-во элементов в установленных лимитах.\n *\n * @param options.min нижняя граница ёмкости;\n * @param options.max верхняя граница ёмкости;\n * @param options.size начальная ёмкость;\n * @param options.fabric фабрика элементов; вызывается ровно `size` раз при создании.\n *\n * @throws если `size < min` или `size > max`.\n */\nexport class LimitedPool<Item extends Disposable> {\n private size: number;\n private readonly min: number;\n private readonly max: number;\n private readonly pool: AsyncPool<Item>;\n\n public constructor(options: Options<Item>) {\n const { size, min, max, fabric } = this.validateOptions(options);\n this.size = size;\n this.min = min;\n this.max = max;\n this.pool = new AsyncPool();\n this.exec = this.pool.exec.bind(this.pool);\n this.dispose = this.pool.dispose.bind(this.pool);\n this.init(this.pool, size, fabric);\n }\n\n /** Прокси на {@link AsyncPool.exec} */\n public exec: AsyncPool<Item>[\"exec\"];\n\n /** Прокси на {@link AsyncPool.dispose} */\n public dispose: AsyncPool<Item>[\"dispose\"];\n\n /**\n * Добавляет элемент в пул, если текущая ёмкость ниже `max`.\n */\n public add(item: Item): void {\n if (this.size < this.max) {\n this.pool.add(item);\n this.size++;\n }\n }\n\n /**\n * Уменьшает ёмкость пула на один элемент, если текущая ёмкость выше `min`.\n *\n * @returns `true`, если ёмкость была уменьшена; `false`, если пул уже на минимуме.\n */\n public evict(): boolean {\n const aboveTheLimit = this.size > this.min;\n if (aboveTheLimit && this.pool.evict()) {\n this.size--;\n return true;\n }\n return false;\n }\n\n private validateOptions(options: Options<Item>): Options<Item> {\n if (inRange(options.size, options.min, options.max)) {\n return options;\n } else {\n throw new Error(\"LimitedPool: size must be between min and max\");\n }\n }\n\n private init(pool: AsyncPool<Item>, size: number, fabric: () => Item): void {\n const initial = Array.from({ length: size }, fabric);\n initial.forEach(i => pool.add(i));\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,WAAW,CAA0B;EAMvCC,WAAWA,CAACC,OAAsB,EAAE;IAAA,KALnCC,IAAI;IAAA,KACKC,GAAG;IAAA,KACHC,GAAG;IAAA,KACHC,IAAI;IAarB;IAAA,KACOC,IAAI;IAEX;IAAA,KACOC,OAAO;IAdV,MAAM;MAAEL,IAAI;MAAEC,GAAG;MAAEC,GAAG;MAAEI;IAAO,CAAC,GAAG,IAAI,CAACC,eAAe,CAACR,OAAO,CAAC;IAChE,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,IAAI,GAAG,IAAIK,oBAAS,CAAC,CAAC;IAC3B,IAAI,CAACJ,IAAI,GAAG,IAAI,CAACD,IAAI,CAACC,IAAI,CAACK,IAAI,CAAC,IAAI,CAACN,IAAI,CAAC;IAC1C,IAAI,CAACE,OAAO,GAAG,IAAI,CAACF,IAAI,CAAC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, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.State = exports.Registry = void 0;
7
+ let State = exports.State = /*#__PURE__*/function (State) {
8
+ State["Idle"] = "Idle";
9
+ State["Busy"] = "Busy";
10
+ State["Doomed"] = "Doomed";
11
+ return State;
12
+ }({});
13
+ class Registry {
14
+ constructor() {
15
+ this.states = new Map();
16
+ }
17
+ stateOf(item) {
18
+ this.ensureHas(item);
19
+ // @ts-expect-error item точно есть
20
+ return this.states.get(item);
21
+ }
22
+ add(item) {
23
+ if (this.states.has(item)) {
24
+ throw new Error("Registry: duplicate");
25
+ }
26
+ this.states.set(item, State.Idle);
27
+ }
28
+ capture(item) {
29
+ this.expect(item, State.Idle);
30
+ this.states.set(item, State.Busy);
31
+ return item;
32
+ }
33
+ free(item) {
34
+ this.expect(item, State.Busy);
35
+ this.states.set(item, State.Idle);
36
+ }
37
+ doom(item) {
38
+ this.ensureHas(item);
39
+ this.states.set(item, State.Doomed);
40
+ }
41
+ remove(item) {
42
+ if (!this.states.delete(item)) {
43
+ throw new Error("Registry: remove unexpected");
44
+ }
45
+ }
46
+ findBusy() {
47
+ var _this$states$entries$;
48
+ return (_this$states$entries$ = this.states.entries().find(([_, state]) => state === State.Busy)) === null || _this$states$entries$ === void 0 ? void 0 : _this$states$entries$[0];
49
+ }
50
+ doomAll() {
51
+ const idles = [];
52
+ for (const [item, state] of this.states.entries()) {
53
+ this.states.set(item, State.Doomed);
54
+ if (state === State.Idle) {
55
+ idles.push(item);
56
+ }
57
+ }
58
+ return idles;
59
+ }
60
+ expect(item, state) {
61
+ this.ensureHas(item);
62
+ if (this.states.get(item) !== state) {
63
+ throw new Error("Registry: unexpected state");
64
+ }
65
+ }
66
+ ensureHas(item) {
67
+ if (!this.states.has(item)) {
68
+ throw new Error("Registry: unexpected item");
69
+ }
70
+ }
71
+ }
72
+ exports.Registry = Registry;
73
+ //# sourceMappingURL=Registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.js","names":["State","exports","Registry","constructor","states","Map","stateOf","item","ensureHas","get","add","has","Error","set","Idle","capture","expect","Busy","free","doom","Doomed","remove","delete","findBusy","_this$states$entries$","entries","find","_","state","doomAll","idles","push"],"sources":["../../../../../Common/async/pool/Registry.ts"],"sourcesContent":["export const enum State {\n Idle = \"Idle\",\n Busy = \"Busy\",\n Doomed = \"Doomed\",\n}\n\nexport class Registry<Item> {\n private readonly states = new Map<Item, State>();\n\n public stateOf(item: Item): State {\n this.ensureHas(item);\n // @ts-expect-error item точно есть\n return this.states.get(item);\n }\n\n public add(item: Item): void {\n if (this.states.has(item)) {\n throw new Error(\"Registry: duplicate\");\n }\n this.states.set(item, State.Idle);\n }\n\n public capture(item: Item): Item {\n this.expect(item, State.Idle);\n this.states.set(item, State.Busy);\n return item;\n }\n\n public free(item: Item): void {\n this.expect(item, State.Busy);\n this.states.set(item, State.Idle);\n }\n\n public doom(item: Item): void {\n this.ensureHas(item);\n this.states.set(item, State.Doomed);\n }\n\n public remove(item: Item): void {\n if (!this.states.delete(item)) {\n throw new Error(\"Registry: remove unexpected\");\n }\n }\n\n public findBusy(): Item | undefined {\n return this.states.entries().find(([_, state]) => state === State.Busy)?.[0];\n }\n\n public doomAll(): Item[] {\n const idles: Item[] = [];\n for (const [item, state] of this.states.entries()) {\n this.states.set(item, State.Doomed);\n if (state === State.Idle) {\n idles.push(item);\n }\n }\n return idles;\n }\n\n private expect(item: Item, state: State): void {\n this.ensureHas(item);\n if (this.states.get(item) !== state) {\n throw new Error(\"Registry: unexpected state\");\n }\n }\n\n private ensureHas(item: Item): void {\n if (!this.states.has(item)) {\n throw new Error(\"Registry: unexpected item\");\n }\n }\n}\n"],"mappings":";;;;;;IAAkBA,KAAK,GAAAC,OAAA,CAAAD,KAAA,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA;AAMhB,MAAME,QAAQ,CAAO;EAAAC,YAAA;IAAA,KACPC,MAAM,GAAG,IAAIC,GAAG,CA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,OAAO,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,CAAC,EAAEC,KAAK,CAAC,KAAKA,KAAK,KAAK5B,KAAK,CAACiB,IAAI,CAAC,cAAAO,qBAAA,uBAAhEA,qBAAA,CAAmE,CAAC,CAAC;EAChF;EAEOK,OAAOA,CAAA,EAAW;IACrB,MAAMC,KAAa,GAAG,EAAE;IACxB,KAAK,MAAM,CAACvB,IAAI,EAAEqB,KAAK,CAAC,IAAI,IAAI,CAACxB,MAAM,CAACqB,OAAO,CAAC,CAAC,EAAE;MAC/C,IAAI,CAACrB,MAAM,CAACS,GAAG,CAACN,IAAI,EAAEP,KAAK,CAACoB,MAAM,CAAC;MACnC,IAAIQ,KAAK,KAAK5B,KAAK,CAACc,IAAI,EAAE;QACtBgB,KAAK,CAACC,IAAI,CAACxB,IAAI,CAAC;MACpB;IACJ;IACA,OAAOuB,KAAK;EAChB;EAEQd,MAAMA,CAACT,IAAU,EAAEqB,KAAY,EAAQ;IAC3C,IAAI,CAACpB,SAAS,CAACD,IAAI,CAAC;IACpB,IAAI,IAAI,CAACH,MAAM,CAACK,GAAG,CAACF,IAAI,CAAC,KAAKqB,KAAK,EAAE;MACjC,MAAM,IAAIhB,KAAK,CAAC,4BAA4B,CAAC;IACjD;EACJ;EAEQJ,SAASA,CAACD,IAAU,EAAQ;IAChC,IAAI,CAAC,IAAI,CAACH,MAAM,CAACO,GAAG,CAACJ,IAAI,CAAC,EAAE;MACxB,MAAM,IAAIK,KAAK,CAAC,2BAA2B,CAAC;IAChD;EACJ;AACJ;AAACX,OAAA,CAAAC,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "FixedPool", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _FixedPool.FixedPool;
10
+ }
11
+ });
12
+ var _FixedPool = require("./FixedPool");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_FixedPool","require"],"sources":["../../../../../Common/async/pool/index.ts"],"sourcesContent":["export type { Disposable } from \"./AsyncPool\";\nexport { FixedPool } from \"./FixedPool\";\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LinkedList = void 0;
7
+ class LinkedListClass {
8
+ constructor() {
9
+ this.length = 0;
10
+ this.first = null;
11
+ this.last = null;
12
+ }
13
+ empty() {
14
+ return this.length === 0;
15
+ }
16
+ notEmpty() {
17
+ return this.length > 0;
18
+ }
19
+ clear() {
20
+ this.length = 0;
21
+ this.first = null;
22
+ this.last = null;
23
+ }
24
+ forEach(fn) {
25
+ let current = this.first;
26
+ while (current !== null) {
27
+ fn(current.item);
28
+ current = current.next;
29
+ }
30
+ }
31
+ push(item) {
32
+ this.length++;
33
+ const last = this.last;
34
+ const element = {
35
+ prev: last,
36
+ next: null,
37
+ item: item
38
+ };
39
+ if (last) {
40
+ last.next = element;
41
+ } else {
42
+ this.first = element;
43
+ }
44
+ this.last = element;
45
+ }
46
+ shift() {
47
+ if (!this.first) {
48
+ return undefined;
49
+ }
50
+ this.length--;
51
+ const element = this.first;
52
+ if (this.last === element) {
53
+ this.first = null;
54
+ this.last = null;
55
+ } else {
56
+ this.first = element.next;
57
+ // @ts-expect-error last !== element => element.next !== null
58
+ this.first.prev = null;
59
+ }
60
+ return element.item;
61
+ }
62
+ }
63
+ const LinkedList = exports.LinkedList = LinkedListClass;
64
+ //# sourceMappingURL=LinkedList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkedList.js","names":["LinkedListClass","constructor","length","first","last","empty","notEmpty","clear","forEach","fn","current","item","next","push","element","prev","shift","undefined","LinkedList","exports"],"sources":["../../../../Common/ds/LinkedList.ts"],"sourcesContent":["interface Element<Item> {\n item: Item;\n prev: Element<Item> | null;\n next: Element<Item> | null;\n}\n\nclass LinkedListClass<Item> {\n private length = 0;\n private first: Element<Item> | null = null;\n private last: Element<Item> | null = null;\n\n public empty(): this is EmptyLinkedList<Item> {\n return this.length === 0;\n }\n\n public notEmpty(): this is NonEmptyLinkedList<Item> {\n return this.length > 0;\n }\n\n public clear(): void {\n this.length = 0;\n this.first = null;\n this.last = null;\n }\n\n public forEach(fn: (item: Item) => void): void {\n let current = this.first;\n while (current !== null) {\n fn(current.item);\n current = current.next;\n }\n }\n\n public push(item: Item): void {\n this.length++;\n const last = this.last;\n const element = { prev: last, next: null, item: item };\n if (last) {\n last.next = element;\n } else {\n this.first = element;\n }\n this.last = element;\n }\n\n public shift(this: NonEmptyLinkedList<Item>): Item;\n public shift(this: EmptyLinkedList<Item>): undefined;\n public shift(): Item | undefined;\n public shift(): Item | undefined {\n if (!this.first) {\n return undefined;\n }\n this.length--;\n const element = this.first;\n if (this.last === element) {\n this.first = null;\n this.last = null;\n } else {\n this.first = element.next;\n // @ts-expect-error last !== element => element.next !== null\n this.first.prev = null;\n }\n return element.item;\n }\n}\n\ndeclare const State: unique symbol;\ntype EmptyLinkedList<Item> = LinkedListClass<Item> & { readonly [State]: \"empty\" };\ntype NonEmptyLinkedList<Item> = LinkedListClass<Item> & { readonly [State]: \"nonempty\" };\n\nexport type LinkedList<Item> = EmptyLinkedList<Item> | NonEmptyLinkedList<Item>;\n\ninterface LinkedListCtor {\n new <Item>(): LinkedList<Item>;\n}\n\nexport const LinkedList = LinkedListClass as LinkedListCtor;\n"],"mappings":";;;;;;AAMA,MAAMA,eAAe,CAAO;EAAAC,YAAA;IAAA,KAChBC,MAAM,GAAG,CAAC;IAAA,KACVC,KAAK,GAAyB,IAAI;IAAA,KAClCC,IAAI,GAAyB,IAAI;EAAA;EAElCC,KAAKA,CAAA,EAAkC;IAC1C,OAAO,IAAI,CAACH,MAAM,KAAK,CAAC;EAC5B;EAEO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,OAAO,CAACH,IAAI;EACvB;AACJ;AAYO,MAAMO,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGlB,eAAiC","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ThreadPool = void 0;
7
+ var _nodeWorker_threads = require("node:worker_threads");
8
+ var _pool = require("../async/pool");
9
+ var _TypingUtils = require("../TypingUtils");
10
+ class ThreadPool {
11
+ constructor(ops) {
12
+ this.pool = void 0;
13
+ this.pool = new _pool.FixedPool({
14
+ size: ops.size,
15
+ fabric: this.fabric.bind(this, ops)
16
+ });
17
+ }
18
+
19
+ /**
20
+ * @throws при вызове после {@link ThreadPool.dispose}
21
+ */
22
+ exec(message) {
23
+ if (!this.pool) {
24
+ return Promise.reject(new Error("ThreadPool: exec on disposed pool"));
25
+ }
26
+ return this.pool.exec(({
27
+ worker
28
+ }) => this.call(worker, message));
29
+ }
30
+ async dispose() {
31
+ var _this$pool;
32
+ await ((_this$pool = this.pool) === null || _this$pool === void 0 ? void 0 : _this$pool.dispose());
33
+ // даем GC собрать
34
+ this.pool = undefined;
35
+ }
36
+ fabric(ops) {
37
+ const worker = new _nodeWorker_threads.Worker(ops.workerPath, ops.workerOptions);
38
+ return {
39
+ worker: worker,
40
+ dispose: () => worker.terminate().then(_TypingUtils.noop)
41
+ };
42
+ }
43
+ call(worker, message) {
44
+ const {
45
+ promise,
46
+ resolve,
47
+ reject
48
+ } = Promise.withResolvers();
49
+ const cleanup = () => {
50
+ worker.off("message", onMessage);
51
+ worker.off("error", onError);
52
+ worker.off("exit", onExit);
53
+ };
54
+ const onMessage = out => {
55
+ cleanup();
56
+ resolve(out);
57
+ };
58
+ const onError = err => {
59
+ cleanup();
60
+ reject(err);
61
+ };
62
+ const onExit = code => {
63
+ cleanup();
64
+ reject(new Error(`Worker exited with code ${code}`));
65
+ };
66
+ worker.once("message", onMessage);
67
+ worker.once("error", onError);
68
+ worker.once("exit", onExit);
69
+ worker.postMessage(message);
70
+ return promise;
71
+ }
72
+ }
73
+ exports.ThreadPool = ThreadPool;
74
+ //# sourceMappingURL=ThreadPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThreadPool.js","names":["_nodeWorker_threads","require","_pool","_TypingUtils","ThreadPool","constructor","ops","pool","FixedPool","size","fabric","bind","exec","message","Promise","reject","Error","worker","call","dispose","_this$pool","undefined","Worker","workerPath","workerOptions","terminate","then","noop","promise","resolve","withResolvers","cleanup","off","onMessage","onError","onExit","out","err","code","once","postMessage","exports"],"sources":["../../../../Common/multithread/ThreadPool.ts"],"sourcesContent":["import { Worker, WorkerOptions } from \"node:worker_threads\";\n\nimport type { Disposable } from \"../async/pool\";\nimport { FixedPool } from \"../async/pool\";\nimport { noop } from \"../TypingUtils\";\n\ninterface Options {\n workerPath: string;\n workerOptions?: WorkerOptions;\n size: number;\n}\n\ninterface Thread extends Disposable {\n worker: Worker;\n}\n\nexport class ThreadPool {\n private pool?: FixedPool<Thread>;\n\n public constructor(ops: Options) {\n this.pool = new FixedPool({ size: ops.size, fabric: this.fabric.bind(this, ops) });\n }\n\n /**\n * @throws при вызове после {@link ThreadPool.dispose}\n */\n public exec<In, Out>(message: In): Promise<Out> {\n if (!this.pool) {\n return Promise.reject(new Error(\"ThreadPool: exec on disposed pool\"));\n }\n return this.pool.exec(({ worker }) => this.call<In, Out>(worker, message));\n }\n\n public async dispose(): Promise<void> {\n await this.pool?.dispose();\n // даем GC собрать\n this.pool = undefined;\n }\n\n private fabric(ops: Options): Thread {\n const worker = new Worker(ops.workerPath, ops.workerOptions);\n return { worker: worker, dispose: () => worker.terminate().then(noop) };\n }\n\n private call<In, Out>(worker: Worker, message: In): Promise<Out> {\n const { promise, resolve, reject } = Promise.withResolvers<Out>();\n const cleanup = (): void => {\n worker.off(\"message\", onMessage);\n worker.off(\"error\", onError);\n worker.off(\"exit\", onExit);\n };\n const onMessage = (out: Out): void => {\n cleanup();\n resolve(out);\n };\n const onError = (err: Error): void => {\n cleanup();\n reject(err);\n };\n const onExit = (code: number): void => {\n cleanup();\n reject(new Error(`Worker exited with code ${code}`));\n };\n worker.once(\"message\", onMessage);\n worker.once(\"error\", onError);\n worker.once(\"exit\", onExit);\n worker.postMessage(message);\n return promise;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAYO,MAAMG,UAAU,CAAC;EAGbC,WAAWA,CAACC,GAAY,EAAE;IAAA,KAFzBC,IAAI;IAGR,IAAI,CAACA,IAAI,GAAG,IAAIC,eAAS,CAAC;MAAEC,IAAI,EAAEH,GAAG,CAACG,IAAI;MAAEC,MAAM,EAAE,IAAI,CAACA,MAAM,CAACC,IAAI,CAAC,IAAI,EAAEL,GAAG;IAAE,CAAC,CAAC;EACtF;;EAEA;AACJ;AACA;EACWM,IAAIA,CAAUC,OAAW,EAAgB;IAC5C,IAAI,CAAC,IAAI,CAACN,IAAI,EAAE;MACZ,OAAOO,OAAO,CAACC,MAAM,CAAC,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACzE;IACA,OAAO,IAAI,CAACT,IAAI,CAACK,IAAI,CAAC,CAAC;MAAEK;IAAO,CAAC,KAAK,IAAI,CAACC,IAAI,CAAUD,MAAM,EAAEJ,OAAO,CAAC,CAAC;EAC9E;EAEA,MAAaM,OAAOA,CAAA,EAAkB;IAAA,IAAAC,UAAA;IAClC,QAAAA,UAAA,GAAM,IAAI,CAACb,IAAI,cAAAa,UAAA,uBAATA,UAAA,CAAWD,OAAO,CAAC,CAAC;IAC1B;IACA,IAAI,CAACZ,IAAI,GAAGc,SAAS;EACzB;EAEQX,MAAMA,CAACJ,GAAY,EAAU;IACjC,MAAMW,MAAM,GAAG,IAAIK,0BAAM,CAAChB,GAAG,CAACiB,UAAU,EAAEjB,GAAG,CAACkB,aAAa,CAAC;IAC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
26
26
  async function generateForm(formSourcesPath, farmDirectory, generator, parentLogger = (0, _StaticLogger.getLogger)(), generationOptions, fileWriter = new DefaultFileWriter()) {
27
- const logger = parentLogger.withPrefix(`GENERATE:${(0, _FormPathUtils.extractGfvFromFormPath)(formSourcesPath)}`);
27
+ const gfv = (0, _FormPathUtils.extractGfvFromFormPath)(formSourcesPath);
28
+ const logger = parentLogger.withPrefix(`GENERATE:${gfv}`);
28
29
  const action = (0, _ILogger.buildActionBegin)(logger, "Generation");
29
30
  const generatedContent = await generator.readSourcesAndProcessSugar(formSourcesPath, farmDirectory, generationOptions);
30
31
  logger.log("Writing files");
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateForm.js","names":["path","_interopRequireWildcard","require","_fsExtra","_FsUtils","_ILogger","_StaticLogger","_FormPathUtils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DefaultFileWriter","writeBatch","fileBatch","filePath","keys","content","undefined","ensureDir","parse","dir","writeFileAsync","generateForm","formSourcesPath","farmDirectory","generator","parentLogger","getLogger","generationOptions","fileWriter","logger","withPrefix","extractGfvFromFormPath","action","buildActionBegin","generatedContent","readSourcesAndProcessSugar","log","writeGeneratedFiles","join","complete","candyFormContent","outputDirectory"],"sources":["../../../../../src/BuildTasks/Form/GenerateForm.ts"],"sourcesContent":["import * as path from \"path\";\n\nimport { ensureDir } from \"fs-extra\";\n\nimport { writeFileAsync } from \"../../Commons/FsUtils\";\nimport { buildActionBegin, ILogger } from \"../../Commons/Logging/ILogger\";\nimport { getLogger } from \"../../Commons/Logging/StaticLogger\";\nimport { FormResources, FormSource, SugarContent } from \"../FormSource\";\nimport { extractGfvFromFormPath } from \"../../../../Common/FormPathUtils\";\nimport { ExtractorResult } from \"../../../../Common/TextExtractor/TextExtractorTypes\";\n\nexport interface GeneratedForm {\n [relativeFileName: string]: Buffer | string;\n}\n\nexport interface LocalizationDictionaryContent {\n [relativeFileName: string]: string;\n}\n\nexport interface LocalizationEntryPoint {\n getLocalizedSugar(sugarFiles: SugarContent, resources: FormResources): Promise<SugarContent>;\n getDictionary(sugarFiles: SugarContent, resources: FormResources): Promise<LocalizationDictionaryContent>;\n}\n\nexport interface FormGenerator {\n readSources(formSourcesPath: string, farmDirectory: string): Promise<FormSource>;\n getAllDependencies(formSourcesPath: string, farmDirectory: string): Promise<string[]>;\n getAllDependenciesHash(formSourcesPath: string, farmDirectory: string): Promise<string>;\n supportsDependenciesExtraction(): Promise<boolean>;\n readSourcesAndProcessSugar(\n formSourcesPath: string,\n farmDirectory: string,\n generationOptions?: GenerationOptions\n ): Promise<GeneratedForm>;\n getLocalizedSugar(sugarFiles: SugarContent, resources: FormResources): Promise<SugarContent>;\n getDictionary(sugarFiles: SugarContent, resources: FormResources): Promise<LocalizationDictionaryContent>;\n getSugarTexts(formSourcesPath: string, farmDirectory: string): Promise<ExtractorResult>;\n}\n\nexport interface GenerationOptions {\n skipCodeReformatting: boolean;\n resourcesHash: string;\n}\n\nexport interface IFileWriter {\n writeBatch(fileBatch: { [absoluteFileName: string]: string }): Promise<void>;\n}\n\nclass DefaultFileWriter implements IFileWriter {\n public async writeBatch(fileBatch: { [absoluteFileName: string]: string }): Promise<void> {\n for (const filePath of Object.keys(fileBatch)) {\n const content = fileBatch[filePath];\n if (content != undefined && content !== \"\") {\n await ensureDir(path.parse(filePath).dir);\n await writeFileAsync(filePath, content);\n }\n }\n }\n}\n\nexport async function generateForm(\n formSourcesPath: string,\n farmDirectory: string,\n generator: FormGenerator,\n parentLogger: ILogger = getLogger(),\n generationOptions?: GenerationOptions,\n fileWriter: IFileWriter = new DefaultFileWriter()\n): Promise<void> {\n const logger = parentLogger.withPrefix(`GENERATE:${extractGfvFromFormPath(formSourcesPath)}`);\n const action = buildActionBegin(logger, \"Generation\");\n const generatedContent = await generator.readSourcesAndProcessSugar(\n formSourcesPath,\n farmDirectory,\n generationOptions\n );\n logger.log(\"Writing files\");\n await writeGeneratedFiles(generatedContent, path.join(formSourcesPath, \"form\"), fileWriter);\n action.complete();\n}\n\nasync function writeGeneratedFiles(\n candyFormContent: GeneratedForm,\n outputDirectory: string,\n fileWriter: IFileWriter\n): Promise<void> {\n const fileBatch = {};\n for (const filePath of Object.keys(candyFormContent)) {\n const content = candyFormContent[filePath];\n if (content != undefined && content !== \"\") {\n // @ts-ignore\n fileBatch[path.join(outputDirectory, filePath)] = content;\n }\n }\n await fileWriter.writeBatch(fileBatch);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,cAAA,GAAAL,OAAA;AAA0E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,S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,0BAA0B,CAC/Db,eAAe,EACfC,aAAa,EACbI,iBACJ,CAAC;EACDE,MAAM,CAACO,GAAG,CAAC,eAAe,CAAC;EAC3B,MAAMC,mBAAmB,CAACH,gBAAgB,EAAEpD,IAAI,CAACwD,IAAI,CAAChB,eAAe,EAAE,MAAM,CAAC,EAAEM,UAAU,CAAC;EAC3FI,MAAM,CAACO,QAAQ,CAAC,CAAC;AACrB;AAEA,eAAeF,mBAAmBA,CAC9BG,gBAA+B,EAC/BC,eAAuB,EACvBb,UAAuB,EACV;EACb,MAAMhB,SAAS,GAAG,CAAC,CAAC;EACpB,KAAK,MAAMC,QAAQ,IAAIX,MAAM,CAACY,IAAI,CAAC0B,gBAAgB,CAAC,EAAE;IAClD,MAAMzB,OAAO,GAAGyB,gBAAgB,CAAC3B,QAAQ,CAAC;IAC1C,IAAIE,OAAO,IAAIC,SAAS,IAAID,OAAO,KAAK,EAAE,EAAE;MACxC;MACAH,SAAS,CAAC9B,IAAI,CAACwD,IAAI,CAACG,eAAe,EAAE5B,QAAQ,CAAC,CAAC,GAAGE,OAAO;IAC7D;EACJ;EACA,MAAMa,UAAU,CAACjB,UAAU,CAACC,SAAS,CAAC;AAC1C","ignoreList":[]}
1
+ {"version":3,"file":"GenerateForm.js","names":["path","_interopRequireWildcard","require","_fsExtra","_FsUtils","_ILogger","_StaticLogger","_FormPathUtils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DefaultFileWriter","writeBatch","fileBatch","filePath","keys","content","undefined","ensureDir","parse","dir","writeFileAsync","generateForm","formSourcesPath","farmDirectory","generator","parentLogger","getLogger","generationOptions","fileWriter","gfv","extractGfvFromFormPath","logger","withPrefix","action","buildActionBegin","generatedContent","readSourcesAndProcessSugar","log","writeGeneratedFiles","join","complete","candyFormContent","outputDirectory"],"sources":["../../../../../src/BuildTasks/Form/GenerateForm.ts"],"sourcesContent":["import * as path from \"path\";\n\nimport { ensureDir } from \"fs-extra\";\n\nimport { writeFileAsync } from \"../../Commons/FsUtils\";\nimport { buildActionBegin, ILogger } from \"../../Commons/Logging/ILogger\";\nimport { getLogger } from \"../../Commons/Logging/StaticLogger\";\nimport { FormResources, FormSource, SugarContent } from \"../FormSource\";\nimport { extractGfvFromFormPath } from \"../../../../Common/FormPathUtils\";\nimport { ExtractorResult } from \"../../../../Common/TextExtractor/TextExtractorTypes\";\n\nexport interface GeneratedForm {\n [relativeFileName: string]: Buffer | string;\n}\n\nexport interface LocalizationDictionaryContent {\n [relativeFileName: string]: string;\n}\n\nexport interface FormGenerator {\n readSources(formSourcesPath: string, farmDirectory: string): Promise<FormSource>;\n getAllDependencies(formSourcesPath: string, farmDirectory: string): Promise<string[]>;\n getAllDependenciesHash(formSourcesPath: string, farmDirectory: string): Promise<string>;\n readSourcesAndProcessSugar(\n formSourcesPath: string,\n farmDirectory: string,\n generationOptions?: GenerationOptions\n ): Promise<GeneratedForm>;\n getLocalizedSugar(sugarFiles: SugarContent, resources: FormResources): Promise<SugarContent>;\n getDictionary(sugarFiles: SugarContent, resources: FormResources): Promise<LocalizationDictionaryContent>;\n getSugarTexts(formSourcesPath: string, farmDirectory: string): Promise<ExtractorResult>;\n dispose?(): Promise<void>;\n}\n\nexport interface GenerationOptions {\n resourcesHash: string;\n}\n\nexport interface IFileWriter {\n writeBatch(fileBatch: { [absoluteFileName: string]: string }): Promise<void>;\n}\n\nclass DefaultFileWriter implements IFileWriter {\n public async writeBatch(fileBatch: { [absoluteFileName: string]: string }): Promise<void> {\n for (const filePath of Object.keys(fileBatch)) {\n const content = fileBatch[filePath];\n if (content != undefined && content !== \"\") {\n await ensureDir(path.parse(filePath).dir);\n await writeFileAsync(filePath, content);\n }\n }\n }\n}\n\nexport async function generateForm(\n formSourcesPath: string,\n farmDirectory: string,\n generator: FormGenerator,\n parentLogger: ILogger = getLogger(),\n generationOptions?: GenerationOptions,\n fileWriter: IFileWriter = new DefaultFileWriter()\n): Promise<void> {\n const gfv = extractGfvFromFormPath(formSourcesPath);\n const logger = parentLogger.withPrefix(`GENERATE:${gfv}`);\n const action = buildActionBegin(logger, \"Generation\");\n const generatedContent = await generator.readSourcesAndProcessSugar(\n formSourcesPath,\n farmDirectory,\n generationOptions\n );\n logger.log(\"Writing files\");\n await writeGeneratedFiles(generatedContent, path.join(formSourcesPath, \"form\"), fileWriter);\n action.complete();\n}\n\nasync function writeGeneratedFiles(\n candyFormContent: GeneratedForm,\n outputDirectory: string,\n fileWriter: IFileWriter\n): Promise<void> {\n const fileBatch = {};\n for (const filePath of Object.keys(candyFormContent)) {\n const content = candyFormContent[filePath];\n if (content != undefined && content !== \"\") {\n // @ts-ignore\n fileBatch[path.join(outputDirectory, filePath)] = content;\n }\n }\n await fileWriter.writeBatch(fileBatch);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,cAAA,GAAAL,OAAA;AAA0E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,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IAAAC,qCAAsB,EAACR,eAAe,CAAC;EACnD,MAAMS,MAAM,GAAGN,YAAY,CAACO,UAAU,CAAC,YAAYH,GAAG,EAAE,CAAC;EACzD,MAAMI,MAAM,GAAG,IAAAC,yBAAgB,EAACH,MAAM,EAAE,YAAY,CAAC;EACrD,MAAMI,gBAAgB,GAAG,MAAMX,SAAS,CAACY,0BAA0B,CAC/Dd,eAAe,EACfC,aAAa,EACbI,iBACJ,CAAC;EACDI,MAAM,CAACM,GAAG,CAAC,eAAe,CAAC;EAC3B,MAAMC,mBAAmB,CAACH,gBAAgB,EAAErD,IAAI,CAACyD,IAAI,CAACjB,eAAe,EAAE,MAAM,CAAC,EAAEM,UAAU,CAAC;EAC3FK,MAAM,CAACO,QAAQ,CAAC,CAAC;AACrB;AAEA,eAAeF,mBAAmBA,CAC9BG,gBAA+B,EAC/BC,eAAuB,EACvBd,UAAuB,EACV;EACb,MAAMhB,SAAS,GAAG,CAAC,CAAC;EACpB,KAAK,MAAMC,QAAQ,IAAIX,MAAM,CAACY,IAAI,CAAC2B,gBAAgB,CAAC,EAAE;IAClD,MAAM1B,OAAO,GAAG0B,gBAAgB,CAAC5B,QAAQ,CAAC;IAC1C,IAAIE,OAAO,IAAIC,SAAS,IAAID,OAAO,KAAK,EAAE,EAAE;MACxC;MACAH,SAAS,CAAC9B,IAAI,CAACyD,IAAI,CAACG,eAAe,EAAE7B,QAAQ,CAAC,CAAC,GAAGE,OAAO;IAC7D;EACJ;EACA,MAAMa,UAAU,CAACjB,UAAU,CAACC,SAAS,CAAC;AAC1C","ignoreList":[]}
@@ -23,9 +23,6 @@ class NullFormGenerator {
23
23
  readSourcesAndProcessSugar() {
24
24
  throw new Error("GenerationNotSupported");
25
25
  }
26
- supportsDependenciesExtraction() {
27
- throw new Error("GenerationNotSupported");
28
- }
29
26
  getSugarTexts() {
30
27
  throw new Error("GenerationNotSupported");
31
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NullFormGenerator.js","names":["NullFormGenerator","getAllDependencies","Error","getAllDependenciesHash","getDictionary","getLocalizedSugar","readSources","readSourcesAndProcessSugar","supportsDependenciesExtraction","getSugarTexts","exports"],"sources":["../../../../../src/BuildTasks/Form/NullFormGenerator.ts"],"sourcesContent":["import { FormSource, SugarContent } from \"../FormSource\";\nimport { ExtractorResult } from \"../../../../Common/TextExtractor/TextExtractorTypes\";\n\nimport { FormGenerator, GeneratedForm, LocalizationDictionaryContent } from \"./GenerateForm\";\n\nexport class NullFormGenerator implements FormGenerator {\n public getAllDependencies(): Promise<string[]> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getAllDependenciesHash(): Promise<string> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getDictionary(): Promise<LocalizationDictionaryContent> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getLocalizedSugar(): Promise<SugarContent> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public readSources(): Promise<FormSource> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public readSourcesAndProcessSugar(): Promise<GeneratedForm> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public supportsDependenciesExtraction(): Promise<boolean> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getSugarTexts(): Promise<ExtractorResult> {\n throw new Error(\"GenerationNotSupported\");\n }\n}\n"],"mappings":";;;;;;AAKO,MAAMA,iBAAiB,CAA0B;EAC7CC,kBAAkBA,CAAA,EAAsB;IAC3C,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOC,sBAAsBA,CAAA,EAAoB;IAC7C,MAAM,IAAID,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOE,aAAaA,CAAA,EAA2C;IAC3D,MAAM,IAAIF,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOG,iBAAiBA,CAAA,EAA0B;IAC9C,MAAM,IAAIH,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOI,WAAWA,CAAA,EAAwB;IACtC,MAAM,IAAIJ,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOK,0BAA0BA,CAAA,EAA2B;IACxD,MAAM,IAAIL,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOM,8BAA8BA,CAAA,EAAqB;IACtD,MAAM,IAAIN,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOO,aAAaA,CAAA,EAA6B;IAC7C,MAAM,IAAIP,KAAK,CAAC,wBAAwB,CAAC;EAC7C;AACJ;AAACQ,OAAA,CAAAV,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"NullFormGenerator.js","names":["NullFormGenerator","getAllDependencies","Error","getAllDependenciesHash","getDictionary","getLocalizedSugar","readSources","readSourcesAndProcessSugar","getSugarTexts","exports"],"sources":["../../../../../src/BuildTasks/Form/NullFormGenerator.ts"],"sourcesContent":["import { FormSource, SugarContent } from \"../FormSource\";\nimport { ExtractorResult } from \"../../../../Common/TextExtractor/TextExtractorTypes\";\n\nimport { FormGenerator, GeneratedForm, LocalizationDictionaryContent } from \"./GenerateForm\";\n\nexport class NullFormGenerator implements FormGenerator {\n public getAllDependencies(): Promise<string[]> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getAllDependenciesHash(): Promise<string> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getDictionary(): Promise<LocalizationDictionaryContent> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getLocalizedSugar(): Promise<SugarContent> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public readSources(): Promise<FormSource> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public readSourcesAndProcessSugar(): Promise<GeneratedForm> {\n throw new Error(\"GenerationNotSupported\");\n }\n\n public getSugarTexts(): Promise<ExtractorResult> {\n throw new Error(\"GenerationNotSupported\");\n }\n}\n"],"mappings":";;;;;;AAKO,MAAMA,iBAAiB,CAA0B;EAC7CC,kBAAkBA,CAAA,EAAsB;IAC3C,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOC,sBAAsBA,CAAA,EAAoB;IAC7C,MAAM,IAAID,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOE,aAAaA,CAAA,EAA2C;IAC3D,MAAM,IAAIF,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOG,iBAAiBA,CAAA,EAA0B;IAC9C,MAAM,IAAIH,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOI,WAAWA,CAAA,EAAwB;IACtC,MAAM,IAAIJ,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOK,0BAA0BA,CAAA,EAA2B;IACxD,MAAM,IAAIL,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEOM,aAAaA,CAAA,EAA6B;IAC7C,MAAM,IAAIN,KAAK,CAAC,wBAAwB,CAAC;EAC7C;AACJ;AAACO,OAAA,CAAAT,iBAAA,GAAAA,iBAAA","ignoreList":[]}