@opra/common 1.17.6 → 1.17.7
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 +4 -4
- package/browser/index.mjs +4 -4
- package/cjs/document/data-type/complex-type-base.js +21 -12
- package/cjs/document/data-type/omit-type.js +0 -6
- package/cjs/document/data-type/partial-type.js +0 -6
- package/esm/document/data-type/complex-type-base.js +21 -12
- package/esm/document/data-type/omit-type.js +0 -6
- package/esm/document/data-type/partial-type.js +0 -6
- package/package.json +1 -1
- package/types/document/data-type/data-type.d.ts +3 -3
- package/types/document/data-type/omit-type.d.ts +9 -2
- package/types/document/data-type/partial-type.d.ts +7 -1
|
@@ -210,9 +210,7 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
210
210
|
: options?.projection,
|
|
211
211
|
currentPath: '',
|
|
212
212
|
};
|
|
213
|
-
|
|
214
|
-
if (context.generateSchemaHook)
|
|
215
|
-
schema = context.generateSchemaHook(schema, this, context.currentPath);
|
|
213
|
+
const schema = this._generateSchema(codec, context);
|
|
216
214
|
let additionalFields;
|
|
217
215
|
if (this.additionalFields instanceof data_type_js_1.DataType) {
|
|
218
216
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -303,17 +301,28 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
303
301
|
});
|
|
304
302
|
}
|
|
305
303
|
else if (!fn) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
304
|
+
const defaultGenerator = () => {
|
|
305
|
+
cacheItem[cacheKey] = null;
|
|
306
|
+
const xfn = this._generateFieldCodec(codec, field, {
|
|
307
|
+
...context,
|
|
308
|
+
partial: context.partial === 'deep' ? context.partial : undefined,
|
|
309
|
+
projection: subProjection,
|
|
310
|
+
currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
|
|
311
|
+
});
|
|
312
|
+
cacheItem[cacheKey] = xfn;
|
|
313
|
+
return xfn;
|
|
314
|
+
};
|
|
315
|
+
if (context.fieldHook)
|
|
316
|
+
fn = context.fieldHook(field, context.currentPath, defaultGenerator);
|
|
317
|
+
else
|
|
318
|
+
fn = defaultGenerator();
|
|
314
319
|
}
|
|
315
320
|
schema[fieldName] =
|
|
316
|
-
context.partial || !field.required
|
|
321
|
+
context.partial || !(field.required || fn.id === 'required')
|
|
322
|
+
? valgen_1.vg.optional(fn)
|
|
323
|
+
: fn.id === 'required'
|
|
324
|
+
? fn
|
|
325
|
+
: valgen_1.vg.required(fn);
|
|
317
326
|
}
|
|
318
327
|
if (context.allowPatchOperators) {
|
|
319
328
|
schema._$pull = valgen_1.vg.optional(valgen_1.vg.isAny());
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OmitType = OmitType;
|
|
4
4
|
const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
|
|
5
|
-
/**
|
|
6
|
-
* Create a new MappedType that omits given fields from base type
|
|
7
|
-
* @param baseType
|
|
8
|
-
* @param keys
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
5
|
/**
|
|
12
6
|
*
|
|
13
7
|
*/
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PartialType = PartialType;
|
|
4
4
|
const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
|
|
5
|
-
/**
|
|
6
|
-
* Create a new MappedType that marks given or all fields as optional
|
|
7
|
-
* @param baseType
|
|
8
|
-
* @param keys
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
5
|
/**
|
|
12
6
|
*
|
|
13
7
|
*/
|
|
@@ -206,9 +206,7 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
206
206
|
: options?.projection,
|
|
207
207
|
currentPath: '',
|
|
208
208
|
};
|
|
209
|
-
|
|
210
|
-
if (context.generateSchemaHook)
|
|
211
|
-
schema = context.generateSchemaHook(schema, this, context.currentPath);
|
|
209
|
+
const schema = this._generateSchema(codec, context);
|
|
212
210
|
let additionalFields;
|
|
213
211
|
if (this.additionalFields instanceof DataType) {
|
|
214
212
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -299,17 +297,28 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
299
297
|
});
|
|
300
298
|
}
|
|
301
299
|
else if (!fn) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
300
|
+
const defaultGenerator = () => {
|
|
301
|
+
cacheItem[cacheKey] = null;
|
|
302
|
+
const xfn = this._generateFieldCodec(codec, field, {
|
|
303
|
+
...context,
|
|
304
|
+
partial: context.partial === 'deep' ? context.partial : undefined,
|
|
305
|
+
projection: subProjection,
|
|
306
|
+
currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
|
|
307
|
+
});
|
|
308
|
+
cacheItem[cacheKey] = xfn;
|
|
309
|
+
return xfn;
|
|
310
|
+
};
|
|
311
|
+
if (context.fieldHook)
|
|
312
|
+
fn = context.fieldHook(field, context.currentPath, defaultGenerator);
|
|
313
|
+
else
|
|
314
|
+
fn = defaultGenerator();
|
|
310
315
|
}
|
|
311
316
|
schema[fieldName] =
|
|
312
|
-
context.partial || !field.required
|
|
317
|
+
context.partial || !(field.required || fn.id === 'required')
|
|
318
|
+
? vg.optional(fn)
|
|
319
|
+
: fn.id === 'required'
|
|
320
|
+
? fn
|
|
321
|
+
: vg.required(fn);
|
|
313
322
|
}
|
|
314
323
|
if (context.allowPatchOperators) {
|
|
315
324
|
schema._$pull = vg.optional(vg.isAny());
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type StrictOmit, type Type } from 'ts-gems';
|
|
2
|
-
import type {
|
|
2
|
+
import type { 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,7 +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 {
|
|
10
|
+
import type { ApiField } from './api-field.js';
|
|
11
11
|
/**
|
|
12
12
|
* @namespace DataType
|
|
13
13
|
*/
|
|
@@ -31,7 +31,7 @@ export declare namespace DataType {
|
|
|
31
31
|
ignoreReadonlyFields?: boolean;
|
|
32
32
|
ignoreWriteonlyFields?: boolean;
|
|
33
33
|
allowPatchOperators?: boolean;
|
|
34
|
-
|
|
34
|
+
fieldHook?: (field: ApiField, currentPath: string, defaultGenerator: () => Validator) => Validator;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
interface DataTypeStatic {
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { Class, Type } from 'ts-gems';
|
|
2
2
|
import type { DataType } from './data-type.js';
|
|
3
|
-
export declare function OmitType(baseType: string | Type, keys: string[], options?: DataType.Options): Type;
|
|
4
3
|
/**
|
|
5
4
|
* Create a new MappedType that omits given fields from base type
|
|
6
5
|
* @param baseType
|
|
7
6
|
* @param keys
|
|
8
7
|
* @param options
|
|
9
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export declare function OmitType<Args extends any[], Instance, Static, K extends keyof Instance>(baseType: Class<Args, Instance, Static>, keys: readonly K[], options?: DataType.Options): Class<Args, Omit<Instance, K>> & Omit<Pick<Static, keyof typeof baseType>, 'prototype' | 'constructor'>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new MappedType that omits given fields from base type
|
|
12
|
+
* @param baseType
|
|
13
|
+
* @param keys
|
|
14
|
+
* @param options
|
|
15
|
+
*/
|
|
16
|
+
export declare function OmitType(baseType: string | Type, keys: string[], options?: DataType.Options): Type;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Class, PartialSome, Type } from 'ts-gems';
|
|
2
2
|
import type { DataType } from './data-type.js';
|
|
3
|
-
export declare function PartialType(baseType: string | Type, keys: string[], options?: DataType.Options): Type;
|
|
4
3
|
/**
|
|
5
4
|
* Create a new MappedType that marks given or all fields as optional
|
|
6
5
|
* @param baseType
|
|
@@ -20,3 +19,10 @@ export declare function PartialType<Args extends any[], Instance, Static, K exte
|
|
|
20
19
|
* @param options
|
|
21
20
|
*/
|
|
22
21
|
export declare function PartialType<Args extends any[], Instance, Static>(baseType: Class<Args, Instance, Static>, options?: DataType.Options): Class<Args, Partial<Instance>> & Omit<Pick<Static, keyof typeof baseType>, 'prototype' | 'constructor'>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new MappedType that marks given or all fields as optional
|
|
24
|
+
* @param baseType
|
|
25
|
+
* @param keys
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
export declare function PartialType(baseType: string | Type, keys: string[], options?: DataType.Options): Type;
|