@opra/common 1.17.5 → 1.17.6
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/browser/index.cjs +1 -1
- package/browser/index.mjs +1 -1
- package/cjs/document/data-type/complex-type-base.js +8 -6
- package/esm/document/data-type/complex-type-base.js +7 -5
- package/package.json +2 -2
- package/types/document/data-type/complex-type-base.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +3 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComplexTypeBase = exports.FIELD_PATH_PATTERN = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const object_hash_1 = tslib_1.__importDefault(require("object-hash"));
|
|
6
6
|
const ts_gems_1 = require("ts-gems");
|
|
7
7
|
const valgen_1 = require("valgen");
|
|
8
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
@@ -210,7 +210,9 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
210
210
|
: options?.projection,
|
|
211
211
|
currentPath: '',
|
|
212
212
|
};
|
|
213
|
-
|
|
213
|
+
let schema = this._generateSchema(codec, context);
|
|
214
|
+
if (context.generateSchemaHook)
|
|
215
|
+
schema = context.generateSchemaHook(schema, this, context.currentPath);
|
|
214
216
|
let additionalFields;
|
|
215
217
|
if (this.additionalFields instanceof data_type_js_1.DataType) {
|
|
216
218
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -241,7 +243,7 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
241
243
|
return fn;
|
|
242
244
|
}
|
|
243
245
|
_generateSchema(codec, context) {
|
|
244
|
-
context.
|
|
246
|
+
context.fieldCache = context.fieldCache || new Map();
|
|
245
247
|
context.level = context.level || 0;
|
|
246
248
|
context.forwardCallbacks = context.forwardCallbacks || new Set();
|
|
247
249
|
const schema = {};
|
|
@@ -279,13 +281,13 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
279
281
|
const subProjection = typeof projection === 'object'
|
|
280
282
|
? projection[fieldName]?.projection || '*'
|
|
281
283
|
: projection;
|
|
282
|
-
let cacheItem = context.
|
|
284
|
+
let cacheItem = context.fieldCache.get(field);
|
|
283
285
|
const cacheKey = typeof subProjection === 'string'
|
|
284
286
|
? subProjection
|
|
285
|
-
: (0,
|
|
287
|
+
: (0, object_hash_1.default)(subProjection || {});
|
|
286
288
|
if (!cacheItem) {
|
|
287
289
|
cacheItem = {};
|
|
288
|
-
context.
|
|
290
|
+
context.fieldCache.set(field, cacheItem);
|
|
289
291
|
}
|
|
290
292
|
let fn = cacheItem[cacheKey];
|
|
291
293
|
/** If in progress (circular) */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import hashObject from 'hash
|
|
1
|
+
import hashObject from 'object-hash';
|
|
2
2
|
import { asMutable } from 'ts-gems';
|
|
3
3
|
import { validator, vg } from 'valgen';
|
|
4
4
|
import { parseFieldsProjection, ResponsiveMap, } from '../../helpers/index.js';
|
|
@@ -206,7 +206,9 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
206
206
|
: options?.projection,
|
|
207
207
|
currentPath: '',
|
|
208
208
|
};
|
|
209
|
-
|
|
209
|
+
let schema = this._generateSchema(codec, context);
|
|
210
|
+
if (context.generateSchemaHook)
|
|
211
|
+
schema = context.generateSchemaHook(schema, this, context.currentPath);
|
|
210
212
|
let additionalFields;
|
|
211
213
|
if (this.additionalFields instanceof DataType) {
|
|
212
214
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -237,7 +239,7 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
237
239
|
return fn;
|
|
238
240
|
}
|
|
239
241
|
_generateSchema(codec, context) {
|
|
240
|
-
context.
|
|
242
|
+
context.fieldCache = context.fieldCache || new Map();
|
|
241
243
|
context.level = context.level || 0;
|
|
242
244
|
context.forwardCallbacks = context.forwardCallbacks || new Set();
|
|
243
245
|
const schema = {};
|
|
@@ -275,13 +277,13 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
275
277
|
const subProjection = typeof projection === 'object'
|
|
276
278
|
? projection[fieldName]?.projection || '*'
|
|
277
279
|
: projection;
|
|
278
|
-
let cacheItem = context.
|
|
280
|
+
let cacheItem = context.fieldCache.get(field);
|
|
279
281
|
const cacheKey = typeof subProjection === 'string'
|
|
280
282
|
? subProjection
|
|
281
283
|
: hashObject(subProjection || {});
|
|
282
284
|
if (!cacheItem) {
|
|
283
285
|
cacheItem = {};
|
|
284
|
-
context.
|
|
286
|
+
context.fieldCache.set(field, cacheItem);
|
|
285
287
|
}
|
|
286
288
|
let fn = cacheItem[cacheKey];
|
|
287
289
|
/** If in progress (circular) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.6",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@browsery/type-is": "^1.6.18-r8",
|
|
13
13
|
"@jsopen/objects": "^1.6.2",
|
|
14
14
|
"fast-tokenizer": "^1.7.0",
|
|
15
|
-
"hash
|
|
15
|
+
"object-hash": "^3.0.0",
|
|
16
16
|
"putil-promisify": "^1.10.1",
|
|
17
17
|
"putil-varhelpers": "^1.6.5",
|
|
18
18
|
"reflect-metadata": "^0.2.2",
|
|
@@ -80,7 +80,7 @@ type GenerateCodecContext = StrictOmit<DataType.GenerateCodecOptions, 'projectio
|
|
|
80
80
|
currentPath: string;
|
|
81
81
|
projection?: FieldsProjection | '*';
|
|
82
82
|
level?: number;
|
|
83
|
-
|
|
83
|
+
fieldCache?: Map<ApiField, Record<string, Validator | null>>;
|
|
84
84
|
forwardCallbacks?: Set<Function>;
|
|
85
85
|
};
|
|
86
86
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type StrictOmit, type Type } from 'ts-gems';
|
|
2
|
-
import type { ValidationOptions, Validator } from 'valgen';
|
|
2
|
+
import type { IsObject, ValidationOptions, Validator } from 'valgen';
|
|
3
3
|
import { FieldsProjection } from '../../helpers/index.js';
|
|
4
4
|
import type { DataTypeBase } from '../../schema/data-type/data-type.interface.js';
|
|
5
5
|
import { OpraSchema } from '../../schema/index.js';
|
|
@@ -7,6 +7,7 @@ import type { ApiDocument } from '../api-document.js';
|
|
|
7
7
|
import { DocumentElement } from '../common/document-element.js';
|
|
8
8
|
import { DocumentInitContext } from '../common/document-init-context.js';
|
|
9
9
|
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
10
|
+
import type { ComplexType } from './complex-type.js';
|
|
10
11
|
/**
|
|
11
12
|
* @namespace DataType
|
|
12
13
|
*/
|
|
@@ -30,6 +31,7 @@ export declare namespace DataType {
|
|
|
30
31
|
ignoreReadonlyFields?: boolean;
|
|
31
32
|
ignoreWriteonlyFields?: boolean;
|
|
32
33
|
allowPatchOperators?: boolean;
|
|
34
|
+
generateSchemaHook?: (schema: IsObject.Schema, dataType: ComplexType, path: string) => IsObject.Schema;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
interface DataTypeStatic {
|