@opra/common 0.28.0 → 0.28.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/browser.js CHANGED
@@ -1401,6 +1401,8 @@ var FieldClass = class {
1401
1401
  this.default = init.default;
1402
1402
  this.fixed = init.fixed;
1403
1403
  this.required = init.required;
1404
+ this.readonly = init.readonly;
1405
+ this.writeonly = init.writeonly;
1404
1406
  this.exclusive = init.exclusive;
1405
1407
  this.deprecated = init.deprecated;
1406
1408
  this.examples = init.examples;
@@ -1413,22 +1415,18 @@ var FieldClass = class {
1413
1415
  default: this.default,
1414
1416
  fixed: this.fixed,
1415
1417
  required: this.required,
1418
+ readonly: this.readonly,
1419
+ writeonly: this.writeonly,
1416
1420
  exclusive: this.exclusive,
1417
1421
  deprecated: this.deprecated,
1418
1422
  examples: this.examples
1419
1423
  });
1420
1424
  }
1421
- getDecoder() {
1422
- if (!this._decoder)
1423
- this._decoder = this.generateCodec("decode");
1424
- return this._decoder;
1425
- }
1426
- getEncoder() {
1427
- if (!this._encoder)
1428
- this._encoder = this.generateCodec("encode");
1429
- return this._encoder;
1430
- }
1431
1425
  generateCodec(codec, options) {
1426
+ if (options?.operation === "read" && this.writeonly)
1427
+ return vg3.isUndefined();
1428
+ if (options?.operation === "write" && this.readonly)
1429
+ return vg3.isUndefined();
1432
1430
  let fn = this.type.generateCodec(codec, options);
1433
1431
  if (this.isArray)
1434
1432
  fn = vg3.isArray(fn);
@@ -10336,7 +10334,7 @@ var Operation = class extends Endpoint {
10336
10334
  this.decodeInput = vg7.isAny();
10337
10335
  this.encodeReturning = vg7.isAny();
10338
10336
  this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType || "any");
10339
- this.encodeReturning = this.returnType.generateCodec("encode");
10337
+ this.encodeReturning = this.returnType.generateCodec("encode", { operation: "read" });
10340
10338
  }
10341
10339
  };
10342
10340
 
@@ -10394,13 +10392,15 @@ var CollectionClass = class extends CrudResource {
10394
10392
  endpoint.decodeInput = this.type.generateCodec("decode", {
10395
10393
  partial: true,
10396
10394
  pick: endpoint.inputPickFields,
10397
- omit: endpoint.inputOmitFields
10395
+ omit: endpoint.inputOmitFields,
10396
+ operation: "write"
10398
10397
  });
10399
10398
  endpoint.returnType = this.type;
10400
10399
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10401
10400
  partial: true,
10402
10401
  pick: endpoint.outputPickFields,
10403
- omit: endpoint.outputOmitFields
10402
+ omit: endpoint.outputOmitFields,
10403
+ operation: "read"
10404
10404
  });
10405
10405
  }
10406
10406
  endpoint = this.operations.get("deleteMany");
@@ -10416,7 +10416,8 @@ var CollectionClass = class extends CrudResource {
10416
10416
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10417
10417
  partial: true,
10418
10418
  pick: endpoint.outputPickFields,
10419
- omit: endpoint.outputOmitFields
10419
+ omit: endpoint.outputOmitFields,
10420
+ operation: "read"
10420
10421
  });
10421
10422
  }
10422
10423
  endpoint = this.operations.get("findMany");
@@ -10434,7 +10435,8 @@ var CollectionClass = class extends CrudResource {
10434
10435
  endpoint.encodeReturning = vg8.isArray(this.type.generateCodec("encode", {
10435
10436
  partial: true,
10436
10437
  pick: endpoint.outputPickFields,
10437
- omit: endpoint.outputOmitFields
10438
+ omit: endpoint.outputOmitFields,
10439
+ operation: "read"
10438
10440
  }));
10439
10441
  }
