@positronic/cli 0.0.3 → 0.0.4

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 (81) hide show
  1. package/dist/src/commands/helpers.js +11 -25
  2. package/dist/types/commands/helpers.d.ts.map +1 -1
  3. package/package.json +5 -1
  4. package/dist/src/commands/brain.test.js +0 -2936
  5. package/dist/src/commands/helpers.test.js +0 -832
  6. package/dist/src/commands/project.test.js +0 -1201
  7. package/dist/src/commands/resources.test.js +0 -2511
  8. package/dist/src/commands/schedule.test.js +0 -1235
  9. package/dist/src/commands/secret.test.d.js +0 -1
  10. package/dist/src/commands/secret.test.js +0 -761
  11. package/dist/src/commands/server.test.js +0 -1237
  12. package/dist/src/commands/test-utils.js +0 -737
  13. package/dist/src/components/secret-sync.js +0 -303
  14. package/dist/src/test/mock-api-client.js +0 -371
  15. package/dist/src/test/test-dev-server.js +0 -1376
  16. package/dist/types/commands/test-utils.d.ts +0 -45
  17. package/dist/types/commands/test-utils.d.ts.map +0 -1
  18. package/dist/types/components/secret-sync.d.ts +0 -9
  19. package/dist/types/components/secret-sync.d.ts.map +0 -1
  20. package/dist/types/test/mock-api-client.d.ts +0 -25
  21. package/dist/types/test/mock-api-client.d.ts.map +0 -1
  22. package/dist/types/test/test-dev-server.d.ts +0 -129
  23. package/dist/types/test/test-dev-server.d.ts.map +0 -1
  24. package/src/cli.ts +0 -997
  25. package/src/commands/backend.ts +0 -63
  26. package/src/commands/brain.test.ts +0 -1004
  27. package/src/commands/brain.ts +0 -215
  28. package/src/commands/helpers.test.ts +0 -487
  29. package/src/commands/helpers.ts +0 -870
  30. package/src/commands/project-config-manager.ts +0 -152
  31. package/src/commands/project.test.ts +0 -502
  32. package/src/commands/project.ts +0 -109
  33. package/src/commands/resources.test.ts +0 -1052
  34. package/src/commands/resources.ts +0 -97
  35. package/src/commands/schedule.test.ts +0 -481
  36. package/src/commands/schedule.ts +0 -65
  37. package/src/commands/secret.test.ts +0 -210
  38. package/src/commands/secret.ts +0 -50
  39. package/src/commands/server.test.ts +0 -493
  40. package/src/commands/server.ts +0 -353
  41. package/src/commands/test-utils.ts +0 -324
  42. package/src/components/brain-history.tsx +0 -198
  43. package/src/components/brain-list.tsx +0 -105
  44. package/src/components/brain-rerun.tsx +0 -111
  45. package/src/components/brain-show.tsx +0 -92
  46. package/src/components/error.tsx +0 -24
  47. package/src/components/project-add.tsx +0 -59
  48. package/src/components/project-create.tsx +0 -83
  49. package/src/components/project-list.tsx +0 -83
  50. package/src/components/project-remove.tsx +0 -55
  51. package/src/components/project-select.tsx +0 -200
  52. package/src/components/project-show.tsx +0 -58
  53. package/src/components/resource-clear.tsx +0 -127
  54. package/src/components/resource-delete.tsx +0 -160
  55. package/src/components/resource-list.tsx +0 -177
  56. package/src/components/resource-sync.tsx +0 -170
  57. package/src/components/resource-types.tsx +0 -55
  58. package/src/components/resource-upload.tsx +0 -182
  59. package/src/components/schedule-create.tsx +0 -90
  60. package/src/components/schedule-delete.tsx +0 -116
  61. package/src/components/schedule-list.tsx +0 -186
  62. package/src/components/schedule-runs.tsx +0 -151
  63. package/src/components/secret-bulk.tsx +0 -79
  64. package/src/components/secret-create.tsx +0 -49
  65. package/src/components/secret-delete.tsx +0 -41
  66. package/src/components/secret-list.tsx +0 -41
  67. package/src/components/watch.tsx +0 -155
  68. package/src/hooks/useApi.ts +0 -183
  69. package/src/positronic.ts +0 -40
  70. package/src/test/data/resources/config.json +0 -1
  71. package/src/test/data/resources/data/config.json +0 -1
  72. package/src/test/data/resources/data/logo.png +0 -2
  73. package/src/test/data/resources/docs/api.md +0 -3
  74. package/src/test/data/resources/docs/readme.md +0 -3
  75. package/src/test/data/resources/example.md +0 -3
  76. package/src/test/data/resources/file with spaces.txt +0 -1
  77. package/src/test/data/resources/readme.md +0 -3
  78. package/src/test/data/resources/test.txt +0 -1
  79. package/src/test/mock-api-client.ts +0 -145
  80. package/src/test/test-dev-server.ts +0 -1003
  81. package/tsconfig.json +0 -11
