@opra/common 0.16.2 → 0.17.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.
Files changed (148) hide show
  1. package/cjs/document/data-type/complex-type.js +69 -56
  2. package/cjs/document/data-type/simple-type.js +0 -1
  3. package/cjs/document/resource/collection.js +15 -16
  4. package/cjs/document/resource/singleton.js +2 -2
  5. package/cjs/http/http-params.js +10 -11
  6. package/esm/document/api-document.js +33 -37
  7. package/esm/document/constants.js +3 -6
  8. package/esm/document/data-type/api-field.js +12 -15
  9. package/esm/document/data-type/builtin/any.type.js +5 -8
  10. package/esm/document/data-type/builtin/base64.type.js +5 -8
  11. package/esm/document/data-type/builtin/bigint.type.js +5 -8
  12. package/esm/document/data-type/builtin/boolean.type.js +8 -11
  13. package/esm/document/data-type/builtin/date.type.js +7 -10
  14. package/esm/document/data-type/builtin/guid.type.js +9 -12
  15. package/esm/document/data-type/builtin/index.js +10 -13
  16. package/esm/document/data-type/builtin/integer.type.js +10 -13
  17. package/esm/document/data-type/builtin/number.type.js +7 -10
  18. package/esm/document/data-type/builtin/object.type.js +5 -8
  19. package/esm/document/data-type/builtin/string.type.js +8 -11
  20. package/esm/document/data-type/builtin/time.type.js +7 -10
  21. package/esm/document/data-type/builtin/timestamp.type.js +9 -12
  22. package/esm/document/data-type/complex-type.js +94 -85
  23. package/esm/document/data-type/data-type.js +9 -12
  24. package/esm/document/data-type/enum-type.js +15 -19
  25. package/esm/document/data-type/mapped-type.js +24 -29
  26. package/esm/document/data-type/simple-type.js +17 -22
  27. package/esm/document/data-type/union-type.js +26 -29
  28. package/esm/document/factory/add-references.js +3 -7
  29. package/esm/document/factory/create-document.js +10 -16
  30. package/esm/document/factory/factory.js +33 -37
  31. package/esm/document/factory/import-resource-class.js +16 -22
  32. package/esm/document/factory/import-type-class.js +24 -34
  33. package/esm/document/factory/index.js +1 -4
  34. package/esm/document/factory/process-resources.js +10 -16
  35. package/esm/document/factory/process-types.js +31 -37
  36. package/esm/document/index.js +14 -17
  37. package/esm/document/resource/collection.js +58 -63
  38. package/esm/document/resource/resource.js +9 -12
  39. package/esm/document/resource/singleton.js +27 -31
  40. package/esm/document/utils/inspect.util.js +4 -7
  41. package/esm/document/utils/string-compare.util.js +1 -5
  42. package/esm/exception/enums/issue-severity.enum.js +2 -5
  43. package/esm/exception/error-issue.js +1 -2
  44. package/esm/exception/http-errors/bad-request.error.js +4 -8
  45. package/esm/exception/http-errors/failed-dependency.error.js +4 -8
  46. package/esm/exception/http-errors/forbidden.error.js +4 -8
  47. package/esm/exception/http-errors/internal-server.error.js +4 -8
  48. package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
  49. package/esm/exception/http-errors/not-acceptable.error.js +4 -8
  50. package/esm/exception/http-errors/not-found.error.js +4 -8
  51. package/esm/exception/http-errors/unauthorized.error.js +4 -8
  52. package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
  53. package/esm/exception/index.js +15 -18
  54. package/esm/exception/opra-exception.js +3 -7
  55. package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
  56. package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
  57. package/esm/exception/wrap-exception.js +20 -24
  58. package/esm/filter/antlr/OpraFilterLexer.js +6 -9
  59. package/esm/filter/antlr/OpraFilterListener.js +2 -5
  60. package/esm/filter/antlr/OpraFilterParser.js +79 -126
  61. package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
  62. package/esm/filter/ast/abstract/ast.js +1 -5
  63. package/esm/filter/ast/abstract/expression.js +2 -6
  64. package/esm/filter/ast/abstract/literal.js +2 -6
  65. package/esm/filter/ast/abstract/term.js +2 -6
  66. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
  67. package/esm/filter/ast/expressions/array-expression.js +2 -6
  68. package/esm/filter/ast/expressions/comparison-expression.js +2 -6
  69. package/esm/filter/ast/expressions/logical-expression.js +2 -6
  70. package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
  71. package/esm/filter/ast/index.js +16 -19
  72. package/esm/filter/ast/terms/boolean-literal.js +2 -6
  73. package/esm/filter/ast/terms/date-literal.js +8 -12
  74. package/esm/filter/ast/terms/external-constant.js +2 -6
  75. package/esm/filter/ast/terms/null-literal.js +2 -6
  76. package/esm/filter/ast/terms/number-literal.js +4 -8
  77. package/esm/filter/ast/terms/qualified-identifier.js +2 -6
  78. package/esm/filter/ast/terms/string-literal.js +4 -8
  79. package/esm/filter/ast/terms/time-literal.js +6 -10
  80. package/esm/filter/build.js +45 -69
  81. package/esm/filter/errors.js +3 -9
  82. package/esm/filter/filter-tree-visitor.js +26 -31
  83. package/esm/filter/index.js +5 -8
  84. package/esm/filter/opra-error-listener.js +4 -8
  85. package/esm/filter/parse.js +14 -19
  86. package/esm/filter/utils.js +2 -7
  87. package/esm/helpers/function-utils.js +8 -14
  88. package/esm/helpers/get-stack-filename.js +1 -5
  89. package/esm/helpers/index.js +8 -11
  90. package/esm/helpers/is-url.js +1 -5
  91. package/esm/helpers/mixin-utils.js +2 -7
  92. package/esm/helpers/object-utils.js +6 -12
  93. package/esm/helpers/path-to-object-tree.js +1 -5
  94. package/esm/helpers/responsive-map.js +1 -5
  95. package/esm/helpers/type-guards.js +7 -17
  96. package/esm/http/codecs/boolean-codec.js +1 -5
  97. package/esm/http/codecs/date-codec.js +1 -5
  98. package/esm/http/codecs/filter-codec.js +5 -9
  99. package/esm/http/codecs/integer-codec.js +2 -6
  100. package/esm/http/codecs/number-codec.js +1 -5
  101. package/esm/http/codecs/string-codec.js +1 -5
  102. package/esm/http/enums/http-headers-codes.enum.js +2 -5
  103. package/esm/http/enums/http-status-codes.enum.js +2 -5
  104. package/esm/http/enums/http-status-messages.js +1 -4
  105. package/esm/http/http-headers.js +5 -9
  106. package/esm/http/http-message.host.js +13 -18
  107. package/esm/http/http-params.js +30 -36
  108. package/esm/http/http-request-message.js +18 -22
  109. package/esm/http/http-response-message.js +23 -28
  110. package/esm/http/index.js +14 -17
  111. package/esm/http/interfaces/client-http-headers.interface.js +1 -2
  112. package/esm/http/interfaces/cookie-options.interface.js +1 -2
  113. package/esm/http/interfaces/server-http-headers.interface.js +1 -2
  114. package/esm/i18n/i18n.js +23 -28
  115. package/esm/i18n/index.js +5 -9
  116. package/esm/i18n/string-utils.js +2 -7
  117. package/esm/i18n/translate.js +3 -7
  118. package/esm/index.js +11 -16
  119. package/esm/schema/constants.js +1 -4
  120. package/esm/schema/data-type/complex-type.interface.js +2 -5
  121. package/esm/schema/data-type/data-type.interface.js +1 -2
  122. package/esm/schema/data-type/enum-type.interface.js +2 -5
  123. package/esm/schema/data-type/field.interface.js +1 -2
  124. package/esm/schema/data-type/mapped-type.interface.js +2 -5
  125. package/esm/schema/data-type/simple-type.interface.js +2 -5
  126. package/esm/schema/data-type/union-type.interface.js +2 -5
  127. package/esm/schema/document.interface.js +1 -2
  128. package/esm/schema/index.js +31 -34
  129. package/esm/schema/resource/collection.interface.js +2 -5
  130. package/esm/schema/resource/container.interface.js +2 -5
  131. package/esm/schema/resource/endpoint.interface.js +1 -2
  132. package/esm/schema/resource/resource.interface.js +1 -2
  133. package/esm/schema/resource/singleton.interface.js +2 -5
  134. package/esm/schema/type-guards.js +40 -53
  135. package/esm/types.js +1 -2
  136. package/esm/url/index.js +5 -8
  137. package/esm/url/opra-url-path-component.js +3 -7
  138. package/esm/url/opra-url-path.js +14 -18
  139. package/esm/url/opra-url.js +15 -19
  140. package/esm/url/utils/decode-path-component.js +4 -8
  141. package/esm/url/utils/encode-path-component.js +3 -8
  142. package/esm/utils/path-utils.js +2 -7
  143. package/package.json +1 -1
  144. package/types/document/data-type/complex-type.d.ts +8 -2
  145. package/types/document/resource/collection.d.ts +5 -3
  146. package/types/document/resource/singleton.d.ts +3 -1
  147. package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
  148. package/types/http/http-params.d.ts +20 -19
