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