@opra/common 0.26.5 → 0.27.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.
Files changed (42) hide show
  1. package/browser.js +297 -206
  2. package/cjs/document/data-type/complex-type-class.js +23 -5
  3. package/cjs/document/data-type/enum-type-class.js +4 -0
  4. package/cjs/document/factory/type-document-factory.js +19 -21
  5. package/cjs/document/index.js +7 -4
  6. package/cjs/document/resource/action.js +10 -0
  7. package/cjs/document/resource/collection-class.js +31 -25
  8. package/cjs/document/resource/endpoint.js +4 -8
  9. package/cjs/document/resource/enums/metadata-mode.enum.js +19 -0
  10. package/cjs/document/resource/operation.js +5 -0
  11. package/cjs/document/resource/resource.js +7 -4
  12. package/cjs/document/resource/singleton-class.js +16 -16
  13. package/cjs/document/resource/types/operation-result.type.js +44 -0
  14. package/cjs/document/type-document.js +61 -52
  15. package/cjs/helpers/object-utils.js +2 -2
  16. package/esm/document/data-type/complex-type-class.js +23 -5
  17. package/esm/document/data-type/enum-type-class.js +4 -0
  18. package/esm/document/factory/type-document-factory.js +19 -21
  19. package/esm/document/index.js +7 -4
  20. package/esm/document/resource/action.js +9 -0
  21. package/esm/document/resource/collection-class.js +31 -25
  22. package/esm/document/resource/endpoint.js +4 -7
  23. package/esm/document/resource/enums/metadata-mode.enum.js +16 -0
  24. package/esm/document/resource/operation.js +5 -0
  25. package/esm/document/resource/resource.js +7 -4
  26. package/esm/document/resource/singleton-class.js +16 -16
  27. package/esm/document/resource/types/operation-result.type.js +41 -0
  28. package/esm/document/type-document.js +61 -52
  29. package/esm/helpers/object-utils.js +2 -2
  30. package/package.json +7 -7
  31. package/types/document/data-type/complex-type-class.d.ts +1 -0
  32. package/types/document/data-type/enum-type-class.d.ts +1 -0
  33. package/types/document/data-type/enum-type.d.ts +2 -2
  34. package/types/document/index.d.ts +7 -4
  35. package/types/document/resource/action.d.ts +6 -1
  36. package/types/document/resource/endpoint.d.ts +2 -6
  37. package/types/document/resource/enums/metadata-mode.enum.d.ts +5 -0
  38. package/types/document/resource/operation.d.ts +4 -0
  39. package/types/document/resource/resource.d.ts +1 -1
  40. package/types/document/resource/types/operation-result.type.d.ts +14 -0
  41. package/types/document/type-document.d.ts +14 -3
  42. package/types/schema/resource/action.interface.d.ts +1 -0
package/browser.js CHANGED
@@ -144,8 +144,7 @@ import isPlainObject from "putil-isplainobject";
144
144
  import merge from "putil-merge";
