mobx-tanstack-query-api 0.24.0 → 0.26.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 (264) hide show
  1. package/builtin.cjs +27 -0
  2. package/builtin.cjs.map +1 -0
  3. package/builtin.d.ts +6 -0
  4. package/builtin.js +27 -0
  5. package/builtin.js.map +1 -0
  6. package/cli.cjs +1279 -0
  7. package/cli.cjs.map +1 -0
  8. package/{codegen/types/generate-query-api-params.d.cts → cli.d.ts} +55 -10
  9. package/cli.js +1278 -0
  10. package/cli.js.map +1 -0
  11. package/index.cjs +771 -16
  12. package/index.cjs.map +1 -0
  13. package/index.d.ts +322 -2
  14. package/index.js +768 -2
  15. package/index.js.map +1 -0
  16. package/package.json +21 -64
  17. package/builtin/index.cjs +0 -25
  18. package/builtin/index.d.cts +0 -4
  19. package/builtin/index.d.cts.map +0 -1
  20. package/builtin/index.d.ts +0 -4
  21. package/builtin/index.d.ts.map +0 -1
  22. package/builtin/index.js +0 -22
  23. package/cli/bin.cjs +0 -17
  24. package/cli/bin.d.cts +0 -2
  25. package/cli/bin.d.cts.map +0 -1
  26. package/cli/bin.d.ts +0 -2
  27. package/cli/bin.d.ts.map +0 -1
  28. package/cli/bin.js +0 -15
  29. package/cli/index.cjs +0 -18
  30. package/cli/index.d.cts +0 -3
  31. package/cli/index.d.cts.map +0 -1
  32. package/cli/index.d.ts +0 -3
  33. package/cli/index.d.ts.map +0 -1
  34. package/cli/index.js +0 -2
  35. package/cli/utils/define-config.cjs +0 -9
  36. package/cli/utils/define-config.d.cts +0 -4
  37. package/cli/utils/define-config.d.cts.map +0 -1
  38. package/cli/utils/define-config.d.ts +0 -4
  39. package/cli/utils/define-config.d.ts.map +0 -1
  40. package/cli/utils/define-config.js +0 -5
  41. package/cli/utils/exec-config-path.cjs +0 -16
  42. package/cli/utils/exec-config-path.d.cts +0 -2
  43. package/cli/utils/exec-config-path.d.cts.map +0 -1
  44. package/cli/utils/exec-config-path.d.ts +0 -2
  45. package/cli/utils/exec-config-path.d.ts.map +0 -1
  46. package/cli/utils/exec-config-path.js +0 -12
  47. package/cli/utils/resolve-config-path.cjs +0 -65
  48. package/cli/utils/resolve-config-path.d.cts +0 -3
  49. package/cli/utils/resolve-config-path.d.cts.map +0 -1
  50. package/cli/utils/resolve-config-path.d.ts +0 -3
  51. package/cli/utils/resolve-config-path.d.ts.map +0 -1
  52. package/cli/utils/resolve-config-path.js +0 -25
  53. package/codegen/index.cjs +0 -545
  54. package/codegen/index.d.cts +0 -4
  55. package/codegen/index.d.cts.map +0 -1
  56. package/codegen/index.d.ts +0 -4
  57. package/codegen/index.d.ts.map +0 -1
  58. package/codegen/index.js +0 -524
  59. package/codegen/templates/all-endpoints-per-file.tmpl.cjs +0 -94
  60. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts +0 -14
  61. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +0 -1
  62. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts +0 -14
  63. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
  64. package/codegen/templates/all-endpoints-per-file.tmpl.js +0 -90
  65. package/codegen/templates/all-exports.tmpl.cjs +0 -14
  66. package/codegen/templates/all-exports.tmpl.d.cts +0 -9
  67. package/codegen/templates/all-exports.tmpl.d.cts.map +0 -1
  68. package/codegen/templates/all-exports.tmpl.d.ts +0 -9
  69. package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
  70. package/codegen/templates/all-exports.tmpl.js +0 -9
  71. package/codegen/templates/constants.cjs +0 -5
  72. package/codegen/templates/constants.d.cts +0 -2
  73. package/codegen/templates/constants.d.cts.map +0 -1
  74. package/codegen/templates/constants.d.ts +0 -2
  75. package/codegen/templates/constants.d.ts.map +0 -1
  76. package/codegen/templates/constants.js +0 -2
  77. package/codegen/templates/data-contract.tmpl.cjs +0 -49
  78. package/codegen/templates/data-contract.tmpl.d.cts +0 -8
  79. package/codegen/templates/data-contract.tmpl.d.cts.map +0 -1
  80. package/codegen/templates/data-contract.tmpl.d.ts +0 -8
  81. package/codegen/templates/data-contract.tmpl.d.ts.map +0 -1
  82. package/codegen/templates/data-contract.tmpl.js +0 -45
  83. package/codegen/templates/data-contracts-file.tmpl.cjs +0 -27
  84. package/codegen/templates/data-contracts-file.tmpl.d.cts +0 -6
  85. package/codegen/templates/data-contracts-file.tmpl.d.cts.map +0 -1
  86. package/codegen/templates/data-contracts-file.tmpl.d.ts +0 -6
  87. package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
  88. package/codegen/templates/data-contracts-file.tmpl.js +0 -23
  89. package/codegen/templates/endpoint-jsdoc.tmpl.cjs +0 -111
  90. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts +0 -8
  91. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +0 -1
  92. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts +0 -8
  93. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
  94. package/codegen/templates/endpoint-jsdoc.tmpl.js +0 -107
  95. package/codegen/templates/endpoint-per-file.tmpl.cjs +0 -87
  96. package/codegen/templates/endpoint-per-file.tmpl.d.cts +0 -14
  97. package/codegen/templates/endpoint-per-file.tmpl.d.cts.map +0 -1
  98. package/codegen/templates/endpoint-per-file.tmpl.d.ts +0 -14
  99. package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
  100. package/codegen/templates/endpoint-per-file.tmpl.js +0 -83
  101. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +0 -10
  102. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +0 -6
  103. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +0 -1
  104. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +0 -6
  105. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +0 -1
  106. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.js +0 -6
  107. package/codegen/templates/meta-info.tmpl.cjs +0 -48
  108. package/codegen/templates/meta-info.tmpl.d.cts +0 -9
  109. package/codegen/templates/meta-info.tmpl.d.cts.map +0 -1
  110. package/codegen/templates/meta-info.tmpl.d.ts +0 -9
  111. package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
  112. package/codegen/templates/meta-info.tmpl.js +0 -42
  113. package/codegen/templates/new-endpoint.tmpl.cjs +0 -188
  114. package/codegen/templates/new-endpoint.tmpl.d.cts +0 -15
  115. package/codegen/templates/new-endpoint.tmpl.d.cts.map +0 -1
  116. package/codegen/templates/new-endpoint.tmpl.d.ts +0 -15
  117. package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
  118. package/codegen/templates/new-endpoint.tmpl.js +0 -184
  119. package/codegen/types/all-import-file-params.cjs +0 -2
  120. package/codegen/types/all-import-file-params.d.cts +0 -5
  121. package/codegen/types/all-import-file-params.d.cts.map +0 -1
  122. package/codegen/types/all-import-file-params.d.ts +0 -5
  123. package/codegen/types/all-import-file-params.d.ts.map +0 -1
  124. package/codegen/types/all-import-file-params.js +0 -1
  125. package/codegen/types/base-tmpl-params.cjs +0 -2
  126. package/codegen/types/base-tmpl-params.d.cts +0 -16
  127. package/codegen/types/base-tmpl-params.d.cts.map +0 -1
  128. package/codegen/types/base-tmpl-params.d.ts +0 -16
  129. package/codegen/types/base-tmpl-params.d.ts.map +0 -1
  130. package/codegen/types/base-tmpl-params.js +0 -1
  131. package/codegen/types/codegen-data-utils.cjs +0 -2
  132. package/codegen/types/codegen-data-utils.d.cts +0 -8
  133. package/codegen/types/codegen-data-utils.d.cts.map +0 -1
  134. package/codegen/types/codegen-data-utils.d.ts +0 -8
  135. package/codegen/types/codegen-data-utils.d.ts.map +0 -1
  136. package/codegen/types/codegen-data-utils.js +0 -1
  137. package/codegen/types/endpoint-data.cjs +0 -2
  138. package/codegen/types/endpoint-data.d.cts +0 -3
  139. package/codegen/types/endpoint-data.d.cts.map +0 -1
  140. package/codegen/types/endpoint-data.d.ts +0 -3
  141. package/codegen/types/endpoint-data.d.ts.map +0 -1
  142. package/codegen/types/endpoint-data.js +0 -1
  143. package/codegen/types/generate-query-api-params.cjs +0 -2
  144. package/codegen/types/generate-query-api-params.d.cts.map +0 -1
  145. package/codegen/types/generate-query-api-params.d.ts +0 -162
  146. package/codegen/types/generate-query-api-params.d.ts.map +0 -1
  147. package/codegen/types/generate-query-api-params.js +0 -1
  148. package/codegen/types/import-file-params.cjs +0 -2
  149. package/codegen/types/import-file-params.d.cts +0 -5
  150. package/codegen/types/import-file-params.d.cts.map +0 -1
  151. package/codegen/types/import-file-params.d.ts +0 -5
  152. package/codegen/types/import-file-params.d.ts.map +0 -1
  153. package/codegen/types/import-file-params.js +0 -1
  154. package/codegen/types/index.cjs +0 -23
  155. package/codegen/types/index.d.cts +0 -8
  156. package/codegen/types/index.d.cts.map +0 -1
  157. package/codegen/types/index.d.ts +0 -8
  158. package/codegen/types/index.d.ts.map +0 -1
  159. package/codegen/types/index.js +0 -7
  160. package/codegen/types/meta-info.cjs +0 -2
  161. package/codegen/types/meta-info.d.cts +0 -6
  162. package/codegen/types/meta-info.d.cts.map +0 -1
  163. package/codegen/types/meta-info.d.ts +0 -6
  164. package/codegen/types/meta-info.d.ts.map +0 -1
  165. package/codegen/types/meta-info.js +0 -1
  166. package/codegen/types/type-info.cjs +0 -2
  167. package/codegen/types/type-info.d.cts +0 -4
  168. package/codegen/types/type-info.d.cts.map +0 -1
  169. package/codegen/types/type-info.d.ts +0 -4
  170. package/codegen/types/type-info.d.ts.map +0 -1
  171. package/codegen/types/type-info.js +0 -1
  172. package/codegen/utils/create-short-model-type.cjs +0 -12
  173. package/codegen/utils/create-short-model-type.d.cts +0 -5
  174. package/codegen/utils/create-short-model-type.d.cts.map +0 -1
  175. package/codegen/utils/create-short-model-type.d.ts +0 -5
  176. package/codegen/utils/create-short-model-type.d.ts.map +0 -1
  177. package/codegen/utils/create-short-model-type.js +0 -8
  178. package/codegen/utils/remove-unused-types.cjs +0 -117
  179. package/codegen/utils/remove-unused-types.d.cts +0 -7
  180. package/codegen/utils/remove-unused-types.d.cts.map +0 -1
  181. package/codegen/utils/remove-unused-types.d.ts +0 -7
  182. package/codegen/utils/remove-unused-types.d.ts.map +0 -1
  183. package/codegen/utils/remove-unused-types.js +0 -110
  184. package/codegen/utils/unpack-filter-option.cjs +0 -23
  185. package/codegen/utils/unpack-filter-option.d.cts +0 -7
  186. package/codegen/utils/unpack-filter-option.d.cts.map +0 -1
  187. package/codegen/utils/unpack-filter-option.d.ts +0 -7
  188. package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
  189. package/codegen/utils/unpack-filter-option.js +0 -19
  190. package/index.d.cts +0 -3
  191. package/index.d.cts.map +0 -1
  192. package/index.d.ts.map +0 -1
  193. package/runtime/endpoint-infinite-query.cjs +0 -101
  194. package/runtime/endpoint-infinite-query.d.cts +0 -17
  195. package/runtime/endpoint-infinite-query.d.cts.map +0 -1
  196. package/runtime/endpoint-infinite-query.d.ts +0 -17
  197. package/runtime/endpoint-infinite-query.d.ts.map +0 -1
  198. package/runtime/endpoint-infinite-query.js +0 -97
  199. package/runtime/endpoint-infinite-query.types.cjs +0 -2
  200. package/runtime/endpoint-infinite-query.types.d.cts +0 -30
  201. package/runtime/endpoint-infinite-query.types.d.cts.map +0 -1
  202. package/runtime/endpoint-infinite-query.types.d.ts +0 -30
  203. package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
  204. package/runtime/endpoint-infinite-query.types.js +0 -1
  205. package/runtime/endpoint-mutation.cjs +0 -74
  206. package/runtime/endpoint-mutation.d.cts +0 -13
  207. package/runtime/endpoint-mutation.d.cts.map +0 -1
  208. package/runtime/endpoint-mutation.d.ts +0 -13
  209. package/runtime/endpoint-mutation.d.ts.map +0 -1
  210. package/runtime/endpoint-mutation.js +0 -70
  211. package/runtime/endpoint-mutation.types.cjs +0 -2
  212. package/runtime/endpoint-mutation.types.d.cts +0 -36
  213. package/runtime/endpoint-mutation.types.d.cts.map +0 -1
  214. package/runtime/endpoint-mutation.types.d.ts +0 -36
  215. package/runtime/endpoint-mutation.types.d.ts.map +0 -1
  216. package/runtime/endpoint-mutation.types.js +0 -1
  217. package/runtime/endpoint-query-client.cjs +0 -79
  218. package/runtime/endpoint-query-client.d.cts +0 -13
  219. package/runtime/endpoint-query-client.d.cts.map +0 -1
  220. package/runtime/endpoint-query-client.d.ts +0 -13
  221. package/runtime/endpoint-query-client.d.ts.map +0 -1
  222. package/runtime/endpoint-query-client.js +0 -75
  223. package/runtime/endpoint-query-client.types.cjs +0 -2
  224. package/runtime/endpoint-query-client.types.d.cts +0 -16
  225. package/runtime/endpoint-query-client.types.d.cts.map +0 -1
  226. package/runtime/endpoint-query-client.types.d.ts +0 -16
  227. package/runtime/endpoint-query-client.types.d.ts.map +0 -1
  228. package/runtime/endpoint-query-client.types.js +0 -1
  229. package/runtime/endpoint-query.cjs +0 -214
  230. package/runtime/endpoint-query.d.cts +0 -29
  231. package/runtime/endpoint-query.d.cts.map +0 -1
  232. package/runtime/endpoint-query.d.ts +0 -29
  233. package/runtime/endpoint-query.d.ts.map +0 -1
  234. package/runtime/endpoint-query.js +0 -208
  235. package/runtime/endpoint-query.types.cjs +0 -2
  236. package/runtime/endpoint-query.types.d.cts +0 -42
  237. package/runtime/endpoint-query.types.d.cts.map +0 -1
  238. package/runtime/endpoint-query.types.d.ts +0 -42
  239. package/runtime/endpoint-query.types.d.ts.map +0 -1
  240. package/runtime/endpoint-query.types.js +0 -1
  241. package/runtime/endpoint.cjs +0 -131
  242. package/runtime/endpoint.d.cts +0 -73
  243. package/runtime/endpoint.d.cts.map +0 -1
  244. package/runtime/endpoint.d.ts +0 -73
  245. package/runtime/endpoint.d.ts.map +0 -1
  246. package/runtime/endpoint.js +0 -127
  247. package/runtime/endpoint.types.cjs +0 -2
  248. package/runtime/endpoint.types.d.cts +0 -24
  249. package/runtime/endpoint.types.d.cts.map +0 -1
  250. package/runtime/endpoint.types.d.ts +0 -24
  251. package/runtime/endpoint.types.d.ts.map +0 -1
  252. package/runtime/endpoint.types.js +0 -1
  253. package/runtime/http-client.cjs +0 -190
  254. package/runtime/http-client.d.cts +0 -85
  255. package/runtime/http-client.d.cts.map +0 -1
  256. package/runtime/http-client.d.ts +0 -85
  257. package/runtime/http-client.d.ts.map +0 -1
  258. package/runtime/http-client.js +0 -184
  259. package/runtime/index.cjs +0 -25
  260. package/runtime/index.d.cts +0 -10
  261. package/runtime/index.d.cts.map +0 -1
  262. package/runtime/index.d.ts +0 -10
  263. package/runtime/index.d.ts.map +0 -1
  264. package/runtime/index.js +0 -9