@@ -1,303 +0,0 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _async_to_generator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _instanceof(left, right) {
39
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
40
- return !!right[Symbol.hasInstance](left);
41
- } else {
42
- return left instanceof right;
43
- }
44
- }
45
- function _iterable_to_array_limit(arr, i) {
46
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
47
- if (_i == null) return;
48
- var _arr = [];
49
- var _n = true;
50
- var _d = false;
51
- var _s, _e;
52
- try {
53
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
54
- _arr.push(_s.value);
55
- if (i && _arr.length === i) break;
56
- }
57
- } catch (err) {
58
- _d = true;
59
- _e = err;
60
- } finally{
61
- try {
62
- if (!_n && _i["return"] != null) _i["return"]();
63
- } finally{
64
- if (_d) throw _e;
65
- }
66
- }
67
- return _arr;
68
- }
69
- function _non_iterable_rest() {
70
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
- }
72
- function _sliced_to_array(arr, i) {
73
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
74
- }
75
- function _unsupported_iterable_to_array(o, minLen) {
76
- if (!o) return;
77
- if (typeof o === "string") return _array_like_to_array(o, minLen);
78
- var n = Object.prototype.toString.call(o).slice(8, -1);
79
- if (n === "Object" && o.constructor) n = o.constructor.name;
80
- if (n === "Map" || n === "Set") return Array.from(n);
81
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
82
- }
83
- function _ts_generator(thisArg, body) {
84
- var f, y, t, _ = {
85
- label: 0,
86
- sent: function() {
87
- if (t[0] & 1) throw t[1];
88
- return t[1];
89
- },
90
- trys: [],
91
- ops: []
92
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
93
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
94
- return this;
95
- }), g;
96
- function verb(n) {
97
- return function(v) {
98
- return step([
99
- n,
100
- v
101
- ]);
102
- };
103
- }
104
- function step(op) {
105
- if (f) throw new TypeError("Generator is already executing.");
106
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
107
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
108
- if (y = 0, t) op = [
109
- op[0] & 2,
110
- t.value
111
- ];
112
- switch(op[0]){
113
- case 0:
114
- case 1:
115
- t = op;
116
- break;
117
- case 4:
118
- _.label++;
119
- return {
120
- value: op[1],
121
- done: false
122
- };
123
- case 5:
124
- _.label++;
125
- y = op[1];
126
- op = [
127
- 0
128
- ];
129
- continue;
130
- case 7:
131
- op = _.ops.pop();
132
- _.trys.pop();
133
- continue;
134
- default:
135
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
136
- _ = 0;
137
- continue;
138
- }
139
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
140
- _.label = op[1];
141
- break;
142
- }
143
- if (op[0] === 6 && _.label < t[1]) {
144
- _.label = t[1];
145
- t = op;
146
- break;
147
- }
148
- if (t && _.label < t[2]) {
149
- _.label = t[2];
150
- _.ops.push(op);
151
- break;
152
- }
153
- if (t[2]) _.ops.pop();
154
- _.trys.pop();
155
- continue;
156
- }
157
- op = body.call(thisArg, _);
158
- } catch (e) {
159
- op = [
160
- 6,
161
- e
162
- ];
163
- y = 0;
164
- } finally{
165
- f = t = 0;
166
- }
167
- if (op[0] & 5) throw op[1];
168
- return {
169
- value: op[0] ? op[1] : void 0,
170
- done: true
171
- };
172
- }
173
- }
174
- import React, { useEffect, useState } from 'react';
175
- import { Text, Box } from 'ink';
176
- import * as path from 'path';
177
- export var SecretSync = function(param) {
178
- var _param_file = param.file, file = _param_file === void 0 ? '.env' : _param_file, _param_dryRun = param.dryRun, dryRun = _param_dryRun === void 0 ? false : _param_dryRun, server = param.server;
179
- var _useState = _sliced_to_array(useState(true), 2), loading = _useState[0], setLoading = _useState[1];
180
- var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
181
- var _useState2 = _sliced_to_array(useState(null), 2), syncResult = _useState2[0], setSyncResult = _useState2[1];
182
- useEffect(function() {
183
- var syncSecrets = function() {
184
- return _async_to_generator(function() {
185
- var filePath, result, error;
186
- return _ts_generator(this, function(_state) {
187
- switch(_state.label){
188
- case 0:
189
- if (!server) {
190
- setError('No server connection available');
191
- setLoading(false);
192
- return [
193
- 2
194
- ];
195
- }
196
- if (!server.syncSecrets) {
197
- setError('Secret sync is not supported by this backend');
198
- setLoading(false);
199
- return [
200
- 2
201
- ];
202
- }
203
- _state.label = 1;
204
- case 1:
205
- _state.trys.push([
206
- 1,
207
- 3,
208
- ,
209
- 4
210
- ]);
211
- setLoading(true);
212
- setError(null);
213
- // Resolve the file path relative to the project root
214
- filePath = path.resolve(server.projectRootDir, file);
215
- return [
216
- 4,
217
- server.syncSecrets(filePath, dryRun)
218
- ];
219
- case 2:
220
- result = _state.sent();
221
- setSyncResult(result);
222
- setLoading(false);
223
- return [
224
- 3,
225
- 4
226
- ];
227
- case 3:
228
- error = _state.sent();
229
- setError(_instanceof(error, Error) ? error.message : 'Failed to sync secrets');
230
- setLoading(false);
231
- return [
232
- 3,
233
- 4
234
- ];
235
- case 4:
236
- return [
237
- 2
238
- ];
239
- }
240
- });
241
- })();
242
- };
243
- syncSecrets();
244
- }, [
245
- file,
246
- dryRun,
247
- server
248
- ]);
249
- if (error) {
250
- return /*#__PURE__*/ React.createElement(Box, {
251
- flexDirection: "column"
252
- }, /*#__PURE__*/ React.createElement(Text, {
253
- color: "red"
254
- }, "❌ Error: ", error));
255
- }
256
- if (loading) {
257
- return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, "\uD83D\uDD04 ", dryRun ? 'Reading' : 'Syncing', " secrets from ", file, "..."));
258
- }
259
- if (syncResult) {
260
- if (dryRun && syncResult.preview) {
261
- return /*#__PURE__*/ React.createElement(Box, {
262
- flexDirection: "column",
263
- paddingTop: 1,
264
- paddingBottom: 1
265
- }, /*#__PURE__*/ React.createElement(Text, {
266
- bold: true
267
- }, "\uD83D\uDD0D Dry run: Secrets found in ", file, ":"), /*#__PURE__*/ React.createElement(Box, {
268
- marginTop: 1,
269
- flexDirection: "column"
270
- }, syncResult.preview.map(function(secret) {
271
- return /*#__PURE__*/ React.createElement(Text, {
272
- key: secret.name
273
- }, " • ", secret.name);
274
- })), /*#__PURE__*/ React.createElement(Box, {
275
- marginTop: 1
276
- }, /*#__PURE__*/ React.createElement(Text, {
277
- dimColor: true
278
- }, "Total: ", syncResult.preview.length, " secret", syncResult.preview.length !== 1 ? 's' : '')));
279
- }
280
- return /*#__PURE__*/ React.createElement(Box, {
281
- flexDirection: "column",
282
- paddingTop: 1,
283
- paddingBottom: 1
284
- }, /*#__PURE__*/ React.createElement(Text, {
285
- bold: true,
286
- color: "green"
287
- }, "✅ Secrets synced successfully!"), /*#__PURE__*/ React.createElement(Box, {
288
- marginTop: 1,
289
- flexDirection: "column"
290
- }, syncResult.created > 0 && /*#__PURE__*/ React.createElement(Text, null, " • Created: ", syncResult.created, " secret", syncResult.created !== 1 ? 's' : ''), syncResult.updated > 0 && /*#__PURE__*/ React.createElement(Text, null, " • Updated: ", syncResult.updated, " secret", syncResult.updated !== 1 ? 's' : '')), syncResult.errors && syncResult.errors.length > 0 && /*#__PURE__*/ React.createElement(Box, {
291
- marginTop: 1,
292
- flexDirection: "column"
293
- }, /*#__PURE__*/ React.createElement(Text, {
294
- color: "yellow"
295
- }, "⚠️ Errors encountered:"), syncResult.errors.map(function(error, index) {
296
- return /*#__PURE__*/ React.createElement(Text, {
297
- key: index,
298
- color: "yellow"
299
- }, " • ", error);
300
- })));
301
- }
302
- return null;
303
- };
@@ -1,371 +0,0 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_without_holes(arr) {
7
- if (Array.isArray(arr)) return _array_like_to_array(arr);
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _async_to_generator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _class_call_check(instance, Constructor) {
39
- if (!(instance instanceof Constructor)) {
40
- throw new TypeError("Cannot call a class as a function");
41
- }
42
- }
43
- function _defineProperties(target, props) {
44
- for(var i = 0; i < props.length; i++){
45
- var descriptor = props[i];
46
- descriptor.enumerable = descriptor.enumerable || false;
47
- descriptor.configurable = true;
48
- if ("value" in descriptor) descriptor.writable = true;
49
- Object.defineProperty(target, descriptor.key, descriptor);
50
- }
51
- }
52
- function _create_class(Constructor, protoProps, staticProps) {
53
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
54
- if (staticProps) _defineProperties(Constructor, staticProps);
55
- return Constructor;
56
- }
57
- function _define_property(obj, key, value) {
58
- if (key in obj) {
59
- Object.defineProperty(obj, key, {
60
- value: value,
61
- enumerable: true,
62
- configurable: true,
63
- writable: true
64
- });
65
- } else {
66
- obj[key] = value;
67
- }
68
- return obj;
69
- }
70
- function _instanceof(left, right) {
71
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
72
- return !!right[Symbol.hasInstance](left);
73
- } else {
74
- return left instanceof right;
75
- }
76
- }
77
- function _iterable_to_array(iter) {
78
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
79
- }
80
- function _non_iterable_spread() {
81
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
82
- }
83
- function _to_consumable_array(arr) {
84
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
85
- }
86
- function _unsupported_iterable_to_array(o, minLen) {
87
- if (!o) return;
88
- if (typeof o === "string") return _array_like_to_array(o, minLen);
89
- var n = Object.prototype.toString.call(o).slice(8, -1);
90
- if (n === "Object" && o.constructor) n = o.constructor.name;
91
- if (n === "Map" || n === "Set") return Array.from(n);
92
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
93
- }
94
- function _ts_generator(thisArg, body) {
95
- var f, y, t, _ = {
96
- label: 0,
97
- sent: function() {
98
- if (t[0] & 1) throw t[1];
99
- return t[1];
100
- },
101
- trys: [],
102
- ops: []
103
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
104
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
105
- return this;
106
- }), g;
107
- function verb(n) {
108
- return function(v) {
109
- return step([
110
- n,
111
- v
112
- ]);
113
- };
114
- }
115
- function step(op) {
116
- if (f) throw new TypeError("Generator is already executing.");
117
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
118
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
119
- if (y = 0, t) op = [
120
- op[0] & 2,
121
- t.value
122
- ];
123
- switch(op[0]){
124
- case 0:
125
- case 1:
126
- t = op;
127
- break;
128
- case 4:
129
- _.label++;
130
- return {
131
- value: op[1],
132
- done: false
133
- };
134
- case 5:
135
- _.label++;
136
- y = op[1];
137
- op = [
138
- 0
139
- ];
140
- continue;
141
- case 7:
142
- op = _.ops.pop();
143
- _.trys.pop();
144
- continue;
145
- default:
146
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
147
- _ = 0;
148
- continue;
149
- }
150
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
151
- _.label = op[1];
152
- break;
153
- }
154
- if (op[0] === 6 && _.label < t[1]) {
155
- _.label = t[1];
156
- t = op;
157
- break;
158
- }
159
- if (t && _.label < t[2]) {
160
- _.label = t[2];
161
- _.ops.push(op);
162
- break;
163
- }
164
- if (t[2]) _.ops.pop();
165
- _.trys.pop();
166
- continue;
167
- }
168
- op = body.call(thisArg, _);
169
- } catch (e) {
170
- op = [
171
- 6,
172
- e
173
- ];
174
- y = 0;
175
- } finally{
176
- f = t = 0;
177
- }
178
- if (op[0] & 5) throw op[1];
179
- return {
180
- value: op[0] ? op[1] : void 0,
181
- done: true
182
- };
183
- }
184
- }
185
- export var MockApiClient = /*#__PURE__*/ function() {
186
- "use strict";
187
- function MockApiClient() {
188
- _class_call_check(this, MockApiClient);
189
- _define_property(this, "resources", []);
190
- _define_property(this, "brainRuns", new Map());
191
- // Track all calls for assertions
192
- _define_property(this, "calls", []);
193
- }
194
- _create_class(MockApiClient, [
195
- {
196
- key: "fetch",
197
- value: function fetch(path, options) {
198
- return _async_to_generator(function() {
199
- var formData, type, key, file, local, newResource, existingIndex, deleteMatch, key1, index, body, brainRunId;
200
- return _ts_generator(this, function(_state) {
201
- this.calls.push({
202
- path: path,
203
- options: options
204
- });
205
- // Mock GET /resources
206
- if (path === '/resources' && (!options || options.method === 'GET')) {
207
- return [
208
- 2,
209
- new Response(JSON.stringify({
210
- resources: this.resources,
211
- truncated: false,
212
- count: this.resources.length
213
- }), {
214
- status: 200,
215
- headers: {
216
- 'Content-Type': 'application/json'
217
- }
218
- })
219
- ];
220
- }
221
- // Mock POST /resources
222
- if (path === '/resources' && (options === null || options === void 0 ? void 0 : options.method) === 'POST') {
223
- // Extract form data from the request
224
- formData = options.body;
225
- if (formData && _instanceof(formData, FormData)) {
226
- type = formData.get('type');
227
- key = formData.get('key');
228
- file = formData.get('file');
229
- local = formData.get('local');
230
- if (type && key && file) {
231
- newResource = {
232
- key: key,
233
- type: type,
234
- size: file.size || 100,
235
- lastModified: new Date().toISOString(),
236
- local: local === 'true'
237
- };
238
- // Update existing or add new
239
- existingIndex = this.resources.findIndex(function(r) {
240
- return r.key === key;
241
- });
242
- if (existingIndex >= 0) {
243
- this.resources[existingIndex] = newResource;
244
- } else {
245
- this.resources.push(newResource);
246
- }
247
- return [
248
- 2,
249
- new Response(JSON.stringify(newResource), {
250
- status: 201,
251
- headers: {
252
- 'Content-Type': 'application/json'
253
- }
254
- })
255
- ];
256
- }
257
- }
258
- return [
259
- 2,
260
- new Response('Bad Request', {
261
- status: 400
262
- })
263
- ];
264
- }
265
- // Mock DELETE /resources (bulk delete all)
266
- if (path === '/resources' && (options === null || options === void 0 ? void 0 : options.method) === 'DELETE') {
267
- this.resources = [];
268
- return [
269
- 2,
270
- new Response(null, {
271
- status: 204
272
- })
273
- ];
274
- }
275
- // Mock DELETE /resources/:key
276
- deleteMatch = path.match(/^\/resources\/(.+)$/);
277
- if (deleteMatch && (options === null || options === void 0 ? void 0 : options.method) === 'DELETE') {
278
- key1 = decodeURIComponent(deleteMatch[1]);
279
- index = this.resources.findIndex(function(r) {
280
- return r.key === key1;
281
- });
282
- if (index >= 0) {
283
- this.resources.splice(index, 1);
284
- }
285
- // Always return 204 for delete (idempotent)
286
- return [
287
- 2,
288
- new Response(null, {
289
- status: 204
290
- })
291
- ];
292
- }
293
- // Mock POST /brains/runs
294
- if (path === '/brains/runs' && (options === null || options === void 0 ? void 0 : options.method) === 'POST') {
295
- if (typeof options.body === 'string') {
296
- body = JSON.parse(options.body);
297
- brainRunId = "run-".concat(Date.now());
298
- this.brainRuns.set(brainRunId, {
299
- brainName: body.brainName,
300
- id: brainRunId
301
- });
302
- return [
303
- 2,
304
- new Response(JSON.stringify({
305
- brainRunId: brainRunId
306
- }), {
307
- status: 201,
308
- headers: {
309
- 'Content-Type': 'application/json'
310
- }
311
- })
312
- ];
313
- }
314
- return [
315
- 2,
316
- new Response('Bad Request', {
317
- status: 400
318
- })
319
- ];
320
- }
321
- // Default: Not found
322
- return [
323
- 2,
324
- new Response('Not Found', {
325
- status: 404
326
- })
327
- ];
328
- });
329
- }).call(this);
330
- }
331
- },
332
- {
333
- // Helper methods for test setup
334
- key: "addResource",
335
- value: function addResource(resource) {
336
- this.resources.push(resource);
337
- }
338
- },
339
- {
340
- key: "clearResources",
341
- value: function clearResources() {
342
- this.resources = [];
343
- }
344
- },
345
- {
346
- key: "getResources",
347
- value: function getResources() {
348
- return _to_consumable_array(this.resources);
349
- }
350
- },
351
- {
352
- key: "reset",
353
- value: function reset() {
354
- this.resources = [];
355
- this.brainRuns.clear();
356
- this.calls = [];
357
- }
358
- }
359
- ]);
360
- return MockApiClient;
361
- }();
362
- // Factory function for creating mock clients with initial data
363
- export function createMockApiClient(initialResources) {
364
- var client = new MockApiClient();
365
- if (initialResources) {
366
- initialResources.forEach(function(r) {
367
- return client.addResource(r);
368
- });
369
- }
370
- return client;
371
- }