@oliasoft-open-source/node-json-migrator 3.0.0-beta-1 → 3.0.0-beta-2

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