devframe 0.9.0-beta.4 → 0.9.0-beta.5

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.
Files changed (65) hide show
  1. package/dist/{_shared-CGPVmXUM.mjs → _shared-CKZPvSrN.mjs} +2 -1
  2. package/dist/{_shared-Bm8p4-fD.d.mts → _shared-QkI6ljJS.d.mts} +2 -2
  3. package/dist/adapters/build.d.mts +10 -12
  4. package/dist/adapters/build.mjs +23 -27
  5. package/dist/adapters/cac.d.mts +1 -1
  6. package/dist/adapters/cac.mjs +3 -4
  7. package/dist/adapters/dev.d.mts +19 -5
  8. package/dist/adapters/dev.mjs +2 -2
  9. package/dist/adapters/embedded.d.mts +1 -1
  10. package/dist/adapters/initiate.d.mts +4 -3
  11. package/dist/adapters/initiate.mjs +1 -1
  12. package/dist/adapters/mcp.d.mts +1 -1
  13. package/dist/adapters/mcp.mjs +1 -1
  14. package/dist/cli/main.mjs +2 -2
  15. package/dist/client/index.d.mts +1 -1
  16. package/dist/client/index.mjs +2 -1175
  17. package/dist/constants.d.mts +1 -2
  18. package/dist/constants.mjs +1 -2
  19. package/dist/{context-DV4uWieM.d.mts → context-CQkRTbAc.d.mts} +1 -1
  20. package/dist/{context-b6iSomtv.mjs → context-D0HD0F7C.mjs} +19 -7
  21. package/dist/{context-CMSryXs-.mjs → context-D0jErmlx.mjs} +1 -1
  22. package/dist/{dev-4xjiynUD.mjs → dev-QEuT8SOF.mjs} +15 -9
  23. package/dist/{devframe-5oblos7I.d.mts → devframe-Cfx6doi4.d.mts} +41 -64
  24. package/dist/{diagnostics-C7IGWppM.mjs → diagnostics-DEuH3P5O.mjs} +32 -0
  25. package/dist/{host-agent-BBkKT27Q.mjs → host-agent-C5HjzfBz.mjs} +41 -3
  26. package/dist/{host-h3-CzCZwtuV.mjs → host-h3-Crkzm42q.mjs} +2 -2
  27. package/dist/{http-Z0w9baEe.mjs → http-CVwj7b4g.mjs} +2 -2
  28. package/dist/{index-BzDl02lt.d.mts → index-MYi1SZVL.d.mts} +2 -2
  29. package/dist/index.d.mts +3 -2
  30. package/dist/{instance-registry-Du_hbx-j.mjs → instance-registry-M2p-z6xE.mjs} +1 -1
  31. package/dist/{instance-shell-B0TwOxCl.mjs → instance-shell-DJ8s-MFw.mjs} +5 -5
  32. package/dist/{instance-shell-B-BSVp37.d.mts → instance-shell-D_UA0Idz.d.mts} +2 -2
  33. package/dist/internal/index.d.mts +72 -10
  34. package/dist/internal/index.mjs +7 -7
  35. package/dist/node/auth.d.mts +2 -2
  36. package/dist/node/auth.mjs +1 -1
  37. package/dist/node/hub-internals.d.mts +2 -2
  38. package/dist/node/hub-internals.mjs +2 -2
  39. package/dist/node/index.d.mts +1 -1
  40. package/dist/node/index.mjs +2 -2
  41. package/dist/recipes/common-rpc-functions.d.mts +1 -1
  42. package/dist/recipes/interactive-auth.d.mts +2 -2
  43. package/dist/recipes/interactive-auth.mjs +2 -2
  44. package/dist/remote-assets-DclsYyoL.d.mts +106 -0
  45. package/dist/rpc/transports/ws-bun.d.mts +1 -1
  46. package/dist/{rpc-core-B4Qm66Qt.d.mts → rpc-core-C8JQ3p7A.d.mts} +2 -2
  47. package/dist/{rpc-core-Cva-0pw0.mjs → rpc-core-IhcWl_xn.mjs} +1 -1
  48. package/dist/state-Cc1IeSmQ.mjs +1291 -0
  49. package/dist/storage-BVuipbGS.mjs +137 -0
  50. package/dist/types/index.d.mts +3 -2
  51. package/dist/utils/events.d.mts +1 -1
  52. package/dist/utils/open.d.mts +2 -10
  53. package/dist/utils/open.mjs +56 -1
  54. package/dist/utils/remote-assets.d.mts +15 -0
  55. package/dist/utils/remote-assets.mjs +309 -0
  56. package/dist/utils/serve-static.d.mts +13 -5
  57. package/dist/utils/serve-static.mjs +103 -9
  58. package/dist/utils/shared-state.d.mts +1 -1
  59. package/dist/utils/streaming-channel.d.mts +1 -1
  60. package/package.json +2 -3
  61. package/skills/devframe/SKILL.md +4 -5
  62. package/dist/open-Dz4V4irZ.mjs +0 -547
  63. package/dist/state-BeUHDDjk.mjs +0 -108
  64. package/dist/storage-CaUVrBrG.mjs +0 -1122
  65. package/skills/devframe/templates/spa-devframe.ts +0 -38