10440
10442
  endpoint = this.operations.get("update");
@@ -10444,13 +10446,15 @@ var CollectionClass = class extends CrudResource {
10444
10446
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10445
10447
  endpoint.decodeInput = this.type.generateCodec("decode", {
10446
10448
  pick: endpoint.inputPickFields,
10447
- omit: endpoint.inputOmitFields
10449
+ omit: endpoint.inputOmitFields,
10450
+ operation: "write"
10448
10451
  });
10449
10452
  endpoint.returnType = this.type;
10450
10453
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10451
10454
  partial: true,
10452
10455
  pick: endpoint.outputPickFields,
10453
- omit: endpoint.outputOmitFields
10456
+ omit: endpoint.outputOmitFields,
10457
+ operation: "read"
10454
10458
  });
10455
10459
  }
10456
10460
  endpoint = this.operations.get("updateMany");
@@ -10458,7 +10462,8 @@ var CollectionClass = class extends CrudResource {
10458
10462
  endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
10459
10463
  endpoint.decodeInput = this.type.generateCodec("decode", {
10460
10464
  pick: endpoint.inputPickFields,
10461
- omit: endpoint.inputOmitFields
10465
+ omit: endpoint.inputOmitFields,
10466
+ operation: "write"
10462
10467
  });
10463
10468
  }
10464
10469
  }
@@ -10800,13 +10805,15 @@ var SingletonClass = class extends CrudResource {
10800
10805
  endpoint.decodeInput = this.type.generateCodec("decode", {
10801
10806
  partial: true,
10802
10807
  pick: endpoint.inputPickFields,
10803
- omit: endpoint.inputOmitFields
10808
+ omit: endpoint.inputOmitFields,
10809
+ operation: "write"
10804
10810
  });
10805
10811
  endpoint.returnType = this.type;
10806
10812
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10807
10813
  partial: true,
10808
10814
  pick: endpoint.outputPickFields,
10809
- omit: endpoint.outputOmitFields
10815
+ omit: endpoint.outputOmitFields,
10816
+ operation: "read"
10810
10817
  });
10811
10818
  }
10812
10819
  endpoint = this.operations.get("get");
@@ -10818,7 +10825,8 @@ var SingletonClass = class extends CrudResource {
10818
10825
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10819
10826
  partial: true,
10820
10827
  pick: endpoint.outputPickFields,
10821
- omit: endpoint.outputOmitFields
10828
+ omit: endpoint.outputOmitFields,
10829
+ operation: "read"
10822
10830
  });
10823
10831
  }
10824
10832
  endpoint = this.operations.get("update");
@@ -10828,13 +10836,15 @@ var SingletonClass = class extends CrudResource {
10828
10836
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10829
10837
  endpoint.decodeInput = this.type.generateCodec("decode", {
10830
10838
  pick: endpoint.inputPickFields,
10831
- omit: endpoint.inputOmitFields
10839
+ omit: endpoint.inputOmitFields,
10840
+ operation: "write"
10832
10841
  });
10833
10842
  endpoint.returnType = this.type;
10834
10843
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10835
10844
  partial: true,
10836
10845
  pick: endpoint.outputPickFields,
10837
- omit: endpoint.outputOmitFields
10846
+ omit: endpoint.outputOmitFields,
10847
+ operation: "read"
10838
10848
  });
10839
10849
  }
10840
10850
  }
@@ -15,6 +15,8 @@ class FieldClass {
15
15
  this.default = init.default;
16
16
  this.fixed = init.fixed;
17
17
  this.required = init.required;
18
+ this.readonly = init.readonly;
19
+ this.writeonly = init.writeonly;
18
20
  this.exclusive = init.exclusive;
19
21
  this.deprecated = init.deprecated;
20
22
  this.examples = init.examples;
@@ -27,22 +29,18 @@ class FieldClass {
27
29
  default: this.default,
28
30
  fixed: this.fixed,
29
31
  required: this.required,
32
+ readonly: this.readonly,
33
+ writeonly: this.writeonly,
30
34
  exclusive: this.exclusive,
31
35
  deprecated: this.deprecated,
32
36
  examples: this.examples
33
37
  });
