@opra/common 0.4.0 → 0.6.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 (416) hide show
  1. package/cjs/constants.js +1 -0
  2. package/cjs/exception/enums/issue-severity.enum.js +23 -0
  3. package/cjs/{types.js → exception/error-issue.js} +0 -0
  4. package/cjs/exception/http-errors/bad-request.error.js +22 -0
  5. package/cjs/exception/http-errors/failed-dependency.error.js +21 -0
  6. package/cjs/exception/http-errors/forbidden.error.js +23 -0
  7. package/cjs/exception/http-errors/internal-server.error.js +21 -0
  8. package/cjs/exception/http-errors/method-not-allowed.error.js +22 -0
  9. package/cjs/exception/http-errors/not-acceptable.error.js +22 -0
  10. package/cjs/exception/http-errors/not-found.error.js +25 -0
  11. package/cjs/exception/http-errors/unauthorized.error.js +22 -0
  12. package/cjs/exception/http-errors/unprocessable-entity.error.js +21 -0
  13. package/cjs/exception/index.js +18 -0
  14. package/cjs/exception/opra-exception.js +56 -0
  15. package/cjs/exception/resource-errors/resource-conflict.error.js +20 -0
  16. package/cjs/exception/resource-errors/resource-not-found.error.js +20 -0
  17. package/cjs/exception/wrap-exception.js +42 -0
  18. package/cjs/filter/antlr/OpraFilterLexer.js +386 -0
  19. package/cjs/filter/antlr/OpraFilterParser.js +2070 -0
  20. package/cjs/filter/antlr/OpraFilterVisitor.js +3 -0
  21. package/cjs/filter/ast/abstract/ast.js +10 -0
  22. package/cjs/filter/ast/abstract/expression.js +7 -0
  23. package/cjs/filter/ast/abstract/literal.js +14 -0
  24. package/cjs/filter/ast/abstract/term.js +7 -0
  25. package/cjs/filter/ast/expressions/arithmetic-expression.js +29 -0
  26. package/cjs/filter/ast/expressions/array-expression.js +15 -0
  27. package/cjs/filter/ast/expressions/comparison-expression.js +18 -0
  28. package/cjs/filter/ast/expressions/logical-expression.js +18 -0
  29. package/cjs/filter/ast/expressions/parentheses-expression.js +15 -0
  30. package/cjs/filter/ast/index.js +19 -0
  31. package/cjs/filter/ast/terms/boolean-literal.js +10 -0
  32. package/cjs/filter/ast/terms/date-literal.js +28 -0
  33. package/cjs/filter/ast/terms/external-constant.js +13 -0
  34. package/cjs/filter/ast/terms/null-literal.js +11 -0
  35. package/cjs/filter/ast/terms/number-literal.js +40 -0
  36. package/cjs/filter/ast/terms/qualified-identifier.js +10 -0
  37. package/cjs/filter/ast/terms/string-literal.js +14 -0
  38. package/cjs/filter/ast/terms/time-literal.js +33 -0
  39. package/cjs/filter/build.js +129 -0
  40. package/cjs/filter/error-listener.js +14 -0
  41. package/cjs/filter/errors.js +21 -0
  42. package/cjs/filter/filter-tree-visitor.js +113 -0
  43. package/cjs/filter/index.js +8 -0
  44. package/cjs/filter/parse.js +37 -0
  45. package/cjs/filter/utils.js +26 -0
  46. package/cjs/helpers/index.js +4 -0
  47. package/cjs/{responsive-map.js → helpers/responsive-map.js} +1 -1
  48. package/cjs/http/enums/http-headers.enum.js +404 -0
  49. package/cjs/http/enums/http-status.enum.js +300 -0
  50. package/cjs/http/http-request.js +118 -0
  51. package/cjs/http/index.js +9 -0
  52. package/cjs/http/interfaces/client-http-headers.interface.js +2 -0
  53. package/cjs/http/interfaces/server-http-headers.interface.js +2 -0
  54. package/cjs/http/multipart/batch-multipart.js +155 -0
  55. package/cjs/http/multipart/http-request-content.js +16 -0
  56. package/cjs/http/multipart/http-response-content.js +14 -0
  57. package/cjs/http/multipart/index.js +4 -0
  58. package/cjs/http/utils/normalize-headers.js +28 -0
  59. package/cjs/i18n/i18n.js +175 -0
  60. package/cjs/i18n/index.js +10 -0
  61. package/cjs/i18n/string-utils.js +13 -0
  62. package/cjs/i18n/translate.js +15 -0
  63. package/cjs/index.js +12 -2
  64. package/cjs/schema/constants.js +11 -0
  65. package/cjs/schema/decorators/opr-collection-resource.decorator.js +23 -0
  66. package/cjs/schema/decorators/opr-complex-type.decorator.js +27 -0
  67. package/cjs/schema/decorators/opr-field.decorator.js +28 -0
  68. package/cjs/schema/decorators/opr-resolver.decorator.js +81 -0
  69. package/cjs/schema/decorators/opr-simple-type.decorator.js +18 -0
  70. package/cjs/schema/decorators/opr-singleton-resource.decorator.js +23 -0
  71. package/cjs/schema/implementation/data-type/builtin/any.type.js +9 -0
  72. package/cjs/schema/implementation/data-type/builtin/base64-binary.type.js +15 -0
  73. package/cjs/schema/implementation/data-type/builtin/bigint.type.js +15 -0
  74. package/cjs/schema/implementation/data-type/builtin/boolean.type.js +15 -0
  75. package/cjs/schema/implementation/data-type/builtin/date-string.type.js +15 -0
  76. package/cjs/schema/implementation/data-type/builtin/date.type.js +15 -0
  77. package/cjs/schema/implementation/data-type/builtin/guid.type.js +15 -0
  78. package/cjs/schema/implementation/data-type/builtin/integer.type.js +15 -0
  79. package/cjs/schema/implementation/data-type/builtin/number.type.js +15 -0
  80. package/cjs/schema/implementation/data-type/builtin/object.type.js +15 -0
  81. package/cjs/schema/implementation/data-type/builtin/string.type.js +15 -0
  82. package/cjs/schema/implementation/data-type/builtin-data-types.js +37 -0
  83. package/cjs/schema/implementation/data-type/complex-type.js +111 -0
  84. package/cjs/schema/implementation/data-type/data-type.js +36 -0
  85. package/cjs/schema/implementation/data-type/simple-type.js +21 -0
  86. package/cjs/schema/implementation/data-type/union-type.js +25 -0
  87. package/cjs/schema/implementation/document-builder.js +140 -0
  88. package/cjs/schema/implementation/opra-document.js +181 -0
  89. package/cjs/schema/implementation/query/collection-count-query.js +19 -0
  90. package/cjs/schema/implementation/query/collection-create-query.js +28 -0
  91. package/cjs/schema/implementation/query/collection-delete-many-query.js +19 -0
  92. package/cjs/schema/implementation/query/collection-delete-query.js +27 -0
  93. package/cjs/schema/implementation/query/collection-get-query.js +38 -0
  94. package/cjs/schema/implementation/query/collection-search-query.js +55 -0
  95. package/cjs/schema/implementation/query/collection-update-many-query.js +21 -0
  96. package/cjs/schema/implementation/query/collection-update-query.js +39 -0
  97. package/cjs/schema/implementation/query/field-get-query.js +45 -0
  98. package/cjs/schema/implementation/query/index.js +22 -0
  99. package/cjs/schema/implementation/query/singleton-get-query.js +27 -0
  100. package/cjs/schema/implementation/resource/collection-resource-info.js +58 -0
  101. package/cjs/schema/implementation/resource/container-resource-info.js +30 -0
  102. package/cjs/schema/implementation/resource/resource-info.js +39 -0
  103. package/cjs/schema/implementation/resource/singleton-resource-info.js +37 -0
  104. package/cjs/schema/implementation/schema-builder/extract-resource-metadata.util.js +84 -0
  105. package/cjs/schema/implementation/schema-builder/extract-type-metadata.util.js +94 -0
  106. package/cjs/schema/index.js +28 -0
  107. package/cjs/schema/interfaces/child-field-query.interface.js +2 -0
  108. package/cjs/schema/interfaces/data-type.metadata.js +2 -0
  109. package/cjs/schema/interfaces/resource-container.interface.js +2 -0
  110. package/cjs/schema/interfaces/resource.metadata.js +2 -0
  111. package/cjs/schema/opra-schema.definition.js +49 -0
  112. package/cjs/schema/type-helpers/extend-type.helper.js +65 -0
  113. package/cjs/schema/type-helpers/mixin-type.helper.js +46 -0
  114. package/cjs/schema/type-helpers/mixin.utils.js +32 -0
  115. package/cjs/schema/types.js +2 -0
  116. package/cjs/schema/utils/class.utils.js +8 -0
  117. package/cjs/schema/utils/clone-object.util.js +19 -0
  118. package/cjs/schema/utils/inspect.util.js +7 -0
  119. package/cjs/schema/utils/normalize-field-array.util.js +44 -0
  120. package/cjs/schema/utils/path-to-tree.util.js +26 -0
  121. package/cjs/schema/utils/string-compare.util.js +11 -0
  122. package/cjs/url/formats/boolean-format.js +25 -0
  123. package/cjs/url/formats/date-format.js +48 -0
  124. package/cjs/url/formats/filter-format.js +18 -0
  125. package/cjs/url/formats/format.js +6 -0
  126. package/cjs/url/formats/integer-format.js +20 -0
  127. package/cjs/url/formats/number-format.js +28 -0
  128. package/cjs/url/formats/string-format.js +28 -0
  129. package/cjs/url/index.js +8 -0
  130. package/cjs/url/opra-url-path-component.js +33 -0
  131. package/cjs/url/opra-url-path.js +128 -0
  132. package/cjs/url/opra-url-search-params.js +247 -0
  133. package/cjs/url/opra-url.js +299 -0
  134. package/cjs/url/utils/path-utils.js +86 -0
  135. package/cjs/utils/index.js +6 -0
  136. package/cjs/utils/is-url.js +8 -0
  137. package/cjs/utils/path-to-tree.js +28 -0
  138. package/cjs/utils/type-guards.js +46 -0
  139. package/esm/constants.d.ts +0 -0
  140. package/esm/constants.js +1 -0
  141. package/esm/exception/enums/issue-severity.enum.d.ts +13 -0
  142. package/esm/exception/enums/issue-severity.enum.js +20 -0
  143. package/esm/exception/error-issue.d.ts +9 -0
  144. package/esm/{types.js → exception/error-issue.js} +0 -0
  145. package/esm/exception/http-errors/bad-request.error.d.ts +10 -0
  146. package/esm/exception/http-errors/bad-request.error.js +18 -0
  147. package/esm/exception/http-errors/failed-dependency.error.d.ts +9 -0
  148. package/esm/exception/http-errors/failed-dependency.error.js +17 -0
  149. package/esm/exception/http-errors/forbidden.error.d.ts +11 -0
  150. package/esm/exception/http-errors/forbidden.error.js +19 -0
  151. package/esm/exception/http-errors/internal-server.error.d.ts +9 -0
  152. package/esm/exception/http-errors/internal-server.error.js +17 -0
  153. package/esm/exception/http-errors/method-not-allowed.error.d.ts +10 -0
  154. package/esm/exception/http-errors/method-not-allowed.error.js +18 -0
  155. package/esm/exception/http-errors/not-acceptable.error.d.ts +10 -0
  156. package/esm/exception/http-errors/not-acceptable.error.js +18 -0
  157. package/esm/exception/http-errors/not-found.error.d.ts +13 -0
  158. package/esm/exception/http-errors/not-found.error.js +21 -0
  159. package/esm/exception/http-errors/unauthorized.error.d.ts +10 -0
  160. package/esm/exception/http-errors/unauthorized.error.js +18 -0
  161. package/esm/exception/http-errors/unprocessable-entity.error.d.ts +9 -0
  162. package/esm/exception/http-errors/unprocessable-entity.error.js +17 -0
  163. package/esm/exception/index.d.ts +15 -0
  164. package/esm/exception/index.js +15 -0
  165. package/esm/exception/opra-exception.d.ts +15 -0
  166. package/esm/exception/opra-exception.js +52 -0
  167. package/esm/exception/resource-errors/resource-conflict.error.d.ts +5 -0
  168. package/esm/exception/resource-errors/resource-conflict.error.js +16 -0
  169. package/esm/exception/resource-errors/resource-not-found.error.d.ts +4 -0
  170. package/esm/exception/resource-errors/resource-not-found.error.js +16 -0
  171. package/esm/exception/wrap-exception.d.ts +2 -0
  172. package/esm/exception/wrap-exception.js +38 -0
  173. package/esm/filter/antlr/OpraFilterLexer.d.ts +78 -0
  174. package/esm/filter/antlr/OpraFilterLexer.js +381 -0
  175. package/esm/filter/antlr/OpraFilterParser.d.ts +365 -0
  176. package/esm/filter/antlr/OpraFilterParser.js +2022 -0
  177. package/esm/filter/antlr/OpraFilterVisitor.d.ts +290 -0
  178. package/esm/filter/antlr/OpraFilterVisitor.js +2 -0
  179. package/esm/filter/ast/abstract/ast.d.ts +5 -0
  180. package/esm/filter/ast/abstract/ast.js +6 -0
  181. package/esm/filter/ast/abstract/expression.d.ts +3 -0
  182. package/esm/filter/ast/abstract/expression.js +3 -0
  183. package/esm/filter/ast/abstract/literal.d.ts +6 -0
  184. package/esm/filter/ast/abstract/literal.js +10 -0
  185. package/esm/filter/ast/abstract/term.d.ts +3 -0
  186. package/esm/filter/ast/abstract/term.js +3 -0
  187. package/esm/filter/ast/expressions/arithmetic-expression.d.ts +13 -0
  188. package/esm/filter/ast/expressions/arithmetic-expression.js +24 -0
  189. package/esm/filter/ast/expressions/array-expression.d.ts +7 -0
  190. package/esm/filter/ast/expressions/array-expression.js +11 -0
  191. package/esm/filter/ast/expressions/comparison-expression.d.ts +10 -0
  192. package/esm/filter/ast/expressions/comparison-expression.js +14 -0
  193. package/esm/filter/ast/expressions/logical-expression.d.ts +8 -0
  194. package/esm/filter/ast/expressions/logical-expression.js +14 -0
  195. package/esm/filter/ast/expressions/parentheses-expression.d.ts +6 -0
  196. package/esm/filter/ast/expressions/parentheses-expression.js +11 -0
  197. package/esm/filter/ast/index.d.ts +16 -0
  198. package/esm/filter/ast/index.js +16 -0
  199. package/esm/filter/ast/terms/boolean-literal.d.ts +5 -0
  200. package/esm/filter/ast/terms/boolean-literal.js +6 -0
  201. package/esm/filter/ast/terms/date-literal.d.ts +6 -0
  202. package/esm/filter/ast/terms/date-literal.js +24 -0
  203. package/esm/filter/ast/terms/external-constant.d.ts +5 -0
  204. package/esm/filter/ast/terms/external-constant.js +9 -0
  205. package/esm/filter/ast/terms/null-literal.d.ts +5 -0
  206. package/esm/filter/ast/terms/null-literal.js +7 -0
  207. package/esm/filter/ast/terms/number-literal.d.ts +6 -0
  208. package/esm/filter/ast/terms/number-literal.js +36 -0
  209. package/esm/filter/ast/terms/qualified-identifier.d.ts +4 -0
  210. package/esm/filter/ast/terms/qualified-identifier.js +6 -0
  211. package/esm/filter/ast/terms/string-literal.d.ts +5 -0
  212. package/esm/filter/ast/terms/string-literal.js +10 -0
  213. package/esm/filter/ast/terms/time-literal.d.ts +6 -0
  214. package/esm/filter/ast/terms/time-literal.js +29 -0
  215. package/esm/filter/build.d.ts +31 -0
  216. package/esm/filter/build.js +105 -0
  217. package/esm/filter/error-listener.d.ts +8 -0
  218. package/esm/filter/error-listener.js +10 -0
  219. package/esm/filter/errors.d.ts +20 -0
  220. package/esm/filter/errors.js +15 -0
  221. package/esm/filter/filter-tree-visitor.d.ts +30 -0
  222. package/esm/filter/filter-tree-visitor.js +109 -0
  223. package/esm/filter/index.d.ts +5 -0
  224. package/esm/filter/index.js +5 -0
  225. package/esm/filter/parse.d.ts +2 -0
  226. package/esm/filter/parse.js +33 -0
  227. package/esm/filter/utils.d.ts +2 -0
  228. package/esm/filter/utils.js +21 -0
  229. package/esm/helpers/index.d.ts +1 -0
  230. package/esm/helpers/index.js +1 -0
  231. package/esm/{responsive-map.d.ts → helpers/responsive-map.d.ts} +0 -0
  232. package/esm/{responsive-map.js → helpers/responsive-map.js} +1 -1
  233. package/esm/http/enums/http-headers.enum.d.ts +379 -0
  234. package/esm/http/enums/http-headers.enum.js +401 -0
  235. package/esm/http/enums/http-status.enum.d.ts +290 -0
  236. package/esm/http/enums/http-status.enum.js +297 -0
  237. package/esm/http/http-request.d.ts +34 -0
  238. package/esm/http/http-request.js +114 -0
  239. package/esm/http/index.d.ts +6 -0
  240. package/esm/http/index.js +6 -0
  241. package/esm/http/interfaces/client-http-headers.interface.d.ts +65 -0
  242. package/esm/http/interfaces/client-http-headers.interface.js +1 -0
  243. package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -0
  244. package/esm/http/interfaces/server-http-headers.interface.js +1 -0
  245. package/esm/http/multipart/batch-multipart.d.ts +30 -0
  246. package/esm/http/multipart/batch-multipart.js +150 -0
  247. package/esm/http/multipart/http-request-content.d.ts +8 -0
  248. package/esm/http/multipart/http-request-content.js +12 -0
  249. package/esm/http/multipart/http-response-content.d.ts +7 -0
  250. package/esm/http/multipart/http-response-content.js +10 -0
  251. package/esm/http/multipart/index.d.ts +1 -0
  252. package/esm/http/multipart/index.js +1 -0
  253. package/esm/http/utils/normalize-headers.d.ts +1 -0
  254. package/esm/http/utils/normalize-headers.js +24 -0
  255. package/esm/i18n/i18n.d.ts +28 -0
  256. package/esm/i18n/i18n.js +170 -0
  257. package/esm/i18n/index.d.ts +5 -0
  258. package/esm/i18n/index.js +6 -0
  259. package/esm/i18n/string-utils.d.ts +2 -0
  260. package/esm/i18n/string-utils.js +8 -0
  261. package/esm/i18n/translate.d.ts +4 -0
  262. package/esm/i18n/translate.js +11 -0
  263. package/esm/index.d.ts +10 -2
  264. package/esm/index.js +10 -2
  265. package/esm/schema/constants.d.ts +8 -0
  266. package/esm/schema/constants.js +8 -0
  267. package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +8 -0
  268. package/esm/schema/decorators/opr-collection-resource.decorator.js +19 -0
  269. package/esm/schema/decorators/opr-complex-type.decorator.d.ts +6 -0
  270. package/esm/schema/decorators/opr-complex-type.decorator.js +23 -0
  271. package/esm/schema/decorators/opr-field.decorator.d.ts +3 -0
  272. package/esm/schema/decorators/opr-field.decorator.js +24 -0
  273. package/esm/schema/decorators/opr-resolver.decorator.d.ts +8 -0
  274. package/esm/schema/decorators/opr-resolver.decorator.js +71 -0
  275. package/esm/schema/decorators/opr-simple-type.decorator.d.ts +6 -0
  276. package/esm/schema/decorators/opr-simple-type.decorator.js +14 -0
  277. package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +8 -0
  278. package/esm/schema/decorators/opr-singleton-resource.decorator.js +19 -0
  279. package/esm/schema/implementation/data-type/builtin/any.type.d.ts +2 -0
  280. package/esm/schema/implementation/data-type/builtin/any.type.js +6 -0
  281. package/esm/schema/implementation/data-type/builtin/base64-binary.type.d.ts +2 -0
  282. package/esm/schema/implementation/data-type/builtin/base64-binary.type.js +12 -0
  283. package/esm/schema/implementation/data-type/builtin/bigint.type.d.ts +2 -0
  284. package/esm/schema/implementation/data-type/builtin/bigint.type.js +12 -0
  285. package/esm/schema/implementation/data-type/builtin/boolean.type.d.ts +2 -0
  286. package/esm/schema/implementation/data-type/builtin/boolean.type.js +12 -0
  287. package/esm/schema/implementation/data-type/builtin/date-string.type.d.ts +2 -0
  288. package/esm/schema/implementation/data-type/builtin/date-string.type.js +12 -0
  289. package/esm/schema/implementation/data-type/builtin/date.type.d.ts +2 -0
  290. package/esm/schema/implementation/data-type/builtin/date.type.js +12 -0
  291. package/esm/schema/implementation/data-type/builtin/guid.type.d.ts +2 -0
  292. package/esm/schema/implementation/data-type/builtin/guid.type.js +12 -0
  293. package/esm/schema/implementation/data-type/builtin/integer.type.d.ts +2 -0
  294. package/esm/schema/implementation/data-type/builtin/integer.type.js +12 -0
  295. package/esm/schema/implementation/data-type/builtin/number.type.d.ts +2 -0
  296. package/esm/schema/implementation/data-type/builtin/number.type.js +12 -0
  297. package/esm/schema/implementation/data-type/builtin/object.type.d.ts +2 -0
  298. package/esm/schema/implementation/data-type/builtin/object.type.js +12 -0
  299. package/esm/schema/implementation/data-type/builtin/string.type.d.ts +2 -0
  300. package/esm/schema/implementation/data-type/builtin/string.type.js +12 -0
  301. package/esm/schema/implementation/data-type/builtin-data-types.d.ts +4 -0
  302. package/esm/schema/implementation/data-type/builtin-data-types.js +34 -0
  303. package/esm/schema/implementation/data-type/complex-type.d.ts +29 -0
  304. package/esm/schema/implementation/data-type/complex-type.js +107 -0
  305. package/esm/schema/implementation/data-type/data-type.d.ts +16 -0
  306. package/esm/schema/implementation/data-type/data-type.js +32 -0
  307. package/esm/schema/implementation/data-type/simple-type.d.ts +12 -0
  308. package/esm/schema/implementation/data-type/simple-type.js +17 -0
  309. package/esm/schema/implementation/data-type/union-type.d.ts +16 -0
  310. package/esm/schema/implementation/data-type/union-type.js +21 -0
  311. package/esm/schema/implementation/document-builder.d.ts +16 -0
  312. package/esm/schema/implementation/document-builder.js +135 -0
  313. package/esm/schema/implementation/opra-document.d.ts +44 -0
  314. package/esm/schema/implementation/opra-document.js +177 -0
  315. package/esm/schema/implementation/query/collection-count-query.d.ts +14 -0
  316. package/esm/schema/implementation/query/collection-count-query.js +15 -0
  317. package/esm/schema/implementation/query/collection-create-query.d.ts +18 -0
  318. package/esm/schema/implementation/query/collection-create-query.js +24 -0
  319. package/esm/schema/implementation/query/collection-delete-many-query.d.ts +14 -0
  320. package/esm/schema/implementation/query/collection-delete-many-query.js +15 -0
  321. package/esm/schema/implementation/query/collection-delete-query.d.ts +10 -0
  322. package/esm/schema/implementation/query/collection-delete-query.js +23 -0
  323. package/esm/schema/implementation/query/collection-get-query.d.ts +21 -0
  324. package/esm/schema/implementation/query/collection-get-query.js +34 -0
  325. package/esm/schema/implementation/query/collection-search-query.d.ts +30 -0
  326. package/esm/schema/implementation/query/collection-search-query.js +51 -0
  327. package/esm/schema/implementation/query/collection-update-many-query.d.ts +15 -0
  328. package/esm/schema/implementation/query/collection-update-many-query.js +17 -0
  329. package/esm/schema/implementation/query/collection-update-query.d.ts +19 -0
  330. package/esm/schema/implementation/query/collection-update-query.js +35 -0
  331. package/esm/schema/implementation/query/field-get-query.d.ts +30 -0
  332. package/esm/schema/implementation/query/field-get-query.js +41 -0
  333. package/esm/schema/implementation/query/index.d.ts +27 -0
  334. package/esm/schema/implementation/query/index.js +17 -0
  335. package/esm/schema/implementation/query/singleton-get-query.d.ts +20 -0
  336. package/esm/schema/implementation/query/singleton-get-query.js +23 -0
  337. package/esm/schema/implementation/resource/collection-resource-info.d.ts +19 -0
  338. package/esm/schema/implementation/resource/collection-resource-info.js +54 -0
  339. package/esm/schema/implementation/resource/container-resource-info.d.ts +13 -0
  340. package/esm/schema/implementation/resource/container-resource-info.js +26 -0
  341. package/esm/schema/implementation/resource/resource-info.d.ts +17 -0
  342. package/esm/schema/implementation/resource/resource-info.js +35 -0
  343. package/esm/schema/implementation/resource/singleton-resource-info.d.ts +14 -0
  344. package/esm/schema/implementation/resource/singleton-resource-info.js +33 -0
  345. package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.d.ts +3 -0
  346. package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.js +80 -0
  347. package/esm/schema/implementation/schema-builder/extract-type-metadata.util.d.ts +4 -0
  348. package/esm/schema/implementation/schema-builder/extract-type-metadata.util.js +89 -0
  349. package/esm/schema/index.d.ts +25 -0
  350. package/esm/schema/index.js +25 -0
  351. package/esm/schema/interfaces/child-field-query.interface.d.ts +4 -0
  352. package/esm/schema/interfaces/child-field-query.interface.js +1 -0
  353. package/esm/schema/interfaces/data-type.metadata.d.ts +18 -0
  354. package/esm/schema/interfaces/data-type.metadata.js +1 -0
  355. package/esm/schema/interfaces/resource-container.interface.d.ts +8 -0
  356. package/esm/schema/interfaces/resource-container.interface.js +1 -0
  357. package/esm/schema/interfaces/resource.metadata.d.ts +18 -0
  358. package/esm/schema/interfaces/resource.metadata.js +1 -0
  359. package/esm/schema/opra-schema.definition.d.ts +178 -0
  360. package/esm/schema/opra-schema.definition.js +46 -0
  361. package/esm/schema/type-helpers/extend-type.helper.d.ts +3 -0
  362. package/esm/schema/type-helpers/extend-type.helper.js +59 -0
  363. package/esm/schema/type-helpers/mixin-type.helper.d.ts +2 -0
  364. package/esm/schema/type-helpers/mixin-type.helper.js +41 -0
  365. package/esm/schema/type-helpers/mixin.utils.d.ts +3 -0
  366. package/esm/schema/type-helpers/mixin.utils.js +27 -0
  367. package/esm/{types.d.ts → schema/types.d.ts} +8 -1
  368. package/esm/schema/types.js +1 -0
  369. package/esm/schema/utils/class.utils.d.ts +2 -0
  370. package/esm/schema/utils/class.utils.js +4 -0
  371. package/esm/schema/utils/clone-object.util.d.ts +1 -0
  372. package/esm/schema/utils/clone-object.util.js +14 -0
  373. package/esm/schema/utils/inspect.util.d.ts +4 -0
  374. package/esm/schema/utils/inspect.util.js +4 -0
  375. package/esm/schema/utils/normalize-field-array.util.d.ts +3 -0
  376. package/esm/schema/utils/normalize-field-array.util.js +40 -0
  377. package/esm/schema/utils/path-to-tree.util.d.ts +4 -0
  378. package/esm/schema/utils/path-to-tree.util.js +22 -0
  379. package/esm/schema/utils/string-compare.util.d.ts +1 -0
  380. package/esm/schema/utils/string-compare.util.js +7 -0
  381. package/esm/url/formats/boolean-format.d.ts +5 -0
  382. package/esm/url/formats/boolean-format.js +21 -0
  383. package/esm/url/formats/date-format.d.ts +16 -0
  384. package/esm/url/formats/date-format.js +44 -0
  385. package/esm/url/formats/filter-format.d.ts +6 -0
  386. package/esm/url/formats/filter-format.js +14 -0
  387. package/esm/url/formats/format.d.ts +4 -0
  388. package/esm/url/formats/format.js +2 -0
  389. package/esm/url/formats/integer-format.d.ts +9 -0
  390. package/esm/url/formats/integer-format.js +16 -0
  391. package/esm/url/formats/number-format.d.ts +12 -0
  392. package/esm/url/formats/number-format.js +24 -0
  393. package/esm/url/formats/string-format.d.ts +14 -0
  394. package/esm/url/formats/string-format.js +24 -0
  395. package/esm/url/index.d.ts +5 -0
  396. package/esm/url/index.js +5 -0
  397. package/esm/url/opra-url-path-component.d.ts +15 -0
  398. package/esm/url/opra-url-path-component.js +29 -0
  399. package/esm/url/opra-url-path.d.ts +30 -0
  400. package/esm/url/opra-url-path.js +124 -0
  401. package/esm/url/opra-url-search-params.d.ts +46 -0
  402. package/esm/url/opra-url-search-params.js +243 -0
  403. package/esm/url/opra-url.d.ts +79 -0
  404. package/esm/url/opra-url.js +295 -0
  405. package/esm/url/utils/path-utils.d.ts +8 -0
  406. package/esm/url/utils/path-utils.js +78 -0
  407. package/esm/utils/index.d.ts +3 -0
  408. package/esm/utils/index.js +3 -0
  409. package/esm/utils/is-url.d.ts +1 -0
  410. package/esm/utils/is-url.js +4 -0
  411. package/esm/utils/path-to-tree.d.ts +4 -0
  412. package/esm/utils/path-to-tree.js +24 -0
  413. package/esm/utils/type-guards.d.ts +9 -0
  414. package/esm/utils/type-guards.js +37 -0
  415. package/package.json +30 -10
  416. package/umd/opra-common.umd.min.js +1 -0