@@ -1,1122 +0,0 @@
1
- import { t as diagnostics } from "./diagnostics-C7IGWppM.mjs";
2
- import fs from "node:fs";
3
- import { dirname } from "pathe";
4
- import process$1 from "node:process";
5
- import { destr } from "destr";
6
- //#region src/utils/events.ts
7
- /**
8
- * Create event emitter.
9
- */
10
- function createEventEmitter() {
11
- const _listeners = {};
12
- function emit(event, ...args) {
13
- const callbacks = _listeners[event] || [];
14
- for (let i = 0, length = callbacks.length; i < length; i++) {
15
- const callback = callbacks[i];
16
- if (callback) callback(...args);
17
- }
18
- }
19
- function emitOnce(event, ...args) {
20
- emit(event, ...args);
21
- delete _listeners[event];
22
- }
23
- function on(event, cb) {
24
- (_listeners[event] ||= []).push(cb);
25
- return () => {
26
- _listeners[event] = _listeners[event]?.filter((i) => cb !== i);
27
- };
28
- }
29
- function once(event, cb) {
30
- const unsubscribe = on(event, ((...args) => {
31
- unsubscribe();
32
- return cb(...args);
33
- }));
34
- return unsubscribe;
35
- }
36
- return {
37
- _listeners,
38
- emit,
39
- emitOnce,
40
- on,
41
- once
42
- };
43
- }
44
- //#endregion
45
- //#region ../../node_modules/.pnpm/immer@11.1.16/node_modules/immer/dist/immer.mjs
46
- var NOTHING = Symbol.for("immer-nothing");
47
- var DRAFTABLE = Symbol.for("immer-draftable");
48
- var DRAFT_STATE = Symbol.for("immer-state");
49
- var errors = process.env.NODE_ENV !== "production" ? [
50
- function(plugin) {
51
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
52
- },
53
- function(thing) {
54
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
55
- },
56
- "This object has been frozen and should not be mutated",
57
- function(data) {
58
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
59
- },
60
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
61
- "Immer forbids circular references",
62
- "The first or second argument to `produce` must be a function",
63
- "The third argument to `produce` must be a function or undefined",
64
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
65
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
66
- function(thing) {
67
- return `'current' expects a draft, got: ${thing}`;
68
- },
69
- "Object.defineProperty() cannot be used on an Immer draft",
70
- "Object.setPrototypeOf() cannot be used on an Immer draft",
71
- "Immer only supports deleting array indices",
72
- "Immer only supports setting array indices and the 'length' property",
73
- function(thing) {
74
- return `'original' expects a draft, got: ${thing}`;
75
- }
76
- ] : [];
77
- function die(error, ...args) {
78
- if (process.env.NODE_ENV !== "production") {
79
- const e = errors[error];
80
- const msg = isFunction(e) ? e.apply(null, args) : e;
81
- throw new Error(`[Immer] ${msg}`);
82
- }
83
- throw new Error(`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`);
84
- }
85
- var O = Object;
86
- var getPrototypeOf = O.getPrototypeOf;
87
- var CONSTRUCTOR = "constructor";
88
- var PROTOTYPE = "prototype";
89
- var CONFIGURABLE = "configurable";
90
- var ENUMERABLE = "enumerable";
91
- var WRITABLE = "writable";
92
- var VALUE = "value";
93
- var isDraft = (value) => !!value && !!value[DRAFT_STATE];
94
- function isDraftable(value) {
95
- if (!value) return false;
96
- return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);
97
- }
98
- var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();
99
- var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
100
- function isPlainObject(value) {
101
- if (!value || !isObjectish(value)) return false;
102
- const proto = getPrototypeOf(value);
103
- if (proto === null || proto === O[PROTOTYPE]) return true;
104
- const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];
105
- if (Ctor === Object) return true;
106
- if (!isFunction(Ctor)) return false;
107
- let ctorString = cachedCtorStrings.get(Ctor);
108
- if (ctorString === void 0) {
109
- ctorString = Function.toString.call(Ctor);
110
- cachedCtorStrings.set(Ctor, ctorString);
111
- }
112
- return ctorString === objectCtorString;
113
- }
114
- function each(obj, iter, strict = true) {
115
- if (getArchtype(obj) === 0) (strict ? Reflect.ownKeys(obj) : O.keys(obj)).forEach((key) => {
116
- iter(key, obj[key], obj);
117
- });
118
- else obj.forEach((entry, index) => iter(index, entry, obj));
119
- }
120
- function getArchtype(thing) {
121
- const state = thing[DRAFT_STATE];
122
- return state ? state.type_ : isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
123
- }
124
- var has = (thing, prop, type = getArchtype(thing)) => type === 2 ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);
125
- var get = (thing, prop, type = getArchtype(thing)) => type === 2 ? thing.get(prop) : thing[prop];
126
- var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {
127
- if (type === 2) thing.set(propOrOldValue, value);
128
- else if (type === 3) thing.add(value);
129
- else thing[propOrOldValue] = value;
130
- };
131
- function is(x, y) {
132
- if (x === y) return x !== 0 || 1 / x === 1 / y;
133
- else return x !== x && y !== y;
134
- }
135
- var isArray = Array.isArray;
136
- var isMap = (target) => target instanceof Map;
137
- var isSet = (target) => target instanceof Set;
138
- var isObjectish = (target) => typeof target === "object";
139
- var isFunction = (target) => typeof target === "function";
140
- var isBoolean = (target) => typeof target === "boolean";
141
- function isArrayIndex(value) {
142
- const n = +value;
143
- return Number.isInteger(n) && String(n) === value;
144
- }
145
- var getProxyDraft = (value) => {
146
- if (!isObjectish(value)) return null;
147
- return value?.[DRAFT_STATE];
148
- };
149
- var latest = (state) => state.copy_ || state.base_;
150
- var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
151
- function shallowCopy(base, strict) {
152
- if (isMap(base)) return new Map(base);
153
- if (isSet(base)) return new Set(base);
154
- if (isArray(base)) return Array[PROTOTYPE].slice.call(base);
155
- const isPlain = isPlainObject(base);
156
- if (strict === true || strict === "class_only" && !isPlain) {
157
- const descriptors = O.getOwnPropertyDescriptors(base);
158
- delete descriptors[DRAFT_STATE];
159
- let keys = Reflect.ownKeys(descriptors);
160
- for (let i = 0; i < keys.length; i++) {
161
- const key = keys[i];
162
- const desc = descriptors[key];
163
- if (desc[WRITABLE] === false) {
164
- desc[WRITABLE] = true;
165
- desc[CONFIGURABLE] = true;
166
- }
167
- if (desc.get || desc.set) descriptors[key] = {
168
- [CONFIGURABLE]: true,
169
- [WRITABLE]: true,
170
- [ENUMERABLE]: desc[ENUMERABLE],
171
- [VALUE]: base[key]
172
- };
173
- }
174
- return O.create(getPrototypeOf(base), descriptors);
175
- } else {
176
- const proto = getPrototypeOf(base);
177
- if (proto !== null && isPlain) return { ...base };
178
- const obj = O.create(proto);
179
- return O.assign(obj, base);
180
- }
181
- }
182
- function freeze(obj, deep = false) {
183
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
184
- if (getArchtype(obj) > 1) O.defineProperties(obj, {
185
- set: dontMutateMethodOverride,
186
- add: dontMutateMethodOverride,
187
- clear: dontMutateMethodOverride,
188
- delete: dontMutateMethodOverride
189
- });
190
- O.freeze(obj);
191
- if (deep) each(obj, (_key, value) => {
192
- freeze(value, true);
193
- }, false);
194
- return obj;
195
- }
196
- function dontMutateFrozenCollections() {
197
- die(2);
198
- }
199
- var dontMutateMethodOverride = { [VALUE]: dontMutateFrozenCollections };
200
- function isFrozen(obj) {
201
- if (obj === null || !isObjectish(obj)) return true;
202
- return O.isFrozen(obj);
203
- }
204
- var PluginMapSet = "MapSet";
205
- var PluginPatches = "Patches";
206
- var PluginArrayMethods = "ArrayMethods";
207
- var plugins = {};
208
- function getPlugin(pluginKey) {
209
- const plugin = plugins[pluginKey];
210
- if (!plugin) die(0, pluginKey);
211
- return plugin;
212
- }
213
- var isPluginLoaded = (pluginKey) => !!plugins[pluginKey];
214
- function loadPlugin(pluginKey, implementation) {
215
- if (!plugins[pluginKey]) plugins[pluginKey] = implementation;
216
- }
217
- var currentScope;
218
- var getCurrentScope = () => currentScope;
219
- var createScope = (parent_, immer_) => ({
220
- drafts_: [],
221
- parent_,
222
- immer_,
223
- canAutoFreeze_: true,
224
- unfinalizedDrafts_: 0,
225
- handledSet_: /* @__PURE__ */ new Set(),
226
- processedForPatches_: /* @__PURE__ */ new Set(),
227
- mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
228
- arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
229
- });
230
- function usePatchesInScope(scope, patchListener) {
231
- if (patchListener) {
232
- scope.patchPlugin_ = getPlugin(PluginPatches);
233
- scope.patches_ = [];
234
- scope.inversePatches_ = [];
235
- scope.patchListener_ = patchListener;
236
- }
237
- }
238
- function revokeScope(scope) {
239
- leaveScope(scope);
240
- scope.drafts_.forEach(revokeDraft);
241
- scope.drafts_ = null;
242
- }
243
- function leaveScope(scope) {
244
- if (scope === currentScope) currentScope = scope.parent_;
245
- }
246
- var enterScope = (immer2) => currentScope = createScope(currentScope, immer2);
247
- function revokeDraft(draft) {
248
- const state = draft[DRAFT_STATE];
249
- if (state.type_ === 0 || state.type_ === 1) state.revoke_();
250
- else state.revoked_ = true;
251
- }
252
- function processResult(result, scope) {
253
- scope.unfinalizedDrafts_ = scope.drafts_.length;
254
- const baseDraft = scope.drafts_[0];
255
- if (result !== void 0 && result !== baseDraft) {
256
- if (baseDraft[DRAFT_STATE].modified_) {
257
- revokeScope(scope);
258
- die(4);
259
- }
260
- if (isDraftable(result)) result = finalize(scope, result);
261
- const { patchPlugin_ } = scope;
262
- if (patchPlugin_) patchPlugin_.generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope);
263
- } else result = finalize(scope, baseDraft);
264
- maybeFreeze(scope, result, true);
265
- revokeScope(scope);
266
- if (scope.patches_) scope.patchListener_(scope.patches_, scope.inversePatches_);
267
- return result !== NOTHING ? result : void 0;
268
- }
269
- function finalize(rootScope, value) {
270
- if (isFrozen(value)) return value;
271
- const state = value[DRAFT_STATE];
272
- if (!state) return handleValue(value, rootScope.handledSet_, rootScope);
273
- if (!isSameScope(state, rootScope)) return value;
274
- if (!state.modified_) return state.base_;
275
- if (!state.finalized_) {
276
- const { callbacks_ } = state;
277
- if (callbacks_) while (callbacks_.length > 0) callbacks_.pop()(rootScope);
278
- generatePatchesAndFinalize(state, rootScope);
279
- }
280
- return state.copy_;
281
- }
282
- function maybeFreeze(scope, value, deep = false) {
283
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) freeze(value, deep);
284
- }
285
- function markStateFinalized(state) {
286
- state.finalized_ = true;
287
- state.scope_.unfinalizedDrafts_--;
288
- }
289
- var isSameScope = (state, rootScope) => state.scope_ === rootScope;
290
- var EMPTY_LOCATIONS_RESULT = [];
291
- function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {
292
- const parentCopy = latest(parent);
293
- const parentType = parent.type_;
294
- if (originalKey !== void 0) {
295
- if (get(parentCopy, originalKey, parentType) === draftValue) {
296
- set(parentCopy, originalKey, finalizedValue, parentType);
297
- return;
298
- }
299
- }
300
- if (!parent.draftLocations_) {
301
- const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();
302
- each(parentCopy, (key, value) => {
303
- if (isDraft(value)) {
304
- const keys = draftLocations.get(value) || [];
305
- keys.push(key);
306
- draftLocations.set(value, keys);
307
- }
308
- });
309
- }
310
- const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;
311
- for (const location of locations) set(parentCopy, location, finalizedValue, parentType);
312
- }
313
- function registerChildFinalizationCallback(parent, child, key) {
314
- parent.callbacks_.push(function childCleanup(rootScope) {
315
- const state = child;
316
- if (!state || !isSameScope(state, rootScope)) return;
317
- rootScope.mapSetPlugin_?.fixSetContents(state);
318
- const finalizedValue = getFinalValue(state);
319
- updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);
320
- generatePatchesAndFinalize(state, rootScope);
321
- });
322
- }
323
- function generatePatchesAndFinalize(state, rootScope) {
324
- if (state.modified_ && !state.finalized_ && (state.type_ === 3 || state.type_ === 1 && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0)) {
325
- const { patchPlugin_ } = rootScope;
326
- if (patchPlugin_) {
327
- const basePath = patchPlugin_.getPath(state);
328
- if (basePath) patchPlugin_.generatePatches_(state, basePath, rootScope);
329
- }
330
- markStateFinalized(state);
331
- }
332
- }
333
- function handleCrossReference(target, key, value) {
334
- const { scope_ } = target;
335
- if (isDraft(value)) {
336
- const state = value[DRAFT_STATE];
337
- if (isSameScope(state, scope_)) state.callbacks_.push(function crossReferenceCleanup() {
338
- prepareCopy(target);
339
- updateDraftInParent(target, value, getFinalValue(state), key);
340
- });
341
- } else if (isDraftable(value)) target.callbacks_.push(function nestedDraftCleanup() {
342
- const targetCopy = latest(target);
343
- if (target.type_ === 3) {
344
- if (targetCopy.has(value)) handleValue(value, scope_.handledSet_, scope_);
345
- } else if (get(targetCopy, key, target.type_) === value) {
346
- if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) handleValue(get(target.copy_, key, target.type_), scope_.handledSet_, scope_);
347
- }
348
- });
349
- }
350
- function handleValue(target, handledSet, rootScope) {
351
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) return target;
352
- if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) return target;
353
- handledSet.add(target);
354
- each(target, (key, value) => {
355
- if (isDraft(value)) {
356
- const state = value[DRAFT_STATE];
357
- if (isSameScope(state, rootScope)) {
358
- set(target, key, getFinalValue(state), target.type_);
359
- markStateFinalized(state);
360
- }
361
- } else if (isDraftable(value)) handleValue(value, handledSet, rootScope);
362
- });
363
- return target;
364
- }
365
- function createProxyProxy(base, parent) {
366
- const baseIsArray = isArray(base);
367
- const state = {
368
- type_: baseIsArray ? 1 : 0,
369
- scope_: parent ? parent.scope_ : getCurrentScope(),
370
- modified_: false,
371
- finalized_: false,
372
- assigned_: void 0,
373
- parent_: parent,
374
- base_: base,
375
- draft_: null,
376
- copy_: null,
377
- revoke_: null,
378
- isManual_: false,
379
- callbacks_: void 0
380
- };
381
- let target = state;
382
- let traps = objectTraps;
383
- if (baseIsArray) {
384
- target = [state];
385
- traps = arrayTraps;
386
- }
387
- const { revoke, proxy } = Proxy.revocable(target, traps);
388
- state.draft_ = proxy;
389
- state.revoke_ = revoke;
390
- return [proxy, state];
391
- }
392
- var objectTraps = {
393
- get(state, prop) {
394
- if (prop === DRAFT_STATE) return state;
395
- let arrayPlugin = state.scope_.arrayMethodsPlugin_;
396
- const isArrayWithStringProp = state.type_ === 1 && typeof prop === "string";
397
- if (isArrayWithStringProp) {
398
- if (arrayPlugin?.isArrayOperationMethod(prop)) return arrayPlugin.createMethodInterceptor(state, prop);
399
- }
400
- const source = latest(state);
401
- if (!has(source, prop, state.type_)) return readPropFromProto(state, source, prop);
402
- const value = source[prop];
403
- if (state.finalized_ || !isDraftable(value)) return value;
404
- if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(state.operationMethod) && isArrayIndex(prop)) return value;
405
- if (value === peek(state.base_, prop) || isRelocatedBaseRef(state, prop, value)) {
406
- prepareCopy(state);
407
- const childKey = state.type_ === 1 ? +prop : prop;
408
- const childDraft = createProxy(state.scope_, value, state, childKey);
409
- return state.copy_[childKey] = childDraft;
410
- }
411
- return value;
412
- },
413
- has(state, prop) {
414
- return prop in latest(state);
415
- },
416
- ownKeys(state) {
417
- return Reflect.ownKeys(latest(state));
418
- },
419
- set(state, prop, value) {
420
- const desc = getDescriptorFromProto(latest(state), prop);
421
- if (desc?.set) {
422
- desc.set.call(state.draft_, value);
423
- return true;
424
- }
425
- if (!state.modified_) {
426
- const current2 = peek(latest(state), prop);
427
- const currentState = current2?.[DRAFT_STATE];
428
- if (currentState && currentState.base_ === value) {
429
- state.copy_[prop] = value;
430
- state.assigned_.set(prop, false);
431
- return true;
432
- }
433
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_))) return true;
434
- prepareCopy(state);
435
- markChanged(state);
436
- }
437
- if (state.copy_[prop] === value && (value !== void 0 || has(state.copy_, prop, state.type_)) || Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
438
- state.copy_[prop] = value;
439
- state.assigned_.set(prop, true);
440
- handleCrossReference(state, prop, value);
441
- return true;
442
- },
443
- deleteProperty(state, prop) {
444
- prepareCopy(state);
445
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
446
- state.assigned_.set(prop, false);
447
- markChanged(state);
448
- } else state.assigned_.delete(prop);
449
- if (state.copy_) delete state.copy_[prop];
450
- return true;
451
- },
452
- getOwnPropertyDescriptor(state, prop) {
453
- const owner = latest(state);
454
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
455
- if (!desc) return desc;
456
- return {
457
- [WRITABLE]: true,
458
- [CONFIGURABLE]: state.type_ !== 1 || prop !== "length",
459
- [ENUMERABLE]: desc[ENUMERABLE],
460
- [VALUE]: owner[prop]
461
- };
462
- },
463
- defineProperty() {
464
- die(11);
465
- },
466
- getPrototypeOf(state) {
467
- return getPrototypeOf(state.base_);
468
- },
469
- setPrototypeOf() {
470
- die(12);
471
- }
472
- };
473
- var arrayTraps = {};
474
- for (let key in objectTraps) {
475
- let fn = objectTraps[key];
476
- arrayTraps[key] = function() {
477
- const args = arguments;
478
- args[0] = args[0][0];
479
- return fn.apply(this, args);
480
- };
481
- }
482
- arrayTraps.deleteProperty = function(state, prop) {
483
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13);
484
- return arrayTraps.set.call(this, state, prop, void 0);
485
- };
486
- arrayTraps.set = function(state, prop, value) {
487
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop))) die(14);
488
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
489
- };
490
- function peek(draft, prop) {
491
- const state = draft[DRAFT_STATE];
492
- return (state ? latest(state) : draft)[prop];
493
- }
494
- function isRelocatedBaseRef(state, prop, value) {
495
- if (state.type_ !== 1 || !state.allIndicesReassigned_ || state.assigned_?.get(prop) || !isDraftable(value) || value[DRAFT_STATE]) return false;
496
- return state.baseRefs_.has(value);
497
- }
498
- function readPropFromProto(state, source, prop) {
499
- const desc = getDescriptorFromProto(source, prop);
500
- return desc ? VALUE in desc ? desc[VALUE] : desc.get?.call(state.draft_) : void 0;
501
- }
502
- function getDescriptorFromProto(source, prop) {
503
- if (!(prop in source)) return void 0;
504
- let proto = getPrototypeOf(source);
505
- while (proto) {
506
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
507
- if (desc) return desc;
508
- proto = getPrototypeOf(proto);
509
- }
510
- }
511
- function markChanged(state) {
512
- if (!state.modified_) {
513
- state.modified_ = true;
514
- if (state.parent_) markChanged(state.parent_);
515
- }
516
- }
517
- function prepareCopy(state) {
518
- if (!state.copy_) {
519
- state.assigned_ = /* @__PURE__ */ new Map();
520
- state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
521
- }
522
- }
523
- var Immer2 = class {
524
- constructor(config) {
525
- this.autoFreeze_ = true;
526
- this.useStrictShallowCopy_ = false;
527
- this.useStrictIteration_ = false;
528
- /**
529
- * The `produce` function takes a value and a "recipe function" (whose
530
- * return value often depends on the base state). The recipe function is
531
- * free to mutate its first argument however it wants. All mutations are
532
- * only ever applied to a __copy__ of the base state.
533
- *
534
- * Pass only a function to create a "curried producer" which relieves you
535
- * from passing the recipe function every time.
536
- *
537
- * Only plain objects and arrays are made mutable. All other objects are
538
- * considered uncopyable.
539
- *
540
- * Note: This function is __bound__ to its `Immer` instance.
541
- *
542
- * @param {any} base - the initial state
543
- * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
544
- * @param {Function} patchListener - optional function that will be called with all the patches produced here
545
- * @returns {any} a new state, or the initial state if nothing was modified
546
- */
547
- this.produce = (base, recipe, patchListener) => {
548
- if (isFunction(base) && !isFunction(recipe)) {
549
- const defaultBase = recipe;
550
- recipe = base;
551
- const self = this;
552
- return function curriedProduce(base2 = defaultBase, ...args) {
553
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
554
- };
555
- }
556
- if (!isFunction(recipe)) die(6);
557
- if (patchListener !== void 0 && !isFunction(patchListener)) die(7);
558
- let result;
559
- if (isDraftable(base)) {
560
- const scope = enterScope(this);
561
- const proxy = createProxy(scope, base, void 0);
562
- let hasError = true;
563
- try {
564
- result = recipe(proxy);
565
- hasError = false;
566
- } finally {
567
- if (hasError) revokeScope(scope);
568
- else leaveScope(scope);
569
- }
570
- usePatchesInScope(scope, patchListener);
571
- return processResult(result, scope);
572
- } else if (!base || !isObjectish(base)) {
573
- result = recipe(base);
574
- if (result === void 0) result = base;
575
- if (result === NOTHING) result = void 0;
576
- if (this.autoFreeze_) freeze(result, true);
577
- if (patchListener) {
578
- const p = [];
579
- const ip = [];
580
- getPlugin(PluginPatches).generateReplacementPatches_(base, result, {
581
- patches_: p,
582
- inversePatches_: ip
583
- });
584
- patchListener(p, ip);
585
- }
586
- return result;
587
- } else die(1, base);
588
- };
589
- this.produceWithPatches = (base, recipe) => {
590
- if (isFunction(base)) return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
591
- let patches, inversePatches;
592
- return [
593
- this.produce(base, recipe, (p, ip) => {
594
- patches = p;
595
- inversePatches = ip;
596
- }),
597
- patches,
598
- inversePatches
599
- ];
600
- };
601
- if (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config.autoFreeze);
602
- if (isBoolean(config?.useStrictShallowCopy)) this.setUseStrictShallowCopy(config.useStrictShallowCopy);
603
- if (isBoolean(config?.useStrictIteration)) this.setUseStrictIteration(config.useStrictIteration);
604
- }
605
- createDraft(base) {
606
- if (!isDraftable(base)) die(8);
607
- if (isDraft(base)) base = current(base);
608
- const scope = enterScope(this);
609
- const proxy = createProxy(scope, base, void 0);
610
- proxy[DRAFT_STATE].isManual_ = true;
611
- leaveScope(scope);
612
- return proxy;
613
- }
614
- finishDraft(draft, patchListener) {
615
- const state = draft && draft[DRAFT_STATE];
616
- if (!state || !state.isManual_) die(9);
617
- const { scope_: scope } = state;
618
- usePatchesInScope(scope, patchListener);
619
- return processResult(void 0, scope);
620
- }
621
- /**
622
- * Pass true to automatically freeze all copies created by Immer.
623
- *
624
- * By default, auto-freezing is enabled.
625
- */
626
- setAutoFreeze(value) {
627
- this.autoFreeze_ = value;
628
- }
629
- /**
630
- * Pass true to enable strict shallow copy.
631
- *
632
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
633
- */
634
- setUseStrictShallowCopy(value) {
635
- this.useStrictShallowCopy_ = value;
636
- }
637
- /**
638
- * Pass false to use faster iteration that skips non-enumerable properties
639
- * but still handles symbols for compatibility.
640
- *
641
- * By default, strict iteration is enabled (includes all own properties).
642
- */
643
- setUseStrictIteration(value) {
644
- this.useStrictIteration_ = value;
645
- }
646
- shouldUseStrictIteration() {
647
- return this.useStrictIteration_;
648
- }
649
- applyPatches(base, patches) {
650
- let i;
651
- for (i = patches.length - 1; i >= 0; i--) {
652
- const patch = patches[i];
653
- if (patch.path.length === 0 && patch.op === "replace") {
654
- base = patch.value;
655
- break;
656
- }
657
- }
658
- if (i > -1) patches = patches.slice(i + 1);
659
- const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;
660
- if (isDraft(base)) return applyPatchesImpl(base, patches);
661
- return this.produce(base, (draft) => applyPatchesImpl(draft, patches));
662
- }
663
- };
664
- function createProxy(rootScope, value, parent, key) {
665
- const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);
666
- (parent?.scope_ ?? getCurrentScope()).drafts_.push(draft);
667
- state.callbacks_ = parent?.callbacks_ ?? [];
668
- state.key_ = key;
669
- if (parent && key !== void 0) registerChildFinalizationCallback(parent, state, key);
670
- else state.callbacks_.push(function rootDraftCleanup(rootScope2) {
671
- rootScope2.mapSetPlugin_?.fixSetContents(state);
672
- const { patchPlugin_ } = rootScope2;
673
- if (state.modified_ && patchPlugin_) patchPlugin_.generatePatches_(state, [], rootScope2);
674
- });
675
- return draft;
676
- }
677
- function current(value) {
678
- if (!isDraft(value)) die(10, value);
679
- return currentImpl(value);
680
- }
681
- function currentImpl(value) {
682
- if (!isDraftable(value) || isFrozen(value)) return value;
683
- const state = value[DRAFT_STATE];
684
- let copy;
685
- let strict = true;
686
- if (state) {
687
- if (!state.modified_) return state.base_;
688
- state.finalized_ = true;
689
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
690
- strict = state.scope_.immer_.shouldUseStrictIteration();
691
- } else copy = shallowCopy(value, true);
692
- each(copy, (key, childValue) => {
693
- set(copy, key, currentImpl(childValue));
694
- }, strict);
695
- if (state) state.finalized_ = false;
696
- return copy;
697
- }
698
- function enablePatches() {
699
- const errorOffset = 16;
700
- if (process.env.NODE_ENV !== "production") errors.push("Sets cannot have \"replace\" patches.", function(op) {
701
- return "Unsupported patch operation: " + op;
702
- }, function(path) {
703
- return "Cannot apply patch, path doesn't resolve: " + path;
704
- }, "Patching reserved attributes like __proto__, prototype and constructor is not allowed");
705
- function getPath(state, path = []) {
706
- if (state.key_ !== void 0) {
707
- const parentCopy = state.parent_.copy_ ?? state.parent_.base_;
708
- const proxyDraft = getProxyDraft(get(parentCopy, state.key_));
709
- const valueAtKey = get(parentCopy, state.key_);
710
- if (valueAtKey === void 0) return null;
711
- if (valueAtKey !== state.draft_ && valueAtKey !== state.base_ && valueAtKey !== state.copy_) return null;
712
- if (proxyDraft != null && proxyDraft.base_ !== state.base_) return null;
713
- const isSet2 = state.parent_.type_ === 3;
714
- let key;
715
- if (isSet2) {
716
- const setParent = state.parent_;
717
- key = Array.from(setParent.drafts_.keys()).indexOf(state.key_);
718
- } else key = state.key_;
719
- if (!(isSet2 && parentCopy.size > key || has(parentCopy, key))) return null;
720
- path.push(key);
721
- }
722
- if (state.parent_) return getPath(state.parent_, path);
723
- path.reverse();
724
- try {
725
- resolvePath(state.copy_, path);
726
- } catch (e) {
727
- return null;
728
- }
729
- return path;
730
- }
731
- function resolvePath(base, path) {
732
- let current2 = base;
733
- for (let i = 0; i < path.length - 1; i++) {
734
- const key = path[i];
735
- current2 = get(current2, key);
736
- if (!isObjectish(current2) || current2 === null) throw new Error(`Cannot resolve path at '${path.join("/")}'`);
737
- }
738
- return current2;
739
- }
740
- const REPLACE = "replace";
741
- const ADD = "add";
742
- const REMOVE = "remove";
743
- function generatePatches_(state, basePath, scope) {
744
- if (state.scope_.processedForPatches_.has(state)) return;
745
- state.scope_.processedForPatches_.add(state);
746
- const { patches_, inversePatches_ } = scope;
747
- switch (state.type_) {
748
- case 0:
749
- case 2: return generatePatchesFromAssigned(state, basePath, patches_, inversePatches_);
750
- case 1: return generateArrayPatches(state, basePath, patches_, inversePatches_);
751
- case 3: return generateSetPatches(state, basePath, patches_, inversePatches_);
752
- }
753
- }
754
- function generateArrayPatches(state, basePath, patches, inversePatches) {
755
- let { base_, assigned_ } = state;
756
- let copy_ = state.copy_;
757
- if (copy_.length < base_.length) {
758
- [base_, copy_] = [copy_, base_];
759
- [patches, inversePatches] = [inversePatches, patches];
760
- }
761
- const allReassigned = state.allIndicesReassigned_ === true;
762
- for (let i = 0; i < base_.length; i++) {
763
- const copiedItem = copy_[i];
764
- const baseItem = base_[i];
765
- if ((allReassigned || assigned_?.get(i.toString())) && copiedItem !== baseItem) {
766
- const childState = copiedItem?.[DRAFT_STATE];
767
- if (childState && childState.modified_) continue;
768
- const path = basePath.concat([i]);
769
- patches.push({
770
- op: REPLACE,
771
- path,
772
- value: clonePatchValueIfNeeded(copiedItem)
773
- });
774
- inversePatches.push({
775
- op: REPLACE,
776
- path,
777
- value: clonePatchValueIfNeeded(baseItem)
778
- });
779
- }
780
- }
781
- for (let i = base_.length; i < copy_.length; i++) {
782
- const path = basePath.concat([i]);
783
- patches.push({
784
- op: ADD,
785
- path,
786
- value: clonePatchValueIfNeeded(copy_[i])
787
- });
788
- }
789
- for (let i = copy_.length - 1; base_.length <= i; --i) {
790
- const path = basePath.concat([i]);
791
- inversePatches.push({
792
- op: REMOVE,
793
- path
794
- });
795
- }
796
- }
797
- function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
798
- const { base_, copy_, type_ } = state;
799
- each(state.assigned_, (key, assignedValue) => {
800
- const origValue = get(base_, key, type_);
801
- const value = get(copy_, key, type_);
802
- const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;
803
- if (origValue === value && op === REPLACE) return;
804
- const path = basePath.concat(key);
805
- patches.push(op === REMOVE ? {
806
- op,
807
- path
808
- } : {
809
- op,
810
- path,
811
- value: clonePatchValueIfNeeded(value)
812
- });
813
- inversePatches.push(op === ADD ? {
814
- op: REMOVE,
815
- path
816
- } : op === REMOVE ? {
817
- op: ADD,
818
- path,
819
- value: clonePatchValueIfNeeded(origValue)
820
- } : {
821
- op: REPLACE,
822
- path,
823
- value: clonePatchValueIfNeeded(origValue)
824
- });
825
- });
826
- }
827
- function generateSetPatches(state, basePath, patches, inversePatches) {
828
- let { base_, copy_ } = state;
829
- let i = 0;
830
- base_.forEach((value) => {
831
- if (!copy_.has(value)) {
832
- const path = basePath.concat([i]);
833
- patches.push({
834
- op: REMOVE,
835
- path,
836
- value
837
- });
838
- inversePatches.unshift({
839
- op: ADD,
840
- path,
841
- value
842
- });
843
- }
844
- i++;
845
- });
846
- i = 0;
847
- copy_.forEach((value) => {
848
- if (!base_.has(value)) {
849
- const path = basePath.concat([i]);
850
- patches.push({
851
- op: ADD,
852
- path,
853
- value
854
- });
855
- inversePatches.unshift({
856
- op: REMOVE,
857
- path,
858
- value
859
- });
860
- }
861
- i++;
862
- });
863
- }
864
- function generateReplacementPatches_(baseValue, replacement, scope) {
865
- const { patches_, inversePatches_ } = scope;
866
- patches_.push({
867
- op: REPLACE,
868
- path: [],
869
- value: replacement === NOTHING ? void 0 : replacement
870
- });
871
- inversePatches_.push({
872
- op: REPLACE,
873
- path: [],
874
- value: baseValue
875
- });
876
- }
877
- function applyPatches_(draft, patches) {
878
- patches.forEach((patch) => {
879
- const { path, op } = patch;
880
- let base = draft;
881
- for (let i = 0; i < path.length - 1; i++) {
882
- const parentType = getArchtype(base);
883
- let p = path[i];
884
- if (typeof p !== "string" && typeof p !== "number") p = "" + p;
885
- if ((parentType === 0 || parentType === 1) && (p === "__proto__" || p === CONSTRUCTOR)) die(19);
886
- if (isFunction(base) && p === PROTOTYPE) die(19);
887
- base = get(base, p);
888
- if (base === null || !isObjectish(base)) die(18, path.join("/"));
889
- }
890
- const type = getArchtype(base);
891
- const value = deepClonePatchValue(patch.value);
892
- const key = path[path.length - 1];
893
- switch (op) {
894
- case REPLACE: switch (type) {
895
- case 2: return base.set(key, value);
896
- case 3: die(errorOffset);
897
- default: return base[key] = value;
898
- }
899
- case ADD: switch (type) {
900
- case 1: return key === "-" ? base.push(value) : base.splice(key, 0, value);
901
- case 2: return base.set(key, value);
902
- case 3: return base.add(value);
903
- default: return base[key] = value;
904
- }
905
- case REMOVE: switch (type) {
906
- case 1: return base.splice(key, 1);
907
- case 2: return base.delete(key);
908
- case 3: return base.delete(patch.value);
909
- default: return delete base[key];
910
- }
911
- default: die(17, op);
912
- }
913
- });
914
- return draft;
915
- }
916
- function deepClonePatchValue(obj) {
917
- if (!isDraftable(obj)) return obj;
918
- if (isArray(obj)) return obj.map(deepClonePatchValue);
919
- if (isMap(obj)) return new Map(Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)]));
920
- if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue));
921
- const cloned = Object.create(getPrototypeOf(obj));
922
- for (const key in obj) cloned[key] = deepClonePatchValue(obj[key]);
923
- if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE];
924
- return cloned;
925
- }
926
- function clonePatchValueIfNeeded(obj) {
927
- if (isDraft(obj)) return deepClonePatchValue(obj);
928
- else return obj;
929
- }
930
- loadPlugin(PluginPatches, {
931
- applyPatches_,
932
- generatePatches_,
933
- generateReplacementPatches_,
934
- getPath
935
- });
936
- }
937
- var immer = new Immer2();
938
- var produce = immer.produce;
939
- var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer);
940
- var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer);
941
- //#endregion
942
- //#region src/utils/nanoid.ts
943
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
944
- function nanoid(size = 21) {
945
- let id = "";
946
- let i = size;
947
- while (i--) id += urlAlphabet[Math.random() * 64 | 0];
948
- return id;
949
- }
950
- //#endregion
951
- //#region src/utils/shared-state.ts
952
- /**
953
- * Upper bound on retained syncIds. Loop echoes arrive near-immediately, so a
954
- * generous window preserves de-dup while capping memory on long-lived,
955
- * frequently-mutated states (e.g. a 1s terminal poll).
956
- */
957
- const MAX_SYNC_IDS = 1e3;
958
- function rememberSyncId(syncIds, syncId) {
959
- syncIds.add(syncId);
960
- if (syncIds.size > MAX_SYNC_IDS) {
961
- const oldest = syncIds.values().next().value;
962
- if (oldest !== void 0) syncIds.delete(oldest);
963
- }
964
- }
965
- function createSharedState(options) {
966
- const { enablePatches: enablePatches$1 = false } = options;
967
- if (enablePatches$1) enablePatches();
968
- const events = createEventEmitter();
969
- let state = options.initialValue;
970
- const syncIds = /* @__PURE__ */ new Set();
971
- return {
972
- on: events.on,
973
- value: () => state,
974
- patch: (patches, syncId = nanoid()) => {
975
- if (syncIds.has(syncId)) return;
976
- enablePatches();
977
- state = applyPatches(state, patches);
978
- rememberSyncId(syncIds, syncId);
979
- events.emit("updated", state, void 0, syncId);
980
- },
981
- mutate: (fn, syncId = nanoid()) => {
982
- if (syncIds.has(syncId)) return;
983
- rememberSyncId(syncIds, syncId);
984
- if (enablePatches$1) {
985
- const [newState, patches] = produceWithPatches(state, fn);
986
- state = newState;
987
- events.emit("updated", state, patches, syncId);
988
- } else {
989
- state = produce(state, fn);
990
- events.emit("updated", state, void 0, syncId);
991
- }
992
- },
993
- syncIds
994
- };
995
- }
996
- //#endregion
997
- //#region ../../node_modules/.pnpm/perfect-debounce@2.1.0/node_modules/perfect-debounce/dist/index.mjs
998
- const DEBOUNCE_DEFAULTS = { trailing: true };
999
- /**
1000
- Debounce functions
1001
- @param fn - Promise-returning/async function to debounce.
1002
- @param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
1003
- @returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
1004
- @example
1005
- ```
1006
- import { debounce } from 'perfect-debounce';
1007
- const expensiveCall = async input => input;
1008
- const debouncedFn = debounce(expensiveCall, 200);
1009
- for (const number of [1, 2, 3]) {
1010
- console.log(await debouncedFn(number));
1011
- }
1012
- //=> 1
1013
- //=> 2
1014
- //=> 3
1015
- ```
1016
- */
1017
- function debounce(fn, wait = 25, options = {}) {
1018
- options = {
1019
- ...DEBOUNCE_DEFAULTS,
1020
- ...options
1021
- };
1022
- if (!Number.isFinite(wait)) throw new TypeError("Expected `wait` to be a finite number");
1023
- let leadingValue;
1024
- let timeout;
1025
- let resolveList = [];
1026
- let currentPromise;
1027
- let trailingArgs;
1028
- const applyFn = (_this, args) => {
1029
- currentPromise = _applyPromised(fn, _this, args);
1030
- currentPromise.finally(() => {
1031
- currentPromise = null;
1032
- if (options.trailing && trailingArgs && !timeout) {
1033
- const promise = applyFn(_this, trailingArgs);
1034
- trailingArgs = null;
1035
- return promise;
1036
- }
1037
- });
1038
- return currentPromise;
1039
- };
1040
- const debounced = function(...args) {
1041
- if (options.trailing) trailingArgs = args;
1042
- if (currentPromise) return currentPromise;
1043
- return new Promise((resolve) => {
1044
- const shouldCallNow = !timeout && options.leading;
1045
- clearTimeout(timeout);
1046
- timeout = setTimeout(() => {
1047
- timeout = null;
1048
- const promise = options.leading ? leadingValue : applyFn(this, args);
1049
- trailingArgs = null;
1050
- for (const _resolve of resolveList) _resolve(promise);
1051
- resolveList = [];
1052
- }, wait);
1053
- if (shouldCallNow) {
1054
- leadingValue = applyFn(this, args);
1055
- resolve(leadingValue);
1056
- } else resolveList.push(resolve);
1057
- });
1058
- };
1059
- const _clearTimeout = (timer) => {
1060
- if (timer) {
1061
- clearTimeout(timer);
1062
- timeout = null;
1063
- }
1064
- };
1065
- debounced.isPending = () => !!timeout;
1066
- debounced.cancel = () => {
1067
- _clearTimeout(timeout);
1068
- resolveList = [];
1069
- trailingArgs = null;
1070
- };
1071
- debounced.flush = () => {
1072
- _clearTimeout(timeout);
1073
- if (!trailingArgs || currentPromise) return;
1074
- const args = trailingArgs;
1075
- trailingArgs = null;
1076
- return applyFn(this, args);
1077
- };
1078
- return debounced;
1079
- }
1080
- async function _applyPromised(fn, _this, args) {
1081
- return await fn.apply(_this, args);
1082
- }
1083
- //#endregion
1084
- //#region src/node/storage.ts
1085
- function createStorage(options) {
1086
- const { mergeInitialValue = (initialValue, savedValue) => ({
1087
- ...initialValue,
1088
- ...savedValue
1089
- }), debounce: debounceTime = 100 } = options;
1090
- let initialValue = options.initialValue;
1091
- if (fs.existsSync(options.filepath)) try {
1092
- const savedValue = destr(fs.readFileSync(options.filepath, "utf-8"), { strict: true });
1093
- initialValue = mergeInitialValue ? mergeInitialValue(options.initialValue, savedValue) : savedValue;
1094
- } catch (error) {
1095
- diagnostics.DF0012({
1096
- filepath: options.filepath,
1097
- cause: error
1098
- }, { method: "warn" });
1099
- initialValue = options.initialValue;
1100
- }
1101
- const state = createSharedState({
1102
- initialValue,
1103
- enablePatches: false
1104
- });
1105
- state.on("updated", debounce((newState) => {
1106
- try {
1107
- const dir = dirname(options.filepath);
1108
- fs.mkdirSync(dir, { recursive: true });
1109
- const tmp = `${options.filepath}.${process$1.pid}.tmp`;
1110
- fs.writeFileSync(tmp, `${JSON.stringify(newState, null, 2)}\n`);
1111
- fs.renameSync(tmp, options.filepath);
1112
- } catch (error) {
1113
- diagnostics.DF0035({
1114
- filepath: options.filepath,
1115
- cause: error
1116
- }, { method: "error" });
1117
- }
1118
- }, debounceTime));
1119
- return state;
1120
- }
1121
- //#endregion
1122
- export { createEventEmitter as i, createSharedState as n, nanoid as r, createStorage as t };