@infomaximum/widget-sdk 7.0.0-2603.0 → 7.0.0-2603.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [7.0.0-2603.1](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-2603.0...v7.0.0-2603.1) (2026-04-15)
6
+
7
+
8
+ ### Features
9
+
10
+ * добавлена вспомогательная функция mapValues (для внутреннего использования) ([6673ff9](https://github.com/Infomaximum/widget-sdk/commit/6673ff97aece9e50a831a1b96540f03de7f0c354))
11
+ * добавлено кеширование результатов вызова фабрик схем ([23698e3](https://github.com/Infomaximum/widget-sdk/commit/23698e3c53924dc41efd2d56c96c0a234217f79b))
12
+
5
13
  ## [7.0.0-2603.0](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-14...v7.0.0-2603.0) (2026-04-06)
6
14
 
7
15
 
package/dist/index.d.ts CHANGED
@@ -134,6 +134,16 @@ declare class VersionedSchemaFactory {
134
134
  private static findClosestVersion;
135
135
  /** Добавляет метаданные к схеме (curried) */
136
136
  private static annotateSchema;
137
+ /**
138
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
139
+ *
140
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
141
+ * поэтому достаточно закешировать единственный результат.
142
+ *
143
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
144
+ * так как результат может зависеть от их значений.
145
+ */
146
+ private static withCache;
137
147
  /** Построить версионированную схему */
138
148
  static build<THistory extends Record<string, ISchemaFactory>, TLatestVersion extends keyof THistory>({ history, latestVersion, meta, }: IVersionedSchemaBuildParams<THistory, TLatestVersion>): TVersionedSchema<THistory, TLatestVersion>;
139
149
  }
package/dist/index.esm.js CHANGED
@@ -221,6 +221,12 @@ function memoize(fn) {
221
221
  return result;
222
222
  };
223
223
  }
224
+ function mapValues(obj, fn) {
225
+ return Object.fromEntries(Object.entries(obj).map(function (_a) {
226
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
227
+ return [key, fn(value, key)];
228
+ }));
229
+ }
224
230
  /** Добавляет свойства к функции */
225
231
  function assignPropsToFn(fn, props) {
226
232
  return Object.assign(fn, props);
@@ -265,6 +271,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
265
271
  });
266
272
  };
267
273
  };
274
+ /**
275
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
276
+ *
277
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
278
+ * поэтому достаточно закешировать единственный результат.
279
+ *
280
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
281
+ * так как результат может зависеть от их значений.
282
+ */
283
+ VersionedSchemaFactory.withCache = function (schemaFactory) {
284
+ var cached;
285
+ return (function (z) {
286
+ var restArgs = [];
287
+ for (var _i = 1; _i < arguments.length; _i++) {
288
+ restArgs[_i - 1] = arguments[_i];
289
+ }
290
+ if (restArgs.length > 0) {
291
+ return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
292
+ }
293
+ if (cached === undefined) {
294
+ cached = schemaFactory(z);
295
+ }
296
+ return cached;
297
+ });
298
+ };
268
299
  /** Построить версионированную схему */