34
38
  }
35
- getDecoder() {
36
- if (!this._decoder)
37
- this._decoder = this.generateCodec('decode');
38
- return this._decoder;
39
- }
40
- getEncoder() {
41
- if (!this._encoder)
42
- this._encoder = this.generateCodec('encode');
43
- return this._encoder;
44
- }
45
39
  generateCodec(codec, options) {
40
+ if (options?.operation === 'read' && this.writeonly)
41
+ return vg.isUndefined();
42
+ if (options?.operation === 'write' && this.readonly)
43
+ return vg.isUndefined();
46
44
  let fn = this.type.generateCodec(codec, options);
47
45
  if (this.isArray)
48
46
  fn = vg.isArray(fn);
@@ -36,12 +36,14 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
36
36
  partial: true,
37
37
  pick: endpoint.inputPickFields,
38
38
  omit: endpoint.inputOmitFields,
39
+ operation: 'write'
39
40
  });
40
41
  endpoint.returnType = this.type;
41
42
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
42
43
  partial: true,
43
44
  pick: endpoint.outputPickFields,
44
45
  omit: endpoint.outputOmitFields,
46
+ operation: 'read'
45
47
  });
46
48
  }
47
49
  // ------------------
@@ -62,6 +64,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
62
64
  partial: true,
63
65
  pick: endpoint.outputPickFields,
64
66
  omit: endpoint.outputOmitFields,
67
+ operation: 'read'
65
68
  });
66
69
  }
67
70
  // ------------------
@@ -82,6 +85,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
82
85
  partial: true,
83
86
  pick: endpoint.outputPickFields,
84
87
  omit: endpoint.outputOmitFields,
88
+ operation: 'read'
85
89
  }));
86
90
  }
87
91
  // ------------------
@@ -94,12 +98,14 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
94
98
  endpoint.decodeInput = this.type.generateCodec('decode', {
95
99
  pick: endpoint.inputPickFields,
96
100
  omit: endpoint.inputOmitFields,
101
+ operation: 'write'
97
102
  });
98
103
  endpoint.returnType = this.type;
99
104
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
100
105
  partial: true,
101
106
  pick: endpoint.outputPickFields,
102
107
  omit: endpoint.outputOmitFields,
108
+ operation: 'read'
103
109
  });
104
110
  }
105
111
  // ------------------
@@ -110,6 +116,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
110
116
  endpoint.decodeInput = this.type.generateCodec('decode', {
111
117
  pick: endpoint.inputPickFields,
112
118
  omit: endpoint.inputOmitFields,
119
+ operation: 'write'
113
120
  });
114
121
  }
115
122
  }
@@ -19,7 +19,7 @@ class Operation extends endpoint_js_1.Endpoint {
19
19
  this.encodeReturning = vg.isAny();
20
20
  this.returnType = init.returnType instanceof data_type_js_1.DataType
21
21
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
22
- this.encodeReturning = this.returnType.generateCodec('encode');
22
+ this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
23
23
  }
24
24
  }
25
25
  exports.Operation = Operation;
@@ -18,12 +18,14 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
18
18
  partial: true,
19
19
  pick: endpoint.inputPickFields,
20
20
  omit: endpoint.inputOmitFields,
21
+ operation: 'write'
21
22
  });
22
23
  endpoint.returnType = this.type;
23
24
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
24
25
  partial: true,
25
26
  pick: endpoint.outputPickFields,
26
27
  omit: endpoint.outputOmitFields,
28
+ operation: 'read'
27
29
  });
28
30
  }
29
31
  // ------------------
@@ -37,6 +39,7 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
37
39
  partial: true,
