@opra/common 0.29.0 → 0.30.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 CHANGED
@@ -797,6 +797,24 @@ var IssueSeverity;
797
797
  };
798
798
  })(IssueSeverity || (IssueSeverity = {}));
799
799
 
800
+ // ../../build/common/esm/exception/http-errors/conflict.error.js
801
+ var ConflictError = class extends OpraException {
802
+ static {
803
+ __name(this, "ConflictError");
804
+ }
805
+ constructor() {
806
+ super(...arguments);
807
+ this.status = 409;
808
+ }
809
+ init(issue) {
810
+ super.init({
811
+ message: translate("error:CONFLICT", "Conflict"),
812
+ code: "CONFLICT",
813
+ ...issue
814
+ });
815
+ }
816
+ };
817
+
800
818
  // ../../build/common/esm/exception/resource-errors/resource-conflict.error.js
801
819
  var ResourceConflictError = class extends OpraException {
802
820
  static {
@@ -1417,7 +1435,7 @@ var FieldClass = class {
1417
1435
  }
1418
1436
  exportSchema(options) {
1419
1437
  return omitUndefined({
1420
- type: this.type.name ? this.type.name : this.type.exportSchema(options),
1438
+ type: this.type ? this.type.name ? this.type.name : this.type.exportSchema(options) : void 0,
1421
1439
  description: this.description,
1422
1440
  isArray: this.isArray,
1423
1441
  default: this.default,
@@ -1647,6 +1665,8 @@ var ComplexTypeClass = class extends DataType {
1647
1665
  let f;
1648
1666
  if (overwriteField) {
1649
1667
  f = { ...overwriteField };
1668
+ if (!field)
1669
+ f.type = this.document.getDataType("any");
1650
1670
  Object.setPrototypeOf(f, field || ApiField.prototype);
1651
1671
  } else
1652
1672
  f = field;
@@ -10354,9 +10374,9 @@ var CrudOperation = class extends Endpoint {
10354
10374
  this.encodeReturning = vg7.isAny();
10355
10375
  this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType || "any");
10356
10376
  this.encodeReturning = this.returnType.generateCodec("encode", { operation: "read" });
10357
- if (init.options.inputOverwriteFields)
10377
+ if (init.options?.inputOverwriteFields)
10358
10378
  this.inputOverwriteFields = new ResponsiveMap(init.options.inputOverwriteFields);
10359
- if (init.options.outputOverwriteFields)
10379
+ if (init.options?.outputOverwriteFields)
10360
10380
  this.outputOverwriteFields = new ResponsiveMap(init.options.outputOverwriteFields);
10361
10381
  }
10362
10382
  exportSchema(options) {
@@ -11147,9 +11167,13 @@ var ApiDocumentFactory = class _ApiDocumentFactory extends TypeDocumentFactory {
11147
11167
  for (const [kA, oA] of Object.entries(source)) {
11148
11168
  if (!oA)
11149
11169
  continue;
11170
+ const o = output[kA] = { ...oA };
11150
11171
  let parameters;
11172
+ if (oA.returnType) {
11173
+ o.returnType = await this.importDataType(oA.returnType);
11174
+ }
11151
11175
  if (oA.parameters) {
11152
- parameters = {};
11176
+ parameters = o.parameters = {};
11153
11177
  for (const [kP, oP] of Object.entries(oA.parameters)) {
11154
11178
  if (oP.enum) {
11155
11179
  oP.type = EnumType2(oP.enum, { name: kP + "Enum" });
@@ -11231,6 +11255,9 @@ var ApiDocumentFactory = class _ApiDocumentFactory extends TypeDocumentFactory {
11231
11255
  const output = {};
11232
11256
  for (const [kA, oA] of Object.entries(source)) {
11233
11257
  const o = output[kA] = { ...oA };
11258
+ if (oA.returnType) {
11259
+ o.returnType = await this.importDataType(oA.returnType);
11260
+ }
11234
11261
  if (oA.parameters) {
11235
11262
  const parameters = o.parameters = {};
11236
11263
  for (const [kP, oP] of Object.entries(oA.parameters)) {
@@ -12034,6 +12061,7 @@ export {
12034
12061
  BaseI18n,
12035
12062
  Collection2 as Collection,
12036
12063
  ComplexType2 as ComplexType,
12064
+ ConflictError,
12037
12065
  Container2 as Container,
12038
12066
  CrudOperation,
12039
12067
  CrudResource,
@@ -192,6 +192,8 @@ class ComplexTypeClass extends data_type_js_1.DataType {
192
192
  let f;
193
193
  if (overwriteField) {
194
194
  f = { ...overwriteField };
195
+ if (!field)
196
+ f.type = this.document.getDataType('any');
195
197
  Object.setPrototypeOf(f, field || field_js_1.ApiField.prototype);
196
198
  }
197
199
  else
@@ -23,7 +23,8 @@ class FieldClass {
23
23
  }
24
24
  exportSchema(options) {
25
25
  return (0, index_js_1.omitUndefined)({
26
- type: this.type.name ? this.type.name : this.type.exportSchema(options),
26
+ type: this.type ?
27
+ (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
27
28
  description: this.description,
28
29
  isArray: this.isArray,
29
30
  default: this.default,
@@ -74,9 +74,14 @@ class ApiDocumentFactory extends type_document_factory_js_1.TypeDocumentFactory
74
74
  /* istanbul ignore next */
75
75
  if (!oA)
76
76
  continue;
77
+ const o = output[kA] = { ...oA };
77
78
  let parameters;
79
+ // Resolve lazy type
80
+ if (oA.returnType) {
81
+ o.returnType = await this.importDataType(oA.returnType);
82
+ }
78
83
  if (oA.parameters) {
79
- parameters = {};
84
+ parameters = o.parameters = {};
80
85
  for (const [kP, oP] of Object.entries(oA.parameters)) {
81
86
  if (oP.enum) {
82
87
  oP.type = (0, enum_type_js_1.EnumType)(oP.enum, { name: kP + 'Enum' });
@@ -163,6 +168,10 @@ class ApiDocumentFactory extends type_document_factory_js_1.TypeDocumentFactory
163
168
  const output = {};
164
169
  for (const [kA, oA] of Object.entries(source)) {
165
170
  const o = output[kA] = { ...oA };
171
+ // Resolve lazy type
172
+ if (oA.returnType) {
173
+ o.returnType = await this.importDataType(oA.returnType);
174
+ }
166
175
  if (oA.parameters) {
167
176
  const parameters = o.parameters = {};
168
177
  for (const [kP, oP] of Object.entries(oA.parameters)) {
@@ -22,9 +22,9 @@ class CrudOperation extends endpoint_js_1.Endpoint {
22
22
  this.returnType = init.returnType instanceof data_type_js_1.DataType
23
23
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
24
24
  this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
25
- if (init.options.inputOverwriteFields)
25
+ if (init.options?.inputOverwriteFields)
26
26
  this.inputOverwriteFields = new index_js_1.ResponsiveMap(init.options.inputOverwriteFields);
27
- if (init.options.outputOverwriteFields)
27
+ if (init.options?.outputOverwriteFields)
28
28
  this.outputOverwriteFields = new index_js_1.ResponsiveMap(init.options.outputOverwriteFields);
29
29
  }
30
30
  exportSchema(options) {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConflictError = void 0;
4
+ const index_js_1 = require("../../i18n/index.js");
5
+ const opra_exception_js_1 = require("../opra-exception.js");
6
+ /**
7
+ * 409 Conflict
8
+ * This response is sent when a request conflicts with the current state of the server.
9
+ */
10
+ class ConflictError extends opra_exception_js_1.OpraException {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.status = 409;
14
+ }
15
+ init(issue) {
16
+ super.init({
17
+ message: (0, index_js_1.translate)('error:CONFLICT', 'Conflict'),
18
+ code: 'CONFLICT',
19
+ ...issue
20
+ });
21
+ }
22
+ }
23
+ exports.ConflictError = ConflictError;
@@ -6,6 +6,7 @@ tslib_1.__exportStar(require("./error-issue.js"), exports);
6
6
  tslib_1.__exportStar(require("./wrap-exception.js"), exports);
7
7
  tslib_1.__exportStar(require("./issue-severity.enum.js"), exports);
8
8
  tslib_1.__exportStar(require("./http-errors/bad-request.error.js"), exports);
9
+ tslib_1.__exportStar(require("./http-errors/conflict.error.js"), exports);
9
10
  tslib_1.__exportStar(require("./http-errors/failed-dependency.error.js"), exports);
10
11
  tslib_1.__exportStar(require("./http-errors/forbidden.error.js"), exports);
11
12
  tslib_1.__exportStar(require("./http-errors/internal-server.error.js"), exports);
@@ -188,6 +188,8 @@ export class ComplexTypeClass extends DataType {
188
188
  let f;
189
189
  if (overwriteField) {
190
190
  f = { ...overwriteField };
191
+ if (!field)
192
+ f.type = this.document.getDataType('any');
191
193
  Object.setPrototypeOf(f, field || ApiField.prototype);
192
194
  }
193
195
  else
@@ -19,7 +19,8 @@ export class FieldClass {
19
19
  }
20
20
  exportSchema(options) {
21
21
  return omitUndefined({
22
- type: this.type.name ? this.type.name : this.type.exportSchema(options),
22
+ type: this.type ?
23
+ (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
23
24
  description: this.description,
24
25
  isArray: this.isArray,
25
26
  default: this.default,
@@ -71,9 +71,14 @@ export class ApiDocumentFactory extends TypeDocumentFactory {
71
71
  /* istanbul ignore next */
72
72
  if (!oA)
73
73
  continue;
74
+ const o = output[kA] = { ...oA };
74
75
  let parameters;
76
+ // Resolve lazy type
77
+ if (oA.returnType) {
78
+ o.returnType = await this.importDataType(oA.returnType);
79
+ }
75
80
  if (oA.parameters) {
76
- parameters = {};
81
+ parameters = o.parameters = {};
77
82
  for (const [kP, oP] of Object.entries(oA.parameters)) {
78
83
  if (oP.enum) {
79
84
  oP.type = EnumType(oP.enum, { name: kP + 'Enum' });
@@ -160,6 +165,10 @@ export class ApiDocumentFactory extends TypeDocumentFactory {
160
165
  const output = {};
161
166
  for (const [kA, oA] of Object.entries(source)) {
162
167
  const o = output[kA] = { ...oA };
168
+ // Resolve lazy type
169
+ if (oA.returnType) {
170
+ o.returnType = await this.importDataType(oA.returnType);
171
+ }
163
172
  if (oA.parameters) {
164
173
  const parameters = o.parameters = {};
165
174
  for (const [kP, oP] of Object.entries(oA.parameters)) {
@@ -18,9 +18,9 @@ export class CrudOperation extends Endpoint {
18
18
  this.returnType = init.returnType instanceof DataType
19
19
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
20
20
  this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
21
- if (init.options.inputOverwriteFields)
21
+ if (init.options?.inputOverwriteFields)
22
22
  this.inputOverwriteFields = new ResponsiveMap(init.options.inputOverwriteFields);
23
- if (init.options.outputOverwriteFields)
23
+ if (init.options?.outputOverwriteFields)
24
24
  this.outputOverwriteFields = new ResponsiveMap(init.options.outputOverwriteFields);
25
25
  }
26
26
  exportSchema(options) {
@@ -0,0 +1,19 @@
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
3
+ /**
4
+ * 409 Conflict
5
+ * This response is sent when a request conflicts with the current state of the server.
6
+ */
7
+ export class ConflictError extends OpraException {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.status = 409;
11
+ }
12
+ init(issue) {
13
+ super.init({
14
+ message: translate('error:CONFLICT', 'Conflict'),
15
+ code: 'CONFLICT',
16
+ ...issue
17
+ });
18
+ }
19
+ }
@@ -3,6 +3,7 @@ export * from './error-issue.js';
3
3
  export * from './wrap-exception.js';
4
4
  export * from './issue-severity.enum.js';
5
5
  export * from './http-errors/bad-request.error.js';
6
+ export * from './http-errors/conflict.error.js';
6
7
  export * from './http-errors/failed-dependency.error.js';
7
8
  export * from './http-errors/forbidden.error.js';
8
9
  export * from './http-errors/internal-server.error.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
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.1"
48
+ "valgen": "^4.1.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@browsery/fs": "^0.4.0",
@@ -75,4 +75,4 @@
75
75
  "opra",
76
76
  "common"
77
77
  ]
78
- }
78
+ }
@@ -16,7 +16,6 @@ export declare namespace ApiDocumentFactory {
16
16
  interface InitArguments extends TypeDocumentFactory.InitArguments {
17
17
  root?: RootInit;
18
18
  }
19
- type DataTypeInitializer = TypeDocumentFactory.DataTypeInitializer;
20
19
  type ResourceInitializer = (Collection.InitArguments & {
21
20
  kind: OpraSchema.Collection.Kind;
22
21
  }) | (Singleton.InitArguments & {
@@ -27,20 +27,36 @@ export declare namespace Collection {
27
27
  interface DecoratorOptions<T = any> extends Partial<StrictOmit<CollectionDecorator.Metadata, 'kind' | 'operations' | 'actions' | 'primaryKey'>> {
28
28
  primaryKey?: keyof T | (keyof T)[];
29
29
  }
30
+ interface Action {
31
+ }
30
32
  namespace Action {
31
33
  }
34
+ interface Create {
35
+ }
32
36
  namespace Create {
33
37
  }
38
+ interface Delete {
39
+ }
34
40
  namespace Delete {
35
41
  }
42
+ interface DeleteMany {
43
+ }
36
44
  namespace DeleteMany {
37
45
  }
46
+ interface FindMany {
47
+ }
38
48
  namespace FindMany {
39
49
  }
50
+ interface Get {
51
+ }
40
52
  namespace Get {
41
53
  }
54
+ interface Update {
55
+ }
42
56
  namespace Update {
43
57
  }
58
+ interface UpdateMany {
59
+ }
44
60
  namespace UpdateMany {
45
61
  }
46
62
  }
@@ -20,6 +20,8 @@ export declare namespace Container {
20
20
  }
21
21
  interface DecoratorOptions extends Partial<StrictOmit<ContainerDecorator.Metadata, 'kind' | 'actions'>> {
22
22
  }
23
+ interface Action {
24
+ }
23
25
  namespace Action {
24
26
  }
25
27
  }
@@ -26,14 +26,24 @@ export declare namespace Singleton {
26
26
  }
27
27
  interface DecoratorOptions extends Partial<StrictOmit<SingletonDecorator.Metadata, 'kind' | 'operations' | 'actions'>> {
28
28
  }
29
+ interface Action {
30
+ }
29
31
  namespace Action {
30
32
  }
33
+ interface Create {
34
+ }
31
35
  namespace Create {
32
36
  }
37
+ interface Delete {
38
+ }
33
39
  namespace Delete {
34
40
  }
41
+ interface Get {
42
+ }
35
43
  namespace Get {
36
44
  }
45
+ interface Update {
46
+ }
37
47
  namespace Update {
38
48
  }
39
49
  }
@@ -20,12 +20,20 @@ export declare namespace Storage {
20
20
  }
21
21
  interface DecoratorOptions extends Partial<StrictOmit<StorageDecorator.Metadata, 'kind' | 'operations' | 'actions'>> {
22
22
  }
23
+ interface Action {
24
+ }
23
25
  namespace Action {
24
26
  }
27
+ interface Delete {
28
+ }
25
29
  namespace Delete {
26
30
  }
31
+ interface Get {
32
+ }
27
33
  namespace Get {
28
34
  }
35
+ interface Post {
36
+ }
29
37
  namespace Post {
30
38
  }
31
39
  }
@@ -0,0 +1,10 @@
1
+ import { ErrorIssue } from '../error-issue.js';
2
+ import { OpraException } from '../opra-exception.js';
3
+ /**
4
+ * 409 Conflict
5
+ * This response is sent when a request conflicts with the current state of the server.
6
+ */
7
+ export declare class ConflictError extends OpraException {
8
+ status: number;
9
+ protected init(issue: Partial<ErrorIssue>): void;
10
+ }
@@ -3,6 +3,7 @@ export * from './error-issue.js';
3
3
  export * from './wrap-exception.js';
4
4
  export * from './issue-severity.enum.js';
5
5
  export * from './http-errors/bad-request.error.js';
6
+ export * from './http-errors/conflict.error.js';
6
7
  export * from './http-errors/failed-dependency.error.js';
7
8
  export * from './http-errors/forbidden.error.js';
8
9
  export * from './http-errors/internal-server.error.js';