@infomaximum/widget-sdk 7.0.0-16 → 7.0.0-17
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 +8 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +42 -8
- package/dist/index.js +42 -8
- package/package.json +1 -1
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-17](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-16...v7.0.0-17) (2026-04-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* добавлена вспомогательная функция mapValues (для внутреннего использования) ([9f4beb0](https://github.com/Infomaximum/widget-sdk/commit/9f4beb0c86e81fdc763046425d749168b7deaae4))
|
|
11
|
+
* добавлено кеширование результатов вызова фабрик схем ([e116856](https://github.com/Infomaximum/widget-sdk/commit/e1168567088fd02e6557abfc6d5c179194eb430c))
|
|
12
|
+
|
|
5
13
|
## [7.0.0-16](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-15...v7.0.0-16) (2026-04-08)
|
|
6
14
|
|
|
7
15
|
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,16 @@ declare class VersionedSchemaFactory {
|
|
|
63
63
|
private static findClosestVersion;
|
|
64
64
|
/** Добавляет метаданные к схеме (curried) */
|
|
65
65
|
private static annotateSchema;
|
|
66
|
+
/**
|
|
67
|
+
* Оборачивает фабрику схемы, добавляя кеширование результата.
|
|
68
|
+
*
|
|
69
|
+
* Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
|
|
70
|
+
* поэтому достаточно закешировать единственный результат.
|
|
71
|
+
*
|
|
72
|
+
* Вызовы с дополнительными аргументами (restArgs) не кешируются,
|
|
73
|
+
* так как результат может зависеть от их значений.
|
|
74
|
+
*/
|
|
75
|
+
private static withCache;
|
|
66
76
|
/** Построить версионированную схему */
|
|
67
77
|
static build<THistory extends Record<string, ISchemaFactory>, TLatestVersion extends keyof THistory>({ history, latestVersion, meta, }: IVersionedSchemaBuildParams<THistory, TLatestVersion>): TVersionedSchema<THistory, TLatestVersion>;
|
|
68
78
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -231,6 +231,12 @@ var clamp = function (value, min, max) {
|
|
|
231
231
|
}
|
|
232
232
|
return value;
|
|
233
233
|
};
|
|
234
|
+
function mapValues(obj, fn) {
|
|
235
|
+
return Object.fromEntries(Object.entries(obj).map(function (_a) {
|
|
236
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
237
|
+
return [key, fn(value, key)];
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
234
240
|
/** Добавляет свойства к функции */
|
|
235
241
|
function assignPropsToFn(fn, props) {
|
|
236
242
|
return Object.assign(fn, props);
|
|
@@ -275,6 +281,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
|
|
|
275
281
|
});
|
|
276
282
|
};
|
|
277
283
|
};
|
|
284
|
+
/**
|
|
285
|
+
* Оборачивает фабрику схемы, добавляя кеширование результата.
|
|
286
|
+
*
|
|
287
|
+
* Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
|
|
288
|
+
* поэтому достаточно закешировать единственный результат.
|
|
289
|
+
*
|
|
290
|
+
* Вызовы с дополнительными аргументами (restArgs) не кешируются,
|
|
291
|
+
* так как результат может зависеть от их значений.
|
|
292
|
+
*/
|
|
293
|
+
VersionedSchemaFactory.withCache = function (schemaFactory) {
|
|
294
|
+
var cached;
|
|
295
|
+
return (function (z) {
|
|
296
|
+
var restArgs = [];
|
|
297
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
298
|
+
restArgs[_i - 1] = arguments[_i];
|
|
299
|
+
}
|
|
300
|
+
if (restArgs.length > 0) {
|
|
301
|
+
return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
|
|
302
|
+
}
|
|
303
|
+
if (cached === undefined) {
|
|
304
|
+
cached = schemaFactory(z);
|
|
305
|
+
}
|
|
306
|
+
return cached;
|
|
307
|
+
});
|
|
308
|
+
};
|
|
278
309
|
/** Построить версионированную схему */
|
|
279
310
|
VersionedSchemaFactory.build = function (_a) {
|
|
280
311
|
var _this = this;
|
|
@@ -283,20 +314,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
|
|
|
283
314
|
if (!latestFactory) {
|
|
284
315
|
throw new Error("Не найдено записи в 'history' по 'latestVersion'");
|
|
285
316
|
}
|
|
286
|
-
var
|
|
287
|
-
var
|
|
317
|
+
var annotate = this.annotateSchema(meta);
|
|
318
|
+
var preparedHistory = mapValues(history, function (factory) {
|
|
319
|
+
return _this.withCache(annotate(factory));
|
|
320
|
+
});
|
|
321
|
+
var schema = assignPropsToFn(preparedHistory[latestVersion], {
|
|
288
322
|
forVersion: function (targetVersion) {
|
|
289
323
|
if (targetVersion === null || targetVersion === undefined) {
|
|
290
|
-
return
|
|
324
|
+
return preparedHistory[latestVersion];
|
|
291
325
|
}
|
|
292
|
-
if (targetVersion in
|
|
293
|
-
return
|
|
326
|
+
if (targetVersion in preparedHistory) {
|
|
327
|
+
return preparedHistory[targetVersion];
|
|
294
328
|
}
|
|
295
|
-
var closestVersion = _this.findClosestVersion(Object.keys(
|
|
296
|
-
if (closestVersion === undefined || !(closestVersion in
|
|
329
|
+
var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
|
|
330
|
+
if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
|
|
297
331
|
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, "'"));
|
|
298
332
|
}
|
|
299
|
-
return
|
|
333
|
+
return preparedHistory[closestVersion];
|
|
300
334
|
},
|
|
301
335
|
});
|
|
302
336
|
return schema;
|
package/dist/index.js
CHANGED
|
@@ -232,6 +232,12 @@ var clamp = function (value, min, max) {
|
|
|
232
232
|
}
|
|
233
233
|
return value;
|
|
234
234
|
};
|
|
235
|
+
function mapValues(obj, fn) {
|
|
236
|
+
return Object.fromEntries(Object.entries(obj).map(function (_a) {
|
|
237
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
238
|
+
return [key, fn(value, key)];
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
235
241
|
/** Добавляет свойства к функции */
|
|
236
242
|
function assignPropsToFn(fn, props) {
|
|
237
243
|
return Object.assign(fn, props);
|
|
@@ -276,6 +282,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
|
|
|
276
282
|
});
|
|
277
283
|
};
|
|
278
284
|
};
|
|
285
|
+
/**
|
|
286
|
+
* Оборачивает фабрику схемы, добавляя кеширование результата.
|
|
287
|
+
*
|
|
288
|
+
* Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
|
|
289
|
+
* поэтому достаточно закешировать единственный результат.
|
|
290
|
+
*
|
|
291
|
+
* Вызовы с дополнительными аргументами (restArgs) не кешируются,
|
|
292
|
+
* так как результат может зависеть от их значений.
|
|
293
|
+
*/
|
|
294
|
+
VersionedSchemaFactory.withCache = function (schemaFactory) {
|
|
295
|
+
var cached;
|
|
296
|
+
return (function (z) {
|
|
297
|
+
var restArgs = [];
|
|
298
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
299
|
+
restArgs[_i - 1] = arguments[_i];
|
|
300
|
+
}
|
|
301
|
+
if (restArgs.length > 0) {
|
|
302
|
+
return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
|
|
303
|
+
}
|
|
304
|
+
if (cached === undefined) {
|
|
305
|
+
cached = schemaFactory(z);
|
|
306
|
+
}
|
|
307
|
+
return cached;
|
|
308
|
+
});
|
|
309
|
+
};
|
|
279
310
|
/** Построить версионированную схему */
|
|
280
311
|
VersionedSchemaFactory.build = function (_a) {
|
|
281
312
|
var _this = this;
|
|
@@ -284,20 +315,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
|
|
|
284
315
|
if (!latestFactory) {
|
|
285
316
|
throw new Error("Не найдено записи в 'history' по 'latestVersion'");
|
|
286
317
|
}
|
|
287
|
-
var
|
|
288
|
-
var
|
|
318
|
+
var annotate = this.annotateSchema(meta);
|
|
319
|
+
var preparedHistory = mapValues(history, function (factory) {
|
|
320
|
+
return _this.withCache(annotate(factory));
|
|
321
|
+
});
|
|
322
|
+
var schema = assignPropsToFn(preparedHistory[latestVersion], {
|
|
289
323
|
forVersion: function (targetVersion) {
|
|
290
324
|
if (targetVersion === null || targetVersion === undefined) {
|
|
291
|
-
return
|
|
325
|
+
return preparedHistory[latestVersion];
|
|
292
326
|
}
|
|
293
|
-
if (targetVersion in
|
|
294
|
-
return
|
|
327
|
+
if (targetVersion in preparedHistory) {
|
|
328
|
+
return preparedHistory[targetVersion];
|
|
295
329
|
}
|
|
296
|
-
var closestVersion = _this.findClosestVersion(Object.keys(
|
|
297
|
-
if (closestVersion === undefined || !(closestVersion in
|
|
330
|
+
var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
|
|
331
|
+
if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
|
|
298
332
|
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, "'"));
|
|
299
333
|
}
|
|
300
|
-
return
|
|
334
|
+
return preparedHistory[closestVersion];
|
|
301
335
|
},
|
|
302
336
|
});
|
|
303
337
|
return schema;
|