@hype-stack/cli 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-CPOgUkiJ.js +4056 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/commands/compose.d.ts +3 -0
- package/dist/commands/compose.d.ts.map +1 -0
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/config/bin.d.ts.map +1 -0
- package/dist/config/bin.js +2440 -0
- package/dist/config/env.d.ts +9 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/constants/constants.d.ts +60 -0
- package/dist/constants/constants.d.ts.map +1 -0
- package/dist/core/access-prompts.d.ts +15 -0
- package/dist/core/access-prompts.d.ts.map +1 -0
- package/dist/core/auth-api.d.ts +9 -0
- package/dist/core/auth-api.d.ts.map +1 -0
- package/dist/core/auth-store.d.ts +16 -0
- package/dist/core/auth-store.d.ts.map +1 -0
- package/dist/core/client.d.ts +2 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/clone.d.ts.map +1 -1
- package/dist/core/codegen.d.ts +18 -0
- package/dist/core/codegen.d.ts.map +1 -0
- package/dist/core/codemods.d.ts +19 -0
- package/dist/core/codemods.d.ts.map +1 -0
- package/dist/core/device.d.ts +3 -0
- package/dist/core/device.d.ts.map +1 -0
- package/dist/core/editor-config.d.ts +1 -1
- package/dist/core/editor-config.d.ts.map +1 -1
- package/dist/core/env-files.d.ts +2 -0
- package/dist/core/env-files.d.ts.map +1 -0
- package/dist/core/installer.d.ts +57 -0
- package/dist/core/installer.d.ts.map +1 -0
- package/dist/core/license.d.ts +2 -0
- package/dist/core/license.d.ts.map +1 -0
- package/dist/core/login.d.ts +13 -0
- package/dist/core/login.d.ts.map +1 -0
- package/dist/core/npm-deps.d.ts +32 -0
- package/dist/core/npm-deps.d.ts.map +1 -0
- package/dist/core/open-browser.d.ts +2 -0
- package/dist/core/open-browser.d.ts.map +1 -0
- package/dist/core/post-setup.d.ts +6 -0
- package/dist/core/post-setup.d.ts.map +1 -0
- package/dist/core/readme.d.ts +10 -0
- package/dist/core/readme.d.ts.map +1 -0
- package/dist/core/registry.d.ts +35 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/resolve.d.ts +44 -0
- package/dist/core/resolve.d.ts.map +1 -0
- package/dist/core/stack-config.d.ts +3 -1
- package/dist/core/stack-config.d.ts.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/types/types.d.ts +177 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/logger.d.ts.map +1 -1
- package/dist/ui/theme.d.ts.map +1 -1
- package/package.json +15 -11
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -5
- package/dist/cli-B_f7CCee.js +0 -548
- package/dist/commands/add.d.ts +0 -2
- package/dist/commands/add.d.ts.map +0 -1
- package/dist/constants.d.ts +0 -30
- package/dist/constants.d.ts.map +0 -1
- package/dist/types.d.ts +0 -23
- package/dist/types.d.ts.map +0 -1
- /package/dist/{bin.d.ts → config/bin.d.ts} +0 -0
|
@@ -0,0 +1,4056 @@
|
|
|
1
|
+
import { Command as e } from "commander";
|
|
2
|
+
import * as t from "@clack/prompts";
|
|
3
|
+
import n from "node:fs/promises";
|
|
4
|
+
import r from "picocolors";
|
|
5
|
+
import i from "node:os";
|
|
6
|
+
import a from "node:path";
|
|
7
|
+
import { exec as o, spawn as s } from "node:child_process";
|
|
8
|
+
import { downloadTemplate as c } from "giget";
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
|
+
var l = Object.create, u = Object.defineProperty, d = Object.getOwnPropertyDescriptor, f = Object.getOwnPropertyNames, p = Object.getPrototypeOf, m = Object.prototype.hasOwnProperty, h = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), g = (e, t, n, r) => {
|
|
11
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = f(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !m.call(e, s) && s !== n && u(e, s, {
|
|
12
|
+
get: ((e) => t[e]).bind(null, s),
|
|
13
|
+
enumerable: !(r = d(t, s)) || r.enumerable
|
|
14
|
+
});
|
|
15
|
+
return e;
|
|
16
|
+
}, _ = (e, t, n) => (n = e == null ? {} : l(p(e)), g(t || !e || !e.__esModule ? u(n, "default", {
|
|
17
|
+
value: e,
|
|
18
|
+
enumerable: !0
|
|
19
|
+
}) : n, e)), v = "0.0.1", y = "gh:BetterTyped/hype-stack", b = "stack.json", x = "/schema/stack.json", S = "https://hypestack.dev", C = "HYPE_STACK_API_URL", w = /^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/, T = [
|
|
20
|
+
{
|
|
21
|
+
value: "cursor",
|
|
22
|
+
label: "Cursor",
|
|
23
|
+
hint: "default"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: "claude",
|
|
27
|
+
label: "Claude Code"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
value: "windsurf",
|
|
31
|
+
label: "Windsurf"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: "copilot",
|
|
35
|
+
label: "GitHub Copilot"
|
|
36
|
+
}
|
|
37
|
+
], E = T.map((e) => e.value), D = ".cursor/rules", O = ".cursor", ee = ".agents";
|
|
38
|
+
function k() {
|
|
39
|
+
let e = process.env.HYPE_STACK_API_URL;
|
|
40
|
+
return e ? (ne(e), e.replace(/\/+$/, "")) : S;
|
|
41
|
+
}
|
|
42
|
+
function te() {
|
|
43
|
+
let e = process.env.HYPE_STACK_WEB_URL;
|
|
44
|
+
return e ? (ne(e), e.replace(/\/+$/, "")) : k();
|
|
45
|
+
}
|
|
46
|
+
function ne(e) {
|
|
47
|
+
try {
|
|
48
|
+
let t = new URL(e);
|
|
49
|
+
if (!t.protocol.startsWith("http")) throw Error(`${C} must use http or https protocol, got "${t.protocol}"`);
|
|
50
|
+
} catch (t) {
|
|
51
|
+
throw t instanceof TypeError ? Error(`${C} is not a valid URL: "${e}"`, { cause: t }) : t;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function re() {
|
|
55
|
+
return `${k()}${x}`;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/ui/theme.ts
|
|
59
|
+
var A = (e) => `\x1b[38;5;208m${e}\x1b[39m`, j = (e) => `\x1b[38;5;214m${e}\x1b[39m`, M = (e) => `\x1b[38;5;220m${e}\x1b[39m`, ie = (e) => `\x1b[38;5;33m${e}\x1b[39m`, N = (e) => `\x1b[38;5;39m${e}\x1b[39m`, P = (e) => `\x1b[38;5;81m${e}\x1b[39m`, F = {
|
|
60
|
+
orange: A,
|
|
61
|
+
orangeBright: j,
|
|
62
|
+
amber: M,
|
|
63
|
+
deepBlue: ie,
|
|
64
|
+
skyBlue: N,
|
|
65
|
+
lightBlue: P
|
|
66
|
+
}, I = {
|
|
67
|
+
brand: (e) => A(e),
|
|
68
|
+
brandBold: (e) => r.bold(A(e)),
|
|
69
|
+
accent: (e) => N(e),
|
|
70
|
+
accentBold: (e) => r.bold(N(e)),
|
|
71
|
+
success: (e) => r.green(e),
|
|
72
|
+
error: (e) => r.red(e),
|
|
73
|
+
warning: (e) => r.yellow(e),
|
|
74
|
+
muted: (e) => r.dim(e),
|
|
75
|
+
bold: (e) => r.bold(e),
|
|
76
|
+
highlight: (e) => r.bold(r.white(e)),
|
|
77
|
+
path: (e) => r.underline(N(e)),
|
|
78
|
+
command: (e) => r.bold(M(e)),
|
|
79
|
+
label: (e) => r.dim(r.bold(e))
|
|
80
|
+
}, L = {
|
|
81
|
+
arrow: A("›"),
|
|
82
|
+
bullet: I.muted("·"),
|
|
83
|
+
dash: I.muted("─"),
|
|
84
|
+
corner: I.muted("╰"),
|
|
85
|
+
pipe: I.muted("│"),
|
|
86
|
+
dot: I.muted("•"),
|
|
87
|
+
spark: M("✦"),
|
|
88
|
+
sparkSmall: j("✧"),
|
|
89
|
+
bolt: M("⚡")
|
|
90
|
+
}, ae = [
|
|
91
|
+
A,
|
|
92
|
+
A,
|
|
93
|
+
j,
|
|
94
|
+
M,
|
|
95
|
+
ie,
|
|
96
|
+
N,
|
|
97
|
+
P,
|
|
98
|
+
P
|
|
99
|
+
];
|
|
100
|
+
function oe(e) {
|
|
101
|
+
let t = [...e], n = t.length;
|
|
102
|
+
return t.map((e, t) => {
|
|
103
|
+
if (e === " " || e === "\n") return e;
|
|
104
|
+
let r = t / Math.max(n - 1, 1);
|
|
105
|
+
return ae[Math.min(Math.floor(r * ae.length), ae.length - 1)](e);
|
|
106
|
+
}).join("");
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region ../../node_modules/.pnpm/@hyper-fetch+core@8.1.1/node_modules/@hyper-fetch/core/dist/index.mjs
|
|
110
|
+
var se = Object.create, ce = Object.defineProperty, le = Object.getOwnPropertyDescriptor, ue = Object.getOwnPropertyNames, de = Object.getPrototypeOf, fe = Object.prototype.hasOwnProperty, pe = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), me = (e, t, n, r) => {
|
|
111
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = ue(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !fe.call(e, s) && s !== n && ce(e, s, {
|
|
112
|
+
get: ((e) => t[e]).bind(null, s),
|
|
113
|
+
enumerable: !(r = le(t, s)) || r.enumerable
|
|
114
|
+
});
|
|
115
|
+
return e;
|
|
116
|
+
}, he = (e, t, n) => (n = e == null ? {} : se(de(e)), me(t || !e || !e.__esModule ? ce(n, "default", {
|
|
117
|
+
value: e,
|
|
118
|
+
enumerable: !0
|
|
119
|
+
}) : n, e)), ge = (e) => `${e.queryKey}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`, _e = /* @__PURE__ */ he((/* @__PURE__ */ pe(((e, t) => {
|
|
120
|
+
var n = typeof Reflect == "object" ? Reflect : null, r = n && typeof n.apply == "function" ? n.apply : function(e, t, n) {
|
|
121
|
+
return Function.prototype.apply.call(e, t, n);
|
|
122
|
+
}, i = n && typeof n.ownKeys == "function" ? n.ownKeys : Object.getOwnPropertySymbols ? function(e) {
|
|
123
|
+
return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
|
|
124
|
+
} : function(e) {
|
|
125
|
+
return Object.getOwnPropertyNames(e);
|
|
126
|
+
};
|
|
127
|
+
function a(e) {
|
|
128
|
+
console && console.warn && console.warn(e);
|
|
129
|
+
}
|
|
130
|
+
var o = Number.isNaN || function(e) {
|
|
131
|
+
return e !== e;
|
|
132
|
+
};
|
|
133
|
+
function s() {
|
|
134
|
+
s.init.call(this);
|
|
135
|
+
}
|
|
136
|
+
t.exports = s, t.exports.once = y, s.EventEmitter = s, s.prototype._events = void 0, s.prototype._eventsCount = 0, s.prototype._maxListeners = void 0;
|
|
137
|
+
var c = 10;
|
|
138
|
+
function l(e) {
|
|
139
|
+
if (typeof e != "function") throw TypeError("The \"listener\" argument must be of type Function. Received type " + typeof e);
|
|
140
|
+
}
|
|
141
|
+
Object.defineProperty(s, "defaultMaxListeners", {
|
|
142
|
+
enumerable: !0,
|
|
143
|
+
get: function() {
|
|
144
|
+
return c;
|
|
145
|
+
},
|
|
146
|
+
set: function(e) {
|
|
147
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
148
|
+
c = e;
|
|
149
|
+
}
|
|
150
|
+
}), s.init = function() {
|
|
151
|
+
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
|
|
152
|
+
}, s.prototype.setMaxListeners = function(e) {
|
|
153
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"n\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
154
|
+
return this._maxListeners = e, this;
|
|
155
|
+
};
|
|
156
|
+
function u(e) {
|
|
157
|
+
return e._maxListeners === void 0 ? s.defaultMaxListeners : e._maxListeners;
|
|
158
|
+
}
|
|
159
|
+
s.prototype.getMaxListeners = function() {
|
|
160
|
+
return u(this);
|
|
161
|
+
}, s.prototype.emit = function(e) {
|
|
162
|
+
for (var t = [], n = 1; n < arguments.length; n++) t.push(arguments[n]);
|
|
163
|
+
var i = e === "error", a = this._events;
|
|
164
|
+
if (a !== void 0) i &&= a.error === void 0;
|
|
165
|
+
else if (!i) return !1;
|
|
166
|
+
if (i) {
|
|
167
|
+
var o;
|
|
168
|
+
if (t.length > 0 && (o = t[0]), o instanceof Error) throw o;
|
|
169
|
+
var s = /* @__PURE__ */ Error("Unhandled error." + (o ? " (" + o.message + ")" : ""));
|
|
170
|
+
throw s.context = o, s;
|
|
171
|
+
}
|
|
172
|
+
var c = a[e];
|
|
173
|
+
if (c === void 0) return !1;
|
|
174
|
+
if (typeof c == "function") r(c, this, t);
|
|
175
|
+
else for (var l = c.length, u = g(c, l), n = 0; n < l; ++n) r(u[n], this, t);
|
|
176
|
+
return !0;
|
|
177
|
+
};
|
|
178
|
+
function d(e, t, n, r) {
|
|
179
|
+
var i, o, s;
|
|
180
|
+
if (l(n), o = e._events, o === void 0 ? (o = e._events = Object.create(null), e._eventsCount = 0) : (o.newListener !== void 0 && (e.emit("newListener", t, n.listener ? n.listener : n), o = e._events), s = o[t]), s === void 0) s = o[t] = n, ++e._eventsCount;
|
|
181
|
+
else if (typeof s == "function" ? s = o[t] = r ? [n, s] : [s, n] : r ? s.unshift(n) : s.push(n), i = u(e), i > 0 && s.length > i && !s.warned) {
|
|
182
|
+
s.warned = !0;
|
|
183
|
+
var c = /* @__PURE__ */ Error("Possible EventEmitter memory leak detected. " + s.length + " " + String(t) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
184
|
+
c.name = "MaxListenersExceededWarning", c.emitter = e, c.type = t, c.count = s.length, a(c);
|
|
185
|
+
}
|
|
186
|
+
return e;
|
|
187
|
+
}
|
|
188
|
+
s.prototype.addListener = function(e, t) {
|
|
189
|
+
return d(this, e, t, !1);
|
|
190
|
+
}, s.prototype.on = s.prototype.addListener, s.prototype.prependListener = function(e, t) {
|
|
191
|
+
return d(this, e, t, !0);
|
|
192
|
+
};
|
|
193
|
+
function f() {
|
|
194
|
+
if (!this.fired) return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
|
|
195
|
+
}
|
|
196
|
+
function p(e, t, n) {
|
|
197
|
+
var r = {
|
|
198
|
+
fired: !1,
|
|
199
|
+
wrapFn: void 0,
|
|
200
|
+
target: e,
|
|
201
|
+
type: t,
|
|
202
|
+
listener: n
|
|
203
|
+
}, i = f.bind(r);
|
|
204
|
+
return i.listener = n, r.wrapFn = i, i;
|
|
205
|
+
}
|
|
206
|
+
s.prototype.once = function(e, t) {
|
|
207
|
+
return l(t), this.on(e, p(this, e, t)), this;
|
|
208
|
+
}, s.prototype.prependOnceListener = function(e, t) {
|
|
209
|
+
return l(t), this.prependListener(e, p(this, e, t)), this;
|
|
210
|
+
}, s.prototype.removeListener = function(e, t) {
|
|
211
|
+
var n, r, i, a, o;
|
|
212
|
+
if (l(t), r = this._events, r === void 0 || (n = r[e], n === void 0)) return this;
|
|
213
|
+
if (n === t || n.listener === t) --this._eventsCount === 0 ? this._events = Object.create(null) : (delete r[e], r.removeListener && this.emit("removeListener", e, n.listener || t));
|
|
214
|
+
else if (typeof n != "function") {
|
|
215
|
+
for (i = -1, a = n.length - 1; a >= 0; a--) if (n[a] === t || n[a].listener === t) {
|
|
216
|
+
o = n[a].listener, i = a;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
if (i < 0) return this;
|
|
220
|
+
i === 0 ? n.shift() : _(n, i), n.length === 1 && (r[e] = n[0]), r.removeListener !== void 0 && this.emit("removeListener", e, o || t);
|
|
221
|
+
}
|
|
222
|
+
return this;
|
|
223
|
+
}, s.prototype.off = s.prototype.removeListener, s.prototype.removeAllListeners = function(e) {
|
|
224
|
+
var t, n = this._events, r;
|
|
225
|
+
if (n === void 0) return this;
|
|
226
|
+
if (n.removeListener === void 0) return arguments.length === 0 ? (this._events = Object.create(null), this._eventsCount = 0) : n[e] !== void 0 && (--this._eventsCount === 0 ? this._events = Object.create(null) : delete n[e]), this;
|
|
227
|
+
if (arguments.length === 0) {
|
|
228
|
+
var i = Object.keys(n), a;
|
|
229
|
+
for (r = 0; r < i.length; ++r) a = i[r], a !== "removeListener" && this.removeAllListeners(a);
|
|
230
|
+
return this.removeAllListeners("removeListener"), this._events = Object.create(null), this._eventsCount = 0, this;
|
|
231
|
+
}
|
|
232
|
+
if (t = n[e], typeof t == "function") this.removeListener(e, t);
|
|
233
|
+
else if (t !== void 0) for (r = t.length - 1; r >= 0; r--) this.removeListener(e, t[r]);
|
|
234
|
+
return this;
|
|
235
|
+
};
|
|
236
|
+
function m(e, t, n) {
|
|
237
|
+
var r = e._events;
|
|
238
|
+
if (r === void 0) return [];
|
|
239
|
+
var i = r[t];
|
|
240
|
+
return i === void 0 ? [] : typeof i == "function" ? n ? [i.listener || i] : [i] : n ? v(i) : g(i, i.length);
|
|
241
|
+
}
|
|
242
|
+
s.prototype.listeners = function(e) {
|
|
243
|
+
return m(this, e, !0);
|
|
244
|
+
}, s.prototype.rawListeners = function(e) {
|
|
245
|
+
return m(this, e, !1);
|
|
246
|
+
}, s.listenerCount = function(e, t) {
|
|
247
|
+
return typeof e.listenerCount == "function" ? e.listenerCount(t) : h.call(e, t);
|
|
248
|
+
}, s.prototype.listenerCount = h;
|
|
249
|
+
function h(e) {
|
|
250
|
+
var t = this._events;
|
|
251
|
+
if (t !== void 0) {
|
|
252
|
+
var n = t[e];
|
|
253
|
+
if (typeof n == "function") return 1;
|
|
254
|
+
if (n !== void 0) return n.length;
|
|
255
|
+
}
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
s.prototype.eventNames = function() {
|
|
259
|
+
return this._eventsCount > 0 ? i(this._events) : [];
|
|
260
|
+
};
|
|
261
|
+
function g(e, t) {
|
|
262
|
+
for (var n = Array(t), r = 0; r < t; ++r) n[r] = e[r];
|
|
263
|
+
return n;
|
|
264
|
+
}
|
|
265
|
+
function _(e, t) {
|
|
266
|
+
for (; t + 1 < e.length; t++) e[t] = e[t + 1];
|
|
267
|
+
e.pop();
|
|
268
|
+
}
|
|
269
|
+
function v(e) {
|
|
270
|
+
for (var t = Array(e.length), n = 0; n < t.length; ++n) t[n] = e[n].listener || e[n];
|
|
271
|
+
return t;
|
|
272
|
+
}
|
|
273
|
+
function y(e, t) {
|
|
274
|
+
return new Promise(function(n, r) {
|
|
275
|
+
function i(n) {
|
|
276
|
+
e.removeListener(t, a), r(n);
|
|
277
|
+
}
|
|
278
|
+
function a() {
|
|
279
|
+
typeof e.removeListener == "function" && e.removeListener("error", i), n([].slice.call(arguments));
|
|
280
|
+
}
|
|
281
|
+
x(e, t, a, { once: !0 }), t !== "error" && b(e, i, { once: !0 });
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function b(e, t, n) {
|
|
285
|
+
typeof e.on == "function" && x(e, "error", t, n);
|
|
286
|
+
}
|
|
287
|
+
function x(e, t, n, r) {
|
|
288
|
+
if (typeof e.on == "function") r.once ? e.once(t, n) : e.on(t, n);
|
|
289
|
+
else if (typeof e.addEventListener == "function") e.addEventListener(t, function i(a) {
|
|
290
|
+
r.once && e.removeEventListener(t, i), n(a);
|
|
291
|
+
});
|
|
292
|
+
else throw TypeError("The \"emitter\" argument must be of type EventEmitter. Received type " + typeof e);
|
|
293
|
+
}
|
|
294
|
+
})))()), ve = (e) => `listen_${String(e)}`, ye = class extends _e.default {
|
|
295
|
+
emitCallbacks = [];
|
|
296
|
+
constructor(e) {
|
|
297
|
+
super(e);
|
|
298
|
+
}
|
|
299
|
+
emit(e, t, n) {
|
|
300
|
+
let r = [e, t];
|
|
301
|
+
return n && r.push(n), this.emitCallbacks?.forEach((e) => e(...r)), super.emit(...r);
|
|
302
|
+
}
|
|
303
|
+
onEmit = (e) => (this.emitCallbacks?.push(e), () => {
|
|
304
|
+
this.emitCallbacks = this.emitCallbacks?.filter((t) => t !== e);
|
|
305
|
+
});
|
|
306
|
+
onListener = (e, t) => (super.on(ve(e), t), () => {
|
|
307
|
+
super.off(ve(e), t);
|
|
308
|
+
});
|
|
309
|
+
on = (e, t) => (super.on(e, t), super.emit(ve(e), super.listeners(e).length), this);
|
|
310
|
+
off = (e, t) => (super.off(e, t), super.emit(ve(e), super.listeners(e).length), this);
|
|
311
|
+
addListener = this.on;
|
|
312
|
+
removeListener = this.off;
|
|
313
|
+
}, be = class {
|
|
314
|
+
emitter = new ye();
|
|
315
|
+
events = Te(this.emitter);
|
|
316
|
+
isBrowser;
|
|
317
|
+
isOnline;
|
|
318
|
+
isFocused;
|
|
319
|
+
constructor(e) {
|
|
320
|
+
this.options = e, this.emitter?.setMaxListeners(1e3);
|
|
321
|
+
let { initiallyFocused: t = z.initiallyFocused, initiallyOnline: n = z.initiallyOnline } = this.options || z;
|
|
322
|
+
this.setInitialFocus(t), this.setInitialOnline(n), this.isBrowser = Se();
|
|
323
|
+
}
|
|
324
|
+
initialize = () => {
|
|
325
|
+
let { focusEvent: e = z.focusEvent, onlineEvent: t = z.onlineEvent } = this.options || z;
|
|
326
|
+
e(this.setFocused), t(this.setOnline);
|
|
327
|
+
};
|
|
328
|
+
setInitialFocus = async (e) => {
|
|
329
|
+
typeof e == "function" ? (this.isFocused = !1, this.isFocused = await e()) : this.isFocused = e;
|
|
330
|
+
};
|
|
331
|
+
setInitialOnline = async (e) => {
|
|
332
|
+
typeof e == "function" ? (this.isOnline = !1, this.isOnline = await e()) : this.isOnline = e;
|
|
333
|
+
};
|
|
334
|
+
setFocused = (e) => {
|
|
335
|
+
this.isFocused = e, e ? this.events.emitFocus() : this.events.emitBlur();
|
|
336
|
+
};
|
|
337
|
+
setOnline = (e) => {
|
|
338
|
+
this.isOnline = e, e ? this.events.emitOnline() : this.events.emitOffline();
|
|
339
|
+
};
|
|
340
|
+
}, xe = () => {
|
|
341
|
+
try {
|
|
342
|
+
return !!(window && window.addEventListener);
|
|
343
|
+
} catch {
|
|
344
|
+
/* istanbul ignore next */
|
|
345
|
+
return !1;
|
|
346
|
+
}
|
|
347
|
+
}, Se = () => {
|
|
348
|
+
try {
|
|
349
|
+
return !!(xe() && window.document && window.document.addEventListener);
|
|
350
|
+
} catch {
|
|
351
|
+
/* istanbul ignore next */
|
|
352
|
+
return !1;
|
|
353
|
+
}
|
|
354
|
+
}, Ce = (e, t, n) => xe() ? (window.addEventListener(e, t, n), () => window.removeEventListener(e, t, n)) : () => null, we = (e, t, n) => Se() ? (window.document.addEventListener(e, t, n), () => window.document.removeEventListener(e, t, n)) : () => null, Te = (e) => ({
|
|
355
|
+
emitFocus: () => {
|
|
356
|
+
e.emit(R.FOCUS);
|
|
357
|
+
},
|
|
358
|
+
emitBlur: () => {
|
|
359
|
+
e.emit(R.BLUR);
|
|
360
|
+
},
|
|
361
|
+
emitOnline: () => {
|
|
362
|
+
e.emit(R.ONLINE);
|
|
363
|
+
},
|
|
364
|
+
emitOffline: () => {
|
|
365
|
+
e.emit(R.OFFLINE);
|
|
366
|
+
},
|
|
367
|
+
onFocus: (t) => (e.on(R.FOCUS, t), () => e.removeListener(R.FOCUS, t)),
|
|
368
|
+
onBlur: (t) => (e.on(R.BLUR, t), () => e.removeListener(R.BLUR, t)),
|
|
369
|
+
onOnline: (t) => (e.on(R.ONLINE, t), () => e.removeListener(R.ONLINE, t)),
|
|
370
|
+
onOffline: (t) => (e.on(R.OFFLINE, t), () => e.removeListener(R.OFFLINE, t))
|
|
371
|
+
}), R = /* @__PURE__ */ function(e) {
|
|
372
|
+
return e.FOCUS = "focus", e.BLUR = "blur", e.ONLINE = "online", e.OFFLINE = "offline", e;
|
|
373
|
+
}({}), z = {
|
|
374
|
+
initiallyFocused: !0,
|
|
375
|
+
initiallyOnline: !0,
|
|
376
|
+
focusEvent: (e) => {
|
|
377
|
+
we("visibilitychange", () => e(!0)), Ce("focus", () => e(!0)), Ce("blur", () => e(!1));
|
|
378
|
+
},
|
|
379
|
+
onlineEvent: (e) => {
|
|
380
|
+
Ce("online", () => e(!0)), Ce("offline", () => e(!1));
|
|
381
|
+
}
|
|
382
|
+
}, Ee = class {
|
|
383
|
+
emitter = new ye();
|
|
384
|
+
events = nt(this.emitter);
|
|
385
|
+
constructor() {
|
|
386
|
+
this.emitter?.setMaxListeners(1e3);
|
|
387
|
+
}
|
|
388
|
+
abortControllers = /* @__PURE__ */ new Map();
|
|
389
|
+
addAbortController = (e, t) => {
|
|
390
|
+
let n = this.abortControllers.get(e);
|
|
391
|
+
if (!n) {
|
|
392
|
+
let t = /* @__PURE__ */ new Map();
|
|
393
|
+
n = t, this.abortControllers.set(e, t);
|
|
394
|
+
}
|
|
395
|
+
let r = n.get(t);
|
|
396
|
+
(!r || r.signal.aborted) && n.set(t, new AbortController());
|
|
397
|
+
};
|
|
398
|
+
getAbortController = (e, t) => this.abortControllers.get(e)?.get(t);
|
|
399
|
+
removeAbortController = (e, t) => {
|
|
400
|
+
this.abortControllers.get(e)?.delete(t);
|
|
401
|
+
};
|
|
402
|
+
useAbortController = (e, t) => {
|
|
403
|
+
(this.abortControllers.get(e)?.get(t))?.abort();
|
|
404
|
+
};
|
|
405
|
+
abortByKey = (e) => {
|
|
406
|
+
let t = this.abortControllers.get(e);
|
|
407
|
+
t && Array.from(t.entries()).forEach(([t]) => {
|
|
408
|
+
this.useAbortController(e, t);
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
abortByRequestId = (e, t) => {
|
|
412
|
+
this.useAbortController(e, t);
|
|
413
|
+
};
|
|
414
|
+
abortAll = () => {
|
|
415
|
+
Array.from(this.abortControllers.entries()).forEach(([e, t]) => {
|
|
416
|
+
Array.from(t.entries()).forEach(([t]) => {
|
|
417
|
+
this.useAbortController(e, t);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
}, De = () => "loading-event-any", Oe = (e) => `${e}-loading-event`, ke = (e) => `${e}-loading-cache-event`, Ae = (e) => `${e}-loading-event-by-id`, je = () => "remove-event-any", Me = (e) => `${e}-remove-event`, Ne = (e) => `${e}-remove-event-by-id`, Pe = () => "request-abort-any", Fe = (e) => `${e}-request-abort`, Ie = (e) => `${e}-request-abort-by-id`, Le = () => "response-any", Re = (e) => `${e}-response`, ze = (e) => `${e}-response-by-id`, Be = () => "request-start-any", Ve = (e) => `${e}-request-start`, He = (e) => `${e}-request-start-by-id`, Ue = () => "response-start-any", We = (e) => `${e}-response-start`, Ge = (e) => `${e}-response-start-by-id`, Ke = () => "request-progress-any", qe = (e) => `${e}-request-progress`, Je = (e) => `${e}-request-progress-by-id`, Ye = () => "response-progress-any", Xe = (e) => `${e}-response-progress`, Ze = (e) => `${e}-response-progress-by-id`, Qe = () => "request-deduplicated-any", $e = (e) => `${e}-query-request-deduplicated`, et = (e) => `${e}-cache-request-deduplicated`, tt = (e) => `${e}-request-deduplicated-by-id`, nt = (e) => ({
|
|
422
|
+
emitDeduplicated: (t, n = !1) => {
|
|
423
|
+
e.emit(Qe(), t, n), e.emit(tt(t.requestId), t, n), e.emit(et(t.request.cacheKey), t, n), e.emit($e(t.request.queryKey), t, n);
|
|
424
|
+
},
|
|
425
|
+
emitLoading: (t, n = !1) => {
|
|
426
|
+
e.emit(De(), t, n), e.emit(Ae(t.requestId), t, n), e.emit(ke(t.request.cacheKey), t, n), e.emit(Oe(t.request.queryKey), t, n);
|
|
427
|
+
},
|
|
428
|
+
emitRequestStart: (t, n = !1) => {
|
|
429
|
+
e.emit(Be(), t, n), e.emit(He(t.requestId), t, n), e.emit(Ve(t.request.queryKey), t, n);
|
|
430
|
+
},
|
|
431
|
+
emitResponseStart: (t, n = !1) => {
|
|
432
|
+
e.emit(Ue(), t, n), e.emit(Ge(t.requestId), t, n), e.emit(We(t.request.queryKey), t, n);
|
|
433
|
+
},
|
|
434
|
+
emitUploadProgress: (t, n = !1) => {
|
|
435
|
+
e.emit(Ke(), t, n), e.emit(Je(t.requestId), t, n), e.emit(qe(t.request.queryKey), t, n);
|
|
436
|
+
},
|
|
437
|
+
emitDownloadProgress: (t, n = !1) => {
|
|
438
|
+
e.emit(Ye(), t, n), e.emit(Ze(t.requestId), t, n), e.emit(Xe(t.request.queryKey), t, n);
|
|
439
|
+
},
|
|
440
|
+
emitResponse: (t, n = !1) => {
|
|
441
|
+
e.emit(Le(), t, n), e.emit(ze(t.requestId), t, n), e.emit(Re(t.request.cacheKey), t, n);
|
|
442
|
+
},
|
|
443
|
+
emitAbort: (t, n = !1) => {
|
|
444
|
+
e.emit(Pe(), t, n), e.emit(Ie(t.requestId), t, n), e.emit(Fe(t.request.abortKey), t, n);
|
|
445
|
+
},
|
|
446
|
+
emitRemove: (t, n = !1) => {
|
|
447
|
+
e.emit(je(), t, n), e.emit(Ne(t.requestId), t, n), e.emit(Me(t.request.queryKey), t, n);
|
|
448
|
+
},
|
|
449
|
+
onDeduplicated: (t) => (e.on(Qe(), t), () => e.removeListener(Qe(), t)),
|
|
450
|
+
onDeduplicatedByQueue: (t, n) => (e.on($e(t), n), () => e.removeListener($e(t), n)),
|
|
451
|
+
onDeduplicatedByCache: (t, n) => (e.on(et(t), n), () => e.removeListener(et(t), n)),
|
|
452
|
+
onDeduplicatedById: (t, n) => (e.on(tt(t), n), () => e.removeListener(tt(t), n)),
|
|
453
|
+
onLoading: (t) => (e.on(De(), t), () => e.removeListener(De(), t)),
|
|
454
|
+
onLoadingByQueue: (t, n) => (e.on(Oe(t), n), () => e.removeListener(Oe(t), n)),
|
|
455
|
+
onLoadingByCache: (t, n) => (e.on(ke(t), n), () => e.removeListener(ke(t), n)),
|
|
456
|
+
onLoadingById: (t, n) => (e.on(Ae(t), n), () => e.removeListener(Ae(t), n)),
|
|
457
|
+
onRequestStart: (t) => (e.on(Be(), t), () => e.removeListener(Be(), t)),
|
|
458
|
+
onRequestStartByQueue: (t, n) => (e.on(Ve(t), n), () => e.removeListener(Ve(t), n)),
|
|
459
|
+
onRequestStartById: (t, n) => (e.on(He(t), n), () => e.removeListener(He(t), n)),
|
|
460
|
+
onResponseStart: (t) => (e.on(Ue(), t), () => e.removeListener(Ue(), t)),
|
|
461
|
+
onResponseStartByQueue: (t, n) => (e.on(We(t), n), () => e.removeListener(We(t), n)),
|
|
462
|
+
onResponseStartById: (t, n) => (e.on(Ge(t), n), () => e.removeListener(Ge(t), n)),
|
|
463
|
+
onUploadProgress: (t) => (e.on(Ke(), t), () => e.removeListener(Ke(), t)),
|
|
464
|
+
onUploadProgressByQueue: (t, n) => (e.on(qe(t), n), () => e.removeListener(qe(t), n)),
|
|
465
|
+
onUploadProgressById: (t, n) => (e.on(Je(t), n), () => e.removeListener(Je(t), n)),
|
|
466
|
+
onDownloadProgress: (t) => (e.on(Ye(), t), () => e.removeListener(Ye(), t)),
|
|
467
|
+
onDownloadProgressByQueue: (t, n) => (e.on(Xe(t), n), () => e.removeListener(Xe(t), n)),
|
|
468
|
+
onDownloadProgressById: (t, n) => (e.on(Ze(t), n), () => e.removeListener(Ze(t), n)),
|
|
469
|
+
onResponse: (t) => (e.on(Le(), t), () => e.removeListener(Le(), t)),
|
|
470
|
+
onResponseByCache: (t, n) => (e.on(Re(t), n), () => e.removeListener(Re(t), n)),
|
|
471
|
+
onResponseById: (t, n) => (e.on(ze(t), n), () => e.removeListener(ze(t), n)),
|
|
472
|
+
onAbort: (t) => (e.on(Pe(), t), () => e.removeListener(Pe(), t)),
|
|
473
|
+
onAbortByKey: (t, n) => (e.on(Fe(t), n), () => e.removeListener(Fe(t), n)),
|
|
474
|
+
onAbortById: (t, n) => (e.on(Ie(t), n), () => e.removeListener(Ie(t), n)),
|
|
475
|
+
onRemove: (t) => (e.on(je(), t), () => e.removeListener(je(), t)),
|
|
476
|
+
onRemoveByQueue: (t, n) => (e.on(Me(t), n), () => e.removeListener(Me(t), n)),
|
|
477
|
+
onRemoveById: (t, n) => (e.on(Ne(t), n), () => e.removeListener(Ne(t), n))
|
|
478
|
+
}), rt = class {
|
|
479
|
+
logger;
|
|
480
|
+
level;
|
|
481
|
+
modules;
|
|
482
|
+
emitter = new _e.default();
|
|
483
|
+
client;
|
|
484
|
+
constructor(e) {
|
|
485
|
+
this.options = e, this.emitter?.setMaxListeners(1e3), this.logger = this.options?.logger || ot, this.level = this.options?.level || "warning", this.modules = this.options?.modules;
|
|
486
|
+
}
|
|
487
|
+
setSeverity = (e) => {
|
|
488
|
+
this.level = e;
|
|
489
|
+
};
|
|
490
|
+
setModules = (e) => {
|
|
491
|
+
this.modules = e;
|
|
492
|
+
};
|
|
493
|
+
initialize = (e, t) => (this.client = e, {
|
|
494
|
+
error: (e) => this.log({
|
|
495
|
+
...e,
|
|
496
|
+
level: "error",
|
|
497
|
+
module: t
|
|
498
|
+
}),
|
|
499
|
+
warning: (e) => this.log({
|
|
500
|
+
...e,
|
|
501
|
+
level: "warning",
|
|
502
|
+
module: t
|
|
503
|
+
}),
|
|
504
|
+
info: (e) => this.log({
|
|
505
|
+
...e,
|
|
506
|
+
level: "info",
|
|
507
|
+
module: t
|
|
508
|
+
}),
|
|
509
|
+
debug: (e) => this.log({
|
|
510
|
+
...e,
|
|
511
|
+
level: "debug",
|
|
512
|
+
module: t
|
|
513
|
+
})
|
|
514
|
+
});
|
|
515
|
+
log = (e) => {
|
|
516
|
+
this.client.debug && (st.indexOf(this.level) <= st.indexOf(e.level) || this.modules && !this.modules.includes(e.module) || this.logger(e));
|
|
517
|
+
};
|
|
518
|
+
}, it = () => `${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`, at = (e) => e.type === "request" || e.type === "response" ? `${e.extra.request.endpoint}` : `[${e.module}]`, ot = (e) => {
|
|
519
|
+
let t = ct[e.level], n = lt[e.level], r = `%c[${it()}]%c${e.title}%c${at(e)}`, i = `${t}${n}font-weight:600;border-radius: 4px 0 0 4px;`, a = `${t}${n}font-weight:600;`, o = `${t}font-weight:normal;border-radius: 0 4px 4px 0;`;
|
|
520
|
+
e.extra && Object.keys(e.extra)?.length ? (console.groupCollapsed(r, i, a, o), console.log(e.extra), console.groupEnd()) : console.log(r, t);
|
|
521
|
+
}, st = [
|
|
522
|
+
"error",
|
|
523
|
+
"warning",
|
|
524
|
+
"info",
|
|
525
|
+
"debug"
|
|
526
|
+
], B = "padding:2px 5px;", ct = {
|
|
527
|
+
error: `${B};background:#db252520;`,
|
|
528
|
+
warning: `${B};background:#e1941e20;`,
|
|
529
|
+
info: `${B};background:#1e74e120;`,
|
|
530
|
+
debug: `${B};background:#00000020;`
|
|
531
|
+
}, lt = {
|
|
532
|
+
error: "color:#ff3737;",
|
|
533
|
+
warning: "color:#ffc107;",
|
|
534
|
+
info: "color:#34a8ff;",
|
|
535
|
+
debug: "color:#cccccc;"
|
|
536
|
+
}, ut = class extends Error {
|
|
537
|
+
constructor() {
|
|
538
|
+
super("Request timeout"), this.name = "TimeoutError";
|
|
539
|
+
}
|
|
540
|
+
}, dt = class extends Error {
|
|
541
|
+
constructor() {
|
|
542
|
+
super("Request aborted"), this.name = "AbortError";
|
|
543
|
+
}
|
|
544
|
+
}, ft = class extends Error {
|
|
545
|
+
constructor() {
|
|
546
|
+
super("Request deleted"), this.name = "DeletedError";
|
|
547
|
+
}
|
|
548
|
+
}, V = class extends Error {
|
|
549
|
+
description;
|
|
550
|
+
constructor(e) {
|
|
551
|
+
super("Request processing error"), this.description = e, this.name = "RequestProcessingError";
|
|
552
|
+
}
|
|
553
|
+
}, pt = class extends Error {
|
|
554
|
+
description;
|
|
555
|
+
constructor(e) {
|
|
556
|
+
super("Unexpected error"), this.description = e, this.name = "UnexpectedError";
|
|
557
|
+
}
|
|
558
|
+
}, H = (e) => e === "timeout" ? new ut() : e === "abort" ? new dt() : e === "deleted" ? new ft() : e === "processing" ? new V() : new pt(), mt = (e) => {
|
|
559
|
+
try {
|
|
560
|
+
return JSON.stringify(e);
|
|
561
|
+
} catch {
|
|
562
|
+
return "";
|
|
563
|
+
}
|
|
564
|
+
}, ht = (e) => {
|
|
565
|
+
let t = xe() && e.payload instanceof FormData, n = typeof e.payload == "object" && e.payload !== null, r = {};
|
|
566
|
+
return !t && n && (r["Content-Type"] = "application/json"), Object.assign(r, e.headers), r;
|
|
567
|
+
}, gt = (e) => xe() && e instanceof FormData ? e : mt(e), _t = [
|
|
568
|
+
"onBeforeSent",
|
|
569
|
+
"onRequestStart",
|
|
570
|
+
"onResponseStart",
|
|
571
|
+
"onUploadProgress",
|
|
572
|
+
"onDownloadProgress",
|
|
573
|
+
"onResponse",
|
|
574
|
+
"onRemove"
|
|
575
|
+
];
|
|
576
|
+
function vt(e) {
|
|
577
|
+
let t = {
|
|
578
|
+
onBeforeSent: [],
|
|
579
|
+
onRequestStart: [],
|
|
580
|
+
onResponseStart: [],
|
|
581
|
+
onUploadProgress: [],
|
|
582
|
+
onDownloadProgress: [],
|
|
583
|
+
onResponse: [],
|
|
584
|
+
onRemove: []
|
|
585
|
+
};
|
|
586
|
+
e && _t.forEach((n) => {
|
|
587
|
+
t[n] = [...e[n]];
|
|
588
|
+
});
|
|
589
|
+
let n = (e) => (n) => (t[e].push(n), () => {
|
|
590
|
+
let r = t[e].indexOf(n);
|
|
591
|
+
r !== -1 && t[e].splice(r, 1);
|
|
592
|
+
});
|
|
593
|
+
return {
|
|
594
|
+
onBeforeSent: n("onBeforeSent"),
|
|
595
|
+
onRequestStart: n("onRequestStart"),
|
|
596
|
+
onResponseStart: n("onResponseStart"),
|
|
597
|
+
onUploadProgress: n("onUploadProgress"),
|
|
598
|
+
onDownloadProgress: n("onDownloadProgress"),
|
|
599
|
+
onResponse: n("onResponse"),
|
|
600
|
+
onRemove: n("onRemove"),
|
|
601
|
+
__emit(e, n) {
|
|
602
|
+
t[e].forEach((e) => {
|
|
603
|
+
e(n);
|
|
604
|
+
});
|
|
605
|
+
},
|
|
606
|
+
__snapshot() {
|
|
607
|
+
let e = {};
|
|
608
|
+
return _t.forEach((n) => {
|
|
609
|
+
e[n] = [...t[n]];
|
|
610
|
+
}), e;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
var yt = /* @__PURE__ */ function(e) {
|
|
615
|
+
return e.GET = "GET", e.POST = "POST", e.PUT = "PUT", e.PATCH = "PATCH", e.DELETE = "DELETE", e;
|
|
616
|
+
}({}), U = (e, t) => t ? `${t}__${e}` : e, bt = (e) => {
|
|
617
|
+
try {
|
|
618
|
+
if (typeof e == "string") return e;
|
|
619
|
+
if (e == null) return "";
|
|
620
|
+
let t = JSON.stringify(e);
|
|
621
|
+
if (typeof t != "string") throw Error();
|
|
622
|
+
return t;
|
|
623
|
+
} catch {
|
|
624
|
+
return "";
|
|
625
|
+
}
|
|
626
|
+
}, xt = ({ loaded: e, total: t }) => !e || !t ? 0 : Number((e * 100 / t).toFixed(0)), St = (e, t, { total: n, loaded: r }) => {
|
|
627
|
+
let i = r / (t - +e || 1), a = Math.max(n, r), o = a - r, s = i ? o / i : null;
|
|
628
|
+
return {
|
|
629
|
+
timeLeft: a === r ? 0 : s,
|
|
630
|
+
sizeLeft: o
|
|
631
|
+
};
|
|
632
|
+
}, Ct = (e, t, n) => {
|
|
633
|
+
let { total: r, loaded: i } = n;
|
|
634
|
+
if (Number.isNaN(r) || Number.isNaN(i)) return {
|
|
635
|
+
progress: 0,
|
|
636
|
+
timeLeft: 0,
|
|
637
|
+
sizeLeft: 0,
|
|
638
|
+
total: 0,
|
|
639
|
+
loaded: 0,
|
|
640
|
+
startTimestamp: +e
|
|
641
|
+
};
|
|
642
|
+
let { timeLeft: a, sizeLeft: o } = St(e, t, n);
|
|
643
|
+
return {
|
|
644
|
+
progress: xt(n),
|
|
645
|
+
timeLeft: a,
|
|
646
|
+
sizeLeft: o,
|
|
647
|
+
total: r,
|
|
648
|
+
loaded: i,
|
|
649
|
+
startTimestamp: +e
|
|
650
|
+
};
|
|
651
|
+
}, wt = (e) => `${e.method}_${e.requestOptions.endpoint}_${e.cancelable}`, Tt = (e, t) => `${bt(e.method)}_${t ? e.requestOptions.endpoint : bt(e.endpoint)}_${t ? "" : bt(e.queryParams)}`, Et = (e, t = "auto") => {
|
|
652
|
+
let { fetchDispatcher: n, submitDispatcher: r } = e.client, i = e.method === yt.GET, a = t === "auto" && i || t === "fetch";
|
|
653
|
+
return [a ? n : r, a];
|
|
654
|
+
}, Dt = async (e, t) => {
|
|
655
|
+
let n = e.unstable_responseMapper?.(t);
|
|
656
|
+
return n instanceof Promise ? await n : n || t;
|
|
657
|
+
}, Ot = async (e, t) => {
|
|
658
|
+
let { client: n } = e, { requestManager: r } = n, [i] = Et(e, t?.dispatcherType), a;
|
|
659
|
+
if (e.optimistic) try {
|
|
660
|
+
a = await e.optimistic({
|
|
661
|
+
request: e,
|
|
662
|
+
client: e.client,
|
|
663
|
+
payload: e.payload
|
|
664
|
+
});
|
|
665
|
+
} catch (e) {
|
|
666
|
+
return {
|
|
667
|
+
data: null,
|
|
668
|
+
error: /* @__PURE__ */ Error(`Optimistic callback failed: ${e instanceof Error ? e.message : e}`),
|
|
669
|
+
status: null,
|
|
670
|
+
success: !1,
|
|
671
|
+
extra: n.adapter.defaultExtra,
|
|
672
|
+
requestTimestamp: +/* @__PURE__ */ new Date(),
|
|
673
|
+
responseTimestamp: +/* @__PURE__ */ new Date()
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
return new Promise((n) => {
|
|
677
|
+
let o = !1, s = i.add(e), { $hooks: c } = e, l = {
|
|
678
|
+
requestId: s,
|
|
679
|
+
request: e,
|
|
680
|
+
mutationContext: a
|
|
681
|
+
};
|
|
682
|
+
t?.onBeforeSent?.(l), c.__emit("onBeforeSent", l);
|
|
683
|
+
let u = r.events.onRequestStartById(s, (e) => {
|
|
684
|
+
let n = {
|
|
685
|
+
...e,
|
|
686
|
+
mutationContext: a
|
|
687
|
+
};
|
|
688
|
+
t?.onRequestStart?.(n), c.__emit("onRequestStart", n);
|
|
689
|
+
}), d = r.events.onResponseStartById(s, (e) => {
|
|
690
|
+
let n = {
|
|
691
|
+
...e,
|
|
692
|
+
mutationContext: a
|
|
693
|
+
};
|
|
694
|
+
t?.onResponseStart?.(n), c.__emit("onResponseStart", n);
|
|
695
|
+
}), f = r.events.onUploadProgressById(s, (e) => {
|
|
696
|
+
let n = {
|
|
697
|
+
...e,
|
|
698
|
+
mutationContext: a
|
|
699
|
+
};
|
|
700
|
+
t?.onUploadProgress?.(n), c.__emit("onUploadProgress", n);
|
|
701
|
+
}), p = r.events.onDownloadProgressById(s, (e) => {
|
|
702
|
+
let n = {
|
|
703
|
+
...e,
|
|
704
|
+
mutationContext: a
|
|
705
|
+
};
|
|
706
|
+
t?.onDownloadProgress?.(n), c.__emit("onDownloadProgress", n);
|
|
707
|
+
}), m = r.events.onResponseById(s, (r) => {
|
|
708
|
+
let { details: i, response: s } = r;
|
|
709
|
+
o = !0;
|
|
710
|
+
let l = {
|
|
711
|
+
...r,
|
|
712
|
+
mutationContext: a
|
|
713
|
+
}, u = e.unstable_responseMapper?.(s), d = e.offline && i.isOffline, { willRetry: f } = i, p = (e, r) => {
|
|
714
|
+
!e && d || !e && f || (t?.onResponse?.(l), c.__emit("onResponse", l), n(r), g());
|
|
715
|
+
};
|
|
716
|
+
if (u instanceof Promise) (async () => {
|
|
717
|
+
let e = await u, { success: t } = e;
|
|
718
|
+
p(t, e);
|
|
719
|
+
})();
|
|
720
|
+
else {
|
|
721
|
+
let e = u || s, { success: t } = e;
|
|
722
|
+
p(t, e);
|
|
723
|
+
}
|
|
724
|
+
}), h = r.events.onRemoveById(s, (r) => {
|
|
725
|
+
if (!o) {
|
|
726
|
+
let i = {
|
|
727
|
+
...r,
|
|
728
|
+
mutationContext: a
|
|
729
|
+
};
|
|
730
|
+
t?.onRemove?.(i), c.__emit("onRemove", i), n({
|
|
731
|
+
data: null,
|
|
732
|
+
status: null,
|
|
733
|
+
success: !1,
|
|
734
|
+
error: H("deleted"),
|
|
735
|
+
extra: e.client.adapter.defaultExtra,
|
|
736
|
+
requestTimestamp: +/* @__PURE__ */ new Date(),
|
|
737
|
+
responseTimestamp: +/* @__PURE__ */ new Date()
|
|
738
|
+
}), g();
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
function g() {
|
|
742
|
+
u(), d(), f(), p(), m(), h();
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}, kt = /* @__PURE__ */ function(e) {
|
|
746
|
+
return e[e.SEC = 1e3] = "SEC", e[e.MIN = 6e4] = "MIN", e[e.HOUR = 36e5] = "HOUR", e[e.DAY = 864e5] = "DAY", e[e.WEEK = 6048e5] = "WEEK", e[e.MONTH_30 = 2592e6] = "MONTH_30", e[e.MONTH_31 = 26784e5] = "MONTH_31", e[e.YEAR = 31536e6] = "YEAR", e[e.YEAR_LEAP = 316224e5] = "YEAR_LEAP", e;
|
|
747
|
+
}({}), At = class e {
|
|
748
|
+
endpoint;
|
|
749
|
+
headers;
|
|
750
|
+
auth;
|
|
751
|
+
method;
|
|
752
|
+
params;
|
|
753
|
+
payload;
|
|
754
|
+
queryParams;
|
|
755
|
+
options;
|
|
756
|
+
cancelable;
|
|
757
|
+
retry;
|
|
758
|
+
retryTime;
|
|
759
|
+
cacheTime;
|
|
760
|
+
cache;
|
|
761
|
+
staleTime;
|
|
762
|
+
queued;
|
|
763
|
+
offline;
|
|
764
|
+
abortKey;
|
|
765
|
+
cacheKey;
|
|
766
|
+
queryKey;
|
|
767
|
+
used;
|
|
768
|
+
deduplicate;
|
|
769
|
+
deduplicateTime;
|
|
770
|
+
scope;
|
|
771
|
+
$hooks = vt();
|
|
772
|
+
isMockerEnabled = !1;
|
|
773
|
+
unstable_mock;
|
|
774
|
+
unstable_payloadMapper;
|
|
775
|
+
unstable_requestMapper;
|
|
776
|
+
unstable_responseMapper;
|
|
777
|
+
retryOnError;
|
|
778
|
+
optimistic;
|
|
779
|
+
unstable_hasParams = !1;
|
|
780
|
+
unstable_hasPayload = !1;
|
|
781
|
+
unstable_hasQuery = !1;
|
|
782
|
+
unstable_hasMutationContext = void 0;
|
|
783
|
+
updatedAbortKey;
|
|
784
|
+
updatedCacheKey;
|
|
785
|
+
updatedQueryKey;
|
|
786
|
+
constructor(e, t, n) {
|
|
787
|
+
this.client = e, this.requestOptions = t, this.initialRequestConfiguration = n;
|
|
788
|
+
let { endpoint: r, headers: i, auth: a = !0, method: o = e.adapter.defaultMethod, options: s, cancelable: c = !1, retry: l = 0, retryTime: u = 500, cacheTime: d = kt.MIN * 5, cache: f = !0, staleTime: p = kt.MIN * 5, queued: m = !1, offline: h = !0, abortKey: g, cacheKey: _, queryKey: v, deduplicate: y = !1, deduplicateTime: b = null } = {
|
|
789
|
+
...this.client.adapter.unstable_getRequestDefaults?.(t),
|
|
790
|
+
...t
|
|
791
|
+
};
|
|
792
|
+
this.endpoint = n?.endpoint ?? r, this.headers = n?.headers ?? i, this.auth = n?.auth ?? a, this.method = o, this.params = n?.params, this.payload = n?.payload, this.queryParams = n?.queryParams, this.options = n?.options ?? s, this.cancelable = n?.cancelable ?? c, this.retry = n?.retry ?? l, this.retryTime = n?.retryTime ?? u, this.cacheTime = n?.cacheTime ?? d, this.cache = n?.cache ?? f, this.staleTime = n?.staleTime ?? p, this.queued = n?.queued ?? m, this.offline = n?.offline ?? h, this.abortKey = n?.abortKey ?? g ?? this.client.unstable_abortKeyMapper(this), this.cacheKey = n?.cacheKey ?? _ ?? this.client.unstable_cacheKeyMapper(this), this.queryKey = n?.queryKey ?? v ?? this.client.unstable_queryKeyMapper(this), this.used = n?.used ?? !1, this.deduplicate = n?.deduplicate ?? y, this.deduplicateTime = n?.deduplicateTime ?? b, this.scope = n?.scope ?? null, this.updatedAbortKey = n?.updatedAbortKey ?? !1, this.updatedCacheKey = n?.updatedCacheKey ?? !1, this.updatedQueryKey = n?.updatedQueryKey ?? !1;
|
|
793
|
+
}
|
|
794
|
+
setHeaders = (e) => this.clone({ headers: e });
|
|
795
|
+
setAuth = (e) => this.clone({ auth: e });
|
|
796
|
+
setParams = (e) => this.clone({ params: e });
|
|
797
|
+
setPayload = (e) => this.clone({ payload: e });
|
|
798
|
+
setQueryParams = (e) => this.clone({ queryParams: e });
|
|
799
|
+
setOptions = (e) => this.clone({ options: e });
|
|
800
|
+
setScope = (e) => {
|
|
801
|
+
let t = this.clone();
|
|
802
|
+
return t.scope = e, t;
|
|
803
|
+
};
|
|
804
|
+
setCancelable = (e) => this.clone({ cancelable: e });
|
|
805
|
+
setRetry = (e) => this.clone({ retry: e });
|
|
806
|
+
setRetryTime = (e) => this.clone({ retryTime: e });
|
|
807
|
+
setRetryOnError = (e) => {
|
|
808
|
+
let t = this.clone();
|
|
809
|
+
return t.retryOnError = e, t;
|
|
810
|
+
};
|
|
811
|
+
setOptimistic = (e) => {
|
|
812
|
+
let t = this.clone();
|
|
813
|
+
return t.optimistic = e, t;
|
|
814
|
+
};
|
|
815
|
+
setCacheTime = (e) => this.clone({ cacheTime: e });
|
|
816
|
+
setCache = (e) => this.clone({ cache: e });
|
|
817
|
+
setStaleTime = (e) => this.clone({ staleTime: e });
|
|
818
|
+
setQueued = (e) => this.clone({ queued: e });
|
|
819
|
+
setAbortKey = (e) => (this.updatedAbortKey = !0, this.clone({ abortKey: e }));
|
|
820
|
+
setCacheKey = (e) => (this.updatedCacheKey = !0, this.clone({ cacheKey: e }));
|
|
821
|
+
setQueryKey = (e) => (this.updatedQueryKey = !0, this.clone({ queryKey: e }));
|
|
822
|
+
setDeduplicate = (e) => this.clone({ deduplicate: e });
|
|
823
|
+
setDeduplicateTime = (e) => this.clone({ deduplicateTime: e });
|
|
824
|
+
setUsed = (e) => this.clone({ used: e });
|
|
825
|
+
setOffline = (e) => this.clone({ offline: e });
|
|
826
|
+
setMock = (e, t = {}) => (this.unstable_mock = {
|
|
827
|
+
fn: e,
|
|
828
|
+
config: t
|
|
829
|
+
}, this.isMockerEnabled = !0, this);
|
|
830
|
+
clearMock = () => (this.unstable_mock = void 0, this.isMockerEnabled = !1, this);
|
|
831
|
+
setMockingEnabled = (e) => (this.isMockerEnabled = e, this);
|
|
832
|
+
setPayloadMapper = (e) => {
|
|
833
|
+
let t = this.clone(void 0);
|
|
834
|
+
return t.unstable_payloadMapper = e, t;
|
|
835
|
+
};
|
|
836
|
+
setRequestMapper = (e) => {
|
|
837
|
+
let t = this.clone(void 0);
|
|
838
|
+
return t.unstable_requestMapper = e, t;
|
|
839
|
+
};
|
|
840
|
+
setResponseMapper = (e) => {
|
|
841
|
+
let t = this.clone();
|
|
842
|
+
return t.unstable_responseMapper = e, t;
|
|
843
|
+
};
|
|
844
|
+
paramsMapper = (e) => {
|
|
845
|
+
let { endpoint: t } = this.requestOptions, n = String(t);
|
|
846
|
+
return e && Object.entries(e).forEach(([e, t]) => {
|
|
847
|
+
n = n.replace(RegExp(`:${e}`, "g"), String(t));
|
|
848
|
+
}), n;
|
|
849
|
+
};
|
|
850
|
+
toJSON() {
|
|
851
|
+
return {
|
|
852
|
+
requestOptions: this.requestOptions,
|
|
853
|
+
endpoint: this.endpoint,
|
|
854
|
+
headers: this.headers,
|
|
855
|
+
auth: this.auth,
|
|
856
|
+
method: this.method,
|
|
857
|
+
params: this.params,
|
|
858
|
+
payload: this.payload,
|
|
859
|
+
queryParams: this.queryParams,
|
|
860
|
+
options: this.options,
|
|
861
|
+
cancelable: this.cancelable,
|
|
862
|
+
retry: this.retry,
|
|
863
|
+
retryTime: this.retryTime,
|
|
864
|
+
cacheTime: this.cacheTime,
|
|
865
|
+
cache: this.cache,
|
|
866
|
+
staleTime: this.staleTime,
|
|
867
|
+
queued: this.queued,
|
|
868
|
+
offline: this.offline,
|
|
869
|
+
abortKey: this.abortKey,
|
|
870
|
+
cacheKey: this.cacheKey,
|
|
871
|
+
queryKey: this.queryKey,
|
|
872
|
+
used: this.used,
|
|
873
|
+
disableResponseInterceptors: this.requestOptions.disableResponseInterceptors,
|
|
874
|
+
disableRequestInterceptors: this.requestOptions.disableRequestInterceptors,
|
|
875
|
+
updatedAbortKey: this.updatedAbortKey,
|
|
876
|
+
updatedCacheKey: this.updatedCacheKey,
|
|
877
|
+
updatedQueryKey: this.updatedQueryKey,
|
|
878
|
+
deduplicate: this.deduplicate,
|
|
879
|
+
deduplicateTime: this.deduplicateTime,
|
|
880
|
+
scope: this.scope,
|
|
881
|
+
isMockerEnabled: this.isMockerEnabled,
|
|
882
|
+
hasMock: !!this.unstable_mock
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
clone(t) {
|
|
886
|
+
let n = {
|
|
887
|
+
...this.toJSON(),
|
|
888
|
+
...t,
|
|
889
|
+
options: t?.options || this.options,
|
|
890
|
+
abortKey: this.updatedAbortKey ? t?.abortKey || this.abortKey : void 0,
|
|
891
|
+
cacheKey: this.updatedCacheKey ? t?.cacheKey || this.cacheKey : void 0,
|
|
892
|
+
queryKey: this.updatedQueryKey ? t?.queryKey || this.queryKey : void 0,
|
|
893
|
+
endpoint: this.paramsMapper(t?.params || this.params),
|
|
894
|
+
queryParams: t?.queryParams || this.queryParams,
|
|
895
|
+
payload: t?.payload || this.payload,
|
|
896
|
+
params: t?.params || this.params
|
|
897
|
+
}, r = new e(this.client, this.requestOptions, n);
|
|
898
|
+
return r.unstable_payloadMapper = this.unstable_payloadMapper, r.unstable_responseMapper = this.unstable_responseMapper, r.unstable_requestMapper = this.unstable_requestMapper, r.retryOnError = this.retryOnError, r.unstable_mock = this.unstable_mock, r.isMockerEnabled = this.isMockerEnabled, r.optimistic = this.optimistic, r.$hooks = vt(this.$hooks.__snapshot()), r;
|
|
899
|
+
}
|
|
900
|
+
abort = () => {
|
|
901
|
+
let { requestManager: e } = this.client;
|
|
902
|
+
return e.abortByKey(U(this.abortKey, this.scope)), this.clone();
|
|
903
|
+
};
|
|
904
|
+
dehydrate = (e) => {
|
|
905
|
+
let { response: t, override: n = !0 } = e || {};
|
|
906
|
+
if (t) return {
|
|
907
|
+
override: n,
|
|
908
|
+
cacheTime: this.cacheTime,
|
|
909
|
+
staleTime: this.staleTime,
|
|
910
|
+
cacheKey: this.cacheKey,
|
|
911
|
+
scope: this.scope,
|
|
912
|
+
timestamp: +/* @__PURE__ */ new Date(),
|
|
913
|
+
hydrated: !0,
|
|
914
|
+
cache: !0,
|
|
915
|
+
response: t
|
|
916
|
+
};
|
|
917
|
+
let r = this.client.cache.get(U(this.cacheKey, this.scope));
|
|
918
|
+
if (r) return {
|
|
919
|
+
override: n,
|
|
920
|
+
cacheTime: this.cacheTime,
|
|
921
|
+
staleTime: this.staleTime,
|
|
922
|
+
cacheKey: this.cacheKey,
|
|
923
|
+
scope: this.scope,
|
|
924
|
+
timestamp: +/* @__PURE__ */ new Date(),
|
|
925
|
+
hydrated: !0,
|
|
926
|
+
cache: !0,
|
|
927
|
+
response: {
|
|
928
|
+
data: r.data,
|
|
929
|
+
error: r.error,
|
|
930
|
+
status: r.status,
|
|
931
|
+
success: r.success,
|
|
932
|
+
extra: r.extra,
|
|
933
|
+
requestTimestamp: r.requestTimestamp,
|
|
934
|
+
responseTimestamp: r.responseTimestamp
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
};
|
|
938
|
+
read() {
|
|
939
|
+
let e = this.client.cache.get(U(this.cacheKey, this.scope));
|
|
940
|
+
if (e) return {
|
|
941
|
+
data: e.data,
|
|
942
|
+
error: e.error,
|
|
943
|
+
status: e.status,
|
|
944
|
+
success: e.success,
|
|
945
|
+
extra: e.extra,
|
|
946
|
+
requestTimestamp: e.requestTimestamp,
|
|
947
|
+
responseTimestamp: e.responseTimestamp
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
exec = async (e) => {
|
|
951
|
+
let { adapter: t, requestManager: n } = this.client, r = this.clone(e), i = this.client.unstable_requestIdMapper(this), a = U(this.abortKey, this.scope);
|
|
952
|
+
n.addAbortController(a, i);
|
|
953
|
+
let o = await t.fetch(r, i);
|
|
954
|
+
return n.removeAbortController(a, i), r.unstable_responseMapper ? r.unstable_responseMapper(o) : o;
|
|
955
|
+
};
|
|
956
|
+
send = async (e) => {
|
|
957
|
+
let { dispatcherType: t, cachePolicy: n = "network-only", ...r } = e || {}, i = this.clone(r), a = e === void 0 ? void 0 : {
|
|
958
|
+
...e,
|
|
959
|
+
cachePolicy: void 0
|
|
960
|
+
};
|
|
961
|
+
if (n === "network-only") return Ot(i, a);
|
|
962
|
+
let o = i.read();
|
|
963
|
+
if (n === "cache-first") return o ? Dt(i, o) : Ot(i, a);
|
|
964
|
+
if (o) {
|
|
965
|
+
let e = await Dt(i, o);
|
|
966
|
+
return Ot(i, a), e;
|
|
967
|
+
}
|
|
968
|
+
return Ot(i, a);
|
|
969
|
+
};
|
|
970
|
+
static fromJSON = (t, n) => new e(t, n.requestOptions, n);
|
|
971
|
+
}, jt = async ({ request: e, requestId: t, resolve: n, onStartTime: r, internalErrorMapping: i }) => {
|
|
972
|
+
let { requestManager: a, loggerManager: o } = e.client, { unstable_payloadMapper: s } = e.client.adapter, c = o.initialize(e.client, "Adapter"), l = null, u = null, d = e, f = 1, p = 1, m = 0, h = 0;
|
|
973
|
+
c.debug({
|
|
974
|
+
title: "Running middleware callbacks",
|
|
975
|
+
type: "request",
|
|
976
|
+
extra: {
|
|
977
|
+
request: d,
|
|
978
|
+
requestId: t
|
|
979
|
+
}
|
|
980
|
+
}), d = await d.client.unstable_modifyRequest(d), d.auth && (d = await d.client.unstable_modifyAuth(d)), d.unstable_requestMapper && (d = await d.unstable_requestMapper(d, t));
|
|
981
|
+
let { client: g, abortKey: _ } = d, v = U(_, d.scope), y = d.payload;
|
|
982
|
+
d.unstable_payloadMapper ? y = await d.unstable_payloadMapper(d.payload) : s && (y = await s(y));
|
|
983
|
+
let b = d.options, x = +/* @__PURE__ */ new Date();
|
|
984
|
+
r(x);
|
|
985
|
+
let S = () => l, C = () => u, w = (e, t) => {
|
|
986
|
+
if (!t) return e;
|
|
987
|
+
let n = Number(t.total || 0), r = Number(t.loaded || 0);
|
|
988
|
+
return Math.max(n, r, e);
|
|
989
|
+
}, T = (e, n, r) => {
|
|
990
|
+
let i = Ct(new Date(e), new Date(n), r);
|
|
991
|
+
m !== 100 && (m = i.total, a.events.emitUploadProgress({
|
|
992
|
+
...i,
|
|
993
|
+
requestId: t,
|
|
994
|
+
request: d
|
|
995
|
+
}));
|
|
996
|
+
}, E = (e, n, r) => {
|
|
997
|
+
let i = Ct(new Date(e), new Date(n), r);
|
|
998
|
+
h !== 100 && (h = i.total, a.events.emitDownloadProgress({
|
|
999
|
+
...i,
|
|
1000
|
+
requestId: t,
|
|
1001
|
+
request: d
|
|
1002
|
+
}));
|
|
1003
|
+
}, D = () => {
|
|
1004
|
+
c.debug({
|
|
1005
|
+
title: "Request about to be sent",
|
|
1006
|
+
type: "request",
|
|
1007
|
+
extra: {
|
|
1008
|
+
request: d,
|
|
1009
|
+
requestId: t
|
|
1010
|
+
}
|
|
1011
|
+
}), g.triggerPlugins("onRequestTrigger", { request: d });
|
|
1012
|
+
}, O = (e) => {
|
|
1013
|
+
c.info({
|
|
1014
|
+
title: "Request start",
|
|
1015
|
+
type: "request",
|
|
1016
|
+
extra: {
|
|
1017
|
+
request: d,
|
|
1018
|
+
requestId: t
|
|
1019
|
+
}
|
|
1020
|
+
}), g.triggerPlugins("onRequestStart", { request: d }), e?.total && (f = w(f, e));
|
|
1021
|
+
let n = {
|
|
1022
|
+
total: f,
|
|
1023
|
+
loaded: e?.loaded || 0
|
|
1024
|
+
};
|
|
1025
|
+
return l = +/* @__PURE__ */ new Date(), T(l, l, n), a.events.emitRequestStart({
|
|
1026
|
+
requestId: t,
|
|
1027
|
+
request: d
|
|
1028
|
+
}), l;
|
|
1029
|
+
}, ee = (e) => {
|
|
1030
|
+
l ||= +/* @__PURE__ */ new Date(), f = w(f, e);
|
|
1031
|
+
let t = +/* @__PURE__ */ new Date();
|
|
1032
|
+
return T(l, t, {
|
|
1033
|
+
total: f,
|
|
1034
|
+
loaded: e.loaded || 0
|
|
1035
|
+
}), t;
|
|
1036
|
+
}, k = () => {
|
|
1037
|
+
l ||= +/* @__PURE__ */ new Date();
|
|
1038
|
+
let e = +/* @__PURE__ */ new Date();
|
|
1039
|
+
return T(l, e, {
|
|
1040
|
+
total: f,
|
|
1041
|
+
loaded: f
|
|
1042
|
+
}), e;
|
|
1043
|
+
}, te = (e) => {
|
|
1044
|
+
u = +/* @__PURE__ */ new Date(), p = w(p, e);
|
|
1045
|
+
let n = {
|
|
1046
|
+
total: p,
|
|
1047
|
+
loaded: e?.loaded || 0
|
|
1048
|
+
};
|
|
1049
|
+
return E(u, u, n), a.events.emitResponseStart({
|
|
1050
|
+
requestId: t,
|
|
1051
|
+
request: d
|
|
1052
|
+
}), u;
|
|
1053
|
+
}, ne = (e) => {
|
|
1054
|
+
u ||= +/* @__PURE__ */ new Date();
|
|
1055
|
+
let t = +/* @__PURE__ */ new Date();
|
|
1056
|
+
return p = w(p, e), E(u, t, {
|
|
1057
|
+
total: e.total || p,
|
|
1058
|
+
loaded: e.loaded || 0
|
|
1059
|
+
}), t;
|
|
1060
|
+
}, re = () => {
|
|
1061
|
+
u ||= +/* @__PURE__ */ new Date();
|
|
1062
|
+
let e = +/* @__PURE__ */ new Date();
|
|
1063
|
+
return E(u, e, {
|
|
1064
|
+
total: p,
|
|
1065
|
+
loaded: p
|
|
1066
|
+
}), e;
|
|
1067
|
+
}, A = async ({ data: e, error: r, status: i, extra: a }) => {
|
|
1068
|
+
let o = {
|
|
1069
|
+
data: e,
|
|
1070
|
+
error: r ?? null,
|
|
1071
|
+
success: !0,
|
|
1072
|
+
status: i,
|
|
1073
|
+
extra: a,
|
|
1074
|
+
requestTimestamp: x,
|
|
1075
|
+
responseTimestamp: +/* @__PURE__ */ new Date()
|
|
1076
|
+
};
|
|
1077
|
+
return o = await d.client.unstable_modifyResponse?.(o, d), o = await d.client.unstable_modifySuccessResponse?.(o, d), g.triggerPlugins("onRequestSuccess", {
|
|
1078
|
+
response: o,
|
|
1079
|
+
request: d
|
|
1080
|
+
}), g.triggerPlugins("onRequestFinished", {
|
|
1081
|
+
response: o,
|
|
1082
|
+
request: d
|
|
1083
|
+
}), n(o), c.info({
|
|
1084
|
+
title: "Response success",
|
|
1085
|
+
type: "response",
|
|
1086
|
+
extra: {
|
|
1087
|
+
request: d,
|
|
1088
|
+
requestId: t,
|
|
1089
|
+
response: o
|
|
1090
|
+
}
|
|
1091
|
+
}), o;
|
|
1092
|
+
}, j = Mt({
|
|
1093
|
+
request: d,
|
|
1094
|
+
requestId: t,
|
|
1095
|
+
startTime: x,
|
|
1096
|
+
logger: c,
|
|
1097
|
+
resolve: n
|
|
1098
|
+
}), M = ({ status: e, extra: n }) => (c.error({
|
|
1099
|
+
title: "Abort error",
|
|
1100
|
+
type: "request",
|
|
1101
|
+
extra: {
|
|
1102
|
+
request: d,
|
|
1103
|
+
requestId: t
|
|
1104
|
+
}
|
|
1105
|
+
}), j({
|
|
1106
|
+
error: i(H("abort")),
|
|
1107
|
+
status: e,
|
|
1108
|
+
extra: n
|
|
1109
|
+
})), ie = ({ status: e, extra: n }) => (c.error({
|
|
1110
|
+
title: "Timeout error",
|
|
1111
|
+
type: "request",
|
|
1112
|
+
extra: {
|
|
1113
|
+
request: d,
|
|
1114
|
+
requestId: t
|
|
1115
|
+
}
|
|
1116
|
+
}), j({
|
|
1117
|
+
error: H("timeout"),
|
|
1118
|
+
status: e,
|
|
1119
|
+
extra: n
|
|
1120
|
+
})), N = ({ status: e, extra: n }) => (c.error({
|
|
1121
|
+
title: "Unexpected error",
|
|
1122
|
+
type: "request",
|
|
1123
|
+
extra: {
|
|
1124
|
+
request: d,
|
|
1125
|
+
requestId: t
|
|
1126
|
+
}
|
|
1127
|
+
}), j({
|
|
1128
|
+
error: H(),
|
|
1129
|
+
status: e,
|
|
1130
|
+
extra: n
|
|
1131
|
+
})), P = () => a.getAbortController(v, t), F = ({ status: e, extra: n, onAbort: r = () => {} }) => {
|
|
1132
|
+
let i = P();
|
|
1133
|
+
if (!i) throw new V("Controller is not found");
|
|
1134
|
+
let o = () => {
|
|
1135
|
+
M({
|
|
1136
|
+
status: e,
|
|
1137
|
+
extra: n
|
|
1138
|
+
}), r(), a.events.emitAbort({
|
|
1139
|
+
requestId: t,
|
|
1140
|
+
request: d
|
|
1141
|
+
});
|
|
1142
|
+
};
|
|
1143
|
+
return i.signal.aborted && o(), i.signal.addEventListener("abort", o), () => i.signal.removeEventListener("abort", o);
|
|
1144
|
+
};
|
|
1145
|
+
c.debug({
|
|
1146
|
+
title: "Mounted adapter bindings",
|
|
1147
|
+
type: "request",
|
|
1148
|
+
extra: {
|
|
1149
|
+
request: d,
|
|
1150
|
+
requestId: t,
|
|
1151
|
+
payload: y,
|
|
1152
|
+
adapterOptions: b
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
let I = e.client.adapter.unstable_queryParamsMapper(d.queryParams), L = e.client.adapter.unstable_endpointMapper(d.endpoint), ae = e.client.adapter.unstable_headerMapper(d), { url: oe } = e.client;
|
|
1156
|
+
return {
|
|
1157
|
+
request: d,
|
|
1158
|
+
requestId: t,
|
|
1159
|
+
url: oe,
|
|
1160
|
+
endpoint: L,
|
|
1161
|
+
queryParams: I,
|
|
1162
|
+
payload: y,
|
|
1163
|
+
headers: ae,
|
|
1164
|
+
adapter: e.client.adapter,
|
|
1165
|
+
adapterOptions: b,
|
|
1166
|
+
getAbortController: P,
|
|
1167
|
+
getRequestStartTimestamp: S,
|
|
1168
|
+
getResponseStartTimestamp: C,
|
|
1169
|
+
createAbortListener: F,
|
|
1170
|
+
onBeforeRequest: D,
|
|
1171
|
+
onRequestStart: O,
|
|
1172
|
+
onRequestProgress: ee,
|
|
1173
|
+
onRequestEnd: k,
|
|
1174
|
+
onResponseStart: te,
|
|
1175
|
+
onResponseProgress: ne,
|
|
1176
|
+
onResponseEnd: re,
|
|
1177
|
+
onSuccess: A,
|
|
1178
|
+
onAbortError: M,
|
|
1179
|
+
onTimeoutError: ie,
|
|
1180
|
+
onUnexpectedError: N,
|
|
1181
|
+
onError: j
|
|
1182
|
+
};
|
|
1183
|
+
};
|
|
1184
|
+
function Mt({ request: e, requestId: t, startTime: n, resolve: r, logger: i }) {
|
|
1185
|
+
let { client: a } = e;
|
|
1186
|
+
return async ({ error: o, status: s, extra: c }) => {
|
|
1187
|
+
let l = {
|
|
1188
|
+
data: null,
|
|
1189
|
+
status: s,
|
|
1190
|
+
error: o,
|
|
1191
|
+
success: !1,
|
|
1192
|
+
extra: c,
|
|
1193
|
+
requestTimestamp: n,
|
|
1194
|
+
responseTimestamp: +/* @__PURE__ */ new Date()
|
|
1195
|
+
};
|
|
1196
|
+
return l = await a.unstable_modifyResponse(l, e), l = await a.unstable_modifyErrorResponse(l, e), a.triggerPlugins("onRequestError", {
|
|
1197
|
+
response: l,
|
|
1198
|
+
request: e
|
|
1199
|
+
}), a.triggerPlugins("onRequestFinished", {
|
|
1200
|
+
response: l,
|
|
1201
|
+
request: e
|
|
1202
|
+
}), r(l), i.error({
|
|
1203
|
+
title: "Request error",
|
|
1204
|
+
type: "request",
|
|
1205
|
+
extra: {
|
|
1206
|
+
request: e,
|
|
1207
|
+
requestId: t,
|
|
1208
|
+
response: l
|
|
1209
|
+
}
|
|
1210
|
+
}), l;
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
var Nt = async ({ request: e, requestId: t, onError: n, onResponseEnd: r, onTimeoutError: i, onRequestEnd: a, createAbortListener: o, onResponseProgress: s, onRequestProgress: c, onResponseStart: l, onBeforeRequest: u, onRequestStart: d, onSuccess: f, onAbortError: p, adapter: m }) => {
|
|
1214
|
+
if (!e.unstable_mock) throw new V("Mock should be defined when calling mocker");
|
|
1215
|
+
let h = !1, { requestTime: g = 20, responseTime: _ = 20, totalUploaded: v = 1e3, totalDownloaded: y = 1e3, timeout: b } = e.unstable_mock.config, { data: x, error: S, status: C, success: w = !0, extra: T = e.client.adapter.defaultExtra } = await e.unstable_mock.fn({
|
|
1216
|
+
request: e,
|
|
1217
|
+
requestId: t
|
|
1218
|
+
});
|
|
1219
|
+
o({
|
|
1220
|
+
status: m.systemErrorStatus,
|
|
1221
|
+
extra: m.systemErrorExtra,
|
|
1222
|
+
onAbort: () => {
|
|
1223
|
+
h = !0;
|
|
1224
|
+
}
|
|
1225
|
+
}), u(), d();
|
|
1226
|
+
let E = (e, t, n) => new Promise((r) => {
|
|
1227
|
+
if (h) {
|
|
1228
|
+
r(!0);
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
let i = +/* @__PURE__ */ new Date(), a = Math.ceil(e / 20), o = Math.ceil(t / a), s = 0, c = setInterval(function() {
|
|
1232
|
+
h && (r(!0), clearInterval(c));
|
|
1233
|
+
let a = Math.min(e, +/* @__PURE__ */ new Date() - i);
|
|
1234
|
+
s += s + o >= t ? t - s : o, n({
|
|
1235
|
+
total: t,
|
|
1236
|
+
loaded: a >= e ? t : s
|
|
1237
|
+
}), a >= e && (r(!0), clearInterval(c));
|
|
1238
|
+
}, 20);
|
|
1239
|
+
});
|
|
1240
|
+
typeof b == "number" && setTimeout(() => {
|
|
1241
|
+
h = !0, i({
|
|
1242
|
+
status: 0,
|
|
1243
|
+
extra: T
|
|
1244
|
+
});
|
|
1245
|
+
}, b), h || await E(g, v, c), h || (a(), l()), h || await E(_, y, s), h ? p({
|
|
1246
|
+
status: m.systemErrorStatus,
|
|
1247
|
+
extra: m.systemErrorExtra
|
|
1248
|
+
}) : w || S && x ? f({
|
|
1249
|
+
data: x,
|
|
1250
|
+
error: S,
|
|
1251
|
+
status: C,
|
|
1252
|
+
extra: T
|
|
1253
|
+
}) : n({
|
|
1254
|
+
error: S,
|
|
1255
|
+
status: C,
|
|
1256
|
+
extra: T
|
|
1257
|
+
}), h || r();
|
|
1258
|
+
}, Pt = (e) => e, Ft = class {
|
|
1259
|
+
unstable_fetcher;
|
|
1260
|
+
name;
|
|
1261
|
+
defaultMethod;
|
|
1262
|
+
defaultExtra;
|
|
1263
|
+
systemErrorStatus;
|
|
1264
|
+
systemErrorExtra;
|
|
1265
|
+
defaultRequestOptions;
|
|
1266
|
+
logger;
|
|
1267
|
+
initialized = !1;
|
|
1268
|
+
client;
|
|
1269
|
+
unstable_onInitializeCallback;
|
|
1270
|
+
unstable_queryParamsMapperConfig;
|
|
1271
|
+
unstable_headerMapperConfig;
|
|
1272
|
+
unstable_payloadMapperConfig;
|
|
1273
|
+
unstable_endpointMapperConfig;
|
|
1274
|
+
constructor(e) {
|
|
1275
|
+
this.options = e, this.name = e.name, this.defaultMethod = e.defaultMethod, this.defaultExtra = e.defaultExtra, this.systemErrorStatus = e.systemErrorStatus, this.systemErrorExtra = e.systemErrorExtra, this.defaultRequestOptions = e.defaultRequestOptions;
|
|
1276
|
+
}
|
|
1277
|
+
initialize = (e) => (this.logger = e.loggerManager.initialize(e, "Adapter"), this.initialized = !0, this.client = e, this.unstable_onInitializeCallback?.({ client: e }), this);
|
|
1278
|
+
onInitialize = (e) => (this.unstable_onInitializeCallback = e, this);
|
|
1279
|
+
unstable_internalErrorMapping = (e) => e;
|
|
1280
|
+
unstable_headerMapper = ht;
|
|
1281
|
+
unstable_payloadMapper = gt;
|
|
1282
|
+
unstable_endpointMapper = Pt;
|
|
1283
|
+
unstable_queryParamsMapper = Pt;
|
|
1284
|
+
unstable_getAdapterDefaults;
|
|
1285
|
+
unstable_getRequestDefaults;
|
|
1286
|
+
unstable_devtoolsEndpointGetter = (e) => e;
|
|
1287
|
+
setDefaultMethod = (e) => (this.defaultMethod = e, this);
|
|
1288
|
+
setDefaultExtra = (e) => (this.defaultExtra = e, this);
|
|
1289
|
+
setDevtoolsEndpointGetter = (e) => (this.unstable_devtoolsEndpointGetter = e, this);
|
|
1290
|
+
setRequestDefaults = (e) => (this.unstable_getRequestDefaults = e, this);
|
|
1291
|
+
setAdapterDefaults = (e) => (this.unstable_getAdapterDefaults = e, this);
|
|
1292
|
+
setInternalErrorMapping = (e) => (this.unstable_internalErrorMapping = e, this);
|
|
1293
|
+
setHeaderMapper = (e) => (this.unstable_headerMapper = ((t) => e(t, this.unstable_headerMapperConfig)), this);
|
|
1294
|
+
setPayloadMapper = (e) => (this.unstable_payloadMapper = ((t) => e(t, this.unstable_payloadMapperConfig)), this);
|
|
1295
|
+
setEndpointMapper = (e) => (this.unstable_endpointMapper = ((t) => e(t, this.unstable_endpointMapperConfig)), this);
|
|
1296
|
+
setQueryParamsMapper = (e) => (this.unstable_queryParamsMapper = ((t) => e(t, this.unstable_queryParamsMapperConfig)), this);
|
|
1297
|
+
setQueryParamsMapperConfig = (e) => (this.unstable_queryParamsMapperConfig = e, this);
|
|
1298
|
+
setHeaderMapperConfig = (e) => (this.unstable_headerMapperConfig = e, this);
|
|
1299
|
+
setEndpointMapperConfig = (e) => (this.unstable_endpointMapperConfig = e, this);
|
|
1300
|
+
setPayloadMapperConfig = (e) => (this.unstable_payloadMapperConfig = e, this);
|
|
1301
|
+
setFetcher(e) {
|
|
1302
|
+
return this.unstable_fetcher = e.bind(this), this;
|
|
1303
|
+
}
|
|
1304
|
+
async fetch(e, t) {
|
|
1305
|
+
let n, r = async (r) => {
|
|
1306
|
+
try {
|
|
1307
|
+
if (!this.initialized) throw new V(`Adapter ${this.options.name} is not initialized`);
|
|
1308
|
+
if (!this.unstable_fetcher) throw new V(`Fetcher for ${this.options.name} adapter is not set`);
|
|
1309
|
+
this.client.triggerPlugins("onAdapterFetch", {
|
|
1310
|
+
adapter: this,
|
|
1311
|
+
request: e,
|
|
1312
|
+
requestId: t
|
|
1313
|
+
});
|
|
1314
|
+
let i = await jt({
|
|
1315
|
+
request: e,
|
|
1316
|
+
requestId: t,
|
|
1317
|
+
resolve: r,
|
|
1318
|
+
internalErrorMapping: this.unstable_internalErrorMapping,
|
|
1319
|
+
onStartTime: (e) => {
|
|
1320
|
+
n = e;
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
return e.unstable_mock && e.isMockerEnabled && e.client.isMockerEnabled ? await Nt(i) : this.unstable_fetcher(i);
|
|
1324
|
+
} catch (i) {
|
|
1325
|
+
return Mt({
|
|
1326
|
+
request: e,
|
|
1327
|
+
requestId: t,
|
|
1328
|
+
startTime: n || Date.now(),
|
|
1329
|
+
logger: this.logger,
|
|
1330
|
+
resolve: r
|
|
1331
|
+
})({
|
|
1332
|
+
error: this.unstable_internalErrorMapping(i),
|
|
1333
|
+
status: this.options.systemErrorStatus,
|
|
1334
|
+
extra: this.options.systemErrorExtra
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
return new Promise((e) => {
|
|
1339
|
+
r(e);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}, It = (e) => {
|
|
1343
|
+
try {
|
|
1344
|
+
return JSON.parse(e);
|
|
1345
|
+
} catch {
|
|
1346
|
+
return e;
|
|
1347
|
+
}
|
|
1348
|
+
}, Lt = (e) => e ? It(e) : H(), Rt = (e) => (t) => {
|
|
1349
|
+
let { skipNull: n, skipEmptyString: r } = e;
|
|
1350
|
+
return !(r && t === void 0 || r && t === "" || n && t === null);
|
|
1351
|
+
}, W = (e, { encode: t, strict: n }) => t && n ? encodeURIComponent(e).replace(/[!'()*]/g, (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`) : t ? encodeURIComponent(e) : e, zt = (e, t, n) => {
|
|
1352
|
+
let r = !Rt(n)(t);
|
|
1353
|
+
return !e || r ? "" : `${W(e, n)}=${W(t instanceof Date ? n.dateParser?.(t) || t.toISOString() : typeof t == "object" && !Array.isArray(t) ? n.objectParser?.(t) || JSON.stringify(t) : String(t), n)}`;
|
|
1354
|
+
}, Bt = (e, t, n) => {
|
|
1355
|
+
let { arrayFormat: r, arraySeparator: i } = n;
|
|
1356
|
+
return t.filter(Rt(n)).reduce((t, a, o) => {
|
|
1357
|
+
switch (r) {
|
|
1358
|
+
case "index": {
|
|
1359
|
+
let r = `${W(e, n)}[${W(String(o), n)}]=`;
|
|
1360
|
+
t.push(`${r}${W(String(a), n)}`);
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
case "bracket": {
|
|
1364
|
+
let r = `${W(e, n)}[]=`;
|
|
1365
|
+
t.push(`${r}${W(String(a), n)}`);
|
|
1366
|
+
break;
|
|
1367
|
+
}
|
|
1368
|
+
case "comma": {
|
|
1369
|
+
let r = !t.length && `${W(e, n)}=` || "";
|
|
1370
|
+
return [[...t, `${r}${W(String(a), n)}`].join(",")];
|
|
1371
|
+
}
|
|
1372
|
+
case "separator": {
|
|
1373
|
+
let r = !t.length && `${W(e, n)}=` || "";
|
|
1374
|
+
return [[...t, `${r}${W(String(a), n)}`].join(i || "|")];
|
|
1375
|
+
}
|
|
1376
|
+
case "bracket-separator": {
|
|
1377
|
+
let r = !t.length && `${W(e, n)}[]=` || "";
|
|
1378
|
+
return [[...t, `${r}${W(String(a), n)}`].join(i || "|")];
|
|
1379
|
+
}
|
|
1380
|
+
default: {
|
|
1381
|
+
let r = `${W(e, n)}=`;
|
|
1382
|
+
t.push(`${r}${W(String(a), n)}`);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return t;
|
|
1386
|
+
}, []).join("&");
|
|
1387
|
+
}, Vt = (e, t = gn) => {
|
|
1388
|
+
if (!e || !Object.keys(e).length) return "";
|
|
1389
|
+
if (typeof e == "string") return e[0] === "?" ? e : `?${e}`;
|
|
1390
|
+
let n = Object.entries(e).map(([e, n]) => Array.isArray(n) ? Bt(e, n, t) : zt(e, n, t)).filter(Boolean).join("&");
|
|
1391
|
+
return n ? `?${n}` : "";
|
|
1392
|
+
}, Ht = kt.SEC * 5, G = { headers: {} }, Ut = () => new Ft({
|
|
1393
|
+
name: "http",
|
|
1394
|
+
defaultMethod: yt.GET,
|
|
1395
|
+
defaultExtra: G,
|
|
1396
|
+
systemErrorStatus: 0,
|
|
1397
|
+
systemErrorExtra: G
|
|
1398
|
+
}).setQueryParamsMapper(Vt).setFetcher(async ({ request: e, adapterOptions: t, headers: n, payload: r, onError: i, onResponseEnd: a, onTimeoutError: o, onRequestEnd: s, createAbortListener: c, getAbortController: l, onResponseProgress: u, onResponseStart: d, onBeforeRequest: f, onRequestStart: p, onRequestProgress: m, onSuccess: h }) => {
|
|
1399
|
+
let { method: g, client: _, endpoint: v, queryParams: y } = e, b = y ? Vt(y) : "", x = `${_.url}${v}${b}`, S = l(), { timeout: C = Ht, streaming: w = !1, ...T } = t || {}, E = !1, D, O = c({
|
|
1400
|
+
status: 0,
|
|
1401
|
+
extra: G
|
|
1402
|
+
});
|
|
1403
|
+
C > 0 && S && (D = setTimeout(() => {
|
|
1404
|
+
E = !0, O(), S.abort();
|
|
1405
|
+
}, C)), f(), p();
|
|
1406
|
+
try {
|
|
1407
|
+
let e = {
|
|
1408
|
+
method: g,
|
|
1409
|
+
headers: n,
|
|
1410
|
+
signal: S?.signal,
|
|
1411
|
+
...T
|
|
1412
|
+
};
|
|
1413
|
+
if (r && g !== "GET" && g !== "HEAD" && (e.body = r, typeof r == "string")) {
|
|
1414
|
+
let e = new Blob([r]).size;
|
|
1415
|
+
m({
|
|
1416
|
+
total: e,
|
|
1417
|
+
loaded: e
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
s();
|
|
1421
|
+
let t = await fetch(x, e);
|
|
1422
|
+
D && clearTimeout(D), d();
|
|
1423
|
+
let o = {};
|
|
1424
|
+
t.headers.forEach((e, t) => {
|
|
1425
|
+
o[t] = e;
|
|
1426
|
+
});
|
|
1427
|
+
let c = { headers: o }, { status: l } = t;
|
|
1428
|
+
if (w && t.body) a(), O(), t.ok ? h({
|
|
1429
|
+
data: t.body,
|
|
1430
|
+
status: l,
|
|
1431
|
+
extra: c
|
|
1432
|
+
}) : i({
|
|
1433
|
+
error: Lt(await t.text()),
|
|
1434
|
+
status: l,
|
|
1435
|
+
extra: c
|
|
1436
|
+
});
|
|
1437
|
+
else {
|
|
1438
|
+
let e;
|
|
1439
|
+
if (t.body && typeof t.body.getReader == "function") {
|
|
1440
|
+
let n = t.body.getReader(), r = parseInt(t.headers.get("content-length") || "0", 10), i = 0, a = [];
|
|
1441
|
+
for (;;) {
|
|
1442
|
+
let { done: e, value: t } = await n.read();
|
|
1443
|
+
if (e) break;
|
|
1444
|
+
a.push(t), i += t.length, u({
|
|
1445
|
+
total: r || i,
|
|
1446
|
+
loaded: i
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
let o = new Uint8Array(i), s = 0;
|
|
1450
|
+
for (let e of a) o.set(e, s), s += e.length;
|
|
1451
|
+
e = new TextDecoder().decode(o);
|
|
1452
|
+
} else e = await t.text();
|
|
1453
|
+
a(), O(), t.ok ? h({
|
|
1454
|
+
data: It(e),
|
|
1455
|
+
status: l,
|
|
1456
|
+
extra: c
|
|
1457
|
+
}) : i({
|
|
1458
|
+
error: Lt(e),
|
|
1459
|
+
status: l,
|
|
1460
|
+
extra: c
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
if (D && clearTimeout(D), O(), S?.signal?.aborted) {
|
|
1465
|
+
E && o({
|
|
1466
|
+
status: 0,
|
|
1467
|
+
extra: G
|
|
1468
|
+
});
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
i({
|
|
1472
|
+
error: e,
|
|
1473
|
+
status: 0,
|
|
1474
|
+
extra: G
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
}), Wt = () => Ut(), Gt = class {
|
|
1478
|
+
emitter = new ye();
|
|
1479
|
+
events;
|
|
1480
|
+
storage;
|
|
1481
|
+
lazyStorage;
|
|
1482
|
+
version;
|
|
1483
|
+
garbageCollectors = /* @__PURE__ */ new Map();
|
|
1484
|
+
logger;
|
|
1485
|
+
client;
|
|
1486
|
+
constructor(e) {
|
|
1487
|
+
this.options = e;
|
|
1488
|
+
let { storage: t = /* @__PURE__ */ new Map(), lazyStorage: n, version: r = "0.0.1" } = e ?? {};
|
|
1489
|
+
this.emitter?.setMaxListeners(1e3), this.events = $t(this.emitter), this.storage = t, this.version = r, this.lazyStorage = n;
|
|
1490
|
+
}
|
|
1491
|
+
initialize = (e) => (this.client = e, this.logger = e.loggerManager.initialize(e, "Cache"), e.appManager.events.onOnline(() => {
|
|
1492
|
+
[...this.storage.keys()].forEach(this.scheduleGarbageCollector);
|
|
1493
|
+
}), [...this.storage.keys()].forEach(this.scheduleGarbageCollector), this);
|
|
1494
|
+
set = (e, t) => {
|
|
1495
|
+
this.logger.debug({
|
|
1496
|
+
title: "Processing cache response",
|
|
1497
|
+
type: "system",
|
|
1498
|
+
extra: {
|
|
1499
|
+
request: e,
|
|
1500
|
+
response: t
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
let { cacheKey: n, cache: r, staleTime: i, cacheTime: a, scope: o } = e, s = U(n, o), c = this.storage.get(s), l = typeof t == "function" ? t(c || null) : t, u = Kt(c, l), d = {
|
|
1504
|
+
...u,
|
|
1505
|
+
scope: o,
|
|
1506
|
+
staleTime: i,
|
|
1507
|
+
version: this.version,
|
|
1508
|
+
cacheKey: n,
|
|
1509
|
+
cacheTime: a,
|
|
1510
|
+
cached: !!e.cache
|
|
1511
|
+
}, f = this.client.mode === "server", p = r && (!f || !!e.scope);
|
|
1512
|
+
l.success && p ? (this.logger.debug({
|
|
1513
|
+
title: "Saving response to cache storage",
|
|
1514
|
+
type: "system",
|
|
1515
|
+
extra: {
|
|
1516
|
+
request: e,
|
|
1517
|
+
data: u
|
|
1518
|
+
}
|
|
1519
|
+
}), this.storage.set(s, d), this.lazyStorage?.set(s, d), this.client.triggerPlugins("onCacheItemChange", {
|
|
1520
|
+
cache: this,
|
|
1521
|
+
cacheKey: n,
|
|
1522
|
+
prevData: c || null,
|
|
1523
|
+
newData: d
|
|
1524
|
+
}), this.scheduleGarbageCollector(s)) : this.logger.debug({
|
|
1525
|
+
title: "Prevented saving response to cache",
|
|
1526
|
+
type: "system",
|
|
1527
|
+
extra: {
|
|
1528
|
+
request: e,
|
|
1529
|
+
data: u
|
|
1530
|
+
}
|
|
1531
|
+
}), this.logger.debug({
|
|
1532
|
+
title: "Emitting cache response",
|
|
1533
|
+
type: "system",
|
|
1534
|
+
extra: {
|
|
1535
|
+
request: e,
|
|
1536
|
+
data: u
|
|
1537
|
+
}
|
|
1538
|
+
}), this.events.emitCacheData(d);
|
|
1539
|
+
};
|
|
1540
|
+
update = (e, t) => {
|
|
1541
|
+
this.logger.debug({
|
|
1542
|
+
title: "Processing cache update",
|
|
1543
|
+
type: "system",
|
|
1544
|
+
extra: {
|
|
1545
|
+
request: e,
|
|
1546
|
+
partialResponse: t
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
let { cacheKey: n, scope: r } = e, i = U(n, r), a = this.storage.get(i), o = typeof t == "function" ? t(a || null) : t;
|
|
1550
|
+
a && this.set(e, {
|
|
1551
|
+
...a,
|
|
1552
|
+
...o
|
|
1553
|
+
});
|
|
1554
|
+
};
|
|
1555
|
+
get = (e) => (this.getLazyResource(e), this.storage.get(e));
|
|
1556
|
+
keys = () => {
|
|
1557
|
+
let e = this.storage.keys();
|
|
1558
|
+
return Array.from(e);
|
|
1559
|
+
};
|
|
1560
|
+
delete = (e) => {
|
|
1561
|
+
this.logger.debug({
|
|
1562
|
+
title: "Deleting cache element",
|
|
1563
|
+
type: "system",
|
|
1564
|
+
extra: { cacheKey: e }
|
|
1565
|
+
}), this.storage.delete(e), this.lazyStorage?.delete(e), this.client.triggerPlugins("onCacheItemDelete", {
|
|
1566
|
+
cache: this,
|
|
1567
|
+
cacheKey: e
|
|
1568
|
+
}), this.events.emitDelete(e);
|
|
1569
|
+
};
|
|
1570
|
+
invalidate = (e) => {
|
|
1571
|
+
this.logger.debug({
|
|
1572
|
+
title: "Revalidating cache element",
|
|
1573
|
+
type: "system",
|
|
1574
|
+
extra: { cacheKeys: e }
|
|
1575
|
+
});
|
|
1576
|
+
let t = (e) => {
|
|
1577
|
+
let t = Array.from(this.storage.keys()), n = (e, t = e) => {
|
|
1578
|
+
let n = this.storage.get(e);
|
|
1579
|
+
n && this.storage.set(e, {
|
|
1580
|
+
...n,
|
|
1581
|
+
staleTime: 0
|
|
1582
|
+
}), this.client.triggerPlugins("onCacheItemInvalidate", {
|
|
1583
|
+
cache: this,
|
|
1584
|
+
cacheKey: t
|
|
1585
|
+
}), this.events.emitInvalidation(t);
|
|
1586
|
+
};
|
|
1587
|
+
e instanceof At ? n(U(e.cacheKey, e.scope), e.cacheKey) : typeof e == "string" ? n(e) : t.length && t.forEach((t) => {
|
|
1588
|
+
e.test(t) && n(t);
|
|
1589
|
+
});
|
|
1590
|
+
};
|
|
1591
|
+
Array.isArray(e) ? e.forEach(t.bind(this)) : t.bind(this)(e);
|
|
1592
|
+
};
|
|
1593
|
+
getLazyResource = async (e) => {
|
|
1594
|
+
let t = await this.lazyStorage?.get(e), n = this.storage.get(e);
|
|
1595
|
+
if (this.lazyStorage && t) {
|
|
1596
|
+
let r = +/* @__PURE__ */ new Date(), i = n ? n.responseTimestamp < t.responseTimestamp : !0, a = t.staleTime <= r - t.responseTimestamp, o = t.version === this.version;
|
|
1597
|
+
if (o || this.lazyStorage?.delete(e), i && !a && o) return this.storage.set(e, t), this.events.emitCacheData({
|
|
1598
|
+
...t,
|
|
1599
|
+
cacheKey: e,
|
|
1600
|
+
cached: !0
|
|
1601
|
+
}), t;
|
|
1602
|
+
}
|
|
1603
|
+
let r = n?.version === this.version;
|
|
1604
|
+
return n && !r && this.delete(e), n;
|
|
1605
|
+
};
|
|
1606
|
+
getLazyKeys = async () => {
|
|
1607
|
+
let e = await this.lazyStorage?.keys() || [];
|
|
1608
|
+
return [...new Set(e)];
|
|
1609
|
+
};
|
|
1610
|
+
getAllKeys = async () => {
|
|
1611
|
+
let e = await this.lazyStorage?.keys(), t = Array.from(e || []), n = Array.from(this.storage.keys());
|
|
1612
|
+
return [...new Set([...t, ...n])];
|
|
1613
|
+
};
|
|
1614
|
+
scheduleGarbageCollector = (e) => {
|
|
1615
|
+
let t = this.storage.get(e);
|
|
1616
|
+
if (clearTimeout(this.garbageCollectors.get(e)), t) {
|
|
1617
|
+
let n = t.cacheTime + t.responseTimestamp - +/* @__PURE__ */ new Date();
|
|
1618
|
+
t.cacheTime === null ? this.logger.debug({
|
|
1619
|
+
title: "Cache time is null",
|
|
1620
|
+
type: "system",
|
|
1621
|
+
extra: { cacheKey: e }
|
|
1622
|
+
}) : t.cacheTime !== null && JSON.stringify(t.cacheTime) === "null" || t.cacheTime === Infinity ? this.logger.debug({
|
|
1623
|
+
title: "Cache time is Infinite",
|
|
1624
|
+
type: "system",
|
|
1625
|
+
extra: { cacheKey: e }
|
|
1626
|
+
}) : n >= 0 ? this.garbageCollectors.set(e, setTimeout(() => {
|
|
1627
|
+
this.client.appManager.isOnline && (this.logger.info({
|
|
1628
|
+
title: "Garbage collecting cache data",
|
|
1629
|
+
type: "system",
|
|
1630
|
+
extra: { cacheKey: e }
|
|
1631
|
+
}), this.delete(e));
|
|
1632
|
+
}, n)) : this.client.appManager.isOnline && (this.logger.info({
|
|
1633
|
+
title: "Garbage collecting cache data",
|
|
1634
|
+
type: "system",
|
|
1635
|
+
extra: { cacheKey: e }
|
|
1636
|
+
}), this.delete(e));
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
clear = async () => {
|
|
1640
|
+
this.garbageCollectors.forEach((e) => clearTimeout(e)), this.storage.clear();
|
|
1641
|
+
};
|
|
1642
|
+
}, Kt = (e, t) => {
|
|
1643
|
+
let { data: n, success: r } = t, i = !r && e ? e.data : null, a = n || i;
|
|
1644
|
+
return {
|
|
1645
|
+
...t,
|
|
1646
|
+
data: a
|
|
1647
|
+
};
|
|
1648
|
+
}, qt = () => "invalidate", Jt = (e) => `${e}_invalidate`, Yt = () => "delete", Xt = (e) => `${e}_delete`, Zt = (e) => `${e}_cache`, Qt = () => "cache", $t = (e) => ({
|
|
1649
|
+
emitCacheData: (t, n = !1) => {
|
|
1650
|
+
e.emit(Qt(), t, n), e.emit(Zt(t.cacheKey), t, n);
|
|
1651
|
+
},
|
|
1652
|
+
emitInvalidation: (t, n = !1) => {
|
|
1653
|
+
e.emit(qt(), t, n), e.emit(Jt(t), n);
|
|
1654
|
+
},
|
|
1655
|
+
emitDelete: (t, n = !1) => {
|
|
1656
|
+
e.emit(Yt(), t, n), e.emit(Xt(t), n);
|
|
1657
|
+
},
|
|
1658
|
+
onData: (t) => (e.on(Qt(), t), () => e.removeListener(Qt(), t)),
|
|
1659
|
+
onDataByKey: (t, n) => (e.on(Zt(t), n), () => e.removeListener(Zt(t), n)),
|
|
1660
|
+
onInvalidate: (t) => (e.on(qt(), t), () => e.removeListener(qt(), t)),
|
|
1661
|
+
onInvalidateByKey: (t, n) => (e.on(Jt(t), n), () => e.removeListener(Jt(t), n)),
|
|
1662
|
+
onDelete: (t) => (e.on(Yt(), t), () => e.removeListener(Yt(), t)),
|
|
1663
|
+
onDeleteByKey: (t, n) => (e.on(Xt(t), n), () => e.removeListener(Xt(t), n))
|
|
1664
|
+
}), K = /* @__PURE__ */ function(e) {
|
|
1665
|
+
return e.ONE_BY_ONE = "one-by-one", e.ALL_AT_ONCE = "all-at-once", e.PREVIOUS_CANCELED = "previous-canceled", e.DEDUPLICATED = "deduplicated", e;
|
|
1666
|
+
}({}), en = (e) => ({
|
|
1667
|
+
emitDrained: (t, n) => {
|
|
1668
|
+
e.emit(nn(), t, n), e.emit(rn(t.queryKey), t, n);
|
|
1669
|
+
},
|
|
1670
|
+
emitQueueStatusChanged: (t, n) => {
|
|
1671
|
+
e.emit(an(), t, n), e.emit(on(t.queryKey), t, n);
|
|
1672
|
+
},
|
|
1673
|
+
emitQueueChanged: (t, n) => {
|
|
1674
|
+
e.emit(sn(), t, n), e.emit(cn(t.queryKey), t, n);
|
|
1675
|
+
},
|
|
1676
|
+
onDrained: (t) => (e.on(nn(), t), () => e.removeListener(nn(), t)),
|
|
1677
|
+
onDrainedByKey: (t, n) => (e.on(rn(t), n), () => e.removeListener(rn(t), n)),
|
|
1678
|
+
onQueueStatusChange: (t) => (e.on(an(), t), () => e.removeListener(an(), t)),
|
|
1679
|
+
onQueueStatusChangeByKey: (t, n) => (e.on(on(t), n), () => e.removeListener(on(t), n)),
|
|
1680
|
+
onQueueChange: (t) => (e.on(sn(), t), () => e.removeListener(sn(), t)),
|
|
1681
|
+
onQueueChangeByKey: (t, n) => (e.on(cn(t), n), () => e.removeListener(cn(t), n))
|
|
1682
|
+
}), tn = class {
|
|
1683
|
+
emitter = new ye();
|
|
1684
|
+
events = en(this.emitter);
|
|
1685
|
+
storage = /* @__PURE__ */ new Map();
|
|
1686
|
+
requestCount = /* @__PURE__ */ new Map();
|
|
1687
|
+
runningRequests = /* @__PURE__ */ new Map();
|
|
1688
|
+
logger;
|
|
1689
|
+
client;
|
|
1690
|
+
constructor(e) {
|
|
1691
|
+
this.options = e, this.emitter?.setMaxListeners(1e3), this.options?.storage && (this.storage = this.options.storage);
|
|
1692
|
+
}
|
|
1693
|
+
isRequestJSON = (e) => !(e instanceof At);
|
|
1694
|
+
initialize = (e) => (this.client = e, this.logger = e.loggerManager.initialize(e, "Dispatcher"), this.client.appManager.events.onOnline(() => {
|
|
1695
|
+
this.flush();
|
|
1696
|
+
}), this);
|
|
1697
|
+
start = (e) => {
|
|
1698
|
+
let t = this.getQueue(e);
|
|
1699
|
+
t.stopped = !1, this.setQueue(e, t), this.flushQueue(e), this.client.triggerPlugins("onDispatcherQueueRunning", {
|
|
1700
|
+
dispatcher: this,
|
|
1701
|
+
queue: t,
|
|
1702
|
+
status: "running"
|
|
1703
|
+
}), this.events.emitQueueStatusChanged(t);
|
|
1704
|
+
};
|
|
1705
|
+
pause = (e) => {
|
|
1706
|
+
let t = this.getQueue(e);
|
|
1707
|
+
t.stopped = !0, this.setQueue(e, t), this.client.triggerPlugins("onDispatcherQueueRunning", {
|
|
1708
|
+
dispatcher: this,
|
|
1709
|
+
queue: t,
|
|
1710
|
+
status: "paused"
|
|
1711
|
+
}), this.events.emitQueueStatusChanged(t);
|
|
1712
|
+
};
|
|
1713
|
+
stop = (e) => {
|
|
1714
|
+
let t = this.getQueue(e);
|
|
1715
|
+
t.stopped = !0, this.setQueue(e, t), this.cancelRunningRequests(e), this.client.triggerPlugins("onDispatcherQueueRunning", {
|
|
1716
|
+
dispatcher: this,
|
|
1717
|
+
queue: t,
|
|
1718
|
+
status: "stopped"
|
|
1719
|
+
}), this.events.emitQueueStatusChanged(t);
|
|
1720
|
+
};
|
|
1721
|
+
getQueuesKeys = () => Array.from(this.storage.keys());
|
|
1722
|
+
getQueue = (e) => {
|
|
1723
|
+
let t = {
|
|
1724
|
+
queryKey: e,
|
|
1725
|
+
requests: [],
|
|
1726
|
+
stopped: !1
|
|
1727
|
+
}, n = this.storage.get(e);
|
|
1728
|
+
if (!n) return t;
|
|
1729
|
+
let r = n.requests.map((e) => this.isRequestJSON(e.request) ? {
|
|
1730
|
+
...e,
|
|
1731
|
+
request: this.client.fromJSON(e.request)
|
|
1732
|
+
} : e);
|
|
1733
|
+
return {
|
|
1734
|
+
...n,
|
|
1735
|
+
requests: r
|
|
1736
|
+
};
|
|
1737
|
+
};
|
|
1738
|
+
getRequest = (e, t) => {
|
|
1739
|
+
let n = {
|
|
1740
|
+
queryKey: e,
|
|
1741
|
+
requests: [],
|
|
1742
|
+
stopped: !1
|
|
1743
|
+
};
|
|
1744
|
+
return (this.storage.get(e) || n).requests.find((e) => e.requestId === t);
|
|
1745
|
+
};
|
|
1746
|
+
getIsActiveQueue = (e) => {
|
|
1747
|
+
let t = this.getQueue(e), n = t.requests.some((e) => !e.stopped), r = !t.stopped;
|
|
1748
|
+
return n && r;
|
|
1749
|
+
};
|
|
1750
|
+
addQueueItem = (e, t) => {
|
|
1751
|
+
let n = this.getQueue(e);
|
|
1752
|
+
n.requests.push(t), this.client.triggerPlugins("onDispatcherItemAdded", {
|
|
1753
|
+
dispatcher: this,
|
|
1754
|
+
queue: n,
|
|
1755
|
+
queueItem: t
|
|
1756
|
+
}), this.setQueue(e, n);
|
|
1757
|
+
};
|
|
1758
|
+
setQueue = (e, t) => (this.storage.set(e, t), this.client.triggerPlugins("onDispatcherQueueCreated", {
|
|
1759
|
+
dispatcher: this,
|
|
1760
|
+
queue: t
|
|
1761
|
+
}), this.events.emitQueueChanged(t), t);
|
|
1762
|
+
clearQueue = (e) => {
|
|
1763
|
+
let t = {
|
|
1764
|
+
queryKey: e,
|
|
1765
|
+
requests: [],
|
|
1766
|
+
stopped: this.getQueue(e).stopped
|
|
1767
|
+
};
|
|
1768
|
+
return this.storage.set(e, t), this.client.triggerPlugins("onDispatcherQueueCleared", {
|
|
1769
|
+
dispatcher: this,
|
|
1770
|
+
queue: t
|
|
1771
|
+
}), this.events.emitQueueChanged(t), this.events.emitDrained(t), t;
|
|
1772
|
+
};
|
|
1773
|
+
flushQueue = async (e) => {
|
|
1774
|
+
let t = this.getQueue(e), n = this.getRunningRequests(e), r = t.requests.find((e) => !e.stopped), i = t && t.stopped, a = !this.client.appManager.isOnline, o = !r?.request.queued, s = !n.length, c = !r;
|
|
1775
|
+
i || a || c ? this.logger.debug({
|
|
1776
|
+
title: "Skipping queue trigger",
|
|
1777
|
+
type: "system",
|
|
1778
|
+
extra: {
|
|
1779
|
+
isStopped: i,
|
|
1780
|
+
isOffline: a,
|
|
1781
|
+
isEmpty: c
|
|
1782
|
+
}
|
|
1783
|
+
}) : o ? t.requests.forEach((t) => {
|
|
1784
|
+
this.hasRunningRequest(e, t.requestId) || this.performRequest(t);
|
|
1785
|
+
}) : s && (await this.performRequest(r), this.flushQueue(e));
|
|
1786
|
+
};
|
|
1787
|
+
flush = async () => {
|
|
1788
|
+
let e = this.getQueuesKeys();
|
|
1789
|
+
for (let t of e) this.getQueue(t) && this.flushQueue(t);
|
|
1790
|
+
};
|
|
1791
|
+
clear = () => {
|
|
1792
|
+
this.getQueuesKeys().forEach((e) => this.cancelRunningRequests(e)), this.runningRequests.clear(), this.storage.clear(), this.client.triggerPlugins("onDispatcherCleared", { dispatcher: this });
|
|
1793
|
+
};
|
|
1794
|
+
startRequest = (e, t) => {
|
|
1795
|
+
let n = this.getQueue(e), r = n.requests.find((e) => e.requestId === t);
|
|
1796
|
+
r && (r.stopped = !1, this.setQueue(e, n), this.flushQueue(e), this.events.emitQueueStatusChanged(n));
|
|
1797
|
+
};
|
|
1798
|
+
stopRequest = (e, t) => {
|
|
1799
|
+
let n = this.getQueue(e), r = n.requests.find((e) => e.requestId === t);
|
|
1800
|
+
r && (r.stopped = !0, this.setQueue(e, n), this.cancelRunningRequest(e, t), this.events.emitQueueStatusChanged(n));
|
|
1801
|
+
};
|
|
1802
|
+
getAllRunningRequests = () => Array.from(this.runningRequests.values()).flat();
|
|
1803
|
+
getRunningRequests = (e) => this.runningRequests.get(e) || [];
|
|
1804
|
+
getRunningRequest = (e, t) => this.getRunningRequests(e).find((e) => e.requestId === t);
|
|
1805
|
+
addRunningRequest = (e, t, n) => {
|
|
1806
|
+
let r = {
|
|
1807
|
+
requestId: t,
|
|
1808
|
+
request: n,
|
|
1809
|
+
timestamp: Date.now()
|
|
1810
|
+
}, i = this.getRunningRequests(e);
|
|
1811
|
+
return i.push(r), this.runningRequests.set(e, i), r;
|
|
1812
|
+
};
|
|
1813
|
+
hasRunningRequests = (e) => !!this.getRunningRequests(e).length;
|
|
1814
|
+
hasRunningRequest = (e, t) => !!this.getRunningRequests(e).find((e) => e.requestId === t);
|
|
1815
|
+
cancelRunningRequests = (e) => {
|
|
1816
|
+
this.runningRequests.get(e)?.forEach((e) => {
|
|
1817
|
+
let t = U(e.request.abortKey, e.request.scope);
|
|
1818
|
+
this.client.requestManager.abortByRequestId(t, e.requestId);
|
|
1819
|
+
}), this.deleteRunningRequests(e);
|
|
1820
|
+
};
|
|
1821
|
+
cancelRunningRequest = (e, t) => {
|
|
1822
|
+
let n = this.getRunningRequests(e).filter((e) => {
|
|
1823
|
+
if (e.requestId === t) {
|
|
1824
|
+
let t = U(e.request.abortKey, e.request.scope);
|
|
1825
|
+
return this.client.requestManager.abortByRequestId(t, e.requestId), !1;
|
|
1826
|
+
}
|
|
1827
|
+
return !0;
|
|
1828
|
+
});
|
|
1829
|
+
this.runningRequests.set(e, n);
|
|
1830
|
+
};
|
|
1831
|
+
deleteRunningRequests = (e) => {
|
|
1832
|
+
this.runningRequests.set(e, []);
|
|
1833
|
+
};
|
|
1834
|
+
deleteRunningRequest = (e, t) => {
|
|
1835
|
+
let n = this.getRunningRequests(e);
|
|
1836
|
+
this.runningRequests.set(e, n.filter((e) => e.requestId !== t));
|
|
1837
|
+
};
|
|
1838
|
+
getQueueRequestCount = (e) => this.requestCount.get(e) || 0;
|
|
1839
|
+
incrementQueueRequestCount = (e) => {
|
|
1840
|
+
let t = this.requestCount.get(e) || 0;
|
|
1841
|
+
this.requestCount.set(e, t + 1);
|
|
1842
|
+
};
|
|
1843
|
+
createStorageItem = (e) => ({
|
|
1844
|
+
requestId: this.client.unstable_requestIdMapper(e),
|
|
1845
|
+
timestamp: +/* @__PURE__ */ new Date(),
|
|
1846
|
+
request: e,
|
|
1847
|
+
retries: 0,
|
|
1848
|
+
stopped: !1,
|
|
1849
|
+
resolved: !1
|
|
1850
|
+
});
|
|
1851
|
+
add = (e) => {
|
|
1852
|
+
let t = U(e.queryKey, e.scope), n = this.createStorageItem(e), { requestId: r } = n, [i] = this.getQueue(t).requests.slice(-1), a = dn(e, i);
|
|
1853
|
+
switch (this.logger.debug({
|
|
1854
|
+
title: "Adding request to queue",
|
|
1855
|
+
type: "system",
|
|
1856
|
+
extra: {
|
|
1857
|
+
requestType: a,
|
|
1858
|
+
request: e,
|
|
1859
|
+
requestId: r
|
|
1860
|
+
}
|
|
1861
|
+
}), a) {
|
|
1862
|
+
case K.ONE_BY_ONE: return this.addQueueItem(t, n), this.flushQueue(t), r;
|
|
1863
|
+
case K.PREVIOUS_CANCELED: return this.cancelRunningRequests(t), this.clearQueue(t), this.addQueueItem(t, n), this.flushQueue(t), r;
|
|
1864
|
+
case K.DEDUPLICATED: return this.client.requestManager.events.emitDeduplicated({
|
|
1865
|
+
request: i.request,
|
|
1866
|
+
requestId: r,
|
|
1867
|
+
deduplicatedRequest: e
|
|
1868
|
+
}), i.requestId;
|
|
1869
|
+
default: return this.addQueueItem(t, n), this.flushQueue(t), r;
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
delete = (e, t, n) => {
|
|
1873
|
+
this.logger.debug({
|
|
1874
|
+
title: "Deleting request",
|
|
1875
|
+
type: "system",
|
|
1876
|
+
extra: {
|
|
1877
|
+
queryKey: e,
|
|
1878
|
+
requestId: t,
|
|
1879
|
+
abortKey: n
|
|
1880
|
+
}
|
|
1881
|
+
});
|
|
1882
|
+
let r = this.getQueue(e), i = r.requests.find((e) => e.requestId === t);
|
|
1883
|
+
if (i) return r.requests = r.requests.filter((e) => e.requestId !== t), this.storage.set(e, r), this.hasRunningRequest(e, t) && (this.deleteRunningRequest(e, t), this.client.requestManager.abortByRequestId(n, t)), this.client.triggerPlugins("onDispatcherItemDeleted", {
|
|
1884
|
+
queue: r,
|
|
1885
|
+
dispatcher: this,
|
|
1886
|
+
queueItem: i
|
|
1887
|
+
}), this.events.emitQueueChanged(r), this.client.requestManager.events.emitRemove({
|
|
1888
|
+
requestId: t,
|
|
1889
|
+
request: i.request,
|
|
1890
|
+
resolved: i.resolved
|
|
1891
|
+
}), r.requests.length || (this.client.triggerPlugins("onDispatcherQueueDrained", {
|
|
1892
|
+
queue: r,
|
|
1893
|
+
dispatcher: this
|
|
1894
|
+
}), this.events.emitDrained(r)), r;
|
|
1895
|
+
};
|
|
1896
|
+
performRequest = async (e) => {
|
|
1897
|
+
let { request: t, requestId: n } = e;
|
|
1898
|
+
this.logger.debug({
|
|
1899
|
+
title: "Performing request",
|
|
1900
|
+
type: "system",
|
|
1901
|
+
extra: {
|
|
1902
|
+
request: t,
|
|
1903
|
+
requestId: n
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
let { retry: r, retryTime: i, queryKey: a, abortKey: o, offline: s, scope: c } = t, l = U(a, c), u = U(o, c), { adapter: d, requestManager: f, cache: p, appManager: m } = this.client, h = ln(e.retries, r), g = !m.isOnline && s, _ = this.hasRunningRequest(l, n), v = e.stopped;
|
|
1907
|
+
if (g || _ || v) return this.logger.warning({
|
|
1908
|
+
title: "Unable to perform request",
|
|
1909
|
+
type: "system",
|
|
1910
|
+
extra: {
|
|
1911
|
+
isOffline: g,
|
|
1912
|
+
isAlreadyRunning: _,
|
|
1913
|
+
isStopped: v
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
let y = this.addRunningRequest(l, n, t);
|
|
1917
|
+
f.events.emitLoading({
|
|
1918
|
+
request: t,
|
|
1919
|
+
requestId: n,
|
|
1920
|
+
loading: !0,
|
|
1921
|
+
isRetry: !!e.retries,
|
|
1922
|
+
isOffline: g
|
|
1923
|
+
}), this.incrementQueueRequestCount(l), f.addAbortController(u, n);
|
|
1924
|
+
let b = await d.fetch(t, n);
|
|
1925
|
+
e.resolved = !0, f.removeAbortController(u, n);
|
|
1926
|
+
let x = !m.isOnline, S = H("abort").message === b.error?.message, C = !this.hasRunningRequest(l, n) || S;
|
|
1927
|
+
this.deleteRunningRequest(l, n);
|
|
1928
|
+
let w = b.success || !h || !t.retryOnError || t.retryOnError(b), T = !b.success && h && w && !C && !x, E = {
|
|
1929
|
+
isCanceled: C,
|
|
1930
|
+
isOffline: x,
|
|
1931
|
+
retries: e.retries,
|
|
1932
|
+
willRetry: T,
|
|
1933
|
+
addedTimestamp: e.timestamp,
|
|
1934
|
+
triggerTimestamp: y.timestamp,
|
|
1935
|
+
requestTimestamp: b.requestTimestamp,
|
|
1936
|
+
responseTimestamp: b.responseTimestamp
|
|
1937
|
+
};
|
|
1938
|
+
if (f.events.emitResponse({
|
|
1939
|
+
request: t,
|
|
1940
|
+
requestId: n,
|
|
1941
|
+
response: b,
|
|
1942
|
+
details: E
|
|
1943
|
+
}), f.events.emitLoading({
|
|
1944
|
+
request: t,
|
|
1945
|
+
requestId: n,
|
|
1946
|
+
loading: !1,
|
|
1947
|
+
isRetry: !!e.retries,
|
|
1948
|
+
isOffline: g
|
|
1949
|
+
}), p.set(t, {
|
|
1950
|
+
...b,
|
|
1951
|
+
...E
|
|
1952
|
+
}), this.logger.debug({
|
|
1953
|
+
title: "Dispatcher processing response",
|
|
1954
|
+
type: "system",
|
|
1955
|
+
extra: {
|
|
1956
|
+
requestId: n,
|
|
1957
|
+
request: t,
|
|
1958
|
+
response: b,
|
|
1959
|
+
details: E
|
|
1960
|
+
}
|
|
1961
|
+
}), C) {
|
|
1962
|
+
let e = this.getQueue(l), r = e.requests.find((e) => e.requestId === n);
|
|
1963
|
+
return !e.stopped && !r?.stopped ? (this.logger.debug({
|
|
1964
|
+
title: "Request paused",
|
|
1965
|
+
type: "system",
|
|
1966
|
+
extra: {
|
|
1967
|
+
response: b,
|
|
1968
|
+
requestDetails: E,
|
|
1969
|
+
request: t
|
|
1970
|
+
}
|
|
1971
|
+
}), this.delete(l, n, u)) : this.logger.debug({
|
|
1972
|
+
title: "Request canceled",
|
|
1973
|
+
type: "system",
|
|
1974
|
+
extra: {
|
|
1975
|
+
response: b,
|
|
1976
|
+
requestDetails: E,
|
|
1977
|
+
request: t
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
if (!b.success && x) return s ? this.logger.debug({
|
|
1982
|
+
title: "Awaiting for network restoration",
|
|
1983
|
+
type: "system",
|
|
1984
|
+
extra: {
|
|
1985
|
+
response: b,
|
|
1986
|
+
requestDetails: E,
|
|
1987
|
+
request: t
|
|
1988
|
+
}
|
|
1989
|
+
}) : (this.logger.warning({
|
|
1990
|
+
title: "Removing non-offline request",
|
|
1991
|
+
type: "system",
|
|
1992
|
+
extra: {
|
|
1993
|
+
response: b,
|
|
1994
|
+
requestDetails: E,
|
|
1995
|
+
request: t
|
|
1996
|
+
}
|
|
1997
|
+
}), this.delete(l, n, u));
|
|
1998
|
+
if (b.success) return this.delete(l, n, u), this.logger.debug({
|
|
1999
|
+
title: "Successful response, removing request from queue.",
|
|
2000
|
+
type: "system",
|
|
2001
|
+
extra: {
|
|
2002
|
+
response: b,
|
|
2003
|
+
requestDetails: E,
|
|
2004
|
+
request: t
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
T ? (this.logger.debug({
|
|
2008
|
+
title: "Waiting for retry",
|
|
2009
|
+
type: "system",
|
|
2010
|
+
extra: {
|
|
2011
|
+
response: b,
|
|
2012
|
+
requestDetails: E,
|
|
2013
|
+
request: t
|
|
2014
|
+
}
|
|
2015
|
+
}), setTimeout(() => {
|
|
2016
|
+
this.logger.warning({
|
|
2017
|
+
title: "Error response, performing retry",
|
|
2018
|
+
type: "request",
|
|
2019
|
+
extra: {
|
|
2020
|
+
response: b,
|
|
2021
|
+
requestDetails: E,
|
|
2022
|
+
request: t,
|
|
2023
|
+
requestId: n
|
|
2024
|
+
}
|
|
2025
|
+
}), this.performRequest({
|
|
2026
|
+
...e,
|
|
2027
|
+
retries: e.retries + 1
|
|
2028
|
+
});
|
|
2029
|
+
}, i || 0)) : (t.retry && this.logger.error({
|
|
2030
|
+
title: "All retries have been used. Removing request from queue.",
|
|
2031
|
+
type: "request",
|
|
2032
|
+
extra: {
|
|
2033
|
+
response: b,
|
|
2034
|
+
requestDetails: E,
|
|
2035
|
+
request: t,
|
|
2036
|
+
requestId: n
|
|
2037
|
+
}
|
|
2038
|
+
}), this.delete(l, n, u));
|
|
2039
|
+
};
|
|
2040
|
+
}, nn = () => "drained-event", rn = (e) => `${e}-drained-event`, an = () => "status-event", on = (e) => `${e}-status-event`, sn = () => "change-event", cn = (e) => `${e}-change-event`, ln = (e, t) => !!(t && e < t), un = (e, t) => e.deduplicateTime ? +/* @__PURE__ */ new Date() - t.timestamp <= e.deduplicateTime : !0, dn = (e, t) => {
|
|
2041
|
+
let { queued: n, cancelable: r, deduplicate: i } = e, a = t ? un(e, t) : !1;
|
|
2042
|
+
return n ? K.ONE_BY_ONE : r ? K.PREVIOUS_CANCELED : a && i ? K.DEDUPLICATED : K.ALL_AT_ONCE;
|
|
2043
|
+
};
|
|
2044
|
+
function fn(e) {
|
|
2045
|
+
return e === "client" || e === "server" ? e : typeof window < "u" && typeof document < "u" ? "client" : "server";
|
|
2046
|
+
}
|
|
2047
|
+
var pn = async (e, t) => {
|
|
2048
|
+
let n = t;
|
|
2049
|
+
if (!t.requestOptions.disableRequestInterceptors) {
|
|
2050
|
+
for (let r of e) if (n = await r(t), !n) throw Error("Request modifier must return request");
|
|
2051
|
+
}
|
|
2052
|
+
return n;
|
|
2053
|
+
}, mn = async (e, t, n) => {
|
|
2054
|
+
let r = t;
|
|
2055
|
+
if (!n.requestOptions.disableResponseInterceptors) {
|
|
2056
|
+
for (let i of e) if (r = await i(t, n), !r) throw Error("Response modifier must return data");
|
|
2057
|
+
}
|
|
2058
|
+
return r;
|
|
2059
|
+
}, hn = class {
|
|
2060
|
+
url;
|
|
2061
|
+
mode;
|
|
2062
|
+
debug;
|
|
2063
|
+
unstable_onErrorCallbacks = [];
|
|
2064
|
+
unstable_onSuccessCallbacks = [];
|
|
2065
|
+
unstable_onResponseCallbacks = [];
|
|
2066
|
+
unstable_onAuthCallbacks = [];
|
|
2067
|
+
unstable_onRequestCallbacks = [];
|
|
2068
|
+
loggerManager = new rt();
|
|
2069
|
+
requestManager = new Ee();
|
|
2070
|
+
appManager;
|
|
2071
|
+
adapter;
|
|
2072
|
+
cache;
|
|
2073
|
+
fetchDispatcher;
|
|
2074
|
+
submitDispatcher;
|
|
2075
|
+
isMockerEnabled = !0;
|
|
2076
|
+
plugins = [];
|
|
2077
|
+
unstable_abortKeyMapper = wt;
|
|
2078
|
+
unstable_cacheKeyMapper = Tt;
|
|
2079
|
+
unstable_queryKeyMapper = Tt;
|
|
2080
|
+
unstable_requestIdMapper = ge;
|
|
2081
|
+
logger = this.loggerManager.initialize(this, "Client");
|
|
2082
|
+
constructor(e) {
|
|
2083
|
+
this.options = e;
|
|
2084
|
+
let { url: t, appManager: n, cache: r, fetchDispatcher: i, submitDispatcher: a, mode: o } = this.options;
|
|
2085
|
+
this.url = t, this.mode = fn(o), this.adapter = Wt(), this.appManager = n?.() || new be(), this.cache = r?.() || new Gt(), this.fetchDispatcher = i?.() || new tn(), this.submitDispatcher = a?.() || new tn(), this.adapter.initialize(this), this.appManager.initialize(), this.cache.initialize(this), this.fetchDispatcher.initialize(this), this.submitDispatcher.initialize(this);
|
|
2086
|
+
}
|
|
2087
|
+
setDebug = (e) => (this.debug = e, this);
|
|
2088
|
+
setLogLevel = (e) => (this.loggerManager.setSeverity(e), this);
|
|
2089
|
+
setLogger = (e) => (this.loggerManager = e(this), this.loggerManager.initialize(this, "Client"), this);
|
|
2090
|
+
setEnableGlobalMocking = (e) => (this.isMockerEnabled = e, this);
|
|
2091
|
+
setAdapter = (e) => (this.adapter = e, this.adapter.initialize(this), this);
|
|
2092
|
+
onAuth = (e) => (this.unstable_onAuthCallbacks.push(e), this);
|
|
2093
|
+
removeOnAuthInterceptors = (e) => (this.unstable_onAuthCallbacks = this.unstable_onAuthCallbacks.filter((t) => !e.includes(t)), this);
|
|
2094
|
+
onError = (e) => (this.unstable_onErrorCallbacks.push(e), this);
|
|
2095
|
+
removeOnErrorInterceptors = (e) => (this.unstable_onErrorCallbacks = this.unstable_onErrorCallbacks.filter((t) => !e.includes(t)), this);
|
|
2096
|
+
onSuccess = (e) => (this.unstable_onSuccessCallbacks.push(e), this);
|
|
2097
|
+
removeOnSuccessInterceptors = (e) => (this.unstable_onSuccessCallbacks = this.unstable_onSuccessCallbacks.filter((t) => !e.includes(t)), this);
|
|
2098
|
+
onRequest = (e) => (this.unstable_onRequestCallbacks.push(e), this);
|
|
2099
|
+
removeOnRequestInterceptors = (e) => (this.unstable_onRequestCallbacks = this.unstable_onRequestCallbacks.filter((t) => !e.includes(t)), this);
|
|
2100
|
+
onResponse = (e) => (this.unstable_onResponseCallbacks.push(e), this);
|
|
2101
|
+
removeOnResponseInterceptors = (e) => (this.unstable_onResponseCallbacks = this.unstable_onResponseCallbacks.filter((t) => !e.includes(t)), this);
|
|
2102
|
+
addPlugin = (e) => (this.plugins.push(e), e.initialize(this), e.trigger("onMount", { client: this }), this);
|
|
2103
|
+
removePlugin = (e) => {
|
|
2104
|
+
let t = this.plugins.length;
|
|
2105
|
+
return this.plugins = this.plugins.filter((t) => t !== e), this.plugins.length !== t && e.trigger("onUnmount", { client: this }), this;
|
|
2106
|
+
};
|
|
2107
|
+
triggerPlugins = (e, t) => (this.plugins.length && this.plugins.forEach((n) => {
|
|
2108
|
+
n.trigger(e, t);
|
|
2109
|
+
}), this);
|
|
2110
|
+
setAbortKeyMapper = (e) => (this.unstable_abortKeyMapper = e, this);
|
|
2111
|
+
setCacheKeyMapper = (e) => (this.unstable_cacheKeyMapper = e, this);
|
|
2112
|
+
setQueryKeyMapper = (e) => (this.unstable_queryKeyMapper = e, this);
|
|
2113
|
+
setRequestIdMapper = (e) => (this.unstable_requestIdMapper = e, this);
|
|
2114
|
+
unstable_modifyAuth = async (e) => pn(this.unstable_onAuthCallbacks, e);
|
|
2115
|
+
unstable_modifyRequest = async (e) => pn(this.unstable_onRequestCallbacks, e);
|
|
2116
|
+
unstable_modifyErrorResponse = async (e, t) => mn(this.unstable_onErrorCallbacks, e, t);
|
|
2117
|
+
unstable_modifySuccessResponse = async (e, t) => mn(this.unstable_onSuccessCallbacks, e, t);
|
|
2118
|
+
unstable_modifyResponse = async (e, t) => mn(this.unstable_onResponseCallbacks, e, t);
|
|
2119
|
+
fromJSON = (e) => At.fromJSON(this, e);
|
|
2120
|
+
clear = () => {
|
|
2121
|
+
let { appManager: e, cache: t, fetchDispatcher: n, submitDispatcher: r } = this.options;
|
|
2122
|
+
this.requestManager.abortControllers.clear(), this.fetchDispatcher.clear(), this.submitDispatcher.clear(), this.cache.clear(), this.requestManager.emitter.removeAllListeners(), this.fetchDispatcher.emitter.removeAllListeners(), this.submitDispatcher.emitter.removeAllListeners(), this.cache.emitter.removeAllListeners(), this.cache = t?.() || new Gt(), this.appManager = e?.() || new be(), this.fetchDispatcher = n?.() || new tn(), this.submitDispatcher = r?.() || new tn(), this.appManager.initialize(), this.cache.initialize(this), this.fetchDispatcher.initialize(this), this.submitDispatcher.initialize(this);
|
|
2123
|
+
};
|
|
2124
|
+
hydrate = (e, t) => {
|
|
2125
|
+
e?.forEach((e) => {
|
|
2126
|
+
if (!e) return;
|
|
2127
|
+
let { cacheKey: n, scope: r, response: i, ...a } = e, o = {
|
|
2128
|
+
cache: !0,
|
|
2129
|
+
override: !0
|
|
2130
|
+
}, s = typeof t == "function" ? {
|
|
2131
|
+
...o,
|
|
2132
|
+
...a,
|
|
2133
|
+
...t(e)
|
|
2134
|
+
} : {
|
|
2135
|
+
...o,
|
|
2136
|
+
...a,
|
|
2137
|
+
...t
|
|
2138
|
+
};
|
|
2139
|
+
if (!s.override && this.cache.get(U(n, r))) return;
|
|
2140
|
+
let c = It(i);
|
|
2141
|
+
this.cache.set({
|
|
2142
|
+
...s,
|
|
2143
|
+
cacheKey: n,
|
|
2144
|
+
scope: r
|
|
2145
|
+
}, c);
|
|
2146
|
+
});
|
|
2147
|
+
};
|
|
2148
|
+
createRequest = (e) => (e) => {
|
|
2149
|
+
let t = this.adapter.unstable_endpointMapper(e.endpoint), n = {
|
|
2150
|
+
...e,
|
|
2151
|
+
endpoint: String(t)
|
|
2152
|
+
}, r = new At(this, n);
|
|
2153
|
+
return this.plugins.forEach((e) => e.trigger("onRequestCreate", { request: r })), r;
|
|
2154
|
+
};
|
|
2155
|
+
}, gn = {
|
|
2156
|
+
strict: !0,
|
|
2157
|
+
encode: !0,
|
|
2158
|
+
arrayFormat: "bracket",
|
|
2159
|
+
arraySeparator: "bracket",
|
|
2160
|
+
sort: !1,
|
|
2161
|
+
skipNull: !0,
|
|
2162
|
+
skipEmptyString: !0
|
|
2163
|
+
};
|
|
2164
|
+
function _n(e) {
|
|
2165
|
+
return new hn(e);
|
|
2166
|
+
}
|
|
2167
|
+
//#endregion
|
|
2168
|
+
//#region src/core/client.ts
|
|
2169
|
+
var q = _n({ url: k() });
|
|
2170
|
+
//#endregion
|
|
2171
|
+
//#region src/core/license.ts
|
|
2172
|
+
function vn(e) {
|
|
2173
|
+
return `${q.url}/packs/${e}/checkout`;
|
|
2174
|
+
}
|
|
2175
|
+
//#endregion
|
|
2176
|
+
//#region src/core/auth-api.ts
|
|
2177
|
+
var yn = /* @__PURE__ */ _((/* @__PURE__ */ h(((e, t) => {
|
|
2178
|
+
t.exports = {};
|
|
2179
|
+
})))(), 1);
|
|
2180
|
+
async function bn(e) {
|
|
2181
|
+
let { data: t, success: n } = await q.createRequest()({
|
|
2182
|
+
endpoint: "/auth/cli/whoami",
|
|
2183
|
+
method: "GET"
|
|
2184
|
+
}).setHeaders({ Authorization: `Bearer ${e}` }).send();
|
|
2185
|
+
return !n || !t ? null : t;
|
|
2186
|
+
}
|
|
2187
|
+
async function xn(e) {
|
|
2188
|
+
await q.createRequest()({
|
|
2189
|
+
endpoint: "/auth/cli/token",
|
|
2190
|
+
method: "DELETE"
|
|
2191
|
+
}).setHeaders({ Authorization: `Bearer ${e}` }).send();
|
|
2192
|
+
}
|
|
2193
|
+
//#endregion
|
|
2194
|
+
//#region src/core/auth-store.ts
|
|
2195
|
+
var Sn = 1, Cn = "hype-stack", wn = "auth.json";
|
|
2196
|
+
function Tn() {
|
|
2197
|
+
let e = process.env.HYPE_STACK_CONFIG_DIR;
|
|
2198
|
+
if (e) return a.join(e, Cn);
|
|
2199
|
+
let t = i.homedir();
|
|
2200
|
+
if (process.platform === "win32") {
|
|
2201
|
+
let e = process.env.APPDATA ?? a.join(t, "AppData", "Roaming");
|
|
2202
|
+
return a.join(e, Cn);
|
|
2203
|
+
}
|
|
2204
|
+
if (process.platform === "darwin") return a.join(t, "Library", "Application Support", Cn);
|
|
2205
|
+
let n = process.env.XDG_CONFIG_HOME ?? a.join(t, ".config");
|
|
2206
|
+
return a.join(n, Cn);
|
|
2207
|
+
}
|
|
2208
|
+
function En() {
|
|
2209
|
+
return a.join(Tn(), wn);
|
|
2210
|
+
}
|
|
2211
|
+
async function Dn() {
|
|
2212
|
+
let e = await n.readFile(En(), "utf-8").catch(() => null);
|
|
2213
|
+
if (!e) return {
|
|
2214
|
+
version: Sn,
|
|
2215
|
+
tokens: {}
|
|
2216
|
+
};
|
|
2217
|
+
let t = JSON.parse(e);
|
|
2218
|
+
return {
|
|
2219
|
+
version: t.version ?? Sn,
|
|
2220
|
+
tokens: t.tokens ?? {}
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
async function On(e) {
|
|
2224
|
+
let t = Tn();
|
|
2225
|
+
await n.mkdir(t, { recursive: !0 }), await n.writeFile(En(), `${JSON.stringify(e, null, 2)}\n`, { mode: 384 });
|
|
2226
|
+
}
|
|
2227
|
+
async function kn(e) {
|
|
2228
|
+
return (await Dn()).tokens[e] ?? null;
|
|
2229
|
+
}
|
|
2230
|
+
async function An(e, t) {
|
|
2231
|
+
let n = await Dn();
|
|
2232
|
+
n.tokens[e] = t, await On(n);
|
|
2233
|
+
}
|
|
2234
|
+
async function jn(e) {
|
|
2235
|
+
let t = await Dn();
|
|
2236
|
+
e in t.tokens && (delete t.tokens[e], await On(t));
|
|
2237
|
+
}
|
|
2238
|
+
//#endregion
|
|
2239
|
+
//#region src/core/device.ts
|
|
2240
|
+
function Mn() {
|
|
2241
|
+
let e = i.networkInterfaces();
|
|
2242
|
+
for (let t of Object.values(e)) if (t) {
|
|
2243
|
+
for (let e of t) if (!e.internal && e.mac !== "00:00:00:00:00:00") return e.mac;
|
|
2244
|
+
}
|
|
2245
|
+
return "unknown";
|
|
2246
|
+
}
|
|
2247
|
+
function Nn() {
|
|
2248
|
+
let e = `${Mn()}:${i.hostname()}:${i.platform()}:${i.arch()}`;
|
|
2249
|
+
return (0, yn.createHash)("sha256").update(e).digest("hex").slice(0, 16);
|
|
2250
|
+
}
|
|
2251
|
+
function Pn() {
|
|
2252
|
+
return `hype-stack/${v} ${i.platform()} ${i.arch()} node/${process.version.slice(1)}`;
|
|
2253
|
+
}
|
|
2254
|
+
//#endregion
|
|
2255
|
+
//#region src/core/open-browser.ts
|
|
2256
|
+
function Fn(e) {
|
|
2257
|
+
o(process.platform === "darwin" ? `open "${e}"` : process.platform === "win32" ? `start "" "${e}"` : `xdg-open "${e}"`);
|
|
2258
|
+
}
|
|
2259
|
+
//#endregion
|
|
2260
|
+
//#region src/core/login.ts
|
|
2261
|
+
var In = 300 * 1e3, Ln = (e) => `<!doctype html><html><head><meta charset="utf-8"><title>Hype Stack CLI</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding-top:4rem;color:#111"><h2>${e}</h2><p>You can close this tab and return to your terminal.</p></body></html>`;
|
|
2262
|
+
async function Rn(e = {}) {
|
|
2263
|
+
let t = (0, yn.randomBytes)(16).toString("hex"), n = k(), r = yn.default.createServer(), i = await new Promise((n, i) => {
|
|
2264
|
+
let a = setTimeout(() => {
|
|
2265
|
+
o(), i(/* @__PURE__ */ Error("Login timed out. Run `hype-stack login` again."));
|
|
2266
|
+
}, In);
|
|
2267
|
+
function o() {
|
|
2268
|
+
clearTimeout(a), r.close();
|
|
2269
|
+
}
|
|
2270
|
+
r.on("request", (e, r) => {
|
|
2271
|
+
let a = new URL(e.url ?? "/", "http://127.0.0.1");
|
|
2272
|
+
if (a.pathname !== "/callback") {
|
|
2273
|
+
r.writeHead(404).end();
|
|
2274
|
+
return;
|
|
2275
|
+
}
|
|
2276
|
+
let s = (e) => {
|
|
2277
|
+
r.writeHead(200, { "Content-Type": "text/html" }), r.end(Ln(e));
|
|
2278
|
+
};
|
|
2279
|
+
if (a.searchParams.get("state") !== t) {
|
|
2280
|
+
s("Login failed."), o(), i(/* @__PURE__ */ Error("Login failed: state mismatch. Run `hype-stack login` again."));
|
|
2281
|
+
return;
|
|
2282
|
+
}
|
|
2283
|
+
let c = a.searchParams.get("token");
|
|
2284
|
+
if (a.searchParams.get("error") || !c) {
|
|
2285
|
+
s("Login cancelled."), o(), i(/* @__PURE__ */ Error("Login was cancelled in the browser."));
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
s("Logged in to Hype Stack."), o(), n(c);
|
|
2289
|
+
}), r.on("error", (e) => {
|
|
2290
|
+
o(), i(e);
|
|
2291
|
+
}), r.listen(0, "127.0.0.1", () => {
|
|
2292
|
+
let { port: n } = r.address(), i = encodeURIComponent(Pn()), a = `${te()}/cli/authorize?port=${n}&state=${t}&label=${i}`;
|
|
2293
|
+
e.onUrl?.(a), Fn(a);
|
|
2294
|
+
});
|
|
2295
|
+
}), a = await bn(i).catch(() => null), o = {
|
|
2296
|
+
token: i,
|
|
2297
|
+
email: a?.email,
|
|
2298
|
+
organizationId: a?.organizationId
|
|
2299
|
+
};
|
|
2300
|
+
return await An(n, o), o;
|
|
2301
|
+
}
|
|
2302
|
+
//#endregion
|
|
2303
|
+
//#region src/core/access-prompts.ts
|
|
2304
|
+
async function zn() {
|
|
2305
|
+
let e = await t.confirm({ message: "Log in to install packs your organization owns? (opens your browser)" });
|
|
2306
|
+
if (t.isCancel(e) || !e) return null;
|
|
2307
|
+
t.log.step("Opening your browser to sign in...");
|
|
2308
|
+
try {
|
|
2309
|
+
let e = await Rn({ onUrl: (e) => {
|
|
2310
|
+
t.log.info(`If your browser didn't open, visit:\n ${I.path(e)}`);
|
|
2311
|
+
} });
|
|
2312
|
+
return t.log.success(e.email ? `Logged in as ${e.email}` : "Logged in"), e.token;
|
|
2313
|
+
} catch (e) {
|
|
2314
|
+
return t.log.error(e instanceof Error ? e.message : String(e)), null;
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
async function Bn(e) {
|
|
2318
|
+
if (e.length === 0) return;
|
|
2319
|
+
t.note([
|
|
2320
|
+
"These packs need a purchase before they can be installed:",
|
|
2321
|
+
"",
|
|
2322
|
+
...e.map((e) => ` ${I.brand(e.displayName)} ${I.highlight(`$${e.price}`)}`)
|
|
2323
|
+
].join("\n"), "Locked Packs");
|
|
2324
|
+
let n = await t.confirm({ message: `Open the purchase ${e.length === 1 ? "page" : "pages"} in your browser?` });
|
|
2325
|
+
if (t.isCancel(n) || !n) {
|
|
2326
|
+
t.log.info(I.muted("Run 'hype-stack login' after purchasing, then 'hype-stack compose' again."));
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
2329
|
+
for (let t of e) Fn(vn(t.name));
|
|
2330
|
+
t.log.info([
|
|
2331
|
+
I.muted("After purchasing, run:"),
|
|
2332
|
+
` ${I.highlight("hype-stack login")} ${I.muted("Save your access")}`,
|
|
2333
|
+
` ${I.highlight("hype-stack compose")} ${I.muted("Install the packs")}`
|
|
2334
|
+
].join("\n"));
|
|
2335
|
+
}
|
|
2336
|
+
//#endregion
|
|
2337
|
+
//#region src/utils/exec.ts
|
|
2338
|
+
function J(e, t, n) {
|
|
2339
|
+
return new Promise((r, i) => {
|
|
2340
|
+
let a = s(e, t, {
|
|
2341
|
+
cwd: n.cwd,
|
|
2342
|
+
stdio: [
|
|
2343
|
+
"ignore",
|
|
2344
|
+
"pipe",
|
|
2345
|
+
"pipe"
|
|
2346
|
+
]
|
|
2347
|
+
}), o = "", c = "";
|
|
2348
|
+
a.stdout.on("data", (e) => {
|
|
2349
|
+
let t = e.toString();
|
|
2350
|
+
if (o += t, n.onData) {
|
|
2351
|
+
let e = t.split("\n").filter(Boolean);
|
|
2352
|
+
for (let t of e) n.onData(t);
|
|
2353
|
+
}
|
|
2354
|
+
}), a.stderr.on("data", (e) => {
|
|
2355
|
+
let t = e.toString();
|
|
2356
|
+
if (c += t, n.onData) {
|
|
2357
|
+
let e = t.split("\n").filter(Boolean);
|
|
2358
|
+
for (let t of e) n.onData(t);
|
|
2359
|
+
}
|
|
2360
|
+
}), a.on("error", i), a.on("close", (e) => {
|
|
2361
|
+
r({
|
|
2362
|
+
exitCode: e ?? 1,
|
|
2363
|
+
stdout: o,
|
|
2364
|
+
stderr: c
|
|
2365
|
+
});
|
|
2366
|
+
});
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
//#endregion
|
|
2370
|
+
//#region src/utils/fs.ts
|
|
2371
|
+
async function Y(e) {
|
|
2372
|
+
return (await n.stat(e).catch(() => null))?.isDirectory() ?? !1;
|
|
2373
|
+
}
|
|
2374
|
+
async function X(e) {
|
|
2375
|
+
return (await n.stat(e).catch(() => null))?.isFile() ?? !1;
|
|
2376
|
+
}
|
|
2377
|
+
async function Vn(e) {
|
|
2378
|
+
return (await n.readdir(e).catch(() => [])).length === 0;
|
|
2379
|
+
}
|
|
2380
|
+
async function Hn(e) {
|
|
2381
|
+
let t = await n.readFile(e, "utf-8").catch(() => null);
|
|
2382
|
+
return t ? JSON.parse(t) : null;
|
|
2383
|
+
}
|
|
2384
|
+
async function Un(e, t) {
|
|
2385
|
+
await n.writeFile(e, JSON.stringify(t, null, 2) + "\n", "utf-8");
|
|
2386
|
+
}
|
|
2387
|
+
async function Wn(e) {
|
|
2388
|
+
let t = {};
|
|
2389
|
+
if (!await Y(e)) return t;
|
|
2390
|
+
let r = await n.readdir(e, { withFileTypes: !0 });
|
|
2391
|
+
for (let n of r) n.isDirectory() && await X(a.join(e, n.name, "package.json")) && (t[n.name] = a.relative(a.dirname(e), a.join(e, n.name)));
|
|
2392
|
+
return t;
|
|
2393
|
+
}
|
|
2394
|
+
async function Gn(e) {
|
|
2395
|
+
await n.rm(e, {
|
|
2396
|
+
recursive: !0,
|
|
2397
|
+
force: !0
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
//#endregion
|
|
2401
|
+
//#region src/core/codegen.ts
|
|
2402
|
+
function Kn(e) {
|
|
2403
|
+
t.log.info(I.muted("Run database setup yourself when ready:")), t.note([
|
|
2404
|
+
`${I.command(`cd ${e}`)}`,
|
|
2405
|
+
`${I.command("pnpm exec prisma generate")} ${I.muted("(regenerate the Prisma client)")}`,
|
|
2406
|
+
`${I.command("pnpm exec prisma migrate dev")} ${I.muted("(create + apply tables for new packs)")}`
|
|
2407
|
+
].join("\n"), "Database Setup");
|
|
2408
|
+
}
|
|
2409
|
+
async function qn(e) {
|
|
2410
|
+
let { projectRoot: n, paths: r, skipPrompts: i, runCommand: o = J } = e, s = r.backend.root, c = a.join(n, s);
|
|
2411
|
+
if (!await X(a.join(c, "package.json"))) return;
|
|
2412
|
+
if (i) {
|
|
2413
|
+
Kn(s);
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
let l = await t.confirm({
|
|
2417
|
+
message: `Run database setup now? (${I.command("prisma generate")} + ${I.command("prisma migrate")})`,
|
|
2418
|
+
initialValue: !0
|
|
2419
|
+
});
|
|
2420
|
+
if (t.isCancel(l) || !l) {
|
|
2421
|
+
Kn(s);
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
let u = t.spinner();
|
|
2425
|
+
if (u.start("Generating Prisma client..."), (await o("pnpm", [
|
|
2426
|
+
"exec",
|
|
2427
|
+
"prisma",
|
|
2428
|
+
"generate"
|
|
2429
|
+
], { cwd: c })).exitCode !== 0) {
|
|
2430
|
+
u.stop(I.warning("Prisma client generation failed")), Kn(s);
|
|
2431
|
+
return;
|
|
2432
|
+
}
|
|
2433
|
+
u.stop(I.success("Prisma client generated"));
|
|
2434
|
+
let d = t.spinner();
|
|
2435
|
+
if (d.start("Applying database schema..."), (await o("pnpm", [
|
|
2436
|
+
"exec",
|
|
2437
|
+
"prisma",
|
|
2438
|
+
"migrate",
|
|
2439
|
+
"dev",
|
|
2440
|
+
"--name",
|
|
2441
|
+
"add-packs"
|
|
2442
|
+
], { cwd: c })).exitCode !== 0) {
|
|
2443
|
+
d.stop(I.warning("Database migration failed (is your database running?)")), Kn(s);
|
|
2444
|
+
return;
|
|
2445
|
+
}
|
|
2446
|
+
d.stop(I.success("Database schema applied"));
|
|
2447
|
+
}
|
|
2448
|
+
//#endregion
|
|
2449
|
+
//#region src/core/stack-config.ts
|
|
2450
|
+
async function Jn(e) {
|
|
2451
|
+
return Hn(a.join(e, b));
|
|
2452
|
+
}
|
|
2453
|
+
async function Yn(e) {
|
|
2454
|
+
return X(a.join(e, b));
|
|
2455
|
+
}
|
|
2456
|
+
async function Xn(e, t) {
|
|
2457
|
+
await Un(a.join(e, b), t);
|
|
2458
|
+
}
|
|
2459
|
+
async function Zn(e) {
|
|
2460
|
+
let t = a.join(e, "apps"), n = a.join(e, "packages"), [r, i] = await Promise.all([Wn(t), Wn(n)]);
|
|
2461
|
+
return {
|
|
2462
|
+
apps: r,
|
|
2463
|
+
packages: i
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
function Qn(e) {
|
|
2467
|
+
let t = e.apps.backend ?? "apps/backend", n = e.apps.frontend ?? "apps/frontend", r = e.packages.enums ?? "packages/enums";
|
|
2468
|
+
return {
|
|
2469
|
+
backend: {
|
|
2470
|
+
root: t,
|
|
2471
|
+
prisma: `${t}/prisma`,
|
|
2472
|
+
features: `${t}/src/features`,
|
|
2473
|
+
middleware: `${t}/src/middleware`,
|
|
2474
|
+
libs: `${t}/src/libs`,
|
|
2475
|
+
utils: `${t}/src/utils`,
|
|
2476
|
+
routes: `${t}/src/routes`
|
|
2477
|
+
},
|
|
2478
|
+
frontend: {
|
|
2479
|
+
root: n,
|
|
2480
|
+
features: `${n}/src/features`,
|
|
2481
|
+
components: `${n}/src/components`,
|
|
2482
|
+
layouts: `${n}/src/components/layouts`,
|
|
2483
|
+
hooks: `${n}/src/hooks`,
|
|
2484
|
+
utils: `${n}/src/lib`
|
|
2485
|
+
},
|
|
2486
|
+
enums: {
|
|
2487
|
+
root: r,
|
|
2488
|
+
src: `${r}/src`
|
|
2489
|
+
}
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
function $n(e, t) {
|
|
2493
|
+
return {
|
|
2494
|
+
$schema: re(),
|
|
2495
|
+
version: 1,
|
|
2496
|
+
name: e,
|
|
2497
|
+
apps: t.apps,
|
|
2498
|
+
packages: t.packages,
|
|
2499
|
+
paths: Qn(t),
|
|
2500
|
+
installedPacks: [],
|
|
2501
|
+
licenseKey: null
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
async function er(e) {
|
|
2505
|
+
let t = a.join(e, "package.json"), n = a.join(e, "apps"), [r, i] = await Promise.all([X(t), Y(n)]);
|
|
2506
|
+
return r && i;
|
|
2507
|
+
}
|
|
2508
|
+
function Z(e, t) {
|
|
2509
|
+
return e.replace(/\{\{(\w+)\.(\w+)\}\}/g, (n, r, i) => {
|
|
2510
|
+
let a = t[r];
|
|
2511
|
+
if (!a) throw Error(`Unknown app "${r}" in path template "${e}"`);
|
|
2512
|
+
let o = a[i];
|
|
2513
|
+
if (!o) throw Error(`Unknown path key "${i}" for app "${r}" in template "${e}"`);
|
|
2514
|
+
return o;
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
//#endregion
|
|
2518
|
+
//#region src/core/registry.ts
|
|
2519
|
+
async function tr(e) {
|
|
2520
|
+
let { data: t, error: n, status: r } = await q.createRequest()({
|
|
2521
|
+
endpoint: `/packs/${encodeURIComponent(e)}/manifest`,
|
|
2522
|
+
method: "GET"
|
|
2523
|
+
}).send();
|
|
2524
|
+
if (r === 404) throw Error(`Pack "${e}" not found in registry`);
|
|
2525
|
+
if (n || !t) throw Error(`Failed to load manifest for "${e}": ${String(n)}`);
|
|
2526
|
+
return t;
|
|
2527
|
+
}
|
|
2528
|
+
async function nr(e, t = {}) {
|
|
2529
|
+
let r = q.createRequest()({
|
|
2530
|
+
endpoint: `/packs/${encodeURIComponent(e)}/download`,
|
|
2531
|
+
method: "POST"
|
|
2532
|
+
}), o = {
|
|
2533
|
+
"X-Device-Id": Nn(),
|
|
2534
|
+
"X-Client-Info": Pn()
|
|
2535
|
+
};
|
|
2536
|
+
t.token && (o.Authorization = `Bearer ${t.token}`);
|
|
2537
|
+
let { data: s, error: c, success: l } = await r.setPayload({ key: t.licenseKey ?? void 0 }).setHeaders(o).send();
|
|
2538
|
+
if (!l || !s) throw Error(`Failed to download pack "${e}": ${String(c)}`);
|
|
2539
|
+
if (!s.ok) return {
|
|
2540
|
+
status: "denied",
|
|
2541
|
+
reason: s.reason,
|
|
2542
|
+
packs: s.packs ?? [],
|
|
2543
|
+
expiresAt: s.expiresAt ?? null
|
|
2544
|
+
};
|
|
2545
|
+
let u = await n.mkdtemp(a.join(i.tmpdir(), `hype-stack-pack-${e}-`));
|
|
2546
|
+
return await Promise.all(s.files.map(async (e) => {
|
|
2547
|
+
let t = a.join(u, ...e.path.split("/"));
|
|
2548
|
+
await n.mkdir(a.dirname(t), { recursive: !0 }), await n.writeFile(t, Buffer.from(e.content, "base64"));
|
|
2549
|
+
})), {
|
|
2550
|
+
status: "ok",
|
|
2551
|
+
packDir: u
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
function rr(e, t, n) {
|
|
2555
|
+
let r = Z(e, t);
|
|
2556
|
+
return a.resolve(n, r);
|
|
2557
|
+
}
|
|
2558
|
+
function ir(e, t) {
|
|
2559
|
+
return a.join(t, e);
|
|
2560
|
+
}
|
|
2561
|
+
var ar = q.createRequest()({
|
|
2562
|
+
endpoint: "/packs/list",
|
|
2563
|
+
method: "GET"
|
|
2564
|
+
});
|
|
2565
|
+
async function or() {
|
|
2566
|
+
let { data: e, error: t } = await ar.send();
|
|
2567
|
+
if (t || !e) throw Error(`Failed to fetch pack list: ${String(t)}`);
|
|
2568
|
+
return e.packs;
|
|
2569
|
+
}
|
|
2570
|
+
async function sr(e, t = {}) {
|
|
2571
|
+
if (e.length === 0) return {};
|
|
2572
|
+
let n = q.createRequest()({
|
|
2573
|
+
endpoint: "/packs/authorize",
|
|
2574
|
+
method: "POST"
|
|
2575
|
+
}), r = {};
|
|
2576
|
+
t.token && (r.Authorization = `Bearer ${t.token}`);
|
|
2577
|
+
let { data: i, error: a } = await n.setPayload({
|
|
2578
|
+
packs: e,
|
|
2579
|
+
key: t.key ?? void 0
|
|
2580
|
+
}).setHeaders(r).send();
|
|
2581
|
+
if (a || !i) throw Error(`Failed to authorize packs: ${String(a)}`);
|
|
2582
|
+
return i.results;
|
|
2583
|
+
}
|
|
2584
|
+
//#endregion
|
|
2585
|
+
//#region src/core/codemods.ts
|
|
2586
|
+
var cr = "@hype-stack/";
|
|
2587
|
+
async function lr(e, t, r) {
|
|
2588
|
+
let i = Z("{{backend.root}}", t), o = a.resolve(r, i, "src/config/env/env.config.ts"), s = a.resolve(r, i, ".env.example"), c = a.resolve(r, i, ".env.test");
|
|
2589
|
+
if (await X(o)) {
|
|
2590
|
+
let t = await n.readFile(o, "utf-8");
|
|
2591
|
+
for (let n of e) t.includes(`from "${n.from}"`) || (t = ur(t, n), t = dr(t, n));
|
|
2592
|
+
await n.writeFile(o, t, "utf-8");
|
|
2593
|
+
}
|
|
2594
|
+
if (await X(s)) {
|
|
2595
|
+
let t = await n.readFile(s, "utf-8");
|
|
2596
|
+
for (let n of e) t = fr(t, n);
|
|
2597
|
+
await n.writeFile(s, t, "utf-8");
|
|
2598
|
+
}
|
|
2599
|
+
if (await X(c)) {
|
|
2600
|
+
let t = await n.readFile(c, "utf-8");
|
|
2601
|
+
for (let n of e) t = pr(t, n);
|
|
2602
|
+
await n.writeFile(c, t, "utf-8");
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
function ur(e, t) {
|
|
2606
|
+
let n = `import { ${t.import} } from "${t.from}";`, r = e.lastIndexOf("import ");
|
|
2607
|
+
if (r === -1) return n + "\n" + e;
|
|
2608
|
+
let i = e.indexOf("\n", e.indexOf(";", r));
|
|
2609
|
+
return i === -1 ? e + "\n" + n : e.slice(0, i + 1) + n + "\n" + e.slice(i + 1);
|
|
2610
|
+
}
|
|
2611
|
+
function dr(e, t) {
|
|
2612
|
+
let n = ` ${t.import}.parse(process.env);`, r = e.match(/(\s*)envSchema\.parse\(process\.env\);/);
|
|
2613
|
+
if (!r) return e;
|
|
2614
|
+
let i = e.indexOf(r[0]), a = e.indexOf("\n", i);
|
|
2615
|
+
return a === -1 ? e + "\n" + n : e.slice(0, a + 1) + n + "\n" + e.slice(a + 1);
|
|
2616
|
+
}
|
|
2617
|
+
function fr(e, t) {
|
|
2618
|
+
for (let n of Object.keys(t.envExample.vars)) if (e.includes(`${n}=`)) return e;
|
|
2619
|
+
let n = [];
|
|
2620
|
+
n.push(""), n.push(`# ${t.envExample.section}`);
|
|
2621
|
+
for (let [e, r] of Object.entries(t.envExample.vars)) n.push(`${e}=${r}`);
|
|
2622
|
+
return e.trimEnd() + "\n" + n.join("\n") + "\n";
|
|
2623
|
+
}
|
|
2624
|
+
function pr(e, t) {
|
|
2625
|
+
for (let n of Object.keys(t.envTest)) if (e.includes(`${n}=`)) return e;
|
|
2626
|
+
let n = [""];
|
|
2627
|
+
for (let [e, r] of Object.entries(t.envTest)) n.push(`${e}=${r}`);
|
|
2628
|
+
return e.trimEnd() + "\n" + n.join("\n") + "\n";
|
|
2629
|
+
}
|
|
2630
|
+
async function mr(e, t, r) {
|
|
2631
|
+
let i = a.resolve(r, Z("{{backend.routes}}", t), "index.ts");
|
|
2632
|
+
if (!await X(i)) return;
|
|
2633
|
+
let o = await n.readFile(i, "utf-8");
|
|
2634
|
+
for (let t of e) o.includes(`from "${t.from}"`) || (o = hr(o, t), o = gr(o, t));
|
|
2635
|
+
await n.writeFile(i, o, "utf-8");
|
|
2636
|
+
}
|
|
2637
|
+
function hr(e, t) {
|
|
2638
|
+
let n = `import { ${t.import} } from "${t.from}";`, r = e.lastIndexOf("from \"./");
|
|
2639
|
+
if (r !== -1) {
|
|
2640
|
+
let t = e.indexOf("\n", r);
|
|
2641
|
+
return t === -1 ? e : e.slice(0, t + 1) + n + "\n" + e.slice(t + 1);
|
|
2642
|
+
}
|
|
2643
|
+
let i = e.indexOf("export const registerRoutes");
|
|
2644
|
+
return i === -1 ? e : e.slice(0, i) + n + "\n\n" + e.slice(i);
|
|
2645
|
+
}
|
|
2646
|
+
function gr(e, t) {
|
|
2647
|
+
let n = `.route("${t.prefix}", ${t.import})`, r = e.match(/\.route\([^)]+\);/g);
|
|
2648
|
+
if (r) {
|
|
2649
|
+
let t = r[r.length - 1], i = e.lastIndexOf(t) + t.length - 1;
|
|
2650
|
+
return e.slice(0, i) + "\n " + n + ";" + e.slice(i + 1);
|
|
2651
|
+
}
|
|
2652
|
+
return e.replace("return app;", `return app\n ${n};`);
|
|
2653
|
+
}
|
|
2654
|
+
async function _r(e, t, r) {
|
|
2655
|
+
let i = a.resolve(r, Z("{{backend.root}}", t), "src/context.ts");
|
|
2656
|
+
if (!await X(i)) return;
|
|
2657
|
+
let o = await n.readFile(i, "utf-8");
|
|
2658
|
+
for (let t of e) o.includes(`export let ${t.export}`) || (o = vr(o, t), o = yr(o, t), o = br(o, t), o = xr(o, t));
|
|
2659
|
+
await n.writeFile(i, o, "utf-8");
|
|
2660
|
+
}
|
|
2661
|
+
function vr(e, t) {
|
|
2662
|
+
let n = `import { ${t.typeImport.name} } from "${t.typeImport.from}";`;
|
|
2663
|
+
if (e.includes(`from "${t.typeImport.from}"`)) return e;
|
|
2664
|
+
let r = e.lastIndexOf("import ");
|
|
2665
|
+
if (r === -1) return n + "\n" + e;
|
|
2666
|
+
let i = e.indexOf("\n", e.indexOf(";", r));
|
|
2667
|
+
return i === -1 ? e + "\n" + n : e.slice(0, i + 1) + n + "\n" + e.slice(i + 1);
|
|
2668
|
+
}
|
|
2669
|
+
function yr(e, t) {
|
|
2670
|
+
let n = `export let ${t.export}: ${t.type};`, r = e.lastIndexOf("export let ");
|
|
2671
|
+
if (r === -1) {
|
|
2672
|
+
let t = e.indexOf("export const setupContext");
|
|
2673
|
+
return t === -1 ? e + "\n" + n + "\n" : e.slice(0, t) + n + "\n\n" + e.slice(t);
|
|
2674
|
+
}
|
|
2675
|
+
let i = e.indexOf("\n", r);
|
|
2676
|
+
return i === -1 ? e + "\n" + n : e.slice(0, i + 1) + n + "\n" + e.slice(i + 1);
|
|
2677
|
+
}
|
|
2678
|
+
function br(e, t) {
|
|
2679
|
+
let n = ` ${t.export} = ${t.init};`, r = e.match(/export const setupContext\s*=\s*async\s*\([^)]*\)\s*=>\s*\{/);
|
|
2680
|
+
if (!r) return e;
|
|
2681
|
+
let i = e.indexOf("{", e.indexOf(r[0]));
|
|
2682
|
+
return i === -1 ? e : e.slice(0, i + 1) + "\n" + n + e.slice(i + 1);
|
|
2683
|
+
}
|
|
2684
|
+
function xr(e, t) {
|
|
2685
|
+
let n = ` ${t.export}: ${t.type};`, r = e.indexOf("export type ContextVariables = {");
|
|
2686
|
+
if (r === -1) return e;
|
|
2687
|
+
let i = e.indexOf("};", r);
|
|
2688
|
+
return i === -1 ? e : e.slice(0, i) + n + "\n" + e.slice(i);
|
|
2689
|
+
}
|
|
2690
|
+
async function Sr(e, t, r) {
|
|
2691
|
+
let i = a.resolve(r, Z("{{enums.src}}", t), "index.ts");
|
|
2692
|
+
if (!await X(i)) return;
|
|
2693
|
+
let o = await n.readFile(i, "utf-8");
|
|
2694
|
+
for (let t of e) o.includes(`from "${t.from}"`) || (o = Cr(o, t));
|
|
2695
|
+
await n.writeFile(i, o, "utf-8");
|
|
2696
|
+
}
|
|
2697
|
+
function Cr(e, t) {
|
|
2698
|
+
let n = `export * from "${t.from}";`, r = e.lastIndexOf("export * from");
|
|
2699
|
+
if (r !== -1) {
|
|
2700
|
+
let t = e.indexOf("\n", r);
|
|
2701
|
+
return t === -1 ? e + "\n" + n + "\n" : e.slice(0, t + 1) + n + "\n" + e.slice(t + 1);
|
|
2702
|
+
}
|
|
2703
|
+
return e.trim() === "" ? n + "\n" : e.trimEnd() + "\n" + n + "\n";
|
|
2704
|
+
}
|
|
2705
|
+
async function wr(e, t, r) {
|
|
2706
|
+
let i = Z("{{backend.root}}", t), o = a.resolve(r, i, "src/sockets/index.ts");
|
|
2707
|
+
if (!await X(o)) return;
|
|
2708
|
+
let s = await n.readFile(o, "utf-8");
|
|
2709
|
+
for (let t of e) s.includes(`from "${t.from}"`) || (s = Tr(s, t), s = Er(s, t));
|
|
2710
|
+
await X(a.resolve(r, i, "src/libs/websocket/ws-authenticate.ts")) && (s = Dr(s)), await n.writeFile(o, s, "utf-8");
|
|
2711
|
+
}
|
|
2712
|
+
function Tr(e, t) {
|
|
2713
|
+
let n = `import { ${t.import} } from "${t.from}";`, r = e.lastIndexOf("from \"./");
|
|
2714
|
+
if (r !== -1) {
|
|
2715
|
+
let t = e.indexOf("\n", r);
|
|
2716
|
+
return t === -1 ? e : e.slice(0, t + 1) + n + "\n" + e.slice(t + 1);
|
|
2717
|
+
}
|
|
2718
|
+
let i = e.indexOf("const sockets");
|
|
2719
|
+
return i === -1 ? e : e.slice(0, i) + n + "\n\n" + e.slice(i);
|
|
2720
|
+
}
|
|
2721
|
+
function Er(e, t) {
|
|
2722
|
+
let n = `.socket("${t.prefix}", ${t.import})`, r = e.match(/\.socket\([^)]+\);/g);
|
|
2723
|
+
if (r) {
|
|
2724
|
+
let t = r[r.length - 1], i = e.lastIndexOf(t) + t.length - 1;
|
|
2725
|
+
return e.slice(0, i) + "\n " + n + ";" + e.slice(i + 1);
|
|
2726
|
+
}
|
|
2727
|
+
return e.replace(/new SocketRouter\([^)]*\);/, (e) => `new SocketRouter(${e.slice(17, e.length - 2)})\n ${n};`);
|
|
2728
|
+
}
|
|
2729
|
+
function Dr(e) {
|
|
2730
|
+
if (e.includes("wsAuthenticate")) return e;
|
|
2731
|
+
let t = e.indexOf("from \"@backend/libs/websocket/socket-router\""), n = e;
|
|
2732
|
+
if (t !== -1) {
|
|
2733
|
+
let e = n.indexOf("\n", t);
|
|
2734
|
+
n = n.slice(0, e + 1) + "import { wsAuthenticate } from \"@backend/libs/websocket/ws-authenticate\";\n" + n.slice(e + 1);
|
|
2735
|
+
}
|
|
2736
|
+
return n.replace("new SocketRouter()", "new SocketRouter({ authenticate: wsAuthenticate })");
|
|
2737
|
+
}
|
|
2738
|
+
async function Or(e, t, r) {
|
|
2739
|
+
let i = a.resolve(r, Z("{{backend.utils}}", t), "frontend-url/frontend-url.ts");
|
|
2740
|
+
if (!await X(i)) return;
|
|
2741
|
+
let o = await n.readFile(i, "utf-8");
|
|
2742
|
+
for (let t of e) o.includes(`"${t.path}"`) || (o = kr(o, t));
|
|
2743
|
+
await n.writeFile(i, o, "utf-8");
|
|
2744
|
+
}
|
|
2745
|
+
function kr(e, t) {
|
|
2746
|
+
let n = ` "${t.path}": ${t.search};`, r = e.indexOf("type RouteDefinitions = {");
|
|
2747
|
+
if (r === -1) return e;
|
|
2748
|
+
let i = e.indexOf("};", r);
|
|
2749
|
+
return i === -1 ? e : e.slice(0, i) + n + "\n" + e.slice(i);
|
|
2750
|
+
}
|
|
2751
|
+
var Ar = "import { type LucideIcon } from \"lucide-react\";\n\n/* -------------------------------------------------------------------------------------------------\n * Types\n * -----------------------------------------------------------------------------------------------*/\n\nexport type NavItem = {\n label: string;\n icon: LucideIcon;\n to: string;\n params?: Record<string, string>;\n};\n\nexport type NavSection = {\n label: string;\n icon: LucideIcon;\n items: NavItem[];\n};\n\nexport type NavSectionLink = NavSection & { to: string; params?: Record<string, string> };\n\nexport type NavEntry = NavSection | NavSectionLink;\n\n/* -------------------------------------------------------------------------------------------------\n * Navigation\n * -----------------------------------------------------------------------------------------------*/\n\nexport const primaryNav: NavEntry[] = [];\n\nexport const secondaryNav: NavEntry[] = [];\n\nexport const tertiaryNav: NavEntry[] = [];\n\nexport const settingsNav: NavEntry[] = [];\n", jr = {
|
|
2752
|
+
primary: "primaryNav",
|
|
2753
|
+
secondary: "secondaryNav",
|
|
2754
|
+
tertiary: "tertiaryNav",
|
|
2755
|
+
settings: "settingsNav"
|
|
2756
|
+
};
|
|
2757
|
+
async function Mr(e, t, r) {
|
|
2758
|
+
let i = Z("{{frontend.root}}", t), o = a.resolve(r, i, "src/constants/nav.constants.ts"), s;
|
|
2759
|
+
await X(o) ? s = await n.readFile(o, "utf-8") : (await n.mkdir(a.dirname(o), { recursive: !0 }), s = Ar);
|
|
2760
|
+
for (let t of e) s.includes(`label: "${t.label}"`) || (s = Pr(s, t), s = Ir(s, t));
|
|
2761
|
+
await n.writeFile(o, s, "utf-8");
|
|
2762
|
+
}
|
|
2763
|
+
function Nr(e) {
|
|
2764
|
+
let t = [e.icon];
|
|
2765
|
+
if (e.items) for (let n of e.items) t.includes(n.icon) || t.push(n.icon);
|
|
2766
|
+
return t;
|
|
2767
|
+
}
|
|
2768
|
+
function Pr(e, t) {
|
|
2769
|
+
let n = Nr(t), r = e;
|
|
2770
|
+
for (let e of n) r = Fr(r, e);
|
|
2771
|
+
return r;
|
|
2772
|
+
}
|
|
2773
|
+
function Fr(e, t) {
|
|
2774
|
+
let n = e.match(/import \{([^}]+)\} from "lucide-react";/);
|
|
2775
|
+
if (!n) return e;
|
|
2776
|
+
let r = n[1].split(",").map((e) => e.trim()).filter(Boolean);
|
|
2777
|
+
if (r.some((e) => e === t)) return e;
|
|
2778
|
+
let i = r.findIndex((e) => e.startsWith("type "));
|
|
2779
|
+
return i === -1 ? r.push(t) : r.splice(i, 0, t), e.replace(n[0], `import { ${r.join(", ")} } from "lucide-react";`);
|
|
2780
|
+
}
|
|
2781
|
+
function Ir(e, t) {
|
|
2782
|
+
let n = jr[t.group];
|
|
2783
|
+
if (!n) return e;
|
|
2784
|
+
let r = Rr(t), i = RegExp(`export const ${n}: NavEntry\\[\\] = \\[`), a = e.match(i);
|
|
2785
|
+
if (!a) return e;
|
|
2786
|
+
let o = e.indexOf(a[0]) + a[0].length, s = Lr(e, o - 1);
|
|
2787
|
+
return s === -1 ? e : e.slice(o, s).trim() === "" ? e.slice(0, s) + "\n" + r + "\n" + e.slice(s) : e.slice(0, s) + r + "\n" + e.slice(s);
|
|
2788
|
+
}
|
|
2789
|
+
function Lr(e, t) {
|
|
2790
|
+
let n = 0;
|
|
2791
|
+
for (let r = t; r < e.length; r++) if (e[r] === "[") n++;
|
|
2792
|
+
else if (e[r] === "]" && (n--, n === 0)) return r;
|
|
2793
|
+
return -1;
|
|
2794
|
+
}
|
|
2795
|
+
function Rr(e) {
|
|
2796
|
+
let t = [];
|
|
2797
|
+
if (t.push(" {"), t.push(` label: "${e.label}",`), t.push(` icon: ${e.icon},`), e.to && t.push(` to: "${e.to}",`), e.params && t.push(` params: ${e.params},`), e.items && e.items.length > 0) {
|
|
2798
|
+
t.push(" items: [");
|
|
2799
|
+
for (let n of e.items) {
|
|
2800
|
+
let e = [
|
|
2801
|
+
`label: "${n.label}"`,
|
|
2802
|
+
`icon: ${n.icon}`,
|
|
2803
|
+
`to: "${n.to}"`
|
|
2804
|
+
];
|
|
2805
|
+
n.params && e.push(`params: ${n.params}`), t.push(` { ${e.join(", ")} },`);
|
|
2806
|
+
}
|
|
2807
|
+
t.push(" ],");
|
|
2808
|
+
} else t.push(" items: [],");
|
|
2809
|
+
return t.push(" },"), t.join("\n");
|
|
2810
|
+
}
|
|
2811
|
+
async function zr(e, t, r) {
|
|
2812
|
+
let i = Z("{{backend.features}}", t), o = a.resolve(r, i, "organizations/modules/setup-organization/steps/index.ts");
|
|
2813
|
+
if (!await X(o)) return;
|
|
2814
|
+
let s = await n.readFile(o, "utf-8");
|
|
2815
|
+
for (let t of e) s.includes(`from "${t.from}"`) || (s = Br(s, t), s = Vr(s, t));
|
|
2816
|
+
await n.writeFile(o, s, "utf-8");
|
|
2817
|
+
}
|
|
2818
|
+
function Br(e, t) {
|
|
2819
|
+
let n = `import { ${t.import} } from "${t.from}";`, r = e.lastIndexOf("import ");
|
|
2820
|
+
if (r !== -1) {
|
|
2821
|
+
let t = e.indexOf("\n", e.indexOf(";", r));
|
|
2822
|
+
return t === -1 ? e + "\n" + n : e.slice(0, t + 1) + n + "\n" + e.slice(t + 1);
|
|
2823
|
+
}
|
|
2824
|
+
return e.indexOf("type "), n + "\n\n" + e;
|
|
2825
|
+
}
|
|
2826
|
+
function Vr(e, t) {
|
|
2827
|
+
let n = ` { id: "${t.id}", execute: (ctx) => ${t.import}(ctx) },`, r = e.match(/export const steps:\s*Step\[\]\s*=\s*\[/);
|
|
2828
|
+
if (!r) return e;
|
|
2829
|
+
let i = e.indexOf(r[0]) + r[0].length, a = Hr(e, i - 1);
|
|
2830
|
+
return a === -1 ? e : e.slice(i, a).trim() === "" ? e.slice(0, a) + "\n" + n + "\n" + e.slice(a) : e.slice(0, a) + n + "\n" + e.slice(a);
|
|
2831
|
+
}
|
|
2832
|
+
function Hr(e, t) {
|
|
2833
|
+
let n = 0;
|
|
2834
|
+
for (let r = t; r < e.length; r++) if (e[r] === "[") n++;
|
|
2835
|
+
else if (e[r] === "]" && (n--, n === 0)) return r;
|
|
2836
|
+
return -1;
|
|
2837
|
+
}
|
|
2838
|
+
var Ur = "import { type ComponentType } from \"react\";\n\nexport type NavbarAction = {\n id: string;\n component: ComponentType;\n};\n\nexport const navbarActions: NavbarAction[] = [];\n";
|
|
2839
|
+
async function Wr(e, t, r) {
|
|
2840
|
+
let i = Z("{{frontend.root}}", t), o = a.resolve(r, i, "src/constants/navbar-actions.tsx"), s;
|
|
2841
|
+
await X(o) ? s = await n.readFile(o, "utf-8") : (await n.mkdir(a.dirname(o), { recursive: !0 }), s = Ur);
|
|
2842
|
+
for (let t of e) s.includes(`id: "${t.id}"`) || (s = Gr(s, t), s = Kr(s, t));
|
|
2843
|
+
await n.writeFile(o, s, "utf-8");
|
|
2844
|
+
}
|
|
2845
|
+
function Gr(e, t) {
|
|
2846
|
+
let n = `import { ${t.import} } from "${t.from}";`;
|
|
2847
|
+
if (e.includes(n)) return e;
|
|
2848
|
+
let r = e.lastIndexOf("import ");
|
|
2849
|
+
if (r === -1) return n + "\n" + e;
|
|
2850
|
+
let i = e.indexOf("\n", r);
|
|
2851
|
+
return i === -1 ? e + "\n" + n : e.slice(0, i + 1) + n + "\n" + e.slice(i + 1);
|
|
2852
|
+
}
|
|
2853
|
+
function Kr(e, t) {
|
|
2854
|
+
let n = ` { id: "${t.id}", component: ${t.import} },`, r = e.match(/export const navbarActions:\s*NavbarAction\[\]\s*=\s*\[/);
|
|
2855
|
+
if (!r) return e;
|
|
2856
|
+
let i = e.indexOf(r[0]) + r[0].length, a = qr(e, i - 1);
|
|
2857
|
+
return a === -1 ? e : e.slice(i, a).trim() === "" ? e.slice(0, a) + "\n" + n + "\n" + e.slice(a) : e.slice(0, a) + n + "\n" + e.slice(a);
|
|
2858
|
+
}
|
|
2859
|
+
function qr(e, t) {
|
|
2860
|
+
let n = 0;
|
|
2861
|
+
for (let r = t; r < e.length; r++) if (e[r] === "[") n++;
|
|
2862
|
+
else if (e[r] === "]" && (n--, n === 0)) return r;
|
|
2863
|
+
return -1;
|
|
2864
|
+
}
|
|
2865
|
+
var Jr = new Set([
|
|
2866
|
+
".ts",
|
|
2867
|
+
".tsx",
|
|
2868
|
+
".js",
|
|
2869
|
+
".jsx"
|
|
2870
|
+
]);
|
|
2871
|
+
async function Yr(e) {
|
|
2872
|
+
let { files: t, paths: r, projectRoot: i, projectName: o } = e;
|
|
2873
|
+
if (o === "hype-stack") return;
|
|
2874
|
+
let s = `@${o}/`;
|
|
2875
|
+
await Promise.all(t.map(async (e) => {
|
|
2876
|
+
let t = rr(e.target, r, i), o = await n.stat(t).catch(() => null);
|
|
2877
|
+
o?.isDirectory() ? await Xr(t, s) : o?.isFile() && Jr.has(a.extname(t)) && await Zr(t, s);
|
|
2878
|
+
}));
|
|
2879
|
+
}
|
|
2880
|
+
async function Xr(e, t) {
|
|
2881
|
+
let r = await n.readdir(e, { withFileTypes: !0 });
|
|
2882
|
+
await Promise.all(r.map(async (n) => {
|
|
2883
|
+
let r = a.join(e, n.name);
|
|
2884
|
+
n.isDirectory() ? await Xr(r, t) : n.isFile() && Jr.has(a.extname(n.name)) && await Zr(r, t);
|
|
2885
|
+
}));
|
|
2886
|
+
}
|
|
2887
|
+
async function Zr(e, t) {
|
|
2888
|
+
let r = await n.readFile(e, "utf-8");
|
|
2889
|
+
if (!r.includes(cr)) return;
|
|
2890
|
+
let i = r.replaceAll(cr, t);
|
|
2891
|
+
await n.writeFile(e, i, "utf-8");
|
|
2892
|
+
}
|
|
2893
|
+
//#endregion
|
|
2894
|
+
//#region src/core/installer.ts
|
|
2895
|
+
async function Qr(e, t) {
|
|
2896
|
+
if ((await n.stat(e)).isDirectory()) {
|
|
2897
|
+
await n.mkdir(t, { recursive: !0 });
|
|
2898
|
+
let r = await n.readdir(e, { withFileTypes: !0 });
|
|
2899
|
+
for (let n of r) await Qr(a.join(e, n.name), a.join(t, n.name));
|
|
2900
|
+
} else await n.mkdir(a.dirname(t), { recursive: !0 }), await n.copyFile(e, t);
|
|
2901
|
+
}
|
|
2902
|
+
async function $r(e) {
|
|
2903
|
+
let { file: t, packDir: n, paths: r, projectRoot: i } = e, a = ir(t.source, n), o = rr(t.target, r, i);
|
|
2904
|
+
return {
|
|
2905
|
+
sourcePath: a,
|
|
2906
|
+
targetPath: o,
|
|
2907
|
+
sourceExists: await X(a) || await Y(a),
|
|
2908
|
+
targetExists: await X(o) || await Y(o)
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
async function ei(e) {
|
|
2912
|
+
let { file: t, packDir: r, paths: i, projectRoot: a } = e, { sourcePath: o, targetPath: s, sourceExists: c, targetExists: l } = await $r({
|
|
2913
|
+
file: t,
|
|
2914
|
+
packDir: r,
|
|
2915
|
+
paths: i,
|
|
2916
|
+
projectRoot: a
|
|
2917
|
+
});
|
|
2918
|
+
if (!c) return `${t.source}: Source not found (${o})`;
|
|
2919
|
+
switch (t.strategy) {
|
|
2920
|
+
case "create":
|
|
2921
|
+
case "skip-if-exists": return null;
|
|
2922
|
+
case "merge": return !l || !t.marker || (await n.readFile(s, "utf-8")).includes(t.marker) ? null : `${t.target}: Marker "${t.marker}" not found`;
|
|
2923
|
+
default: return `${t.target}: Unknown strategy: ${String(t.strategy)}`;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
async function ti(e) {
|
|
2927
|
+
let { file: t, packDir: r, paths: i, projectRoot: a, force: o } = e, { sourcePath: s, targetPath: c, sourceExists: l, targetExists: u } = await $r({
|
|
2928
|
+
file: t,
|
|
2929
|
+
packDir: r,
|
|
2930
|
+
paths: i,
|
|
2931
|
+
projectRoot: a
|
|
2932
|
+
});
|
|
2933
|
+
if (!l) return {
|
|
2934
|
+
status: "error",
|
|
2935
|
+
path: t.source,
|
|
2936
|
+
reason: "Source not found"
|
|
2937
|
+
};
|
|
2938
|
+
switch (t.strategy) {
|
|
2939
|
+
case "create": return u && !o ? {
|
|
2940
|
+
status: "skipped",
|
|
2941
|
+
path: t.target,
|
|
2942
|
+
reason: "Already exists"
|
|
2943
|
+
} : (await Qr(s, c), {
|
|
2944
|
+
status: "installed",
|
|
2945
|
+
path: t.target
|
|
2946
|
+
});
|
|
2947
|
+
case "skip-if-exists": return u ? {
|
|
2948
|
+
status: "skipped",
|
|
2949
|
+
path: t.target,
|
|
2950
|
+
reason: "Already exists (skip-if-exists)"
|
|
2951
|
+
} : (await Qr(s, c), {
|
|
2952
|
+
status: "installed",
|
|
2953
|
+
path: t.target
|
|
2954
|
+
});
|
|
2955
|
+
case "merge": {
|
|
2956
|
+
if (!u) return await Qr(s, c), {
|
|
2957
|
+
status: "installed",
|
|
2958
|
+
path: t.target
|
|
2959
|
+
};
|
|
2960
|
+
let e = await n.readFile(s, "utf-8"), r = await n.readFile(c, "utf-8");
|
|
2961
|
+
if (t.marker) {
|
|
2962
|
+
let i = r.indexOf(t.marker);
|
|
2963
|
+
if (i === -1) return {
|
|
2964
|
+
status: "error",
|
|
2965
|
+
path: t.target,
|
|
2966
|
+
reason: `Marker "${t.marker}" not found`
|
|
2967
|
+
};
|
|
2968
|
+
let a = r.slice(0, i) + e + r.slice(i);
|
|
2969
|
+
await n.writeFile(c, a);
|
|
2970
|
+
} else {
|
|
2971
|
+
let t = r + "\n" + e;
|
|
2972
|
+
await n.writeFile(c, t);
|
|
2973
|
+
}
|
|
2974
|
+
return {
|
|
2975
|
+
status: "installed",
|
|
2976
|
+
path: t.target
|
|
2977
|
+
};
|
|
2978
|
+
}
|
|
2979
|
+
default: return {
|
|
2980
|
+
status: "error",
|
|
2981
|
+
path: t.target,
|
|
2982
|
+
reason: `Unknown strategy: ${String(t.strategy)}`
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
async function ni(e) {
|
|
2987
|
+
let { manifest: t, config: n, projectRoot: r, force: i, packDir: a } = e, o = n.paths;
|
|
2988
|
+
if (!o) throw Error("stack.json is missing 'paths' configuration. Run 'hype-stack init' to set it up.");
|
|
2989
|
+
let s = [];
|
|
2990
|
+
for (let e of t.files) {
|
|
2991
|
+
let t = await ei({
|
|
2992
|
+
file: e,
|
|
2993
|
+
packDir: a,
|
|
2994
|
+
paths: o,
|
|
2995
|
+
projectRoot: r,
|
|
2996
|
+
force: i
|
|
2997
|
+
});
|
|
2998
|
+
t && s.push(t);
|
|
2999
|
+
}
|
|
3000
|
+
return s;
|
|
3001
|
+
}
|
|
3002
|
+
async function ri(e) {
|
|
3003
|
+
let { manifest: t, config: n, projectRoot: r, force: i, packDir: a } = e, o = n.paths;
|
|
3004
|
+
if (!o) throw Error("stack.json is missing 'paths' configuration. Run 'hype-stack init' to set it up.");
|
|
3005
|
+
let s = {
|
|
3006
|
+
installed: [],
|
|
3007
|
+
skipped: [],
|
|
3008
|
+
errors: []
|
|
3009
|
+
};
|
|
3010
|
+
for (let e of t.files) {
|
|
3011
|
+
let t = await ti({
|
|
3012
|
+
file: e,
|
|
3013
|
+
packDir: a,
|
|
3014
|
+
paths: o,
|
|
3015
|
+
projectRoot: r,
|
|
3016
|
+
force: i
|
|
3017
|
+
});
|
|
3018
|
+
switch (t.status) {
|
|
3019
|
+
case "installed":
|
|
3020
|
+
s.installed.push(t.path);
|
|
3021
|
+
break;
|
|
3022
|
+
case "skipped":
|
|
3023
|
+
s.skipped.push(`${t.path} (${t.reason})`);
|
|
3024
|
+
break;
|
|
3025
|
+
case "error":
|
|
3026
|
+
s.errors.push(`${t.path}: ${t.reason}`);
|
|
3027
|
+
break;
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
return await Yr({
|
|
3031
|
+
files: t.files,
|
|
3032
|
+
paths: o,
|
|
3033
|
+
projectRoot: r,
|
|
3034
|
+
projectName: n.name
|
|
3035
|
+
}), t.env && t.env.length > 0 && await lr(t.env, o, r), t.routes && t.routes.length > 0 && await mr(t.routes, o, r), t.context && t.context.length > 0 && await _r(t.context, o, r), t.sockets && t.sockets.length > 0 && await wr(t.sockets, o, r), t.enums && t.enums.length > 0 && await Sr(t.enums, o, r), t.frontendRoutes && t.frontendRoutes.length > 0 && await Or(t.frontendRoutes, o, r), t.nav && t.nav.length > 0 && await Mr(t.nav, o, r), t.navbarActions && t.navbarActions.length > 0 && await Wr(t.navbarActions, o, r), t.onboardingSteps && t.onboardingSteps.length > 0 && await zr(t.onboardingSteps, o, r), s;
|
|
3036
|
+
}
|
|
3037
|
+
async function ii(e) {
|
|
3038
|
+
let { packs: t, config: n, projectRoot: r, force: i } = e, a = [];
|
|
3039
|
+
for (let e of t) {
|
|
3040
|
+
let t = await ni({
|
|
3041
|
+
manifest: e.manifest,
|
|
3042
|
+
config: n,
|
|
3043
|
+
projectRoot: r,
|
|
3044
|
+
force: i,
|
|
3045
|
+
packDir: e.packDir
|
|
3046
|
+
});
|
|
3047
|
+
for (let n of t) a.push(`${e.manifest.name}: ${n}`);
|
|
3048
|
+
}
|
|
3049
|
+
if (a.length > 0) return {
|
|
3050
|
+
installed: [],
|
|
3051
|
+
skipped: [],
|
|
3052
|
+
errors: a,
|
|
3053
|
+
appliedPacks: [],
|
|
3054
|
+
aborted: !0,
|
|
3055
|
+
config: n
|
|
3056
|
+
};
|
|
3057
|
+
let o = [], s = [], c = [], l = [], u = n;
|
|
3058
|
+
for (let e of t) {
|
|
3059
|
+
let t = await ri({
|
|
3060
|
+
manifest: e.manifest,
|
|
3061
|
+
config: u,
|
|
3062
|
+
projectRoot: r,
|
|
3063
|
+
force: i,
|
|
3064
|
+
packDir: e.packDir
|
|
3065
|
+
});
|
|
3066
|
+
o.push(...t.installed), s.push(...t.skipped), c.push(...t.errors), u = await ai(u, e.manifest.name, r), l.push(e.manifest.name);
|
|
3067
|
+
}
|
|
3068
|
+
return {
|
|
3069
|
+
installed: o,
|
|
3070
|
+
skipped: s,
|
|
3071
|
+
errors: c,
|
|
3072
|
+
appliedPacks: l,
|
|
3073
|
+
aborted: !1,
|
|
3074
|
+
config: u
|
|
3075
|
+
};
|
|
3076
|
+
}
|
|
3077
|
+
async function ai(e, t, n) {
|
|
3078
|
+
let r = {
|
|
3079
|
+
...e,
|
|
3080
|
+
installedPacks: [...e.installedPacks ?? [], t]
|
|
3081
|
+
};
|
|
3082
|
+
return await Xn(n, r), r;
|
|
3083
|
+
}
|
|
3084
|
+
//#endregion
|
|
3085
|
+
//#region src/core/npm-deps.ts
|
|
3086
|
+
function oi(e, t) {
|
|
3087
|
+
let n = [], r = [];
|
|
3088
|
+
if (!e) return {
|
|
3089
|
+
errors: n,
|
|
3090
|
+
operations: r
|
|
3091
|
+
};
|
|
3092
|
+
for (let [i, a] of Object.entries(e)) {
|
|
3093
|
+
let e = t[i];
|
|
3094
|
+
if (!e?.root) {
|
|
3095
|
+
n.push(`Unknown stack app "${i}" for dependencies_npm - no paths.${i}.root in stack.json.`);
|
|
3096
|
+
continue;
|
|
3097
|
+
}
|
|
3098
|
+
let o = [];
|
|
3099
|
+
for (let [e, t] of Object.entries(a)) {
|
|
3100
|
+
let r = t.trim();
|
|
3101
|
+
if (!r) {
|
|
3102
|
+
n.push(`Empty version range for npm package "${e}" under dependencies_npm.${i}.`);
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
o.push(`${e}@${r}`);
|
|
3106
|
+
}
|
|
3107
|
+
o.length > 0 && r.push({
|
|
3108
|
+
relativeDir: e.root,
|
|
3109
|
+
specs: o
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
return {
|
|
3113
|
+
errors: n,
|
|
3114
|
+
operations: r
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
function si(e) {
|
|
3118
|
+
let t = {};
|
|
3119
|
+
for (let n of e) if (n) for (let [e, r] of Object.entries(n)) t[e] = {
|
|
3120
|
+
...t[e],
|
|
3121
|
+
...r
|
|
3122
|
+
};
|
|
3123
|
+
return t;
|
|
3124
|
+
}
|
|
3125
|
+
async function ci(e, t, n = J) {
|
|
3126
|
+
let r = [];
|
|
3127
|
+
for (let i of e) {
|
|
3128
|
+
let e = a.join(t, i.relativeDir);
|
|
3129
|
+
if (!await X(a.join(e, "package.json"))) {
|
|
3130
|
+
r.push(`Cannot install npm dependencies under "${i.relativeDir}": package.json not found.`);
|
|
3131
|
+
continue;
|
|
3132
|
+
}
|
|
3133
|
+
let o = a.normalize(i.relativeDir), s;
|
|
3134
|
+
try {
|
|
3135
|
+
s = await n("pnpm", [
|
|
3136
|
+
"add",
|
|
3137
|
+
...i.specs,
|
|
3138
|
+
"--dir",
|
|
3139
|
+
o
|
|
3140
|
+
], { cwd: t });
|
|
3141
|
+
} catch (e) {
|
|
3142
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
3143
|
+
r.push(`pnpm add failed for "${i.relativeDir}": ${t}`);
|
|
3144
|
+
continue;
|
|
3145
|
+
}
|
|
3146
|
+
if (s.exitCode !== 0) {
|
|
3147
|
+
let e = s.stderr.trim() || s.stdout.trim() || `(exit ${String(s.exitCode)})`;
|
|
3148
|
+
r.push(`pnpm add failed for "${i.relativeDir}": ${e}`);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
return {
|
|
3152
|
+
ok: r.length === 0,
|
|
3153
|
+
errors: r
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
//#endregion
|
|
3157
|
+
//#region src/core/resolve.ts
|
|
3158
|
+
function li(e) {
|
|
3159
|
+
let t = /* @__PURE__ */ new Map();
|
|
3160
|
+
for (let n of e) t.set(n.name, {
|
|
3161
|
+
name: n.name,
|
|
3162
|
+
dependencies: n.dependencies
|
|
3163
|
+
});
|
|
3164
|
+
return t;
|
|
3165
|
+
}
|
|
3166
|
+
function ui(e, t, n = /* @__PURE__ */ new Set()) {
|
|
3167
|
+
let r = /* @__PURE__ */ new Set();
|
|
3168
|
+
function i(e) {
|
|
3169
|
+
if (n.has(e)) return [];
|
|
3170
|
+
if (r.has(e)) throw Error(`Circular dependency detected: ${e}`);
|
|
3171
|
+
r.add(e);
|
|
3172
|
+
let a = t.get(e);
|
|
3173
|
+
if (!a) throw Error(`Pack "${e}" not found in registry`);
|
|
3174
|
+
let o = [];
|
|
3175
|
+
for (let e of a.dependencies) o.push(...i(e));
|
|
3176
|
+
return n.add(e), o.push(e), o;
|
|
3177
|
+
}
|
|
3178
|
+
return i(e);
|
|
3179
|
+
}
|
|
3180
|
+
function di(e, t, n = []) {
|
|
3181
|
+
let r = new Set(n), i = new Set(n), a = [];
|
|
3182
|
+
for (let n of e) {
|
|
3183
|
+
let e = ui(n, t, new Set(i));
|
|
3184
|
+
for (let t of e) i.has(t) || (i.add(t), a.push(t));
|
|
3185
|
+
}
|
|
3186
|
+
return {
|
|
3187
|
+
order: a,
|
|
3188
|
+
alreadyInstalled: e.filter((e) => r.has(e))
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
function fi(e) {
|
|
3192
|
+
let { order: t, graph: n, isLocked: r, installed: i = [] } = e, a = new Set(i), o = /* @__PURE__ */ new Set();
|
|
3193
|
+
for (let e of t) {
|
|
3194
|
+
let t = n.get(e)?.dependencies.some((e) => !a.has(e) && o.has(e)) ?? !1;
|
|
3195
|
+
(r(e) || t) && o.add(e);
|
|
3196
|
+
}
|
|
3197
|
+
return {
|
|
3198
|
+
installable: t.filter((e) => !o.has(e)),
|
|
3199
|
+
blocked: t.filter((e) => o.has(e))
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
//#endregion
|
|
3203
|
+
//#region src/ui/banner.ts
|
|
3204
|
+
var pi = [
|
|
3205
|
+
" ██╗ ██╗ ██╗ ██╗ ██████╗ ███████╗",
|
|
3206
|
+
" ██║ ██║ ╚██╗ ██╔╝ ██╔══██╗ ██╔════╝",
|
|
3207
|
+
" ███████║ ╚████╔╝ ██████╔╝ █████╗ ",
|
|
3208
|
+
" ██╔══██║ ╚██╔╝ ██╔═══╝ ██╔══╝ ",
|
|
3209
|
+
" ██║ ██║ ██║ ██║ ███████╗",
|
|
3210
|
+
" ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝"
|
|
3211
|
+
], mi = [
|
|
3212
|
+
" ███████╗ ████████╗ █████╗ ██████╗ ██╗ ██╗",
|
|
3213
|
+
" ██╔════╝ ╚══██╔══╝ ██╔══██╗ ██╔════╝ ██║ ██╔╝",
|
|
3214
|
+
" ███████╗ ██║ ███████║ ██║ █████╔╝ ",
|
|
3215
|
+
" ╚════██║ ██║ ██╔══██║ ██║ ██╔═██╗ ",
|
|
3216
|
+
" ███████║ ██║ ██║ ██║ ╚██████╗ ██║ ██╗",
|
|
3217
|
+
" ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝"
|
|
3218
|
+
];
|
|
3219
|
+
function hi() {
|
|
3220
|
+
console.log();
|
|
3221
|
+
for (let e of pi) console.log(F.orange(e));
|
|
3222
|
+
for (let e of mi) console.log(F.skyBlue(e));
|
|
3223
|
+
console.log(), console.log(` ${L.spark} ${r.dim("v" + v)} ${r.dim("·")} ${oe("Ship web + desktop apps from one codebase")}`), console.log();
|
|
3224
|
+
}
|
|
3225
|
+
function gi() {
|
|
3226
|
+
console.log(), console.log(` ${L.bolt} ${F.orange("Hype")}${F.skyBlue("Stack")} ${r.dim("v" + v)}`), console.log();
|
|
3227
|
+
}
|
|
3228
|
+
//#endregion
|
|
3229
|
+
//#region src/ui/logger.ts
|
|
3230
|
+
function _i(e) {
|
|
3231
|
+
t.note(e.map((e) => `${L.arrow} ${e}`).join("\n"), "Next steps");
|
|
3232
|
+
}
|
|
3233
|
+
function Q() {
|
|
3234
|
+
t.cancel(I.muted("Operation cancelled.")), process.exit(0);
|
|
3235
|
+
}
|
|
3236
|
+
//#endregion
|
|
3237
|
+
//#region src/commands/init.ts
|
|
3238
|
+
async function vi(e) {
|
|
3239
|
+
let n = e.cwd ?? process.cwd(), r = e.silent ?? !1;
|
|
3240
|
+
if (r || (gi(), t.intro(I.brandBold("Initialize Hype Stack configuration"))), !await er(n)) {
|
|
3241
|
+
t.log.error(`This doesn't look like a Hype Stack project. ${I.muted("Expected apps/ directory and package.json")}`), t.outro(I.muted(`Run ${I.command("hype-stack create")} to scaffold a new project.`));
|
|
3242
|
+
return;
|
|
3243
|
+
}
|
|
3244
|
+
if (await Yn(n)) {
|
|
3245
|
+
let e = await Jn(n);
|
|
3246
|
+
if (e && !r) {
|
|
3247
|
+
t.log.info(`Found existing ${I.path("stack.json")} for project ${I.highlight(e.name)}`);
|
|
3248
|
+
let n = await t.confirm({
|
|
3249
|
+
message: "Overwrite existing configuration?",
|
|
3250
|
+
initialValue: !1
|
|
3251
|
+
});
|
|
3252
|
+
if (t.isCancel(n) || !n) {
|
|
3253
|
+
t.outro(I.muted("Keeping existing configuration."));
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
let i = await Zn(n);
|
|
3259
|
+
if (!r) {
|
|
3260
|
+
let e = Object.entries(i.apps), n = Object.entries(i.packages);
|
|
3261
|
+
if (e.length > 0) {
|
|
3262
|
+
t.log.info(I.bold("Detected apps:"));
|
|
3263
|
+
for (let [n, r] of e) t.log.message(` ${L.arrow} ${I.highlight(n)} ${I.muted(`→ ${r}`)}`);
|
|
3264
|
+
}
|
|
3265
|
+
if (n.length > 0) {
|
|
3266
|
+
t.log.info(I.bold("Detected packages:"));
|
|
3267
|
+
for (let [e, r] of n) t.log.message(` ${L.arrow} ${I.highlight(e)} ${I.muted(`→ ${r}`)}`);
|
|
3268
|
+
}
|
|
3269
|
+
e.length === 0 && n.length === 0 && t.log.warn("No apps or packages detected in the workspace.");
|
|
3270
|
+
}
|
|
3271
|
+
let o = (await Hn(a.join(n, "package.json")))?.name?.replace(/^@/, "").replace(/\/source$/, "") ?? "my-app", s = o;
|
|
3272
|
+
if (!r) {
|
|
3273
|
+
let e = await t.text({
|
|
3274
|
+
message: "Project name for stack.json?",
|
|
3275
|
+
placeholder: o,
|
|
3276
|
+
initialValue: o
|
|
3277
|
+
});
|
|
3278
|
+
t.isCancel(e) && Q(), s = e;
|
|
3279
|
+
}
|
|
3280
|
+
await Xn(n, $n(s, i)), r || (t.log.success(`${I.path("stack.json")} written successfully`), t.outro(I.muted("Your project is mapped and ready for Hype Stack CLI commands.")));
|
|
3281
|
+
}
|
|
3282
|
+
async function yi(e) {
|
|
3283
|
+
await Yn(e) || (t.log.warn(`No ${I.path("stack.json")} found. Let's set one up first.`), await vi({
|
|
3284
|
+
cwd: e,
|
|
3285
|
+
silent: !1
|
|
3286
|
+
}));
|
|
3287
|
+
}
|
|
3288
|
+
//#endregion
|
|
3289
|
+
//#region src/commands/compose.ts
|
|
3290
|
+
async function bi(e = {}) {
|
|
3291
|
+
let r = e.cwd ?? process.cwd();
|
|
3292
|
+
gi(), await yi(r), t.intro(I.brandBold("Compose your stack"));
|
|
3293
|
+
let i = await Jn(r);
|
|
3294
|
+
i || (t.cancel("Could not load stack.json. Run 'hype-stack init' first."), process.exit(1)), i.paths || (t.cancel("stack.json is missing `paths`. Run 'hype-stack init' again to regenerate it."), process.exit(1));
|
|
3295
|
+
let a = t.spinner();
|
|
3296
|
+
a.start("Loading packs...");
|
|
3297
|
+
let o;
|
|
3298
|
+
try {
|
|
3299
|
+
o = await or();
|
|
3300
|
+
} catch (e) {
|
|
3301
|
+
a.stop("Failed to load packs"), t.cancel(`Could not reach Hype Stack. Check your connection and try again.\n${xi(e)}`), process.exit(1);
|
|
3302
|
+
}
|
|
3303
|
+
a.stop("Packs loaded");
|
|
3304
|
+
let s = i.installedPacks ?? [], c = new Set(s), l = new Map(o.map((e) => [e.name, e])), u = e.licenseKey ?? process.env.HYPE_STACK_LICENSE_KEY ?? i.licenseKey ?? null, d = (await kn(k()))?.token ?? null, f = await Si(o, c, {
|
|
3305
|
+
token: d,
|
|
3306
|
+
key: u
|
|
3307
|
+
}), p = (e) => {
|
|
3308
|
+
let t = l.get(e);
|
|
3309
|
+
return !t || t.tier === "free" ? "free" : f[e]?.owned ? "owned" : "locked";
|
|
3310
|
+
}, m = (e) => !c.has(e) && p(e) === "locked", h = await wi({
|
|
3311
|
+
packs: o,
|
|
3312
|
+
installedSet: c,
|
|
3313
|
+
stateOf: p,
|
|
3314
|
+
options: e
|
|
3315
|
+
});
|
|
3316
|
+
if (h === null && (t.cancel("Cancelled."), process.exit(0)), h.length === 0) {
|
|
3317
|
+
t.outro(I.muted("No packs selected. Nothing to do."));
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
let g = li(o), _;
|
|
3321
|
+
try {
|
|
3322
|
+
_ = di(h, g, s);
|
|
3323
|
+
} catch (e) {
|
|
3324
|
+
t.cancel(xi(e)), process.exit(1);
|
|
3325
|
+
}
|
|
3326
|
+
if (_.order.length === 0) {
|
|
3327
|
+
t.note(`${_.alreadyInstalled.join(", ")} already installed.`, "Nothing to do"), t.outro(I.muted("Your selection is already part of the project."));
|
|
3328
|
+
return;
|
|
3329
|
+
}
|
|
3330
|
+
let v = fi({
|
|
3331
|
+
order: _.order,
|
|
3332
|
+
graph: g,
|
|
3333
|
+
isLocked: m,
|
|
3334
|
+
installed: s
|
|
3335
|
+
});
|
|
3336
|
+
if (v.blocked.length > 0 && !d && !u) {
|
|
3337
|
+
let e = await zn();
|
|
3338
|
+
e && (d = e, f = await Si(o, c, {
|
|
3339
|
+
token: d,
|
|
3340
|
+
key: u
|
|
3341
|
+
}), v = fi({
|
|
3342
|
+
order: _.order,
|
|
3343
|
+
graph: g,
|
|
3344
|
+
isLocked: m,
|
|
3345
|
+
installed: s
|
|
3346
|
+
}));
|
|
3347
|
+
}
|
|
3348
|
+
if (v.blocked.length > 0 && await Ti(v.blocked, m, l), v.installable.length === 0) {
|
|
3349
|
+
t.outro(I.muted("Nothing left to install once locked packs are removed."));
|
|
3350
|
+
return;
|
|
3351
|
+
}
|
|
3352
|
+
if (Ei(v.installable, l), !e.yes) {
|
|
3353
|
+
let e = await t.confirm({ message: `Install ${v.installable.length} pack${v.installable.length === 1 ? "" : "s"}?` });
|
|
3354
|
+
(t.isCancel(e) || !e) && (t.cancel("Installation cancelled."), process.exit(0));
|
|
3355
|
+
}
|
|
3356
|
+
a.start("Downloading packs...");
|
|
3357
|
+
let y;
|
|
3358
|
+
try {
|
|
3359
|
+
y = await Di(v.installable, {
|
|
3360
|
+
token: d,
|
|
3361
|
+
key: u
|
|
3362
|
+
});
|
|
3363
|
+
} catch (e) {
|
|
3364
|
+
a.stop("Download failed"), t.cancel(xi(e)), process.exit(1);
|
|
3365
|
+
}
|
|
3366
|
+
a.stop(`Downloaded ${y.length} pack${y.length === 1 ? "" : "s"}`);
|
|
3367
|
+
try {
|
|
3368
|
+
a.start("Installing pack files...");
|
|
3369
|
+
let n = await ii({
|
|
3370
|
+
packs: y,
|
|
3371
|
+
config: i,
|
|
3372
|
+
projectRoot: r,
|
|
3373
|
+
force: e.force ?? !1
|
|
3374
|
+
});
|
|
3375
|
+
if (n.aborted) {
|
|
3376
|
+
a.stop("Installation aborted");
|
|
3377
|
+
for (let e of n.errors) t.log.error(e);
|
|
3378
|
+
t.cancel("No files were written. Fix the errors above (or pass --force for existing files) and try again."), process.exit(1);
|
|
3379
|
+
}
|
|
3380
|
+
a.stop("Files installed"), n.installed.length > 0 && t.log.success(`${I.highlight(String(n.installed.length))} files installed`), n.skipped.length > 0 && t.log.warning(`${n.skipped.length} files skipped (use --force to overwrite)`);
|
|
3381
|
+
for (let e of n.errors) t.log.error(e);
|
|
3382
|
+
await Oi({
|
|
3383
|
+
prepared: y,
|
|
3384
|
+
paths: i.paths,
|
|
3385
|
+
cwd: r,
|
|
3386
|
+
spinner: a
|
|
3387
|
+
}), await qn({
|
|
3388
|
+
projectRoot: r,
|
|
3389
|
+
paths: i.paths,
|
|
3390
|
+
skipPrompts: e.yes ?? !1
|
|
3391
|
+
}), ki(y), t.outro(I.brand(`Installed ${n.appliedPacks.join(", ")}.`));
|
|
3392
|
+
} finally {
|
|
3393
|
+
await Promise.all(y.map((e) => n.rm(e.packDir, {
|
|
3394
|
+
recursive: !0,
|
|
3395
|
+
force: !0
|
|
3396
|
+
})));
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
function xi(e) {
|
|
3400
|
+
return e instanceof Error ? e.message : String(e);
|
|
3401
|
+
}
|
|
3402
|
+
async function Si(e, t, n) {
|
|
3403
|
+
let r = e.filter((e) => e.tier === "paid" && !t.has(e.name)).map((e) => e.name);
|
|
3404
|
+
return r.length === 0 ? {} : sr(r, n).catch(() => ({}));
|
|
3405
|
+
}
|
|
3406
|
+
function Ci(e, t) {
|
|
3407
|
+
return e === "free" ? I.success("free") : e === "owned" ? I.accent("owned") : `${I.highlight(`$${t}`)} ${I.muted("locked")}`;
|
|
3408
|
+
}
|
|
3409
|
+
async function wi(e) {
|
|
3410
|
+
let { packs: n, installedSet: r, stateOf: i, options: a } = e;
|
|
3411
|
+
if (a.packs && a.packs.length > 0) {
|
|
3412
|
+
let e = a.packs.filter((e) => !n.some((t) => t.name === e));
|
|
3413
|
+
return e.length > 0 && (t.cancel(`Unknown pack${e.length === 1 ? "" : "s"}: ${e.join(", ")}`), process.exit(1)), a.packs;
|
|
3414
|
+
}
|
|
3415
|
+
let o = n.filter((e) => r.has(e.name));
|
|
3416
|
+
o.length > 0 && t.note(o.map((e) => ` ${I.muted("✓")} ${e.displayName}`).join("\n"), "Already Installed");
|
|
3417
|
+
let s = n.filter((e) => !r.has(e.name));
|
|
3418
|
+
if (s.length === 0) return t.outro(I.muted("Every available pack is already installed.")), [];
|
|
3419
|
+
let c = await t.multiselect({
|
|
3420
|
+
message: "Select packs to add (free packs install without an account)",
|
|
3421
|
+
options: s.map((e) => {
|
|
3422
|
+
let t = i(e.name);
|
|
3423
|
+
return {
|
|
3424
|
+
value: e.name,
|
|
3425
|
+
label: `${e.displayName} ${Ci(t, e.price)}`,
|
|
3426
|
+
hint: e.description
|
|
3427
|
+
};
|
|
3428
|
+
}),
|
|
3429
|
+
required: !1
|
|
3430
|
+
});
|
|
3431
|
+
return t.isCancel(c) ? null : c;
|
|
3432
|
+
}
|
|
3433
|
+
async function Ti(e, n, r) {
|
|
3434
|
+
let i = e.filter((e) => n(e)), a = e.filter((e) => !n(e));
|
|
3435
|
+
a.length > 0 && t.log.warning(`Skipping ${a.join(", ")} because ${a.length === 1 ? "it depends" : "they depend"} on a pack you don't own yet.`), await Bn(i.map((e) => r.get(e)).filter((e) => e !== void 0).map((e) => ({
|
|
3436
|
+
name: e.name,
|
|
3437
|
+
displayName: e.displayName,
|
|
3438
|
+
price: e.price
|
|
3439
|
+
})));
|
|
3440
|
+
}
|
|
3441
|
+
function Ei(e, n) {
|
|
3442
|
+
let r = e.map((e, t) => {
|
|
3443
|
+
let r = n.get(e), i = r ? r.displayName : e;
|
|
3444
|
+
return ` ${I.muted(`${t + 1}.`)} ${I.brand(i)}`;
|
|
3445
|
+
});
|
|
3446
|
+
t.note([
|
|
3447
|
+
"These packs will be installed, in order:",
|
|
3448
|
+
"",
|
|
3449
|
+
...r
|
|
3450
|
+
].join("\n"), "Install Plan");
|
|
3451
|
+
}
|
|
3452
|
+
async function Di(e, t) {
|
|
3453
|
+
let n = [];
|
|
3454
|
+
for (let r of e) {
|
|
3455
|
+
let e = await tr(r), i = await nr(r, t);
|
|
3456
|
+
if (i.status === "denied") throw Error(`Access to "${r}" was denied (${i.reason}). Try 'hype-stack login' or check your license.`);
|
|
3457
|
+
n.push({
|
|
3458
|
+
manifest: e,
|
|
3459
|
+
packDir: i.packDir
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
return n;
|
|
3463
|
+
}
|
|
3464
|
+
async function Oi(e) {
|
|
3465
|
+
let { prepared: n, paths: r, cwd: i, spinner: a } = e, o = oi(si(n.map((e) => e.manifest.dependencies_npm)), r);
|
|
3466
|
+
if (o.errors.length > 0) {
|
|
3467
|
+
for (let e of o.errors) t.log.error(e);
|
|
3468
|
+
return;
|
|
3469
|
+
}
|
|
3470
|
+
if (o.operations.length === 0) return;
|
|
3471
|
+
a.start("Installing npm dependencies...");
|
|
3472
|
+
let s = await ci(o.operations, i);
|
|
3473
|
+
if (a.stop(s.ok ? "npm dependencies installed" : "npm dependency installation failed"), !s.ok) for (let e of s.errors) t.log.error(e);
|
|
3474
|
+
}
|
|
3475
|
+
function ki(e) {
|
|
3476
|
+
let n = e.flatMap((e) => e.manifest.postInstall ?? []), r = [...new Set(n)];
|
|
3477
|
+
r.length !== 0 && t.note(r.map((e) => ` ${I.muted("→")} ${e}`).join("\n"), "Next Steps");
|
|
3478
|
+
}
|
|
3479
|
+
//#endregion
|
|
3480
|
+
//#region src/core/clone.ts
|
|
3481
|
+
async function Ai(e) {
|
|
3482
|
+
let t = await c(y, {
|
|
3483
|
+
dir: e,
|
|
3484
|
+
force: !0
|
|
3485
|
+
});
|
|
3486
|
+
return {
|
|
3487
|
+
dir: t.dir,
|
|
3488
|
+
source: t.source
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
3491
|
+
//#endregion
|
|
3492
|
+
//#region src/core/editor-config.ts
|
|
3493
|
+
function ji(e) {
|
|
3494
|
+
let t = {
|
|
3495
|
+
globs: [],
|
|
3496
|
+
alwaysApply: !1
|
|
3497
|
+
};
|
|
3498
|
+
if (!e.startsWith("---")) return {
|
|
3499
|
+
frontmatter: t,
|
|
3500
|
+
content: e
|
|
3501
|
+
};
|
|
3502
|
+
let n = e.indexOf("---", 3);
|
|
3503
|
+
if (n === -1) return {
|
|
3504
|
+
frontmatter: t,
|
|
3505
|
+
content: e
|
|
3506
|
+
};
|
|
3507
|
+
let r = e.slice(3, n).trim(), i = e.slice(n + 3).trimStart(), a = r.split("\n"), o = 0;
|
|
3508
|
+
for (; o < a.length;) {
|
|
3509
|
+
let e = a[o].trim();
|
|
3510
|
+
if (e.startsWith("description:")) t.description = e.slice(12).trim();
|
|
3511
|
+
else if (e.startsWith("alwaysApply:")) t.alwaysApply = e.slice(12).trim() === "true";
|
|
3512
|
+
else if (e.startsWith("globs:")) {
|
|
3513
|
+
let n = e.slice(6).trim();
|
|
3514
|
+
if (n) t.globs = n.split(",").map((e) => e.trim()).filter(Boolean);
|
|
3515
|
+
else {
|
|
3516
|
+
let e = [];
|
|
3517
|
+
for (; o + 1 < a.length && a[o + 1].trim().startsWith("- ");) o++, e.push(a[o].trim().slice(2).trim());
|
|
3518
|
+
t.globs = e;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
o++;
|
|
3522
|
+
}
|
|
3523
|
+
return {
|
|
3524
|
+
frontmatter: t,
|
|
3525
|
+
content: i
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3528
|
+
function Mi(e) {
|
|
3529
|
+
return e.frontmatter.globs.length > 0 ? `---\npaths:\n${e.frontmatter.globs.map((e) => ` - "${e}"`).join("\n")}\n---\n\n${e.content}` : e.content;
|
|
3530
|
+
}
|
|
3531
|
+
function Ni(e) {
|
|
3532
|
+
let t;
|
|
3533
|
+
t = e.frontmatter.alwaysApply ? "always_on" : e.frontmatter.globs.length > 0 ? "glob" : "model_decision";
|
|
3534
|
+
let n = [`trigger: ${t}`];
|
|
3535
|
+
if (t === "glob") {
|
|
3536
|
+
let t = e.frontmatter.globs.map((e) => ` - "${e}"`).join("\n");
|
|
3537
|
+
n.push(`globs:\n${t}`);
|
|
3538
|
+
}
|
|
3539
|
+
return e.frontmatter.description && n.push(`description: ${e.frontmatter.description}`), `---\n${n.join("\n")}\n---\n\n${e.content}`;
|
|
3540
|
+
}
|
|
3541
|
+
function Pi(e) {
|
|
3542
|
+
return e.frontmatter.globs.length > 0 ? `---\napplyTo: "${e.frontmatter.globs.join(", ")}"\n---\n\n${e.content}` : e.content;
|
|
3543
|
+
}
|
|
3544
|
+
var Fi = {
|
|
3545
|
+
claude: {
|
|
3546
|
+
rulesDir: ".claude/rules",
|
|
3547
|
+
extension: ".md",
|
|
3548
|
+
convert: Mi
|
|
3549
|
+
},
|
|
3550
|
+
windsurf: {
|
|
3551
|
+
rulesDir: ".windsurf/rules",
|
|
3552
|
+
extension: ".md",
|
|
3553
|
+
convert: Ni
|
|
3554
|
+
},
|
|
3555
|
+
copilot: {
|
|
3556
|
+
rulesDir: ".github/instructions",
|
|
3557
|
+
extension: ".instructions.md",
|
|
3558
|
+
convert: Pi
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
async function Ii(e) {
|
|
3562
|
+
let t = a.join(e, D), r = (await n.readdir(t, { withFileTypes: !0 }).catch(() => [])).filter((e) => e.isFile() && e.name.endsWith(".mdc"));
|
|
3563
|
+
return await Promise.all(r.map(async (e) => {
|
|
3564
|
+
let r = a.join(t, e.name), { frontmatter: i, content: o } = ji(await n.readFile(r, "utf-8"));
|
|
3565
|
+
return {
|
|
3566
|
+
frontmatter: i,
|
|
3567
|
+
content: o,
|
|
3568
|
+
filename: e.name
|
|
3569
|
+
};
|
|
3570
|
+
}));
|
|
3571
|
+
}
|
|
3572
|
+
async function Li(e, t) {
|
|
3573
|
+
if (t === "cursor") return;
|
|
3574
|
+
let r = Fi[t], i = await Ii(e), o = a.join(e, r.rulesDir);
|
|
3575
|
+
await n.mkdir(o, { recursive: !0 }), await Promise.all(i.map((e) => {
|
|
3576
|
+
let t = r.convert(e), i = e.filename.replace(/\.mdc$/, r.extension);
|
|
3577
|
+
return n.writeFile(a.join(o, i), t, "utf-8");
|
|
3578
|
+
})), await Gn(a.join(e, O)), await Gn(a.join(e, ee));
|
|
3579
|
+
}
|
|
3580
|
+
//#endregion
|
|
3581
|
+
//#region src/core/env-files.ts
|
|
3582
|
+
var Ri = [
|
|
3583
|
+
"apps",
|
|
3584
|
+
"packages",
|
|
3585
|
+
"libs",
|
|
3586
|
+
"shared"
|
|
3587
|
+
];
|
|
3588
|
+
async function zi(e) {
|
|
3589
|
+
let t = await Bi(e);
|
|
3590
|
+
return (await Promise.all(t.map(async (t) => {
|
|
3591
|
+
let r = a.join(a.dirname(t), ".env");
|
|
3592
|
+
return await X(r) ? null : (await n.copyFile(t, r), a.relative(e, r));
|
|
3593
|
+
}))).filter((e) => e !== null).sort();
|
|
3594
|
+
}
|
|
3595
|
+
async function Bi(e) {
|
|
3596
|
+
let t = [a.join(e, ".env.example")], r = await Promise.all(Ri.map(async (t) => {
|
|
3597
|
+
let r = a.join(e, t);
|
|
3598
|
+
return (await n.readdir(r, { withFileTypes: !0 }).catch(() => [])).filter((e) => e.isDirectory()).map((e) => a.join(r, e.name, ".env.example"));
|
|
3599
|
+
}));
|
|
3600
|
+
return t.push(...r.flat()), (await Promise.all(t.map(async (e) => await X(e) ? e : null))).filter((e) => e !== null);
|
|
3601
|
+
}
|
|
3602
|
+
//#endregion
|
|
3603
|
+
//#region src/core/post-clone.ts
|
|
3604
|
+
var $ = "@hype-stack/", Vi = "hype-stack";
|
|
3605
|
+
async function Hi(e) {
|
|
3606
|
+
await Gn(a.join(e, ".git"));
|
|
3607
|
+
}
|
|
3608
|
+
async function Ui(e) {
|
|
3609
|
+
await J("git", ["init"], { cwd: e }), await J("git", ["add", "."], { cwd: e }), await J("git", [
|
|
3610
|
+
"-c",
|
|
3611
|
+
"user.name=Hype Stack CLI",
|
|
3612
|
+
"-c",
|
|
3613
|
+
"user.email=cli@hypestack.dev",
|
|
3614
|
+
"commit",
|
|
3615
|
+
"-m",
|
|
3616
|
+
"Initial commit from Hype Stack CLI"
|
|
3617
|
+
], { cwd: e });
|
|
3618
|
+
}
|
|
3619
|
+
async function Wi(e, t) {
|
|
3620
|
+
let r = `@${t}/`, i = await Ji(e);
|
|
3621
|
+
for (let e of i) {
|
|
3622
|
+
let t = await Hn(e);
|
|
3623
|
+
if (!t) continue;
|
|
3624
|
+
let i = !1;
|
|
3625
|
+
t.name?.startsWith($) && (t.name = t.name.replace($, r), i = !0), Gi(t.dependencies, r) && (i = !0), Gi(t.devDependencies, r) && (i = !0), t.nx && Ki(t.nx, r) && (i = !0);
|
|
3626
|
+
let a = await n.readFile(e, "utf-8");
|
|
3627
|
+
if (a.includes($)) {
|
|
3628
|
+
let t = a.replaceAll($, r);
|
|
3629
|
+
await n.writeFile(e, t, "utf-8");
|
|
3630
|
+
} else i && await Un(e, t);
|
|
3631
|
+
}
|
|
3632
|
+
await qi(e, t);
|
|
3633
|
+
}
|
|
3634
|
+
function Gi(e, t) {
|
|
3635
|
+
if (!e) return !1;
|
|
3636
|
+
let n = !1;
|
|
3637
|
+
for (let r of Object.keys(e)) if (r.startsWith($)) {
|
|
3638
|
+
let i = r.replace($, t);
|
|
3639
|
+
e[i] = e[r], delete e[r], n = !0;
|
|
3640
|
+
}
|
|
3641
|
+
return n;
|
|
3642
|
+
}
|
|
3643
|
+
function Ki(e, t) {
|
|
3644
|
+
if (!e) return !1;
|
|
3645
|
+
let n = !1;
|
|
3646
|
+
if (e.implicitDependencies &&= e.implicitDependencies.map((e) => e.startsWith($) ? (n = !0, e.replace($, t)) : e), e.targets) {
|
|
3647
|
+
for (let r of Object.values(e.targets)) if (r.buildTarget?.includes($) && (r.buildTarget = r.buildTarget.replaceAll($, t), n = !0), r.dependsOn &&= r.dependsOn.map((e) => e.includes($) ? (n = !0, e.replaceAll($, t)) : e), r.configurations) for (let e of Object.values(r.configurations)) e.buildTarget?.includes($) && (e.buildTarget = e.buildTarget.replaceAll($, t), n = !0);
|
|
3648
|
+
}
|
|
3649
|
+
return n;
|
|
3650
|
+
}
|
|
3651
|
+
async function qi(e, t) {
|
|
3652
|
+
let r = a.join(e, "packages/enums/src/app/index.ts"), i = await n.readFile(r, "utf-8").catch(() => null);
|
|
3653
|
+
if (!i) return;
|
|
3654
|
+
let o = t.split("-").map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" "), s = i.replaceAll(`id: "${Vi}"`, `id: "${t}"`).replaceAll(`name: "${Vi}"`, `name: "${t}"`).replace(/name: "Hype Stack"/, `name: "${o}"`).replace(/description: ".*?"/, `description: "${o} application"`);
|
|
3655
|
+
await n.writeFile(r, s, "utf-8");
|
|
3656
|
+
}
|
|
3657
|
+
async function Ji(e) {
|
|
3658
|
+
let t = [], r = a.join(e, "package.json");
|
|
3659
|
+
(await n.stat(r).catch(() => null))?.isFile() && t.push(r);
|
|
3660
|
+
for (let r of [
|
|
3661
|
+
"apps",
|
|
3662
|
+
"packages",
|
|
3663
|
+
"libs",
|
|
3664
|
+
"shared"
|
|
3665
|
+
]) {
|
|
3666
|
+
let i = a.join(e, r), o = await n.readdir(i, { withFileTypes: !0 }).catch(() => []);
|
|
3667
|
+
for (let e of o) {
|
|
3668
|
+
if (!e.isDirectory()) continue;
|
|
3669
|
+
let r = a.join(i, e.name, "package.json");
|
|
3670
|
+
(await n.stat(r).catch(() => null))?.isFile() && t.push(r);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
return t;
|
|
3674
|
+
}
|
|
3675
|
+
//#endregion
|
|
3676
|
+
//#region src/core/post-setup.ts
|
|
3677
|
+
async function Yi() {
|
|
3678
|
+
return (await J("docker", ["info"], { cwd: process.cwd() })).exitCode === 0;
|
|
3679
|
+
}
|
|
3680
|
+
async function Xi(e) {
|
|
3681
|
+
return X(`${e}/apps/backend/.env`);
|
|
3682
|
+
}
|
|
3683
|
+
async function Zi(e, n, r) {
|
|
3684
|
+
let i = r ? `Start services with ${I.command("docker compose up -d")}?` : `Docker is not running. Start services with ${I.command("docker compose up -d")}?`, a = n ? !0 : await t.confirm({
|
|
3685
|
+
message: i,
|
|
3686
|
+
initialValue: !0
|
|
3687
|
+
});
|
|
3688
|
+
if (t.isCancel(a) && Q(), !a) return t.log.info(I.muted("Skipping Docker services and database migrations.")), !1;
|
|
3689
|
+
let o = t.spinner();
|
|
3690
|
+
return o.start("Starting Docker services..."), (await J("docker", [
|
|
3691
|
+
"compose",
|
|
3692
|
+
"up",
|
|
3693
|
+
"-d"
|
|
3694
|
+
], { cwd: `${e}/apps/backend` })).exitCode === 0 ? (o.stop(I.success("Docker services started")), !0) : (o.stop(I.warning("Failed to start Docker services")), t.log.warn(I.muted("Run `docker compose up -d` in apps/backend manually to start services.")), t.log.info(I.muted("Skipping database migrations.")), !1);
|
|
3695
|
+
}
|
|
3696
|
+
async function Qi(e, t = 15, n = 2e3) {
|
|
3697
|
+
for (let r = 0; r < t; r++) {
|
|
3698
|
+
if ((await J("docker", [
|
|
3699
|
+
"compose",
|
|
3700
|
+
"exec",
|
|
3701
|
+
"-T",
|
|
3702
|
+
"postgres",
|
|
3703
|
+
"pg_isready",
|
|
3704
|
+
"-U",
|
|
3705
|
+
"postgres"
|
|
3706
|
+
], { cwd: `${e}/apps/backend` })).exitCode === 0) return !0;
|
|
3707
|
+
await new Promise((e) => setTimeout(e, n));
|
|
3708
|
+
}
|
|
3709
|
+
return !1;
|
|
3710
|
+
}
|
|
3711
|
+
async function $i(e, n, r = {}) {
|
|
3712
|
+
if (!await Xi(e)) {
|
|
3713
|
+
t.log.warn(`${I.path(".env")} not found in ${I.path("apps/backend")}. Skipping Docker and migrations - configure it first.`);
|
|
3714
|
+
return;
|
|
3715
|
+
}
|
|
3716
|
+
if (!await Zi(e, n, await Yi())) return;
|
|
3717
|
+
let i = t.spinner();
|
|
3718
|
+
if (i.start("Waiting for Postgres to be ready..."), !await Qi(e, r.postgresMaxAttempts ?? 15, r.postgresCheckIntervalMs ?? 2e3)) {
|
|
3719
|
+
i.stop(I.warning("Postgres health check timed out")), t.log.warn(I.muted("Run migrations manually once Postgres is ready: pnpm --filter @internal/backend migration:latest"));
|
|
3720
|
+
return;
|
|
3721
|
+
}
|
|
3722
|
+
i.stop(I.success("Postgres is ready"));
|
|
3723
|
+
let a = n ? !0 : await t.confirm({
|
|
3724
|
+
message: `Run database migrations with ${I.command("prisma migrate deploy")}?`,
|
|
3725
|
+
initialValue: !0
|
|
3726
|
+
});
|
|
3727
|
+
if (t.isCancel(a) && Q(), !a) {
|
|
3728
|
+
t.log.info(I.muted("Skipping database migrations."));
|
|
3729
|
+
return;
|
|
3730
|
+
}
|
|
3731
|
+
let o = t.spinner();
|
|
3732
|
+
if (o.start("Running database migrations..."), (await J("pnpm", [
|
|
3733
|
+
"--filter",
|
|
3734
|
+
"@internal/backend",
|
|
3735
|
+
"migration:latest"
|
|
3736
|
+
], { cwd: e })).exitCode !== 0) {
|
|
3737
|
+
o.stop(I.warning("Migrations failed")), t.log.warn(I.muted("Run `pnpm --filter @internal/backend migration:latest` manually to apply migrations."));
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
o.stop(I.success("Database migrations applied"));
|
|
3741
|
+
let s = t.spinner();
|
|
3742
|
+
if (s.start("Generating Prisma client..."), (await J("pnpm", [
|
|
3743
|
+
"--filter",
|
|
3744
|
+
"@internal/backend",
|
|
3745
|
+
"generate"
|
|
3746
|
+
], { cwd: e })).exitCode !== 0) {
|
|
3747
|
+
s.stop(I.warning("Prisma client generation failed")), t.log.warn(I.muted("Run `pnpm --filter @internal/backend generate` manually."));
|
|
3748
|
+
return;
|
|
3749
|
+
}
|
|
3750
|
+
s.stop(I.success("Prisma client generated"));
|
|
3751
|
+
}
|
|
3752
|
+
//#endregion
|
|
3753
|
+
//#region src/core/readme.ts
|
|
3754
|
+
var ea = {
|
|
3755
|
+
cursor: {
|
|
3756
|
+
label: "Cursor",
|
|
3757
|
+
rulesDir: ".cursor/rules"
|
|
3758
|
+
},
|
|
3759
|
+
claude: {
|
|
3760
|
+
label: "Claude Code",
|
|
3761
|
+
rulesDir: ".claude/rules"
|
|
3762
|
+
},
|
|
3763
|
+
windsurf: {
|
|
3764
|
+
label: "Windsurf",
|
|
3765
|
+
rulesDir: ".windsurf/rules"
|
|
3766
|
+
},
|
|
3767
|
+
copilot: {
|
|
3768
|
+
label: "GitHub Copilot",
|
|
3769
|
+
rulesDir: ".github/instructions"
|
|
3770
|
+
}
|
|
3771
|
+
}, ta = {
|
|
3772
|
+
backend: "Hono API server (Postgres, Prisma, Kysely, Valkey cache, WorkOS auth)",
|
|
3773
|
+
frontend: "React + Vite app talking to the backend through the typed HyperFetch SDK"
|
|
3774
|
+
}, na = {
|
|
3775
|
+
enums: "Shared enums and app config used across apps",
|
|
3776
|
+
cli: "Project tooling and code generators"
|
|
3777
|
+
};
|
|
3778
|
+
function ra(e) {
|
|
3779
|
+
return e.split(/[-_]/).filter(Boolean).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
|
|
3780
|
+
}
|
|
3781
|
+
function ia(e, t) {
|
|
3782
|
+
return Object.entries(e).toSorted(([e], [t]) => e.localeCompare(t)).map(([e, n]) => {
|
|
3783
|
+
let r = t[e];
|
|
3784
|
+
return r ? `- \`${n}\` - ${r}` : `- \`${n}\``;
|
|
3785
|
+
});
|
|
3786
|
+
}
|
|
3787
|
+
function aa(e) {
|
|
3788
|
+
let { projectName: t, editor: n, workspace: r } = e, i = ra(t), a = ea[n], o = !!r.apps.backend, s = ia(r.apps, ta), c = ia(r.packages, na), l = [];
|
|
3789
|
+
s.length > 0 && l.push(...s), c.length > 0 && l.push(...c), l.push("- `stack.json` - Hype Stack workspace config (apps, paths, installed packs)");
|
|
3790
|
+
let u = [];
|
|
3791
|
+
u.push(`# ${i}`), u.push([
|
|
3792
|
+
`${i} is built on [Hype Stack](https://hypestack.dev), a typed full stack template.`,
|
|
3793
|
+
"The backend runs on Hono with Postgres, Prisma, and Kysely. The frontend is React + Vite and",
|
|
3794
|
+
"talks to the API through a fully typed SDK, so types flow end to end with no manual wiring."
|
|
3795
|
+
].join(" ")), u.push([
|
|
3796
|
+
"## Prerequisites",
|
|
3797
|
+
"",
|
|
3798
|
+
"- [Node.js](https://nodejs.org) 20 or newer",
|
|
3799
|
+
"- [pnpm](https://pnpm.io) (this repo uses pnpm workspaces)",
|
|
3800
|
+
"- [Docker](https://www.docker.com) for local Postgres, Valkey, and object storage"
|
|
3801
|
+
].join("\n"));
|
|
3802
|
+
let d = [];
|
|
3803
|
+
d.push([
|
|
3804
|
+
"Install dependencies",
|
|
3805
|
+
"",
|
|
3806
|
+
"```bash",
|
|
3807
|
+
"pnpm install",
|
|
3808
|
+
"```"
|
|
3809
|
+
]);
|
|
3810
|
+
let f = ["```bash"];
|
|
3811
|
+
o && f.push("cp apps/backend/.env.example apps/backend/.env"), r.apps.frontend && f.push("cp apps/frontend/.env.example apps/frontend/.env"), f.push("```"), d.push([
|
|
3812
|
+
"Configure environment variables",
|
|
3813
|
+
"",
|
|
3814
|
+
"Copy the example env files and fill in any required values.",
|
|
3815
|
+
"",
|
|
3816
|
+
...f
|
|
3817
|
+
]), o && (d.push([
|
|
3818
|
+
"Start local services",
|
|
3819
|
+
"",
|
|
3820
|
+
"Postgres, Valkey (Redis compatible), and object storage run in Docker. Ports and",
|
|
3821
|
+
"credentials are defined in `apps/backend/docker-compose.yml` and `apps/backend/.env.example`.",
|
|
3822
|
+
"",
|
|
3823
|
+
"```bash",
|
|
3824
|
+
"cd apps/backend && docker compose up -d && cd ../..",
|
|
3825
|
+
"```"
|
|
3826
|
+
]), d.push([
|
|
3827
|
+
"Set up the database",
|
|
3828
|
+
"",
|
|
3829
|
+
"Apply migrations and generate the Prisma client.",
|
|
3830
|
+
"",
|
|
3831
|
+
"```bash",
|
|
3832
|
+
"pnpm --filter @internal/backend migration:latest",
|
|
3833
|
+
"pnpm --filter @internal/backend generate",
|
|
3834
|
+
"```"
|
|
3835
|
+
])), d.push([
|
|
3836
|
+
"Run the app",
|
|
3837
|
+
"",
|
|
3838
|
+
"```bash",
|
|
3839
|
+
"pnpm dev",
|
|
3840
|
+
"```",
|
|
3841
|
+
"",
|
|
3842
|
+
"Check the `.env` files for the exact URLs and ports."
|
|
3843
|
+
]);
|
|
3844
|
+
let p = d.flatMap((e, t) => {
|
|
3845
|
+
let [n, ...r] = e;
|
|
3846
|
+
return [
|
|
3847
|
+
`### ${t + 1}. ${n}`,
|
|
3848
|
+
"",
|
|
3849
|
+
...r,
|
|
3850
|
+
""
|
|
3851
|
+
];
|
|
3852
|
+
});
|
|
3853
|
+
u.push([
|
|
3854
|
+
"## Getting started",
|
|
3855
|
+
"",
|
|
3856
|
+
...p
|
|
3857
|
+
].join("\n").trimEnd()), u.push([
|
|
3858
|
+
"## Project structure",
|
|
3859
|
+
"",
|
|
3860
|
+
...l
|
|
3861
|
+
].join("\n"));
|
|
3862
|
+
let m = [
|
|
3863
|
+
"Run these from the repo root unless noted otherwise.",
|
|
3864
|
+
"",
|
|
3865
|
+
"| Command | What it does |",
|
|
3866
|
+
"| --- | --- |",
|
|
3867
|
+
"| `pnpm dev` | Start backend and frontend in watch mode |",
|
|
3868
|
+
"| `pnpm build` | Build all apps and packages |",
|
|
3869
|
+
"| `pnpm test` | Run the test suites |",
|
|
3870
|
+
"| `pnpm typecheck` | Type check the whole workspace |",
|
|
3871
|
+
"| `pnpm lint` | Lint the whole workspace |"
|
|
3872
|
+
];
|
|
3873
|
+
return o && m.push("| `pnpm --filter @internal/backend migration:create` | Create a new migration from schema changes |", "| `pnpm --filter @internal/backend migration:latest` | Apply pending migrations |", "| `pnpm --filter @internal/backend generate` | Regenerate the Prisma client |"), u.push([
|
|
3874
|
+
"## Scripts",
|
|
3875
|
+
"",
|
|
3876
|
+
...m
|
|
3877
|
+
].join("\n")), u.push([
|
|
3878
|
+
"## Adding features",
|
|
3879
|
+
"",
|
|
3880
|
+
"Hype Stack ships features as packs (auth, monetization, notifications, and more).",
|
|
3881
|
+
"Pick the ones you want with the CLI:",
|
|
3882
|
+
"",
|
|
3883
|
+
"```bash",
|
|
3884
|
+
"npx hype-stack compose",
|
|
3885
|
+
"```",
|
|
3886
|
+
"",
|
|
3887
|
+
"Installed packs are tracked in `stack.json`."
|
|
3888
|
+
].join("\n")), u.push([
|
|
3889
|
+
"## Editor and AI rules",
|
|
3890
|
+
"",
|
|
3891
|
+
`This project was set up for **${a.label}**. Coding conventions and AI guidance`,
|
|
3892
|
+
`live in \`${a.rulesDir}\`. Keep them up to date as the project grows so the assistant`,
|
|
3893
|
+
"stays useful."
|
|
3894
|
+
].join("\n")), u.join("\n\n") + "\n";
|
|
3895
|
+
}
|
|
3896
|
+
async function oa(e, t) {
|
|
3897
|
+
let r = a.join(e, "README.md");
|
|
3898
|
+
await n.writeFile(r, aa(t), "utf-8");
|
|
3899
|
+
}
|
|
3900
|
+
//#endregion
|
|
3901
|
+
//#region src/utils/validate.ts
|
|
3902
|
+
function sa(e) {
|
|
3903
|
+
if (!e.trim()) return "Project name cannot be empty";
|
|
3904
|
+
if (!w.test(e)) return "Project name must be lowercase, alphanumeric, and may contain hyphens, dots, or underscores";
|
|
3905
|
+
if (e.length > 214) return "Project name is too long (max 214 characters)";
|
|
3906
|
+
}
|
|
3907
|
+
//#endregion
|
|
3908
|
+
//#region src/commands/create.ts
|
|
3909
|
+
async function ca(e) {
|
|
3910
|
+
hi(), t.intro(I.brandBold("Create a new Hype Stack project"));
|
|
3911
|
+
let n = e.yes === !0, r;
|
|
3912
|
+
if (n && e.name) {
|
|
3913
|
+
let n = sa(e.name);
|
|
3914
|
+
n && (t.log.error(n), Q()), r = e.name;
|
|
3915
|
+
} else {
|
|
3916
|
+
let n = await t.text({
|
|
3917
|
+
message: "What is your project named?",
|
|
3918
|
+
placeholder: "my-app",
|
|
3919
|
+
initialValue: e.name ?? "",
|
|
3920
|
+
validate: (e) => sa(e ?? "")
|
|
3921
|
+
});
|
|
3922
|
+
t.isCancel(n) && Q(), r = n;
|
|
3923
|
+
}
|
|
3924
|
+
let i;
|
|
3925
|
+
if (n) i = e.directory ?? `./${r}`;
|
|
3926
|
+
else {
|
|
3927
|
+
let n = await t.text({
|
|
3928
|
+
message: "Where should we create it?",
|
|
3929
|
+
placeholder: `./${r}`,
|
|
3930
|
+
initialValue: e.directory ?? `./${r}`
|
|
3931
|
+
});
|
|
3932
|
+
t.isCancel(n) && Q(), i = n;
|
|
3933
|
+
}
|
|
3934
|
+
let o = e.editor && E.includes(e.editor) ? e.editor : null, s;
|
|
3935
|
+
if (o) s = o;
|
|
3936
|
+
else if (n) s = "cursor";
|
|
3937
|
+
else {
|
|
3938
|
+
let e = await t.select({
|
|
3939
|
+
message: "Which code editor do you use?",
|
|
3940
|
+
options: T.map((e) => ({
|
|
3941
|
+
value: e.value,
|
|
3942
|
+
label: e.label,
|
|
3943
|
+
hint: "hint" in e ? e.hint : void 0
|
|
3944
|
+
})),
|
|
3945
|
+
initialValue: "cursor"
|
|
3946
|
+
});
|
|
3947
|
+
t.isCancel(e) && Q(), s = e;
|
|
3948
|
+
}
|
|
3949
|
+
if (!n) {
|
|
3950
|
+
let e = T.find((e) => e.value === s)?.label ?? s, n = await t.confirm({ message: `Create ${I.highlight(r)} in ${I.path(i)} with ${I.highlight(e)} config?` });
|
|
3951
|
+
(t.isCancel(n) || !n) && Q();
|
|
3952
|
+
}
|
|
3953
|
+
let c = a.resolve(i);
|
|
3954
|
+
if (await Y(c) && !await Vn(c)) {
|
|
3955
|
+
let e = await t.confirm({
|
|
3956
|
+
message: `Directory ${I.path(c)} is not empty. Continue anyway?`,
|
|
3957
|
+
initialValue: !1
|
|
3958
|
+
});
|
|
3959
|
+
(t.isCancel(e) || !e) && Q();
|
|
3960
|
+
}
|
|
3961
|
+
let l = t.spinner();
|
|
3962
|
+
l.start("Cloning Hype Stack template..."), await Ai(c), l.stop(I.success("Template cloned"));
|
|
3963
|
+
let u = t.spinner();
|
|
3964
|
+
u.start("Setting up project..."), await Hi(c), await Wi(c, r), await Li(c, s);
|
|
3965
|
+
let d = await Zn(c);
|
|
3966
|
+
await Xn(c, $n(r, d)), await oa(c, {
|
|
3967
|
+
projectName: r,
|
|
3968
|
+
editor: s,
|
|
3969
|
+
workspace: d
|
|
3970
|
+
}), u.stop(I.success("Project configured"));
|
|
3971
|
+
let f = t.spinner();
|
|
3972
|
+
f.start("Installing dependencies..."), (await J("pnpm", ["install"], { cwd: c })).exitCode === 0 ? f.stop(I.success("Dependencies installed")) : (f.stop(I.warning("Dependencies installed with warnings")), t.log.warn(I.muted("You may need to run `pnpm install` manually to resolve issues.")));
|
|
3973
|
+
let p = t.spinner();
|
|
3974
|
+
p.start("Initializing git repository..."), await Ui(c), p.stop(I.success("Git repository initialized with clean history"));
|
|
3975
|
+
let m = t.spinner();
|
|
3976
|
+
m.start("Creating .env files from examples...");
|
|
3977
|
+
let h = await zi(c);
|
|
3978
|
+
if (h.length > 0) {
|
|
3979
|
+
let e = h.length;
|
|
3980
|
+
m.stop(I.success(`Created ${e} .env file${e === 1 ? "" : "s"} from examples`));
|
|
3981
|
+
} else m.stop(I.muted("No .env.example files to copy"));
|
|
3982
|
+
t.log.success(`${I.brandBold("Hype Stack")} project ${I.highlight(r)} is ready!`);
|
|
3983
|
+
let g = a.relative(process.cwd(), c) || ".", _ = [`${I.command(`cd ${g}`)}`];
|
|
3984
|
+
h.length > 0 ? _.push(`Review your ${I.path(".env")} files and fill in any secrets`) : _.push(`Copy ${I.path(".env.example")} to ${I.path(".env")} and configure`), _i(_);
|
|
3985
|
+
let v = n ? !0 : await t.confirm({
|
|
3986
|
+
message: "Would you like to start Docker services and run database migrations now?",
|
|
3987
|
+
initialValue: !0
|
|
3988
|
+
});
|
|
3989
|
+
t.isCancel(v) && Q(), v ? await $i(c, n) : (t.log.info(I.muted("You can start services later:")), _i([
|
|
3990
|
+
`${I.command("docker compose up -d")} ${I.muted("(in apps/backend - start Postgres, Valkey, RustFS)")}`,
|
|
3991
|
+
`${I.command("pnpm --filter @internal/backend migration:latest")} ${I.muted("(apply migrations)")}`,
|
|
3992
|
+
`${I.command("pnpm --filter @internal/backend generate")} ${I.muted("(generate Prisma client)")}`
|
|
3993
|
+
])), _i([`${I.command("pnpm dev")} ${I.muted("(start frontend + backend)")}`]), t.outro(I.muted("Happy building!"));
|
|
3994
|
+
}
|
|
3995
|
+
//#endregion
|
|
3996
|
+
//#region src/commands/login.ts
|
|
3997
|
+
async function la() {
|
|
3998
|
+
gi(), t.intro(I.brandBold("Log in to Hype Stack")), t.log.step("Opening your browser to sign in...");
|
|
3999
|
+
let e;
|
|
4000
|
+
try {
|
|
4001
|
+
e = await Rn({ onUrl: (e) => {
|
|
4002
|
+
t.log.info(`If your browser didn't open, visit:\n ${I.path(e)}`);
|
|
4003
|
+
} });
|
|
4004
|
+
} catch (e) {
|
|
4005
|
+
t.cancel(e instanceof Error ? e.message : String(e)), process.exit(1);
|
|
4006
|
+
}
|
|
4007
|
+
t.outro(I.brand(e.email ? `Logged in as ${e.email}. You can now install packs your organization owns.` : "Logged in. You can now install packs your organization owns."));
|
|
4008
|
+
}
|
|
4009
|
+
//#endregion
|
|
4010
|
+
//#region src/commands/logout.ts
|
|
4011
|
+
async function ua() {
|
|
4012
|
+
gi(), t.intro(I.brandBold("Log out of Hype Stack"));
|
|
4013
|
+
let e = k(), n = await kn(e);
|
|
4014
|
+
if (!n) {
|
|
4015
|
+
t.outro(I.muted("You're not logged in."));
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
await xn(n.token).catch(() => null), await jn(e), t.outro(I.brand("Logged out."));
|
|
4019
|
+
}
|
|
4020
|
+
//#endregion
|
|
4021
|
+
//#region src/cli.ts
|
|
4022
|
+
function da(e) {
|
|
4023
|
+
if (!e) return;
|
|
4024
|
+
let t = e.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
|
|
4025
|
+
return t.length > 0 ? t : void 0;
|
|
4026
|
+
}
|
|
4027
|
+
function fa() {
|
|
4028
|
+
let t = new e();
|
|
4029
|
+
return t.name("hype-stack").description("Build with Hype Stack -- templates, components, modules, and more").version(v, "-v, --version"), t.command("create").description("Create a new Hype Stack project").option("-n, --name <name>", "Project name").option("-d, --directory <path>", "Target directory").option("-e, --editor <editor>", "Code editor (cursor, claude, windsurf, copilot)").option("--no-install", "Skip dependency installation").option("-y, --yes", "Skip confirmation prompts (requires --name)").action(async (e) => {
|
|
4030
|
+
await ca({
|
|
4031
|
+
name: e.name,
|
|
4032
|
+
directory: e.directory,
|
|
4033
|
+
install: e.install,
|
|
4034
|
+
editor: e.editor,
|
|
4035
|
+
yes: e.yes
|
|
4036
|
+
});
|
|
4037
|
+
}), t.command("init").description("Initialize stack.json in the current project").action(async () => {
|
|
4038
|
+
await vi({});
|
|
4039
|
+
}), t.command("compose").description("Choose feature packs to add to your project").option("--packs <list>", "Comma-separated pack names (non-interactive)").option("--force", "Overwrite existing files").option("-y, --yes", "Skip confirmation prompts").option("-k, --key <key>", "License key").option("--license-key <key>", "License key (alias for --key)").option("--cwd <path>", "Working directory").action(async (e) => {
|
|
4040
|
+
await bi({
|
|
4041
|
+
packs: da(e.packs),
|
|
4042
|
+
force: e.force,
|
|
4043
|
+
yes: e.yes,
|
|
4044
|
+
licenseKey: e.key ?? e.licenseKey,
|
|
4045
|
+
cwd: e.cwd
|
|
4046
|
+
});
|
|
4047
|
+
}), t.command("login").description("Log in via your browser to install packs your organization owns").action(async () => {
|
|
4048
|
+
await la();
|
|
4049
|
+
}), t.command("logout").description("Log out and remove the saved CLI token").action(async () => {
|
|
4050
|
+
await ua();
|
|
4051
|
+
}), t.command("auth").description("Alias for `login`").action(async () => {
|
|
4052
|
+
await la();
|
|
4053
|
+
}), t;
|
|
4054
|
+
}
|
|
4055
|
+
//#endregion
|
|
4056
|
+
export { bi as a, ca as i, ua as n, yi as o, la as r, vi as s, fa as t };
|