269
300
  VersionedSchemaFactory.build = function (_a) {
270
301
  var _this = this;
@@ -273,20 +304,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
273
304
  if (!latestFactory) {
274
305
  throw new Error("Не найдено записи в 'history' по 'latestVersion'");
275
306
  }
276
- var map = this.annotateSchema(meta);
277
- var schema = assignPropsToFn(map(latestFactory), {
307
+ var annotate = this.annotateSchema(meta);
308
+ var preparedHistory = mapValues(history, function (factory) {
309
+ return _this.withCache(annotate(factory));
310
+ });
311
+ var schema = assignPropsToFn(preparedHistory[latestVersion], {
278
312
  forVersion: function (targetVersion) {
279
313
  if (targetVersion === null || targetVersion === undefined) {
280
- return map(latestFactory);
314
+ return preparedHistory[latestVersion];
281
315
  }
282
- if (targetVersion in history) {
283
- return map(history[targetVersion]);
316
+ if (targetVersion in preparedHistory) {
317
+ return preparedHistory[targetVersion];
284
318
  }
285
- var closestVersion = _this.findClosestVersion(Object.keys(history), targetVersion, VersionedSchemaFactory.compareVersions);
286
- if (closestVersion === undefined || !(closestVersion in history)) {
319
+ var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
320
+ if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
287
321
  throw new Error("\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E \u043F\u043E\u0434\u0445\u043E\u0434\u044F\u0449\u0435\u0439 \u0441\u0445\u0435\u043C\u044B \u0434\u043B\u044F \u0432\u0435\u0440\u0441\u0438\u0438 '".concat(targetVersion, "'"));
288
322
  }
289
- return map(history[closestVersion]);
323
+ return preparedHistory[closestVersion];
290
324
  },
291
325
  });
292
326
  return schema;
package/dist/index.js CHANGED
@@ -222,6 +222,12 @@ function memoize(fn) {
222
222
  return result;
223
223
  };
224
224
  }
225
+ function mapValues(obj, fn) {
226
+ return Object.fromEntries(Object.entries(obj).map(function (_a) {
227
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
228
+ return [key, fn(value, key)];
229
+ }));
230
+ }
225
231
  /** Добавляет свойства к функции */
226
232
  function assignPropsToFn(fn, props) {
227
233
  return Object.assign(fn, props);
@@ -266,6 +272,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
266
272
  });
267
273
  };
268
274
  };
275
+ /**
276
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
277
+ *
278
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
279
+ * поэтому достаточно закешировать единственный результат.
280
+ *
281
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
282
+ * так как результат может зависеть от их значений.
283
+ */
284
+ VersionedSchemaFactory.withCache = function (schemaFactory) {
285
+ var cached;
286
+ return (function (z) {
287
+ var restArgs = [];
288
+ for (var _i = 1; _i < arguments.length; _i++) {
289
+ restArgs[_i - 1] = arguments[_i];
290
+ }
291
+ if (restArgs.length > 0) {
292
+ return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
293
+ }
294
+ if (cached === undefined) {
295
+ cached = schemaFactory(z);
296
+ }
297
+ return cached;
298
+ });
299
+ };
269
300
  /** Построить версионированную схему */
270
301
  VersionedSchemaFactory.build = function (_a) {
271
302
  var _this = this;
@@ -274,20 +305,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
274
305
  if (!latestFactory) {
275
306
  throw new Error("Не найдено записи в 'history' по 'latestVersion'");
276
307
  }
277
- var map = this.annotateSchema(meta);
278
- var schema = assignPropsToFn(map(latestFactory), {
308
+ var annotate = this.annotateSchema(meta);
309
+ var preparedHistory = mapValues(history, function (factory) {
310
+ return _this.withCache(annotate(factory));
311
+ });
312
+ var schema = assignPropsToFn(preparedHistory[latestVersion], {
279
313
  forVersion: function (targetVersion) {
280
314
  if (targetVersion === null || targetVersion === undefined) {
281
- return map(latestFactory);
315
+ return preparedHistory[latestVersion];
282
316
  }
283
- if (targetVersion in history) {
284
- return map(history[targetVersion]);
317
+ if (targetVersion in preparedHistory) {
318
+ return preparedHistory[targetVersion];
285
319
  }
286
- var closestVersion = _this.findClosestVersion(Object.keys(history), targetVersion, VersionedSchemaFactory.compareVersions);
287
- if (closestVersion === undefined || !(closestVersion in history)) {
320
+ var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
321
+ if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
288
322
  throw new Error("\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E \u043F\u043E\u0434\u0445\u043E\u0434\u044F\u0449\u0435\u0439 \u0441\u0445\u0435\u043C\u044B \u0434\u043B\u044F \u0432\u0435\u0440\u0441\u0438\u0438 '".concat(targetVersion, "'"));
289
323
  }
290
- return map(history[closestVersion]);
324
+ return preparedHistory[closestVersion];
291
325
  },
292
326
  });
293
327
  return schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/widget-sdk",
3
- "version": "7.0.0-2603.0",
3
+ "version": "7.0.0-2603.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",