@@ -1,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpClient = exports.isHttpBadResponse = exports.isHttpResponse = void 0;
4
- const mobx_1 = require("mobx");
5
- const qs_1 = require("qs");
6
- const isHttpResponse = (response, status) => !!response &&
7
- typeof response === 'object' &&
8
- response instanceof Response &&
9
- 'data' in response &&
10
- (!status || response.status === status);
11
- exports.isHttpResponse = isHttpResponse;
12
- const isHttpBadResponse = (response) => {
13
- return (0, exports.isHttpResponse)(response) && (!response.ok || !!response.error);
14
- };
15
- exports.isHttpBadResponse = isHttpBadResponse;
16
- class HttpClient {
17
- config;
18
- fetch;
19
- meta;
20
- baseApiParams;
21
- badResponse;
22
- toQueryString;
23
- constructor(config) {
24
- this.config = config ?? {};
25
- this.badResponse = null;
26
- this.meta = config?.meta ?? null;
27
- this.fetch =
28
- config?.fetch ??
29
- ((...fetchParams) => globalThis.fetch(...fetchParams));
30
- this.toQueryString =
31
- config?.toQueryString ??
32
- ((query) => (0, qs_1.stringify)(query, config?.queryStringifyOptions));
33
- this.baseApiParams = {
34
- credentials: 'same-origin',
35
- headers: {},
36
- redirect: 'follow',
37
- referrerPolicy: 'no-referrer',
38
- };
39
- this.updateConfig(this.config);
40
- mobx_1.observable.ref(this, 'badResponse');
41
- mobx_1.observable.ref(this, 'meta');
42
- (0, mobx_1.action)(this, 'setMeta');
43
- (0, mobx_1.action)(this, 'setBadResponse');
44
- (0, mobx_1.makeObservable)(this);
45
- }
46
- get baseUrl() {
47
- return this.config.baseUrl ?? '';
48
- }
49
- updateConfig(update) {
50
- Object.assign(this.config, update);
51
- if (update.baseApiParams) {
52
- Object.assign(this.baseApiParams, update.baseApiParams);
53
- }
54
- if (update.contentFormatters) {
55
- Object.assign(this.contentFormatters, update.contentFormatters);
56
- }
57
- if (update.fetch) {
58
- this.fetch = update.fetch;
59
- }
60
- }
61
- setMeta = (data) => {
62
- this.meta = data;
63
- };
64
- setBadResponse = (response) => {
65
- this.badResponse = response;
66
- };
67
- contentFormatters = {
68
- 'application/json': (input) => input !== null && (typeof input === 'object' || typeof input === 'string')
69
- ? JSON.stringify(input)
70
- : input,
71
- 'text/plain': (input) => input !== null && typeof input !== 'string'
72
- ? JSON.stringify(input)
73
- : input,
74
- 'multipart/form-data': (input) => Object.keys(input || {}).reduce((formData, key) => {
75
- const property = input[key];
76
- if (property instanceof Blob) {
77
- formData.append(key, property);
78
- }
79
- else if (typeof property === 'object' && property !== null) {
80
- formData.append(key, JSON.stringify(property));
81
- }
82
- else {
83
- formData.append(key, `${property}`);
84
- }
85
- return formData;
86
- }, new FormData()),
87
- 'application/x-www-form-urlencoded': (input) => this.toQueryString(input),
88
- 'application/octet-stream': (input) => input,
89
- };
90
- mergeRequestParams(params1, params2) {
91
- return {
92
- ...this.baseApiParams,
93
- ...params1,
94
- ...params2,
95
- headers: {
96
- ...this.baseApiParams.headers,
97
- ...params1.headers,
98
- ...params2?.headers,
99
- },
100
- };
101
- }
102
- async createResponse(responseFormat, raw, url, params) {
103
- const response = raw;
104
- response.request = {
105
- url,
106
- params,
107
- };
108
- response.data = null;
109
- response.error = null;
110
- if (responseFormat) {
111
- try {
112
- const formatted = await response[responseFormat]();
113
- if (response.ok) {
114
- response.data = formatted;
115
- }
116
- else {
117
- response.error = formatted;
118
- }
119
- }
120
- catch (error) {
121
- if (response.ok) {
122
- response.error = error;
123
- }
124
- else {
125
- response.error = null;
126
- }
127
- }
128
- }
129
- if (!response.ok || response.error) {
130
- this.setBadResponse(response);
131
- }
132
- return response;
133
- }
134
- buildUrl = (params) => {
135
- const baseUrl = params.baseUrl ?? this.baseUrl ?? '';
136
- const path = params.path;
137
- const queryString = params.query && this.toQueryString(params.query);
138
- const query = queryString ? `?${queryString}` : '';
139
- if (this.config.buildUrl) {
140
- return this.config.buildUrl(params, { baseUrl, path, query }, this.meta);
141
- }
142
- const url = baseUrl + path + query;
143
- return url;
144
- };
145
- async request(fullParams, endpoint) {
146
- this.setBadResponse(null);
147
- const { body, contentType = 'application/json', format = 'json', ...params } = fullParams;
148
- let requestParams = this.mergeRequestParams(params);
149
- if (this.config.interceptor) {
150
- requestParams =
151
- (await this.config.interceptor(requestParams, this.meta, endpoint)) ??
152
- requestParams;
153
- }
154
- const payloadFormatter = this.contentFormatters[contentType];
155
- const responseFormat = format || requestParams.format;
156
- const url = this.buildUrl(fullParams);
157
- let headers;
158
- if (requestParams.headers instanceof Headers) {
159
- headers = requestParams.headers;
160
- }
161
- else if (Array.isArray(requestParams.headers)) {
162
- headers = new Headers(requestParams.headers);
163
- }
164
- else {
165
- headers = new Headers(requestParams.headers);
166
- }
167
- if (!headers.has('Content-Type')) {
168
- headers.set('Content-Type', contentType);
169
- }
170
- const fetchUrl = url;
171
- const fetchParams = {
172
- ...requestParams,
173
- headers,
174
- body: body == null ? null : payloadFormatter(body),
175
- };
176
- let response;
177
- try {
178
- response = await this.fetch(fetchUrl, fetchParams);
179
- }
180
- catch (error) {
181
- response = error;
182
- }
183
- const httpResponse = await this.createResponse(responseFormat, response, fetchUrl, fetchParams);
184
- if (!httpResponse.ok || httpResponse.error) {
185
- throw httpResponse;
186
- }
187
- return httpResponse;
188
- }
189
- }
190
- exports.HttpClient = HttpClient;
@@ -1,85 +0,0 @@
1
- import type { HttpStatusCode, HttpSuccessStatusCode } from 'http-status-code-types';
2
- import { type BooleanOptional, type IStringifyOptions } from 'qs';
3
- import type { AnyObject, Defined, Maybe, ValueOf } from 'yummies/utils/types';
4
- import type { AnyEndpoint } from "./endpoint.types.cjs";
5
- export type QueryParamsType = Record<string | number, any>;
6
- export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
7
- export interface FullRequestParams extends Omit<RequestInit, 'body'> {
8
- /** set parameter to `true` for call `securityWorker` for this request */
9
- secure?: boolean;
10
- /** request path */
11
- path: string;
12
- /** content type of request body */
13
- contentType?: string;
14
- /** query params */
15
- query?: QueryParamsType;
16
- /** format of response (i.e. response.json() -> format: "json") */
17
- format?: ResponseFormat;
18
- /** request body */
19
- body?: unknown;
20
- /** base url */
21
- baseUrl?: string;
22
- /** meta data */
23
- meta?: Record<string, any>;
24
- }
25
- export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path' | 'serviceName'>;
26
- export interface HttpClientConfig<TMeta = unknown> {
27
- baseUrl?: string;
28
- meta?: TMeta;
29
- fetch?: typeof globalThis.fetch;
30
- baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
31
- contentFormatters?: Record<string, (input: any) => any>;
32
- queryStringifyOptions?: IStringifyOptions<BooleanOptional>;
33
- toQueryString?: (query?: AnyObject) => string;
34
- buildUrl?: (fullParams: FullRequestParams, formattedParts: {
35
- baseUrl: string;
36
- path: string;
37
- query: string;
38
- }, metadata: TMeta | null) => string;
39
- interceptor?: (requestParams: RequestParams, metadata: TMeta | null, endpoint?: Maybe<AnyEndpoint>) => Promise<RequestParams | void> | RequestParams | void;
40
- }
41
- export interface HttpResponse<TData, TError = null, TStatus = number> extends Omit<Response, 'status'> {
42
- data: TData;
43
- error: TError;
44
- status: TStatus;
45
- request: {
46
- url: string;
47
- params: globalThis.RequestInit;
48
- };
49
- }
50
- export type HttpMultistatusResponse<TResponsesByStatusMap extends Partial<Record<HttpStatusCode, any>>, TDefaultOkResponse, TDefaultBadResponse = unknown> = Omit<Response, 'status'> & (ValueOf<{
51
- [K in keyof TResponsesByStatusMap]: {
52
- status: K;
53
- data: K extends HttpSuccessStatusCode ? TResponsesByStatusMap[K] : TDefaultOkResponse;
54
- error: K extends HttpSuccessStatusCode ? TDefaultBadResponse : TResponsesByStatusMap[K];
55
- };
56
- }> | {
57
- status: Exclude<HttpStatusCode, keyof TResponsesByStatusMap>;
58
- data: TDefaultOkResponse;
59
- error: TDefaultBadResponse;
60
- });
61
- export type GetHttpResponse<T> = T extends (...args: any[]) => infer R ? R extends Promise<HttpResponse<any, any>> ? Awaited<R> : R extends Promise<HttpMultistatusResponse<any, any, any>> ? Awaited<R> : HttpResponse<any, any> : HttpResponse<any, any>;
62
- export type HttpBadResponse<T = any> = HttpResponse<null, T>;
63
- export type AnyHttpResponse = HttpResponse<any, any>;
64
- export declare const isHttpResponse: (response: unknown, status?: number) => response is AnyHttpResponse;
65
- export declare const isHttpBadResponse: (response: unknown) => response is HttpResponse<null, any>;
66
- export declare class HttpClient<TMeta = unknown> {
67
- private config;
68
- private fetch;
69
- meta: TMeta | null;
70
- baseApiParams: RequestParams;
71
- badResponse: unknown;
72
- protected toQueryString: Defined<HttpClientConfig<TMeta>['toQueryString']>;
73
- constructor(config?: HttpClientConfig<TMeta>);
74
- get baseUrl(): string;
75
- updateConfig(update: Partial<HttpClientConfig<TMeta>>): void;
76
- setMeta: (data: TMeta | null) => void;
77
- setBadResponse: (response: unknown) => void;
78
- private contentFormatters;
79
- protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams;
80
- protected createResponse(responseFormat: FullRequestParams['format'], raw: Response, url: string, params: RequestInit): Promise<AnyHttpResponse>;
81
- buildUrl: (params: FullRequestParams) => string;
82
- request<T, E>(fullParams: FullRequestParams, endpoint?: Maybe<AnyEndpoint>): Promise<HttpResponse<T, E>>;
83
- request<THttpResponse extends HttpResponse<any, any>>(fullParams: FullRequestParams, endpoint?: Maybe<AnyEndpoint>): Promise<THttpResponse>;
84
- }
85
- //# sourceMappingURL=http-client.d.ts.map
@@ -1 +0,0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O,CAAC,aAAa,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EACzD,UAAU,EAAE,iBAAiB,EAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAC5B,OAAO,CAAC,aAAa,CAAC;CAsE1B"}
@@ -1,85 +0,0 @@
1
- import type { HttpStatusCode, HttpSuccessStatusCode } from 'http-status-code-types';
2
- import { type BooleanOptional, type IStringifyOptions } from 'qs';
3
- import type { AnyObject, Defined, Maybe, ValueOf } from 'yummies/utils/types';
4
- import type { AnyEndpoint } from "./endpoint.types.js";
5
- export type QueryParamsType = Record<string | number, any>;
6
- export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
7
- export interface FullRequestParams extends Omit<RequestInit, 'body'> {
8
- /** set parameter to `true` for call `securityWorker` for this request */
9
- secure?: boolean;
10
- /** request path */
11
- path: string;
12
- /** content type of request body */
13
- contentType?: string;
14
- /** query params */
15
- query?: QueryParamsType;
16
- /** format of response (i.e. response.json() -> format: "json") */
17
- format?: ResponseFormat;
18
- /** request body */
19
- body?: unknown;
20
- /** base url */
21
- baseUrl?: string;
22
- /** meta data */
23
- meta?: Record<string, any>;
24
- }
25
- export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path' | 'serviceName'>;
26
- export interface HttpClientConfig<TMeta = unknown> {
27
- baseUrl?: string;
28
- meta?: TMeta;
29
- fetch?: typeof globalThis.fetch;
30
- baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
31
- contentFormatters?: Record<string, (input: any) => any>;
32
- queryStringifyOptions?: IStringifyOptions<BooleanOptional>;
33
- toQueryString?: (query?: AnyObject) => string;
34
- buildUrl?: (fullParams: FullRequestParams, formattedParts: {
35
- baseUrl: string;
36
- path: string;
37
- query: string;
38
- }, metadata: TMeta | null) => string;
39
- interceptor?: (requestParams: RequestParams, metadata: TMeta | null, endpoint?: Maybe<AnyEndpoint>) => Promise<RequestParams | void> | RequestParams | void;
40
- }
41
- export interface HttpResponse<TData, TError = null, TStatus = number> extends Omit<Response, 'status'> {
42
- data: TData;
43
- error: TError;
44
- status: TStatus;
45
- request: {
46
- url: string;
47
- params: globalThis.RequestInit;
48
- };
49
- }
50
- export type HttpMultistatusResponse<TResponsesByStatusMap extends Partial<Record<HttpStatusCode, any>>, TDefaultOkResponse, TDefaultBadResponse = unknown> = Omit<Response, 'status'> & (ValueOf<{
51
- [K in keyof TResponsesByStatusMap]: {
52
- status: K;
53
- data: K extends HttpSuccessStatusCode ? TResponsesByStatusMap[K] : TDefaultOkResponse;
54
- error: K extends HttpSuccessStatusCode ? TDefaultBadResponse : TResponsesByStatusMap[K];
55
- };
56
- }> | {
57
- status: Exclude<HttpStatusCode, keyof TResponsesByStatusMap>;
58
- data: TDefaultOkResponse;
59
- error: TDefaultBadResponse;
60
- });
61
- export type GetHttpResponse<T> = T extends (...args: any[]) => infer R ? R extends Promise<HttpResponse<any, any>> ? Awaited<R> : R extends Promise<HttpMultistatusResponse<any, any, any>> ? Awaited<R> : HttpResponse<any, any> : HttpResponse<any, any>;
62
- export type HttpBadResponse<T = any> = HttpResponse<null, T>;
63
- export type AnyHttpResponse = HttpResponse<any, any>;
64
- export declare const isHttpResponse: (response: unknown, status?: number) => response is AnyHttpResponse;
65
- export declare const isHttpBadResponse: (response: unknown) => response is HttpResponse<null, any>;
66
- export declare class HttpClient<TMeta = unknown> {
67
- private config;
68
- private fetch;
69
- meta: TMeta | null;
70
- baseApiParams: RequestParams;
71
- badResponse: unknown;
72
- protected toQueryString: Defined<HttpClientConfig<TMeta>['toQueryString']>;
73
- constructor(config?: HttpClientConfig<TMeta>);
74
- get baseUrl(): string;
75
- updateConfig(update: Partial<HttpClientConfig<TMeta>>): void;
76
- setMeta: (data: TMeta | null) => void;
77
- setBadResponse: (response: unknown) => void;
78
- private contentFormatters;
79
- protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams;
80
- protected createResponse(responseFormat: FullRequestParams['format'], raw: Response, url: string, params: RequestInit): Promise<AnyHttpResponse>;
81
- buildUrl: (params: FullRequestParams) => string;
82
- request<T, E>(fullParams: FullRequestParams, endpoint?: Maybe<AnyEndpoint>): Promise<HttpResponse<T, E>>;
83
- request<THttpResponse extends HttpResponse<any, any>>(fullParams: FullRequestParams, endpoint?: Maybe<AnyEndpoint>): Promise<THttpResponse>;
84
- }
85
- //# sourceMappingURL=http-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/runtime/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAa,MAAM,IAAI,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B;AAEvD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;AAEnE,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;IAClE,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,kEAAkE;IAClE,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,mBAAmB;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;I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MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,eAAe,CAAC;IAkCpB,QAAQ,GAAI,QAAQ,iBAAiB,YAgB1C;IAEK,OAAO,CAAC,CAAC,EAAE,CAAC,EACjB,UAAU,EAAE,iBAAiB,EAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvB,OAAO,CAAC,aAAa,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EACzD,UAAU,EAAE,iBAAiB,EAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAC5B,OAAO,CAAC,aAAa,CAAC;CAsE1B"}
@@ -1,184 +0,0 @@
1
- import { action, makeObservable, observable } from 'mobx';
2
- import { stringify } from 'qs';
3
- export const isHttpResponse = (response, status) => !!response &&
4
- typeof response === 'object' &&
5
- response instanceof Response &&
6
- 'data' in response &&
7
- (!status || response.status === status);
8
- export const isHttpBadResponse = (response) => {
9
- return isHttpResponse(response) && (!response.ok || !!response.error);
10
- };
11
- export class HttpClient {
12
- config;
13
- fetch;
14
- meta;
15
- baseApiParams;
16
- badResponse;
17
- toQueryString;
18
- constructor(config) {
19
- this.config = config ?? {};
20
- this.badResponse = null;
21
- this.meta = config?.meta ?? null;
22
- this.fetch =
23
- config?.fetch ??
24
- ((...fetchParams) => globalThis.fetch(...fetchParams));
25
- this.toQueryString =
26
- config?.toQueryString ??
27
- ((query) => stringify(query, config?.queryStringifyOptions));
28
- this.baseApiParams = {
29
- credentials: 'same-origin',
30
- headers: {},
31
- redirect: 'follow',
32
- referrerPolicy: 'no-referrer',
33
- };
34
- this.updateConfig(this.config);
35
- observable.ref(this, 'badResponse');
36
- observable.ref(this, 'meta');
37
- action(this, 'setMeta');
38
- action(this, 'setBadResponse');
39
- makeObservable(this);
40
- }
41
- get baseUrl() {
42
- return this.config.baseUrl ?? '';
43
- }
44
- updateConfig(update) {
45
- Object.assign(this.config, update);
46
- if (update.baseApiParams) {
47
- Object.assign(this.baseApiParams, update.baseApiParams);
48
- }
49
- if (update.contentFormatters) {
50
- Object.assign(this.contentFormatters, update.contentFormatters);
51
- }
52
- if (update.fetch) {
53
- this.fetch = update.fetch;
54
- }
55
- }
56
- setMeta = (data) => {
57
- this.meta = data;
58
- };
59
- setBadResponse = (response) => {
60
- this.badResponse = response;
61
- };
62
- contentFormatters = {
63
- 'application/json': (input) => input !== null && (typeof input === 'object' || typeof input === 'string')
64
- ? JSON.stringify(input)
65
- : input,
66
- 'text/plain': (input) => input !== null && typeof input !== 'string'
67
- ? JSON.stringify(input)
68
- : input,
69
- 'multipart/form-data': (input) => Object.keys(input || {}).reduce((formData, key) => {
70
- const property = input[key];
71
- if (property instanceof Blob) {
72
- formData.append(key, property);
73
- }
74
- else if (typeof property === 'object' && property !== null) {
75
- formData.append(key, JSON.stringify(property));
76
- }
77
- else {
78
- formData.append(key, `${property}`);
79
- }
80
- return formData;
81
- }, new FormData()),
82
- 'application/x-www-form-urlencoded': (input) => this.toQueryString(input),
83
- 'application/octet-stream': (input) => input,
84
- };
85
- mergeRequestParams(params1, params2) {
86
- return {
87
- ...this.baseApiParams,
88
- ...params1,
89
- ...params2,
90
- headers: {
91
- ...this.baseApiParams.headers,
92
- ...params1.headers,
93
- ...params2?.headers,
94
- },
95
- };
96
- }
97
- async createResponse(responseFormat, raw, url, params) {
98
- const response = raw;
99
- response.request = {
100
- url,
101
- params,
102
- };
103
- response.data = null;
104
- response.error = null;
105
- if (responseFormat) {
106
- try {
107
- const formatted = await response[responseFormat]();
108
- if (response.ok) {
109
- response.data = formatted;
110
- }
111
- else {
112
- response.error = formatted;
113
- }
114
- }
115
- catch (error) {
116
- if (response.ok) {
117
- response.error = error;
118
- }
119
- else {
120
- response.error = null;
121
- }
122
- }
123
- }
124
- if (!response.ok || response.error) {
125
- this.setBadResponse(response);
126
- }
127
- return response;
128
- }
129
- buildUrl = (params) => {
130
- const baseUrl = params.baseUrl ?? this.baseUrl ?? '';
131
- const path = params.path;
132
- const queryString = params.query && this.toQueryString(params.query);
133
- const query = queryString ? `?${queryString}` : '';
134
- if (this.config.buildUrl) {
135
- return this.config.buildUrl(params, { baseUrl, path, query }, this.meta);
136
- }
137
- const url = baseUrl + path + query;
138
- return url;
139
- };
140
- async request(fullParams, endpoint) {
141
- this.setBadResponse(null);
142
- const { body, contentType = 'application/json', format = 'json', ...params } = fullParams;
143
- let requestParams = this.mergeRequestParams(params);
144
- if (this.config.interceptor) {
145
- requestParams =
146
- (await this.config.interceptor(requestParams, this.meta, endpoint)) ??
147
- requestParams;
148
- }
149
- const payloadFormatter = this.contentFormatters[contentType];
150
- const responseFormat = format || requestParams.format;
151
- const url = this.buildUrl(fullParams);
152
- let headers;
153
- if (requestParams.headers instanceof Headers) {
154
- headers = requestParams.headers;
155
- }
156
- else if (Array.isArray(requestParams.headers)) {
157
- headers = new Headers(requestParams.headers);
158
- }
159
- else {
160
- headers = new Headers(requestParams.headers);
161
- }
162
- if (!headers.has('Content-Type')) {
163
- headers.set('Content-Type', contentType);
164
- }
165
- const fetchUrl = url;
166
- const fetchParams = {
167
- ...requestParams,
168
- headers,
169
- body: body == null ? null : payloadFormatter(body),
170
- };
171
- let response;
172
- try {
173
- response = await this.fetch(fetchUrl, fetchParams);
174
- }
175
- catch (error) {
176
- response = error;
177
- }
178
- const httpResponse = await this.createResponse(responseFormat, response, fetchUrl, fetchParams);
179
- if (!httpResponse.ok || httpResponse.error) {
180
- throw httpResponse;
181
- }
182
- return httpResponse;
183
- }
184
- }
package/runtime/index.cjs DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./endpoint.cjs"), exports);
18
- __exportStar(require("./endpoint.types.cjs"), exports);
19
- __exportStar(require("./endpoint-mutation.cjs"), exports);
20
- __exportStar(require("./endpoint-mutation.types.cjs"), exports);
21
- __exportStar(require("./endpoint-query.cjs"), exports);
22
- __exportStar(require("./endpoint-query.types.cjs"), exports);
23
- __exportStar(require("./endpoint-query-client.cjs"), exports);
24
- __exportStar(require("./endpoint-query-client.types.cjs"), exports);
25
- __exportStar(require("./http-client.cjs"), exports);
@@ -1,10 +0,0 @@
1
- export * from "./endpoint.cjs";
2
- export * from "./endpoint.types.cjs";
3
- export * from "./endpoint-mutation.cjs";
4
- export * from "./endpoint-mutation.types.cjs";
5
- export * from "./endpoint-query.cjs";
6
- export * from "./endpoint-query.types.cjs";
7
- export * from "./endpoint-query-client.cjs";
8
- export * from "./endpoint-query-client.types.cjs";
9
- export * from "./http-client.cjs";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,+BAA8B;AAC9B,qCAAoC;AACpC,wCAAuC;AACvC,8CAA6C;AAC7C,qCAAoC;AACpC,2CAA0C;AAC1C,4CAA2C;AAC3C,kDAAiD;AACjD,kCAAiC"}
@@ -1,10 +0,0 @@
1
- export * from "./endpoint.js";
2
- export * from "./endpoint.types.js";
3
- export * from "./endpoint-mutation.js";
4
- export * from "./endpoint-mutation.types.js";
5
- export * from "./endpoint-query.js";
6
- export * from "./endpoint-query.types.js";
7
- export * from "./endpoint-query-client.js";
8
- export * from "./endpoint-query-client.types.js";
9
- export * from "./http-client.js";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,oCAAoC;AACpC,uCAAuC;AACvC,6CAA6C;AAC7C,oCAAoC;AACpC,0CAA0C;AAC1C,2CAA2C;AAC3C,iDAAiD;AACjD,iCAAiC"}
package/runtime/index.js DELETED
@@ -1,9 +0,0 @@
1
- export * from "./endpoint.js";
2
- export * from "./endpoint.types.js";
3
- export * from "./endpoint-mutation.js";
4
- export * from "./endpoint-mutation.types.js";
5
- export * from "./endpoint-query.js";
6
- export * from "./endpoint-query.types.js";
7
- export * from "./endpoint-query-client.js";
8
- export * from "./endpoint-query-client.types.js";
9
- export * from "./http-client.js";