@@ -0,0 +1,17 @@
1
+ import { parseFilter } from '../../../filter/index.js';
2
+ export class CollectionUpdateManyQuery {
3
+ resource;
4
+ data;
5
+ kind = 'CollectionUpdateManyQuery';
6
+ method = 'updateMany';
7
+ operation = 'update';
8
+ filter;
9
+ constructor(resource, data, options) {
10
+ this.resource = resource;
11
+ this.data = data;
12
+ this.filter = typeof options?.filter === 'string' ? parseFilter(options.filter) : options?.filter;
13
+ }
14
+ get dataType() {
15
+ return this.resource.dataType;
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ import { CollectionResourceInfo } from '../resource/collection-resource-info.js';
2
+ export declare type CollectionUpdateQueryOptions = {
3
+ pick?: string[];
4
+ omit?: string[];
5
+ include?: string[];
6
+ };
7
+ export declare class CollectionUpdateQuery {
8
+ readonly resource: CollectionResourceInfo;
9
+ data: any;
10
+ readonly kind = "CollectionUpdateQuery";
11
+ readonly method = "update";
12
+ readonly operation = "update";
13
+ keyValue: any;
14
+ pick?: string[];
15
+ omit?: string[];
16
+ include?: string[];
17
+ constructor(resource: CollectionResourceInfo, keyValue: any, data: any, options?: CollectionUpdateQueryOptions);
18
+ get dataType(): import("../data-type/complex-type.js").ComplexType;
19
+ }
@@ -0,0 +1,35 @@
1
+ import { normalizeFieldArray } from '../../utils/normalize-field-array.util.js';
2
+ export class CollectionUpdateQuery {
3
+ resource;
4
+ data;
5
+ kind = 'CollectionUpdateQuery';
6
+ method = 'update';
7
+ operation = 'update';
8
+ keyValue;
9
+ pick;
10
+ omit;
11
+ include;
12
+ constructor(resource, keyValue, data, options) {
13
+ this.resource = resource;
14
+ this.data = data;
15
+ if (resource.keyFields.length > 1) {
16
+ if (typeof keyValue !== 'object')
17
+ throw new Error(`You must provide an key/value object for all key fields (${resource.keyFields})`);
18
+ resource.keyFields.reduce((o, k) => {
19
+ o[k] = keyValue[k];
20
+ return o;
21
+ }, {});
22
+ }
23
+ else
24
+ this.keyValue = resource.dataType.getFieldType(resource.keyFields[0]).parse(keyValue);
25
+ if (options?.pick)
26
+ this.pick = normalizeFieldArray(resource.document, resource.dataType, options.pick);
27
+ if (options?.omit)
28
+ this.omit = normalizeFieldArray(resource.document, resource.dataType, options.omit);
29
+ if (options?.include)
30
+ this.include = normalizeFieldArray(resource.document, resource.dataType, options.include);
31
+ }
32
+ get dataType() {
33
+ return this.resource.dataType;
34
+ }
35
+ }
@@ -0,0 +1,30 @@
1
+ import type { IChildFieldQuery } from '../../interfaces/child-field-query.interface.js';
2
+ import { ComplexType, Field } from '../data-type/complex-type.js';
3
+ import type { DataType } from '../data-type/data-type.js';
4
+ import type { CollectionResourceInfo } from '../resource/collection-resource-info.js';
5
+ import type { SingletonResourceInfo } from '../resource/singleton-resource-info.js';
6
+ import type { CollectionGetQuery } from './collection-get-query.js';
7
+ import type { SingletonGetQuery } from './singleton-get-query.js';
8
+ export declare type FieldGetQueryOptions = {
9
+ pick?: string[];
10
+ omit?: string[];
11
+ include?: string[];
12
+ castingType?: ComplexType;
13
+ };
14
+ export declare class FieldGetQuery implements IChildFieldQuery {
15
+ readonly parent: CollectionGetQuery | SingletonGetQuery | FieldGetQuery;
16
+ readonly resource: CollectionResourceInfo | SingletonResourceInfo;
17
+ readonly kind = "FieldGetQuery";
18
+ readonly method = "get";
19
+ readonly operation = "read";
20
+ readonly fieldName: string;
21
+ readonly field?: Field;
22
+ readonly path: string;
23
+ readonly dataType: DataType;
24
+ readonly parentType: ComplexType;
25
+ pick?: string[];
26
+ omit?: string[];
27
+ include?: string[];
28
+ child?: FieldGetQuery;
29
+ constructor(parent: CollectionGetQuery | SingletonGetQuery | FieldGetQuery, fieldName: string, options?: FieldGetQueryOptions);
30
+ }
@@ -0,0 +1,41 @@
1
+ import { normalizeFieldArray } from '../../utils/normalize-field-array.util.js';
2
+ import { ComplexType } from '../data-type/complex-type.js';
3
+ export class FieldGetQuery {
4
+ parent;
5
+ resource;
6
+ kind = 'FieldGetQuery';
7
+ method = 'get';
8
+ operation = 'read';
9
+ fieldName;
10
+ field;
11
+ path;
12
+ dataType;
13
+ parentType;
14
+ pick;
15
+ omit;
16
+ include;
17
+ child;
18
+ constructor(parent, fieldName, options) {
19
+ this.parent = parent;
20
+ this.resource = parent.resource;
21
+ const parentType = options?.castingType || parent.dataType;
22
+ if (!parentType || !(parentType instanceof ComplexType))
23
+ throw new TypeError(`Data type of parent query is not a ComplexType`);
24
+ this.parentType = parentType;
25
+ this.field = parentType.additionalFields
26
+ ? parentType.fields.get(fieldName)
27
+ : parentType.getField(fieldName);
28
+ this.fieldName = this.field ? this.field.name : fieldName;
29
+ this.dataType = this.resource.document.getDataType(this.field ? (this.field.type || 'string') : 'object');
30
+ this.path = (parent instanceof FieldGetQuery
31
+ ? parent.path + '.' : '') + this.fieldName;
32
+ if (this.dataType instanceof ComplexType) {
33
+ if (options?.pick)
34
+ this.pick = normalizeFieldArray(this.resource.document, this.dataType, options.pick, this.path);
35
+ if (options?.omit)
36
+ this.omit = normalizeFieldArray(this.resource.document, this.dataType, options.omit, this.path);
37
+ if (options?.include)
38
+ this.include = normalizeFieldArray(this.resource.document, this.dataType, options.include, this.path);
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,27 @@
1
+ import { IChildFieldQuery } from '../../interfaces/child-field-query.interface.js';
2
+ import { CollectionCountQuery } from './collection-count-query.js';
3
+ import { CollectionCreateQuery } from './collection-create-query.js';
4
+ import { CollectionDeleteManyQuery } from './collection-delete-many-query.js';
5
+ import { CollectionDeleteQuery } from './collection-delete-query.js';
6
+ import { CollectionGetQuery } from './collection-get-query.js';
7
+ import { CollectionSearchQuery } from './collection-search-query.js';
8
+ import { CollectionUpdateManyQuery } from './collection-update-many-query.js';
9
+ import { CollectionUpdateQuery } from './collection-update-query.js';
10
+ import { FieldGetQuery } from './field-get-query.js';
11
+ import { SingletonGetQuery } from './singleton-get-query.js';
12
+ export * from './collection-create-query.js';
13
+ export * from './collection-count-query.js';
14
+ export * from './collection-delete-many-query.js';
15
+ export * from './collection-delete-query.js';
16
+ export * from './collection-delete-many-query.js';
17
+ export * from './collection-get-query.js';
18
+ export * from './field-get-query.js';
19
+ export * from './singleton-get-query.js';
20
+ export * from './collection-search-query.js';
21
+ export * from './collection-update-many-query.js';
22
+ export * from './collection-update-query.js';
23
+ export declare type CollectionQuery = CollectionCountQuery | CollectionCreateQuery | CollectionDeleteManyQuery | CollectionDeleteQuery | CollectionGetQuery | CollectionSearchQuery | CollectionUpdateManyQuery | CollectionUpdateQuery;
24
+ export declare type FieldQuery = FieldGetQuery;
25
+ export declare type SingletonQuery = SingletonGetQuery;
26
+ export declare type OpraQuery = CollectionQuery | SingletonQuery | FieldQuery;
27
+ export declare function isChildFieldQuery(query: any): query is IChildFieldQuery;
@@ -0,0 +1,17 @@
1
+ export * from './collection-create-query.js';
2
+ export * from './collection-count-query.js';
3
+ export * from './collection-delete-many-query.js';
4
+ export * from './collection-delete-query.js';
5
+ export * from './collection-delete-many-query.js';
6
+ export * from './collection-get-query.js';
7
+ export * from './field-get-query.js';
8
+ export * from './singleton-get-query.js';
9
+ export * from './collection-search-query.js';
10
+ export * from './collection-update-many-query.js';
11
+ export * from './collection-update-query.js';
12
+ export function isChildFieldQuery(query) {
13
+ return query &&
14
+ (query.kind === 'SingletonGetQuery' ||
15
+ query.kind === 'CollectionGetQuery' ||
16
+ query.kind === 'FieldGetQuery');
17
+ }
@@ -0,0 +1,20 @@
1
+ import type { IChildFieldQuery } from '../../interfaces/child-field-query.interface.js';
2
+ import type { SingletonResourceInfo } from '../resource/singleton-resource-info.js';
3
+ import type { FieldGetQuery } from './field-get-query.js';
4
+ export declare type SingletonGetQueryOptions = {
5
+ pick?: string[];
6
+ omit?: string[];
7
+ include?: string[];
8
+ };
9
+ export declare class SingletonGetQuery implements IChildFieldQuery {
10
+ readonly resource: SingletonResourceInfo;
11
+ readonly kind = "SingletonGetQuery";
12
+ readonly method = "get";
13
+ readonly operation = "read";
14
+ pick?: string[];
15
+ omit?: string[];
16
+ include?: string[];
17
+ child?: FieldGetQuery;
18
+ constructor(resource: SingletonResourceInfo, options?: SingletonGetQueryOptions);
19
+ get dataType(): import("../data-type/complex-type.js").ComplexType;
20
+ }
@@ -0,0 +1,23 @@
1
+ import { normalizeFieldArray } from '../../utils/normalize-field-array.util.js';
2
+ export class SingletonGetQuery {
3
+ resource;
4
+ kind = 'SingletonGetQuery';
5
+ method = 'get';
6
+ operation = 'read';
7
+ pick;
8
+ omit;
9
+ include;
10
+ child;
11
+ constructor(resource, options) {
12
+ this.resource = resource;
13
+ if (options?.pick)
14
+ this.pick = normalizeFieldArray(resource.document, resource.dataType, options.pick);
15
+ if (options?.omit)
16
+ this.omit = normalizeFieldArray(resource.document, resource.dataType, options.omit);
17
+ if (options?.include)
18
+ this.include = normalizeFieldArray(resource.document, resource.dataType, options.include);
19
+ }
20
+ get dataType() {
21
+ return this.resource.dataType;
22
+ }
23
+ }
@@ -0,0 +1,19 @@
1
+ import { OpraSchema } from '../../opra-schema.definition.js';
2
+ import { ComplexType } from '../data-type/complex-type.js';
3
+ import type { OpraDocument } from '../opra-document';
4
+ import { ResourceInfo } from './resource-info.js';
5
+ export declare class CollectionResourceInfo extends ResourceInfo {
6
+ readonly metadata: OpraSchema.CollectionResource;
7
+ readonly dataType: ComplexType;
8
+ constructor(document: OpraDocument, name: string, dataType: ComplexType, metadata: OpraSchema.CollectionResource);
9
+ get keyFields(): string[];
10
+ get create(): OpraSchema.CreateMethodResolver | undefined;
11
+ get count(): OpraSchema.MethodResolver | undefined;
12
+ get delete(): OpraSchema.MethodResolver | undefined;
13
+ get deleteMany(): OpraSchema.DeleteManyMethodResolver | undefined;
14
+ get get(): OpraSchema.GetMethodResolver | undefined;
15
+ get update(): OpraSchema.UpdateMethodResolver | undefined;
16
+ get updateMany(): OpraSchema.UpdateManyMethodResolver | undefined;
17
+ get search(): OpraSchema.SearchMethodResolver | undefined;
18
+ getSchema(jsonOnly?: boolean): OpraSchema.CollectionResource;
19
+ }
@@ -0,0 +1,54 @@
1
+ import { collectionMethods } from '../../constants.js';
2
+ import { normalizeFieldArray } from '../../utils/normalize-field-array.util.js';
3
+ import { ResourceInfo } from './resource-info.js';
4
+ export class CollectionResourceInfo extends ResourceInfo {
5
+ dataType;
6
+ constructor(document, name, dataType, metadata) {
7
+ if (!metadata.keyFields)
8
+ throw new TypeError(`You should provide key fields for ${name}`);
9
+ super(document, name, metadata);
10
+ metadata.keyFields = Array.isArray(metadata.keyFields) ? metadata.keyFields : [metadata.keyFields];
11
+ metadata.keyFields.forEach(f => dataType.getField(f));
12
+ this.dataType = dataType;
13
+ if (metadata.search && metadata.search.sortFields) {
14
+ metadata.search.sortFields = normalizeFieldArray(document, dataType, metadata.search.sortFields);
15
+ }
16
+ }
17
+ get keyFields() {
18
+ return this.metadata.keyFields;
19
+ }
20
+ get create() {
21
+ return this.metadata.create;
22
+ }
23
+ get count() {
24
+ return this.metadata.count;
25
+ }
26
+ get delete() {
27
+ return this.metadata.delete;
28
+ }
29
+ get deleteMany() {
30
+ return this.metadata.deleteMany;
31
+ }
32
+ get get() {
33
+ return this.metadata.get;
34
+ }
35
+ get update() {
36
+ return this.metadata.update;
37
+ }
38
+ get updateMany() {
39
+ return this.metadata.updateMany;
40
+ }
41
+ get search() {
42
+ return this.metadata.search;
43
+ }
44
+ getSchema(jsonOnly) {
45
+ const out = super.getSchema(jsonOnly);
46
+ if (out.keyFields.length < 2)
47
+ out.keyFields = out.keyFields[0];
48
+ for (const k of collectionMethods) {
49
+ if (typeof out[k] === 'object' && !Object.keys(out[k]).length)
50
+ out[k] = true;
51
+ }
52
+ return out;
53
+ }
54
+ }
@@ -0,0 +1,13 @@
1
+ import { IResourceContainer } from '../../interfaces/resource-container.interface.js';
2
+ import { OpraSchema } from '../../opra-schema.definition.js';
3
+ import type { OpraDocument } from '../opra-document.js';
4
+ import { CollectionResourceInfo } from './collection-resource-info.js';
5
+ import { ResourceInfo } from './resource-info.js';
6
+ import { SingletonResourceInfo } from './singleton-resource-info.js';
7
+ export declare class ContainerResourceInfo extends ResourceInfo implements IResourceContainer {
8
+ readonly metadata: OpraSchema.ContainerResource;
9
+ constructor(service: OpraDocument, name: string, metadata: OpraSchema.ContainerResource);
10
+ getResource<T extends ResourceInfo>(name: string): T;
11
+ getCollectionResource(name: string): CollectionResourceInfo;
12
+ getSingletonResource(name: string): SingletonResourceInfo;
13
+ }
@@ -0,0 +1,26 @@
1
+ import { CollectionResourceInfo } from './collection-resource-info.js';
2
+ import { ResourceInfo } from './resource-info.js';
3
+ import { SingletonResourceInfo } from './singleton-resource-info.js';
4
+ export class ContainerResourceInfo extends ResourceInfo {
5
+ constructor(service, name, metadata) {
6
+ super(service, name, metadata);
7
+ }
8
+ getResource(name) {
9
+ const t = this.metadata.resources[name];
10
+ if (!t)
11
+ throw new Error(`Resource "${name}" does not exists`);
12
+ return t;
13
+ }
14
+ getCollectionResource(name) {
15
+ const t = this.getResource(name);
16
+ if (!(t instanceof CollectionResourceInfo))
17
+ throw new Error(`"${name}" is not a Collection Resource`);
18
+ return t;
19
+ }
20
+ getSingletonResource(name) {
21
+ const t = this.getResource(name);
22
+ if (!(t instanceof SingletonResourceInfo))
23
+ throw new Error(`"${name}" is not a SingletonResource`);
24
+ return t;
25
+ }
26
+ }
@@ -0,0 +1,17 @@
1
+ import { OpraSchema } from '../../opra-schema.definition.js';
2
+ import { nodeInspectCustom } from '../../utils/inspect.util.js';
3
+ import type { OpraDocument } from '../opra-document.js';
4
+ export declare abstract class ResourceInfo {
5
+ readonly metadata: OpraSchema.Resource;
6
+ readonly document: OpraDocument;
7
+ readonly name: string;
8
+ protected path: string;
9
+ protected constructor(document: OpraDocument, name: string, metadata: OpraSchema.Resource);
10
+ get instance(): {} | undefined;
11
+ get kind(): OpraSchema.ResourceKind;
12
+ get description(): string | undefined;
13
+ toString(): string;
14
+ validateQueryOptions(): any;
15
+ getSchema(jsonOnly?: boolean): OpraSchema.Resource;
16
+ [nodeInspectCustom](): string;
17
+ }
@@ -0,0 +1,35 @@
1
+ import { cloneObject } from '../../utils/clone-object.util.js';
2
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../../utils/inspect.util.js';
3
+ export class ResourceInfo {
4
+ metadata;
5
+ document;
6
+ name;
7
+ path;
8
+ constructor(document, name, metadata) {
9
+ this.document = document;
10
+ this.name = name;
11
+ this.metadata = metadata;
12
+ }
13
+ get instance() {
14
+ return this.metadata.instance;
15
+ }
16
+ get kind() {
17
+ return this.metadata.kind;
18
+ }
19
+ get description() {
20
+ return this.metadata.description;
21
+ }
22
+ toString() {
23
+ return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
24
+ }
25
+ validateQueryOptions() {
26
+ //
27
+ }
28
+ getSchema(jsonOnly) {
29
+ return cloneObject(this.metadata, jsonOnly);
30
+ }
31
+ [nodeInspectCustom]() {
32
+ return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset}` +
33
+ ` ${colorFgMagenta + this.name + colorReset}]`;
34
+ }
35
+ }
@@ -0,0 +1,14 @@
1
+ import { OpraSchema } from '../../opra-schema.definition.js';
2
+ import { ComplexType } from '../data-type/complex-type.js';
3
+ import type { OpraDocument } from '../opra-document.js';
4
+ import { ResourceInfo } from './resource-info.js';
5
+ export declare class SingletonResourceInfo extends ResourceInfo {
6
+ readonly metadata: OpraSchema.SingletonResource;
7
+ readonly dataType: ComplexType;
8
+ constructor(document: OpraDocument, name: string, dataType: ComplexType, metadata: OpraSchema.SingletonResource);
9
+ get create(): OpraSchema.CreateMethodResolver | undefined;
10
+ get delete(): OpraSchema.MethodResolver | undefined;
11
+ get get(): OpraSchema.GetMethodResolver | undefined;
12
+ get update(): OpraSchema.UpdateMethodResolver | undefined;
13
+ getSchema(jsonOnly?: boolean): OpraSchema.SingletonResource;
14
+ }
@@ -0,0 +1,33 @@
1
+ import { singletonMethods } from '../../constants.js';
2
+ import { ComplexType } from '../data-type/complex-type.js';
3
+ import { ResourceInfo } from './resource-info.js';
4
+ export class SingletonResourceInfo extends ResourceInfo {
5
+ dataType;
6
+ constructor(document, name, dataType, metadata) {
7
+ // noinspection SuspiciousTypeOfGuard
8
+ if (!(dataType instanceof ComplexType))
9
+ throw new TypeError(`You should provide a ComplexType as "dataType" argument`);
10
+ super(document, name, metadata);
11
+ this.dataType = dataType;
12
+ }
13
+ get create() {
14
+ return this.metadata.create;
15
+ }
16
+ get delete() {
17
+ return this.metadata.delete;
18
+ }
19
+ get get() {
20
+ return this.metadata.get;
21
+ }
22
+ get update() {
23
+ return this.metadata.update;
24
+ }
25
+ getSchema(jsonOnly) {
26
+ const out = super.getSchema(jsonOnly);
27
+ for (const k of singletonMethods) {
28
+ if (typeof out[k] === 'object' && !Object.keys(out[k]).length)
29
+ out[k] = true;
30
+ }
31
+ return out;
32
+ }
33
+ }
@@ -0,0 +1,3 @@
1
+ import { OpraSchema } from '../../opra-schema.definition.js';
2
+ import { Named } from '../../types.js';
3
+ export declare function extractResourceSchema(instance: object): Promise<Named<OpraSchema.Resource>>;
@@ -0,0 +1,80 @@
1
+ import { collectionMethods, IGNORE_RESOLVER_METHOD, RESOLVER_METADATA, RESOURCE_METADATA, singletonMethods } from '../../constants.js';
2
+ import { OpraSchema } from '../../opra-schema.definition.js';
3
+ import { cloneObject } from '../../utils/clone-object.util.js';
4
+ export async function extractResourceSchema(instance) {
5
+ const proto = Object.getPrototypeOf(instance);
6
+ const ctor = proto.constructor;
7
+ const metadata = Reflect.getMetadata(RESOURCE_METADATA, ctor);
8
+ if (!metadata)
9
+ throw new TypeError(`Class "${ctor.name}" doesn't have "Resource" metadata information`);
10
+ const schema = cloneObject(metadata);
11
+ schema.instance = instance;
12
+ schema.name = metadata.name || ctor.name.replace(/(Resource|Controller)$/, '');
13
+ if (OpraSchema.isCollectionResource(metadata))
14
+ return await processCollectionResource(schema);
15
+ if (OpraSchema.isSingletonResource(metadata))
16
+ return await processSingletonResource(schema);
17
+ throw new TypeError(`Invalid Resource metadata`);
18
+ }
19
+ async function processCollectionResource(schema) {
20
+ const instance = schema.instance;
21
+ const proto = Object.getPrototypeOf(schema.instance);
22
+ let methodMetadata;
23
+ let fn;
24
+ const locateFn = (inst, methodName) => {
25
+ fn = inst[methodName];
26
+ methodMetadata = Reflect.getMetadata(RESOLVER_METADATA, inst, methodName);
27
+ if (fn == null) {
28
+ if (methodMetadata) {
29
+ inst = Object.getPrototypeOf(inst);
30
+ fn = inst[methodName];
31
+ }
32
+ }
33
+ };
34
+ for (const methodName of collectionMethods) {
35
+ locateFn(instance, methodName);
36
+ if (typeof fn !== 'function')
37
+ continue;
38
+ const info = schema[methodName] = {
39
+ ...methodMetadata
40
+ };
41
+ if (!Reflect.hasMetadata(IGNORE_RESOLVER_METHOD, proto.constructor, methodName)) {
42
+ info.handler = fn.bind(instance);
43
+ fn = instance['pre_' + methodName];
44
+ if (typeof fn === 'function')
45
+ schema['pre_' + methodName] = fn.bind(instance);
46
+ }
47
+ }
48
+ return schema;
49
+ }
50
+ async function processSingletonResource(schema) {
51
+ const instance = schema.instance;
52
+ const proto = Object.getPrototypeOf(schema.instance);
53
+ let methodMetadata;
54
+ let fn;
55
+ const locateFn = (inst, methodName) => {
56
+ fn = inst[methodName];
57
+ methodMetadata = Reflect.getMetadata(RESOLVER_METADATA, inst, methodName);
58
+ if (fn == null) {
59
+ if (methodMetadata) {
60
+ inst = Object.getPrototypeOf(inst);
61
+ fn = inst[methodName];
62
+ }
63
+ }
64
+ };
65
+ for (const methodName of singletonMethods) {
66
+ locateFn(instance, methodName);
67
+ if (typeof fn !== 'function')
68
+ continue;
69
+ const info = schema[methodName] = {
70
+ ...methodMetadata
71
+ };
72
+ if (!Reflect.hasMetadata(IGNORE_RESOLVER_METHOD, proto.constructor, methodName)) {
73
+ info.handler = fn.bind(instance);
74
+ fn = instance['pre_' + methodName];
75
+ if (typeof fn === 'function')
76
+ schema['pre_' + methodName] = fn.bind(instance);
77
+ }
78
+ }
79
+ return schema;
80
+ }
@@ -0,0 +1,4 @@
1
+ import { Type } from 'ts-gems';
2
+ import { OpraSchema } from '../../opra-schema.definition.js';
3
+ import { Named } from '../../types.js';
4
+ export declare function extractDataTypeSchema(ctor: Type | Function): Promise<Named<OpraSchema.DataType>>;
@@ -0,0 +1,89 @@
1
+ import * as Optionals from '@opra/optionals';
2
+ import { COMPLEXTYPE_FIELDS, DATATYPE_METADATA, MAPPED_TYPE_METADATA } from '../../constants.js';
3
+ import { OpraSchema } from '../../opra-schema.definition.js';
4
+ import { cloneObject } from '../../utils/clone-object.util.js';
5
+ import { primitiveClasses } from '../data-type/builtin-data-types.js';
6
+ export async function extractDataTypeSchema(ctor) {
7
+ const metadata = Reflect.getMetadata(DATATYPE_METADATA, ctor);
8
+ if (!metadata)
9
+ throw new TypeError(`Class "${ctor}" doesn't have "DataType" metadata information`);
10
+ if (OpraSchema.isComplexType(metadata))
11
+ return await extractComplexTypeSchema(ctor, metadata);
12
+ if (OpraSchema.isSimpleType(metadata))
13
+ return await extractSimpleTypeSchema(ctor, metadata);
14
+ throw new TypeError(`Invalid DataType metadata`);
15
+ }
16
+ async function extractSimpleTypeSchema(ctor, metadata) {
17
+ const out = cloneObject(metadata);
18
+ out.ctor = ctor;
19
+ return out;
20
+ }
21
+ async function extractComplexTypeSchema(ctor, metadata) {
22
+ const out = cloneObject(metadata);
23
+ out.ctor = ctor;
24
+ const mappedTypeMetadata = Reflect.getMetadata(MAPPED_TYPE_METADATA, ctor);
25
+ if (mappedTypeMetadata) {
26
+ out.extends = [...mappedTypeMetadata.map(x => cloneObject(x))];
27
+ }
28
+ const fields = Reflect.getMetadata(COMPLEXTYPE_FIELDS, ctor);
29
+ if (fields) {
30
+ out.fields = cloneObject(fields);
31
+ for (const [fieldName, field] of Object.entries(out.fields)) {
32
+ if (typeof field.type === 'function') {
33
+ const type = primitiveClasses.get(field.type);
34
+ if (type)
35
+ field.type = type;
36
+ }
37
+ let sqbField;
38
+ if (Optionals.SqbConnect) {
39
+ const { EntityMetadata, isAssociationField } = Optionals.SqbConnect;
40
+ const meta = EntityMetadata.get(ctor);
41
+ sqbField = meta && EntityMetadata.getField(meta, fieldName);
42
+ if (sqbField) {
43
+ if (field.type === Function || field.type === 'object' ||
44
+ field.type === Object || field.type === 'any') {
45
+ field.type = 'any';
46
+ if (isAssociationField(sqbField)) {
47
+ if (!sqbField.association.returnsMany())
48
+ delete field.isArray;
49
+ const trg = await sqbField.association.resolveTarget();
50
+ if (trg) {
51
+ field.type = trg.ctor;
52
+ }
53
+ }
54
+ }
55
+ if (sqbField.exclusive && field.exclusive === undefined)
56
+ field.exclusive = sqbField.exclusive;
57
+ }
58
+ }
59
+ if (sqbField && sqbField.kind === 'column') {
60
+ const DataType = Optionals.SqbConnect.DataType;
61
+ if (field.type === 'number' || field.type === Number) {
62
+ switch (sqbField.dataType) {
63
+ case DataType.INTEGER:
64
+ case DataType.SMALLINT:
65
+ field.type = 'integer';
66
+ break;
67
+ case DataType.BIGINT:
68
+ field.type = 'bigint';
69
+ break;
70
+ }
71
+ }
72
+ else if (field.type === 'string' || field.type === String) {
73
+ switch (sqbField.dataType) {
74
+ case DataType.GUID:
75
+ field.type = 'guid';
76
+ break;
77
+ }
78
+ }
79
+ if (sqbField.notNull && field.required === undefined)
80
+ field.required = sqbField.notNull;
81
+ if (sqbField.exclusive && field.exclusive === undefined)
82
+ field.exclusive = sqbField.exclusive;
83
+ if (sqbField.default !== undefined && field.default === undefined)
84
+ field.default = sqbField.default;
85
+ }
86
+ }
87
+ }
88
+ return out;
89
+ }