msw-dev-tool 1.0.23 → 1.1.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.
@@ -0,0 +1,708 @@
1
+ // src/utils/env.ts
2
+ var NOTHING = Symbol.for("immer-nothing");
3
+ var DRAFTABLE = Symbol.for("immer-draftable");
4
+ var DRAFT_STATE = Symbol.for("immer-state");
5
+
6
+ // src/utils/errors.ts
7
+ var errors = process.env.NODE_ENV !== "production" ? [
8
+ // All error codes, starting by 0:
9
+ function(plugin) {
10
+ return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
11
+ },
12
+ function(thing) {
13
+ 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}'`;
14
+ },
15
+ "This object has been frozen and should not be mutated",
16
+ function(data) {
17
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
18
+ },
19
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
20
+ "Immer forbids circular references",
21
+ "The first or second argument to `produce` must be a function",
22
+ "The third argument to `produce` must be a function or undefined",
23
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
24
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
25
+ function(thing) {
26
+ return `'current' expects a draft, got: ${thing}`;
27
+ },
28
+ "Object.defineProperty() cannot be used on an Immer draft",
29
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
30
+ "Immer only supports deleting array indices",
31
+ "Immer only supports setting array indices and the 'length' property",
32
+ function(thing) {
33
+ return `'original' expects a draft, got: ${thing}`;
34
+ }
35
+ // Note: if more errors are added, the errorOffset in Patches.ts should be increased
36
+ // See Patches.ts for additional errors
37
+ ] : [];
38
+ function die(error, ...args) {
39
+ if (process.env.NODE_ENV !== "production") {
40
+ const e = errors[error];
41
+ const msg = typeof e === "function" ? e.apply(null, args) : e;
42
+ throw new Error(`[Immer] ${msg}`);
43
+ }
44
+ throw new Error(
45
+ `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
46
+ );
47
+ }
48
+
49
+ // src/utils/common.ts
50
+ var getPrototypeOf = Object.getPrototypeOf;
51
+ function isDraft(value) {
52
+ return !!value && !!value[DRAFT_STATE];
53
+ }
54
+ function isDraftable(value) {
55
+ if (!value)
56
+ return false;
57
+ return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
58
+ }
59
+ var objectCtorString = Object.prototype.constructor.toString();
60
+ function isPlainObject(value) {
61
+ if (!value || typeof value !== "object")
62
+ return false;
63
+ const proto = getPrototypeOf(value);
64
+ if (proto === null) {
65
+ return true;
66
+ }
67
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
68
+ if (Ctor === Object)
69
+ return true;
70
+ return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
71
+ }
72
+ function each(obj, iter) {
73
+ if (getArchtype(obj) === 0 /* Object */) {
74
+ Reflect.ownKeys(obj).forEach((key) => {
75
+ iter(key, obj[key], obj);
76
+ });
77
+ } else {
78
+ obj.forEach((entry, index) => iter(index, entry, obj));
79
+ }
80
+ }
81
+ function getArchtype(thing) {
82
+ const state = thing[DRAFT_STATE];
83
+ return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
84
+ }
85
+ function has(thing, prop) {
86
+ return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
87
+ }
88
+ function set(thing, propOrOldValue, value) {
89
+ const t = getArchtype(thing);
90
+ if (t === 2 /* Map */)
91
+ thing.set(propOrOldValue, value);
92
+ else if (t === 3 /* Set */) {
93
+ thing.add(value);
94
+ } else
95
+ thing[propOrOldValue] = value;
96
+ }
97
+ function is(x, y) {
98
+ if (x === y) {
99
+ return x !== 0 || 1 / x === 1 / y;
100
+ } else {
101
+ return x !== x && y !== y;
102
+ }
103
+ }
104
+ function isMap(target) {
105
+ return target instanceof Map;
106
+ }
107
+ function isSet(target) {
108
+ return target instanceof Set;
109
+ }
110
+ function latest(state) {
111
+ return state.copy_ || state.base_;
112
+ }
113
+ function shallowCopy(base, strict) {
114
+ if (isMap(base)) {
115
+ return new Map(base);
116
+ }
117
+ if (isSet(base)) {
118
+ return new Set(base);
119
+ }
120
+ if (Array.isArray(base))
121
+ return Array.prototype.slice.call(base);
122
+ const isPlain = isPlainObject(base);
123
+ if (strict === true || strict === "class_only" && !isPlain) {
124
+ const descriptors = Object.getOwnPropertyDescriptors(base);
125
+ delete descriptors[DRAFT_STATE];
126
+ let keys = Reflect.ownKeys(descriptors);
127
+ for (let i = 0; i < keys.length; i++) {
128
+ const key = keys[i];
129
+ const desc = descriptors[key];
130
+ if (desc.writable === false) {
131
+ desc.writable = true;
132
+ desc.configurable = true;
133
+ }
134
+ if (desc.get || desc.set)
135
+ descriptors[key] = {
136
+ configurable: true,
137
+ writable: true,
138
+ // could live with !!desc.set as well here...
139
+ enumerable: desc.enumerable,
140
+ value: base[key]
141
+ };
142
+ }
143
+ return Object.create(getPrototypeOf(base), descriptors);
144
+ } else {
145
+ const proto = getPrototypeOf(base);
146
+ if (proto !== null && isPlain) {
147
+ return { ...base };
148
+ }
149
+ const obj = Object.create(proto);
150
+ return Object.assign(obj, base);
151
+ }
152
+ }
153
+ function freeze(obj, deep = false) {
154
+ if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
155
+ return obj;
156
+ if (getArchtype(obj) > 1) {
157
+ obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
158
+ }
159
+ Object.freeze(obj);
160
+ if (deep)
161
+ Object.entries(obj).forEach(([key, value]) => freeze(value, true));
162
+ return obj;
163
+ }
164
+ function dontMutateFrozenCollections() {
165
+ die(2);
166
+ }
167
+ function isFrozen(obj) {
168
+ return Object.isFrozen(obj);
169
+ }
170
+
171
+ // src/utils/plugins.ts
172
+ var plugins = {};
173
+ function getPlugin(pluginKey) {
174
+ const plugin = plugins[pluginKey];
175
+ if (!plugin) {
176
+ die(0, pluginKey);
177
+ }
178
+ return plugin;
179
+ }
180
+
181
+ // src/core/scope.ts
182
+ var currentScope;
183
+ function getCurrentScope() {
184
+ return currentScope;
185
+ }
186
+ function createScope(parent_, immer_) {
187
+ return {
188
+ drafts_: [],
189
+ parent_,
190
+ immer_,
191
+ // Whenever the modified draft contains a draft from another scope, we
192
+ // need to prevent auto-freezing so the unowned draft can be finalized.
193
+ canAutoFreeze_: true,
194
+ unfinalizedDrafts_: 0
195
+ };
196
+ }
197
+ function usePatchesInScope(scope, patchListener) {
198
+ if (patchListener) {
199
+ getPlugin("Patches");
200
+ scope.patches_ = [];
201
+ scope.inversePatches_ = [];
202
+ scope.patchListener_ = patchListener;
203
+ }
204
+ }
205
+ function revokeScope(scope) {
206
+ leaveScope(scope);
207
+ scope.drafts_.forEach(revokeDraft);
208
+ scope.drafts_ = null;
209
+ }
210
+ function leaveScope(scope) {
211
+ if (scope === currentScope) {
212
+ currentScope = scope.parent_;
213
+ }
214
+ }
215
+ function enterScope(immer2) {
216
+ return currentScope = createScope(currentScope, immer2);
217
+ }
218
+ function revokeDraft(draft) {
219
+ const state = draft[DRAFT_STATE];
220
+ if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
221
+ state.revoke_();
222
+ else
223
+ state.revoked_ = true;
224
+ }
225
+
226
+ // src/core/finalize.ts
227
+ function processResult(result, scope) {
228
+ scope.unfinalizedDrafts_ = scope.drafts_.length;
229
+ const baseDraft = scope.drafts_[0];
230
+ const isReplaced = result !== void 0 && result !== baseDraft;
231
+ if (isReplaced) {
232
+ if (baseDraft[DRAFT_STATE].modified_) {
233
+ revokeScope(scope);
234
+ die(4);
235
+ }
236
+ if (isDraftable(result)) {
237
+ result = finalize(scope, result);
238
+ if (!scope.parent_)
239
+ maybeFreeze(scope, result);
240
+ }
241
+ if (scope.patches_) {
242
+ getPlugin("Patches").generateReplacementPatches_(
243
+ baseDraft[DRAFT_STATE].base_,
244
+ result,
245
+ scope.patches_,
246
+ scope.inversePatches_
247
+ );
248
+ }
249
+ } else {
250
+ result = finalize(scope, baseDraft, []);
251
+ }
252
+ revokeScope(scope);
253
+ if (scope.patches_) {
254
+ scope.patchListener_(scope.patches_, scope.inversePatches_);
255
+ }
256
+ return result !== NOTHING ? result : void 0;
257
+ }
258
+ function finalize(rootScope, value, path) {
259
+ if (isFrozen(value))
260
+ return value;
261
+ const state = value[DRAFT_STATE];
262
+ if (!state) {
263
+ each(
264
+ value,
265
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
266
+ );
267
+ return value;
268
+ }
269
+ if (state.scope_ !== rootScope)
270
+ return value;
271
+ if (!state.modified_) {
272
+ maybeFreeze(rootScope, state.base_, true);
273
+ return state.base_;
274
+ }
275
+ if (!state.finalized_) {
276
+ state.finalized_ = true;
277
+ state.scope_.unfinalizedDrafts_--;
278
+ const result = state.copy_;
279
+ let resultEach = result;
280
+ let isSet2 = false;
281
+ if (state.type_ === 3 /* Set */) {
282
+ resultEach = new Set(result);
283
+ result.clear();
284
+ isSet2 = true;
285
+ }
286
+ each(
287
+ resultEach,
288
+ (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
289
+ );
290
+ maybeFreeze(rootScope, result, false);
291
+ if (path && rootScope.patches_) {
292
+ getPlugin("Patches").generatePatches_(
293
+ state,
294
+ path,
295
+ rootScope.patches_,
296
+ rootScope.inversePatches_
297
+ );
298
+ }
299
+ }
300
+ return state.copy_;
301
+ }
302
+ function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
303
+ if (process.env.NODE_ENV !== "production" && childValue === targetObject)
304
+ die(5);
305
+ if (isDraft(childValue)) {
306
+ const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
307
+ !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
308
+ const res = finalize(rootScope, childValue, path);
309
+ set(targetObject, prop, res);
310
+ if (isDraft(res)) {
311
+ rootScope.canAutoFreeze_ = false;
312
+ } else
313
+ return;
314
+ } else if (targetIsSet) {
315
+ targetObject.add(childValue);
316
+ }
317
+ if (isDraftable(childValue) && !isFrozen(childValue)) {
318
+ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
319
+ return;
320
+ }
321
+ finalize(rootScope, childValue);
322
+ if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
323
+ maybeFreeze(rootScope, childValue);
324
+ }
325
+ }
326
+ function maybeFreeze(scope, value, deep = false) {
327
+ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
328
+ freeze(value, deep);
329
+ }
330
+ }
331
+
332
+ // src/core/proxy.ts
333
+ function createProxyProxy(base, parent) {
334
+ const isArray = Array.isArray(base);
335
+ const state = {
336
+ type_: isArray ? 1 /* Array */ : 0 /* Object */,
337
+ // Track which produce call this is associated with.
338
+ scope_: parent ? parent.scope_ : getCurrentScope(),
339
+ // True for both shallow and deep changes.
340
+ modified_: false,
341
+ // Used during finalization.
342
+ finalized_: false,
343
+ // Track which properties have been assigned (true) or deleted (false).
344
+ assigned_: {},
345
+ // The parent draft state.
346
+ parent_: parent,
347
+ // The base state.
348
+ base_: base,
349
+ // The base proxy.
350
+ draft_: null,
351
+ // set below
352
+ // The base copy with any updated values.
353
+ copy_: null,
354
+ // Called by the `produce` function.
355
+ revoke_: null,
356
+ isManual_: false
357
+ };
358
+ let target = state;
359
+ let traps = objectTraps;
360
+ if (isArray) {
361
+ target = [state];
362
+ traps = arrayTraps;
363
+ }
364
+ const { revoke, proxy } = Proxy.revocable(target, traps);
365
+ state.draft_ = proxy;
366
+ state.revoke_ = revoke;
367
+ return proxy;
368
+ }
369
+ var objectTraps = {
370
+ get(state, prop) {
371
+ if (prop === DRAFT_STATE)
372
+ return state;
373
+ const source = latest(state);
374
+ if (!has(source, prop)) {
375
+ return readPropFromProto(state, source, prop);
376
+ }
377
+ const value = source[prop];
378
+ if (state.finalized_ || !isDraftable(value)) {
379
+ return value;
380
+ }
381
+ if (value === peek(state.base_, prop)) {
382
+ prepareCopy(state);
383
+ return state.copy_[prop] = createProxy(value, state);
384
+ }
385
+ return value;
386
+ },
387
+ has(state, prop) {
388
+ return prop in latest(state);
389
+ },
390
+ ownKeys(state) {
391
+ return Reflect.ownKeys(latest(state));
392
+ },
393
+ set(state, prop, value) {
394
+ const desc = getDescriptorFromProto(latest(state), prop);
395
+ if (desc?.set) {
396
+ desc.set.call(state.draft_, value);
397
+ return true;
398
+ }
399
+ if (!state.modified_) {
400
+ const current2 = peek(latest(state), prop);
401
+ const currentState = current2?.[DRAFT_STATE];
402
+ if (currentState && currentState.base_ === value) {
403
+ state.copy_[prop] = value;
404
+ state.assigned_[prop] = false;
405
+ return true;
406
+ }
407
+ if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
408
+ return true;
409
+ prepareCopy(state);
410
+ markChanged(state);
411
+ }
412
+ if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
413
+ (value !== void 0 || prop in state.copy_) || // special case: NaN
414
+ Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
415
+ return true;
416
+ state.copy_[prop] = value;
417
+ state.assigned_[prop] = true;
418
+ return true;
419
+ },
420
+ deleteProperty(state, prop) {
421
+ if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
422
+ state.assigned_[prop] = false;
423
+ prepareCopy(state);
424
+ markChanged(state);
425
+ } else {
426
+ delete state.assigned_[prop];
427
+ }
428
+ if (state.copy_) {
429
+ delete state.copy_[prop];
430
+ }
431
+ return true;
432
+ },
433
+ // Note: We never coerce `desc.value` into an Immer draft, because we can't make
434
+ // the same guarantee in ES5 mode.
435
+ getOwnPropertyDescriptor(state, prop) {
436
+ const owner = latest(state);
437
+ const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
438
+ if (!desc)
439
+ return desc;
440
+ return {
441
+ writable: true,
442
+ configurable: state.type_ !== 1 /* Array */ || prop !== "length",
443
+ enumerable: desc.enumerable,
444
+ value: owner[prop]
445
+ };
446
+ },
447
+ defineProperty() {
448
+ die(11);
449
+ },
450
+ getPrototypeOf(state) {
451
+ return getPrototypeOf(state.base_);
452
+ },
453
+ setPrototypeOf() {
454
+ die(12);
455
+ }
456
+ };
457
+ var arrayTraps = {};
458
+ each(objectTraps, (key, fn) => {
459
+ arrayTraps[key] = function() {
460
+ arguments[0] = arguments[0][0];
461
+ return fn.apply(this, arguments);
462
+ };
463
+ });
464
+ arrayTraps.deleteProperty = function(state, prop) {
465
+ if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
466
+ die(13);
467
+ return arrayTraps.set.call(this, state, prop, void 0);
468
+ };
469
+ arrayTraps.set = function(state, prop, value) {
470
+ if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
471
+ die(14);
472
+ return objectTraps.set.call(this, state[0], prop, value, state[0]);
473
+ };
474
+ function peek(draft, prop) {
475
+ const state = draft[DRAFT_STATE];
476
+ const source = state ? latest(state) : draft;
477
+ return source[prop];
478
+ }
479
+ function readPropFromProto(state, source, prop) {
480
+ const desc = getDescriptorFromProto(source, prop);
481
+ return desc ? `value` in desc ? desc.value : (
482
+ // This is a very special case, if the prop is a getter defined by the
483
+ // prototype, we should invoke it with the draft as context!
484
+ desc.get?.call(state.draft_)
485
+ ) : void 0;
486
+ }
487
+ function getDescriptorFromProto(source, prop) {
488
+ if (!(prop in source))
489
+ return void 0;
490
+ let proto = getPrototypeOf(source);
491
+ while (proto) {
492
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
493
+ if (desc)
494
+ return desc;
495
+ proto = getPrototypeOf(proto);
496
+ }
497
+ return void 0;
498
+ }
499
+ function markChanged(state) {
500
+ if (!state.modified_) {
501
+ state.modified_ = true;
502
+ if (state.parent_) {
503
+ markChanged(state.parent_);
504
+ }
505
+ }
506
+ }
507
+ function prepareCopy(state) {
508
+ if (!state.copy_) {
509
+ state.copy_ = shallowCopy(
510
+ state.base_,
511
+ state.scope_.immer_.useStrictShallowCopy_
512
+ );
513
+ }
514
+ }
515
+
516
+ // src/core/immerClass.ts
517
+ var Immer2 = class {
518
+ constructor(config) {
519
+ this.autoFreeze_ = true;
520
+ this.useStrictShallowCopy_ = false;
521
+ /**
522
+ * The `produce` function takes a value and a "recipe function" (whose
523
+ * return value often depends on the base state). The recipe function is
524
+ * free to mutate its first argument however it wants. All mutations are
525
+ * only ever applied to a __copy__ of the base state.
526
+ *
527
+ * Pass only a function to create a "curried producer" which relieves you
528
+ * from passing the recipe function every time.
529
+ *
530
+ * Only plain objects and arrays are made mutable. All other objects are
531
+ * considered uncopyable.
532
+ *
533
+ * Note: This function is __bound__ to its `Immer` instance.
534
+ *
535
+ * @param {any} base - the initial state
536
+ * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
537
+ * @param {Function} patchListener - optional function that will be called with all the patches produced here
538
+ * @returns {any} a new state, or the initial state if nothing was modified
539
+ */
540
+ this.produce = (base, recipe, patchListener) => {
541
+ if (typeof base === "function" && typeof recipe !== "function") {
542
+ const defaultBase = recipe;
543
+ recipe = base;
544
+ const self = this;
545
+ return function curriedProduce(base2 = defaultBase, ...args) {
546
+ return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
547
+ };
548
+ }
549
+ if (typeof recipe !== "function")
550
+ die(6);
551
+ if (patchListener !== void 0 && typeof patchListener !== "function")
552
+ die(7);
553
+ let result;
554
+ if (isDraftable(base)) {
555
+ const scope = enterScope(this);
556
+ const proxy = createProxy(base, void 0);
557
+ let hasError = true;
558
+ try {
559
+ result = recipe(proxy);
560
+ hasError = false;
561
+ } finally {
562
+ if (hasError)
563
+ revokeScope(scope);
564
+ else
565
+ leaveScope(scope);
566
+ }
567
+ usePatchesInScope(scope, patchListener);
568
+ return processResult(result, scope);
569
+ } else if (!base || typeof base !== "object") {
570
+ result = recipe(base);
571
+ if (result === void 0)
572
+ result = base;
573
+ if (result === NOTHING)
574
+ result = void 0;
575
+ if (this.autoFreeze_)
576
+ freeze(result, true);
577
+ if (patchListener) {
578
+ const p = [];
579
+ const ip = [];
580
+ getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
581
+ patchListener(p, ip);
582
+ }
583
+ return result;
584
+ } else
585
+ die(1, base);
586
+ };
587
+ this.produceWithPatches = (base, recipe) => {
588
+ if (typeof base === "function") {
589
+ return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
590
+ }
591
+ let patches, inversePatches;
592
+ const result = this.produce(base, recipe, (p, ip) => {
593
+ patches = p;
594
+ inversePatches = ip;
595
+ });
596
+ return [result, patches, inversePatches];
597
+ };
598
+ if (typeof config?.autoFreeze === "boolean")
599
+ this.setAutoFreeze(config.autoFreeze);
600
+ if (typeof config?.useStrictShallowCopy === "boolean")
601
+ this.setUseStrictShallowCopy(config.useStrictShallowCopy);
602
+ }
603
+ createDraft(base) {
604
+ if (!isDraftable(base))
605
+ die(8);
606
+ if (isDraft(base))
607
+ base = current(base);
608
+ const scope = enterScope(this);
609
+ const proxy = createProxy(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_)
617
+ die(9);
618
+ const { scope_: scope } = state;
619
+ usePatchesInScope(scope, patchListener);
620
+ return processResult(void 0, scope);
621
+ }
622
+ /**
623
+ * Pass true to automatically freeze all copies created by Immer.
624
+ *
625
+ * By default, auto-freezing is enabled.
626
+ */
627
+ setAutoFreeze(value) {
628
+ this.autoFreeze_ = value;
629
+ }
630
+ /**
631
+ * Pass true to enable strict shallow copy.
632
+ *
633
+ * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
634
+ */
635
+ setUseStrictShallowCopy(value) {
636
+ this.useStrictShallowCopy_ = value;
637
+ }
638
+ applyPatches(base, patches) {
639
+ let i;
640
+ for (i = patches.length - 1; i >= 0; i--) {
641
+ const patch = patches[i];
642
+ if (patch.path.length === 0 && patch.op === "replace") {
643
+ base = patch.value;
644
+ break;
645
+ }
646
+ }
647
+ if (i > -1) {
648
+ patches = patches.slice(i + 1);
649
+ }
650
+ const applyPatchesImpl = getPlugin("Patches").applyPatches_;
651
+ if (isDraft(base)) {
652
+ return applyPatchesImpl(base, patches);
653
+ }
654
+ return this.produce(
655
+ base,
656
+ (draft) => applyPatchesImpl(draft, patches)
657
+ );
658
+ }
659
+ };
660
+ function createProxy(value, parent) {
661
+ const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
662
+ const scope = parent ? parent.scope_ : getCurrentScope();
663
+ scope.drafts_.push(draft);
664
+ return draft;
665
+ }
666
+
667
+ // src/core/current.ts
668
+ function current(value) {
669
+ if (!isDraft(value))
670
+ die(10, value);
671
+ return currentImpl(value);
672
+ }
673
+ function currentImpl(value) {
674
+ if (!isDraftable(value) || isFrozen(value))
675
+ return value;
676
+ const state = value[DRAFT_STATE];
677
+ let copy;
678
+ if (state) {
679
+ if (!state.modified_)
680
+ return state.base_;
681
+ state.finalized_ = true;
682
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
683
+ } else {
684
+ copy = shallowCopy(value, true);
685
+ }
686
+ each(copy, (key, childValue) => {
687
+ set(copy, key, currentImpl(childValue));
688
+ });
689
+ if (state) {
690
+ state.finalized_ = false;
691
+ }
692
+ return copy;
693
+ }
694
+
695
+ // src/immer.ts
696
+ var immer = new Immer2();
697
+ var produce = immer.produce;
698
+ immer.produceWithPatches.bind(
699
+ immer
700
+ );
701
+ immer.setAutoFreeze.bind(immer);
702
+ immer.setUseStrictShallowCopy.bind(immer);
703
+ immer.applyPatches.bind(immer);
704
+ immer.createDraft.bind(immer);
705
+ immer.finishDraft.bind(immer);
706
+
707
+ export { Immer2 as Immer, current, freeze, DRAFTABLE as immerable, isDraft, isDraftable, NOTHING as nothing, produce };
708
+ //# sourceMappingURL=immer.js.map