@opra/common 0.31.13 → 0.32.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.
- package/browser.js +27 -20
- package/cjs/document/data-type/complex-type-class.js +2 -1
- package/cjs/document/data-type/field-class.js +6 -3
- package/cjs/document/factory/type-document-factory.js +4 -1
- package/cjs/document/resource/crud-operation.js +2 -2
- package/cjs/document/type-document.js +13 -13
- package/esm/document/data-type/complex-type-class.js +2 -1
- package/esm/document/data-type/field-class.js +6 -3
- package/esm/document/factory/type-document-factory.js +4 -1
- package/esm/document/resource/crud-operation.js +2 -2
- package/esm/document/type-document.js +13 -13
- package/package.json +3 -3
- package/types/document/data-type/data-type.d.ts +3 -2
- package/types/document/factory/type-document-factory.d.ts +4 -3
- package/types/types.d.ts +4 -8
package/browser.js
CHANGED
|
@@ -2180,11 +2180,14 @@ var FieldClass = class {
|
|
|
2180
2180
|
return vg3.isUndefined();
|
|
2181
2181
|
if (options?.operation === "write" && this.readonly)
|
|
2182
2182
|
return vg3.isUndefined();
|
|
2183
|
-
let fn = this.type.generateCodec(codec, {
|
|
2183
|
+
let fn = this.type.generateCodec(codec, {
|
|
2184
|
+
...options,
|
|
2185
|
+
designType: this.designType,
|
|
2186
|
+
partial: options?.partial && (this.partialUpdate || !this.isArray)
|
|
2187
|
+
});
|
|
2184
2188
|
if (this.isArray)
|
|
2185
2189
|
fn = vg3.isArray(fn);
|
|
2186
|
-
|
|
2187
|
-
return !partial && this.required ? vg3.required(fn) : vg3.optional(fn);
|
|
2190
|
+
return !options?.partial && this.required ? vg3.required(fn) : vg3.optional(fn);
|
|
2188
2191
|
}
|
|
2189
2192
|
};
|
|
2190
2193
|
|
|
@@ -2381,7 +2384,8 @@ var ComplexTypeClass = class extends DataType {
|
|
|
2381
2384
|
ctor: this.ctor,
|
|
2382
2385
|
additionalFields,
|
|
2383
2386
|
name: this.name,
|
|
2384
|
-
caseInSensitive: !options?.caseSensitive
|
|
2387
|
+
caseInSensitive: !options?.caseSensitive,
|
|
2388
|
+
onFail: options?.onFail
|
|
2385
2389
|
});
|
|
2386
2390
|
}
|
|
2387
2391
|
generateCodecSchema(codec, options) {
|
|
@@ -2698,20 +2702,20 @@ var TypeDocument = class extends DocumentBase {
|
|
|
2698
2702
|
getComplexType(nameOrCtor, silent) {
|
|
2699
2703
|
if (nameOrCtor === Object)
|
|
2700
2704
|
nameOrCtor = "object";
|
|
2701
|
-
const t = this.getDataType(nameOrCtor);
|
|
2702
|
-
if (
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2705
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
2706
|
+
if (t) {
|
|
2707
|
+
if (t && t.kind === opra_schema_ns_exports.ComplexType.Kind)
|
|
2708
|
+
return t;
|
|
2709
|
+
throw new NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
|
|
2710
|
+
}
|
|
2707
2711
|
}
|
|
2708
2712
|
getSimpleType(nameOrCtor, silent) {
|
|
2709
|
-
const t = this.getDataType(nameOrCtor);
|
|
2710
|
-
if (
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2713
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
2714
|
+
if (t) {
|
|
2715
|
+
if (t && t.kind === opra_schema_ns_exports.SimpleType.Kind)
|
|
2716
|
+
return t;
|
|
2717
|
+
throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
2718
|
+
}
|
|
2715
2719
|
}
|
|
2716
2720
|
getEnumType(nameOrCtor, silent) {
|
|
2717
2721
|
const t = this.getDataType(nameOrCtor);
|
|
@@ -2732,7 +2736,7 @@ var TypeDocument = class extends DocumentBase {
|
|
|
2732
2736
|
for (const [ns, r] of this.references.entries()) {
|
|
2733
2737
|
if (ns.toLowerCase() === "opra")
|
|
2734
2738
|
continue;
|
|
2735
|
-
references[ns] = r.
|
|
2739
|
+
references[ns] = r.exportSchema(options);
|
|
2736
2740
|
i++;
|
|
2737
2741
|
}
|
|
2738
2742
|
if (i)
|
|
@@ -3453,7 +3457,10 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
|
|
|
3453
3457
|
}
|
|
3454
3458
|
async addReferences(references) {
|
|
3455
3459
|
const { document } = this;
|
|
3456
|
-
|
|
3460
|
+
let ns;
|
|
3461
|
+
let r;
|
|
3462
|
+
for ([ns, r] of Object.entries(references)) {
|
|
3463
|
+
r = await r;
|
|
3457
3464
|
if (typeof r === "string") {
|
|
3458
3465
|
document.references.set(ns, await this.initDocumentFromUrl(r));
|
|
3459
3466
|
} else if (r instanceof TypeDocument)
|
|
@@ -11178,8 +11185,8 @@ var CrudOperation = class extends Endpoint {
|
|
|
11178
11185
|
this.encodeReturning = vg7.isAny();
|
|
11179
11186
|
this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType || "any");
|
|
11180
11187
|
this.encodeReturning = this.returnType.generateCodec("encode", { operation: "read" });
|
|
11181
|
-
this.inputOverwriteFields = init.options
|
|
11182
|
-
this.outputOverwriteFields = init.options
|
|
11188
|
+
this.inputOverwriteFields = init.options?.inputOverwriteFields;
|
|
11189
|
+
this.outputOverwriteFields = init.options?.outputOverwriteFields;
|
|
11183
11190
|
}
|
|
11184
11191
|
exportSchema(options) {
|
|
11185
11192
|
const schema = super.exportSchema(options);
|
|
@@ -175,7 +175,8 @@ class ComplexTypeClass extends data_type_js_1.DataType {
|
|
|
175
175
|
ctor: this.ctor,
|
|
176
176
|
additionalFields,
|
|
177
177
|
name: this.name,
|
|
178
|
-
caseInSensitive: !options?.caseSensitive
|
|
178
|
+
caseInSensitive: !options?.caseSensitive,
|
|
179
|
+
onFail: options?.onFail
|
|
179
180
|
});
|
|
180
181
|
}
|
|
181
182
|
generateCodecSchema(codec, options) {
|
|
@@ -52,11 +52,14 @@ class FieldClass {
|
|
|
52
52
|
return vg.isUndefined();
|
|
53
53
|
if (options?.operation === 'write' && this.readonly)
|
|
54
54
|
return vg.isUndefined();
|
|
55
|
-
let fn = this.type.generateCodec(codec, {
|
|
55
|
+
let fn = this.type.generateCodec(codec, {
|
|
56
|
+
...options,
|
|
57
|
+
designType: this.designType,
|
|
58
|
+
partial: options?.partial && (this.partialUpdate || !this.isArray)
|
|
59
|
+
});
|
|
56
60
|
if (this.isArray)
|
|
57
61
|
fn = vg.isArray(fn);
|
|
58
|
-
|
|
59
|
-
return !partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
62
|
+
return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
exports.FieldClass = FieldClass;
|
|
@@ -108,7 +108,10 @@ class TypeDocumentFactory {
|
|
|
108
108
|
}
|
|
109
109
|
async addReferences(references) {
|
|
110
110
|
const { document } = this;
|
|
111
|
-
|
|
111
|
+
let ns;
|
|
112
|
+
let r;
|
|
113
|
+
for ([ns, r] of Object.entries(references)) {
|
|
114
|
+
r = await r;
|
|
112
115
|
if (typeof r === 'string') {
|
|
113
116
|
document.references.set(ns, await this.initDocumentFromUrl(r));
|
|
114
117
|
}
|
|
@@ -21,8 +21,8 @@ class CrudOperation extends endpoint_js_1.Endpoint {
|
|
|
21
21
|
this.returnType = init.returnType instanceof data_type_js_1.DataType
|
|
22
22
|
? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
|
|
23
23
|
this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
|
|
24
|
-
this.inputOverwriteFields = init.options
|
|
25
|
-
this.outputOverwriteFields = init.options
|
|
24
|
+
this.inputOverwriteFields = init.options?.inputOverwriteFields;
|
|
25
|
+
this.outputOverwriteFields = init.options?.outputOverwriteFields;
|
|
26
26
|
}
|
|
27
27
|
exportSchema(options) {
|
|
28
28
|
const schema = super.exportSchema(options);
|
|
@@ -148,20 +148,20 @@ class TypeDocument extends document_base_js_1.DocumentBase {
|
|
|
148
148
|
getComplexType(nameOrCtor, silent) {
|
|
149
149
|
if (nameOrCtor === Object)
|
|
150
150
|
nameOrCtor = 'object';
|
|
151
|
-
const t = this.getDataType(nameOrCtor);
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
152
|
+
if (t) {
|
|
153
|
+
if (t && t.kind === index_js_3.OpraSchema.ComplexType.Kind)
|
|
154
|
+
return t;
|
|
155
|
+
throw new index_js_1.NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
|
|
156
|
+
}
|
|
157
157
|
}
|
|
158
158
|
getSimpleType(nameOrCtor, silent) {
|
|
159
|
-
const t = this.getDataType(nameOrCtor);
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
160
|
+
if (t) {
|
|
161
|
+
if (t && t.kind === index_js_3.OpraSchema.SimpleType.Kind)
|
|
162
|
+
return t;
|
|
163
|
+
throw new index_js_1.NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
164
|
+
}
|
|
165
165
|
}
|
|
166
166
|
getEnumType(nameOrCtor, silent) {
|
|
167
167
|
const t = this.getDataType(nameOrCtor);
|
|
@@ -182,7 +182,7 @@ class TypeDocument extends document_base_js_1.DocumentBase {
|
|
|
182
182
|
for (const [ns, r] of this.references.entries()) {
|
|
183
183
|
if (ns.toLowerCase() === 'opra')
|
|
184
184
|
continue;
|
|
185
|
-
references[ns] = r.
|
|
185
|
+
references[ns] = r.exportSchema(options);
|
|
186
186
|
i++;
|
|
187
187
|
}
|
|
188
188
|
if (i)
|
|
@@ -171,7 +171,8 @@ export class ComplexTypeClass extends DataType {
|
|
|
171
171
|
ctor: this.ctor,
|
|
172
172
|
additionalFields,
|
|
173
173
|
name: this.name,
|
|
174
|
-
caseInSensitive: !options?.caseSensitive
|
|
174
|
+
caseInSensitive: !options?.caseSensitive,
|
|
175
|
+
onFail: options?.onFail
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
178
|
generateCodecSchema(codec, options) {
|
|
@@ -48,10 +48,13 @@ export class FieldClass {
|
|
|
48
48
|
return vg.isUndefined();
|
|
49
49
|
if (options?.operation === 'write' && this.readonly)
|
|
50
50
|
return vg.isUndefined();
|
|
51
|
-
let fn = this.type.generateCodec(codec, {
|
|
51
|
+
let fn = this.type.generateCodec(codec, {
|
|
52
|
+
...options,
|
|
53
|
+
designType: this.designType,
|
|
54
|
+
partial: options?.partial && (this.partialUpdate || !this.isArray)
|
|
55
|
+
});
|
|
52
56
|
if (this.isArray)
|
|
53
57
|
fn = vg.isArray(fn);
|
|
54
|
-
|
|
55
|
-
return !partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
58
|
+
return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -105,7 +105,10 @@ export class TypeDocumentFactory {
|
|
|
105
105
|
}
|
|
106
106
|
async addReferences(references) {
|
|
107
107
|
const { document } = this;
|
|
108
|
-
|
|
108
|
+
let ns;
|
|
109
|
+
let r;
|
|
110
|
+
for ([ns, r] of Object.entries(references)) {
|
|
111
|
+
r = await r;
|
|
109
112
|
if (typeof r === 'string') {
|
|
110
113
|
document.references.set(ns, await this.initDocumentFromUrl(r));
|
|
111
114
|
}
|
|
@@ -17,8 +17,8 @@ export class CrudOperation extends Endpoint {
|
|
|
17
17
|
this.returnType = init.returnType instanceof DataType
|
|
18
18
|
? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
|
|
19
19
|
this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
|
|
20
|
-
this.inputOverwriteFields = init.options
|
|
21
|
-
this.outputOverwriteFields = init.options
|
|
20
|
+
this.inputOverwriteFields = init.options?.inputOverwriteFields;
|
|
21
|
+
this.outputOverwriteFields = init.options?.outputOverwriteFields;
|
|
22
22
|
}
|
|
23
23
|
exportSchema(options) {
|
|
24
24
|
const schema = super.exportSchema(options);
|
|
@@ -145,20 +145,20 @@ export class TypeDocument extends DocumentBase {
|
|
|
145
145
|
getComplexType(nameOrCtor, silent) {
|
|
146
146
|
if (nameOrCtor === Object)
|
|
147
147
|
nameOrCtor = 'object';
|
|
148
|
-
const t = this.getDataType(nameOrCtor);
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
149
|
+
if (t) {
|
|
150
|
+
if (t && t.kind === OpraSchema.ComplexType.Kind)
|
|
151
|
+
return t;
|
|
152
|
+
throw new NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
|
|
153
|
+
}
|
|
154
154
|
}
|
|
155
155
|
getSimpleType(nameOrCtor, silent) {
|
|
156
|
-
const t = this.getDataType(nameOrCtor);
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
const t = this.getDataType(nameOrCtor, silent);
|
|
157
|
+
if (t) {
|
|
158
|
+
if (t && t.kind === OpraSchema.SimpleType.Kind)
|
|
159
|
+
return t;
|
|
160
|
+
throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
161
|
+
}
|
|
162
162
|
}
|
|
163
163
|
getEnumType(nameOrCtor, silent) {
|
|
164
164
|
const t = this.getDataType(nameOrCtor);
|
|
@@ -179,7 +179,7 @@ export class TypeDocument extends DocumentBase {
|
|
|
179
179
|
for (const [ns, r] of this.references.entries()) {
|
|
180
180
|
if (ns.toLowerCase() === 'opra')
|
|
181
181
|
continue;
|
|
182
|
-
references[ns] = r.
|
|
182
|
+
references[ns] = r.exportSchema(options);
|
|
183
183
|
i++;
|
|
184
184
|
}
|
|
185
185
|
if (i)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"putil-varhelpers": "^1.6.5",
|
|
47
47
|
"reflect-metadata": "^0.1.13",
|
|
48
48
|
"uid": "^2.0.1",
|
|
49
|
-
"valgen": "^4.
|
|
49
|
+
"valgen": "^4.3.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@browsery/fs": "^0.4.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/lodash.omit": "^4.5.9",
|
|
57
57
|
"@types/validator": "^13.11.7",
|
|
58
58
|
"path-browserify": "^1.0.1",
|
|
59
|
-
"ts-gems": "^2.
|
|
59
|
+
"ts-gems": "^2.7.1"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=16.0",
|
|
@@ -46,11 +46,12 @@ export declare namespace DataType {
|
|
|
46
46
|
};
|
|
47
47
|
interface GenerateCodecOptions {
|
|
48
48
|
caseSensitive?: boolean;
|
|
49
|
-
pick?: string[];
|
|
50
|
-
omit?: string[];
|
|
49
|
+
pick?: string[] | readonly string[];
|
|
50
|
+
omit?: string[] | readonly string[];
|
|
51
51
|
partial?: boolean;
|
|
52
52
|
operation?: 'read' | 'write';
|
|
53
53
|
overwriteFields?: Record<string, OverrideFieldsConfig>;
|
|
54
54
|
designType?: Type;
|
|
55
|
+
onFail?: vg.OnFailFunction;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -2,7 +2,6 @@ import { PartialSome, StrictOmit, Type } from 'ts-gems';
|
|
|
2
2
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { ThunkAsync } from '../../types.js';
|
|
5
|
-
import type { ApiDocument } from '../api-document.js';
|
|
6
5
|
import { ComplexType } from '../data-type/complex-type.js';
|
|
7
6
|
import { DataType } from '../data-type/data-type.js';
|
|
8
7
|
import { EnumType } from '../data-type/enum-type.js';
|
|
@@ -10,9 +9,10 @@ import { MappedType } from '../data-type/mapped-type.js';
|
|
|
10
9
|
import { MixinType } from '../data-type/mixin-type.js';
|
|
11
10
|
import { SimpleType } from '../data-type/simple-type.js';
|
|
12
11
|
import { TypeDocument } from '../type-document.js';
|
|
12
|
+
type ReferenceUnion = string | OpraSchema.TypeDocument | TypeDocument;
|
|
13
13
|
export declare namespace TypeDocumentFactory {
|
|
14
14
|
interface InitArguments extends PartialSome<StrictOmit<OpraSchema.TypeDocument, 'references' | 'types'>, 'version'> {
|
|
15
|
-
references?: Record<string,
|
|
15
|
+
references?: Record<string, ReferenceUnion | Promise<ReferenceUnion>>;
|
|
16
16
|
types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[] | Record<string, OpraSchema.DataType>;
|
|
17
17
|
noBuiltinTypes?: boolean;
|
|
18
18
|
}
|
|
@@ -49,8 +49,9 @@ export declare class TypeDocumentFactory {
|
|
|
49
49
|
protected initDocument(init: TypeDocumentFactory.InitArguments): Promise<TypeDocument>;
|
|
50
50
|
initDocumentFromUrl(url: string): Promise<TypeDocument>;
|
|
51
51
|
protected createBuiltinTypeDocument(): Promise<TypeDocument>;
|
|
52
|
-
protected addReferences(references: Record<string,
|
|
52
|
+
protected addReferences(references: Record<string, ReferenceUnion | Promise<ReferenceUnion>>): Promise<void>;
|
|
53
53
|
protected importDataType(thunk: ThunkAsync<string | Type | EnumType.EnumObject | EnumType.EnumArray | OpraSchema.DataType>): Promise<DataType>;
|
|
54
54
|
protected prepareDataTypeInitArguments(schema: TypeDocumentFactory.DataTypeInitializer | OpraSchema.DataType, ctor?: Type): Promise<TypeDocumentFactory.DataTypeInitializer | undefined>;
|
|
55
55
|
protected createDataTypeInstance(kind: OpraSchema.DataType.Kind, name?: string): DataType;
|
|
56
56
|
}
|
|
57
|
+
export {};
|
package/types/types.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type PartialInput<T> =
|
|
3
|
-
export type PartialOutput<T> =
|
|
4
|
-
type DeepNullablePartial<T> = T extends Builtin ? T : T extends Promise<infer U> ? Promise<DeepNullablePartial<U>> : T extends (infer U)[] ? DeepNullablePartial<U>[] : {
|
|
5
|
-
[P in keyof T]?: DeepNullablePartial<Exclude<T[P], undefined>> | null;
|
|
6
|
-
};
|
|
1
|
+
import { DeepPickWritable, HighDeepNullish, Type } from 'ts-gems';
|
|
2
|
+
export type PartialInput<T> = HighDeepNullish<DeepPickWritable<T>>;
|
|
3
|
+
export type PartialOutput<T> = HighDeepNullish<T>;
|
|
7
4
|
export type Thunk<T> = T | (() => T);
|
|
8
|
-
export type ThunkAsync<T> =
|
|
5
|
+
export type ThunkAsync<T> = Thunk<T> | Thunk<Promise<T>>;
|
|
9
6
|
export type TypeThunk<T = any> = Thunk<Type<T>>;
|
|
10
7
|
export type TypeThunkAsync<T = any> = ThunkAsync<Type<T>>;
|
|
11
|
-
export {};
|