diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index cd9776bb..f5304bb1 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -3,8 +3,7 @@ name: Bug report
about: 创建一个报告来帮助我们改进
title: "[Bug] 标题简要描述问题"
labels: bug
-assignees: ''
-
+assignees: ""
---
**描述问题**
@@ -12,6 +11,7 @@ assignees: ''
**复现步骤**
复现该问题的步骤:
+
1. 去到 '...'
2. 点击 '...'
3. 滚动到 '...'
@@ -24,9 +24,10 @@ assignees: ''
如有可能,请添加截图以帮助解释问题。
**环境**
+
- 操作系统: [e.g. Windows, macOS]
- 浏览器: [e.g. Chrome, Safari]
- 仓库版本: [e.g. v1.0.0]
**其他信息**
-在此处添加关于该问题的任何其他信息。
\ No newline at end of file
+在此处添加关于该问题的任何其他信息。
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
index 5b86dfe7..eccd8712 100644
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -3,8 +3,7 @@ name: Feature request
about: 提出一个新功能请求
title: "[Feature] 简要描述你希望实现的功能"
labels: enhancement
-assignees: ''
-
+assignees: ""
---
**功能描述**
@@ -17,4 +16,4 @@ assignees: ''
描述你已经考虑过的替代方案。
**其他信息**
-在这里添加任何相关的附加信息或截图。
\ No newline at end of file
+在这里添加任何相关的附加信息或截图。
diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml
index 78aa8bf2..b64c8bbf 100644
--- a/.github/workflows/push_image.yml
+++ b/.github/workflows/push_image.yml
@@ -30,7 +30,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
- usual2970/certimate
+ usual2970/certimate
registry.cn-shanghai.aliyuncs.com/usual2970/certimate
- name: Log in to DOCKERHUB
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 54e81666..66b8aff2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -58,8 +58,7 @@ Certimate 的管理页面是一个基于 React 和 Vite 构建的单页应用(
你可以通过浏览器访问 `http://localhost:5173` 来查看运行中的管理页面。
-由于 Admin UI 只是一个客户端应用,运行时需要 Certimate 的后端服务作为支撑。你可以手动运行Certimate,或者使用预构建的可执行文件。
-
+由于 Admin UI 只是一个客户端应用,运行时需要 Certimate 的后端服务作为支撑。你可以手动运行 Certimate,或者使用预构建的可执行文件。
所有对 Admin UI 的修改将会自动反映在浏览器中,无需手动刷新页面。
@@ -69,4 +68,4 @@ Certimate 的管理页面是一个基于 React 和 Vite 构建的单页应用(
npm run build
```
-完成所有步骤后,你可以将改动提交 PR 到 Certimate 主仓库。
\ No newline at end of file
+完成所有步骤后,你可以将改动提交 PR 到 Certimate 主仓库。
diff --git a/CONTRIBUTING_EN.md b/CONTRIBUTING_EN.md
index 2f2d6efd..c29ba51c 100644
--- a/CONTRIBUTING_EN.md
+++ b/CONTRIBUTING_EN.md
@@ -70,4 +70,4 @@ After completing your changes, build the Admin UI so it can be embedded into the
npm run build
```
-Once all steps are completed, you are ready to submit a PR to the main Certimate repository.
\ No newline at end of file
+Once all steps are completed, you are ready to submit a PR to the main Certimate repository.
diff --git a/Dockerfile_build b/Dockerfile_build
index 23b27630..efd3d962 100644
--- a/Dockerfile_build
+++ b/Dockerfile_build
@@ -13,4 +13,4 @@ WORKDIR /app
COPY --from=builder /app/certimate .
-ENTRYPOINT ["./certimate", "serve", "--http", "0.0.0.0:8090"]
\ No newline at end of file
+ENTRYPOINT ["./certimate", "serve", "--http", "0.0.0.0:8090"]
diff --git a/Makefile b/Makefile
index fb6c79e9..7c2f0d6d 100644
--- a/Makefile
+++ b/Makefile
@@ -34,4 +34,4 @@ help:
@echo " make clean - 清理构建文件"
@echo " make help - 显示此帮助信息"
-.PHONY: all build clean help
\ No newline at end of file
+.PHONY: all build clean help
diff --git a/README.md b/README.md
index d0866159..881a5db6 100644
--- a/README.md
+++ b/README.md
@@ -4,8 +4,8 @@
做个人产品或在小企业负责运维的同学,需要管理多个域名,要给域名申请证书。但手动申请证书有以下缺点:
-1. 😱麻烦:申请、部署证书虽不困难,但也挺麻烦的,尤其是维护多个域名的时候。
-2. 😭易忘:当前免费证书有效期仅90天,这就要求定期操作,增加工作量的同时,也很容易忘掉,导致网站无法访问。
+1. 😱 麻烦:申请、部署证书虽不困难,但也挺麻烦的,尤其是维护多个域名的时候。
+2. 😭 易忘:当前免费证书有效期仅 90 天,这就要求定期操作,增加工作量的同时,也很容易忘掉,导致网站无法访问。
Certimate 就是为了解决上述问题而产生的,它具有以下特点:
@@ -15,9 +15,9 @@ Certimate 就是为了解决上述问题而产生的,它具有以下特点:
相关文章:
-* [⚠️⚠️⚠️V0.2.0-第一个不向后兼容的版本](https://docs.certimate.me/blog/v0.2.0)
-* [Why Certimate?](https://docs.certimate.me/blog/why-certimate)
-* [域名变量及部署授权组介绍](https://docs.certimate.me/blog/multi-deployer)
+- [⚠️⚠️⚠️V0.2.0-第一个不向后兼容的版本](https://docs.certimate.me/blog/v0.2.0)
+- [Why Certimate?](https://docs.certimate.me/blog/why-certimate)
+- [域名变量及部署授权组介绍](https://docs.certimate.me/blog/multi-deployer)
Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决方案。使用文档请访问[https://docs.certimate.me](https://docs.certimate.me)
@@ -34,12 +34,13 @@ Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决
```
或运行以下命令自动给 Certimate 自身添加证书
+
```bash
./certimate serve 你的域名
```
> [!NOTE]
-> MacOS 在执行二进制文件时会提示:无法打开“certimate”,因为Apple无法检查其是否包含恶意软件。可在系统设置> 隐私与安全性> 安全性 中点击 "仍然允许",然后再次尝试执行二进制文件。
+> MacOS 在执行二进制文件时会提示:无法打开“certimate”,因为 Apple 无法检查其是否包含恶意软件。可在系统设置> 隐私与安全性> 安全性 中点击 "仍然允许",然后再次尝试执行二进制文件。
### 2. Docker 安装
@@ -71,14 +72,14 @@ go run main.go serve
## 三、支持的服务商列表
-| 服务商 | 是否域名服务商 | 是否部署服务 | 备注 |
-| ---------- | -------------- | ------------ | ------------------------------------------------------ |
-| 阿里云 | 是 | 是 | 支持阿里云注册的域名,支持部署到阿里云 CDN,OSS |
-| 腾讯云 | 是 | 是 | 支持腾讯云注册的域名,支持部署到腾讯云 CDN |
-| 七牛云 | 否 | 是 | 七牛云没有注册域名服务,支持部署到七牛云 CDN |
-| CloudFlare | 是 | 否 | 支持 CloudFlare 注册的域名,CloudFlare 服务自带SSL证书 |
-| SSH | 否 | 是 | 支持部署到 SSH 服务器 |
-| WEBHOOK | 否 | 是 | 支持回调到 WEBHOOK |
+| 服务商 | 是否域名服务商 | 是否部署服务 | 备注 |
+| ---------- | -------------- | ------------ | -------------------------------------------------------- |
+| 阿里云 | 是 | 是 | 支持阿里云注册的域名,支持部署到阿里云 CDN,OSS |
+| 腾讯云 | 是 | 是 | 支持腾讯云注册的域名,支持部署到腾讯云 CDN |
+| 七牛云 | 否 | 是 | 七牛云没有注册域名服务,支持部署到七牛云 CDN |
+| CloudFlare | 是 | 否 | 支持 CloudFlare 注册的域名,CloudFlare 服务自带 SSL 证书 |
+| SSH | 否 | 是 | 支持部署到 SSH 服务器 |
+| WEBHOOK | 否 | 是 | 支持回调到 WEBHOOK |
## 四、系统截图
@@ -96,10 +97,10 @@ go run main.go serve
Certimate 的工作流程如下:
-* 用户通过 Certimate 管理页面填写申请证书的信息,包括域名、dns 服务商的授权信息、以及要部署到的服务商的授权信息。
-* Certimate 向证书厂商的 API 发起申请请求,获取 SSL 证书。
-* Certimate 存储证书信息,包括证书内容、私钥、证书有效期等,并在证书即将过期时自动续期。
-* Certimate 向服务商的 API 发起部署请求,将证书部署到服务商的服务器上。
+- 用户通过 Certimate 管理页面填写申请证书的信息,包括域名、dns 服务商的授权信息、以及要部署到的服务商的授权信息。
+- Certimate 向证书厂商的 API 发起申请请求,获取 SSL 证书。
+- Certimate 存储证书信息,包括证书内容、私钥、证书有效期等,并在证书即将过期时自动续期。
+- Certimate 向服务商的 API 发起部署请求,将证书部署到服务商的服务器上。
这就涉及域名、dns 服务商的授权信息、部署服务商的授权信息等。
@@ -135,17 +136,17 @@ Certimate 申请证书后,会自动将证书部署到你指定的目标上,
## 六、常见问题
-Q: 提供saas服务吗?
+Q: 提供 saas 服务吗?
-> A: 不提供,目前仅支持self-hosted(私有部署)。
+> A: 不提供,目前仅支持 self-hosted(私有部署)。
Q: 数据安全?
-> A: 由于仅支持私有部署,各种数据都保存在用户的服务器上。另外Certimate源码也开源,二进制包及Docker镜像打包过程全部使用Github actions进行,过程透明可见,可自行审计。
+> A: 由于仅支持私有部署,各种数据都保存在用户的服务器上。另外 Certimate 源码也开源,二进制包及 Docker 镜像打包过程全部使用 Github actions 进行,过程透明可见,可自行审计。
Q: 自动续期证书?
-> A: 已经申请的证书会在过期前10天自动续期。每天会检查一次证书是否快要过期,快要过期时会自动重新申请证书并部署到目标服务上。
+> A: 已经申请的证书会在过期前 10 天自动续期。每天会检查一次证书是否快要过期,快要过期时会自动重新申请证书并部署到目标服务上。
## 七、贡献
@@ -153,17 +154,18 @@ Certimate 是一个免费且开源的项目,采用 [MIT 开源协议](LICENSE.
你可以通过以下方式来支持 Certimate 的开发:
-* [提交代码:如果你发现了 bug 或有新的功能需求,而你又有相关经验,可以提交代码给我们](CONTRIBUTING.md)。
-* 提交 issue:功能建议或者 bug 可以[提交 issue](https://github.com/usual2970/certimate/issues) 给我们。
+- [提交代码:如果你发现了 bug 或有新的功能需求,而你又有相关经验,可以提交代码给我们](CONTRIBUTING.md)。
+- 提交 issue:功能建议或者 bug 可以[提交 issue](https://github.com/usual2970/certimate/issues) 给我们。
支持更多服务商、UI 的优化改进、BUG 修复、文档完善等,欢迎大家提交 PR。
## 八、加入社区
-* [Telegram-a new era of messaging](https://t.me/+ZXphsppxUg41YmVl)
-* 微信群聊(超200人需邀请入群,可先加作者好友)
+- [Telegram-a new era of messaging](https://t.me/+ZXphsppxUg41YmVl)
+- 微信群聊(超 200 人需邀请入群,可先加作者好友)
## 九、Star History
+
[](https://starchart.cc/usual2970/certimate)
diff --git a/README_EN.md b/README_EN.md
index 4d1794ea..9064b8b6 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -15,8 +15,8 @@ Certimate was created to solve the above-mentioned issues and has the following
Related articles:
-* [Why Certimate?](https://docs.certimate.me/blog/why-certimate)
-* [Introduction to Domain Variables and Deployment Authorization Groups](https://docs.certimate.me/blog/multi-deployer)
+- [Why Certimate?](https://docs.certimate.me/blog/why-certimate)
+- [Introduction to Domain Variables and Deployment Authorization Groups](https://docs.certimate.me/blog/multi-deployer)
Certimate aims to provide users with a secure and user-friendly SSL certificate management solution. For usage documentation, please visit.[https://docs.certimate.me](https://docs.certimate.me)
@@ -96,10 +96,10 @@ password:1234567890
The workflow of Certimate is as follows:
-* Users fill in the certificate application information on the Certimate management page, including domain name, authorization information for the DNS provider, and authorization information for the service provider to deploy to.
-* Certimate sends a request to the certificate vendor's API to apply for an SSL certificate.
-* Certimate stores the certificate information, including the certificate content, private key, validity period, etc., and automatically renews the certificate when it is about to expire.
-* Certimate sends a deployment request to the service provider's API to deploy the certificate to the service provider's servers.
+- Users fill in the certificate application information on the Certimate management page, including domain name, authorization information for the DNS provider, and authorization information for the service provider to deploy to.
+- Certimate sends a request to the certificate vendor's API to apply for an SSL certificate.
+- Certimate stores the certificate information, including the certificate content, private key, validity period, etc., and automatically renews the certificate when it is about to expire.
+- Certimate sends a deployment request to the service provider's API to deploy the certificate to the service provider's servers.
This involves authorization information for the domain, DNS provider, and deployment service provider.
@@ -153,14 +153,14 @@ Certimate is a free and open-source project, licensed under the [MIT License](LI
You can support the development of Certimate in the following ways:
-* **Submit Code**: If you find a bug or have new feature requests, and you have relevant experience, [you can submit code to us](CONTRIBUTING_EN.md).
-* **Submit an Issue**: For feature suggestions or bugs, you can [submit an issue](https://github.com/usual2970/certimate/issues) to us.
+- **Submit Code**: If you find a bug or have new feature requests, and you have relevant experience, [you can submit code to us](CONTRIBUTING_EN.md).
+- **Submit an Issue**: For feature suggestions or bugs, you can [submit an issue](https://github.com/usual2970/certimate/issues) to us.
Support for more service providers, UI enhancements, bug fixes, and documentation improvements are all welcome. We encourage everyone to submit pull requests (PRs).
## Join the Community
-* [Telegram-a new era of messaging](https://t.me/+ZXphsppxUg41YmVl)
-* Wechat Group
+- [Telegram-a new era of messaging](https://t.me/+ZXphsppxUg41YmVl)
+- Wechat Group
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 385bc989..858148e8 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -1,10 +1,10 @@
-version: '3.0'
+version: "3.0"
services:
- certimate:
- image: registry.cn-shanghai.aliyuncs.com/usual2970/certimate:latest
- container_name: certimate_server
- ports:
+ certimate:
+ image: registry.cn-shanghai.aliyuncs.com/usual2970/certimate:latest
+ container_name: certimate_server
+ ports:
- 8090:8090
- volumes:
+ volumes:
- ./data:/app/pb_data
- restart: unless-stopped
\ No newline at end of file
+ restart: unless-stopped
diff --git a/nixpacks.toml b/nixpacks.toml
index 1d68c6bf..c56baee7 100644
--- a/nixpacks.toml
+++ b/nixpacks.toml
@@ -27,4 +27,4 @@ nixOverlays = []
nixpkgsArchive = '1f13eabcd6f5b00fe9de9575ac52c66a0e887ce6'
[start]
-cmd = './out serve --http=0.0.0.0:8090 --dir=/data/pb_data '
\ No newline at end of file
+cmd = './out serve --http=0.0.0.0:8090 --dir=/data/pb_data '
diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json
deleted file mode 100644
index 2e03ca09..00000000
--- a/node_modules/.package-lock.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "certimate",
- "lockfileVersion": 3,
- "requires": true,
- "packages": {
- "node_modules/immer": {
- "version": "10.1.1",
- "resolved": "https://registry.npmmirror.com/immer/-/immer-10.1.1.tgz",
- "integrity": "sha512-s2MPrmjovJcoMaHtx6K11Ra7oD05NT97w1IC5zpMkT6Atjr7H8LjaDd81iIxUYpMKSRRNMJE703M1Fhr/TctHw==",
- "funding": {
- "type": "opencollective",
- "url": "https://opencollective.com/immer"
- }
- }
- }
-}
diff --git a/node_modules/immer/LICENSE b/node_modules/immer/LICENSE
deleted file mode 100644
index c0141158..00000000
--- a/node_modules/immer/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2017 Michel Weststrate
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/node_modules/immer/dist/cjs/immer.cjs.development.js b/node_modules/immer/dist/cjs/immer.cjs.development.js
deleted file mode 100644
index 893f6952..00000000
--- a/node_modules/immer/dist/cjs/immer.cjs.development.js
+++ /dev/null
@@ -1,1276 +0,0 @@
-"use strict";
-var __defProp = Object.defineProperty;
-var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
-var __getOwnPropNames = Object.getOwnPropertyNames;
-var __hasOwnProp = Object.prototype.hasOwnProperty;
-var __export = (target, all) => {
- for (var name in all)
- __defProp(target, name, { get: all[name], enumerable: true });
-};
-var __copyProps = (to, from, except, desc) => {
- if (from && typeof from === "object" || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
- }
- return to;
-};
-var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
-
-// src/immer.ts
-var immer_exports = {};
-__export(immer_exports, {
- Immer: () => Immer2,
- applyPatches: () => applyPatches,
- castDraft: () => castDraft,
- castImmutable: () => castImmutable,
- createDraft: () => createDraft,
- current: () => current,
- enableMapSet: () => enableMapSet,
- enablePatches: () => enablePatches,
- finishDraft: () => finishDraft,
- freeze: () => freeze,
- immerable: () => DRAFTABLE,
- isDraft: () => isDraft,
- isDraftable: () => isDraftable,
- nothing: () => NOTHING,
- original: () => original,
- produce: () => produce,
- produceWithPatches: () => produceWithPatches,
- setAutoFreeze: () => setAutoFreeze,
- setUseStrictShallowCopy: () => setUseStrictShallowCopy
-});
-module.exports = __toCommonJS(immer_exports);
-
-// src/utils/env.ts
-var NOTHING = Symbol.for("immer-nothing");
-var DRAFTABLE = Symbol.for("immer-draftable");
-var DRAFT_STATE = Symbol.for("immer-state");
-
-// src/utils/errors.ts
-var errors = process.env.NODE_ENV !== "production" ? [
- // All error codes, starting by 0:
- function(plugin) {
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
- },
- function(thing) {
- 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}'`;
- },
- "This object has been frozen and should not be mutated",
- function(data) {
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
- },
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
- "Immer forbids circular references",
- "The first or second argument to `produce` must be a function",
- "The third argument to `produce` must be a function or undefined",
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
- function(thing) {
- return `'current' expects a draft, got: ${thing}`;
- },
- "Object.defineProperty() cannot be used on an Immer draft",
- "Object.setPrototypeOf() cannot be used on an Immer draft",
- "Immer only supports deleting array indices",
- "Immer only supports setting array indices and the 'length' property",
- function(thing) {
- return `'original' expects a draft, got: ${thing}`;
- }
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
- // See Patches.ts for additional errors
-] : [];
-function die(error, ...args) {
- if (process.env.NODE_ENV !== "production") {
- const e = errors[error];
- const msg = typeof e === "function" ? e.apply(null, args) : e;
- throw new Error(`[Immer] ${msg}`);
- }
- throw new Error(
- `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
- );
-}
-
-// src/utils/common.ts
-var getPrototypeOf = Object.getPrototypeOf;
-function isDraft(value) {
- return !!value && !!value[DRAFT_STATE];
-}
-function isDraftable(value) {
- if (!value)
- return false;
- return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
-}
-var objectCtorString = Object.prototype.constructor.toString();
-function isPlainObject(value) {
- if (!value || typeof value !== "object")
- return false;
- const proto = getPrototypeOf(value);
- if (proto === null) {
- return true;
- }
- const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
- if (Ctor === Object)
- return true;
- return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
-}
-function original(value) {
- if (!isDraft(value))
- die(15, value);
- return value[DRAFT_STATE].base_;
-}
-function each(obj, iter) {
- if (getArchtype(obj) === 0 /* Object */) {
- Reflect.ownKeys(obj).forEach((key) => {
- iter(key, obj[key], obj);
- });
- } else {
- obj.forEach((entry, index) => iter(index, entry, obj));
- }
-}
-function getArchtype(thing) {
- const state = thing[DRAFT_STATE];
- return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
-}
-function has(thing, prop) {
- return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
-}
-function get(thing, prop) {
- return getArchtype(thing) === 2 /* Map */ ? thing.get(prop) : thing[prop];
-}
-function set(thing, propOrOldValue, value) {
- const t = getArchtype(thing);
- if (t === 2 /* Map */)
- thing.set(propOrOldValue, value);
- else if (t === 3 /* Set */) {
- thing.add(value);
- } else
- thing[propOrOldValue] = value;
-}
-function is(x, y) {
- if (x === y) {
- return x !== 0 || 1 / x === 1 / y;
- } else {
- return x !== x && y !== y;
- }
-}
-function isMap(target) {
- return target instanceof Map;
-}
-function isSet(target) {
- return target instanceof Set;
-}
-function latest(state) {
- return state.copy_ || state.base_;
-}
-function shallowCopy(base, strict) {
- if (isMap(base)) {
- return new Map(base);
- }
- if (isSet(base)) {
- return new Set(base);
- }
- if (Array.isArray(base))
- return Array.prototype.slice.call(base);
- const isPlain = isPlainObject(base);
- if (strict === true || strict === "class_only" && !isPlain) {
- const descriptors = Object.getOwnPropertyDescriptors(base);
- delete descriptors[DRAFT_STATE];
- let keys = Reflect.ownKeys(descriptors);
- for (let i = 0; i < keys.length; i++) {
- const key = keys[i];
- const desc = descriptors[key];
- if (desc.writable === false) {
- desc.writable = true;
- desc.configurable = true;
- }
- if (desc.get || desc.set)
- descriptors[key] = {
- configurable: true,
- writable: true,
- // could live with !!desc.set as well here...
- enumerable: desc.enumerable,
- value: base[key]
- };
- }
- return Object.create(getPrototypeOf(base), descriptors);
- } else {
- const proto = getPrototypeOf(base);
- if (proto !== null && isPlain) {
- return { ...base };
- }
- const obj = Object.create(proto);
- return Object.assign(obj, base);
- }
-}
-function freeze(obj, deep = false) {
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
- return obj;
- if (getArchtype(obj) > 1) {
- obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
- }
- Object.freeze(obj);
- if (deep)
- Object.entries(obj).forEach(([key, value]) => freeze(value, true));
- return obj;
-}
-function dontMutateFrozenCollections() {
- die(2);
-}
-function isFrozen(obj) {
- return Object.isFrozen(obj);
-}
-
-// src/utils/plugins.ts
-var plugins = {};
-function getPlugin(pluginKey) {
- const plugin = plugins[pluginKey];
- if (!plugin) {
- die(0, pluginKey);
- }
- return plugin;
-}
-function loadPlugin(pluginKey, implementation) {
- if (!plugins[pluginKey])
- plugins[pluginKey] = implementation;
-}
-
-// src/core/scope.ts
-var currentScope;
-function getCurrentScope() {
- return currentScope;
-}
-function createScope(parent_, immer_) {
- return {
- drafts_: [],
- parent_,
- immer_,
- // Whenever the modified draft contains a draft from another scope, we
- // need to prevent auto-freezing so the unowned draft can be finalized.
- canAutoFreeze_: true,
- unfinalizedDrafts_: 0
- };
-}
-function usePatchesInScope(scope, patchListener) {
- if (patchListener) {
- getPlugin("Patches");
- scope.patches_ = [];
- scope.inversePatches_ = [];
- scope.patchListener_ = patchListener;
- }
-}
-function revokeScope(scope) {
- leaveScope(scope);
- scope.drafts_.forEach(revokeDraft);
- scope.drafts_ = null;
-}
-function leaveScope(scope) {
- if (scope === currentScope) {
- currentScope = scope.parent_;
- }
-}
-function enterScope(immer2) {
- return currentScope = createScope(currentScope, immer2);
-}
-function revokeDraft(draft) {
- const state = draft[DRAFT_STATE];
- if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
- state.revoke_();
- else
- state.revoked_ = true;
-}
-
-// src/core/finalize.ts
-function processResult(result, scope) {
- scope.unfinalizedDrafts_ = scope.drafts_.length;
- const baseDraft = scope.drafts_[0];
- const isReplaced = result !== void 0 && result !== baseDraft;
- if (isReplaced) {
- if (baseDraft[DRAFT_STATE].modified_) {
- revokeScope(scope);
- die(4);
- }
- if (isDraftable(result)) {
- result = finalize(scope, result);
- if (!scope.parent_)
- maybeFreeze(scope, result);
- }
- if (scope.patches_) {
- getPlugin("Patches").generateReplacementPatches_(
- baseDraft[DRAFT_STATE].base_,
- result,
- scope.patches_,
- scope.inversePatches_
- );
- }
- } else {
- result = finalize(scope, baseDraft, []);
- }
- revokeScope(scope);
- if (scope.patches_) {
- scope.patchListener_(scope.patches_, scope.inversePatches_);
- }
- return result !== NOTHING ? result : void 0;
-}
-function finalize(rootScope, value, path) {
- if (isFrozen(value))
- return value;
- const state = value[DRAFT_STATE];
- if (!state) {
- each(
- value,
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
- );
- return value;
- }
- if (state.scope_ !== rootScope)
- return value;
- if (!state.modified_) {
- maybeFreeze(rootScope, state.base_, true);
- return state.base_;
- }
- if (!state.finalized_) {
- state.finalized_ = true;
- state.scope_.unfinalizedDrafts_--;
- const result = state.copy_;
- let resultEach = result;
- let isSet2 = false;
- if (state.type_ === 3 /* Set */) {
- resultEach = new Set(result);
- result.clear();
- isSet2 = true;
- }
- each(
- resultEach,
- (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
- );
- maybeFreeze(rootScope, result, false);
- if (path && rootScope.patches_) {
- getPlugin("Patches").generatePatches_(
- state,
- path,
- rootScope.patches_,
- rootScope.inversePatches_
- );
- }
- }
- return state.copy_;
-}
-function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
- die(5);
- if (isDraft(childValue)) {
- const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
- const res = finalize(rootScope, childValue, path);
- set(targetObject, prop, res);
- if (isDraft(res)) {
- rootScope.canAutoFreeze_ = false;
- } else
- return;
- } else if (targetIsSet) {
- targetObject.add(childValue);
- }
- if (isDraftable(childValue) && !isFrozen(childValue)) {
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
- return;
- }
- finalize(rootScope, childValue);
- if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
- maybeFreeze(rootScope, childValue);
- }
-}
-function maybeFreeze(scope, value, deep = false) {
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
- freeze(value, deep);
- }
-}
-
-// src/core/proxy.ts
-function createProxyProxy(base, parent) {
- const isArray = Array.isArray(base);
- const state = {
- type_: isArray ? 1 /* Array */ : 0 /* Object */,
- // Track which produce call this is associated with.
- scope_: parent ? parent.scope_ : getCurrentScope(),
- // True for both shallow and deep changes.
- modified_: false,
- // Used during finalization.
- finalized_: false,
- // Track which properties have been assigned (true) or deleted (false).
- assigned_: {},
- // The parent draft state.
- parent_: parent,
- // The base state.
- base_: base,
- // The base proxy.
- draft_: null,
- // set below
- // The base copy with any updated values.
- copy_: null,
- // Called by the `produce` function.
- revoke_: null,
- isManual_: false
- };
- let target = state;
- let traps = objectTraps;
- if (isArray) {
- target = [state];
- traps = arrayTraps;
- }
- const { revoke, proxy } = Proxy.revocable(target, traps);
- state.draft_ = proxy;
- state.revoke_ = revoke;
- return proxy;
-}
-var objectTraps = {
- get(state, prop) {
- if (prop === DRAFT_STATE)
- return state;
- const source = latest(state);
- if (!has(source, prop)) {
- return readPropFromProto(state, source, prop);
- }
- const value = source[prop];
- if (state.finalized_ || !isDraftable(value)) {
- return value;
- }
- if (value === peek(state.base_, prop)) {
- prepareCopy(state);
- return state.copy_[prop] = createProxy(value, state);
- }
- return value;
- },
- has(state, prop) {
- return prop in latest(state);
- },
- ownKeys(state) {
- return Reflect.ownKeys(latest(state));
- },
- set(state, prop, value) {
- const desc = getDescriptorFromProto(latest(state), prop);
- if (desc?.set) {
- desc.set.call(state.draft_, value);
- return true;
- }
- if (!state.modified_) {
- const current2 = peek(latest(state), prop);
- const currentState = current2?.[DRAFT_STATE];
- if (currentState && currentState.base_ === value) {
- state.copy_[prop] = value;
- state.assigned_[prop] = false;
- return true;
- }
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
- return true;
- prepareCopy(state);
- markChanged(state);
- }
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
- (value !== void 0 || prop in state.copy_) || // special case: NaN
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
- return true;
- state.copy_[prop] = value;
- state.assigned_[prop] = true;
- return true;
- },
- deleteProperty(state, prop) {
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
- state.assigned_[prop] = false;
- prepareCopy(state);
- markChanged(state);
- } else {
- delete state.assigned_[prop];
- }
- if (state.copy_) {
- delete state.copy_[prop];
- }
- return true;
- },
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
- // the same guarantee in ES5 mode.
- getOwnPropertyDescriptor(state, prop) {
- const owner = latest(state);
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
- if (!desc)
- return desc;
- return {
- writable: true,
- configurable: state.type_ !== 1 /* Array */ || prop !== "length",
- enumerable: desc.enumerable,
- value: owner[prop]
- };
- },
- defineProperty() {
- die(11);
- },
- getPrototypeOf(state) {
- return getPrototypeOf(state.base_);
- },
- setPrototypeOf() {
- die(12);
- }
-};
-var arrayTraps = {};
-each(objectTraps, (key, fn) => {
- arrayTraps[key] = function() {
- arguments[0] = arguments[0][0];
- return fn.apply(this, arguments);
- };
-});
-arrayTraps.deleteProperty = function(state, prop) {
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
- die(13);
- return arrayTraps.set.call(this, state, prop, void 0);
-};
-arrayTraps.set = function(state, prop, value) {
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
- die(14);
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
-};
-function peek(draft, prop) {
- const state = draft[DRAFT_STATE];
- const source = state ? latest(state) : draft;
- return source[prop];
-}
-function readPropFromProto(state, source, prop) {
- const desc = getDescriptorFromProto(source, prop);
- return desc ? `value` in desc ? desc.value : (
- // This is a very special case, if the prop is a getter defined by the
- // prototype, we should invoke it with the draft as context!
- desc.get?.call(state.draft_)
- ) : void 0;
-}
-function getDescriptorFromProto(source, prop) {
- if (!(prop in source))
- return void 0;
- let proto = getPrototypeOf(source);
- while (proto) {
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
- if (desc)
- return desc;
- proto = getPrototypeOf(proto);
- }
- return void 0;
-}
-function markChanged(state) {
- if (!state.modified_) {
- state.modified_ = true;
- if (state.parent_) {
- markChanged(state.parent_);
- }
- }
-}
-function prepareCopy(state) {
- if (!state.copy_) {
- state.copy_ = shallowCopy(
- state.base_,
- state.scope_.immer_.useStrictShallowCopy_
- );
- }
-}
-
-// src/core/immerClass.ts
-var Immer2 = class {
- constructor(config) {
- this.autoFreeze_ = true;
- this.useStrictShallowCopy_ = false;
- /**
- * The `produce` function takes a value and a "recipe function" (whose
- * return value often depends on the base state). The recipe function is
- * free to mutate its first argument however it wants. All mutations are
- * only ever applied to a __copy__ of the base state.
- *
- * Pass only a function to create a "curried producer" which relieves you
- * from passing the recipe function every time.
- *
- * Only plain objects and arrays are made mutable. All other objects are
- * considered uncopyable.
- *
- * Note: This function is __bound__ to its `Immer` instance.
- *
- * @param {any} base - the initial state
- * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
- * @param {Function} patchListener - optional function that will be called with all the patches produced here
- * @returns {any} a new state, or the initial state if nothing was modified
- */
- this.produce = (base, recipe, patchListener) => {
- if (typeof base === "function" && typeof recipe !== "function") {
- const defaultBase = recipe;
- recipe = base;
- const self = this;
- return function curriedProduce(base2 = defaultBase, ...args) {
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
- };
- }
- if (typeof recipe !== "function")
- die(6);
- if (patchListener !== void 0 && typeof patchListener !== "function")
- die(7);
- let result;
- if (isDraftable(base)) {
- const scope = enterScope(this);
- const proxy = createProxy(base, void 0);
- let hasError = true;
- try {
- result = recipe(proxy);
- hasError = false;
- } finally {
- if (hasError)
- revokeScope(scope);
- else
- leaveScope(scope);
- }
- usePatchesInScope(scope, patchListener);
- return processResult(result, scope);
- } else if (!base || typeof base !== "object") {
- result = recipe(base);
- if (result === void 0)
- result = base;
- if (result === NOTHING)
- result = void 0;
- if (this.autoFreeze_)
- freeze(result, true);
- if (patchListener) {
- const p = [];
- const ip = [];
- getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
- patchListener(p, ip);
- }
- return result;
- } else
- die(1, base);
- };
- this.produceWithPatches = (base, recipe) => {
- if (typeof base === "function") {
- return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
- }
- let patches, inversePatches;
- const result = this.produce(base, recipe, (p, ip) => {
- patches = p;
- inversePatches = ip;
- });
- return [result, patches, inversePatches];
- };
- if (typeof config?.autoFreeze === "boolean")
- this.setAutoFreeze(config.autoFreeze);
- if (typeof config?.useStrictShallowCopy === "boolean")
- this.setUseStrictShallowCopy(config.useStrictShallowCopy);
- }
- createDraft(base) {
- if (!isDraftable(base))
- die(8);
- if (isDraft(base))
- base = current(base);
- const scope = enterScope(this);
- const proxy = createProxy(base, void 0);
- proxy[DRAFT_STATE].isManual_ = true;
- leaveScope(scope);
- return proxy;
- }
- finishDraft(draft, patchListener) {
- const state = draft && draft[DRAFT_STATE];
- if (!state || !state.isManual_)
- die(9);
- const { scope_: scope } = state;
- usePatchesInScope(scope, patchListener);
- return processResult(void 0, scope);
- }
- /**
- * Pass true to automatically freeze all copies created by Immer.
- *
- * By default, auto-freezing is enabled.
- */
- setAutoFreeze(value) {
- this.autoFreeze_ = value;
- }
- /**
- * Pass true to enable strict shallow copy.
- *
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
- */
- setUseStrictShallowCopy(value) {
- this.useStrictShallowCopy_ = value;
- }
- applyPatches(base, patches) {
- let i;
- for (i = patches.length - 1; i >= 0; i--) {
- const patch = patches[i];
- if (patch.path.length === 0 && patch.op === "replace") {
- base = patch.value;
- break;
- }
- }
- if (i > -1) {
- patches = patches.slice(i + 1);
- }
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
- if (isDraft(base)) {
- return applyPatchesImpl(base, patches);
- }
- return this.produce(
- base,
- (draft) => applyPatchesImpl(draft, patches)
- );
- }
-};
-function createProxy(value, parent) {
- const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
- const scope = parent ? parent.scope_ : getCurrentScope();
- scope.drafts_.push(draft);
- return draft;
-}
-
-// src/core/current.ts
-function current(value) {
- if (!isDraft(value))
- die(10, value);
- return currentImpl(value);
-}
-function currentImpl(value) {
- if (!isDraftable(value) || isFrozen(value))
- return value;
- const state = value[DRAFT_STATE];
- let copy;
- if (state) {
- if (!state.modified_)
- return state.base_;
- state.finalized_ = true;
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
- } else {
- copy = shallowCopy(value, true);
- }
- each(copy, (key, childValue) => {
- set(copy, key, currentImpl(childValue));
- });
- if (state) {
- state.finalized_ = false;
- }
- return copy;
-}
-
-// src/plugins/patches.ts
-function enablePatches() {
- const errorOffset = 16;
- if (process.env.NODE_ENV !== "production") {
- errors.push(
- 'Sets cannot have "replace" patches.',
- function(op) {
- return "Unsupported patch operation: " + op;
- },
- function(path) {
- return "Cannot apply patch, path doesn't resolve: " + path;
- },
- "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
- );
- }
- const REPLACE = "replace";
- const ADD = "add";
- const REMOVE = "remove";
- function generatePatches_(state, basePath, patches, inversePatches) {
- switch (state.type_) {
- case 0 /* Object */:
- case 2 /* Map */:
- return generatePatchesFromAssigned(
- state,
- basePath,
- patches,
- inversePatches
- );
- case 1 /* Array */:
- return generateArrayPatches(state, basePath, patches, inversePatches);
- case 3 /* Set */:
- return generateSetPatches(
- state,
- basePath,
- patches,
- inversePatches
- );
- }
- }
- function generateArrayPatches(state, basePath, patches, inversePatches) {
- let { base_, assigned_ } = state;
- let copy_ = state.copy_;
- if (copy_.length < base_.length) {
- ;
- [base_, copy_] = [copy_, base_];
- [patches, inversePatches] = [inversePatches, patches];
- }
- for (let i = 0; i < base_.length; i++) {
- if (assigned_[i] && copy_[i] !== base_[i]) {
- const path = basePath.concat([i]);
- patches.push({
- op: REPLACE,
- path,
- // Need to maybe clone it, as it can in fact be the original value
- // due to the base/copy inversion at the start of this function
- value: clonePatchValueIfNeeded(copy_[i])
- });
- inversePatches.push({
- op: REPLACE,
- path,
- value: clonePatchValueIfNeeded(base_[i])
- });
- }
- }
- for (let i = base_.length; i < copy_.length; i++) {
- const path = basePath.concat([i]);
- patches.push({
- op: ADD,
- path,
- // Need to maybe clone it, as it can in fact be the original value
- // due to the base/copy inversion at the start of this function
- value: clonePatchValueIfNeeded(copy_[i])
- });
- }
- for (let i = copy_.length - 1; base_.length <= i; --i) {
- const path = basePath.concat([i]);
- inversePatches.push({
- op: REMOVE,
- path
- });
- }
- }
- function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
- const { base_, copy_ } = state;
- each(state.assigned_, (key, assignedValue) => {
- const origValue = get(base_, key);
- const value = get(copy_, key);
- const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;
- if (origValue === value && op === REPLACE)
- return;
- const path = basePath.concat(key);
- patches.push(op === REMOVE ? { op, path } : { op, path, value });
- inversePatches.push(
- op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) }
- );
- });
- }
- function generateSetPatches(state, basePath, patches, inversePatches) {
- let { base_, copy_ } = state;
- let i = 0;
- base_.forEach((value) => {
- if (!copy_.has(value)) {
- const path = basePath.concat([i]);
- patches.push({
- op: REMOVE,
- path,
- value
- });
- inversePatches.unshift({
- op: ADD,
- path,
- value
- });
- }
- i++;
- });
- i = 0;
- copy_.forEach((value) => {
- if (!base_.has(value)) {
- const path = basePath.concat([i]);
- patches.push({
- op: ADD,
- path,
- value
- });
- inversePatches.unshift({
- op: REMOVE,
- path,
- value
- });
- }
- i++;
- });
- }
- function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {
- patches.push({
- op: REPLACE,
- path: [],
- value: replacement === NOTHING ? void 0 : replacement
- });
- inversePatches.push({
- op: REPLACE,
- path: [],
- value: baseValue
- });
- }
- function applyPatches_(draft, patches) {
- patches.forEach((patch) => {
- const { path, op } = patch;
- let base = draft;
- for (let i = 0; i < path.length - 1; i++) {
- const parentType = getArchtype(base);
- let p = path[i];
- if (typeof p !== "string" && typeof p !== "number") {
- p = "" + p;
- }
- if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === "__proto__" || p === "constructor"))
- die(errorOffset + 3);
- if (typeof base === "function" && p === "prototype")
- die(errorOffset + 3);
- base = get(base, p);
- if (typeof base !== "object")
- die(errorOffset + 2, path.join("/"));
- }
- const type = getArchtype(base);
- const value = deepClonePatchValue(patch.value);
- const key = path[path.length - 1];
- switch (op) {
- case REPLACE:
- switch (type) {
- case 2 /* Map */:
- return base.set(key, value);
- case 3 /* Set */:
- die(errorOffset);
- default:
- return base[key] = value;
- }
- case ADD:
- switch (type) {
- case 1 /* Array */:
- return key === "-" ? base.push(value) : base.splice(key, 0, value);
- case 2 /* Map */:
- return base.set(key, value);
- case 3 /* Set */:
- return base.add(value);
- default:
- return base[key] = value;
- }
- case REMOVE:
- switch (type) {
- case 1 /* Array */:
- return base.splice(key, 1);
- case 2 /* Map */:
- return base.delete(key);
- case 3 /* Set */:
- return base.delete(patch.value);
- default:
- return delete base[key];
- }
- default:
- die(errorOffset + 1, op);
- }
- });
- return draft;
- }
- function deepClonePatchValue(obj) {
- if (!isDraftable(obj))
- return obj;
- if (Array.isArray(obj))
- return obj.map(deepClonePatchValue);
- if (isMap(obj))
- return new Map(
- Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])
- );
- if (isSet(obj))
- return new Set(Array.from(obj).map(deepClonePatchValue));
- const cloned = Object.create(getPrototypeOf(obj));
- for (const key in obj)
- cloned[key] = deepClonePatchValue(obj[key]);
- if (has(obj, DRAFTABLE))
- cloned[DRAFTABLE] = obj[DRAFTABLE];
- return cloned;
- }
- function clonePatchValueIfNeeded(obj) {
- if (isDraft(obj)) {
- return deepClonePatchValue(obj);
- } else
- return obj;
- }
- loadPlugin("Patches", {
- applyPatches_,
- generatePatches_,
- generateReplacementPatches_
- });
-}
-
-// src/plugins/mapset.ts
-function enableMapSet() {
- class DraftMap extends Map {
- constructor(target, parent) {
- super();
- this[DRAFT_STATE] = {
- type_: 2 /* Map */,
- parent_: parent,
- scope_: parent ? parent.scope_ : getCurrentScope(),
- modified_: false,
- finalized_: false,
- copy_: void 0,
- assigned_: void 0,
- base_: target,
- draft_: this,
- isManual_: false,
- revoked_: false
- };
- }
- get size() {
- return latest(this[DRAFT_STATE]).size;
- }
- has(key) {
- return latest(this[DRAFT_STATE]).has(key);
- }
- set(key, value) {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- if (!latest(state).has(key) || latest(state).get(key) !== value) {
- prepareMapCopy(state);
- markChanged(state);
- state.assigned_.set(key, true);
- state.copy_.set(key, value);
- state.assigned_.set(key, true);
- }
- return this;
- }
- delete(key) {
- if (!this.has(key)) {
- return false;
- }
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- prepareMapCopy(state);
- markChanged(state);
- if (state.base_.has(key)) {
- state.assigned_.set(key, false);
- } else {
- state.assigned_.delete(key);
- }
- state.copy_.delete(key);
- return true;
- }
- clear() {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- if (latest(state).size) {
- prepareMapCopy(state);
- markChanged(state);
- state.assigned_ = /* @__PURE__ */ new Map();
- each(state.base_, (key) => {
- state.assigned_.set(key, false);
- });
- state.copy_.clear();
- }
- }
- forEach(cb, thisArg) {
- const state = this[DRAFT_STATE];
- latest(state).forEach((_value, key, _map) => {
- cb.call(thisArg, this.get(key), key, this);
- });
- }
- get(key) {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- const value = latest(state).get(key);
- if (state.finalized_ || !isDraftable(value)) {
- return value;
- }
- if (value !== state.base_.get(key)) {
- return value;
- }
- const draft = createProxy(value, state);
- prepareMapCopy(state);
- state.copy_.set(key, draft);
- return draft;
- }
- keys() {
- return latest(this[DRAFT_STATE]).keys();
- }
- values() {
- const iterator = this.keys();
- return {
- [Symbol.iterator]: () => this.values(),
- next: () => {
- const r = iterator.next();
- if (r.done)
- return r;
- const value = this.get(r.value);
- return {
- done: false,
- value
- };
- }
- };
- }
- entries() {
- const iterator = this.keys();
- return {
- [Symbol.iterator]: () => this.entries(),
- next: () => {
- const r = iterator.next();
- if (r.done)
- return r;
- const value = this.get(r.value);
- return {
- done: false,
- value: [r.value, value]
- };
- }
- };
- }
- [(DRAFT_STATE, Symbol.iterator)]() {
- return this.entries();
- }
- }
- function proxyMap_(target, parent) {
- return new DraftMap(target, parent);
- }
- function prepareMapCopy(state) {
- if (!state.copy_) {
- state.assigned_ = /* @__PURE__ */ new Map();
- state.copy_ = new Map(state.base_);
- }
- }
- class DraftSet extends Set {
- constructor(target, parent) {
- super();
- this[DRAFT_STATE] = {
- type_: 3 /* Set */,
- parent_: parent,
- scope_: parent ? parent.scope_ : getCurrentScope(),
- modified_: false,
- finalized_: false,
- copy_: void 0,
- base_: target,
- draft_: this,
- drafts_: /* @__PURE__ */ new Map(),
- revoked_: false,
- isManual_: false
- };
- }
- get size() {
- return latest(this[DRAFT_STATE]).size;
- }
- has(value) {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- if (!state.copy_) {
- return state.base_.has(value);
- }
- if (state.copy_.has(value))
- return true;
- if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))
- return true;
- return false;
- }
- add(value) {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- if (!this.has(value)) {
- prepareSetCopy(state);
- markChanged(state);
- state.copy_.add(value);
- }
- return this;
- }
- delete(value) {
- if (!this.has(value)) {
- return false;
- }
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- prepareSetCopy(state);
- markChanged(state);
- return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : (
- /* istanbul ignore next */
- false
- ));
- }
- clear() {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- if (latest(state).size) {
- prepareSetCopy(state);
- markChanged(state);
- state.copy_.clear();
- }
- }
- values() {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- prepareSetCopy(state);
- return state.copy_.values();
- }
- entries() {
- const state = this[DRAFT_STATE];
- assertUnrevoked(state);
- prepareSetCopy(state);
- return state.copy_.entries();
- }
- keys() {
- return this.values();
- }
- [(DRAFT_STATE, Symbol.iterator)]() {
- return this.values();
- }
- forEach(cb, thisArg) {
- const iterator = this.values();
- let result = iterator.next();
- while (!result.done) {
- cb.call(thisArg, result.value, result.value, this);
- result = iterator.next();
- }
- }
- }
- function proxySet_(target, parent) {
- return new DraftSet(target, parent);
- }
- function prepareSetCopy(state) {
- if (!state.copy_) {
- state.copy_ = /* @__PURE__ */ new Set();
- state.base_.forEach((value) => {
- if (isDraftable(value)) {
- const draft = createProxy(value, state);
- state.drafts_.set(value, draft);
- state.copy_.add(draft);
- } else {
- state.copy_.add(value);
- }
- });
- }
- }
- function assertUnrevoked(state) {
- if (state.revoked_)
- die(3, JSON.stringify(latest(state)));
- }
- loadPlugin("MapSet", { proxyMap_, proxySet_ });
-}
-
-// src/immer.ts
-var immer = new Immer2();
-var produce = immer.produce;
-var produceWithPatches = immer.produceWithPatches.bind(
- immer
-);
-var setAutoFreeze = immer.setAutoFreeze.bind(immer);
-var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
-var applyPatches = immer.applyPatches.bind(immer);
-var createDraft = immer.createDraft.bind(immer);
-var finishDraft = immer.finishDraft.bind(immer);
-function castDraft(value) {
- return value;
-}
-function castImmutable(value) {
- return value;
-}
-// Annotate the CommonJS export names for ESM import in node:
-0 && (module.exports = {
- Immer,
- applyPatches,
- castDraft,
- castImmutable,
- createDraft,
- current,
- enableMapSet,
- enablePatches,
- finishDraft,
- freeze,
- immerable,
- isDraft,
- isDraftable,
- nothing,
- original,
- produce,
- produceWithPatches,
- setAutoFreeze,
- setUseStrictShallowCopy
-});
-//# sourceMappingURL=immer.cjs.development.js.map
\ No newline at end of file
diff --git a/node_modules/immer/dist/cjs/immer.cjs.development.js.map b/node_modules/immer/dist/cjs/immer.cjs.development.js.map
deleted file mode 100644
index 5b6b3aec..00000000
--- a/node_modules/immer/dist/cjs/immer.cjs.development.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"sources":["../../src/immer.ts","../../src/utils/env.ts","../../src/utils/errors.ts","../../src/utils/common.ts","../../src/utils/plugins.ts","../../src/core/scope.ts","../../src/core/finalize.ts","../../src/core/proxy.ts","../../src/core/immerClass.ts","../../src/core/current.ts","../../src/plugins/patches.ts","../../src/plugins/mapset.ts"],"sourcesContent":["import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tNOTHING as nothing,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport function castDraft(value: T): Draft {\n\treturn value as any\n}\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport function castImmutable(value: T): Immutable {\n\treturn value as any\n}\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\n","// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","export const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = typeof e === \"function\" ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nexport const getPrototypeOf = Object.getPrototypeOf\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport function isDraft(value: any): boolean {\n\treturn !!value && !!value[DRAFT_STATE]\n}\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tArray.isArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value.constructor?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = Object.prototype.constructor.toString()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || typeof value !== \"object\") return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null) {\n\t\treturn true\n\t}\n\tconst Ctor =\n\t\tObject.hasOwnProperty.call(proto, \"constructor\") && proto.constructor\n\n\tif (Ctor === Object) return true\n\n\treturn (\n\t\ttypeof Ctor == \"function\" &&\n\t\tFunction.toString.call(Ctor) === objectCtorString\n\t)\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n * Regardless whether they are enumerable or symbols\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void\n): void\nexport function each(obj: any, iter: any) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\tReflect.ownKeys(obj).forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: Array.isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport function has(thing: any, prop: PropertyKey): boolean {\n\treturn getArchtype(thing) === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: Object.prototype.hasOwnProperty.call(thing, prop)\n}\n\n/*#__PURE__*/\nexport function get(thing: AnyMap | AnyObject, prop: PropertyKey): any {\n\t// @ts-ignore\n\treturn getArchtype(thing) === ArchType.Map ? thing.get(prop) : thing[prop]\n}\n\n/*#__PURE__*/\nexport function set(thing: any, propOrOldValue: PropertyKey, value: any) {\n\tconst t = getArchtype(thing)\n\tif (t === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (t === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\n/*#__PURE__*/\nexport function isMap(target: any): target is AnyMap {\n\treturn target instanceof Map\n}\n\n/*#__PURE__*/\nexport function isSet(target: any): target is AnySet {\n\treturn target instanceof Set\n}\n/*#__PURE__*/\nexport function latest(state: ImmerState): any {\n\treturn state.copy_ || state.base_\n}\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (Array.isArray(base)) return Array.prototype.slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = Object.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc.writable === false) {\n\t\t\t\tdesc.writable = true\n\t\t\t\tdesc.configurable = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\twritable: true, // could live with !!desc.set as well here...\n\t\t\t\t\tenumerable: desc.enumerable,\n\t\t\t\t\tvalue: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn Object.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = Object.create(proto)\n\t\treturn Object.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tobj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any\n\t}\n\tObject.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.entries (only string-like, enumerables) instead of each()\n\t\tObject.entries(obj).forEach(([key, value]) => freeze(value, true))\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nexport function isFrozen(obj: any): boolean {\n\treturn Object.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie\n} from \"../internal\"\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: {\n\t\tgeneratePatches_(\n\t\t\tstate: ImmerState,\n\t\t\tbasePath: PatchPath,\n\t\t\tpatches: Patch[],\n\t\t\tinversePatches: Patch[]\n\t\t): void\n\t\tgenerateReplacementPatches_(\n\t\t\tbase: any,\n\t\t\treplacement: any,\n\t\t\tpatches: Patch[],\n\t\t\tinversePatches: Patch[]\n\t\t): void\n\t\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\t}\n\tMapSet?: {\n\t\tproxyMap_(target: T, parent?: ImmerState): T\n\t\tproxySet_(target: T, parent?: ImmerState): T\n\t}\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tassigned_: Map | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport function getCurrentScope() {\n\treturn currentScope!\n}\n\nfunction createScope(\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope {\n\treturn {\n\t\tdrafts_: [],\n\t\tparent_,\n\t\timmer_,\n\t\t// Whenever the modified draft contains a draft from another scope, we\n\t\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\t\tcanAutoFreeze_: true,\n\t\tunfinalizedDrafts_: 0\n\t}\n}\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tgetPlugin(\"Patches\") // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport function enterScope(immer: Immer) {\n\treturn (currentScope = createScope(currentScope, immer))\n}\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\thas,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t\tif (!scope.parent_) maybeFreeze(scope, result)\n\t\t}\n\t\tif (scope.patches_) {\n\t\t\tgetPlugin(\"Patches\").generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope.patches_,\n\t\t\t\tscope.inversePatches_!\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft, [])\n\t}\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any, path?: PatchPath) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\t// A plain object, might need freezing, might contain drafts\n\tif (!state) {\n\t\teach(value, (key, childValue) =>\n\t\t\tfinalizeProperty(rootScope, state, value, key, childValue, path)\n\t\t)\n\t\treturn value\n\t}\n\t// Never finalize drafts owned by another scope.\n\tif (state.scope_ !== rootScope) return value\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\tmaybeFreeze(rootScope, state.base_, true)\n\t\treturn state.base_\n\t}\n\t// Not finalized yet, let's do that now\n\tif (!state.finalized_) {\n\t\tstate.finalized_ = true\n\t\tstate.scope_.unfinalizedDrafts_--\n\t\tconst result = state.copy_\n\t\t// Finalize all children of the copy\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\t// And we let finalizeProperty know it needs to re-add non-draft children back to the target\n\t\tlet resultEach = result\n\t\tlet isSet = false\n\t\tif (state.type_ === ArchType.Set) {\n\t\t\tresultEach = new Set(result)\n\t\t\tresult.clear()\n\t\t\tisSet = true\n\t\t}\n\t\teach(resultEach, (key, childValue) =>\n\t\t\tfinalizeProperty(rootScope, state, result, key, childValue, path, isSet)\n\t\t)\n\t\t// everything inside is frozen, we can freeze here\n\t\tmaybeFreeze(rootScope, result, false)\n\t\t// first time finalizing, let's create those patches\n\t\tif (path && rootScope.patches_) {\n\t\t\tgetPlugin(\"Patches\").generatePatches_(\n\t\t\t\tstate,\n\t\t\t\tpath,\n\t\t\t\trootScope.patches_,\n\t\t\t\trootScope.inversePatches_!\n\t\t\t)\n\t\t}\n\t}\n\treturn state.copy_\n}\n\nfunction finalizeProperty(\n\trootScope: ImmerScope,\n\tparentState: undefined | ImmerState,\n\ttargetObject: any,\n\tprop: string | number,\n\tchildValue: any,\n\trootPath?: PatchPath,\n\ttargetIsSet?: boolean\n) {\n\tif (process.env.NODE_ENV !== \"production\" && childValue === targetObject)\n\t\tdie(5)\n\tif (isDraft(childValue)) {\n\t\tconst path =\n\t\t\trootPath &&\n\t\t\tparentState &&\n\t\t\tparentState!.type_ !== ArchType.Set && // Set objects are atomic since they have no keys.\n\t\t\t!has((parentState as Exclude).assigned_!, prop) // Skip deep patches for assigned keys.\n\t\t\t\t? rootPath!.concat(prop)\n\t\t\t\t: undefined\n\t\t// Drafts owned by `scope` are finalized here.\n\t\tconst res = finalize(rootScope, childValue, path)\n\t\tset(targetObject, prop, res)\n\t\t// Drafts from another scope must prevented to be frozen\n\t\t// if we got a draft back from finalize, we're in a nested produce and shouldn't freeze\n\t\tif (isDraft(res)) {\n\t\t\trootScope.canAutoFreeze_ = false\n\t\t} else return\n\t} else if (targetIsSet) {\n\t\ttargetObject.add(childValue)\n\t}\n\t// Search new objects for unfinalized drafts. Frozen objects should never contain drafts.\n\tif (isDraftable(childValue) && !isFrozen(childValue)) {\n\t\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t\t// This benefits especially adding large data tree's without further processing.\n\t\t\t// See add-data.js perf test\n\t\t\treturn\n\t\t}\n\t\tfinalize(rootScope, childValue)\n\t\t// Immer deep freezes plain objects, so if there is no parent state, we freeze as well\n\t\t// Per #590, we never freeze symbolic properties. Just to make sure don't accidentally interfere\n\t\t// with other frameworks.\n\t\tif (\n\t\t\t(!parentState || !parentState.scope_.parent_) &&\n\t\t\ttypeof prop !== \"symbol\" &&\n\t\t\tObject.prototype.propertyIsEnumerable.call(targetObject, prop)\n\t\t)\n\t\t\tmaybeFreeze(rootScope, childValue)\n\t}\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tassigned_: {\n\t\t[property: string]: boolean\n\t}\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): Drafted {\n\tconst isArray = Array.isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: isArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\tassigned_: {},\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler