@opra/common 0.13.0 → 0.15.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 (476) hide show
  1. package/cjs/document/api-document.js +211 -0
  2. package/cjs/document/constants.js +6 -0
  3. package/cjs/document/data-type/api-field.js +82 -0
  4. package/cjs/document/data-type/builtin/any.type.js +14 -0
  5. package/cjs/document/data-type/builtin/base64.type.js +38 -0
  6. package/cjs/document/data-type/builtin/bigint.type.js +33 -0
  7. package/cjs/document/data-type/builtin/boolean.type.js +28 -0
  8. package/cjs/document/data-type/builtin/date.type.js +18 -0
  9. package/cjs/document/data-type/builtin/guid.type.js +35 -0
  10. package/cjs/document/data-type/builtin/index.js +13 -0
  11. package/cjs/document/data-type/builtin/integer.type.js +28 -0
  12. package/cjs/document/data-type/builtin/number.type.js +33 -0
  13. package/cjs/document/data-type/builtin/object.type.js +20 -0
  14. package/cjs/document/data-type/builtin/string.type.js +24 -0
  15. package/cjs/document/data-type/builtin/time.type.js +32 -0
  16. package/cjs/document/data-type/builtin/timestamp.type.js +29 -0
  17. package/cjs/document/data-type/complex-type.js +154 -0
  18. package/cjs/document/data-type/data-type.js +46 -0
  19. package/cjs/document/data-type/enum-type.js +62 -0
  20. package/cjs/document/data-type/mapped-type.js +96 -0
  21. package/cjs/document/data-type/simple-type.js +61 -0
  22. package/cjs/document/data-type/union-type.js +81 -0
  23. package/cjs/document/factory/add-references.js +20 -0
  24. package/cjs/document/factory/create-document.js +81 -0
  25. package/cjs/document/factory/factory.js +62 -0
  26. package/cjs/document/factory/import-resource-class.js +53 -0
  27. package/cjs/document/factory/import-type-class.js +130 -0
  28. package/cjs/document/factory/index.js +4 -0
  29. package/cjs/document/factory/process-resources.js +55 -0
  30. package/cjs/document/factory/process-types.js +191 -0
  31. package/cjs/document/index.js +17 -0
  32. package/cjs/document/resource/collection.js +185 -0
  33. package/cjs/document/resource/resource.js +38 -0
  34. package/cjs/document/resource/singleton.js +91 -0
  35. package/cjs/exception/opra-exception.js +2 -0
  36. package/cjs/exception/resource-errors/resource-not-found.error.js +4 -0
  37. package/cjs/filter/parse.js +3 -1
  38. package/cjs/helpers/function-utils.js +25 -0
  39. package/cjs/helpers/get-stack-filename.js +24 -0
  40. package/cjs/helpers/index.js +7 -0
  41. package/cjs/{utils → helpers}/is-url.js +2 -2
  42. package/cjs/{schema/utils/clone-object.util.js → helpers/object-utils.js} +13 -1
  43. package/cjs/{utils/path-to-tree.js → helpers/path-to-object-tree.js} +9 -9
  44. package/cjs/helpers/responsive-map.js +62 -14
  45. package/cjs/{utils → helpers}/type-guards.js +12 -5
  46. package/cjs/http/{param-codec → codecs}/boolean-codec.js +1 -2
  47. package/cjs/http/{param-codec → codecs}/date-codec.js +1 -4
  48. package/cjs/http/{param-codec → codecs}/filter-codec.js +1 -2
  49. package/cjs/http/{param-codec → codecs}/number-codec.js +1 -3
  50. package/cjs/http/{param-codec → codecs}/string-codec.js +1 -3
  51. package/cjs/http/enums/http-headers-codes.enum.js +13 -4
  52. package/cjs/http/enums/http-status-messages.js +68 -0
  53. package/cjs/http/http-headers.js +138 -124
  54. package/cjs/http/http-message.host.js +251 -0
  55. package/cjs/http/http-params.js +78 -45
  56. package/cjs/http/http-request-message.js +152 -0
  57. package/cjs/http/http-response-message.js +238 -0
  58. package/cjs/http/index.js +8 -11
  59. package/cjs/http/multipart/batch-multipart.js +169 -153
  60. package/cjs/http/multipart/http-request-content.js +16 -11
  61. package/cjs/http/multipart/http-response-content.js +13 -10
  62. package/cjs/http/multipart/index.js +1 -3
  63. package/cjs/i18n/i18n.js +1 -1
  64. package/cjs/index.js +6 -5
  65. package/cjs/schema/constants.js +2 -9
  66. package/cjs/schema/data-type/complex-type.interface.js +7 -0
  67. package/cjs/schema/data-type/enum-type.interface.js +7 -0
  68. package/cjs/schema/data-type/mapped-type.interface.js +7 -0
  69. package/cjs/schema/data-type/simple-type.interface.js +7 -0
  70. package/cjs/schema/data-type/union-type.interface.js +7 -0
  71. package/cjs/schema/index.js +42 -26
  72. package/cjs/schema/resource/collection.interface.js +7 -0
  73. package/cjs/schema/resource/container.interface.js +7 -0
  74. package/cjs/schema/resource/resource.interface.js +2 -0
  75. package/cjs/schema/resource/singleton.interface.js +7 -0
  76. package/cjs/schema/type-guards.js +59 -0
  77. package/cjs/types.js +2 -0
  78. package/cjs/url/index.js +2 -2
  79. package/cjs/url/opra-url-path-component.js +2 -2
  80. package/cjs/url/opra-url-path.js +7 -4
  81. package/cjs/url/opra-url.js +84 -115
  82. package/cjs/url/utils/{path-utils.js → decode-path-component.js} +1 -46
  83. package/cjs/url/utils/encode-path-component.js +27 -0
  84. package/cjs/utils/path-utils.js +24 -0
  85. package/esm/document/api-document.d.ts +102 -0
  86. package/esm/document/api-document.js +207 -0
  87. package/esm/document/constants.d.ts +3 -0
  88. package/esm/document/constants.js +3 -0
  89. package/esm/document/data-type/api-field.d.ts +41 -0
  90. package/esm/document/data-type/api-field.js +79 -0
  91. package/esm/document/data-type/builtin/any.type.d.ts +2 -0
  92. package/esm/document/data-type/builtin/any.type.js +11 -0
  93. package/esm/document/data-type/builtin/base64.type.d.ts +6 -0
  94. package/esm/document/data-type/builtin/base64.type.js +35 -0
  95. package/esm/document/data-type/builtin/bigint.type.d.ts +6 -0
  96. package/esm/document/data-type/builtin/bigint.type.js +30 -0
  97. package/esm/document/data-type/builtin/boolean.type.d.ts +5 -0
  98. package/esm/document/data-type/builtin/boolean.type.js +25 -0
  99. package/esm/document/data-type/builtin/date.type.d.ts +4 -0
  100. package/esm/document/data-type/builtin/date.type.js +15 -0
  101. package/esm/document/data-type/builtin/guid.type.d.ts +7 -0
  102. package/esm/document/data-type/builtin/guid.type.js +32 -0
  103. package/esm/document/data-type/builtin/index.d.ts +10 -0
  104. package/esm/document/data-type/builtin/index.js +10 -0
  105. package/esm/document/data-type/builtin/integer.type.d.ts +6 -0
  106. package/esm/document/data-type/builtin/integer.type.js +25 -0
  107. package/esm/document/data-type/builtin/number.type.d.ts +6 -0
  108. package/esm/document/data-type/builtin/number.type.js +30 -0
  109. package/esm/document/data-type/builtin/object.type.d.ts +3 -0
  110. package/esm/document/data-type/builtin/object.type.js +17 -0
  111. package/esm/document/data-type/builtin/string.type.d.ts +5 -0
  112. package/esm/document/data-type/builtin/string.type.js +21 -0
  113. package/esm/document/data-type/builtin/time.type.d.ts +7 -0
  114. package/esm/document/data-type/builtin/time.type.js +29 -0
  115. package/esm/document/data-type/builtin/timestamp.type.d.ts +5 -0
  116. package/esm/document/data-type/builtin/timestamp.type.js +26 -0
  117. package/esm/document/data-type/complex-type.d.ts +50 -0
  118. package/esm/document/data-type/complex-type.js +150 -0
  119. package/esm/document/data-type/data-type.d.ts +33 -0
  120. package/esm/document/data-type/data-type.js +43 -0
  121. package/esm/document/data-type/enum-type.d.ts +32 -0
  122. package/esm/document/data-type/enum-type.js +58 -0
  123. package/esm/document/data-type/mapped-type.d.ts +53 -0
  124. package/esm/document/data-type/mapped-type.js +91 -0
  125. package/esm/document/data-type/simple-type.d.ts +33 -0
  126. package/esm/document/data-type/simple-type.js +57 -0
  127. package/esm/document/data-type/union-type.d.ts +42 -0
  128. package/esm/document/data-type/union-type.js +78 -0
  129. package/esm/document/factory/add-references.d.ts +4 -0
  130. package/esm/document/factory/add-references.js +16 -0
  131. package/esm/document/factory/create-document.d.ts +12 -0
  132. package/esm/document/factory/create-document.js +75 -0
  133. package/esm/document/factory/factory.d.ts +61 -0
  134. package/esm/document/factory/factory.js +58 -0
  135. package/esm/document/factory/import-resource-class.d.ts +9 -0
  136. package/esm/document/factory/import-resource-class.js +47 -0
  137. package/esm/document/factory/import-type-class.d.ts +17 -0
  138. package/esm/document/factory/import-type-class.js +120 -0
  139. package/esm/document/factory/index.d.ts +1 -0
  140. package/esm/document/factory/index.js +1 -0
  141. package/esm/document/factory/process-resources.d.ts +7 -0
  142. package/esm/document/factory/process-resources.js +49 -0
  143. package/esm/document/factory/process-types.d.ts +6 -0
  144. package/esm/document/factory/process-types.js +185 -0
  145. package/esm/document/index.d.ts +14 -0
  146. package/esm/document/index.js +14 -0
  147. package/esm/document/resource/collection.d.ts +67 -0
  148. package/esm/document/resource/collection.js +181 -0
  149. package/esm/document/resource/resource.d.ts +29 -0
  150. package/esm/document/resource/resource.js +35 -0
  151. package/esm/document/resource/singleton.d.ts +49 -0
  152. package/esm/document/resource/singleton.js +87 -0
  153. package/esm/exception/opra-exception.js +2 -0
  154. package/esm/exception/resource-errors/resource-not-found.error.d.ts +4 -0
  155. package/esm/exception/resource-errors/resource-not-found.error.js +4 -0
  156. package/esm/filter/parse.js +3 -1
  157. package/esm/helpers/function-utils.d.ts +4 -0
  158. package/esm/helpers/function-utils.js +19 -0
  159. package/esm/helpers/get-stack-filename.d.ts +1 -0
  160. package/esm/helpers/get-stack-filename.js +20 -0
  161. package/esm/helpers/index.d.ts +7 -0
  162. package/esm/helpers/index.js +7 -0
  163. package/esm/helpers/is-url.d.ts +1 -0
  164. package/esm/helpers/is-url.js +4 -0
  165. package/esm/{schema/utils/clone-object.util.d.ts → helpers/object-utils.d.ts} +1 -0
  166. package/esm/{schema/utils/clone-object.util.js → helpers/object-utils.js} +11 -0
  167. package/esm/helpers/path-to-object-tree.d.ts +4 -0
  168. package/esm/{utils/path-to-tree.js → helpers/path-to-object-tree.js} +7 -7
  169. package/esm/helpers/responsive-map.d.ts +15 -13
  170. package/esm/helpers/responsive-map.js +62 -14
  171. package/esm/{utils → helpers}/type-guards.d.ts +3 -1
  172. package/esm/{utils → helpers}/type-guards.js +9 -3
  173. package/esm/http/codecs/boolean-codec.d.ts +5 -0
  174. package/esm/http/{param-codec → codecs}/boolean-codec.js +1 -2
  175. package/esm/http/{param-codec → codecs}/date-codec.d.ts +2 -2
  176. package/esm/http/{param-codec → codecs}/date-codec.js +1 -4
  177. package/esm/http/{param-codec → codecs}/filter-codec.d.ts +2 -2
  178. package/esm/http/{param-codec → codecs}/filter-codec.js +1 -2
  179. package/esm/http/codecs/integer-codec.d.ts +11 -0
  180. package/esm/http/codecs/number-codec.d.ts +14 -0
  181. package/esm/http/{param-codec → codecs}/number-codec.js +1 -3
  182. package/esm/http/codecs/string-codec.d.ts +16 -0
  183. package/esm/http/{param-codec → codecs}/string-codec.js +1 -3
  184. package/esm/http/enums/http-headers-codes.enum.d.ts +13 -4
  185. package/esm/http/enums/http-headers-codes.enum.js +13 -4
  186. package/esm/http/enums/http-status-messages.d.ts +65 -0
  187. package/esm/http/enums/http-status-messages.js +65 -0
  188. package/esm/http/http-headers.d.ts +50 -34
  189. package/esm/http/http-headers.js +137 -123
  190. package/esm/http/http-message.host.d.ts +122 -0
  191. package/esm/http/http-message.host.js +246 -0
  192. package/esm/http/http-params.d.ts +43 -29
  193. package/esm/http/http-params.js +75 -43
  194. package/esm/http/http-request-message.d.ts +213 -0
  195. package/esm/http/http-request-message.js +148 -0
  196. package/esm/http/http-response-message.d.ts +318 -0
  197. package/esm/http/http-response-message.js +233 -0
  198. package/esm/http/index.d.ts +8 -11
  199. package/esm/http/index.js +8 -11
  200. package/esm/http/interfaces/cookie-options.interface.d.ts +4 -0
  201. package/esm/http/multipart/batch-multipart.d.ts +0 -31
  202. package/esm/http/multipart/batch-multipart.js +170 -149
  203. package/esm/http/multipart/http-request-content.d.ts +0 -8
  204. package/esm/http/multipart/http-request-content.js +17 -8
  205. package/esm/http/multipart/http-response-content.d.ts +0 -7
  206. package/esm/http/multipart/http-response-content.js +14 -7
  207. package/esm/http/multipart/index.d.ts +0 -1
  208. package/esm/http/multipart/index.js +2 -1
  209. package/esm/i18n/i18n.js +1 -1
  210. package/esm/index.d.ts +6 -5
  211. package/esm/index.js +6 -5
  212. package/esm/schema/constants.d.ts +2 -8
  213. package/esm/schema/constants.js +1 -8
  214. package/esm/schema/data-type/complex-type.interface.d.ts +16 -0
  215. package/esm/schema/data-type/complex-type.interface.js +4 -0
  216. package/esm/schema/data-type/data-type.interface.d.ts +14 -0
  217. package/esm/schema/data-type/enum-type.interface.d.ts +15 -0
  218. package/esm/schema/data-type/enum-type.interface.js +4 -0
  219. package/esm/schema/data-type/field.interface.d.ts +21 -0
  220. package/esm/schema/data-type/mapped-type.interface.d.ts +11 -0
  221. package/esm/schema/data-type/mapped-type.interface.js +4 -0
  222. package/esm/schema/data-type/simple-type.interface.d.ts +18 -0
  223. package/esm/schema/data-type/simple-type.interface.js +4 -0
  224. package/esm/schema/data-type/union-type.interface.d.ts +10 -0
  225. package/esm/schema/data-type/union-type.interface.js +4 -0
  226. package/esm/schema/document.interface.d.ts +34 -0
  227. package/esm/schema/index.d.ts +51 -25
  228. package/esm/schema/index.js +41 -25
  229. package/esm/schema/resource/collection.interface.d.ts +33 -0
  230. package/esm/schema/resource/collection.interface.js +4 -0
  231. package/esm/schema/resource/container.interface.d.ts +9 -0
  232. package/esm/schema/resource/container.interface.js +4 -0
  233. package/esm/schema/resource/endpoint.interface.d.ts +29 -0
  234. package/esm/schema/resource/resource.interface.d.ts +12 -0
  235. package/esm/schema/resource/resource.interface.js +1 -0
  236. package/esm/schema/resource/singleton.interface.d.ts +22 -0
  237. package/esm/schema/resource/singleton.interface.js +4 -0
  238. package/esm/schema/type-guards.d.ts +20 -0
  239. package/esm/schema/type-guards.js +46 -0
  240. package/esm/{schema/types.d.ts → types.d.ts} +0 -3
  241. package/esm/types.js +1 -0
  242. package/esm/url/index.d.ts +2 -2
  243. package/esm/url/index.js +2 -2
  244. package/esm/url/opra-url-path-component.js +1 -1
  245. package/esm/url/opra-url-path.js +6 -3
  246. package/esm/url/opra-url.d.ts +8 -27
  247. package/esm/url/opra-url.js +83 -114
  248. package/esm/url/utils/decode-path-component.d.ts +5 -0
  249. package/esm/url/utils/{path-utils.js → decode-path-component.js} +0 -41
  250. package/esm/url/utils/encode-path-component.d.ts +1 -0
  251. package/esm/url/utils/encode-path-component.js +22 -0
  252. package/esm/utils/path-utils.d.ts +2 -0
  253. package/esm/utils/path-utils.js +19 -0
  254. package/package.json +21 -6
  255. package/cjs/constants.js +0 -1
  256. package/cjs/http/http-param-codec.js +0 -6
  257. package/cjs/http/http-request-node.js +0 -105
  258. package/cjs/http/http-request.js +0 -89
  259. package/cjs/http/http-response.js +0 -23
  260. package/cjs/http/utils/encodeURIParam.js +0 -21
  261. package/cjs/http/utils/normalize-headers.js +0 -28
  262. package/cjs/schema/decorators/opr-collection-resource.decorator.js +0 -24
  263. package/cjs/schema/decorators/opr-complex-type.decorator.js +0 -28
  264. package/cjs/schema/decorators/opr-field.decorator.js +0 -29
  265. package/cjs/schema/decorators/opr-resolver.decorator.js +0 -81
  266. package/cjs/schema/decorators/opr-simple-type.decorator.js +0 -19
  267. package/cjs/schema/decorators/opr-singleton-resource.decorator.js +0 -24
  268. package/cjs/schema/implementation/data-type/builtin/any.type.js +0 -9
  269. package/cjs/schema/implementation/data-type/builtin/base64-binary.type.js +0 -15
  270. package/cjs/schema/implementation/data-type/builtin/bigint.type.js +0 -15
  271. package/cjs/schema/implementation/data-type/builtin/boolean.type.js +0 -15
  272. package/cjs/schema/implementation/data-type/builtin/date-string.type.js +0 -15
  273. package/cjs/schema/implementation/data-type/builtin/date.type.js +0 -15
  274. package/cjs/schema/implementation/data-type/builtin/guid.type.js +0 -15
  275. package/cjs/schema/implementation/data-type/builtin/integer.type.js +0 -15
  276. package/cjs/schema/implementation/data-type/builtin/number.type.js +0 -15
  277. package/cjs/schema/implementation/data-type/builtin/object.type.js +0 -15
  278. package/cjs/schema/implementation/data-type/builtin/string.type.js +0 -15
  279. package/cjs/schema/implementation/data-type/builtin-data-types.js +0 -37
  280. package/cjs/schema/implementation/data-type/complex-type.js +0 -110
  281. package/cjs/schema/implementation/data-type/data-type.js +0 -37
  282. package/cjs/schema/implementation/data-type/simple-type.js +0 -21
  283. package/cjs/schema/implementation/data-type/union-type.js +0 -24
  284. package/cjs/schema/implementation/document-builder.js +0 -140
  285. package/cjs/schema/implementation/opra-document.js +0 -183
  286. package/cjs/schema/implementation/query/collection-count-query.js +0 -17
  287. package/cjs/schema/implementation/query/collection-create-query.js +0 -23
  288. package/cjs/schema/implementation/query/collection-delete-many-query.js +0 -17
  289. package/cjs/schema/implementation/query/collection-delete-query.js +0 -25
  290. package/cjs/schema/implementation/query/collection-get-query.js +0 -32
  291. package/cjs/schema/implementation/query/collection-search-query.js +0 -45
  292. package/cjs/schema/implementation/query/collection-update-many-query.js +0 -18
  293. package/cjs/schema/implementation/query/collection-update-query.js +0 -33
  294. package/cjs/schema/implementation/query/field-get-query.js +0 -34
  295. package/cjs/schema/implementation/query/index.js +0 -22
  296. package/cjs/schema/implementation/query/singleton-get-query.js +0 -22
  297. package/cjs/schema/implementation/resource/collection-resource-info.js +0 -72
  298. package/cjs/schema/implementation/resource/container-resource-info.js +0 -30
  299. package/cjs/schema/implementation/resource/resource-info.js +0 -35
  300. package/cjs/schema/implementation/resource/singleton-resource-info.js +0 -44
  301. package/cjs/schema/implementation/schema-builder/extract-resource-metadata.util.js +0 -84
  302. package/cjs/schema/implementation/schema-builder/extract-type-metadata.util.js +0 -94
  303. package/cjs/schema/opra-schema.definition.js +0 -49
  304. package/cjs/schema/type-helpers/extend-type.helper.js +0 -65
  305. package/cjs/schema/type-helpers/mixin-type.helper.js +0 -46
  306. package/cjs/schema/utils/class.utils.js +0 -8
  307. package/cjs/schema/utils/normalize-field-array.util.js +0 -44
  308. package/cjs/schema/utils/path-to-tree.util.js +0 -26
  309. package/cjs/url/formats/boolean-format.js +0 -25
  310. package/cjs/url/formats/date-format.js +0 -44
  311. package/cjs/url/formats/filter-format.js +0 -18
  312. package/cjs/url/formats/format.js +0 -6
  313. package/cjs/url/formats/integer-format.js +0 -19
  314. package/cjs/url/formats/number-format.js +0 -26
  315. package/cjs/url/formats/string-format.js +0 -25
  316. package/cjs/url/opra-url-search-params.js +0 -28
  317. package/cjs/utils/index.js +0 -6
  318. package/esm/constants.d.ts +0 -0
  319. package/esm/constants.js +0 -1
  320. package/esm/http/http-param-codec.d.ts +0 -4
  321. package/esm/http/http-param-codec.js +0 -2
  322. package/esm/http/http-request-node.d.ts +0 -34
  323. package/esm/http/http-request-node.js +0 -101
  324. package/esm/http/http-request.d.ts +0 -76
  325. package/esm/http/http-request.js +0 -85
  326. package/esm/http/http-response.d.ts +0 -41
  327. package/esm/http/http-response.js +0 -19
  328. package/esm/http/param-codec/boolean-codec.d.ts +0 -5
  329. package/esm/http/param-codec/integer-codec.d.ts +0 -9
  330. package/esm/http/param-codec/number-codec.d.ts +0 -12
  331. package/esm/http/param-codec/string-codec.d.ts +0 -14
  332. package/esm/http/utils/encodeURIParam.d.ts +0 -1
  333. package/esm/http/utils/encodeURIParam.js +0 -17
  334. package/esm/http/utils/normalize-headers.d.ts +0 -1
  335. package/esm/http/utils/normalize-headers.js +0 -24
  336. package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +0 -8
  337. package/esm/schema/decorators/opr-collection-resource.decorator.js +0 -19
  338. package/esm/schema/decorators/opr-complex-type.decorator.d.ts +0 -6
  339. package/esm/schema/decorators/opr-complex-type.decorator.js +0 -23
  340. package/esm/schema/decorators/opr-field.decorator.d.ts +0 -3
  341. package/esm/schema/decorators/opr-field.decorator.js +0 -24
  342. package/esm/schema/decorators/opr-resolver.decorator.d.ts +0 -8
  343. package/esm/schema/decorators/opr-resolver.decorator.js +0 -71
  344. package/esm/schema/decorators/opr-simple-type.decorator.d.ts +0 -6
  345. package/esm/schema/decorators/opr-simple-type.decorator.js +0 -14
  346. package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +0 -8
  347. package/esm/schema/decorators/opr-singleton-resource.decorator.js +0 -19
  348. package/esm/schema/implementation/data-type/builtin/any.type.d.ts +0 -2
  349. package/esm/schema/implementation/data-type/builtin/any.type.js +0 -6
  350. package/esm/schema/implementation/data-type/builtin/base64-binary.type.d.ts +0 -2
  351. package/esm/schema/implementation/data-type/builtin/base64-binary.type.js +0 -12
  352. package/esm/schema/implementation/data-type/builtin/bigint.type.d.ts +0 -2
  353. package/esm/schema/implementation/data-type/builtin/bigint.type.js +0 -12
  354. package/esm/schema/implementation/data-type/builtin/boolean.type.d.ts +0 -2
  355. package/esm/schema/implementation/data-type/builtin/boolean.type.js +0 -12
  356. package/esm/schema/implementation/data-type/builtin/date-string.type.d.ts +0 -2
  357. package/esm/schema/implementation/data-type/builtin/date-string.type.js +0 -12
  358. package/esm/schema/implementation/data-type/builtin/date.type.d.ts +0 -2
  359. package/esm/schema/implementation/data-type/builtin/date.type.js +0 -12
  360. package/esm/schema/implementation/data-type/builtin/guid.type.d.ts +0 -2
  361. package/esm/schema/implementation/data-type/builtin/guid.type.js +0 -12
  362. package/esm/schema/implementation/data-type/builtin/integer.type.d.ts +0 -2
  363. package/esm/schema/implementation/data-type/builtin/integer.type.js +0 -12
  364. package/esm/schema/implementation/data-type/builtin/number.type.d.ts +0 -2
  365. package/esm/schema/implementation/data-type/builtin/number.type.js +0 -12
  366. package/esm/schema/implementation/data-type/builtin/object.type.d.ts +0 -2
  367. package/esm/schema/implementation/data-type/builtin/object.type.js +0 -12
  368. package/esm/schema/implementation/data-type/builtin/string.type.d.ts +0 -2
  369. package/esm/schema/implementation/data-type/builtin/string.type.js +0 -12
  370. package/esm/schema/implementation/data-type/builtin-data-types.d.ts +0 -4
  371. package/esm/schema/implementation/data-type/builtin-data-types.js +0 -34
  372. package/esm/schema/implementation/data-type/complex-type.d.ts +0 -29
  373. package/esm/schema/implementation/data-type/complex-type.js +0 -106
  374. package/esm/schema/implementation/data-type/data-type.d.ts +0 -17
  375. package/esm/schema/implementation/data-type/data-type.js +0 -33
  376. package/esm/schema/implementation/data-type/simple-type.d.ts +0 -12
  377. package/esm/schema/implementation/data-type/simple-type.js +0 -17
  378. package/esm/schema/implementation/data-type/union-type.d.ts +0 -16
  379. package/esm/schema/implementation/data-type/union-type.js +0 -19
  380. package/esm/schema/implementation/document-builder.d.ts +0 -16
  381. package/esm/schema/implementation/document-builder.js +0 -135
  382. package/esm/schema/implementation/opra-document.d.ts +0 -44
  383. package/esm/schema/implementation/opra-document.js +0 -178
  384. package/esm/schema/implementation/query/collection-count-query.d.ts +0 -14
  385. package/esm/schema/implementation/query/collection-count-query.js +0 -13
  386. package/esm/schema/implementation/query/collection-create-query.d.ts +0 -18
  387. package/esm/schema/implementation/query/collection-create-query.js +0 -19
  388. package/esm/schema/implementation/query/collection-delete-many-query.d.ts +0 -14
  389. package/esm/schema/implementation/query/collection-delete-many-query.js +0 -13
  390. package/esm/schema/implementation/query/collection-delete-query.d.ts +0 -10
  391. package/esm/schema/implementation/query/collection-delete-query.js +0 -21
  392. package/esm/schema/implementation/query/collection-get-query.d.ts +0 -21
  393. package/esm/schema/implementation/query/collection-get-query.js +0 -28
  394. package/esm/schema/implementation/query/collection-search-query.d.ts +0 -30
  395. package/esm/schema/implementation/query/collection-search-query.js +0 -41
  396. package/esm/schema/implementation/query/collection-update-many-query.d.ts +0 -15
  397. package/esm/schema/implementation/query/collection-update-many-query.js +0 -14
  398. package/esm/schema/implementation/query/collection-update-query.d.ts +0 -19
  399. package/esm/schema/implementation/query/collection-update-query.js +0 -29
  400. package/esm/schema/implementation/query/field-get-query.d.ts +0 -30
  401. package/esm/schema/implementation/query/field-get-query.js +0 -30
  402. package/esm/schema/implementation/query/index.d.ts +0 -27
  403. package/esm/schema/implementation/query/index.js +0 -17
  404. package/esm/schema/implementation/query/singleton-get-query.d.ts +0 -20
  405. package/esm/schema/implementation/query/singleton-get-query.js +0 -18
  406. package/esm/schema/implementation/resource/collection-resource-info.d.ts +0 -22
  407. package/esm/schema/implementation/resource/collection-resource-info.js +0 -68
  408. package/esm/schema/implementation/resource/container-resource-info.d.ts +0 -13
  409. package/esm/schema/implementation/resource/container-resource-info.js +0 -26
  410. package/esm/schema/implementation/resource/resource-info.d.ts +0 -17
  411. package/esm/schema/implementation/resource/resource-info.js +0 -31
  412. package/esm/schema/implementation/resource/singleton-resource-info.d.ts +0 -15
  413. package/esm/schema/implementation/resource/singleton-resource-info.js +0 -40
  414. package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.d.ts +0 -3
  415. package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.js +0 -80
  416. package/esm/schema/implementation/schema-builder/extract-type-metadata.util.d.ts +0 -4
  417. package/esm/schema/implementation/schema-builder/extract-type-metadata.util.js +0 -90
  418. package/esm/schema/interfaces/child-field-query.interface.d.ts +0 -4
  419. package/esm/schema/interfaces/data-type.metadata.d.ts +0 -18
  420. package/esm/schema/interfaces/resource-container.interface.d.ts +0 -8
  421. package/esm/schema/interfaces/resource.metadata.d.ts +0 -18
  422. package/esm/schema/opra-schema.definition.d.ts +0 -178
  423. package/esm/schema/opra-schema.definition.js +0 -46
  424. package/esm/schema/type-helpers/extend-type.helper.d.ts +0 -3
  425. package/esm/schema/type-helpers/extend-type.helper.js +0 -60
  426. package/esm/schema/type-helpers/mixin-type.helper.d.ts +0 -2
  427. package/esm/schema/type-helpers/mixin-type.helper.js +0 -42
  428. package/esm/schema/utils/class.utils.d.ts +0 -2
  429. package/esm/schema/utils/class.utils.js +0 -4
  430. package/esm/schema/utils/normalize-field-array.util.d.ts +0 -3
  431. package/esm/schema/utils/normalize-field-array.util.js +0 -40
  432. package/esm/schema/utils/path-to-tree.util.d.ts +0 -4
  433. package/esm/schema/utils/path-to-tree.util.js +0 -22
  434. package/esm/url/formats/boolean-format.d.ts +0 -5
  435. package/esm/url/formats/boolean-format.js +0 -21
  436. package/esm/url/formats/date-format.d.ts +0 -16
  437. package/esm/url/formats/date-format.js +0 -40
  438. package/esm/url/formats/filter-format.d.ts +0 -6
  439. package/esm/url/formats/filter-format.js +0 -14
  440. package/esm/url/formats/format.d.ts +0 -4
  441. package/esm/url/formats/format.js +0 -2
  442. package/esm/url/formats/integer-format.d.ts +0 -9
  443. package/esm/url/formats/integer-format.js +0 -15
  444. package/esm/url/formats/number-format.d.ts +0 -12
  445. package/esm/url/formats/number-format.js +0 -22
  446. package/esm/url/formats/string-format.d.ts +0 -14
  447. package/esm/url/formats/string-format.js +0 -21
  448. package/esm/url/opra-url-search-params.d.ts +0 -5
  449. package/esm/url/opra-url-search-params.js +0 -24
  450. package/esm/url/utils/path-utils.d.ts +0 -8
  451. package/esm/utils/index.d.ts +0 -3
  452. package/esm/utils/index.js +0 -3
  453. package/esm/utils/is-url.d.ts +0 -1
  454. package/esm/utils/is-url.js +0 -4
  455. package/esm/utils/path-to-tree.d.ts +0 -4
  456. /package/cjs/{schema → document}/utils/inspect.util.js +0 -0
  457. /package/cjs/{schema → document}/utils/string-compare.util.js +0 -0
  458. /package/cjs/{schema/type-helpers/mixin.utils.js → helpers/mixin-utils.js} +0 -0
  459. /package/cjs/http/{param-codec → codecs}/integer-codec.js +0 -0
  460. /package/cjs/{schema/interfaces/child-field-query.interface.js → http/interfaces/cookie-options.interface.js} +0 -0
  461. /package/cjs/schema/{interfaces/data-type.metadata.js → data-type/data-type.interface.js} +0 -0
  462. /package/cjs/schema/{interfaces/resource-container.interface.js → data-type/field.interface.js} +0 -0
  463. /package/cjs/schema/{interfaces/resource.metadata.js → document.interface.js} +0 -0
  464. /package/cjs/schema/{types.js → resource/endpoint.interface.js} +0 -0
  465. /package/esm/{schema → document}/utils/inspect.util.d.ts +0 -0
  466. /package/esm/{schema → document}/utils/inspect.util.js +0 -0
  467. /package/esm/{schema → document}/utils/string-compare.util.d.ts +0 -0
  468. /package/esm/{schema → document}/utils/string-compare.util.js +0 -0
  469. /package/esm/{schema/type-helpers/mixin.utils.d.ts → helpers/mixin-utils.d.ts} +0 -0
  470. /package/esm/{schema/type-helpers/mixin.utils.js → helpers/mixin-utils.js} +0 -0
  471. /package/esm/http/{param-codec → codecs}/integer-codec.js +0 -0
  472. /package/esm/{schema/interfaces/child-field-query.interface.js → http/interfaces/cookie-options.interface.js} +0 -0
  473. /package/esm/schema/{interfaces/data-type.metadata.js → data-type/data-type.interface.js} +0 -0
  474. /package/esm/schema/{interfaces/resource-container.interface.js → data-type/field.interface.js} +0 -0
  475. /package/esm/schema/{interfaces/resource.metadata.js → document.interface.js} +0 -0
  476. /package/esm/schema/{types.js → resource/endpoint.interface.js} +0 -0
@@ -0,0 +1,102 @@
1
+ import { Type } from 'ts-gems';
2
+ import { ResponsiveMap } from '../helpers/index.js';
3
+ import { OpraSchema } from '../schema/index.js';
4
+ import { ComplexType } from './data-type/complex-type.js';
5
+ import type { DataType } from './data-type/data-type.js';
6
+ import { SimpleType } from './data-type/simple-type.js';
7
+ import type { Collection } from './resource/collection.js';
8
+ import { Resource } from './resource/resource.js';
9
+ import { Singleton } from './resource/singleton.js';
10
+ export declare class ApiDocument {
11
+ protected _typeCache: ResponsiveMap<DataType | null>;
12
+ protected _typesCacheByCtor: Map<object | Type<any>, DataType | null>;
13
+ url?: string;
14
+ info: OpraSchema.DocumentInfo;
15
+ references: ResponsiveMap<ApiDocument>;
16
+ types: ResponsiveMap<DataType>;
17
+ resources: ResponsiveMap<Resource>;
18
+ constructor();
19
+ /**
20
+ * Returns DataType instance by name or Constructor. Returns undefined if not found
21
+ * @param nameOrCtor
22
+ * @param silent
23
+ */
24
+ getDataType(nameOrCtor: string | Type | object, silent: true): DataType | undefined;
25
+ /**
26
+ * Returns DataType instance by name or Constructor. Throws error if not found
27
+ * @param nameOrCtor
28
+ */
29
+ getDataType(nameOrCtor: string | Type | object): DataType;
30
+ /**
31
+ * Returns ComplexType instance by name or Constructor.
32
+ * Returns undefined if not found
33
+ * Throws error if data type is not a ComplexType
34
+ * @param nameOrCtor
35
+ * @param silent
36
+ */
37
+ getComplexType(nameOrCtor: string | Type, silent: true): ComplexType | undefined;
38
+ /**
39
+ * Returns ComplexType instance by name or Constructor.
40
+ * Throws error undefined if not found or data type is not a ComplexType
41
+ * @param nameOrCtor
42
+ */
43
+ getComplexType(nameOrCtor: string | Type): ComplexType;
44
+ /**
45
+ * Returns SimpleType instance by name or Constructor.
46
+ * Returns undefined if not found
47
+ * Throws error if data type is not a SimpleType
48
+ * @param nameOrCtor
49
+ * @param silent
50
+ */
51
+ getSimpleType(nameOrCtor: string | Type, silent: true): SimpleType | undefined;
52
+ /**
53
+ Returns SimpleType instance by name or Constructor.
54
+ Throws error undefined if not found or data type is not a SimpleType
55
+ * @param nameOrCtor
56
+ */
57
+ getSimpleType(nameOrCtor: string | Type): SimpleType;
58
+ /**
59
+ * Returns Resource instance by path. Returns undefined if not found
60
+ * @param path
61
+ * @param silent
62
+ */
63
+ getResource(path: string, silent: boolean): Resource | undefined;
64
+ /**
65
+ * Returns Resource instance by path. Throws error if not found
66
+ * @param path
67
+ */
68
+ getResource(path: string): Resource;
69
+ /**
70
+ * Returns Collection resource instance by path
71
+ * Returns undefined if not found
72
+ * Throws error if resource is not a Collection
73
+ * @param path
74
+ * @param silent
75
+ */
76
+ getCollection(path: string, silent: true): Collection | undefined;
77
+ /**
78
+ * Returns ComplexType instance by name or Constructor.
79
+ * Throws error undefined if not found or data type is not a ComplexType
80
+ * @param path
81
+ */
82
+ getCollection(path: string): Collection;
83
+ /**
84
+ * Returns Singleton resource instance by path
85
+ * Returns undefined if not found
86
+ * Throws error if resource is not a Collection
87
+ * @param path
88
+ * @param silent
89
+ */
90
+ getSingleton(path: string, silent: true): Singleton | undefined;
91
+ /**
92
+ * Returns ComplexType instance by name or Constructor.
93
+ * Throws error undefined if not found or data type is not a ComplexType
94
+ * @param path
95
+ */
96
+ getSingleton(path: string): Singleton;
97
+ /**
98
+ * Export as Opra schema definition object
99
+ */
100
+ exportSchema(): OpraSchema.ApiDocument;
101
+ invalidate(): void;
102
+ }
@@ -0,0 +1,207 @@
1
+ import { NotAcceptableError, NotFoundError } from '../exception/index.js';
2
+ import { cloneObject, omitUndefined, ResponsiveMap } from '../helpers/index.js';
3
+ import { OpraSchema } from '../schema/index.js';
4
+ import { NAMESPACE_PATTERN } from './constants.js';
5
+ import { ComplexType } from './data-type/complex-type.js';
6
+ import { SimpleType } from './data-type/simple-type.js';
7
+ export class ApiDocument {
8
+ constructor() {
9
+ this._typeCache = new ResponsiveMap();
10
+ this._typesCacheByCtor = new Map();
11
+ this.references = new ResponsiveMap();
12
+ this.types = new ResponsiveMap();
13
+ this.resources = new ResponsiveMap();
14
+ this.info = {
15
+ version: '',
16
+ title: ''
17
+ };
18
+ }
19
+ getDataType(nameOrCtor, silent) {
20
+ let dataType;
21
+ if (nameOrCtor === Object)
22
+ nameOrCtor = 'any';
23
+ const nameOrCtorName = typeof nameOrCtor === 'function' ? nameOrCtor.name : nameOrCtor;
24
+ // Try to get instance from cache
25
+ const t = typeof nameOrCtor === 'string'
26
+ ? this._typeCache.get(nameOrCtor)
27
+ : this._typesCacheByCtor.get(nameOrCtor);
28
+ if (t)
29
+ return t;
30
+ if (t === null) {
31
+ if (silent)
32
+ return;
33
+ throw new NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
34
+ }
35
+ if (typeof nameOrCtor === 'string') {
36
+ const m = NAMESPACE_PATTERN.exec(nameOrCtor);
37
+ if (!m)
38
+ throw new NotFoundError(`Invalid data type name "${nameOrCtorName}"`);
39
+ // If given string has namespace pattern (ns:type_name)
40
+ if (m[2]) {
41
+ const ref = this.references.get(m[1]);
42
+ if (!ref) {
43
+ if (silent)
44
+ return;
45
+ throw new NotFoundError(`Reference "${m[1]}" not found`);
46
+ }
47
+ dataType = ref.getDataType(m[2]);
48
+ this._typeCache.set(nameOrCtor, dataType);
49
+ }
50
+ else {
51
+ const name = m[1];
52
+ // Get instance from own types
53
+ dataType = this.types.get(name);
54
+ // if not found, search in references (from last to first)
55
+ if (!dataType) {
56
+ const references = Array.from(this.references.values()).reverse();
57
+ for (const ref of references) {
58
+ dataType = ref.getDataType(name);
59
+ if (dataType)
60
+ break;
61
+ }
62
+ }
63
+ if (dataType)
64
+ this._typeCache.set(dataType.name || name, dataType);
65
+ }
66
+ }
67
+ else if (typeof nameOrCtor === 'function') {
68
+ const types = Array.from(this.types.values()).reverse();
69
+ for (const dt of types) {
70
+ if ((dt instanceof ComplexType || dt instanceof SimpleType) && dt.own.ctor === nameOrCtor) {
71
+ dataType = dt;
72
+ break;
73
+ }
74
+ }
75
+ // if not found, search in references (from last to first)
76
+ if (!dataType) {
77
+ const references = Array.from(this.references.values()).reverse();
78
+ for (const ref of references) {
79
+ dataType = ref.getDataType(nameOrCtor, true);
80
+ if (dataType)
81
+ break;
82
+ }
83
+ }
84
+ }
85
+ if (dataType) {
86
+ if ((dataType instanceof ComplexType || dataType instanceof SimpleType) &&
87
+ dataType.own?.ctor && dataType.own.ctor !== Object)
88
+ this._typesCacheByCtor.set(dataType.own.ctor, dataType);
89
+ return dataType;
90
+ }
91
+ else {
92
+ if (typeof nameOrCtor === 'string')
93
+ this._typeCache.set(nameOrCtor, null);
94
+ else
95
+ this._typesCacheByCtor.set(nameOrCtor, null);
96
+ }
97
+ if (silent)
98
+ return;
99
+ throw new NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
100
+ }
101
+ getComplexType(nameOrCtor, silent) {
102
+ if (nameOrCtor === Object)
103
+ nameOrCtor = 'object';
104
+ const t = this.getDataType(nameOrCtor);
105
+ if (!t && silent)
106
+ return;
107
+ if (t && t.kind === OpraSchema.ComplexType.Kind)
108
+ return t;
109
+ throw new NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
110
+ }
111
+ getSimpleType(nameOrCtor, silent) {
112
+ const t = this.getDataType(nameOrCtor);
113
+ if (!t && silent)
114
+ return;
115
+ if (t && t.kind === OpraSchema.SimpleType.Kind)
116
+ return t;
117
+ throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
118
+ }
119
+ getResource(path, silent) {
120
+ let resource;
121
+ const m = NAMESPACE_PATTERN.exec(path);
122
+ if (!m)
123
+ throw new NotFoundError(`Invalid resource path "${path}"`);
124
+ // If given string has namespace pattern (ns:type_name)
125
+ if (m[2]) {
126
+ const ref = this.references.get(m[1]);
127
+ if (!ref) {
128
+ if (silent)
129
+ return;
130
+ throw new NotFoundError(`Reference "${m[1]}" not found`);
131
+ }
132
+ return ref.getResource(m[2]);
133
+ }
134
+ else {
135
+ const name = m[1];
136
+ // Get instance from own types
137
+ resource = this.resources.get(name);
138
+ if (resource)
139
+ return resource;
140
+ // if not found, search in references (from last to first)
141
+ const references = Array.from(this.references.values()).reverse();
142
+ for (const ref of references) {
143
+ resource = silent ? ref.getResource(name, silent) : ref.getResource(name);
144
+ if (resource)
145
+ return resource;
146
+ }
147
+ }
148
+ if (silent)
149
+ return;
150
+ throw new NotFoundError(`Resource not found (${path})`);
151
+ }
152
+ getCollection(path, silent) {
153
+ const t = this.getResource(path);
154
+ if (!t && silent)
155
+ return;
156
+ if (t && t.kind === OpraSchema.Collection.Kind)
157
+ return t;
158
+ throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
159
+ }
160
+ getSingleton(path, silent) {
161
+ const t = this.getResource(path);
162
+ if (!t && silent)
163
+ return;
164
+ if (t && t.kind === OpraSchema.Singleton.Kind)
165
+ return t;
166
+ throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
167
+ }
168
+ /**
169
+ * Export as Opra schema definition object
170
+ */
171
+ exportSchema() {
172
+ const schema = {
173
+ version: OpraSchema.SpecVersion,
174
+ url: this.url,
175
+ info: cloneObject(this.info)
176
+ };
177
+ if (this.references.size) {
178
+ const references = {};
179
+ let i = 0;
180
+ for (const [ns, r] of this.references.entries()) {
181
+ if (ns.toLowerCase() === 'opra')
182
+ continue;
183
+ references[ns] = r.url ? r.url : r.exportSchema();
184
+ i++;
185
+ }
186
+ if (i)
187
+ schema.references = references;
188
+ }
189
+ if (this.resources.size) {
190
+ const resources = schema.resources = {};
191
+ for (const [name, r] of this.resources.entries()) {
192
+ resources[name] = r.exportSchema();
193
+ }
194
+ }
195
+ if (this.types.size) {
196
+ const types = schema.types = {};
197
+ for (const [name, r] of this.types.entries()) {
198
+ types[name] = r.exportSchema();
199
+ }
200
+ }
201
+ return omitUndefined(schema);
202
+ }
203
+ invalidate() {
204
+ this._typeCache.clear();
205
+ this._typesCacheByCtor.clear();
206
+ }
207
+ }
@@ -0,0 +1,3 @@
1
+ export declare const METADATA_KEY: unique symbol;
2
+ export declare const NAMESPACE_PATTERN: RegExp;
3
+ export declare const TYPENAME_PATTERN: RegExp;
@@ -0,0 +1,3 @@
1
+ export const METADATA_KEY = Symbol.for('opra.metadata');
2
+ export const NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
3
+ export const TYPENAME_PATTERN = /^(.*)Type$/;
@@ -0,0 +1,41 @@
1
+ import { StrictOmit, Type } from 'ts-gems';
2
+ import { OpraSchema } from '../../schema/index.js';
3
+ import { TypeThunkAsync } from '../../types.js';
4
+ import type { ComplexType } from './complex-type.js';
5
+ import { DataType } from './data-type.js';
6
+ export declare namespace ApiField {
7
+ interface InitArguments extends StrictOmit<OpraSchema.Field, 'type'> {
8
+ name: string;
9
+ type: DataType;
10
+ origin?: ComplexType;
11
+ }
12
+ interface DecoratorOptions extends Partial<StrictOmit<OpraSchema.Field, 'isArray' | 'type'>> {
13
+ type?: string | OpraSchema.DataType | TypeThunkAsync;
14
+ enum?: OpraSchema.EnumObject | string[];
15
+ }
16
+ interface Metadata extends StrictOmit<OpraSchema.Field, 'type'> {
17
+ type?: string | OpraSchema.DataType | TypeThunkAsync;
18
+ enum?: OpraSchema.EnumObject;
19
+ designType?: Type;
20
+ }
21
+ }
22
+ export interface ApiField extends StrictOmit<OpraSchema.Field, 'type'> {
23
+ readonly owner: ComplexType;
24
+ readonly origin?: ComplexType;
25
+ readonly type: DataType;
26
+ readonly name: string;
27
+ exportSchema(): OpraSchema.Field;
28
+ }
29
+ /**
30
+ * Type definition of ComplexType constructor type
31
+ * @type ApiFieldConstructor
32
+ */
33
+ export interface ApiFieldConstructor {
34
+ new (owner: ComplexType, init: ApiField.InitArguments): ApiField;
35
+ (options?: ApiField.DecoratorOptions): PropertyDecorator;
36
+ prototype: ApiField;
37
+ }
38
+ /**
39
+ * @class ComplexType
40
+ */
41
+ export declare const ApiField: ApiFieldConstructor;
@@ -0,0 +1,79 @@
1
+ import { omitUndefined } from '../../helpers/index.js';
2
+ import { OpraSchema } from '../../schema/index.js';
3
+ import { METADATA_KEY } from '../constants.js';
4
+ import { EnumType } from './enum-type.js';
5
+ /**
6
+ * @class ComplexType
7
+ */
8
+ export const ApiField = function (...args) {
9
+ // ClassDecorator
10
+ if (!this) {
11
+ const [options] = args;
12
+ return function (target, propertyKey) {
13
+ if (typeof propertyKey !== 'string')
14
+ throw new TypeError(`Symbol properties can't be used as a field`);
15
+ const metadata = Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {};
16
+ metadata.kind = OpraSchema.ComplexType.Kind;
17
+ metadata.fields = metadata.fields || {};
18
+ const designType = Reflect.getMetadata('design:type', target, propertyKey);
19
+ const isArray = designType === Array;
20
+ const elemMeta = metadata.fields[propertyKey] = {
21
+ ...options,
22
+ enum: undefined,
23
+ designType: isArray ? undefined : designType
24
+ };
25
+ if (designType === Array)
26
+ elemMeta.isArray = true;
27
+ if (options?.enum) {
28
+ elemMeta.type = undefined;
29
+ if (Array.isArray(options.enum)) {
30
+ const enumObj = options.enum.reduce((o, v) => {
31
+ o[v] = v;
32
+ return o;
33
+ }, {});
34
+ EnumType(enumObj);
35
+ elemMeta.enum = enumObj;
36
+ }
37
+ else {
38
+ const m = Reflect.getOwnMetadata(METADATA_KEY, options?.enum);
39
+ if (!OpraSchema.isEnumType(m))
40
+ throw new TypeError(`Invalid "enum" value. Did you forget to set metadata using EnumType() method?`);
41
+ elemMeta.enum = options.enum;
42
+ }
43
+ }
44
+ Reflect.defineMetadata(METADATA_KEY, omitUndefined(metadata), target.constructor);
45
+ };
46
+ }
47
+ // Constructor
48
+ const [owner, init] = args;
49
+ const _this = this;
50
+ _this.owner = owner;
51
+ _this.name = init.name;
52
+ _this.origin = init.origin || owner;
53
+ _this.type = init.type;
54
+ if (init?.description)
55
+ this.description = init?.description;
56
+ if (init?.isArray != null)
57
+ this.isArray = init?.isArray;
58
+ this.default = init?.default;
59
+ this.fixed = init?.fixed;
60
+ if (init?.deprecated != null)
61
+ this.deprecated = init?.deprecated;
62
+ if (init?.exclusive != null)
63
+ this.exclusive = init?.exclusive;
64
+ if (init?.required != null)
65
+ this.required = init?.required;
66
+ };
67
+ const proto = {
68
+ exportSchema() {
69
+ const out = {
70
+ type: this.type.name ? this.type.name : this.type.exportSchema(),
71
+ description: this.description,
72
+ isArray: this.isArray,
73
+ default: this.default,
74
+ fixed: this.fixed
75
+ };
76
+ return out;
77
+ }
78
+ };
79
+ Object.assign(ApiField.prototype, proto);
@@ -0,0 +1,2 @@
1
+ export declare class AnyType {
2
+ }
@@ -0,0 +1,11 @@
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
3
+ let AnyType = class AnyType {
4
+ };
5
+ AnyType = __decorate([
6
+ SimpleType({
7
+ description: 'Any value',
8
+ ctor: Object
9
+ })
10
+ ], AnyType);
11
+ export { AnyType };
@@ -0,0 +1,6 @@
1
+ export declare class Base64Type {
2
+ decode(v: any): ArrayBuffer | undefined;
3
+ encode(v: any): string | undefined;
4
+ coerce(v: any): ArrayBuffer | undefined;
5
+ validate(v: any): void;
6
+ }
@@ -0,0 +1,35 @@
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
3
+ const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:(?:[A-Za-z0-9+/][AQgw](:?==)?)|(?:[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=?))?$/;
4
+ let Base64Type = class Base64Type {
5
+ decode(v) {
6
+ if (v == null)
7
+ return v;
8
+ if (typeof v === 'string')
9
+ this.validate(v);
10
+ return Buffer.from(v, 'base64').buffer.slice(0);
11
+ }
12
+ encode(v) {
13
+ if (v == null)
14
+ return v;
15
+ if (Buffer.isBuffer(v))
16
+ return v.toString('base64');
17
+ return Buffer.from(v).toString('base64');
18
+ }
19
+ coerce(v) {
20
+ if (v instanceof ArrayBuffer)
21
+ return v;
22
+ return this.decode(v);
23
+ }
24
+ validate(v) {
25
+ if (!(typeof v === 'string' && BASE64_PATTERN.test(v)))
26
+ throw new TypeError(`Invalid base64 value "${String(v).substring(0, 10)}..."`);
27
+ }
28
+ };
29
+ Base64Type = __decorate([
30
+ SimpleType({
31
+ description: 'A stream of bytes, base64 encoded',
32
+ ctor: ArrayBuffer
33
+ })
34
+ ], Base64Type);
35
+ export { Base64Type };
@@ -0,0 +1,6 @@
1
+ export declare class BigIntType {
2
+ decode(v: any): bigint | undefined;
3
+ encode(v: any): string | undefined;
4
+ coerce(v: any): bigint | undefined;
5
+ validate(v: any): void;
6
+ }
@@ -0,0 +1,30 @@
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
3
+ const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
4
+ let BigIntType = class BigIntType {
5
+ decode(v) {
6
+ if (v == null)
7
+ return v;
8
+ return typeof v === 'bigint' ? v : BigInt(v);
9
+ }
10
+ encode(v) {
11
+ if (v == null)
12
+ return v;
13
+ return typeof v === 'bigint' ? String(v) : undefined;
14
+ }
15
+ coerce(v) {
16
+ return this.decode(v);
17
+ }
18
+ validate(v) {
19
+ if (!((typeof v === 'number' && !isNaN(v)) || typeof v === 'bigint'))
20
+ throw new TypeError(`Invalid number value "${v}"`);
21
+ }
22
+ };
23
+ BigIntType = __decorate([
24
+ SimpleType({
25
+ name: 'bigint',
26
+ description: 'BigInt number',
27
+ ctor: BigIntConstructor
28
+ })
29
+ ], BigIntType);
30
+ export { BigIntType };
@@ -0,0 +1,5 @@
1
+ export declare class BooleanType {
2
+ decode(v: any): boolean | undefined;
3
+ encode(v: any): boolean | undefined;
4
+ coerce(v: any): boolean | undefined;
5
+ }
@@ -0,0 +1,25 @@
1
+ import { __decorate } from "tslib";
2
+ import { toBoolean } from 'putil-varhelpers';
3
+ import { SimpleType } from '../simple-type.js';
4
+ let BooleanType = class BooleanType {
5
+ decode(v) {
6
+ if (v == null)
7
+ return v;
8
+ return toBoolean(v);
9
+ }
10
+ encode(v) {
11
+ if (v == null)
12
+ return v;
13
+ return toBoolean(v);
14
+ }
15
+ coerce(v) {
16
+ return this.decode(v);
17
+ }
18
+ };
19
+ BooleanType = __decorate([
20
+ SimpleType({
21
+ description: 'Simple true/false value',
22
+ ctor: Boolean
23
+ })
24
+ ], BooleanType);
25
+ export { BooleanType };
@@ -0,0 +1,4 @@
1
+ import { TimestampType } from './timestamp.type.js';
2
+ export declare class DateType extends TimestampType {
3
+ format: string;
4
+ }
@@ -0,0 +1,15 @@
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
3
+ import { TimestampType } from './timestamp.type.js';
4
+ let DateType = class DateType extends TimestampType {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.format = 'YYYY-MM-DD';
8
+ }
9
+ };
10
+ DateType = __decorate([
11
+ SimpleType({
12
+ description: 'full-date notation as defined by RFC 3339, section 5.6, for example, 2021-04-18',
13
+ })
14
+ ], DateType);
15
+ export { DateType };
@@ -0,0 +1,7 @@
1
+ import { StringType } from './string.type.js';
2
+ export declare class GuidType extends StringType {
3
+ decode(v: any): string | undefined;
4
+ encode(v: any): string | undefined;
5
+ coerce(v: any): string | undefined;
6
+ validate(v: string): void;
7
+ }
@@ -0,0 +1,32 @@
1
+ import { __decorate } from "tslib";
2
+ import { toString } from 'putil-varhelpers';
3
+ import { SimpleType } from '../simple-type.js';
4
+ import { StringType } from './string.type.js';
5
+ const GUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
6
+ let GuidType = class GuidType extends StringType {
7
+ decode(v) {
8
+ if (v == null)
9
+ return v;
10
+ const s = toString(v);
11
+ if (s)
12
+ this.validate(s);
13
+ return s;
14
+ }
15
+ encode(v) {
16
+ return this.decode(v);
17
+ }
18
+ coerce(v) {
19
+ return this.decode(v);
20
+ }
21
+ validate(v) {
22
+ // noinspection SuspiciousTypeOfGuard
23
+ if (typeof v === 'string' && !GUID_PATTERN.test(v))
24
+ throw new TypeError(`Invalid GUID value "${v}"`);
25
+ }
26
+ };
27
+ GuidType = __decorate([
28
+ SimpleType({
29
+ description: 'A Globally Unique Identifier (GUID) value',
30
+ })
31
+ ], GuidType);
32
+ export { GuidType };
@@ -0,0 +1,10 @@
1
+ export * from './any.type.js';
2
+ export * from './base64.type.js';
3
+ export * from './bigint.type.js';
4
+ export * from './boolean.type.js';
5
+ export * from './date.type.js';
6
+ export * from './guid.type.js';
7
+ export * from './integer.type.js';
8
+ export * from './number.type.js';
9
+ export * from './object.type.js';
10
+ export * from './string.type.js';
@@ -0,0 +1,10 @@
1
+ export * from './any.type.js';
2
+ export * from './base64.type.js';
3
+ export * from './bigint.type.js';
4
+ export * from './boolean.type.js';
5
+ export * from './date.type.js';
6
+ export * from './guid.type.js';
7
+ export * from './integer.type.js';
8
+ export * from './number.type.js';
9
+ export * from './object.type.js';
10
+ export * from './string.type.js';
@@ -0,0 +1,6 @@
1
+ import { NumberType } from './number.type.js';
2
+ export declare class IntegerType extends NumberType {
3
+ decode(v: any): number | undefined;
4
+ encode(v: any): number | undefined;
5
+ coerce(v: any): number | undefined;
6
+ }