@opra/common 0.31.0 → 0.31.2

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
@@ -1011,7 +1011,8 @@ var DataType = class _DataType {
1011
1011
  this.name = init?.name;
1012
1012
  this.own = {};
1013
1013
  this.description = init?.description;
1014
- this.isAnonymous = !this.name;
1014
+ if (!this.name)
1015
+ this.isAnonymous = true;
1015
1016
  }
1016
1017
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1017
1018
  exportSchema(options) {
@@ -1436,8 +1437,9 @@ var FieldClass = class {
1436
1437
  this.format = init.format;
1437
1438
  }
1438
1439
  exportSchema(options) {
1440
+ const isAnonymous = !this.type.name || this.type.kind === "ComplexType" && this.type.isAnonymous;
1439
1441
  return omitUndefined({
1440
- type: this.type ? this.type.name ? this.type.name : this.type.exportSchema(options) : void 0,
1442
+ type: this.type ? isAnonymous ? this.type.exportSchema(options) : this.type.name : void 0,
1441
1443
  description: this.description,
1442
1444
  isArray: this.isArray,
1443
1445
  default: this.default,
@@ -1516,12 +1518,14 @@ var ComplexTypeClass = class extends DataType {
1516
1518
  own.ctor = own.ctor || init.base.ctor;
1517
1519
  }
1518
1520
  own.additionalFields = init?.additionalFields;
1521
+ own.anonymous = init?.anonymous;
1519
1522
  own.fields = new ResponsiveMap();
1520
1523
  this.kind = opra_schema_ns_exports.ComplexType.Kind;
1521
1524
  this.base = init?.base;
1522
1525
  this.ctor = own.ctor || Object;
1523
1526
  this.abstract = init.abstract;
1524
1527
  this.additionalFields = own.additionalFields;
1528
+ this.isAnonymous = this.isAnonymous || init.anonymous;
1525
1529
  if (this.base?.additionalFields === true && this.additionalFields !== true)
1526
1530
  this.additionalFields = true;
1527
1531
  else if (this.base?.additionalFields === "error" && !this.additionalFields)
@@ -10416,8 +10420,11 @@ var CrudResource = class extends Resource {
10416
10420
  }
10417
10421
  }
10418
10422
  }
10419
- getOperation(name) {
10420
- return this.operations.get(name);
10423
+ getOperation(operation) {
10424
+ const op = this.operations.get(operation);
10425
+ if (!op)
10426
+ throw new Error(`${this.name} resource does not support "${operation}" operations`);
10427
+ return op;
10421
10428
  }
10422
10429
  exportSchema(options) {
10423
10430
  const schema = super.exportSchema(options);
@@ -10513,6 +10520,7 @@ var CollectionClass = class extends CrudResource {
10513
10520
  endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10514
10521
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10515
10522
  endpoint.decodeInput = this.type.generateCodec("decode", {
10523
+ partial: true,
10516
10524
  pick: endpoint.options.inputPickFields,
10517
10525
  omit: endpoint.options.inputOmitFields,
10518
10526
  operation: "write",
@@ -24,12 +24,14 @@ class ComplexTypeClass extends data_type_js_1.DataType {
24
24
  own.ctor = own.ctor || init.base.ctor;
25
25
  }
26
26
  own.additionalFields = init?.additionalFields;
27
+ own.anonymous = init?.anonymous;
27
28
  own.fields = new index_js_1.ResponsiveMap();
28
29
  this.kind = index_js_3.OpraSchema.ComplexType.Kind;
29
30
  this.base = init?.base;
30
31
  this.ctor = own.ctor || Object;
31
32
  this.abstract = init.abstract;
32
33
  this.additionalFields = own.additionalFields;
34
+ this.isAnonymous = this.isAnonymous || init.anonymous;
33
35
  if (this.base?.additionalFields === true && this.additionalFields !== true)
34
36
  this.additionalFields = true;
35
37
  else if (this.base?.additionalFields === 'error' && !this.additionalFields)
@@ -13,7 +13,8 @@ class DataType {
13
13
  this.name = init?.name;
14
14
  this.own = {};
15
15
  this.description = init?.description;
16
- this.isAnonymous = !this.name;
16
+ if (!this.name)
17
+ this.isAnonymous = true;
17
18
  }
18
19
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
20
  exportSchema(options) {
@@ -24,9 +24,12 @@ class FieldClass {
24
24
  this.format = init.format;
25
25
  }
26
26
  exportSchema(options) {
27
+ const isAnonymous = !this.type.name ||
28
+ (this.type.kind === 'ComplexType' && this.type.isAnonymous);
27
29
  return (0, index_js_1.omitUndefined)({
28
- type: this.type ?
29
- (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
30
+ type: this.type
31
+ ? (isAnonymous ? this.type.exportSchema(options) : this.type.name)
32
+ : undefined,
30
33
  description: this.description,
31
34
  isArray: this.isArray,
32
35
  default: this.default,
@@ -100,6 +100,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
100
100
  endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
101
101
  endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
102
102
  endpoint.decodeInput = this.type.generateCodec('decode', {
103
+ partial: true,
103
104
  pick: endpoint.options.inputPickFields,
104
105
  omit: endpoint.options.inputOmitFields,
105
106
  operation: 'write',
@@ -14,8 +14,11 @@ class CrudResource extends resource_js_1.Resource {
14
14
  }
15
15
  }
16
16
  }
17
- getOperation(name) {
18
- return this.operations.get(name);
17
+ getOperation(operation) {
18
+ const op = this.operations.get(operation);
19
+ if (!op)
20
+ throw new Error(`${this.name} resource does not support "${operation}" operations`);
21
+ return op;
19
22
  }
20
23
  exportSchema(options) {
21
24
  const schema = super.exportSchema(options);
@@ -20,12 +20,14 @@ export class ComplexTypeClass extends DataType {
20
20
  own.ctor = own.ctor || init.base.ctor;
21
21
  }
22
22
  own.additionalFields = init?.additionalFields;
23
+ own.anonymous = init?.anonymous;
23
24
  own.fields = new ResponsiveMap();
24
25
  this.kind = OpraSchema.ComplexType.Kind;
25
26
  this.base = init?.base;
26
27
  this.ctor = own.ctor || Object;
27
28
  this.abstract = init.abstract;
28
29
  this.additionalFields = own.additionalFields;
30
+ this.isAnonymous = this.isAnonymous || init.anonymous;
29
31
  if (this.base?.additionalFields === true && this.additionalFields !== true)
30
32
  this.additionalFields = true;
31
33
  else if (this.base?.additionalFields === 'error' && !this.additionalFields)
@@ -10,7 +10,8 @@ export class DataType {
10
10
  this.name = init?.name;
11
11
  this.own = {};
12
12
  this.description = init?.description;
13
- this.isAnonymous = !this.name;
13
+ if (!this.name)
14
+ this.isAnonymous = true;
14
15
  }
15
16
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
17
  exportSchema(options) {
@@ -20,9 +20,12 @@ export class FieldClass {
20
20
  this.format = init.format;
21
21
  }
22
22
  exportSchema(options) {
23
+ const isAnonymous = !this.type.name ||
24
+ (this.type.kind === 'ComplexType' && this.type.isAnonymous);
23
25
  return omitUndefined({
24
- type: this.type ?
25
- (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
26
+ type: this.type
27
+ ? (isAnonymous ? this.type.exportSchema(options) : this.type.name)
28
+ : undefined,
26
29
  description: this.description,
27
30
  isArray: this.isArray,
28
31
  default: this.default,
@@ -96,6 +96,7 @@ export class CollectionClass extends CrudResource {
96
96
  endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
97
97
  endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
98
98
  endpoint.decodeInput = this.type.generateCodec('decode', {
99
+ partial: true,
99
100
  pick: endpoint.options.inputPickFields,
100
101
  omit: endpoint.options.inputOmitFields,
101
102
  operation: 'write',
@@ -11,8 +11,11 @@ export class CrudResource extends Resource {
11
11
  }
12
12
  }
13
13
  }
14
- getOperation(name) {
15
- return this.operations.get(name);
14
+ getOperation(operation) {
15
+ const op = this.operations.get(operation);
16
+ if (!op)
17
+ throw new Error(`${this.name} resource does not support "${operation}" operations`);
18
+ return op;
16
19
  }
17
20
  exportSchema(options) {
18
21
  const schema = super.exportSchema(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -32,11 +32,13 @@ export declare namespace ComplexType {
32
32
  base?: ComplexType | MappedType | MixinType;
33
33
  fields?: Record<string, ApiField.InitArguments>;
34
34
  additionalFields?: boolean | DataType | 'error';
35
+ anonymous?: boolean;
35
36
  }
36
37
  interface OwnProperties extends DataType.OwnProperties {
37
38
  ctor?: Type;
38
39
  additionalFields?: boolean | DataType | 'error';
39
40
  fields: ResponsiveMap<ApiField>;
41
+ anonymous?: boolean;
40
42
  }
41
43
  interface DecoratorOptions extends DataType.DecoratorOptions, Pick<InitArguments, 'ctor' | 'abstract'> {
42
44
  anonymous?: boolean;
@@ -15,8 +15,8 @@ export declare abstract class DataType {
15
15
  readonly name?: string;
16
16
  readonly base?: DataType;
17
17
  readonly own: DataType.OwnProperties;
18
- readonly description?: string;
19
- readonly isAnonymous: boolean;
18
+ description?: string;
19
+ isAnonymous?: boolean;
20
20
  protected constructor(document: ApiDocument, init?: DataType.InitArguments);
21
21
  abstract generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.Validator;
22
22
  exportSchema(options?: {
@@ -7,7 +7,7 @@ import { Resource } from './resource.js';
7
7
  export declare abstract class CrudResource extends Resource {
8
8
  operations: ResponsiveMap<CrudOperation>;
9
9
  protected constructor(parent: ApiDocument | Container, init: Resource.InitArguments);
10
- getOperation(name: string): CrudOperation | undefined;
10
+ getOperation(operation: string): CrudOperation | undefined;
11
11
  exportSchema(options?: {
12
12
  webSafe?: boolean;
13
13
  }): OpraSchema.ResourceBase & {