@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,243 @@
|
|
|
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, { useState, useEffect } from 'react';
|
|
175
|
+
import { Text, Box } from 'ink';
|
|
176
|
+
import { generateTypes } from '../commands/helpers.js';
|
|
177
|
+
import { ErrorComponent } from './error.js';
|
|
178
|
+
export var ResourceTypes = function(param) {
|
|
179
|
+
var projectRootDir = param.projectRootDir;
|
|
180
|
+
var _useState = _sliced_to_array(useState('loading'), 2), status = _useState[0], setStatus = _useState[1];
|
|
181
|
+
var _useState1 = _sliced_to_array(useState(''), 2), typesFilePath = _useState1[0], setTypesFilePath = _useState1[1];
|
|
182
|
+
var _useState2 = _sliced_to_array(useState(null), 2), error = _useState2[0], setError = _useState2[1];
|
|
183
|
+
useEffect(function() {
|
|
184
|
+
var generateResourceTypes = function() {
|
|
185
|
+
return _async_to_generator(function() {
|
|
186
|
+
var filePath, err;
|
|
187
|
+
return _ts_generator(this, function(_state) {
|
|
188
|
+
switch(_state.label){
|
|
189
|
+
case 0:
|
|
190
|
+
_state.trys.push([
|
|
191
|
+
0,
|
|
192
|
+
2,
|
|
193
|
+
,
|
|
194
|
+
3
|
|
195
|
+
]);
|
|
196
|
+
return [
|
|
197
|
+
4,
|
|
198
|
+
generateTypes(projectRootDir)
|
|
199
|
+
];
|
|
200
|
+
case 1:
|
|
201
|
+
filePath = _state.sent();
|
|
202
|
+
setTypesFilePath(filePath);
|
|
203
|
+
setStatus('success');
|
|
204
|
+
return [
|
|
205
|
+
3,
|
|
206
|
+
3
|
|
207
|
+
];
|
|
208
|
+
case 2:
|
|
209
|
+
err = _state.sent();
|
|
210
|
+
setError(_instanceof(err, Error) ? err : new Error(String(err)));
|
|
211
|
+
setStatus('error');
|
|
212
|
+
return [
|
|
213
|
+
3,
|
|
214
|
+
3
|
|
215
|
+
];
|
|
216
|
+
case 3:
|
|
217
|
+
return [
|
|
218
|
+
2
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
})();
|
|
223
|
+
};
|
|
224
|
+
generateResourceTypes();
|
|
225
|
+
}, [
|
|
226
|
+
projectRootDir
|
|
227
|
+
]);
|
|
228
|
+
if (status === 'loading') {
|
|
229
|
+
return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, "\uD83D\uDD04 Generating resource types..."));
|
|
230
|
+
}
|
|
231
|
+
if (status === 'error') {
|
|
232
|
+
return /*#__PURE__*/ React.createElement(ErrorComponent, {
|
|
233
|
+
error: {
|
|
234
|
+
title: 'Type Generation Failed',
|
|
235
|
+
message: 'Failed to generate resource types.',
|
|
236
|
+
details: (error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, {
|
|
241
|
+
color: "green"
|
|
242
|
+
}, "✅ Generated resource types at ", typesFilePath));
|
|
243
|
+
};
|
|
@@ -0,0 +1,366 @@
|
|
|
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 _iterable_to_array_limit(arr, i) {
|
|
39
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
+
if (_i == null) return;
|
|
41
|
+
var _arr = [];
|
|
42
|
+
var _n = true;
|
|
43
|
+
var _d = false;
|
|
44
|
+
var _s, _e;
|
|
45
|
+
try {
|
|
46
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
+
_arr.push(_s.value);
|
|
48
|
+
if (i && _arr.length === i) break;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_d = true;
|
|
52
|
+
_e = err;
|
|
53
|
+
} finally{
|
|
54
|
+
try {
|
|
55
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
+
} finally{
|
|
57
|
+
if (_d) throw _e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return _arr;
|
|
61
|
+
}
|
|
62
|
+
function _non_iterable_rest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _sliced_to_array(arr, i) {
|
|
66
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
|
+
}
|
|
68
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
69
|
+
if (!o) return;
|
|
70
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
71
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
72
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
73
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
74
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
75
|
+
}
|
|
76
|
+
function _ts_generator(thisArg, body) {
|
|
77
|
+
var f, y, t, _ = {
|
|
78
|
+
label: 0,
|
|
79
|
+
sent: function() {
|
|
80
|
+
if (t[0] & 1) throw t[1];
|
|
81
|
+
return t[1];
|
|
82
|
+
},
|
|
83
|
+
trys: [],
|
|
84
|
+
ops: []
|
|
85
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
86
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
87
|
+
return this;
|
|
88
|
+
}), g;
|
|
89
|
+
function verb(n) {
|
|
90
|
+
return function(v) {
|
|
91
|
+
return step([
|
|
92
|
+
n,
|
|
93
|
+
v
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function step(op) {
|
|
98
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
99
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
100
|
+
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;
|
|
101
|
+
if (y = 0, t) op = [
|
|
102
|
+
op[0] & 2,
|
|
103
|
+
t.value
|
|
104
|
+
];
|
|
105
|
+
switch(op[0]){
|
|
106
|
+
case 0:
|
|
107
|
+
case 1:
|
|
108
|
+
t = op;
|
|
109
|
+
break;
|
|
110
|
+
case 4:
|
|
111
|
+
_.label++;
|
|
112
|
+
return {
|
|
113
|
+
value: op[1],
|
|
114
|
+
done: false
|
|
115
|
+
};
|
|
116
|
+
case 5:
|
|
117
|
+
_.label++;
|
|
118
|
+
y = op[1];
|
|
119
|
+
op = [
|
|
120
|
+
0
|
|
121
|
+
];
|
|
122
|
+
continue;
|
|
123
|
+
case 7:
|
|
124
|
+
op = _.ops.pop();
|
|
125
|
+
_.trys.pop();
|
|
126
|
+
continue;
|
|
127
|
+
default:
|
|
128
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
129
|
+
_ = 0;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
133
|
+
_.label = op[1];
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
137
|
+
_.label = t[1];
|
|
138
|
+
t = op;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (t && _.label < t[2]) {
|
|
142
|
+
_.label = t[2];
|
|
143
|
+
_.ops.push(op);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (t[2]) _.ops.pop();
|
|
147
|
+
_.trys.pop();
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
op = body.call(thisArg, _);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
op = [
|
|
153
|
+
6,
|
|
154
|
+
e
|
|
155
|
+
];
|
|
156
|
+
y = 0;
|
|
157
|
+
} finally{
|
|
158
|
+
f = t = 0;
|
|
159
|
+
}
|
|
160
|
+
if (op[0] & 5) throw op[1];
|
|
161
|
+
return {
|
|
162
|
+
value: op[0] ? op[1] : void 0,
|
|
163
|
+
done: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
168
|
+
import { Box, Text } from 'ink';
|
|
169
|
+
import { ErrorComponent } from './error.js';
|
|
170
|
+
import { uploadFileWithPresignedUrl, generateTypes } from '../commands/helpers.js';
|
|
171
|
+
import * as fs from 'fs';
|
|
172
|
+
import * as path from 'path';
|
|
173
|
+
export var ResourceUpload = function(param) {
|
|
174
|
+
var filePath = param.filePath, customKey = param.customKey, projectRootPath = param.projectRootPath;
|
|
175
|
+
var _useState = _sliced_to_array(useState(false), 2), uploading = _useState[0], setUploading = _useState[1];
|
|
176
|
+
var _useState1 = _sliced_to_array(useState(null), 2), progress = _useState1[0], setProgress = _useState1[1];
|
|
177
|
+
var _useState2 = _sliced_to_array(useState(false), 2), complete = _useState2[0], setComplete = _useState2[1];
|
|
178
|
+
var _useState3 = _sliced_to_array(useState(null), 2), error = _useState3[0], setError = _useState3[1];
|
|
179
|
+
var _useState4 = _sliced_to_array(useState(''), 2), resourceKey = _useState4[0], setResourceKey = _useState4[1];
|
|
180
|
+
var abortControllerRef = useRef(null);
|
|
181
|
+
useEffect(function() {
|
|
182
|
+
performUpload();
|
|
183
|
+
return function() {
|
|
184
|
+
// Cleanup: abort upload if component unmounts
|
|
185
|
+
if (abortControllerRef.current) {
|
|
186
|
+
abortControllerRef.current.abort();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}, []);
|
|
190
|
+
var performUpload = function() {
|
|
191
|
+
return _async_to_generator(function() {
|
|
192
|
+
var _abortControllerRef_current, stats, key, typeError, err, _err_message;
|
|
193
|
+
return _ts_generator(this, function(_state) {
|
|
194
|
+
switch(_state.label){
|
|
195
|
+
case 0:
|
|
196
|
+
_state.trys.push([
|
|
197
|
+
0,
|
|
198
|
+
6,
|
|
199
|
+
7,
|
|
200
|
+
8
|
|
201
|
+
]);
|
|
202
|
+
// Check if file exists
|
|
203
|
+
if (!fs.existsSync(filePath)) {
|
|
204
|
+
setError({
|
|
205
|
+
title: 'File Not Found',
|
|
206
|
+
message: 'The file "'.concat(filePath, '" does not exist.')
|
|
207
|
+
});
|
|
208
|
+
return [
|
|
209
|
+
2
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
stats = fs.statSync(filePath);
|
|
213
|
+
if (!stats.isFile()) {
|
|
214
|
+
setError({
|
|
215
|
+
title: 'Invalid Path',
|
|
216
|
+
message: '"'.concat(filePath, '" is not a file.')
|
|
217
|
+
});
|
|
218
|
+
return [
|
|
219
|
+
2
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
// Determine resource key
|
|
223
|
+
key = customKey || path.basename(filePath);
|
|
224
|
+
setResourceKey(key);
|
|
225
|
+
setUploading(true);
|
|
226
|
+
setProgress({
|
|
227
|
+
loaded: 0,
|
|
228
|
+
total: stats.size,
|
|
229
|
+
percentage: 0
|
|
230
|
+
});
|
|
231
|
+
// Create abort controller for cancellation
|
|
232
|
+
abortControllerRef.current = new AbortController();
|
|
233
|
+
// Use presigned URL upload with progress callback
|
|
234
|
+
return [
|
|
235
|
+
4,
|
|
236
|
+
uploadFileWithPresignedUrl(filePath, key, undefined, function(progressInfo) {
|
|
237
|
+
setProgress(progressInfo);
|
|
238
|
+
}, (_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal)
|
|
239
|
+
];
|
|
240
|
+
case 1:
|
|
241
|
+
_state.sent();
|
|
242
|
+
setProgress({
|
|
243
|
+
loaded: stats.size,
|
|
244
|
+
total: stats.size,
|
|
245
|
+
percentage: 100
|
|
246
|
+
});
|
|
247
|
+
setComplete(true);
|
|
248
|
+
if (!projectRootPath) return [
|
|
249
|
+
3,
|
|
250
|
+
5
|
|
251
|
+
];
|
|
252
|
+
_state.label = 2;
|
|
253
|
+
case 2:
|
|
254
|
+
_state.trys.push([
|
|
255
|
+
2,
|
|
256
|
+
4,
|
|
257
|
+
,
|
|
258
|
+
5
|
|
259
|
+
]);
|
|
260
|
+
return [
|
|
261
|
+
4,
|
|
262
|
+
generateTypes(projectRootPath)
|
|
263
|
+
];
|
|
264
|
+
case 3:
|
|
265
|
+
_state.sent();
|
|
266
|
+
return [
|
|
267
|
+
3,
|
|
268
|
+
5
|
|
269
|
+
];
|
|
270
|
+
case 4:
|
|
271
|
+
typeError = _state.sent();
|
|
272
|
+
// Don't fail the upload if type generation fails
|
|
273
|
+
console.error('Failed to generate types:', typeError);
|
|
274
|
+
return [
|
|
275
|
+
3,
|
|
276
|
+
5
|
|
277
|
+
];
|
|
278
|
+
case 5:
|
|
279
|
+
return [
|
|
280
|
+
3,
|
|
281
|
+
8
|
|
282
|
+
];
|
|
283
|
+
case 6:
|
|
284
|
+
err = _state.sent();
|
|
285
|
+
if (err.name === 'AbortError' || err.message === 'AbortError') {
|
|
286
|
+
setError({
|
|
287
|
+
title: 'Upload Cancelled',
|
|
288
|
+
message: 'The upload was cancelled.'
|
|
289
|
+
});
|
|
290
|
+
} else if ((_err_message = err.message) === null || _err_message === void 0 ? void 0 : _err_message.includes('R2 credentials not configured')) {
|
|
291
|
+
setError({
|
|
292
|
+
title: 'R2 Configuration Required',
|
|
293
|
+
message: 'Large file uploads require R2 configuration.',
|
|
294
|
+
details: 'Set R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_ACCOUNT_ID, and R2_BUCKET_NAME in your .env file.'
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
setError({
|
|
298
|
+
title: 'Upload Failed',
|
|
299
|
+
message: err.message || 'An unknown error occurred',
|
|
300
|
+
details: err.code === 'ECONNREFUSED' ? "Please ensure the server is running ('positronic server' or 'px s')" : undefined
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return [
|
|
304
|
+
3,
|
|
305
|
+
8
|
|
306
|
+
];
|
|
307
|
+
case 7:
|
|
308
|
+
setUploading(false);
|
|
309
|
+
abortControllerRef.current = null;
|
|
310
|
+
return [
|
|
311
|
+
7
|
|
312
|
+
];
|
|
313
|
+
case 8:
|
|
314
|
+
return [
|
|
315
|
+
2
|
|
316
|
+
];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
})();
|
|
320
|
+
};
|
|
321
|
+
if (error) {
|
|
322
|
+
return /*#__PURE__*/ React.createElement(ErrorComponent, {
|
|
323
|
+
error: error
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (complete) {
|
|
327
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
328
|
+
flexDirection: "column"
|
|
329
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
330
|
+
color: "green"
|
|
331
|
+
}, "✅ Upload complete!"), /*#__PURE__*/ React.createElement(Text, {
|
|
332
|
+
dimColor: true
|
|
333
|
+
}, "Resource key: ", resourceKey));
|
|
334
|
+
}
|
|
335
|
+
if (uploading && progress) {
|
|
336
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
337
|
+
flexDirection: "column"
|
|
338
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "⬆️ Uploading ", path.basename(filePath), "..."), /*#__PURE__*/ React.createElement(Box, {
|
|
339
|
+
marginTop: 1
|
|
340
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
341
|
+
dimColor: true
|
|
342
|
+
}, "Size: ", formatSize(progress.total))), progress.total > 1024 * 1024 && /*#__PURE__*/ React.createElement(Box, {
|
|
343
|
+
marginTop: 1
|
|
344
|
+
}, /*#__PURE__*/ React.createElement(ProgressBar, {
|
|
345
|
+
percentage: progress.percentage
|
|
346
|
+
})));
|
|
347
|
+
}
|
|
348
|
+
return /*#__PURE__*/ React.createElement(Text, null, "Preparing upload...");
|
|
349
|
+
};
|
|
350
|
+
var ProgressBar = function(param) {
|
|
351
|
+
var percentage = param.percentage;
|
|
352
|
+
var width = 30;
|
|
353
|
+
var filled = Math.round(percentage / 100 * width);
|
|
354
|
+
var empty = width - filled;
|
|
355
|
+
return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, "["), /*#__PURE__*/ React.createElement(Text, {
|
|
356
|
+
color: "green"
|
|
357
|
+
}, '█'.repeat(filled)), /*#__PURE__*/ React.createElement(Text, {
|
|
358
|
+
dimColor: true
|
|
359
|
+
}, '░'.repeat(empty)), /*#__PURE__*/ React.createElement(Text, null, "] ", percentage.toFixed(0), "%"));
|
|
360
|
+
};
|
|
361
|
+
function formatSize(bytes) {
|
|
362
|
+
if (bytes < 1024) return "".concat(bytes, " B");
|
|
363
|
+
if (bytes < 1024 * 1024) return "".concat((bytes / 1024).toFixed(1), " KB");
|
|
364
|
+
if (bytes < 1024 * 1024 * 1024) return "".concat((bytes / (1024 * 1024)).toFixed(1), " MB");
|
|
365
|
+
return "".concat((bytes / (1024 * 1024 * 1024)).toFixed(1), " GB");
|
|
366
|
+
}
|