@dooboostore/simple-boot-http-server 1.0.24 → 1.0.26

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 (190) hide show
  1. package/README.md +113 -0
  2. package/dist/cjs/SimpleBootHttpServer.js +16 -4
  3. package/dist/cjs/SimpleBootHttpServer.js.map +2 -2
  4. package/dist/cjs/bundle-entry.js +34 -24
  5. package/dist/cjs/bundle-entry.js.map +2 -2
  6. package/dist/cjs/decorators/MethodMapping.js +33 -3
  7. package/dist/cjs/decorators/MethodMapping.js.map +2 -2
  8. package/dist/cjs/errors/BadRequestError.js +2 -1
  9. package/dist/cjs/errors/BadRequestError.js.map +2 -2
  10. package/dist/cjs/errors/ForbiddenError.js +2 -1
  11. package/dist/cjs/errors/ForbiddenError.js.map +2 -2
  12. package/dist/cjs/errors/InternalServerError.js +2 -1
  13. package/dist/cjs/errors/InternalServerError.js.map +2 -2
  14. package/dist/cjs/errors/NotFoundError.js +2 -1
  15. package/dist/cjs/errors/NotFoundError.js.map +2 -2
  16. package/dist/cjs/errors/UnauthorizedError.js +2 -1
  17. package/dist/cjs/errors/UnauthorizedError.js.map +2 -2
  18. package/dist/cjs/filters/IntentSchemeFilter.js +1 -2
  19. package/dist/cjs/filters/IntentSchemeFilter.js.map +2 -2
  20. package/dist/cjs/filters/ResourceFilter.js +3 -2
  21. package/dist/cjs/filters/ResourceFilter.js.map +2 -2
  22. package/dist/cjs/filters/index.js +3 -1
  23. package/dist/cjs/filters/index.js.map +2 -2
  24. package/dist/cjs/index.js +2 -0
  25. package/dist/cjs/index.js.map +2 -2
  26. package/dist/cjs/inject/InjectSituationType.js +1 -1
  27. package/dist/cjs/inject/InjectSituationType.js.map +2 -2
  28. package/dist/cjs/models/RequestResponse.js +19 -2
  29. package/dist/cjs/models/RequestResponse.js.map +2 -2
  30. package/dist/cjs/models/datas/body/index.js +28 -0
  31. package/dist/cjs/models/datas/body/index.js.map +7 -0
  32. package/dist/cjs/models/datas/index.js +32 -0
  33. package/dist/cjs/models/datas/index.js.map +7 -0
  34. package/dist/cjs/models/datas/{body → path}/ReqPathData.js.map +1 -1
  35. package/dist/cjs/models/datas/{search → path}/ReqSearchParamsObj.js.map +1 -1
  36. package/dist/cjs/models/datas/path/index.js +24 -0
  37. package/dist/cjs/models/datas/path/index.js.map +7 -0
  38. package/dist/cjs/models/index.js +4 -16
  39. package/dist/cjs/models/index.js.map +2 -2
  40. package/dist/cjs/models/method/index.js +22 -0
  41. package/dist/cjs/models/method/index.js.map +7 -0
  42. package/dist/cjs/models/method/patch/index.js +22 -0
  43. package/dist/cjs/models/method/patch/index.js.map +7 -0
  44. package/dist/cjs/option/HttpServerOption.js.map +2 -2
  45. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js +98 -95
  46. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js.map +3 -3
  47. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js +1 -1
  48. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js.map +2 -2
  49. package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js +244 -266
  50. package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js.map +3 -3
  51. package/dist/cjs/websocket/WebSocketClient.js +2 -1
  52. package/dist/cjs/websocket/WebSocketClient.js.map +2 -2
  53. package/dist/esm/SimpleBootHttpServer.js +16 -4
  54. package/dist/esm/SimpleBootHttpServer.js.map +2 -2
  55. package/dist/esm/bundle-entry.js +14 -12
  56. package/dist/esm/bundle-entry.js.map +2 -2
  57. package/dist/esm/decorators/MethodMapping.js +22 -2
  58. package/dist/esm/decorators/MethodMapping.js.map +2 -2
  59. package/dist/esm/errors/BadRequestError.js +2 -1
  60. package/dist/esm/errors/BadRequestError.js.map +2 -2
  61. package/dist/esm/errors/ForbiddenError.js +2 -1
  62. package/dist/esm/errors/ForbiddenError.js.map +2 -2
  63. package/dist/esm/errors/InternalServerError.js +2 -1
  64. package/dist/esm/errors/InternalServerError.js.map +2 -2
  65. package/dist/esm/errors/NotFoundError.js +2 -1
  66. package/dist/esm/errors/NotFoundError.js.map +2 -2
  67. package/dist/esm/errors/UnauthorizedError.js +2 -1
  68. package/dist/esm/errors/UnauthorizedError.js.map +2 -2
  69. package/dist/esm/filters/IntentSchemeFilter.js +2 -3
  70. package/dist/esm/filters/IntentSchemeFilter.js.map +2 -2
  71. package/dist/esm/filters/ResourceFilter.js +3 -2
  72. package/dist/esm/filters/ResourceFilter.js.map +2 -2
  73. package/dist/esm/filters/index.js +1 -0
  74. package/dist/esm/filters/index.js.map +2 -2
  75. package/dist/esm/index.js +1 -0
  76. package/dist/esm/index.js.map +2 -2
  77. package/dist/esm/inject/InjectSituationType.js +1 -1
  78. package/dist/esm/inject/InjectSituationType.js.map +2 -2
  79. package/dist/esm/models/RequestResponse.js +19 -2
  80. package/dist/esm/models/RequestResponse.js.map +2 -2
  81. package/dist/esm/models/datas/body/index.js +5 -0
  82. package/dist/esm/models/datas/body/index.js.map +7 -0
  83. package/dist/esm/models/datas/index.js +7 -0
  84. package/dist/esm/models/datas/index.js.map +7 -0
  85. package/dist/esm/models/datas/{body → path}/ReqPathData.js.map +1 -1
  86. package/dist/esm/models/datas/{search → path}/ReqSearchParamsObj.js.map +1 -1
  87. package/dist/esm/models/datas/path/index.js +3 -0
  88. package/dist/esm/models/datas/path/index.js.map +7 -0
  89. package/dist/esm/models/index.js +2 -8
  90. package/dist/esm/models/index.js.map +2 -2
  91. package/dist/esm/models/method/index.js +2 -0
  92. package/dist/esm/models/method/index.js.map +7 -0
  93. package/dist/esm/models/method/patch/index.js +2 -0
  94. package/dist/esm/models/method/patch/index.js.map +7 -0
  95. package/dist/esm/option/HttpServerOption.js.map +2 -2
  96. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js +98 -95
  97. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js.map +3 -3
  98. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js +2 -2
  99. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js.map +2 -2
  100. package/dist/esm/proxy/TopicProtocolApiServiceProxy.js +244 -266
  101. package/dist/esm/proxy/TopicProtocolApiServiceProxy.js.map +3 -3
  102. package/dist/esm/websocket/WebSocketClient.js +3 -2
  103. package/dist/esm/websocket/WebSocketClient.js.map +2 -2
  104. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +19374 -4956
  105. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
  106. package/dist/types/SimpleBootHttpServer.d.ts +1 -1
  107. package/dist/types/SimpleBootHttpServer.d.ts.map +1 -1
  108. package/dist/types/bundle-entry.d.ts +7 -12
  109. package/dist/types/bundle-entry.d.ts.map +1 -1
  110. package/dist/types/decorators/MethodMapping.d.ts +10 -0
  111. package/dist/types/decorators/MethodMapping.d.ts.map +1 -1
  112. package/dist/types/errors/BadRequestError.d.ts +2 -2
  113. package/dist/types/errors/BadRequestError.d.ts.map +1 -1
  114. package/dist/types/errors/ForbiddenError.d.ts +2 -2
  115. package/dist/types/errors/ForbiddenError.d.ts.map +1 -1
  116. package/dist/types/errors/InternalServerError.d.ts +2 -2
  117. package/dist/types/errors/InternalServerError.d.ts.map +1 -1
  118. package/dist/types/errors/NotFoundError.d.ts +2 -2
  119. package/dist/types/errors/NotFoundError.d.ts.map +1 -1
  120. package/dist/types/errors/UnauthorizedError.d.ts +2 -2
  121. package/dist/types/errors/UnauthorizedError.d.ts.map +1 -1
  122. package/dist/types/filters/ResourceFilter.d.ts.map +1 -1
  123. package/dist/types/filters/index.d.ts +1 -0
  124. package/dist/types/filters/index.d.ts.map +1 -1
  125. package/dist/types/index.d.ts +1 -0
  126. package/dist/types/index.d.ts.map +1 -1
  127. package/dist/types/inject/InjectSituationType.d.ts.map +1 -1
  128. package/dist/types/models/RequestResponse.d.ts +3 -1
  129. package/dist/types/models/RequestResponse.d.ts.map +1 -1
  130. package/dist/types/models/datas/body/index.d.ts +5 -0
  131. package/dist/types/models/datas/body/index.d.ts.map +1 -0
  132. package/dist/types/models/datas/index.d.ts +7 -0
  133. package/dist/types/models/datas/index.d.ts.map +1 -0
  134. package/dist/types/models/datas/{body → path}/ReqPathData.d.ts.map +1 -1
  135. package/dist/types/models/datas/path/ReqSearchParamsObj.d.ts.map +1 -0
  136. package/dist/types/models/datas/path/index.d.ts +3 -0
  137. package/dist/types/models/datas/path/index.d.ts.map +1 -0
  138. package/dist/types/models/index.d.ts +2 -8
  139. package/dist/types/models/index.d.ts.map +1 -1
  140. package/dist/types/models/method/index.d.ts +2 -0
  141. package/dist/types/models/method/index.d.ts.map +1 -0
  142. package/dist/types/models/method/patch/index.d.ts +2 -0
  143. package/dist/types/models/method/patch/index.d.ts.map +1 -0
  144. package/dist/types/option/HttpServerOption.d.ts +6 -2
  145. package/dist/types/option/HttpServerOption.d.ts.map +1 -1
  146. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts +6 -8
  147. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts.map +1 -1
  148. package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts +5 -15
  149. package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts.map +1 -1
  150. package/dist/types/websocket/WebSocketClient.d.ts.map +1 -1
  151. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +19340 -4928
  152. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
  153. package/dist/umd-bundle/websocket-client.umd.js +378 -1468
  154. package/dist/umd-bundle/websocket-client.umd.js.map +4 -4
  155. package/package.json +8 -8
  156. package/src/SimpleBootHttpServer.ts +20 -6
  157. package/src/bundle-entry.ts +12 -12
  158. package/src/decorators/MethodMapping.ts +13 -1
  159. package/src/errors/BadRequestError.ts +7 -3
  160. package/src/errors/ForbiddenError.ts +7 -3
  161. package/src/errors/InternalServerError.ts +7 -3
  162. package/src/errors/NotFoundError.ts +7 -3
  163. package/src/errors/UnauthorizedError.ts +7 -3
  164. package/src/filters/IntentSchemeFilter.ts +2 -2
  165. package/src/filters/ResourceFilter.ts +5 -2
  166. package/src/filters/index.ts +1 -0
  167. package/src/index.ts +1 -0
  168. package/src/inject/InjectSituationType.ts +1 -1
  169. package/src/models/RequestResponse.ts +28 -2
  170. package/src/models/datas/body/index.ts +4 -0
  171. package/src/models/datas/index.ts +6 -0
  172. package/src/models/datas/path/index.ts +2 -0
  173. package/src/models/index.ts +2 -8
  174. package/src/models/method/index.ts +1 -0
  175. package/src/models/method/patch/index.ts +1 -0
  176. package/src/option/HttpServerOption.ts +4 -2
  177. package/src/proxy/SymbolIntentApiServiceProxy.ts +103 -97
  178. package/src/proxy/SymbolIntentApiServiceProxyBase.ts +2 -2
  179. package/src/proxy/TopicProtocolApiServiceProxy.ts +260 -275
  180. package/src/websocket/WebSocketClient.ts +3 -2
  181. package/README.MD +0 -62
  182. package/dist/types/models/datas/search/ReqSearchParamsObj.d.ts.map +0 -1
  183. /package/dist/cjs/models/datas/{body → path}/ReqPathData.js +0 -0
  184. /package/dist/cjs/models/datas/{search → path}/ReqSearchParamsObj.js +0 -0
  185. /package/dist/esm/models/datas/{body → path}/ReqPathData.js +0 -0
  186. /package/dist/esm/models/datas/{search → path}/ReqSearchParamsObj.js +0 -0
  187. /package/dist/types/models/datas/{body → path}/ReqPathData.d.ts +0 -0
  188. /package/dist/types/models/datas/{search → path}/ReqSearchParamsObj.d.ts +0 -0
  189. /package/src/models/datas/{body → path}/ReqPathData.ts +0 -0
  190. /package/src/models/datas/{search → path}/ReqSearchParamsObj.ts +0 -0