145
145
  function cloneObject(obj, jsonOnly) {
146
146
  return merge({}, obj, {
147
- deep: true,
148
- clone: true,
147
+ deep: (v) => isPlainObject(v) && !v[DATATYPE_METADATA],
149
148
  filter: (source, key) => {
150
149
  const v = source[key];
151
150
  return v != null && !jsonOnly || typeof v !== "function" && (typeof v !== "object" || isPlainObject(v) || Array.isArray(v));
@@ -1023,7 +1022,7 @@ var colorReset = "\x1B[0m";
1023
1022
  var colorFgYellow = "\x1B[33m";
1024
1023
  var colorFgMagenta = "\x1B[35m";
1025
1024
 
1026
- // ../../build/common/esm/document/resource/endpoint.js
1025
+ // ../../build/common/esm/document/resource/action.js
1027
1026
  import * as vg2 from "valgen";
1028
1027
 
1029
1028
  // ../../build/common/esm/document/data-type/data-type.js
@@ -1117,7 +1116,6 @@ var Endpoint = class {
1117
1116
  constructor(resource, name, init) {
1118
1117
  this.resource = resource;
1119
1118
  this.name = name;
1120
- this.encodeReturning = vg2.isAny();
1121
1119
  Object.assign(this, init);
1122
1120
  this.parameters = new ResponsiveMap();
1123
1121
  if (init.parameters) {
@@ -1125,10 +1123,9 @@ var Endpoint = class {
1125
1123
  this.defineParameter(n, p);
1126
1124
  }
1127
1125
  }
1128
- if (init.returnType) {
1129
- this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType);
1130
- this.encodeReturning = this.returnType.generateCodec("encode");
1131
- }
1126
+ }
1127
+ getFullPath(documentPath) {
1128
+ return this.resource.getFullPath(documentPath) + (this.kind === "action" ? (documentPath ? "/actions/" : "/") + this.name : "");
1132
1129
  }
1133
1130
  defineParameter(name, init) {
1134
1131
  const type = init.type && init.type instanceof DataType ? init.type : this.resource.document.getDataType(init.type || "any");
@@ -1164,11 +1161,17 @@ var Action = class extends Endpoint {
1164
1161
  this.resource = resource;
1165
1162
  this.name = name;
1166
1163
  this.kind = "action";
1164
+ this.encodeReturning = vg2.isAny();
1165
+ if (init.returnType)
1166
+ this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType);
1167
+ this.returnMime = init.returnMime;
1167
1168
  }
1168
1169
  exportSchema(options) {
1169
1170
  const schema = super.exportSchema(options);
1170
1171
  if (this.returnType)
1171
1172
  schema.returnType = this.returnType.name ? this.returnType.name : this.returnType.exportSchema(options);
1173
+ if (this.returnMime)
1174
+ schema.returnMime = this.returnMime;
1172
1175
  return schema;
1173
1176
  }
1174
1177
  };
@@ -1198,10 +1201,13 @@ var Resource = class _Resource {
1198
1201
  }
1199
1202
  }
1200
1203
  }
1201
- getFullPath() {
1202
- if (this.parent && this.parent.name)
1203
- return this.parent?.getFullPath() + "/" + this.name;
1204
- return this.name;
1204
+ getFullPath(documentPath) {
1205
+ if (this === this.document.root)
1206
+ return documentPath ? "/root" : "/";
1207
+ let out = this.parent?.getFullPath(documentPath);
1208
+ if (!out?.endsWith("/"))
1209
+ out += "/";
1210
+ return out + (documentPath ? "resources/" : "") + this.name;
1205
1211
  }
1206
1212
  exportSchema(options) {
1207
1213
  const schema = omitUndefined({
@@ -1653,10 +1659,7 @@ var ComplexTypeClass = class extends DataType {
1653
1659
  return false;
1654
1660
  }
1655
1661
  generateCodec(codec, options) {
1656
- const schema = {};
1657
- for (const f of this.fields.values()) {
1658
- schema[f.name] = f.generateCodec(codec, options);
1659
- }
1662
+ const schema = this._generateCodecSchema(codec, options);
1660
1663
  return vg4.isObject(schema, {
1661
1664
  ctor: this.ctor,
1662
1665
  additionalFields: this.additionalFields ?? false,
@@ -1664,6 +1667,24 @@ var ComplexTypeClass = class extends DataType {
1664
1667
  caseInSensitive: !options?.caseSensitive
1665
1668
  });
1666
1669
  }
1670
+ _generateCodecSchema(codec, options) {
1671
+ const schema = {};
1672
+ const pickOption = (options?.pick || []).map((x) => x.toLowerCase());
1673
+ const omitOption = (options?.omit || []).map((x) => x.toLowerCase());
1674
+ for (const f of this.fields.values()) {
1675
+ const nameLower = f.name.toLowerCase();
1676
+ if (omitOption.find((x) => x === nameLower))
1677
+ continue;
1678
+ if (pickOption.length && !pickOption.find((x) => x === nameLower || x.startsWith(nameLower + ".")))
1679
+ continue;
1680
+ schema[f.name] = f.generateCodec(codec, {
1681
+ ...options,
1682
+ pick: pickOption.filter((x) => x.startsWith(nameLower + ".")).map((x) => x.substring(x.indexOf(".") + 1)),
1683
+ omit: omitOption.filter((x) => x.startsWith(nameLower + ".")).map((x) => x.substring(x.indexOf(".") + 1))
1684
+ });
1685
+ }
1686
+ return schema;
1687
+ }
1667
1688
  };
1668
1689
 
1669
1690
  // ../../build/common/esm/document/data-type/complex-type.js
@@ -1679,6 +1700,83 @@ ComplexType2.prototype = ComplexTypeClass.prototype;
1679
1700
  Object.assign(ComplexType2, ComplexTypeDecorator);
1680
1701
  ComplexType2[DECORATOR] = ComplexTypeDecorator;
1681
1702
 
1703
+ // ../../build/common/esm/document/data-type/enum-type.js
1704
+ import "reflect-metadata";
1705
+ import merge6 from "putil-merge";
1706
+
1707
+ // ../../build/common/esm/document/data-type/enum-type-class.js
1708
+ import * as vg5 from "valgen";
1709
+ var EnumTypeClass = class extends DataType {
1710
+ static {
1711
+ __name(this, "EnumTypeClass");
1712
+ }
1713
+ constructor(document, init) {
1714
+ super(document, init);
1715
+ this.kind = opra_schema_ns_exports.EnumType.Kind;
1716
+ this.enumObject = init.enumObject;
1717
+ this.base = init.base;
1718
+ this.ownValues = { ...init.values };
1719
+ this.values = { ...this.base?.values, ...this.ownValues };
1720
+ this.decode = vg5.isEnum(Object.keys(this.values));
1721
+ this.encode = vg5.isEnum(Object.keys(this.values));
1722
+ }
1723
+ isTypeOf(t) {
1724
+ return t[DATATYPE_METADATA] === this.enumObject?.[DATATYPE_METADATA];
1725
+ }
1726
+ exportSchema() {
1727
+ const out = super.exportSchema();
1728
+ out.values = {};
1729
+ Object.entries(this.values).forEach(([k, i]) => {
1730
+ out.values[k] = omitUndefined({ key: i.key, description: i.description });
1731
+ });
1732
+ return out;
1733
+ }
1734
+ generateCodec(codec) {
1735
+ if (codec === "encode")
1736
+ return this.encode;
1737
+ else
1738
+ return this.decode;
1739
+ }
1740
+ };
1741
+
1742
+ // ../../build/common/esm/document/data-type/enum-type.js
1743
+ var EnumType2 = /* @__PURE__ */ __name(function(...args) {
1744
+ if (!this) {
1745
+ const [enumSource, options] = args;
1746
+ let values = {};
1747
+ if (Array.isArray(enumSource)) {
1748
+ values = {};
1749
+ enumSource.forEach((k) => {
1750
+ const description = options?.meanings?.[k];
1751
+ values[k] = omitUndefined({ description });
1752
+ });
1753
+ } else {
1754
+ Object.keys(enumSource).forEach((k) => {
1755
+ const description = options?.meanings?.[k];
1756
+ values[enumSource[k]] = omitUndefined({ key: k, description });
1757
+ });
1758
+ }
1759
+ const metadata = {
1760
+ kind: opra_schema_ns_exports.EnumType.Kind,
1761
+ values,
1762
+ base: options?.base,
1763
+ name: options?.name,
1764
+ description: options?.description
1765
+ };
1766
+ Object.defineProperty(enumSource, DATATYPE_METADATA, {
1767
+ value: metadata,
1768
+ enumerable: false,
1769
+ configurable: true,
1770
+ writable: true
1771
+ });
1772
+ return metadata;
1773
+ }
1774
+ const [document, init] = args;
1775
+ merge6(this, new EnumTypeClass(document, init), { descriptor: true });
1776
+ return;
1777
+ }, "EnumType");
1778
+ EnumType2.prototype = EnumTypeClass.prototype;
1779
+
1682
1780
  // ../../build/common/esm/document/document-base.js
1683
1781
  var DocumentBase = class {
1684
1782
  static {
@@ -1710,8 +1808,8 @@ var TypeDocument = class extends DocumentBase {
1710
1808
  constructor() {
1711
1809
  super();
1712
1810
  this._designCtorMap = /* @__PURE__ */ new Map();
1713
- this._typeCache = new ResponsiveMap();
1714
- this._typesCacheByCtor = /* @__PURE__ */ new Map();
1811
+ this._typeIndex = /* @__PURE__ */ new Map();
1812
+ this._typeNsMap = /* @__PURE__ */ new Map();
1715
1813
  this.references = new ResponsiveMap();
1716
1814
  this.types = new ResponsiveMap();
1717
1815
  const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
@@ -1735,30 +1833,37 @@ var TypeDocument = class extends DocumentBase {
1735
1833
  if (x)
1736
1834
  arg0 = x;
1737
1835
  }
1738
- let dataType;
1739
- let name;
1740
- if (typeof arg0 === "function") {
1741
- const metadata = Reflect.getMetadata(DATATYPE_METADATA, arg0);
1742
- name = metadata?.name || arg0.name;
1743
- } else if (typeof arg0 === "function") {
1744
- const metadata = Reflect.getMetadata(DATATYPE_METADATA, arg0);
1745
- name = metadata?.name;
1746
- } else
1747
- name = String(arg0);
1748
- const t = typeof arg0 === "string" ? this._typeCache.get(arg0) : this._typesCacheByCtor.get(arg0);
1836
+ const t = typeof arg0 === "string" ? this._typeIndex.get(arg0.toLowerCase()) : this._typeIndex.get(arg0);
1749
1837
  if (t)
1750
1838
  return t;
1839
+ let name;
1840
+ if (typeof arg0 === "string")
1841
+ name = arg0;
1842
+ else if (arg0 instanceof DataType)
1843
+ name = arg0.name || "";
1844
+ else {
1845
+ const metadata = typeof arg0 === "function" ? Reflect.getMetadata(DATATYPE_METADATA, arg0) : arg0?.[DATATYPE_METADATA];
1846
+ if (!metadata) {
1847
+ if (!silent)
1848
+ throw new TypeError("Invalid argument");
1849
+ return;
1850
+ }
1851
+ name = metadata.name;
1852
+ }
1751
1853
  if (t === null) {
1752
1854
  if (silent)
1753
1855
  return;
1754
1856
  throw new Error(`Data type "${name}" does not exists`);
1755
1857
  }
1858
+ let dataType;
1859
+ let ns = "";
1756
1860
  if (typeof arg0 === "string" && arg0) {
1757
1861
  const m = NAMESPACE_PATTERN.exec(arg0);
1758
1862
  if (!m)
1759
1863
  throw new TypeError(`Invalid data type name "${name}"`);
1760
1864
  if (m[2]) {
1761
- const ref = this.references.get(m[1]);
1865
+ ns = m[1];
1866
+ const ref = this.references.get(ns);
1762
1867
  if (!ref) {
1763
1868
  if (silent)
1764
1869
  return;
@@ -1768,59 +1873,57 @@ var TypeDocument = class extends DocumentBase {
1768
1873
  } else {
1769
1874
  dataType = this.types.get(arg0);
1770
1875
  if (!dataType) {
1771
- const references = Array.from(this.references.values()).reverse();
1772
- for (const ref of references) {
1876
+ const references = Array.from(this.references.keys()).reverse();
1877
+ for (const refNs of references) {
1878
+ const ref = this.references.get(refNs);
1773
1879
  dataType = ref.getDataType(name, true);
1774
- if (dataType)
1880
+ if (dataType) {
1881
+ ns = refNs;
1775
1882
  break;
1883
+ }
1776
1884
  }
1777
1885
  }
1778
1886
  }
1779
- if (dataType) {
1780
- this._typeCache.set(arg0, dataType);
1781
- return dataType;
1782
- }
1783
- if (!silent)
1784
- throw new NotFoundError(`Data type "${arg0}" does not exists`);
1785
- return;
1786
- }
1787
- if (typeof arg0 === "function") {
1887
+ } else {
1788
1888
  const types = Array.from(this.types.values()).reverse();
1789
1889
  for (const dt of types) {
1790
- if (dt instanceof ComplexType2 && dt.isTypeOf(arg0)) {
1890
+ if (dt === arg0 || (dt instanceof ComplexType2 || dt instanceof EnumType2) && dt.isTypeOf(arg0)) {
1791
1891
  dataType = dt;
1792
1892
  break;
1793
1893
  }
1794
1894
  }
1795
1895
  if (!dataType) {
1796
- const references = Array.from(this.references.values()).reverse();
1797
- for (const ref of references) {
1896
+ const references = Array.from(this.references.keys()).reverse();
1897
+ for (const refNs of references) {
1898
+ const ref = this.references.get(refNs);
1798
1899
  dataType = ref.getDataType(arg0, true);
1799
- if (dataType)
1900
+ if (dataType) {
1901
+ ns = refNs;
1800
1902
  break;
1903
+ }
1801
1904
  }
1802
1905
  }
1803
- if (dataType)
1804
- this._typesCacheByCtor.set(arg0, dataType);
1805
- if (dataType)
1806
- return dataType;
1807
- if (!silent)
1808
- throw new Error(`No data type mapping found for class "${name}"`);
1809
- return;
1810
1906
  }
1811
- if (typeof arg0 === "object") {
1812
- const metadata = arg0[DATATYPE_METADATA];
1813
- if (metadata && metadata.name) {
1814
- dataType = this.getDataType(metadata.name, true);
1815
- if (dataType)
1816
- return dataType;
1817
- if (!silent)
1818
- throw new Error(`No data type mapping found for class "${name}"`);
1819
- }
1907
+ if (dataType) {
1908
+ this._typeIndex.set(arg0, dataType);
1909
+ if (ns)
1910
+ this._typeNsMap.set(dataType, ns);
1911
+ return dataType;
1820
1912
  }
1913
+ if (!silent)
1914
+ throw new NotFoundError(`Data type "${name}" does not exists`);
1915
+ return;
1821
1916
  if (!silent)
1822
1917
  throw new TypeError("Invalid argument");
1823
1918
  }
1919
+ /**
1920
+ *
1921
+ */
1922
+ getDataTypeNs(arg0, silent) {
1923
+ const dt = this.getDataType(arg0, silent);
1924
+ if (dt)
1925
+ return this._typeNsMap.get(dt);
1926
+ }
1824
1927
  getComplexType(nameOrCtor, silent) {
1825
1928
  if (nameOrCtor === Object)
1826
1929
  nameOrCtor = "object";
@@ -1873,8 +1976,8 @@ var TypeDocument = class extends DocumentBase {
1873
1976
  return schema;
1874
1977
  }
1875
1978
  invalidate() {
1876
- this._typeCache.clear();
1877
- this._typesCacheByCtor.clear();
1979
+ this._typeIndex.clear();
1980
+ this._typeNsMap.clear();
1878
1981
  }
1879
1982
  };
1880
1983
 
@@ -1931,7 +2034,7 @@ __name(__decorate, "__decorate");
1931
2034
 
1932
2035
  // ../../build/common/esm/document/data-type/simple-type.js
1933
2036
  import "reflect-metadata";
1934
- import merge6 from "putil-merge";
2037
+ import merge7 from "putil-merge";
1935
2038
 
1936
2039
  // ../../build/common/esm/document/data-type/simple-type.decorator.js
1937
2040
  import omit3 from "lodash.omit";
@@ -1950,7 +2053,7 @@ function SimpleTypeDecorator(options) {
1950
2053
  __name(SimpleTypeDecorator, "SimpleTypeDecorator");
1951
2054
 
1952
2055
  // ../../build/common/esm/document/data-type/simple-type-class.js
1953
- import * as vg5 from "valgen";
2056
+ import * as vg6 from "valgen";
1954
2057
  var SimpleTypeClass = class extends DataType {
1955
2058
  static {
1956
2059
  __name(this, "SimpleTypeClass");
@@ -1959,8 +2062,8 @@ var SimpleTypeClass = class extends DataType {
1959
2062
  super(document, init);
1960
2063
  this.kind = opra_schema_ns_exports.SimpleType.Kind;
1961
2064
  this.base = init.base;
1962
- this.decode = init.decoder || init.base?.decode || vg5.isAny();
1963
- this.encode = init.encoder || init.base?.encode || vg5.isAny();
2065
+ this.decode = init.decoder || init.base?.decode || vg6.isAny();
2066
+ this.encode = init.encoder || init.base?.encode || vg6.isAny();
1964
2067
  }
1965
2068
  exportSchema(options) {
1966
2069
  const out = super.exportSchema(options);
@@ -1986,7 +2089,7 @@ var SimpleType2 = /* @__PURE__ */ __name(function(...args) {
1986
2089
  return SimpleType2[DECORATOR](options);
1987
2090
  }
1988
2091
  const [document, init] = args;
1989
- merge6(this, new SimpleTypeClass(document, init), { descriptor: true });
2092
+ merge7(this, new SimpleTypeClass(document, init), { descriptor: true });
1990
2093
  }, "SimpleType");
1991
2094
  SimpleType2.prototype = SimpleTypeClass.prototype;
1992
2095
  Object.assign(SimpleType2, SimpleTypeDecorator);
@@ -2216,80 +2319,6 @@ TimestampType = __decorate([
2216
2319
  })
2217
2320
  ], TimestampType);
2218
2321
 
2219
- // ../../build/common/esm/document/data-type/enum-type.js
2220
- import "reflect-metadata";
2221
- import merge7 from "putil-merge";
2222
-
2223
- // ../../build/common/esm/document/data-type/enum-type-class.js
2224
- import * as vg6 from "valgen";
2225
- var EnumTypeClass = class extends DataType {
2226
- static {
2227
- __name(this, "EnumTypeClass");
2228
- }
2229
- constructor(document, init) {
2230
- super(document, init);
2231
- this.kind = opra_schema_ns_exports.EnumType.Kind;
2232
- this.enumObject = init.enumObject;
2233
- this.base = init.base;
2234
- this.ownValues = { ...init.values };
2235
- this.values = { ...this.base?.values, ...this.ownValues };
2236
- this.decode = vg6.isEnum(Object.keys(this.values));
2237
- this.encode = vg6.isEnum(Object.keys(this.values));
2238
- }
2239
- exportSchema() {
2240
- const out = super.exportSchema();
2241
- out.values = {};
2242
- Object.entries(this.values).forEach(([k, i]) => {
2243
- out.values[k] = omitUndefined({ key: i.key, description: i.description });
2244
- });
2245
- return out;
2246
- }
2247
- generateCodec(codec) {
2248
- if (codec === "encode")
2249
- return this.encode;
2250
- else
2251
- return this.decode;
2252
- }
2253
- };
2254
-
2255
- // ../../build/common/esm/document/data-type/enum-type.js
2256
- var EnumType2 = /* @__PURE__ */ __name(function(...args) {
2257
- if (!this) {
2258
- const [enumSource, options] = args;
2259
- let values = {};
2260
- if (Array.isArray(enumSource)) {
2261
- values = {};
2262
- enumSource.forEach((k) => {
2263
- const description = options?.meanings?.[k];
2264
- values[k] = omitUndefined({ description });
2265
- });
2266
- } else {
2267
- Object.keys(enumSource).forEach((k) => {
2268
- const description = options?.meanings?.[k];
2269
- values[enumSource[k]] = omitUndefined({ key: k, description });
2270
- });
2271
- }
2272
- const metadata = {
2273
- kind: opra_schema_ns_exports.EnumType.Kind,
2274
- values,
2275
- base: options?.base,
2276
- name: options?.name,
2277
- description: options?.description
2278
- };
2279
- Object.defineProperty(enumSource, DATATYPE_METADATA, {
2280
- value: metadata,
2281
- enumerable: false,
2282
- configurable: true,
2283
- writable: true
2284
- });
2285
- return metadata;
2286
- }
2287
- const [document, init] = args;
2288
- merge7(this, new EnumTypeClass(document, init), { descriptor: true });
2289
- return;
2290
- }, "EnumType");
2291
- EnumType2.prototype = EnumTypeClass.prototype;
2292
-
2293
2322
  // ../../build/common/esm/document/data-type/mapped-type.js
2294
2323
  import "reflect-metadata";
2295
2324
  import merge8 from "putil-merge";
@@ -2461,6 +2490,66 @@ var UnionType2 = /* @__PURE__ */ __name(function(...args) {
2461
2490
  UnionType2.prototype = UnionTypeClass.prototype;
2462
2491
  UnionType2._applyMixin = () => void 0;
2463
2492
 
2493
+ // ../../build/common/esm/document/resource/enums/metadata-mode.enum.js
2494
+ var MetadataMode;
2495
+ (function(MetadataMode2) {
2496
+ MetadataMode2["none"] = "none";
2497
+ MetadataMode2["minimal"] = "minimal";
2498
+ MetadataMode2["full"] = "full";
2499
+ })(MetadataMode || (MetadataMode = {}));
2500
+ EnumType2(MetadataMode, {
2501
+ name: "MetadataMode",
2502
+ description: 'Parameter "enumeration" that controls how metadata information sent',
2503
+ meanings: {
2504
+ "none": "Specifies that the service will include NO metadata information in the response",
2505
+ "minimal": "Specifies that the service will include ALL metadata information in the response",
2506
+ "full": "Specifies that the service will include MINIMAL metadata information in the response"
2507
+ }
2508
+ });
2509
+
2510
+ // ../../build/common/esm/document/resource/types/operation-result.type.js
2511
+ var OperationResult = class OperationResult2 {
2512
+ static {
2513
+ __name(this, "OperationResult");
2514
+ }
2515
+ constructor(init) {
2516
+ if (init)
2517
+ Object.assign(this, init);
2518
+ }
2519
+ };
2520
+ __decorate([
2521
+ ApiField()
2522
+ ], OperationResult.prototype, "context", void 0);
2523
+ __decorate([
2524
+ ApiField()
2525
+ ], OperationResult.prototype, "contextUrl", void 0);
2526
+ __decorate([
2527
+ ApiField()
2528
+ ], OperationResult.prototype, "type", void 0);
2529
+ __decorate([
2530
+ ApiField()
2531
+ ], OperationResult.prototype, "typeUrl", void 0);
2532
+ __decorate([
2533
+ ApiField()
2534
+ ], OperationResult.prototype, "affected", void 0);
2535
+ __decorate([
2536
+ ApiField()
2537
+ ], OperationResult.prototype, "count", void 0);
2538
+ __decorate([
2539
+ ApiField()
2540
+ ], OperationResult.prototype, "totalMatches", void 0);
2541
+ __decorate([
2542
+ ApiField({ type: "any" })
2543
+ ], OperationResult.prototype, "payload", void 0);
2544
+ __decorate([
2545
+ ApiField({ type: "object" })
2546
+ ], OperationResult.prototype, "errors", void 0);
2547
+ OperationResult = __decorate([
2548
+ ComplexType2({
2549
+ description: "Operation result"
2550
+ })
2551
+ ], OperationResult);
2552
+
2464
2553
  // ../../build/common/esm/document/factory/type-document-factory.js
2465
2554
  var TypeDocumentFactory = class _TypeDocumentFactory {
2466
2555
  static {
@@ -2496,7 +2585,7 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2496
2585
  Object.assign(this.document.info, init.info);
2497
2586
  if (!init?.noBuiltinTypes) {
2498
2587
  const builtinDocument = await this.createBuiltinTypeDocument();
2499
- this.document.references.set("Opra", builtinDocument);
2588
+ this.document.references.set("opra", builtinDocument);
2500
2589
  }
2501
2590
  if (init.references)
2502
2591
  await this.addReferences(init.references);
@@ -2533,14 +2622,10 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2533
2622
  async createBuiltinTypeDocument() {
2534
2623
  const init = {
2535
2624
  version: opra_schema_ns_exports.SpecVersion,
2625
+ url: "https://oprajs.com/spec/v1.0",
2536
2626
  info: {
2537
2627
  version: opra_schema_ns_exports.SpecVersion,
2538
2628
  title: "Opra built-in types",
2539
- contact: [
2540
- {
2541
- url: "https://github.com/oprajs/opra"
2542
- }
2543
- ],
2544
2629
  license: {
2545
2630
  url: "https://github.com/oprajs/opra/blob/main/LICENSE",
2546
2631
  name: "MIT"
@@ -2560,7 +2645,9 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2560
2645
  ObjectIdType,
2561
2646
  StringType,
2562
2647
  TimeType,
2563
- TimestampType
2648
+ TimestampType,
2649
+ OperationResult,
2650
+ MetadataMode
2564
2651
  ]
2565
2652
  };
2566
2653
  const factory = new _TypeDocumentFactory();
@@ -2583,12 +2670,13 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2583
2670
  async importDataType(thunk) {
2584
2671
  thunk = await resolveThunk(thunk);
2585
2672
  let name = "";
2586
- let schema;
2587
2673
  let ctor;
2588
2674
  if (typeof thunk === "string") {
2589
2675
  name = thunk;
2590
- schema = this.typeQueue.get(name);
2591
- } else if (typeof thunk === "function") {
2676
+ thunk = this.typeQueue.get(name);
2677
+ }
2678
+ let initArguments;
2679
+ if (typeof thunk === "function") {
2592
2680
  const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk);
2593
2681
  if (!metadata) {
2594
2682
  const dataType = this.document.getDataType(thunk, true);
@@ -2597,25 +2685,23 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2597
2685
  throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
2598
2686
  }
2599
2687
  name = metadata.name;
2600
- schema = metadata;
2688
+ initArguments = cloneObject(metadata);
2601
2689
  ctor = thunk;
2602
2690
  } else if (typeof thunk === "object") {
2603
2691
  if (opra_schema_ns_exports.isDataType(thunk)) {
2604
2692
  name = thunk.name;
2605
2693
  ctor = thunk.ctor || ctor;
2606
- schema = thunk;
2694
+ initArguments = cloneObject(thunk);
2607
2695
  } else {
2608
2696
  const metadata = thunk[DATATYPE_METADATA];
2609
2697
  if (!metadata)
2610
2698
  throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
2611
2699
  name = metadata.name;
2612
- const dataType = this.document.getDataType(name, true);
2613
- if (dataType)
2614
- return dataType;
2615
- schema = cloneObject(metadata);
2700
+ initArguments = cloneObject(metadata);
2701
+ initArguments.enumObject = thunk;
2616
2702
  }
2617
2703
  }
2618
- ctor = ctor ?? (schema && isConstructor(schema.ctor) ? schema.ctor : void 0);
2704
+ ctor = ctor ?? (initArguments && isConstructor(initArguments.ctor) ? initArguments.ctor : void 0);
2619
2705
  if (name) {
2620
2706
  if (this.circularRefs.has(name.toLowerCase()))
2621
2707
  throw new TypeError("Circular reference detected");
@@ -2634,12 +2720,11 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2634
2720
  this.circularRefs.set(ctor, 1);
2635
2721
  }
2636
2722
  try {
2637
- if (!opra_schema_ns_exports.isDataType(schema))
2723
+ if (!initArguments)
2638
2724
  throw new TypeError(`No DataType schema determined`);
2639
- const instance = this.createDataTypeInstance(schema.kind, name);
2725
+ const instance = this.createDataTypeInstance(initArguments.kind, name);
2640
2726
  if (name)
2641
2727
  this.document.types.set(name, instance);
2642
- const initArguments = cloneObject(schema);
2643
2728
  await this.prepareDataTypeInitArguments(initArguments, ctor);
2644
2729
  if (initArguments.kind === "ComplexType")
2645
2730
  ComplexType2.apply(instance, [this.document, initArguments]);
@@ -2652,7 +2737,7 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2652
2737
  else if (initArguments.kind === "UnionType")
2653
2738
  UnionType2.apply(instance, [this.document, initArguments]);
2654
2739
  else
2655
- throw new TypeError(`Invalid data type schema: ${String(schema)}`);
2740
+ throw new TypeError(`Invalid data type schema: ${String(initArguments)}`);
2656
2741
  return instance;
2657
2742
  } finally {
2658
2743
  if (name) {
@@ -2702,7 +2787,7 @@ var TypeDocumentFactory = class _TypeDocumentFactory {
2702
2787
  if (enumObject[DATATYPE_METADATA]) {
2703
2788
  fieldInit.type = await this.importDataType(enumObject);
2704
2789
  } else {
2705
- const enumMeta = EnumType2(enumObject);
2790
+ const enumMeta = EnumType2(enumObject, { name: "" });
2706
2791
  fieldInit.type = await this.importDataType({ ...enumMeta, kind: "EnumType", base: void 0 });
2707
2792
  }
2708
2793
  } else {
@@ -10291,6 +10376,9 @@ var Operation = class extends Endpoint {
10291
10376
  this.name = name;
10292
10377
  this.kind = "operation";
10293
10378
  this.decodeInput = vg7.isAny();
10379
+ this.encodeReturning = vg7.isAny();
10380
+ this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType || "any");
10381
+ this.encodeReturning = this.returnType.generateCodec("encode");
10294
10382
  }
10295
10383
  };
10296
10384
 
@@ -10342,20 +10430,20 @@ var CollectionClass = class extends CrudResource {
10342
10430
  });
10343
10431
  let endpoint = this.operations.get("create");
10344
10432
  if (endpoint) {
10345
- endpoint.returnType = this.type;
10346
- endpoint.decode = this.type.generateCodec("decode", {
10433
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10434
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10435
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10436
+ endpoint.decodeInput = this.type.generateCodec("decode", {
10347
10437
  partial: true,
10348
10438
  pick: endpoint.inputPickFields,
10349
10439
  omit: endpoint.inputOmitFields
10350
10440
  });
10351
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10441
+ endpoint.returnType = this.type;
10442
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10352
10443
  partial: true,
10353
10444
  pick: endpoint.outputPickFields,
10354
10445
  omit: endpoint.outputOmitFields
10355
10446
  });
10356
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10357
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10358
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10359
10447
  }
10360
10448
  endpoint = this.operations.get("deleteMany");
10361
10449
  if (endpoint) {
@@ -10363,24 +10451,18 @@ var CollectionClass = class extends CrudResource {
10363
10451
  }
10364
10452
  endpoint = this.operations.get("get");
10365
10453
  if (endpoint) {
10454
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10455
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10456
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10366
10457
  endpoint.returnType = this.type;
10367
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10458
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10368
10459
  partial: true,
10369
10460
  pick: endpoint.outputPickFields,
10370
10461
  omit: endpoint.outputOmitFields
10371
10462
  });
10372
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10373
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10374
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10375
10463
  }
10376
10464
  endpoint = this.operations.get("findMany");
10377
10465
  if (endpoint) {
10378
- endpoint.returnType = this.type;
10379
- endpoint.encodeReturning = vg8.isArray(this.type.generateCodec("encode", {
10380
- partial: true,
10381
- pick: endpoint.outputPickFields,
10382
- omit: endpoint.outputOmitFields
10383
- }));
10384
10466
  endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10385
10467
  endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10386
10468
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
@@ -10390,30 +10472,36 @@ var CollectionClass = class extends CrudResource {
10390
10472
  endpoint.defineParameter("skip", { type: "integer", isBuiltin: true });
10391
10473
  endpoint.defineParameter("distinct", { type: "boolean", isBuiltin: true });
10392
10474
  endpoint.defineParameter("count", { type: "boolean", isBuiltin: true });
10475
+ endpoint.returnType = this.type;
10476
+ endpoint.encodeReturning = vg8.isArray(this.type.generateCodec("encode", {
10477
+ partial: true,
10478
+ pick: endpoint.outputPickFields,
10479
+ omit: endpoint.outputOmitFields
10480
+ }));
10393
10481
  }
10394
10482
  endpoint = this.operations.get("update");
10395
10483
  if (endpoint) {
10396
- endpoint.returnType = this.type;
10397
- endpoint.decode = this.type.generateCodec("decode", {
10484
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10485
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10486
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10487
+ endpoint.decodeInput = this.type.generateCodec("decode", {
10398
10488
  pick: endpoint.inputPickFields,
10399
10489
  omit: endpoint.inputOmitFields
10400
10490
  });
10401
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10491
+ endpoint.returnType = this.type;
10492
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10402
10493
  partial: true,
10403
10494
  pick: endpoint.outputPickFields,
10404
10495
  omit: endpoint.outputOmitFields
10405
10496
  });
10406
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10407
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10408
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10409
10497
  }
10410
10498
  endpoint = this.operations.get("updateMany");
10411
10499
  if (endpoint) {
10412
- endpoint.decode = this.type.generateCodec("decode", {
10500
+ endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
10501
+ endpoint.decodeInput = this.type.generateCodec("decode", {
10413
10502
  pick: endpoint.inputPickFields,
10414
10503
  omit: endpoint.inputOmitFields
10415
10504
  });
10416
- endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
10417
10505
  }
10418
10506
  }
10419
10507
  getOperation(name) {
@@ -10450,7 +10538,7 @@ var CollectionClass = class extends CrudResource {
10450
10538
  value = value[primaryKey];
10451
10539
  const el = dataType.getField(primaryKey);
10452
10540
  let result;
10453
- if (el.type instanceof SimpleType2)
10541
+ if (value != null && el.type instanceof SimpleType2)
10454
10542
  result = el.type.decode(value);
10455
10543
  if (result == null)
10456
10544
  throw new TypeError(`You must provide value of primary field(s) (${primaryKey})`);
@@ -10748,48 +10836,48 @@ var SingletonClass = class extends CrudResource {
10748
10836
  this.type = init.type;
10749
10837
  let endpoint = this.operations.get("create");
10750
10838
  if (endpoint) {
10751
- endpoint.returnType = this.type;
10752
- endpoint.decode = this.type.generateCodec("decode", {
10839
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10840
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10841
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10842
+ endpoint.decodeInput = this.type.generateCodec("decode", {
10753
10843
  partial: true,
10754
10844
  pick: endpoint.inputPickFields,
10755
10845
  omit: endpoint.inputOmitFields
10756
10846
  });
10757
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10847
+ endpoint.returnType = this.type;
10848
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10758
10849
  partial: true,
10759
10850
  pick: endpoint.outputPickFields,
10760
10851
  omit: endpoint.outputOmitFields
10761
10852
  });
10762
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10763
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10764
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10765
10853
  }
10766
10854
  endpoint = this.operations.get("get");
10767
10855
  if (endpoint) {
10856
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10857
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10858
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10768
10859
  endpoint.returnType = this.type;
10769
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10860
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10770
10861
  partial: true,
10771
10862
  pick: endpoint.outputPickFields,
10772
10863
  omit: endpoint.outputOmitFields
10773
10864
  });
10774
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10775
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10776
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10777
10865
  }
10778
10866
  endpoint = this.operations.get("update");
10779
10867
  if (endpoint) {
10780
- endpoint.returnType = this.type;
10781
- endpoint.decode = this.type.generateCodec("decode", {
10868
+ endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10869
+ endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10870
+ endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10871
+ endpoint.decodeInput = this.type.generateCodec("decode", {
10782
10872
  pick: endpoint.inputPickFields,
10783
10873
  omit: endpoint.inputOmitFields
10784
10874
  });
10785
- endpoint.encodeReturning = this.type.generateCodec("encode", {
10875
+ endpoint.returnType = this.type;
10876
+ endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10786
10877
  partial: true,
10787
10878
  pick: endpoint.outputPickFields,
10788
10879
  omit: endpoint.outputOmitFields
10789
10880
  });
10790
- endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
10791
- endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
10792
- endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10793
10881
  }
10794
10882
  }
10795
10883
  getOperation(name) {
@@ -11883,6 +11971,7 @@ export {
11883
11971
  DATATYPE_METADATA,
11884
11972
  DECORATOR,
11885
11973
  DataType,
11974
+ Endpoint,
11886
11975
  EnumType2 as EnumType,
11887
11976
  FailedDependencyError,
11888
11977
  ForbiddenError,
@@ -11893,12 +11982,14 @@ export {
11893
11982
  InternalServerError,
11894
11983
  IssueSeverity,
11895
11984
  MappedType2 as MappedType,
11985
+ MetadataMode,
11896
11986
  MethodNotAllowedError,
11897
11987
  NAMESPACE_PATTERN,
11898
11988
  NotAcceptableError,
11899
11989
  NotFoundError,
11900
11990
  OmitType,
11901
11991
  Operation,
11992
+ OperationResult,
11902
11993
  OpraException,
11903
11994
  opra_filter_ns_exports as OpraFilter,
11904
11995
  opra_schema_ns_exports as OpraSchema,