38
40
  pick: endpoint.outputPickFields,
39
41
  omit: endpoint.outputOmitFields,
42
+ operation: 'read'
40
43
  });
41
44
  }
42
45
  // ------------------
@@ -48,12 +51,14 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
48
51
  endpoint.decodeInput = this.type.generateCodec('decode', {
49
52
  pick: endpoint.inputPickFields,
50
53
  omit: endpoint.inputOmitFields,
54
+ operation: 'write'
51
55
  });
52
56
  endpoint.returnType = this.type;
53
57
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
54
58
  partial: true,
55
59
  pick: endpoint.outputPickFields,
56
60
  omit: endpoint.outputOmitFields,
61
+ operation: 'read'
57
62
  });
58
63
  }
59
64
  }
@@ -11,6 +11,8 @@ export class FieldClass {
11
11
  this.default = init.default;
12
12
  this.fixed = init.fixed;
13
13
  this.required = init.required;
14
+ this.readonly = init.readonly;
15
+ this.writeonly = init.writeonly;
14
16
  this.exclusive = init.exclusive;
15
17
  this.deprecated = init.deprecated;
16
18
  this.examples = init.examples;
@@ -23,22 +25,18 @@ export class FieldClass {
23
25
  default: this.default,
24
26
  fixed: this.fixed,
25
27
  required: this.required,
28
+ readonly: this.readonly,
29
+ writeonly: this.writeonly,
26
30
  exclusive: this.exclusive,
27
31
  deprecated: this.deprecated,
28
32
  examples: this.examples
29
33
  });
30
34
  }
31
- getDecoder() {
32
- if (!this._decoder)
33
- this._decoder = this.generateCodec('decode');
34
- return this._decoder;
35
- }
36
- getEncoder() {
37
- if (!this._encoder)
38
- this._encoder = this.generateCodec('encode');
39
- return this._encoder;
40
- }
41
35
  generateCodec(codec, options) {
36
+ if (options?.operation === 'read' && this.writeonly)
37
+ return vg.isUndefined();
38
+ if (options?.operation === 'write' && this.readonly)
39
+ return vg.isUndefined();
42
40
  let fn = this.type.generateCodec(codec, options);
43
41
  if (this.isArray)
44
42
  fn = vg.isArray(fn);
@@ -32,12 +32,14 @@ export class CollectionClass extends CrudResource {
32
32
  partial: true,
33
33
  pick: endpoint.inputPickFields,
34
34
  omit: endpoint.inputOmitFields,
35
+ operation: 'write'
35
36
  });
36
37
  endpoint.returnType = this.type;
37
38
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
38
39
  partial: true,
39
40
  pick: endpoint.outputPickFields,
40
41
  omit: endpoint.outputOmitFields,
42
+ operation: 'read'
41
43
  });
42
44
  }
43
45
  // ------------------
@@ -58,6 +60,7 @@ export class CollectionClass extends CrudResource {
58
60
  partial: true,
59
61
  pick: endpoint.outputPickFields,
60
62
  omit: endpoint.outputOmitFields,
63
+ operation: 'read'
61
64
  });
62
65
  }
63
66
  // ------------------
@@ -78,6 +81,7 @@ export class CollectionClass extends CrudResource {
78
81
  partial: true,
79
82
  pick: endpoint.outputPickFields,
80
83
  omit: endpoint.outputOmitFields,
84
+ operation: 'read'
81
85
  }));
82
86
  }
83
87
  // ------------------
@@ -90,12 +94,14 @@ export class CollectionClass extends CrudResource {
90
94
  endpoint.decodeInput = this.type.generateCodec('decode', {
91
95
  pick: endpoint.inputPickFields,
92
96
  omit: endpoint.inputOmitFields,
97
+ operation: 'write'
93
98
  });
94
99
  endpoint.returnType = this.type;
95
100
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
96
101
  partial: true,
97
102
  pick: endpoint.outputPickFields,
98
103
  omit: endpoint.outputOmitFields,
104
+ operation: 'read'
99
105
  });
