likec4 1.48.0 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/__app__/src/likec4.js +5941 -4496
- package/__app__/src/routes/index.js +3 -153
- package/__app__/src/routes/projects.js +21 -1087
- package/__app__/src/routes/single.js +1228 -16
- package/__app__/src/style.css +1 -1
- package/__app__/src/vendors.js +4649 -1897
- package/__app__/src/webcomponent.js +1 -1
- package/config/schema.json +169 -141
- package/dist/THIRD-PARTY-LICENSES.md +1769 -0
- package/dist/_chunks/LikeC4.mjs +1154 -202
- package/dist/_chunks/binary.mjs +72 -0
- package/dist/_chunks/index.d.mts +234 -140
- package/dist/_chunks/index2.d.mts +2043 -1828
- package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
- package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
- package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
- package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
- package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
- package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
- package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
- package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
- package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
- package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
- package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -10
- package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
- package/dist/_chunks/libs/ajv.mjs +1 -777
- package/dist/_chunks/libs/atomically.mjs +1 -362
- package/dist/_chunks/libs/birpc.mjs +1 -201
- package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
- package/dist/_chunks/libs/chevrotain.mjs +55 -6229
- package/dist/_chunks/libs/conf.mjs +1 -2258
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/esm-env.mjs +1 -5
- package/dist/_chunks/libs/eventemitter3.mjs +1 -243
- package/dist/_chunks/libs/fast-equals.mjs +1 -446
- package/dist/_chunks/libs/find-up-simple.mjs +1 -24
- package/dist/_chunks/libs/get-port.mjs +1 -107
- package/dist/_chunks/libs/is-docker.mjs +1 -26
- package/dist/_chunks/libs/is-error-instance.mjs +1 -26
- package/dist/_chunks/libs/is-inside-container.mjs +1 -20
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/isexe.mjs +1 -127
- package/dist/_chunks/libs/json5.mjs +14 -959
- package/dist/_chunks/libs/khroma.mjs +1 -605
- package/dist/_chunks/libs/ky.mjs +2 -807
- package/dist/_chunks/libs/langium.d.mts +2913 -2876
- package/dist/_chunks/libs/langium.mjs +33 -20351
- package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
- package/dist/_chunks/libs/p-limit.mjs +1 -120
- package/dist/_chunks/libs/p-queue.mjs +1 -449
- package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
- package/dist/_chunks/libs/package-up.mjs +1 -10
- package/dist/_chunks/libs/pako.mjs +1 -0
- package/dist/_chunks/libs/parse-ms.mjs +1 -36
- package/dist/_chunks/libs/pathe.mjs +1 -0
- package/dist/_chunks/libs/picomatch.mjs +1 -1673
- package/dist/_chunks/libs/pretty-ms.mjs +1 -80
- package/dist/_chunks/libs/remeda.mjs +2 -690
- package/dist/_chunks/libs/safe-stringify.mjs +1 -21
- package/dist/_chunks/libs/strip-indent.mjs +1 -15
- package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
- package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
- package/dist/_chunks/libs/ufo.mjs +1 -240
- package/dist/_chunks/libs/which.mjs +1 -84
- package/dist/_chunks/libs/word-wrap.mjs +12 -43
- package/dist/_chunks/rolldown-runtime.mjs +1 -48
- package/dist/_chunks/sequence.mjs +1 -0
- package/dist/_chunks/src.mjs +15 -0
- package/dist/_chunks/src2.mjs +499 -0
- package/dist/cli/index.mjs +77 -1952
- package/dist/config/index.d.mts +2 -2
- package/dist/config/index.mjs +1 -6
- package/dist/index.d.mts +150 -7
- package/dist/index.mjs +1 -21
- package/dist/model/builder.mjs +1 -3
- package/dist/model/index.d.mts +57 -3
- package/dist/model/index.mjs +1 -5
- package/dist/vite-plugin/index.d.mts +7 -3
- package/dist/vite-plugin/index.mjs +1 -22
- package/dist/vite-plugin/internal.d.mts +6 -7
- package/dist/vite-plugin/internal.mjs +1 -68
- package/package.json +64 -45
- package/react/{index.d.ts → index.d.mts} +114 -72
- package/react/{index.js → index.mjs} +21320 -22041
- package/react/package.json +2 -5
- package/vite-plugin-modules.d.ts +10 -5
- package/dist/_chunks/LikeC4.d.mts +0 -121
- package/dist/_chunks/config-app.prod.d.mts +0 -18
- package/dist/_chunks/config-app.prod.mjs +0 -188
- package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
- package/dist/_chunks/define-config.mjs +0 -409
- package/dist/_chunks/index3.d.mts +0 -60
- package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -3969
- package/dist/_chunks/libs/hono.mjs +0 -1829
- package/dist/_chunks/libs/nanoid.mjs +0 -29
- package/dist/_chunks/libs/nanostores.d.mts +0 -63
- package/dist/_chunks/libs/nanostores.mjs +0 -198
- package/dist/_chunks/model.mjs +0 -12
- package/dist/_chunks/module.d.mts +0 -71
- package/dist/_chunks/module.mjs +0 -18657
- package/dist/_chunks/plugin.mjs +0 -996
- package/dist/_chunks/sequence-view.mjs +0 -575
- package/dist/_chunks/vite-build.mjs +0 -69
- package/dist/_chunks/vite-dev.mjs +0 -79
- package/dist/_chunks/vite-preview.mjs +0 -27
- package/dist/language/module.d.mts +0 -5
- package/dist/language/module.mjs +0 -20
- package/dist/vite/vite-build.d.mts +0 -26
- package/dist/vite/vite-build.mjs +0 -27
- package/dist/vite/vite-dev.d.mts +0 -34
- package/dist/vite/vite-dev.mjs +0 -29
- package/dist/vite/vite-preview.d.mts +0 -20
- package/dist/vite/vite-preview.mjs +0 -26
- /package/dist/_chunks/{index4.d.mts → libs/@chevrotain/types.d.mts} +0 -0
|
@@ -1,362 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
|
|
7
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/attemptify.js
|
|
8
|
-
const attemptifyAsync = (fn, onError) => {
|
|
9
|
-
return function attemptified(...args) {
|
|
10
|
-
return fn.apply(void 0, args).catch(onError);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
const attemptifySync = (fn, onError) => {
|
|
14
|
-
return function attemptified(...args) {
|
|
15
|
-
try {
|
|
16
|
-
return fn.apply(void 0, args);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
return onError(error);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/constants.js
|
|
25
|
-
const IS_USER_ROOT$1 = process.getuid ? !process.getuid() : false;
|
|
26
|
-
const LIMIT_FILES_DESCRIPTORS = 1e4;
|
|
27
|
-
const NOOP = () => void 0;
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/handlers.js
|
|
31
|
-
const Handlers = {
|
|
32
|
-
isChangeErrorOk: (error) => {
|
|
33
|
-
if (!Handlers.isNodeError(error)) return false;
|
|
34
|
-
const { code } = error;
|
|
35
|
-
if (code === "ENOSYS") return true;
|
|
36
|
-
if (!IS_USER_ROOT$1 && (code === "EINVAL" || code === "EPERM")) return true;
|
|
37
|
-
return false;
|
|
38
|
-
},
|
|
39
|
-
isNodeError: (error) => {
|
|
40
|
-
return error instanceof Error;
|
|
41
|
-
},
|
|
42
|
-
isRetriableError: (error) => {
|
|
43
|
-
if (!Handlers.isNodeError(error)) return false;
|
|
44
|
-
const { code } = error;
|
|
45
|
-
if (code === "EMFILE" || code === "ENFILE" || code === "EAGAIN" || code === "EBUSY" || code === "EACCESS" || code === "EACCES" || code === "EACCS" || code === "EPERM") return true;
|
|
46
|
-
return false;
|
|
47
|
-
},
|
|
48
|
-
onChangeError: (error) => {
|
|
49
|
-
if (!Handlers.isNodeError(error)) throw error;
|
|
50
|
-
if (Handlers.isChangeErrorOk(error)) return;
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var handlers_default = Handlers;
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/retryify_queue.js
|
|
58
|
-
var RetryfyQueue = class {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.interval = 25;
|
|
61
|
-
this.intervalId = void 0;
|
|
62
|
-
this.limit = LIMIT_FILES_DESCRIPTORS;
|
|
63
|
-
this.queueActive = /* @__PURE__ */ new Set();
|
|
64
|
-
this.queueWaiting = /* @__PURE__ */ new Set();
|
|
65
|
-
this.init = () => {
|
|
66
|
-
if (this.intervalId) return;
|
|
67
|
-
this.intervalId = setInterval(this.tick, this.interval);
|
|
68
|
-
};
|
|
69
|
-
this.reset = () => {
|
|
70
|
-
if (!this.intervalId) return;
|
|
71
|
-
clearInterval(this.intervalId);
|
|
72
|
-
delete this.intervalId;
|
|
73
|
-
};
|
|
74
|
-
this.add = (fn) => {
|
|
75
|
-
this.queueWaiting.add(fn);
|
|
76
|
-
if (this.queueActive.size < this.limit / 2) this.tick();
|
|
77
|
-
else this.init();
|
|
78
|
-
};
|
|
79
|
-
this.remove = (fn) => {
|
|
80
|
-
this.queueWaiting.delete(fn);
|
|
81
|
-
this.queueActive.delete(fn);
|
|
82
|
-
};
|
|
83
|
-
this.schedule = () => {
|
|
84
|
-
return new Promise((resolve) => {
|
|
85
|
-
const cleanup = () => this.remove(resolver);
|
|
86
|
-
const resolver = () => resolve(cleanup);
|
|
87
|
-
this.add(resolver);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
this.tick = () => {
|
|
91
|
-
if (this.queueActive.size >= this.limit) return;
|
|
92
|
-
if (!this.queueWaiting.size) return this.reset();
|
|
93
|
-
for (const fn of this.queueWaiting) {
|
|
94
|
-
if (this.queueActive.size >= this.limit) break;
|
|
95
|
-
this.queueWaiting.delete(fn);
|
|
96
|
-
this.queueActive.add(fn);
|
|
97
|
-
fn();
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var retryify_queue_default = new RetryfyQueue();
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/retryify.js
|
|
106
|
-
const retryifyAsync = (fn, isRetriableError) => {
|
|
107
|
-
return function retrified(timestamp) {
|
|
108
|
-
return function attempt(...args) {
|
|
109
|
-
return retryify_queue_default.schedule().then((cleanup) => {
|
|
110
|
-
const onResolve = (result) => {
|
|
111
|
-
cleanup();
|
|
112
|
-
return result;
|
|
113
|
-
};
|
|
114
|
-
const onReject = (error) => {
|
|
115
|
-
cleanup();
|
|
116
|
-
if (Date.now() >= timestamp) throw error;
|
|
117
|
-
if (isRetriableError(error)) {
|
|
118
|
-
const delay = Math.round(100 * Math.random());
|
|
119
|
-
return new Promise((resolve) => setTimeout(resolve, delay)).then(() => attempt.apply(void 0, args));
|
|
120
|
-
}
|
|
121
|
-
throw error;
|
|
122
|
-
};
|
|
123
|
-
return fn.apply(void 0, args).then(onResolve, onReject);
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
const retryifySync = (fn, isRetriableError) => {
|
|
129
|
-
return function retrified(timestamp) {
|
|
130
|
-
return function attempt(...args) {
|
|
131
|
-
try {
|
|
132
|
-
return fn.apply(void 0, args);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (Date.now() > timestamp) throw error;
|
|
135
|
-
if (isRetriableError(error)) return attempt.apply(void 0, args);
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region ../../node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/index.js
|
|
144
|
-
const FS = {
|
|
145
|
-
attempt: {
|
|
146
|
-
chmod: attemptifyAsync(promisify(fs.chmod), handlers_default.onChangeError),
|
|
147
|
-
chown: attemptifyAsync(promisify(fs.chown), handlers_default.onChangeError),
|
|
148
|
-
close: attemptifyAsync(promisify(fs.close), NOOP),
|
|
149
|
-
fsync: attemptifyAsync(promisify(fs.fsync), NOOP),
|
|
150
|
-
mkdir: attemptifyAsync(promisify(fs.mkdir), NOOP),
|
|
151
|
-
realpath: attemptifyAsync(promisify(fs.realpath), NOOP),
|
|
152
|
-
stat: attemptifyAsync(promisify(fs.stat), NOOP),
|
|
153
|
-
unlink: attemptifyAsync(promisify(fs.unlink), NOOP),
|
|
154
|
-
chmodSync: attemptifySync(fs.chmodSync, handlers_default.onChangeError),
|
|
155
|
-
chownSync: attemptifySync(fs.chownSync, handlers_default.onChangeError),
|
|
156
|
-
closeSync: attemptifySync(fs.closeSync, NOOP),
|
|
157
|
-
existsSync: attemptifySync(fs.existsSync, NOOP),
|
|
158
|
-
fsyncSync: attemptifySync(fs.fsync, NOOP),
|
|
159
|
-
mkdirSync: attemptifySync(fs.mkdirSync, NOOP),
|
|
160
|
-
realpathSync: attemptifySync(fs.realpathSync, NOOP),
|
|
161
|
-
statSync: attemptifySync(fs.statSync, NOOP),
|
|
162
|
-
unlinkSync: attemptifySync(fs.unlinkSync, NOOP)
|
|
163
|
-
},
|
|
164
|
-
retry: {
|
|
165
|
-
close: retryifyAsync(promisify(fs.close), handlers_default.isRetriableError),
|
|
166
|
-
fsync: retryifyAsync(promisify(fs.fsync), handlers_default.isRetriableError),
|
|
167
|
-
open: retryifyAsync(promisify(fs.open), handlers_default.isRetriableError),
|
|
168
|
-
readFile: retryifyAsync(promisify(fs.readFile), handlers_default.isRetriableError),
|
|
169
|
-
rename: retryifyAsync(promisify(fs.rename), handlers_default.isRetriableError),
|
|
170
|
-
stat: retryifyAsync(promisify(fs.stat), handlers_default.isRetriableError),
|
|
171
|
-
write: retryifyAsync(promisify(fs.write), handlers_default.isRetriableError),
|
|
172
|
-
writeFile: retryifyAsync(promisify(fs.writeFile), handlers_default.isRetriableError),
|
|
173
|
-
closeSync: retryifySync(fs.closeSync, handlers_default.isRetriableError),
|
|
174
|
-
fsyncSync: retryifySync(fs.fsyncSync, handlers_default.isRetriableError),
|
|
175
|
-
openSync: retryifySync(fs.openSync, handlers_default.isRetriableError),
|
|
176
|
-
readFileSync: retryifySync(fs.readFileSync, handlers_default.isRetriableError),
|
|
177
|
-
renameSync: retryifySync(fs.renameSync, handlers_default.isRetriableError),
|
|
178
|
-
statSync: retryifySync(fs.statSync, handlers_default.isRetriableError),
|
|
179
|
-
writeSync: retryifySync(fs.writeSync, handlers_default.isRetriableError),
|
|
180
|
-
writeFileSync: retryifySync(fs.writeFileSync, handlers_default.isRetriableError)
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var dist_default = FS;
|
|
184
|
-
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region ../../node_modules/.pnpm/atomically@2.0.3/node_modules/atomically/dist/constants.js
|
|
187
|
-
const DEFAULT_ENCODING = "utf8";
|
|
188
|
-
const DEFAULT_FILE_MODE = 438;
|
|
189
|
-
const DEFAULT_FOLDER_MODE = 511;
|
|
190
|
-
const DEFAULT_WRITE_OPTIONS = {};
|
|
191
|
-
const DEFAULT_USER_UID = os.userInfo().uid;
|
|
192
|
-
const DEFAULT_USER_GID = os.userInfo().gid;
|
|
193
|
-
const DEFAULT_TIMEOUT_SYNC = 1e3;
|
|
194
|
-
const IS_POSIX = !!process.getuid;
|
|
195
|
-
const IS_USER_ROOT = process.getuid ? !process.getuid() : false;
|
|
196
|
-
const LIMIT_BASENAME_LENGTH = 128;
|
|
197
|
-
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region ../../node_modules/.pnpm/atomically@2.0.3/node_modules/atomically/dist/utils/lang.js
|
|
200
|
-
const isException = (value) => {
|
|
201
|
-
return value instanceof Error && "code" in value;
|
|
202
|
-
};
|
|
203
|
-
const isString = (value) => {
|
|
204
|
-
return typeof value === "string";
|
|
205
|
-
};
|
|
206
|
-
const isUndefined = (value) => {
|
|
207
|
-
return value === void 0;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
//#endregion
|
|
211
|
-
//#region ../../node_modules/.pnpm/when-exit@2.1.4/node_modules/when-exit/dist/node/constants.js
|
|
212
|
-
const IS_LINUX = process.platform === "linux";
|
|
213
|
-
const IS_WINDOWS = process.platform === "win32";
|
|
214
|
-
|
|
215
|
-
//#endregion
|
|
216
|
-
//#region ../../node_modules/.pnpm/when-exit@2.1.4/node_modules/when-exit/dist/node/signals.js
|
|
217
|
-
const Signals = [
|
|
218
|
-
"SIGABRT",
|
|
219
|
-
"SIGALRM",
|
|
220
|
-
"SIGHUP",
|
|
221
|
-
"SIGINT",
|
|
222
|
-
"SIGTERM"
|
|
223
|
-
];
|
|
224
|
-
if (!IS_WINDOWS) Signals.push("SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
|
|
225
|
-
if (IS_LINUX) Signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT", "SIGUNUSED");
|
|
226
|
-
var signals_default = Signals;
|
|
227
|
-
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region ../../node_modules/.pnpm/when-exit@2.1.4/node_modules/when-exit/dist/node/interceptor.js
|
|
230
|
-
var Interceptor = class {
|
|
231
|
-
constructor() {
|
|
232
|
-
this.callbacks = /* @__PURE__ */ new Set();
|
|
233
|
-
this.exited = false;
|
|
234
|
-
this.exit = (signal) => {
|
|
235
|
-
if (this.exited) return;
|
|
236
|
-
this.exited = true;
|
|
237
|
-
for (const callback of this.callbacks) callback();
|
|
238
|
-
if (signal) if (IS_WINDOWS && signal !== "SIGINT" && signal !== "SIGTERM" && signal !== "SIGKILL") process.kill(process.pid, "SIGTERM");
|
|
239
|
-
else process.kill(process.pid, signal);
|
|
240
|
-
};
|
|
241
|
-
this.hook = () => {
|
|
242
|
-
process.once("exit", () => this.exit());
|
|
243
|
-
for (const signal of signals_default) try {
|
|
244
|
-
process.once(signal, () => this.exit(signal));
|
|
245
|
-
} catch {}
|
|
246
|
-
};
|
|
247
|
-
this.register = (callback) => {
|
|
248
|
-
this.callbacks.add(callback);
|
|
249
|
-
return () => {
|
|
250
|
-
this.callbacks.delete(callback);
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
this.hook();
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var interceptor_default = new Interceptor();
|
|
257
|
-
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region ../../node_modules/.pnpm/when-exit@2.1.4/node_modules/when-exit/dist/node/index.js
|
|
260
|
-
const whenExit = interceptor_default.register;
|
|
261
|
-
var node_default = whenExit;
|
|
262
|
-
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region ../../node_modules/.pnpm/atomically@2.0.3/node_modules/atomically/dist/utils/temp.js
|
|
265
|
-
const Temp = {
|
|
266
|
-
store: {},
|
|
267
|
-
create: (filePath) => {
|
|
268
|
-
const randomness = `000000${Math.floor(Math.random() * 16777215).toString(16)}`.slice(-6);
|
|
269
|
-
return `${filePath}${`.tmp-${Date.now().toString().slice(-10)}${randomness}`}`;
|
|
270
|
-
},
|
|
271
|
-
get: (filePath, creator, purge = true) => {
|
|
272
|
-
const tempPath = Temp.truncate(creator(filePath));
|
|
273
|
-
if (tempPath in Temp.store) return Temp.get(filePath, creator, purge);
|
|
274
|
-
Temp.store[tempPath] = purge;
|
|
275
|
-
const disposer = () => delete Temp.store[tempPath];
|
|
276
|
-
return [tempPath, disposer];
|
|
277
|
-
},
|
|
278
|
-
purge: (filePath) => {
|
|
279
|
-
if (!Temp.store[filePath]) return;
|
|
280
|
-
delete Temp.store[filePath];
|
|
281
|
-
dist_default.attempt.unlink(filePath);
|
|
282
|
-
},
|
|
283
|
-
purgeSync: (filePath) => {
|
|
284
|
-
if (!Temp.store[filePath]) return;
|
|
285
|
-
delete Temp.store[filePath];
|
|
286
|
-
dist_default.attempt.unlinkSync(filePath);
|
|
287
|
-
},
|
|
288
|
-
purgeSyncAll: () => {
|
|
289
|
-
for (const filePath in Temp.store) Temp.purgeSync(filePath);
|
|
290
|
-
},
|
|
291
|
-
truncate: (filePath) => {
|
|
292
|
-
const basename = path.basename(filePath);
|
|
293
|
-
if (basename.length <= LIMIT_BASENAME_LENGTH) return filePath;
|
|
294
|
-
const truncable = /^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(basename);
|
|
295
|
-
if (!truncable) return filePath;
|
|
296
|
-
const truncationLength = basename.length - LIMIT_BASENAME_LENGTH;
|
|
297
|
-
return `${filePath.slice(0, -basename.length)}${truncable[1]}${truncable[2].slice(0, -truncationLength)}${truncable[3]}`;
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
node_default(Temp.purgeSyncAll);
|
|
301
|
-
var temp_default = Temp;
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region ../../node_modules/.pnpm/atomically@2.0.3/node_modules/atomically/dist/index.js
|
|
305
|
-
function writeFileSync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
306
|
-
if (isString(options)) return writeFileSync(filePath, data, { encoding: options });
|
|
307
|
-
const timeout = Date.now() + ((options.timeout ?? DEFAULT_TIMEOUT_SYNC) || -1);
|
|
308
|
-
let tempDisposer = null;
|
|
309
|
-
let tempPath = null;
|
|
310
|
-
let fd = null;
|
|
311
|
-
try {
|
|
312
|
-
const filePathReal = dist_default.attempt.realpathSync(filePath);
|
|
313
|
-
const filePathExists = !!filePathReal;
|
|
314
|
-
filePath = filePathReal || filePath;
|
|
315
|
-
[tempPath, tempDisposer] = temp_default.get(filePath, options.tmpCreate || temp_default.create, !(options.tmpPurge === false));
|
|
316
|
-
const useStatChown = IS_POSIX && isUndefined(options.chown);
|
|
317
|
-
const useStatMode = isUndefined(options.mode);
|
|
318
|
-
if (filePathExists && (useStatChown || useStatMode)) {
|
|
319
|
-
const stats = dist_default.attempt.statSync(filePath);
|
|
320
|
-
if (stats) {
|
|
321
|
-
options = { ...options };
|
|
322
|
-
if (useStatChown) options.chown = {
|
|
323
|
-
uid: stats.uid,
|
|
324
|
-
gid: stats.gid
|
|
325
|
-
};
|
|
326
|
-
if (useStatMode) options.mode = stats.mode;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (!filePathExists) {
|
|
330
|
-
const parentPath = path.dirname(filePath);
|
|
331
|
-
dist_default.attempt.mkdirSync(parentPath, {
|
|
332
|
-
mode: DEFAULT_FOLDER_MODE,
|
|
333
|
-
recursive: true
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
fd = dist_default.retry.openSync(timeout)(tempPath, "w", options.mode || DEFAULT_FILE_MODE);
|
|
337
|
-
if (options.tmpCreated) options.tmpCreated(tempPath);
|
|
338
|
-
if (isString(data)) dist_default.retry.writeSync(timeout)(fd, data, 0, options.encoding || DEFAULT_ENCODING);
|
|
339
|
-
else if (!isUndefined(data)) dist_default.retry.writeSync(timeout)(fd, data, 0, data.length, 0);
|
|
340
|
-
if (options.fsync !== false) if (options.fsyncWait !== false) dist_default.retry.fsyncSync(timeout)(fd);
|
|
341
|
-
else dist_default.attempt.fsync(fd);
|
|
342
|
-
dist_default.retry.closeSync(timeout)(fd);
|
|
343
|
-
fd = null;
|
|
344
|
-
if (options.chown && (options.chown.uid !== DEFAULT_USER_UID || options.chown.gid !== DEFAULT_USER_GID)) dist_default.attempt.chownSync(tempPath, options.chown.uid, options.chown.gid);
|
|
345
|
-
if (options.mode && options.mode !== DEFAULT_FILE_MODE) dist_default.attempt.chmodSync(tempPath, options.mode);
|
|
346
|
-
try {
|
|
347
|
-
dist_default.retry.renameSync(timeout)(tempPath, filePath);
|
|
348
|
-
} catch (error) {
|
|
349
|
-
if (!isException(error)) throw error;
|
|
350
|
-
if (error.code !== "ENAMETOOLONG") throw error;
|
|
351
|
-
dist_default.retry.renameSync(timeout)(tempPath, temp_default.truncate(filePath));
|
|
352
|
-
}
|
|
353
|
-
tempDisposer();
|
|
354
|
-
tempPath = null;
|
|
355
|
-
} finally {
|
|
356
|
-
if (fd) dist_default.attempt.closeSync(fd);
|
|
357
|
-
if (tempPath) temp_default.purge(tempPath);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
//#endregion
|
|
362
|
-
export { writeFileSync as t };
|
|
1
|
+
import{promisify as e}from"node:util";import t from"node:path";import n from"node:fs";import r from"node:os";import i from"node:process";const a=(e,t)=>function n(...r){return e.apply(void 0,r).catch(t)},o=(e,t)=>function n(...r){try{return e.apply(void 0,r)}catch(e){return t(e)}},s=i.getuid?!i.getuid():!1,c=()=>void 0,l={isChangeErrorOk:e=>{if(!l.isNodeError(e))return!1;let{code:t}=e;return t===`ENOSYS`||!s&&(t===`EINVAL`||t===`EPERM`)},isNodeError:e=>e instanceof Error,isRetriableError:e=>{if(!l.isNodeError(e))return!1;let{code:t}=e;return t===`EMFILE`||t===`ENFILE`||t===`EAGAIN`||t===`EBUSY`||t===`EACCESS`||t===`EACCES`||t===`EACCS`||t===`EPERM`},onChangeError:e=>{if(!l.isNodeError(e)||!l.isChangeErrorOk(e))throw e}};var u=class{constructor(){this.interval=25,this.intervalId=void 0,this.limit=1e4,this.queueActive=new Set,this.queueWaiting=new Set,this.init=()=>{this.intervalId||=setInterval(this.tick,this.interval)},this.reset=()=>{this.intervalId&&(clearInterval(this.intervalId),delete this.intervalId)},this.add=e=>{this.queueWaiting.add(e),this.queueActive.size<this.limit/2?this.tick():this.init()},this.remove=e=>{this.queueWaiting.delete(e),this.queueActive.delete(e)},this.schedule=()=>new Promise(e=>{let t=()=>this.remove(n),n=()=>e(t);this.add(n)}),this.tick=()=>{if(!(this.queueActive.size>=this.limit)){if(!this.queueWaiting.size)return this.reset();for(let e of this.queueWaiting){if(this.queueActive.size>=this.limit)break;this.queueWaiting.delete(e),this.queueActive.add(e),e()}}}}},d=new u;const f=(e,t)=>function n(r){return function n(...i){return d.schedule().then(a=>{let o=e=>(a(),e),s=e=>{if(a(),Date.now()>=r)throw e;if(t(e)){let e=Math.round(100*Math.random());return new Promise(t=>setTimeout(t,e)).then(()=>n.apply(void 0,i))}throw e};return e.apply(void 0,i).then(o,s)})}},p=(e,t)=>function n(r){return function n(...i){try{return e.apply(void 0,i)}catch(e){if(Date.now()>r)throw e;if(t(e))return n.apply(void 0,i);throw e}}},m={attempt:{chmod:a(e(n.chmod),l.onChangeError),chown:a(e(n.chown),l.onChangeError),close:a(e(n.close),c),fsync:a(e(n.fsync),c),mkdir:a(e(n.mkdir),c),realpath:a(e(n.realpath),c),stat:a(e(n.stat),c),unlink:a(e(n.unlink),c),chmodSync:o(n.chmodSync,l.onChangeError),chownSync:o(n.chownSync,l.onChangeError),closeSync:o(n.closeSync,c),existsSync:o(n.existsSync,c),fsyncSync:o(n.fsync,c),mkdirSync:o(n.mkdirSync,c),realpathSync:o(n.realpathSync,c),statSync:o(n.statSync,c),unlinkSync:o(n.unlinkSync,c)},retry:{close:f(e(n.close),l.isRetriableError),fsync:f(e(n.fsync),l.isRetriableError),open:f(e(n.open),l.isRetriableError),readFile:f(e(n.readFile),l.isRetriableError),rename:f(e(n.rename),l.isRetriableError),stat:f(e(n.stat),l.isRetriableError),write:f(e(n.write),l.isRetriableError),writeFile:f(e(n.writeFile),l.isRetriableError),closeSync:p(n.closeSync,l.isRetriableError),fsyncSync:p(n.fsyncSync,l.isRetriableError),openSync:p(n.openSync,l.isRetriableError),readFileSync:p(n.readFileSync,l.isRetriableError),renameSync:p(n.renameSync,l.isRetriableError),statSync:p(n.statSync,l.isRetriableError),writeSync:p(n.writeSync,l.isRetriableError),writeFileSync:p(n.writeFileSync,l.isRetriableError)}},h={},g=r.userInfo().uid,_=r.userInfo().gid,v=!!i.getuid;i.getuid&&i.getuid();const y=e=>e instanceof Error&&`code`in e,b=e=>typeof e==`string`,x=e=>e===void 0,S=i.platform===`linux`,C=i.platform===`win32`,w=[`SIGABRT`,`SIGALRM`,`SIGHUP`,`SIGINT`,`SIGTERM`];C||w.push(`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),S&&w.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`,`SIGUNUSED`);var T=class{constructor(){this.callbacks=new Set,this.exited=!1,this.exit=e=>{if(!this.exited){this.exited=!0;for(let e of this.callbacks)e();e&&(C&&e!==`SIGINT`&&e!==`SIGTERM`&&e!==`SIGKILL`?i.kill(i.pid,`SIGTERM`):i.kill(i.pid,e))}},this.hook=()=>{i.once(`exit`,()=>this.exit());for(let e of w)try{i.once(e,()=>this.exit(e))}catch{}},this.register=e=>(this.callbacks.add(e),()=>{this.callbacks.delete(e)}),this.hook()}};const E=new T().register,D={store:{},create:e=>{let t=`000000${Math.floor(Math.random()*16777215).toString(16)}`.slice(-6);return`${e}${`.tmp-${Date.now().toString().slice(-10)}${t}`}`},get:(e,t,n=!0)=>{let r=D.truncate(t(e));if(r in D.store)return D.get(e,t,n);D.store[r]=n;let i=()=>delete D.store[r];return[r,i]},purge:e=>{D.store[e]&&(delete D.store[e],m.attempt.unlink(e))},purgeSync:e=>{D.store[e]&&(delete D.store[e],m.attempt.unlinkSync(e))},purgeSyncAll:()=>{for(let e in D.store)D.purgeSync(e)},truncate:e=>{let n=t.basename(e);if(n.length<=128)return e;let r=/^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(n);if(!r)return e;let i=n.length-128;return`${e.slice(0,-n.length)}${r[1]}${r[2].slice(0,-i)}${r[3]}`}};E(D.purgeSyncAll);function O(e,n,r=h){if(b(r))return O(e,n,{encoding:r});let i=Date.now()+((r.timeout??1e3)||-1),a=null,o=null,s=null;try{let c=m.attempt.realpathSync(e),l=!!c;e=c||e,[o,a]=D.get(e,r.tmpCreate||D.create,r.tmpPurge!==!1);let u=v&&x(r.chown),d=x(r.mode);if(l&&(u||d)){let t=m.attempt.statSync(e);t&&(r={...r},u&&(r.chown={uid:t.uid,gid:t.gid}),d&&(r.mode=t.mode))}if(!l){let n=t.dirname(e);m.attempt.mkdirSync(n,{mode:511,recursive:!0})}s=m.retry.openSync(i)(o,`w`,r.mode||438),r.tmpCreated&&r.tmpCreated(o),b(n)?m.retry.writeSync(i)(s,n,0,r.encoding||`utf8`):x(n)||m.retry.writeSync(i)(s,n,0,n.length,0),r.fsync!==!1&&(r.fsyncWait===!1?m.attempt.fsync(s):m.retry.fsyncSync(i)(s)),m.retry.closeSync(i)(s),s=null,r.chown&&(r.chown.uid!==g||r.chown.gid!==_)&&m.attempt.chownSync(o,r.chown.uid,r.chown.gid),r.mode&&r.mode!==438&&m.attempt.chmodSync(o,r.mode);try{m.retry.renameSync(i)(o,e)}catch(t){if(!y(t)||t.code!==`ENAMETOOLONG`)throw t;m.retry.renameSync(i)(o,D.truncate(e))}a(),o=null}finally{s&&m.attempt.closeSync(s),o&&D.purge(o)}}export{O as t};
|
|
@@ -1,201 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const TYPE_REQUEST = "q";
|
|
3
|
-
const TYPE_RESPONSE = "s";
|
|
4
|
-
function createPromiseWithResolvers() {
|
|
5
|
-
let resolve;
|
|
6
|
-
let reject;
|
|
7
|
-
return {
|
|
8
|
-
promise: new Promise((res, rej) => {
|
|
9
|
-
resolve = res;
|
|
10
|
-
reject = rej;
|
|
11
|
-
}),
|
|
12
|
-
resolve,
|
|
13
|
-
reject
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const random = Math.random.bind(Math);
|
|
17
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
18
|
-
function nanoid(size = 21) {
|
|
19
|
-
let id = "";
|
|
20
|
-
let i = size;
|
|
21
|
-
while (i--) id += urlAlphabet[random() * 64 | 0];
|
|
22
|
-
return id;
|
|
23
|
-
}
|
|
24
|
-
const DEFAULT_TIMEOUT = 6e4;
|
|
25
|
-
const defaultSerialize = (i) => i;
|
|
26
|
-
const defaultDeserialize = defaultSerialize;
|
|
27
|
-
const { clearTimeout, setTimeout } = globalThis;
|
|
28
|
-
function createBirpc($functions, options) {
|
|
29
|
-
const { post, on, off = () => {}, eventNames = [], serialize = defaultSerialize, deserialize = defaultDeserialize, resolver, bind = "rpc", timeout = DEFAULT_TIMEOUT, proxify = true } = options;
|
|
30
|
-
let $closed = false;
|
|
31
|
-
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
32
|
-
let _promiseInit;
|
|
33
|
-
let rpc;
|
|
34
|
-
async function _call(method, args, event, optional) {
|
|
35
|
-
if ($closed) throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
36
|
-
const req = {
|
|
37
|
-
m: method,
|
|
38
|
-
a: args,
|
|
39
|
-
t: TYPE_REQUEST
|
|
40
|
-
};
|
|
41
|
-
if (optional) req.o = true;
|
|
42
|
-
const send = async (_req) => post(serialize(_req));
|
|
43
|
-
if (event) {
|
|
44
|
-
await send(req);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (_promiseInit) try {
|
|
48
|
-
await _promiseInit;
|
|
49
|
-
} finally {
|
|
50
|
-
_promiseInit = void 0;
|
|
51
|
-
}
|
|
52
|
-
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
53
|
-
const id = nanoid();
|
|
54
|
-
req.i = id;
|
|
55
|
-
let timeoutId;
|
|
56
|
-
async function handler(newReq = req) {
|
|
57
|
-
if (timeout >= 0) {
|
|
58
|
-
timeoutId = setTimeout(() => {
|
|
59
|
-
try {
|
|
60
|
-
if (options.onTimeoutError?.call(rpc, method, args) !== true) throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
reject(e);
|
|
63
|
-
}
|
|
64
|
-
_rpcPromiseMap.delete(id);
|
|
65
|
-
}, timeout);
|
|
66
|
-
if (typeof timeoutId === "object") timeoutId = timeoutId.unref?.();
|
|
67
|
-
}
|
|
68
|
-
_rpcPromiseMap.set(id, {
|
|
69
|
-
resolve,
|
|
70
|
-
reject,
|
|
71
|
-
timeoutId,
|
|
72
|
-
method
|
|
73
|
-
});
|
|
74
|
-
await send(newReq);
|
|
75
|
-
return promise;
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
if (options.onRequest) await options.onRequest.call(rpc, req, handler, resolve);
|
|
79
|
-
else await handler();
|
|
80
|
-
} catch (e) {
|
|
81
|
-
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
82
|
-
return;
|
|
83
|
-
} finally {
|
|
84
|
-
clearTimeout(timeoutId);
|
|
85
|
-
_rpcPromiseMap.delete(id);
|
|
86
|
-
}
|
|
87
|
-
return promise;
|
|
88
|
-
}
|
|
89
|
-
const builtinMethods = {
|
|
90
|
-
$call: (method, ...args) => _call(method, args, false),
|
|
91
|
-
$callOptional: (method, ...args) => _call(method, args, false, true),
|
|
92
|
-
$callEvent: (method, ...args) => _call(method, args, true),
|
|
93
|
-
$callRaw: (options$1) => _call(options$1.method, options$1.args, options$1.event, options$1.optional),
|
|
94
|
-
$rejectPendingCalls,
|
|
95
|
-
get $closed() {
|
|
96
|
-
return $closed;
|
|
97
|
-
},
|
|
98
|
-
get $meta() {
|
|
99
|
-
return options.meta;
|
|
100
|
-
},
|
|
101
|
-
$close,
|
|
102
|
-
$functions
|
|
103
|
-
};
|
|
104
|
-
if (proxify) rpc = new Proxy({}, { get(_, method) {
|
|
105
|
-
if (Object.prototype.hasOwnProperty.call(builtinMethods, method)) return builtinMethods[method];
|
|
106
|
-
if (method === "then" && !eventNames.includes("then") && !("then" in $functions)) return void 0;
|
|
107
|
-
const sendEvent = (...args) => _call(method, args, true);
|
|
108
|
-
if (eventNames.includes(method)) {
|
|
109
|
-
sendEvent.asEvent = sendEvent;
|
|
110
|
-
return sendEvent;
|
|
111
|
-
}
|
|
112
|
-
const sendCall = (...args) => _call(method, args, false);
|
|
113
|
-
sendCall.asEvent = sendEvent;
|
|
114
|
-
return sendCall;
|
|
115
|
-
} });
|
|
116
|
-
else rpc = builtinMethods;
|
|
117
|
-
function $close(customError) {
|
|
118
|
-
$closed = true;
|
|
119
|
-
_rpcPromiseMap.forEach(({ reject, method }) => {
|
|
120
|
-
const error = /* @__PURE__ */ new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
121
|
-
if (customError) {
|
|
122
|
-
customError.cause ??= error;
|
|
123
|
-
return reject(customError);
|
|
124
|
-
}
|
|
125
|
-
reject(error);
|
|
126
|
-
});
|
|
127
|
-
_rpcPromiseMap.clear();
|
|
128
|
-
off(onMessage);
|
|
129
|
-
}
|
|
130
|
-
function $rejectPendingCalls(handler) {
|
|
131
|
-
const handlerResults = Array.from(_rpcPromiseMap.values()).map(({ method, reject }) => {
|
|
132
|
-
if (!handler) return reject(/* @__PURE__ */ new Error(`[birpc]: rejected pending call "${method}".`));
|
|
133
|
-
return handler({
|
|
134
|
-
method,
|
|
135
|
-
reject
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
_rpcPromiseMap.clear();
|
|
139
|
-
return handlerResults;
|
|
140
|
-
}
|
|
141
|
-
async function onMessage(data, ...extra) {
|
|
142
|
-
let msg;
|
|
143
|
-
try {
|
|
144
|
-
msg = deserialize(data);
|
|
145
|
-
} catch (e) {
|
|
146
|
-
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (msg.t === TYPE_REQUEST) {
|
|
150
|
-
const { m: method, a: args, o: optional } = msg;
|
|
151
|
-
let result, error;
|
|
152
|
-
let fn = await (resolver ? resolver.call(rpc, method, $functions[method]) : $functions[method]);
|
|
153
|
-
if (optional) fn ||= () => void 0;
|
|
154
|
-
if (!fn) error = /* @__PURE__ */ new Error(`[birpc] function "${method}" not found`);
|
|
155
|
-
else try {
|
|
156
|
-
result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
error = e;
|
|
159
|
-
}
|
|
160
|
-
if (msg.i) {
|
|
161
|
-
if (error && options.onFunctionError) {
|
|
162
|
-
if (options.onFunctionError.call(rpc, error, method, args) === true) return;
|
|
163
|
-
}
|
|
164
|
-
if (!error) try {
|
|
165
|
-
await post(serialize({
|
|
166
|
-
t: TYPE_RESPONSE,
|
|
167
|
-
i: msg.i,
|
|
168
|
-
r: result
|
|
169
|
-
}), ...extra);
|
|
170
|
-
return;
|
|
171
|
-
} catch (e) {
|
|
172
|
-
error = e;
|
|
173
|
-
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
await post(serialize({
|
|
177
|
-
t: TYPE_RESPONSE,
|
|
178
|
-
i: msg.i,
|
|
179
|
-
e: error
|
|
180
|
-
}), ...extra);
|
|
181
|
-
} catch (e) {
|
|
182
|
-
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
const { i: ack, r: result, e: error } = msg;
|
|
187
|
-
const promise = _rpcPromiseMap.get(ack);
|
|
188
|
-
if (promise) {
|
|
189
|
-
clearTimeout(promise.timeoutId);
|
|
190
|
-
if (error) promise.reject(error);
|
|
191
|
-
else promise.resolve(result);
|
|
192
|
-
}
|
|
193
|
-
_rpcPromiseMap.delete(ack);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
_promiseInit = on(onMessage);
|
|
197
|
-
return rpc;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
export { createBirpc as t };
|
|
1
|
+
function e(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}const t=Math.random.bind(Math);function n(e=21){let n=``,r=e;for(;r--;)n+=`useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict`[t()*64|0];return n}const r=e=>e,i=r,{clearTimeout:a,setTimeout:o}=globalThis;function s(t,s){let{post:c,on:l,off:u=()=>{},eventNames:d=[],serialize:f=r,deserialize:p=i,resolver:m,bind:h=`rpc`,timeout:g=6e4,proxify:_=!0}=s,v=!1,y=new Map,b,x;async function S(t,r,i,l){if(v)throw Error(`[birpc] rpc is closed, cannot call "${t}"`);let u={m:t,a:r,t:`q`};l&&(u.o=!0);let d=async e=>c(f(e));if(i){await d(u);return}if(b)try{await b}finally{b=void 0}let{promise:p,resolve:m,reject:h}=e(),_=n();u.i=_;let S;async function C(e=u){return g>=0&&(S=o(()=>{try{if(s.onTimeoutError?.call(x,t,r)!==!0)throw Error(`[birpc] timeout on calling "${t}"`)}catch(e){h(e)}y.delete(_)},g),typeof S==`object`&&(S=S.unref?.())),y.set(_,{resolve:m,reject:h,timeoutId:S,method:t}),await d(e),p}try{s.onRequest?await s.onRequest.call(x,u,C,m):await C()}catch(e){if(s.onGeneralError?.call(x,e)!==!0)throw e;return}finally{a(S),y.delete(_)}return p}let C={$call:(e,...t)=>S(e,t,!1),$callOptional:(e,...t)=>S(e,t,!1,!0),$callEvent:(e,...t)=>S(e,t,!0),$callRaw:e=>S(e.method,e.args,e.event,e.optional),$rejectPendingCalls:T,get $closed(){return v},get $meta(){return s.meta},$close:w,$functions:t};x=_?new Proxy({},{get(e,n){if(Object.prototype.hasOwnProperty.call(C,n))return C[n];if(n===`then`&&!d.includes(`then`)&&!(`then`in t))return;let r=(...e)=>S(n,e,!0);if(d.includes(n))return r.asEvent=r,r;let i=(...e)=>S(n,e,!1);return i.asEvent=r,i}}):C;function w(e){v=!0,y.forEach(({reject:t,method:n})=>{let r=Error(`[birpc] rpc is closed, cannot call "${n}"`);if(e)return e.cause??=r,t(e);t(r)}),y.clear(),u(E)}function T(e){let t=Array.from(y.values()).map(({method:t,reject:n})=>e?e({method:t,reject:n}):n(Error(`[birpc]: rejected pending call "${t}".`)));return y.clear(),t}async function E(e,...n){let r;try{r=p(e)}catch(e){if(s.onGeneralError?.call(x,e)!==!0)throw e;return}if(r.t===`q`){let{m:e,a:i,o:a}=r,o,l,u=await(m?m.call(x,e,t[e]):t[e]);if(a&&(u||=()=>void 0),!u)l=Error(`[birpc] function "${e}" not found`);else try{o=await u.apply(h===`rpc`?x:t,i)}catch(e){l=e}if(r.i){if(l&&s.onFunctionError&&s.onFunctionError.call(x,l,e,i)===!0)return;if(!l)try{await c(f({t:`s`,i:r.i,r:o}),...n);return}catch(t){if(l=t,s.onGeneralError?.call(x,t,e,i)!==!0)throw t}try{await c(f({t:`s`,i:r.i,e:l}),...n)}catch(t){if(s.onGeneralError?.call(x,t,e,i)!==!0)throw t}}}else{let{i:e,r:t,e:n}=r,i=y.get(e);i&&(a(i.timeoutId),n?i.reject(n):i.resolve(t)),y.delete(e)}}return b=l(E),x}export{s as t};
|