@positronic/cli 0.0.2
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.
- package/dist/src/cli.js +739 -0
- package/dist/src/commands/backend.js +199 -0
- package/dist/src/commands/brain.js +446 -0
- package/dist/src/commands/brain.test.js +2936 -0
- package/dist/src/commands/helpers.js +1315 -0
- package/dist/src/commands/helpers.test.js +832 -0
- package/dist/src/commands/project-config-manager.js +197 -0
- package/dist/src/commands/project.js +130 -0
- package/dist/src/commands/project.test.js +1201 -0
- package/dist/src/commands/resources.js +272 -0
- package/dist/src/commands/resources.test.js +2511 -0
- package/dist/src/commands/schedule.js +73 -0
- package/dist/src/commands/schedule.test.js +1235 -0
- package/dist/src/commands/secret.js +87 -0
- package/dist/src/commands/secret.test.d.js +1 -0
- package/dist/src/commands/secret.test.js +761 -0
- package/dist/src/commands/server.js +816 -0
- package/dist/src/commands/server.test.js +1237 -0
- package/dist/src/commands/test-utils.js +737 -0
- package/dist/src/components/brain-history.js +169 -0
- package/dist/src/components/brain-list.js +108 -0
- package/dist/src/components/brain-rerun.js +313 -0
- package/dist/src/components/brain-show.js +65 -0
- package/dist/src/components/error.js +19 -0
- package/dist/src/components/project-add.js +95 -0
- package/dist/src/components/project-create.js +276 -0
- package/dist/src/components/project-list.js +88 -0
- package/dist/src/components/project-remove.js +91 -0
- package/dist/src/components/project-select.js +224 -0
- package/dist/src/components/project-show.js +41 -0
- package/dist/src/components/resource-clear.js +152 -0
- package/dist/src/components/resource-delete.js +189 -0
- package/dist/src/components/resource-list.js +174 -0
- package/dist/src/components/resource-sync.js +386 -0
- package/dist/src/components/resource-types.js +243 -0
- package/dist/src/components/resource-upload.js +366 -0
- package/dist/src/components/schedule-create.js +259 -0
- package/dist/src/components/schedule-delete.js +161 -0
- package/dist/src/components/schedule-list.js +176 -0
- package/dist/src/components/schedule-runs.js +103 -0
- package/dist/src/components/secret-bulk.js +262 -0
- package/dist/src/components/secret-create.js +199 -0
- package/dist/src/components/secret-delete.js +190 -0
- package/dist/src/components/secret-list.js +190 -0
- package/dist/src/components/secret-sync.js +303 -0
- package/dist/src/components/watch.js +184 -0
- package/dist/src/hooks/useApi.js +512 -0
- package/dist/src/positronic.js +33 -0
- package/dist/src/test/mock-api-client.js +371 -0
- package/dist/src/test/test-dev-server.js +1376 -0
- package/dist/types/cli.d.ts +9 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/commands/backend.d.ts +6 -0
- package/dist/types/commands/backend.d.ts.map +1 -0
- package/dist/types/commands/brain.d.ts +35 -0
- package/dist/types/commands/brain.d.ts.map +1 -0
- package/dist/types/commands/helpers.d.ts +55 -0
- package/dist/types/commands/helpers.d.ts.map +1 -0
- package/dist/types/commands/project-config-manager.d.ts +37 -0
- package/dist/types/commands/project-config-manager.d.ts.map +1 -0
- package/dist/types/commands/project.d.ts +55 -0
- package/dist/types/commands/project.d.ts.map +1 -0
- package/dist/types/commands/resources.d.ts +13 -0
- package/dist/types/commands/resources.d.ts.map +1 -0
- package/dist/types/commands/schedule.d.ts +27 -0
- package/dist/types/commands/schedule.d.ts.map +1 -0
- package/dist/types/commands/secret.d.ts +23 -0
- package/dist/types/commands/secret.d.ts.map +1 -0
- package/dist/types/commands/server.d.ts +12 -0
- package/dist/types/commands/server.d.ts.map +1 -0
- package/dist/types/commands/test-utils.d.ts +45 -0
- package/dist/types/commands/test-utils.d.ts.map +1 -0
- package/dist/types/components/brain-history.d.ts +7 -0
- package/dist/types/components/brain-history.d.ts.map +1 -0
- package/dist/types/components/brain-list.d.ts +2 -0
- package/dist/types/components/brain-list.d.ts.map +1 -0
- package/dist/types/components/brain-rerun.d.ts +9 -0
- package/dist/types/components/brain-rerun.d.ts.map +1 -0
- package/dist/types/components/brain-show.d.ts +6 -0
- package/dist/types/components/brain-show.d.ts.map +1 -0
- package/dist/types/components/error.d.ts +10 -0
- package/dist/types/components/error.d.ts.map +1 -0
- package/dist/types/components/project-add.d.ts +9 -0
- package/dist/types/components/project-add.d.ts.map +1 -0
- package/dist/types/components/project-create.d.ts +6 -0
- package/dist/types/components/project-create.d.ts.map +1 -0
- package/dist/types/components/project-list.d.ts +7 -0
- package/dist/types/components/project-list.d.ts.map +1 -0
- package/dist/types/components/project-remove.d.ts +8 -0
- package/dist/types/components/project-remove.d.ts.map +1 -0
- package/dist/types/components/project-select.d.ts +8 -0
- package/dist/types/components/project-select.d.ts.map +1 -0
- package/dist/types/components/project-show.d.ts +7 -0
- package/dist/types/components/project-show.d.ts.map +1 -0
- package/dist/types/components/resource-clear.d.ts +2 -0
- package/dist/types/components/resource-clear.d.ts.map +1 -0
- package/dist/types/components/resource-delete.d.ts +9 -0
- package/dist/types/components/resource-delete.d.ts.map +1 -0
- package/dist/types/components/resource-list.d.ts +2 -0
- package/dist/types/components/resource-list.d.ts.map +1 -0
- package/dist/types/components/resource-sync.d.ts +8 -0
- package/dist/types/components/resource-sync.d.ts.map +1 -0
- package/dist/types/components/resource-types.d.ts +7 -0
- package/dist/types/components/resource-types.d.ts.map +1 -0
- package/dist/types/components/resource-upload.d.ts +8 -0
- package/dist/types/components/resource-upload.d.ts.map +1 -0
- package/dist/types/components/schedule-create.d.ts +7 -0
- package/dist/types/components/schedule-create.d.ts.map +1 -0
- package/dist/types/components/schedule-delete.d.ts +7 -0
- package/dist/types/components/schedule-delete.d.ts.map +1 -0
- package/dist/types/components/schedule-list.d.ts +6 -0
- package/dist/types/components/schedule-list.d.ts.map +1 -0
- package/dist/types/components/schedule-runs.d.ts +8 -0
- package/dist/types/components/schedule-runs.d.ts.map +1 -0
- package/dist/types/components/secret-bulk.d.ts +8 -0
- package/dist/types/components/secret-bulk.d.ts.map +1 -0
- package/dist/types/components/secret-create.d.ts +9 -0
- package/dist/types/components/secret-create.d.ts.map +1 -0
- package/dist/types/components/secret-delete.d.ts +8 -0
- package/dist/types/components/secret-delete.d.ts.map +1 -0
- package/dist/types/components/secret-list.d.ts +7 -0
- package/dist/types/components/secret-list.d.ts.map +1 -0
- package/dist/types/components/secret-sync.d.ts +9 -0
- package/dist/types/components/secret-sync.d.ts.map +1 -0
- package/dist/types/components/watch.d.ts +7 -0
- package/dist/types/components/watch.d.ts.map +1 -0
- package/dist/types/hooks/useApi.d.ts +29 -0
- package/dist/types/hooks/useApi.d.ts.map +1 -0
- package/dist/types/positronic.d.ts +3 -0
- package/dist/types/positronic.d.ts.map +1 -0
- package/dist/types/test/mock-api-client.d.ts +25 -0
- package/dist/types/test/mock-api-client.d.ts.map +1 -0
- package/dist/types/test/test-dev-server.d.ts +129 -0
- package/dist/types/test/test-dev-server.d.ts.map +1 -0
- package/package.json +37 -0
- package/src/cli.ts +981 -0
- package/src/commands/backend.ts +63 -0
- package/src/commands/brain.test.ts +1004 -0
- package/src/commands/brain.ts +215 -0
- package/src/commands/helpers.test.ts +487 -0
- package/src/commands/helpers.ts +870 -0
- package/src/commands/project-config-manager.ts +152 -0
- package/src/commands/project.test.ts +502 -0
- package/src/commands/project.ts +109 -0
- package/src/commands/resources.test.ts +1052 -0
- package/src/commands/resources.ts +97 -0
- package/src/commands/schedule.test.ts +481 -0
- package/src/commands/schedule.ts +65 -0
- package/src/commands/secret.test.ts +210 -0
- package/src/commands/secret.ts +50 -0
- package/src/commands/server.test.ts +493 -0
- package/src/commands/server.ts +353 -0
- package/src/commands/test-utils.ts +324 -0
- package/src/components/brain-history.tsx +198 -0
- package/src/components/brain-list.tsx +105 -0
- package/src/components/brain-rerun.tsx +111 -0
- package/src/components/brain-show.tsx +92 -0
- package/src/components/error.tsx +24 -0
- package/src/components/project-add.tsx +59 -0
- package/src/components/project-create.tsx +83 -0
- package/src/components/project-list.tsx +83 -0
- package/src/components/project-remove.tsx +55 -0
- package/src/components/project-select.tsx +200 -0
- package/src/components/project-show.tsx +58 -0
- package/src/components/resource-clear.tsx +127 -0
- package/src/components/resource-delete.tsx +160 -0
- package/src/components/resource-list.tsx +177 -0
- package/src/components/resource-sync.tsx +170 -0
- package/src/components/resource-types.tsx +55 -0
- package/src/components/resource-upload.tsx +182 -0
- package/src/components/schedule-create.tsx +90 -0
- package/src/components/schedule-delete.tsx +116 -0
- package/src/components/schedule-list.tsx +186 -0
- package/src/components/schedule-runs.tsx +151 -0
- package/src/components/secret-bulk.tsx +79 -0
- package/src/components/secret-create.tsx +49 -0
- package/src/components/secret-delete.tsx +41 -0
- package/src/components/secret-list.tsx +41 -0
- package/src/components/watch.tsx +155 -0
- package/src/hooks/useApi.ts +183 -0
- package/src/positronic.ts +40 -0
- package/src/test/data/resources/config.json +1 -0
- package/src/test/data/resources/data/config.json +1 -0
- package/src/test/data/resources/data/logo.png +2 -0
- package/src/test/data/resources/docs/api.md +3 -0
- package/src/test/data/resources/docs/readme.md +3 -0
- package/src/test/data/resources/example.md +3 -0
- package/src/test/data/resources/file with spaces.txt +1 -0
- package/src/test/data/resources/readme.md +3 -0
- package/src/test/data/resources/test.txt +1 -0
- package/src/test/mock-api-client.ts +145 -0
- package/src/test/test-dev-server.ts +1003 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { buildCli } from './cli.js';
|
|
5
|
+
import { render } from 'ink';
|
|
6
|
+
import { createDevServer } from './commands/backend.js';
|
|
7
|
+
function findProjectRootSync(startDir) {
|
|
8
|
+
var currentDir = path.resolve(startDir);
|
|
9
|
+
while(true){
|
|
10
|
+
var configPath = path.join(currentDir, 'positronic.config.json');
|
|
11
|
+
try {
|
|
12
|
+
fs.accessSync(configPath);
|
|
13
|
+
return currentDir;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
var parentDir = path.dirname(currentDir);
|
|
16
|
+
if (parentDir === currentDir) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
currentDir = parentDir;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Determine mode and project path once at the start
|
|
24
|
+
var projectRootPath = findProjectRootSync(process.cwd());
|
|
25
|
+
var server = projectRootPath ? await createDevServer(projectRootPath) : undefined;
|
|
26
|
+
// Build and parse the CLI
|
|
27
|
+
var cli = buildCli({
|
|
28
|
+
server: server,
|
|
29
|
+
exitProcess: true,
|
|
30
|
+
render: render
|
|
31
|
+
});
|
|
32
|
+
// Parse the arguments
|
|
33
|
+
cli.parse();
|
|
@@ -0,0 +1,371 @@
|
|
|
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
|
+
}
|