@@ -1,29 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFieldSchema = exports.extractEnumTypeSchema = exports.extractUnionTypeSchema = exports.extractMappedTypeSchema = exports.extractComplexTypeSchema = exports.extractSimpleTypeSchema = exports.importTypeClass = void 0;
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../schema/index.js");
6
- const constants_js_1 = require("../constants.js");
7
- async function importTypeClass(typeThunk) {
1
+ import { cloneObject, isConstructor, resolveThunk } from '../../helpers/index.js';
2
+ import { OpraSchema } from '../../schema/index.js';
3
+ import { METADATA_KEY } from '../constants.js';
4
+ export async function importTypeClass(typeThunk) {
8
5
  const { document, typeQueue, cache } = this;
9
- const thunk = await (0, index_js_1.resolveThunk)(typeThunk);
6
+ const thunk = await resolveThunk(typeThunk);
10
7
  const cached = cache.get(thunk);
11
8
  if (cached)
12
9
  return cached;
13
10
  const dt = document.getDataType(thunk, true);
14
11
  if (dt && dt.name)
15
12
  return dt.name;
16
- const metadata = Reflect.getMetadata(constants_js_1.METADATA_KEY, thunk);
17
- if (!(metadata && index_js_2.OpraSchema.isDataType(metadata))) {
13
+ const metadata = Reflect.getMetadata(METADATA_KEY, thunk);
14
+ if (!(metadata && OpraSchema.isDataType(metadata))) {
18
15
  // If thunk is a Type class
19
- if ((0, index_js_1.isConstructor)(thunk))
16
+ if (isConstructor(thunk))
20
17
  throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
21
18
  // If thunk is an Enum object
22
19
  throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
23
20
  }
24
21
  // Clone metadata to prevent changing its contents
25
22
  const name = metadata.name;
26
- const schema = (0, index_js_1.cloneObject)(metadata);
23
+ const schema = cloneObject(metadata);
27
24
  const result = name || schema;
28
25
  if (name) {
29
26
  if (this.document.types.has(name) || typeQueue.has(name))
@@ -32,15 +29,15 @@ async function importTypeClass(typeThunk) {
32
29
  typeQueue.set(name, schema);
33
30
  }
34
31
  // If thunk is a DataType class
35
- if ((0, index_js_1.isConstructor)(thunk)) {
32
+ if (isConstructor(thunk)) {
36
33
  const ctor = thunk;
37
- if (index_js_2.OpraSchema.isSimpleType(schema))
34
+ if (OpraSchema.isSimpleType(schema))
38
35
  await this.extractSimpleTypeSchema(schema, ctor, metadata);
39
- else if (index_js_2.OpraSchema.isComplexType(schema))
36
+ else if (OpraSchema.isComplexType(schema))
40
37
  await this.extractComplexTypeSchema(schema, ctor, metadata);
41
- else if (index_js_2.OpraSchema.isMappedType(schema))
38
+ else if (OpraSchema.isMappedType(schema))
42
39
  await this.extractMappedTypeSchema(schema, ctor, metadata);
43
- else if (index_js_2.OpraSchema.isUnionType(schema))
40
+ else if (OpraSchema.isUnionType(schema))
44
41
  await this.extractUnionTypeSchema(schema, ctor, metadata);
45
42
  else
46
43
  throw new TypeError(`Class "${ctor.name}" doesn't have a valid DataType metadata`);
@@ -48,9 +45,9 @@ async function importTypeClass(typeThunk) {
48
45
  }
49
46
  // If thunk is a EnumType object
50
47
  const enumObject = thunk;
51
- if (index_js_2.OpraSchema.isEnumType(schema)) {
48
+ if (OpraSchema.isEnumType(schema)) {
52
49
  let baseType;
53
- if (metadata.base && Reflect.hasMetadata(constants_js_1.METADATA_KEY, metadata.base)) {
50
+ if (metadata.base && Reflect.hasMetadata(METADATA_KEY, metadata.base)) {
54
51
  baseType = await this.importTypeClass(metadata.base);
55
52
  }
56
53
  schema.base = baseType;
@@ -59,20 +56,18 @@ async function importTypeClass(typeThunk) {
59
56
  }
60
57
  throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(enumObject).substring(0, 20)}...`);
61
58
  }
62
- exports.importTypeClass = importTypeClass;
63
59
  // noinspection JSUnusedLocalSymbols
64
- async function extractSimpleTypeSchema(target, ctor,
60
+ export async function extractSimpleTypeSchema(target, ctor,
65
61
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
62
  metadata) {
67
63
  const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
68
- if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
64
+ if (Reflect.hasMetadata(METADATA_KEY, baseClass))
69
65
  target.base = await this.importTypeClass(baseClass);
70
66
  target.codec = Object.create(ctor.prototype);
71
67
  }
72
- exports.extractSimpleTypeSchema = extractSimpleTypeSchema;
73
- async function extractComplexTypeSchema(target, ctor, metadata) {
68
+ export async function extractComplexTypeSchema(target, ctor, metadata) {
74
69
  const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
75
- if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
70
+ if (Reflect.hasMetadata(METADATA_KEY, baseClass))
76
71
  target.base = await this.importTypeClass(baseClass);
77
72
  target.ctor = ctor;
78
73
  // Fields
@@ -109,29 +104,24 @@ async function extractComplexTypeSchema(target, ctor, metadata) {
109
104
  }
110
105
  }
111
106
  }
112
- exports.extractComplexTypeSchema = extractComplexTypeSchema;
113
- async function extractMappedTypeSchema(target, ctor, metadata) {
107
+ export async function extractMappedTypeSchema(target, ctor, metadata) {
114
108
  target.type = await this.importTypeClass(metadata.type);
115
109
  }
116
- exports.extractMappedTypeSchema = extractMappedTypeSchema;
117
- async function extractUnionTypeSchema(target, ctor, metadata) {
110
+ export async function extractUnionTypeSchema(target, ctor, metadata) {
118
111
  const oldTypes = metadata.types;
119
112
  target.types = [];
120
113
  for (const type of oldTypes)
121
114
  target.types.push(await this.importTypeClass(type));
122
115
  }
123
- exports.extractUnionTypeSchema = extractUnionTypeSchema;
124
116
  // noinspection JSUnusedLocalSymbols
125
- async function extractEnumTypeSchema(
117
+ export async function extractEnumTypeSchema(
126
118
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
119
  target, enumObject, metadata) {
128
120
  // Do nothing. This method is used by external modules for extending the factory
129
121
  }
130
- exports.extractEnumTypeSchema = extractEnumTypeSchema;
131
122
  // noinspection JSUnusedLocalSymbols
132
- async function extractFieldSchema(
123
+ export async function extractFieldSchema(
133
124
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
125
  target, ctor, metadata, name) {
135
126
  // Do nothing. This method is used by external modules for extending the factory
136
127
  }
137
- exports.extractFieldSchema = extractFieldSchema;
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./factory.js"), exports);
1
+ export * from './factory.js';
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSingleton = exports.createCollection = exports.processResourceQueue = void 0;
4
- const index_js_1 = require("../../schema/index.js");
5
- const collection_js_1 = require("../resource/collection.js");
6
- const singleton_js_1 = require("../resource/singleton.js");
7
- async function processResourceQueue() {
1
+ import { OpraSchema } from '../../schema/index.js';
2
+ import { Collection } from '../resource/collection.js';
3
+ import { Singleton } from '../resource/singleton.js';
4
+ export async function processResourceQueue() {
8
5
  const { document, resourceQueue } = this;
9
6
  const resourceNames = Array.from(resourceQueue.keys());
10
7
  for (const name of resourceNames) {
@@ -12,12 +9,12 @@ async function processResourceQueue() {
12
9
  if (!schema)
13
10
  continue;
14
11
  try {
15
- if (index_js_1.OpraSchema.isCollection(schema)) {
12
+ if (OpraSchema.isCollection(schema)) {
16
13
  const resource = await this.createCollection(name, schema);
17
14
  document.resources.set(name, resource);
18
15
  continue;
19
16
  }
20
- if (index_js_1.OpraSchema.isSingleton(schema)) {
17
+ if (OpraSchema.isSingleton(schema)) {
21
18
  const resource = await this.createSingleton(name, schema);
22
19
  document.resources.set(name, resource);
23
20
  continue;
@@ -30,8 +27,7 @@ async function processResourceQueue() {
30
27
  throw new TypeError(`Invalid Resource schema: ${JSON.stringify(schema).substring(0, 20)}...`);
31
28
  }
32
29
  }
33
- exports.processResourceQueue = processResourceQueue;
34
- async function createCollection(name, schema) {
30
+ export async function createCollection(name, schema) {
35
31
  const { document } = this;
36
32
  const dataType = document.getComplexType(schema.type);
37
33
  const initArgs = {
@@ -39,10 +35,9 @@ async function createCollection(name, schema) {
39
35
  name,
40
36
  type: dataType
41
37
  };
42
- return new collection_js_1.Collection(document, initArgs);
38
+ return new Collection(document, initArgs);
43
39
  }
44
- exports.createCollection = createCollection;
45
- async function createSingleton(name, schema) {
40
+ export async function createSingleton(name, schema) {
46
41
  const { document } = this;
47
42
  const dataType = document.getComplexType(schema.type);
48
43
  const initArgs = {
@@ -50,6 +45,5 @@ async function createSingleton(name, schema) {
50
45
  name,
51
46
  type: dataType
52
47
  };
53
- return new singleton_js_1.Singleton(document, initArgs);
48
+ return new Singleton(document, initArgs);
54
49
  }
55
- exports.createSingleton = createSingleton;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addDataType = exports.createDataTypeInstance = exports.processTypes = void 0;
4
- const index_js_1 = require("../../schema/index.js");
5
- const complex_type_js_1 = require("../data-type/complex-type.js");
6
- const enum_type_js_1 = require("../data-type/enum-type.js");
7
- const mapped_type_js_1 = require("../data-type/mapped-type.js");
8
- const simple_type_js_1 = require("../data-type/simple-type.js");
9
- const union_type_js_1 = require("../data-type/union-type.js");
10
- async function processTypes() {
1
+ import { OpraSchema } from '../../schema/index.js';
2
+ import { ComplexType } from '../data-type/complex-type.js';
3
+ import { EnumType } from '../data-type/enum-type.js';
4
+ import { MappedType } from '../data-type/mapped-type.js';
5
+ import { SimpleType } from '../data-type/simple-type.js';
6
+ import { UnionType } from '../data-type/union-type.js';
7
+ export async function processTypes() {
11
8
  const { document, typeQueue } = this;
12
9
  // Create DataType instances
13
10
  for (const [name, schema] of typeQueue.entries()) {
@@ -23,36 +20,34 @@ async function processTypes() {
23
20
  }
24
21
  document.invalidate();
25
22
  }
26
- exports.processTypes = processTypes;
27
- function createDataTypeInstance(kind, name) {
23
+ export function createDataTypeInstance(kind, name) {
28
24
  const dataType = {
29
25
  document: this.document,
30
26
  kind,
31
27
  name
32
28
  };
33
29
  switch (kind) {
34
- case index_js_1.OpraSchema.ComplexType.Kind:
35
- Object.setPrototypeOf(dataType, complex_type_js_1.ComplexType.prototype);
30
+ case OpraSchema.ComplexType.Kind:
31
+ Object.setPrototypeOf(dataType, ComplexType.prototype);
36
32
  break;
37
- case index_js_1.OpraSchema.EnumType.Kind:
38
- Object.setPrototypeOf(dataType, enum_type_js_1.EnumType.prototype);
33
+ case OpraSchema.EnumType.Kind:
34
+ Object.setPrototypeOf(dataType, EnumType.prototype);
39
35
  break;
40
- case index_js_1.OpraSchema.MappedType.Kind:
41
- Object.setPrototypeOf(dataType, mapped_type_js_1.MappedType.prototype);
36
+ case OpraSchema.MappedType.Kind:
37
+ Object.setPrototypeOf(dataType, MappedType.prototype);
42
38
  break;
43
- case index_js_1.OpraSchema.SimpleType.Kind:
44
- Object.setPrototypeOf(dataType, simple_type_js_1.SimpleType.prototype);
39
+ case OpraSchema.SimpleType.Kind:
40
+ Object.setPrototypeOf(dataType, SimpleType.prototype);
45
41
  break;
46
- case index_js_1.OpraSchema.UnionType.Kind:
47
- Object.setPrototypeOf(dataType, union_type_js_1.UnionType.prototype);
42
+ case OpraSchema.UnionType.Kind:
43
+ Object.setPrototypeOf(dataType, UnionType.prototype);
48
44
  break;
49
45
  default:
50
46
  throw new TypeError(`Unknown DataType kind (${kind})`);
51
47
  }
52
48
  return dataType;
53
49
  }
54
- exports.createDataTypeInstance = createDataTypeInstance;
55
- function addDataType(schemaOrName) {
50
+ export function addDataType(schemaOrName) {
56
51
  const { document, typeQueue, circularRefs, curPath } = this;
57
52
  const name = typeof schemaOrName === 'string' ? schemaOrName : undefined;
58
53
  let schema;
@@ -74,13 +69,13 @@ function addDataType(schemaOrName) {
74
69
  try {
75
70
  // Init base
76
71
  let base;
77
- if ((index_js_1.OpraSchema.isSimpleType(schema) || index_js_1.OpraSchema.isComplexType(schema) || index_js_1.OpraSchema.isEnumType(schema)) && schema.base) {
72
+ if ((OpraSchema.isSimpleType(schema) || OpraSchema.isComplexType(schema) || OpraSchema.isEnumType(schema)) && schema.base) {
78
73
  curPath.push(typeof schema.base === 'string' ? schema.base : '[base]');
79
74
  base = this.addDataType(schema.base);
80
75
  curPath.pop();
81
76
  }
82
77
  // **** Init SimpleType ****
83
- if (index_js_1.OpraSchema.isSimpleType(schema)) {
78
+ if (OpraSchema.isSimpleType(schema)) {
84
79
  const initArgs = {
85
80
  ...schema,
86
81
  name,
@@ -89,13 +84,13 @@ function addDataType(schemaOrName) {
89
84
  dataType = dataType || this.createDataTypeInstance(schema.kind, name);
90
85
  if (name)
91
86
  curPath.push(name);
92
- simple_type_js_1.SimpleType.apply(dataType, [document, initArgs]);
87
+ SimpleType.apply(dataType, [document, initArgs]);
93
88
  if (name)
94
89
  curPath.pop();
95
90
  return dataType;
96
91
  }
97
92
  // **** Init ComplexType ****
98
- if (index_js_1.OpraSchema.isComplexType(schema)) {
93
+ if (OpraSchema.isComplexType(schema)) {
99
94
  const initArgs = {
100
95
  ...schema,
101
96
  name,
@@ -104,7 +99,7 @@ function addDataType(schemaOrName) {
104
99
  dataType = dataType || this.createDataTypeInstance(schema.kind, name);
105
100
  if (name)
106
101
  curPath.push(name);
107
- complex_type_js_1.ComplexType.apply(dataType, [document, initArgs]);
102
+ ComplexType.apply(dataType, [document, initArgs]);
108
103
  if (name)
109
104
  typeQueue.delete(name);
110
105
  // process fields
@@ -126,7 +121,7 @@ function addDataType(schemaOrName) {
126
121
  return dataType;
127
122
  }
128
123
  // **** Init EnumType ****
129
- if (index_js_1.OpraSchema.isEnumType(schema)) {
124
+ if (OpraSchema.isEnumType(schema)) {
130
125
  const initArgs = {
131
126
  ...schema,
132
127
  name,
@@ -135,13 +130,13 @@ function addDataType(schemaOrName) {
135
130
  dataType = dataType || this.createDataTypeInstance(schema.kind, name);
136
131
  if (name)
137
132
  curPath.push(name);
138
- enum_type_js_1.EnumType.apply(dataType, [document, initArgs]);
133
+ EnumType.apply(dataType, [document, initArgs]);
139
134
  if (name)
140
135
  curPath.pop();
141
136
  return dataType;
142
137
  }
143
138
  // **** Init UnionType ****
144
- if (index_js_1.OpraSchema.isUnionType(schema)) {
139
+ if (OpraSchema.isUnionType(schema)) {
145
140
  const unionTypes = schema.types.map(t => this.addDataType(t));
146
141
  const initArgs = {
147
142
  ...schema,
@@ -151,15 +146,15 @@ function addDataType(schemaOrName) {
151
146
  dataType = dataType || this.createDataTypeInstance(schema.kind, name);
152
147
  if (name)
153
148
  curPath.push(name);
154
- union_type_js_1.UnionType.apply(dataType, [document, initArgs]);
149
+ UnionType.apply(dataType, [document, initArgs]);
155
150
  if (name)
156
151
  curPath.pop();
157
152
  return dataType;
158
153
  }
159
154
  // **** Init MappedType ****
160
- if (index_js_1.OpraSchema.isMappedType(schema)) {
155
+ if (OpraSchema.isMappedType(schema)) {
161
156
  const dt = this.addDataType(schema.type);
162
- if (!(dt instanceof complex_type_js_1.ComplexType))
157
+ if (!(dt instanceof ComplexType))
163
158
  throw new TypeError(`MappedType requires a ComplexType`);
164
159
  const initArgs = {
165
160
  ...schema,
@@ -169,7 +164,7 @@ function addDataType(schemaOrName) {
169
164
  dataType = dataType || this.createDataTypeInstance(schema.kind, name);
170
165
  if (name)
171
166
  curPath.push(name);
172
- mapped_type_js_1.MappedType.apply(dataType, [document, initArgs]);
167
+ MappedType.apply(dataType, [document, initArgs]);
173
168
  if (name)
174
169
  curPath.pop();
175
170
  return dataType;
@@ -188,4 +183,3 @@ function addDataType(schemaOrName) {
188
183
  }
189
184
  throw new TypeError(`Invalid DataType schema: ${JSON.stringify(schema).substring(0, 20)}...`);
190
185
  }
191
- exports.addDataType = addDataType;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("reflect-metadata");
5
- tslib_1.__exportStar(require("./constants.js"), exports);
6
- tslib_1.__exportStar(require("./api-document.js"), exports);
7
- tslib_1.__exportStar(require("./factory/index.js"), exports);
8
- tslib_1.__exportStar(require("./data-type/data-type.js"), exports);
9
- tslib_1.__exportStar(require("./data-type/complex-type.js"), exports);
10
- tslib_1.__exportStar(require("./data-type/api-field.js"), exports);
11
- tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
12
- tslib_1.__exportStar(require("./data-type/mapped-type.js"), exports);
13
- tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
14
- tslib_1.__exportStar(require("./data-type/union-type.js"), exports);
15
- tslib_1.__exportStar(require("./resource/resource.js"), exports);
16
- tslib_1.__exportStar(require("./resource/collection.js"), exports);
17
- tslib_1.__exportStar(require("./resource/singleton.js"), exports);
1
+ import 'reflect-metadata';
2
+ export * from './constants.js';
3
+ export * from './api-document.js';
4
+ export * from './factory/index.js';
5
+ export * from './data-type/data-type.js';
6
+ export * from './data-type/complex-type.js';
7
+ export * from './data-type/api-field.js';
8
+ export * from './data-type/enum-type.js';
9
+ export * from './data-type/mapped-type.js';
10
+ export * from './data-type/simple-type.js';
11
+ export * from './data-type/union-type.js';
12
+ export * from './resource/resource.js';
13
+ export * from './resource/collection.js';
14
+ export * from './resource/singleton.js';
@@ -1,44 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Collection = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
- const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
7
- const index_js_1 = require("../../exception/index.js");
8
- const index_js_2 = require("../../filter/index.js");
9
- const index_js_3 = require("../../helpers/index.js");
10
- const index_js_4 = require("../../i18n/index.js");
11
- const index_js_5 = require("../../schema/index.js");
12
- const constants_js_1 = require("../constants.js");
13
- const simple_type_js_1 = require("../data-type/simple-type.js");
14
- const resource_js_1 = require("./resource.js");
1
+ import omit from 'lodash.omit';
2
+ import merge from 'putil-merge';
3
+ import { BadRequestError } from '../../exception/index.js';
4
+ import { ArithmeticExpression, ArrayExpression, ComparisonExpression, LogicalExpression, ParenthesesExpression, QualifiedIdentifier } from '../../filter/index.js';
5
+ import { omitUndefined } from '../../helpers/index.js';
6
+ import { translate } from '../../i18n/index.js';
7
+ import { OpraSchema } from '../../schema/index.js';
8
+ import { METADATA_KEY } from '../constants.js';
9
+ import { SimpleType } from '../data-type/simple-type.js';
10
+ import { Resource } from './resource.js';
15
11
  const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
16
12
  const NAME_PATTERN = /^(.*)(Resource|Collection)$/;
17
13
  /**
18
14
  *
19
15
  */
20
- exports.Collection = function (...args) {
16
+ export const Collection = function (...args) {
21
17
  // ClassDecorator
22
18
  if (!this) {
23
19
  const [type, options] = args;
24
20
  return function (target) {
25
21
  const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
26
- const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
27
- const baseMetadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, Object.getPrototypeOf(target));
22
+ const metadata = Reflect.getOwnMetadata(METADATA_KEY, target) || {};
23
+ const baseMetadata = Reflect.getOwnMetadata(METADATA_KEY, Object.getPrototypeOf(target));
28
24
  if (baseMetadata) {
29
- (0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
25
+ merge(metadata, baseMetadata, { deep: true });
30
26
  }
31
- metadata.kind = index_js_5.OpraSchema.Collection.Kind;
27
+ metadata.kind = OpraSchema.Collection.Kind;
32
28
  metadata.name = name;
33
29
  metadata.type = type;
34
30
  // Merge with previous metadata object
35
- const m = Reflect.getMetadata(constants_js_1.METADATA_KEY, target);
31
+ const m = Reflect.getMetadata(METADATA_KEY, target);
36
32
  if (m && metadata !== m)
37
- Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
33
+ Object.assign(metadata, omit(m), Object.keys(metadata));
38
34
  // Merge options
39
35
  if (options)
40
- Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
41
- Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
36
+ Object.assign(metadata, omit(options, ['kind', 'name', 'type', 'controller']));
37
+ Reflect.defineMetadata(METADATA_KEY, metadata, target);
42
38
  /* Define Injectable metadata for NestJS support*/
43
39
  Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
44
40
  };
@@ -46,14 +42,14 @@ exports.Collection = function (...args) {
46
42
  // Constructor
47
43
  const [document, init] = args;
48
44
  // call super()
49
- resource_js_1.Resource.apply(this, [document, init]);
45
+ Resource.apply(this, [document, init]);
50
46
  };
51
47
  const proto = {
52
48
  _construct(init) {
53
49
  // call super()
54
- resource_js_1.Resource.prototype._construct.call(this, init);
50
+ Resource.prototype._construct.call(this, init);
55
51
  const _this = this;
56
- _this.kind = index_js_5.OpraSchema.Collection.Kind;
52
+ _this.kind = OpraSchema.Collection.Kind;
57
53
  _this.controller = init.controller;
58
54
  const operations = _this.operations = init.operations || {};
59
55
  const dataType = _this.type = init.type;
@@ -64,9 +60,9 @@ const proto = {
64
60
  if (!_this.primaryKey.length)
65
61
  throw new TypeError(`You must provide primaryKey for Collection resource ("${_this.name}")`);
66
62
  _this.primaryKey.forEach(f => {
67
- const el = dataType.getField(f);
68
- if (!(el.type instanceof simple_type_js_1.SimpleType))
69
- throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${el.type.kind}`);
63
+ const field = dataType.getField(f);
64
+ if (!(field?.type instanceof SimpleType))
65
+ throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
70
66
  });
71
67
  if (_this.controller) {
72
68
  const instance = typeof _this.controller == 'function'
@@ -83,8 +79,8 @@ const proto = {
83
79
  }
84
80
  },
85
81
  exportSchema() {
86
- const out = resource_js_1.Resource.prototype.exportSchema.call(this);
87
- Object.assign(out, (0, index_js_3.omitUndefined)({
82
+ const out = Resource.prototype.exportSchema.call(this);
83
+ Object.assign(out, omitUndefined({
88
84
  type: this.type.name,
89
85
  operations: this.operations,
90
86
  primaryKey: this.primaryKey
@@ -122,64 +118,63 @@ const proto = {
122
118
  return result;
123
119
  }
124
120
  },
125
- normalizeFieldNames(fields) {
126
- return this.type.normalizeFieldNames(fields);
121
+ normalizeFieldPath(path) {
122
+ return this.type.normalizeFieldPath(path);
127
123
  },
128
124
  normalizeSortFields(fields) {
129
- const normalized = this.normalizeFieldNames(fields);
130
- if (!normalized)
131
- return;
125
+ const normalized = this.type.normalizeFieldPath(fields);
132
126
  const findManyEndpoint = this.operations.findMany;
133
127
  const sortFields = findManyEndpoint && findManyEndpoint.sortFields;
134
128
  normalized.forEach(field => {
135
129
  if (!sortFields?.find(x => x === field))
136
- throw new index_js_1.BadRequestError({
137
- message: (0, index_js_4.translate)('error:UNACCEPTED_SORT_FIELD', { field }, `Field '${field}' is not available for sort operation`),
130
+ throw new BadRequestError({
131
+ message: translate('error:UNACCEPTED_SORT_FIELD', { field }, `Field '${field}' is not available for sort operation`),
138
132
  });
139
133
  });
140
134
  return normalized;
141
135
  },
142
- normalizeFilterFields(ast) {
143
- if (ast instanceof index_js_2.ComparisonExpression) {
144
- this.normalizeFilterFields(ast.left);
136
+ normalizeFilter(ast) {
137
+ if (ast instanceof ComparisonExpression) {
138
+ this.normalizeFilter(ast.left);
145
139
  }
146
- else if (ast instanceof index_js_2.LogicalExpression) {
147
- ast.items.forEach(item => this.normalizeFilterFields(item));
140
+ else if (ast instanceof LogicalExpression) {
141
+ ast.items.forEach(item => this.normalizeFilter(item));
148
142
  }
149
- else if (ast instanceof index_js_2.ArithmeticExpression) {
150
- ast.items.forEach(item => this.normalizeFilterFields(item.expression));
143
+ else if (ast instanceof ArithmeticExpression) {
144
+ ast.items.forEach(item => this.normalizeFilter(item.expression));
151
145
  }
152
- else if (ast instanceof index_js_2.ArrayExpression) {
153
- ast.items.forEach(item => this.normalizeFilterFields(item));
146
+ else if (ast instanceof ArrayExpression) {
147
+ ast.items.forEach(item => this.normalizeFilter(item));
154
148
  }
155
- else if (ast instanceof index_js_2.ParenthesesExpression) {
156
- this.normalizeFilterFields(ast.expression);
149
+ else if (ast instanceof ParenthesesExpression) {
150
+ this.normalizeFilter(ast.expression);
157
151
  }
158
- else if (ast instanceof index_js_2.QualifiedIdentifier) {
159
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
160
- ast.value = this.normalizeFieldNames([ast.value])[0];
152
+ else if (ast instanceof QualifiedIdentifier) {
153
+ ast.field = this.type.findField(ast.value);
154
+ ast.dataType = ast.field?.type || this.document.getDataType('any');
155
+ ast.value = this.type.normalizeFieldPath(ast.value);
161
156
  }
162
157
  return ast;
163
158
  }
164
159
  };
165
- Object.assign(exports.Collection.prototype, proto);
166
- Object.setPrototypeOf(exports.Collection.prototype, resource_js_1.Resource.prototype);
160
+ Object.assign(Collection.prototype, proto);
161
+ Object.setPrototypeOf(Collection.prototype, Resource.prototype);
167
162
  function createOperationDecorator(operation) {
168
163
  return (options) => ((target, propertyKey) => {
169
164
  const metadata = {
170
165
  ...options,
171
166
  handlerName: propertyKey
172
167
  };
173
- const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target.constructor) || {});
168
+ const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
174
169
  resourceMetadata.operations = resourceMetadata.operations || {};
175
170
  resourceMetadata.operations[operation] = metadata;
176
- Reflect.defineMetadata(constants_js_1.METADATA_KEY, resourceMetadata, target.constructor);
171
+ Reflect.defineMetadata(METADATA_KEY, resourceMetadata, target.constructor);
177
172
  });
178
173
  }
179
- exports.Collection.Create = createOperationDecorator('create');
180
- exports.Collection.Delete = createOperationDecorator('delete');
181
- exports.Collection.DeleteMany = createOperationDecorator('deleteMany');
182
- exports.Collection.Get = createOperationDecorator('get');
183
- exports.Collection.FindMany = createOperationDecorator('findMany');
184
- exports.Collection.Update = createOperationDecorator('update');
185
- exports.Collection.UpdateMany = createOperationDecorator('updateMany');
174
+ Collection.Create = createOperationDecorator('create');
175
+ Collection.Delete = createOperationDecorator('delete');
176
+ Collection.DeleteMany = createOperationDecorator('deleteMany');
177
+ Collection.Get = createOperationDecorator('get');
178
+ Collection.FindMany = createOperationDecorator('findMany');
179
+ Collection.Update = createOperationDecorator('update');
180
+ Collection.UpdateMany = createOperationDecorator('updateMany');
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Resource = void 0;
4
- const object_utils_js_1 = require("../../helpers/object-utils.js");
5
- const inspect_util_js_1 = require("../utils/inspect.util.js");
6
- exports.Resource = function (document, init) {
7
- if (!(this instanceof exports.Resource)) {
1
+ import { omitUndefined } from '../../helpers/object-utils.js';
2
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
3
+ export const Resource = function (document, init) {
4
+ if (!(this instanceof Resource)) {
8
5
  throw new TypeError(`Class constructor must be called with "new" keyword`);
9
6
  // noinspection UnreachableCodeJS
10
7
  return;
@@ -22,7 +19,7 @@ const proto = {
22
19
  // Do nothing
23
20
  },
24
21
  exportSchema() {
25
- return (0, object_utils_js_1.omitUndefined)({
22
+ return omitUndefined({
26
23
  kind: this.kind,
27
24
  description: this.description
28
25
  });
@@ -30,9 +27,9 @@ const proto = {
30
27
  toString() {
31
28
  return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || '#anonymous'}]`;
32
29
  },
33
- [inspect_util_js_1.nodeInspectCustom]() {
34
- return `[${inspect_util_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + inspect_util_js_1.colorReset}` +
35
- ` ${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
30
+ [nodeInspectCustom]() {
31
+ return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset}` +
32
+ ` ${colorFgMagenta + this.name + colorReset}]`;
36
33
  }
37
34
  };
38
- Object.assign(exports.Resource.prototype, proto);
35
+ Object.assign(Resource.prototype, proto);