@@ -17,7 +17,8 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var TopicProtocolApiServiceProxy_exports = {};
19
19
  __export(TopicProtocolApiServiceProxy_exports, {
20
- TopicProtocolApiServiceProxy: () => TopicProtocolApiServiceProxy
20
+ createTopicHandler: () => createTopicHandler,
21
+ default: () => TopicProtocolApiServiceProxy_default
21
22
  });
22
23
  module.exports = __toCommonJS(TopicProtocolApiServiceProxy_exports);
23
24
  var import_simple_boot = require("@dooboostore/simple-boot");
@@ -33,292 +34,269 @@ var __decorate = function(decorators, target, key, desc) {
33
34
  var __metadata = function(k, v) {
34
35
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
36
  };
36
- var TopicProtocolApiServiceProxy_1;
37
- var _a;
38
- let TopicProtocolApiServiceProxy = TopicProtocolApiServiceProxy_1 = class TopicProtocolApiServiceProxy2 {
39
- constructor(apiService) {
40
- this.apiService = apiService;
41
- }
42
- static isFileValue(value) {
43
- if (typeof File !== "undefined" && value instanceof File) {
44
- return true;
45
- }
46
- if (typeof Blob !== "undefined" && value instanceof Blob) {
47
- return true;
48
- }
49
- if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
50
- return true;
51
- }
52
- if (typeof Uint8Array !== "undefined" && value instanceof Uint8Array) {
53
- return true;
54
- }
55
- return false;
56
- }
57
- static toFileEntry(value, id) {
58
- if (typeof Blob === "undefined") {
59
- return void 0;
60
- }
61
- if (typeof File !== "undefined" && value instanceof File) {
62
- const blob2 = new Blob([value], { type: value.type });
63
- return { id, file: blob2, filename: value.name };
64
- }
65
- if (value instanceof Blob) {
66
- return { id, file: value };
67
- }
68
- const view = value instanceof Uint8Array ? value : new Uint8Array(value);
69
- const safe = value instanceof Uint8Array ? new Uint8Array(value) : new Uint8Array(view);
70
- const blob = new Blob([safe]);
71
- return { id, file: blob };
72
- }
73
- static buildRequest(target, body, type = "intent") {
74
- const fileEntries = [];
75
- let fileIndex = 0;
76
- const registerFile = (value) => {
77
- const id = `f${++fileIndex}`;
78
- const entry = TopicProtocolApiServiceProxy_1.toFileEntry(value, id);
79
- if (entry) {
80
- fileEntries.push(entry);
81
- return id;
82
- }
83
- return void 0;
84
- };
85
- const replaceFiles = (value) => {
86
- if (TopicProtocolApiServiceProxy_1.isFileValue(value)) {
87
- const id = registerFile(value);
88
- if (id) {
89
- return { $file: id };
90
- }
91
- return value;
92
- }
93
- if (Array.isArray(value)) {
94
- return value.map((item) => replaceFiles(item));
95
- }
96
- if (value && typeof value === "object") {
97
- const result = {};
98
- Object.keys(value).forEach((key) => {
99
- result[key] = replaceFiles(value[key]);
100
- });
101
- return result;
102
- }
103
- return value;
104
- };
105
- const payload = replaceFiles(body);
106
- const request = {
107
- type,
108
- target,
109
- requestUUID: import_core.RandomUtils.uuid4(),
110
- body: payload,
111
- files: fileEntries.length > 0 ? fileEntries.map((entry) => ({ id: entry.id })) : void 0
112
- };
113
- return { request, fileEntries };
114
- }
115
- static async parseMultipartMixed(response) {
116
- const contentType = response.headers.get("Content-Type") ?? "";
117
- const boundaryMatch = contentType.match(/boundary=([^;]+)/i);
118
- if (!boundaryMatch) {
119
- return void 0;
120
- }
121
- const boundary = boundaryMatch[1].replace(/^"|"$/g, "");
122
- const buffer = new Uint8Array(await response.arrayBuffer());
123
- const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
124
- const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
125
- const separator = new TextEncoder().encode("\r\n\r\n");
126
- const indexOf = (source, needle, from = 0) => {
127
- for (let i = from; i <= source.length - needle.length; i++) {
128
- let matched = true;
129
- for (let j = 0; j < needle.length; j++) {
130
- if (source[i + j] !== needle[j]) {
131
- matched = false;
132
- break;
133
- }
134
- }
135
- if (matched) {
136
- return i;
137
- }
138
- }
139
- return -1;
140
- };
141
- const parts = [];
142
- let cursor = indexOf(buffer, boundaryBytes, 0);
143
- while (cursor !== -1) {
144
- const nextBoundary = indexOf(buffer, boundaryBytes, cursor + boundaryBytes.length);
145
- const endBoundary = indexOf(buffer, endBoundaryBytes, cursor + boundaryBytes.length);
146
- const isFinal = endBoundary !== -1 && (endBoundary < nextBoundary || nextBoundary === -1);
147
- const partStart = cursor + boundaryBytes.length;
148
- if (isFinal) {
149
- break;
150
- }
151
- let headerStart = partStart;
152
- if (buffer[headerStart] === 13 && buffer[headerStart + 1] === 10) {
153
- headerStart += 2;
154
- }
155
- const headerEnd = indexOf(buffer, separator, headerStart);
156
- if (headerEnd === -1) {
157
- break;
158
- }
159
- const headerText = new TextDecoder().decode(buffer.slice(headerStart, headerEnd));
160
- const headers = {};
161
- headerText.split("\r\n").forEach((line) => {
162
- const idx = line.indexOf(":");
163
- if (idx > -1) {
164
- const key = line.slice(0, idx).trim().toLowerCase();
165
- headers[key] = line.slice(idx + 1).trim();
166
- }
167
- });
168
- const bodyStart = headerEnd + separator.length;
169
- const bodyEnd = nextBoundary === -1 ? buffer.length : nextBoundary - 2;
170
- const body = buffer.slice(bodyStart, bodyEnd);
171
- parts.push({ headers, body });
172
- cursor = nextBoundary;
173
- }
174
- return { boundary, parts };
175
- }
176
- static parseDispositionFilename(disposition) {
177
- if (!disposition) {
178
- return void 0;
179
- }
180
- const match = disposition.match(/filename=\"?([^\";]+)\"?/i);
181
- return match ? match[1] : void 0;
182
- }
183
- static parseDispositionName(disposition) {
184
- if (!disposition) {
185
- return void 0;
186
- }
187
- const match = disposition.match(/name=\"?([^\";]+)\"?/i);
188
- return match ? match[1] : void 0;
37
+ const isFileValue = (value) => {
38
+ if (typeof File !== "undefined" && value instanceof File)
39
+ return true;
40
+ if (typeof Blob !== "undefined" && value instanceof Blob)
41
+ return true;
42
+ if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer)
43
+ return true;
44
+ if (typeof Uint8Array !== "undefined" && value instanceof Uint8Array)
45
+ return true;
46
+ return false;
47
+ };
48
+ const toFileEntry = (value, id) => {
49
+ if (typeof Blob === "undefined")
50
+ return void 0;
51
+ if (typeof File !== "undefined" && value instanceof File) {
52
+ return { id, file: new Blob([value], { type: value.type }), filename: value.name };
189
53
  }
190
- static replaceFileRefs(value, fileMap) {
191
- if (value && typeof value === "object" && "$file" in value) {
192
- const fileKey = value.$file;
193
- if (typeof fileKey === "string") {
194
- const file = fileMap.get(fileKey);
195
- if (file) {
196
- return file;
197
- }
198
- }
54
+ if (value instanceof Blob)
55
+ return { id, file: value };
56
+ const safe = value instanceof Uint8Array ? new Uint8Array(value) : new Uint8Array(value);
57
+ return { id, file: new Blob([safe]) };
58
+ };
59
+ const buildRequest = (target, body, type = "intent") => {
60
+ const fileEntries = [];
61
+ let fileIndex = 0;
62
+ const registerFile = (value) => {
63
+ const id = `f${++fileIndex}`;
64
+ const entry = toFileEntry(value, id);
65
+ if (entry) {
66
+ fileEntries.push(entry);
67
+ return id;
199
68
  }
200
- if (Array.isArray(value)) {
201
- return value.map((item) => TopicProtocolApiServiceProxy_1.replaceFileRefs(item, fileMap));
69
+ return void 0;
70
+ };
71
+ const replaceFiles = (value) => {
72
+ if (isFileValue(value)) {
73
+ const id = registerFile(value);
74
+ return id ? { $file: id } : value;
202
75
  }
76
+ if (Array.isArray(value))
77
+ return value.map((item) => replaceFiles(item));
203
78
  if (value && typeof value === "object") {
204
79
  const result = {};
205
80
  Object.keys(value).forEach((key) => {
206
- result[key] = TopicProtocolApiServiceProxy_1.replaceFileRefs(value[key], fileMap);
81
+ result[key] = replaceFiles(value[key]);
207
82
  });
208
83
  return result;
209
84
  }
210
85
  return value;
211
- }
212
- static normalizeResponse(value) {
213
- if (value && typeof value === "object" && "state" in value && "body" in value) {
214
- const typed = value;
215
- if (typed.state === "error") {
216
- const message = typeof typed.body === "object" && typed.body && "message" in typed.body ? String(typed.body.message) : "TopicProtocol error";
217
- throw new Error(message);
86
+ };
87
+ const payload = replaceFiles(body);
88
+ const request = {
89
+ type,
90
+ target,
91
+ requestUUID: import_core.RandomUtils.uuid4(),
92
+ body: payload,
93
+ files: fileEntries.length > 0 ? fileEntries.map((e) => ({ id: e.id })) : void 0
94
+ };
95
+ return { request, fileEntries };
96
+ };
97
+ const parseDispositionName = (disposition) => {
98
+ const match = disposition?.match(/name=\"?([^\";]+)\"?/i);
99
+ return match ? match[1] : void 0;
100
+ };
101
+ const parseDispositionFilename = (disposition) => {
102
+ const match = disposition?.match(/filename=\"?([^\";]+)\"?/i);
103
+ return match ? match[1] : void 0;
104
+ };
105
+ const parseMultipartMixed = async (response) => {
106
+ const contentType = response.headers.get("Content-Type") ?? "";
107
+ const boundaryMatch = contentType.match(/boundary=([^;]+)/i);
108
+ if (!boundaryMatch)
109
+ return void 0;
110
+ const boundary = boundaryMatch[1].replace(/^"|"$/g, "");
111
+ const buffer = new Uint8Array(await response.arrayBuffer());
112
+ const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
113
+ const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
114
+ const separator = new TextEncoder().encode("\r\n\r\n");
115
+ const indexOf = (source, needle, from = 0) => {
116
+ for (let i = from; i <= source.length - needle.length; i++) {
117
+ let matched = true;
118
+ for (let j = 0; j < needle.length; j++) {
119
+ if (source[i + j] !== needle[j]) {
120
+ matched = false;
121
+ break;
122
+ }
218
123
  }
219
- return typed.body;
124
+ if (matched)
125
+ return i;
220
126
  }
221
- return value;
127
+ return -1;
128
+ };
129
+ const parts = [];
130
+ let cursor = indexOf(buffer, boundaryBytes, 0);
131
+ while (cursor !== -1) {
132
+ const nextBoundary = indexOf(buffer, boundaryBytes, cursor + boundaryBytes.length);
133
+ const endBoundary = indexOf(buffer, endBoundaryBytes, cursor + boundaryBytes.length);
134
+ const isFinal = endBoundary !== -1 && (endBoundary < nextBoundary || nextBoundary === -1);
135
+ const partStart = cursor + boundaryBytes.length;
136
+ if (isFinal)
137
+ break;
138
+ let headerStart = partStart;
139
+ if (buffer[headerStart] === 13 && buffer[headerStart + 1] === 10)
140
+ headerStart += 2;
141
+ const headerEnd = indexOf(buffer, separator, headerStart);
142
+ if (headerEnd === -1)
143
+ break;
144
+ const headerText = new TextDecoder().decode(buffer.slice(headerStart, headerEnd));
145
+ const headers = {};
146
+ headerText.split("\r\n").forEach((line) => {
147
+ const idx = line.indexOf(":");
148
+ if (idx > -1)
149
+ headers[line.slice(0, idx).trim().toLowerCase()] = line.slice(idx + 1).trim();
150
+ });
151
+ const bodyStart = headerEnd + separator.length;
152
+ const bodyEnd = nextBoundary === -1 ? buffer.length : nextBoundary - 2;
153
+ parts.push({ headers, body: buffer.slice(bodyStart, bodyEnd) });
154
+ cursor = nextBoundary;
222
155
  }
223
- static createHandler(apiService) {
224
- return {
225
- get(target, prop, receiver) {
226
- const simConfig = (0, import_simple_boot.getSim)(target);
227
- const value = Reflect.get(target, prop, receiver);
228
- if (typeof value === "function" && simConfig?.symbol) {
229
- return function(...args) {
230
- const f = value;
231
- const p = (userConfig) => {
232
- const symbolValue = Array.isArray(simConfig.symbol) ? simConfig.symbol[0] : simConfig.symbol;
233
- const symbolName = symbolValue?.description ?? String(symbolValue ?? simConfig.symbol);
234
- const targetPath = `Symbol.for(${symbolName}):/${String(prop)}`;
235
- const { request, fileEntries } = TopicProtocolApiServiceProxy_1.buildRequest(targetPath, userConfig?.body, userConfig?.type ?? "intent");
236
- const formData = new FormData();
237
- formData.append("body", JSON.stringify(request));
238
- fileEntries.forEach((entry) => {
239
- if (entry.filename) {
240
- formData.append(entry.id, entry.file, entry.filename);
241
- } else {
242
- formData.append(entry.id, entry.file);
243
- }
244
- });
245
- const headers = {
246
- ...userConfig?.headers ?? {},
247
- [import_HttpHeaders.HttpHeaders.XSimpleBootHttpTopicProtocol]: "topic"
248
- };
249
- const endpoint = userConfig?.endpoint ?? "/";
250
- return apiService.post({
251
- target: endpoint,
252
- config: {
253
- responseTransform: userConfig?.bypassTransform ? "response" : userConfig?.transformText ? "text" : async (response) => {
254
- const contentType = response.headers.get("Content-Type") ?? "";
255
- if (contentType.toLowerCase().includes("multipart/mixed")) {
256
- const parsed2 = await TopicProtocolApiServiceProxy_1.parseMultipartMixed(response);
257
- if (!parsed2) {
258
- return void 0;
156
+ return { boundary, parts };
157
+ };
158
+ const replaceFileRefs = (value, fileMap) => {
159
+ if (value && typeof value === "object" && "$file" in value) {
160
+ const fileKey = value.$file;
161
+ if (typeof fileKey === "string") {
162
+ const file = fileMap.get(fileKey);
163
+ if (file)
164
+ return file;
165
+ }
166
+ }
167
+ if (Array.isArray(value))
168
+ return value.map((item) => replaceFileRefs(item, fileMap));
169
+ if (value && typeof value === "object") {
170
+ const result = {};
171
+ Object.keys(value).forEach((key) => {
172
+ result[key] = replaceFileRefs(value[key], fileMap);
173
+ });
174
+ return result;
175
+ }
176
+ return value;
177
+ };
178
+ const normalizeResponse = (value) => {
179
+ if (value && typeof value === "object" && "state" in value && "body" in value) {
180
+ const typed = value;
181
+ if (typed.state === "error") {
182
+ const message = typeof typed.body === "object" && typed.body && "message" in typed.body ? String(typed.body.message) : "TopicProtocol error";
183
+ throw new Error(message);
184
+ }
185
+ return typed.body;
186
+ }
187
+ return value;
188
+ };
189
+ const createTopicHandler = (apiService) => {
190
+ return {
191
+ get(target, prop, receiver) {
192
+ if (prop === "_SimpleBoot_origin")
193
+ return target;
194
+ const simConfig = (0, import_simple_boot.getSim)(target);
195
+ const value = Reflect.get(target, prop, receiver);
196
+ if (typeof value === "function" && simConfig?.symbol) {
197
+ return function(...args) {
198
+ const f = value;
199
+ const p = (userConfig) => {
200
+ const symbolValue = Array.isArray(simConfig.symbol) ? simConfig.symbol[0] : simConfig.symbol;
201
+ const symbolName = symbolValue?.description ?? String(symbolValue ?? simConfig.symbol);
202
+ const targetPath = `Symbol.for(${symbolName}):/${String(prop)}`;
203
+ const { request, fileEntries } = buildRequest(targetPath, userConfig?.body, userConfig?.type ?? "intent");
204
+ const formData = new FormData();
205
+ formData.append("body", JSON.stringify(request));
206
+ fileEntries.forEach((entry) => {
207
+ if (entry.filename)
208
+ formData.append(entry.id, entry.file, entry.filename);
209
+ else
210
+ formData.append(entry.id, entry.file);
211
+ });
212
+ const headers = {
213
+ ...userConfig?.headers ?? {},
214
+ [import_HttpHeaders.HttpHeaders.XSimpleBootHttpTopicProtocol]: "topic"
215
+ };
216
+ const endpoint = userConfig?.endpoint ?? "/";
217
+ return apiService.post({
218
+ target: endpoint,
219
+ config: {
220
+ responseTransform: userConfig?.bypassTransform ? "response" : userConfig?.transformText ? "text" : async (response) => {
221
+ const ct = response.headers.get("Content-Type") ?? "";
222
+ if (ct.toLowerCase().includes("multipart/mixed")) {
223
+ const parsed2 = await parseMultipartMixed(response);
224
+ if (!parsed2)
225
+ return void 0;
226
+ const fileMap = /* @__PURE__ */ new Map();
227
+ let jsonBody = void 0;
228
+ parsed2.parts.forEach((part) => {
229
+ const partType = part.headers["content-type"] ?? "";
230
+ const disposition = part.headers["content-disposition"];
231
+ const name = parseDispositionName(disposition);
232
+ if (partType.includes("application/json")) {
233
+ const text2 = new TextDecoder().decode(part.body);
234
+ jsonBody = text2 ? JSON.parse(text2) : void 0;
235
+ return;
259
236
  }
260
- const fileMap = /* @__PURE__ */ new Map();
261
- let jsonBody = void 0;
262
- parsed2.parts.forEach((part) => {
263
- const partType = part.headers["content-type"] ?? "";
264
- const disposition = part.headers["content-disposition"];
265
- const name = TopicProtocolApiServiceProxy_1.parseDispositionName(disposition);
266
- if (partType.includes("application/json")) {
267
- const text2 = new TextDecoder().decode(part.body);
268
- jsonBody = text2 ? JSON.parse(text2) : void 0;
269
- return;
270
- }
271
- const filename = TopicProtocolApiServiceProxy_1.parseDispositionFilename(disposition);
272
- if (name) {
273
- const view = part.body;
274
- const safe = new Uint8Array(view.byteLength);
275
- safe.set(view);
276
- fileMap.set(name, {
277
- name: filename,
278
- mime: partType || "application/octet-stream",
279
- size: view.byteLength,
280
- buffer: safe.buffer
281
- });
282
- }
283
- });
284
- if (jsonBody) {
285
- const replaced = TopicProtocolApiServiceProxy_1.replaceFileRefs(jsonBody, fileMap);
286
- return TopicProtocolApiServiceProxy_1.normalizeResponse(replaced);
237
+ if (name) {
238
+ const filename = parseDispositionFilename(disposition);
239
+ const safe = new Uint8Array(part.body.byteLength);
240
+ safe.set(part.body);
241
+ fileMap.set(name, {
242
+ name: filename,
243
+ mime: partType || "application/octet-stream",
244
+ size: part.body.byteLength,
245
+ buffer: safe.buffer
246
+ });
287
247
  }
288
- return void 0;
289
- }
290
- const text = await response.text();
291
- const parsed = text ? JSON.parse(text) : void 0;
292
- return TopicProtocolApiServiceProxy_1.normalizeResponse(parsed);
293
- },
294
- transformText: userConfig?.transformText,
295
- config: userConfig?.config,
296
- fetch: {
297
- credentials: "include",
298
- headers,
299
- body: formData
248
+ });
249
+ if (jsonBody)
250
+ return normalizeResponse(replaceFileRefs(jsonBody, fileMap));
251
+ return void 0;
300
252
  }
253
+ const text = await response.text();
254
+ const parsed = text ? JSON.parse(text) : void 0;
255
+ return normalizeResponse(parsed);
256
+ },
257
+ transformText: userConfig?.transformText,
258
+ config: userConfig?.config,
259
+ fetch: {
260
+ credentials: "include",
261
+ headers,
262
+ body: formData
301
263
  }
302
- });
303
- };
304
- args.push(p);
305
- return Reflect.apply(f, target, args);
264
+ }
265
+ });
306
266
  };
307
- }
308
- return value;
267
+ args.push(p);
268
+ return Reflect.apply(f, target, args);
269
+ };
309
270
  }
310
- };
311
- }
312
- get(target, prop, receiver) {
313
- return TopicProtocolApiServiceProxy_1.createHandler(this.apiService).get(target, prop, receiver);
314
- }
271
+ return Reflect.get(target, prop, receiver);
272
+ },
273
+ apply(target, thisArg, argArray) {
274
+ console.log("TopicProtocolApiServiceProxy apply");
275
+ return Reflect.apply(target, thisArg, argArray);
276
+ }
277
+ };
278
+ };
279
+ var TopicProtocolApiServiceProxy_default = (config) => {
280
+ var _a;
281
+ let TopicProtocolApiServiceProxy = class TopicProtocolApiServiceProxy {
282
+ constructor(apiService) {
283
+ this.apiService = apiService;
284
+ }
285
+ get(target, prop, receiver) {
286
+ return createTopicHandler(this.apiService).get(target, prop, receiver);
287
+ }
288
+ apply(target, thisArg, argArray) {
289
+ return createTopicHandler(this.apiService).apply(target, thisArg, argArray);
290
+ }
291
+ };
292
+ TopicProtocolApiServiceProxy = __decorate([
293
+ (0, import_simple_boot.sim)(config),
294
+ __metadata("design:paramtypes", [typeof (_a = typeof import_simple_boot2.ApiService !== "undefined" && import_simple_boot2.ApiService) === "function" ? _a : Object])
295
+ ], TopicProtocolApiServiceProxy);
296
+ return TopicProtocolApiServiceProxy;
315
297
  };
316
- TopicProtocolApiServiceProxy = TopicProtocolApiServiceProxy_1 = __decorate([
317
- import_simple_boot.Sim,
318
- __metadata("design:paramtypes", [typeof (_a = typeof import_simple_boot2.ApiService !== "undefined" && import_simple_boot2.ApiService) === "function" ? _a : Object])
319
- ], TopicProtocolApiServiceProxy);
320
298
  // Annotate the CommonJS export names for ESM import in node:
321
299
  0 && (module.exports = {
322
- TopicProtocolApiServiceProxy
300
+ createTopicHandler
323
301
  });
324
302
  //# sourceMappingURL=TopicProtocolApiServiceProxy.js.map