100
106
  }
101
107
  // ------------------
@@ -106,6 +112,7 @@ export class CollectionClass extends CrudResource {
106
112
  endpoint.decodeInput = this.type.generateCodec('decode', {
107
113
  pick: endpoint.inputPickFields,
108
114
  omit: endpoint.inputOmitFields,
115
+ operation: 'write'
109
116
  });
110
117
  }
111
118
  }
@@ -15,6 +15,6 @@ export class Operation extends Endpoint {
15
15
  this.encodeReturning = vg.isAny();
16
16
  this.returnType = init.returnType instanceof DataType
17
17
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
18
- this.encodeReturning = this.returnType.generateCodec('encode');
18
+ this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
19
19
  }
20
20
  }
@@ -15,12 +15,14 @@ export class SingletonClass extends CrudResource {
15
15
  partial: true,
16
16
  pick: endpoint.inputPickFields,
17
17
  omit: endpoint.inputOmitFields,
18
+ operation: 'write'
18
19
  });
19
20
  endpoint.returnType = this.type;
20
21
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
21
22
  partial: true,
22
23
  pick: endpoint.outputPickFields,
23
24
  omit: endpoint.outputOmitFields,
25
+ operation: 'read'
24
26
  });
25
27
  }
26
28
  // ------------------
@@ -34,6 +36,7 @@ export class SingletonClass extends CrudResource {
34
36
  partial: true,
35
37
  pick: endpoint.outputPickFields,
36
38
  omit: endpoint.outputOmitFields,
39
+ operation: 'read'
37
40
  });
38
41
  }
39
42
  // ------------------
@@ -45,12 +48,14 @@ export class SingletonClass extends CrudResource {
45
48
  endpoint.decodeInput = this.type.generateCodec('decode', {
46
49
  pick: endpoint.inputPickFields,
47
50
  omit: endpoint.inputOmitFields,
51
+ operation: 'write'
48
52
  });
49
53
  endpoint.returnType = this.type;
50
54
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
51
55
  partial: true,
52
56
  pick: endpoint.outputPickFields,
53
57
  omit: endpoint.outputOmitFields,
58
+ operation: 'read'
54
59
  });
55
60
  }
56
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "putil-varhelpers": "^1.6.5",
46
46
  "reflect-metadata": "^0.1.13",
47
47
  "uid": "^2.0.1",
48
- "valgen": "^4.0.0"
48
+ "valgen": "^4.0.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@browsery/fs": "^0.4.0",
@@ -41,5 +41,6 @@ export declare namespace DataType {
41
41
  pick?: string[];
42
42
  omit?: string[];
43
43
  partial?: boolean;
44
+ operation?: 'read' | 'write';
44
45
  }
45
46
  }
@@ -15,6 +15,8 @@ export declare class FieldClass {
15
15
  default?: any;
16
16
  fixed?: string | number;
17
17
  required?: boolean;
18
+ readonly?: boolean;
19
+ writeonly?: boolean;
18
20
  exclusive?: boolean;
19
21
  deprecated?: boolean | string;
20
22
  examples?: any[] | Record<string, any>;
@@ -22,7 +24,5 @@ export declare class FieldClass {
22
24
  exportSchema(options?: {
23
25
  webSafe?: boolean;
24
26
  }): OpraSchema.Field;
25
- getDecoder(): vg.Validator;
26
- getEncoder(): vg.Validator;
27
27
  generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.Validator;
28
28
  }
@@ -9,6 +9,8 @@ export type Field = {
9
9
  isArray?: boolean;
10
10
  default?: any;
11
11
  required?: boolean;
12
+ readonly?: boolean;
13
+ writeonly?: boolean;
12
14
  format?: string;
13
15
  fixed?: string | number;
14
16
  examples?: any[] | Record<string, any>;