@zuplo/cli 7.6.3 → 7.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.d.ts +1 -1
  2. package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
  3. package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.js +149 -10
  4. package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.mjs +149 -10
  5. package/node_modules/@posthog/core/dist/index.d.ts +3 -1
  6. package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
  7. package/node_modules/@posthog/core/dist/index.js +48 -31
  8. package/node_modules/@posthog/core/dist/index.mjs +4 -2
  9. package/node_modules/@posthog/core/dist/logs/logs-utils.d.ts +1 -3
  10. package/node_modules/@posthog/core/dist/logs/logs-utils.d.ts.map +1 -1
  11. package/node_modules/@posthog/core/dist/logs/logs-utils.js +7 -170
  12. package/node_modules/@posthog/core/dist/logs/logs-utils.mjs +6 -163
  13. package/node_modules/@posthog/core/dist/metrics/index.js +2 -2
  14. package/node_modules/@posthog/core/dist/metrics/index.mjs +1 -1
  15. package/node_modules/@posthog/core/dist/metrics/metrics-utils.d.ts.map +1 -1
  16. package/node_modules/@posthog/core/dist/metrics/metrics-utils.js +4 -14
  17. package/node_modules/@posthog/core/dist/metrics/metrics-utils.mjs +3 -13
  18. package/node_modules/@posthog/core/dist/utils/otlp-any-value.d.ts +5 -0
  19. package/node_modules/@posthog/core/dist/utils/otlp-any-value.d.ts.map +1 -0
  20. package/node_modules/@posthog/core/dist/utils/otlp-any-value.js +207 -0
  21. package/node_modules/@posthog/core/dist/utils/otlp-any-value.mjs +170 -0
  22. package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts +38 -0
  23. package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts.map +1 -0
  24. package/node_modules/@posthog/core/dist/utils/otlp-resource.js +81 -0
  25. package/node_modules/@posthog/core/dist/utils/otlp-resource.mjs +41 -0
  26. package/node_modules/@posthog/core/dist/utils/user-agent-utils.d.ts +4 -4
  27. package/node_modules/@posthog/core/dist/utils/user-agent-utils.d.ts.map +1 -1
  28. package/node_modules/@posthog/core/dist/utils/user-agent-utils.js +16 -0
  29. package/node_modules/@posthog/core/dist/utils/user-agent-utils.mjs +16 -0
  30. package/node_modules/@posthog/core/package.json +1 -1
  31. package/node_modules/@posthog/core/src/featureFlagLocalEvaluation.ts +199 -12
  32. package/node_modules/@posthog/core/src/index.ts +2 -2
  33. package/node_modules/@posthog/core/src/logs/logs-utils.spec.ts +2 -350
  34. package/node_modules/@posthog/core/src/logs/logs-utils.ts +5 -215
  35. package/node_modules/@posthog/core/src/metrics/index.ts +1 -1
  36. package/node_modules/@posthog/core/src/metrics/metrics-utils.ts +3 -9
  37. package/node_modules/@posthog/core/src/utils/otlp-any-value.spec.ts +376 -0
  38. package/node_modules/@posthog/core/src/utils/otlp-any-value.ts +231 -0
  39. package/node_modules/@posthog/core/src/utils/otlp-resource.spec.ts +125 -0
  40. package/node_modules/@posthog/core/src/utils/otlp-resource.ts +89 -0
  41. package/node_modules/@posthog/core/src/utils/user-agent-utils.ts +22 -6
  42. package/node_modules/@posthog/types/dist/posthog-config.d.ts +22 -3
  43. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  44. package/node_modules/@posthog/types/package.json +1 -1
  45. package/node_modules/@posthog/types/src/posthog-config.ts +22 -3
  46. package/node_modules/@zuplo/core/package.json +1 -1
  47. package/node_modules/@zuplo/graphql/package.json +1 -1
  48. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  49. package/node_modules/@zuplo/otel/package.json +1 -1
  50. package/node_modules/@zuplo/runtime/out/esm/{chunk-W73FK5P6.js → chunk-HTMKXG7D.js} +94 -94
  51. package/node_modules/@zuplo/runtime/out/esm/chunk-HTMKXG7D.js.map +1 -0
  52. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  53. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  54. package/node_modules/@zuplo/runtime/out/types/index.d.ts +1 -1
  55. package/node_modules/@zuplo/runtime/package.json +1 -1
  56. package/node_modules/express-rate-limit/dist/index.cjs +6 -3
  57. package/node_modules/express-rate-limit/dist/index.d.cts +11 -0
  58. package/node_modules/express-rate-limit/dist/index.d.mts +11 -0
  59. package/node_modules/express-rate-limit/dist/index.d.ts +11 -0
  60. package/node_modules/express-rate-limit/dist/index.mjs +6 -3
  61. package/node_modules/express-rate-limit/{license.md → license} +7 -6
  62. package/node_modules/express-rate-limit/package.json +5 -5
  63. package/node_modules/express-rate-limit/readme.md +1 -0
  64. package/node_modules/fast-copy/README.md +52 -0
  65. package/node_modules/fast-copy/dist/cjs/index.cjs +54 -11
  66. package/node_modules/fast-copy/dist/cjs/index.cjs.map +1 -1
  67. package/node_modules/fast-copy/dist/cjs/index.d.cts +81 -1
  68. package/node_modules/fast-copy/dist/es/index.d.mts +81 -1
  69. package/node_modules/fast-copy/dist/es/index.mjs +54 -12
  70. package/node_modules/fast-copy/dist/es/index.mjs.map +1 -1
  71. package/node_modules/fast-copy/dist/umd/index.d.ts +81 -1
  72. package/node_modules/fast-copy/dist/umd/index.js +54 -11
  73. package/node_modules/fast-copy/dist/umd/index.js.map +1 -1
  74. package/node_modules/fast-copy/index.d.ts +81 -1
  75. package/node_modules/fast-copy/package.json +1 -1
  76. package/node_modules/fastq/package.json +1 -1
  77. package/node_modules/ip-address/README.md +92 -82
  78. package/node_modules/ip-address/dist/common.d.ts +20 -0
  79. package/node_modules/ip-address/dist/common.js +36 -0
  80. package/node_modules/ip-address/dist/common.js.map +1 -1
  81. package/node_modules/ip-address/dist/ipv4.d.ts +50 -0
  82. package/node_modules/ip-address/dist/ipv4.js +75 -0
  83. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  84. package/node_modules/ip-address/dist/ipv6.d.ts +79 -10
  85. package/node_modules/ip-address/dist/ipv6.js +120 -30
  86. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  87. package/node_modules/ip-address/dist/v4/constants.d.ts +12 -0
  88. package/node_modules/ip-address/dist/v4/constants.js +40 -1
  89. package/node_modules/ip-address/dist/v4/constants.js.map +1 -1
  90. package/node_modules/ip-address/dist/v6/constants.d.ts +14 -0
  91. package/node_modules/ip-address/dist/v6/constants.js +47 -1
  92. package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
  93. package/node_modules/ip-address/package.json +1 -1
  94. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  95. package/node_modules/qs/CHANGELOG.md +15 -0
  96. package/node_modules/qs/README.md +19 -1
  97. package/node_modules/qs/dist/qs.js +21 -21
  98. package/node_modules/qs/eslint.config.mjs +1 -1
  99. package/node_modules/qs/lib/parse.js +3 -4
  100. package/node_modules/qs/lib/stringify.js +23 -8
  101. package/node_modules/qs/lib/utils.js +10 -3
  102. package/node_modules/qs/package.json +4 -4
  103. package/node_modules/qs/test/parse.js +192 -3
  104. package/node_modules/qs/test/stringify.js +317 -0
  105. package/node_modules/qs/test/utils.js +12 -0
  106. package/package.json +11 -11
  107. package/node_modules/@zuplo/runtime/out/esm/chunk-W73FK5P6.js.map +0 -1
  108. package/node_modules/fastq/.nyc_output/14a00d8b-3fa4-4f2d-9cc9-7be2ee7816af.json +0 -1
  109. package/node_modules/fastq/.nyc_output/processinfo/14a00d8b-3fa4-4f2d-9cc9-7be2ee7816af.json +0 -1
  110. package/node_modules/fastq/.nyc_output/processinfo/index.json +0 -1
  111. /package/node_modules/@zuplo/runtime/out/esm/{chunk-W73FK5P6.js.LEGAL.txt → chunk-HTMKXG7D.js.LEGAL.txt} +0 -0
@@ -13877,7 +13877,7 @@ export declare type SemanticCacheInboundPolicyOptions = {
13877
13877
  */
13878
13878
  cacheBy: "function" | "propertyPath";
13879
13879
  /**
13880
- * The path to the property in the request body (JSON) to use as cache key. For example '.userId' would read the 'userId' property from the request body. Only works with cacheBy=propertyPath.
13880
+ * A light path selector into the JSON request body to use as the cache key. Start with `.` for dot notation or `[` for a quoted key containing dots or slashes, for example `.userId`, `.data.customerId`, or `["https://example.com/cache-key"]`. Only works with cacheBy=propertyPath.
13881
13881
  */
13882
13882
  cacheByPropertyPath?: string;
13883
13883
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "7.6.3",
4
+ "version": "7.6.5",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
@@ -297,9 +297,9 @@ var setDraft8Headers = (response, info, windowMs, name, key) => {
297
297
  response.append("RateLimit", `"${name}"; ${header}`);
298
298
  response.append("RateLimit-Policy", `"${name}"; ${policy}`);
299
299
  };
300
- var setRetryAfterHeader = (response, info, windowMs) => {
300
+ var setRetryAfterHeader = (response, info, windowMs, retryAfter) => {
301
301
  if (response.headersSent) return;
302
- const resetSeconds = getResetSeconds(windowMs, info.resetTime);
302
+ const resetSeconds = retryAfter ?? getResetSeconds(windowMs, info.resetTime);
303
303
  response.setHeader("Retry-After", resetSeconds.toString());
304
304
  };
305
305
 
@@ -566,6 +566,7 @@ var validations = {
566
566
  legacyHeaders: true,
567
567
  standardHeaders: true,
568
568
  identifier: true,
569
+ retryAfter: true,
569
570
  requestPropertyName: true,
570
571
  skipFailedRequests: true,
571
572
  skipSuccessfulRequests: true,
@@ -1050,7 +1051,9 @@ var rateLimit = (passedOptions) => {
1050
1051
  debug("limit exceeded");
1051
1052
  if (config.legacyHeaders || config.standardHeaders) {
1052
1053
  debug("set retry-after header");
1053
- setRetryAfterHeader(response, info, config.windowMs);
1054
+ const retrieveRetryAfter = typeof config.retryAfter === "function" ? config.retryAfter(request, response) : config.retryAfter;
1055
+ const retryAfter = await retrieveRetryAfter;
1056
+ setRetryAfterHeader(response, info, config.windowMs, retryAfter);
1054
1057
  }
1055
1058
  config.handler(request, response, next, options);
1056
1059
  return;
@@ -408,6 +408,17 @@ export type Options = {
408
408
  * Defaults to `{limit}-in-{window}`.
409
409
  */
410
410
  identifier: string | ValueDeterminingMiddleware<string>;
411
+ /**
412
+ * Method to generate a custom `Retry-After` header value (in seconds) when
413
+ * a client is rate limited.
414
+ *
415
+ * This is advisory only, it customizes what the header says, it does not
416
+ * change how long the limiter actually keeps blocking the client for.
417
+ * That is still controlled by `windowMs`.
418
+ *
419
+ * By default, the number of seconds remaining until the window resets.
420
+ */
421
+ retryAfter?: number | ValueDeterminingMiddleware<number>;
411
422
  /**
412
423
  * The name of the property on the request object to store the rate limit info.
413
424
  *
@@ -408,6 +408,17 @@ export type Options = {
408
408
  * Defaults to `{limit}-in-{window}`.
409
409
  */
410
410
  identifier: string | ValueDeterminingMiddleware<string>;
411
+ /**
412
+ * Method to generate a custom `Retry-After` header value (in seconds) when
413
+ * a client is rate limited.
414
+ *
415
+ * This is advisory only, it customizes what the header says, it does not
416
+ * change how long the limiter actually keeps blocking the client for.
417
+ * That is still controlled by `windowMs`.
418
+ *
419
+ * By default, the number of seconds remaining until the window resets.
420
+ */
421
+ retryAfter?: number | ValueDeterminingMiddleware<number>;
411
422
  /**
412
423
  * The name of the property on the request object to store the rate limit info.
413
424
  *
@@ -408,6 +408,17 @@ export type Options = {
408
408
  * Defaults to `{limit}-in-{window}`.
409
409
  */
410
410
  identifier: string | ValueDeterminingMiddleware<string>;
411
+ /**
412
+ * Method to generate a custom `Retry-After` header value (in seconds) when
413
+ * a client is rate limited.
414
+ *
415
+ * This is advisory only, it customizes what the header says, it does not
416
+ * change how long the limiter actually keeps blocking the client for.
417
+ * That is still controlled by `windowMs`.
418
+ *
419
+ * By default, the number of seconds remaining until the window resets.
420
+ */
421
+ retryAfter?: number | ValueDeterminingMiddleware<number>;
411
422
  /**
412
423
  * The name of the property on the request object to store the rate limit info.
413
424
  *
@@ -254,9 +254,9 @@ var setDraft8Headers = (response, info, windowMs, name, key) => {
254
254
  response.append("RateLimit", `"${name}"; ${header}`);
255
255
  response.append("RateLimit-Policy", `"${name}"; ${policy}`);
256
256
  };
257
- var setRetryAfterHeader = (response, info, windowMs) => {
257
+ var setRetryAfterHeader = (response, info, windowMs, retryAfter) => {
258
258
  if (response.headersSent) return;
259
- const resetSeconds = getResetSeconds(windowMs, info.resetTime);
259
+ const resetSeconds = retryAfter ?? getResetSeconds(windowMs, info.resetTime);
260
260
  response.setHeader("Retry-After", resetSeconds.toString());
261
261
  };
262
262
 
@@ -523,6 +523,7 @@ var validations = {
523
523
  legacyHeaders: true,
524
524
  standardHeaders: true,
525
525
  identifier: true,
526
+ retryAfter: true,
526
527
  requestPropertyName: true,
527
528
  skipFailedRequests: true,
528
529
  skipSuccessfulRequests: true,
@@ -1007,7 +1008,9 @@ var rateLimit = (passedOptions) => {
1007
1008
  debug("limit exceeded");
1008
1009
  if (config.legacyHeaders || config.standardHeaders) {
1009
1010
  debug("set retry-after header");
1010
- setRetryAfterHeader(response, info, config.windowMs);
1011
+ const retrieveRetryAfter = typeof config.retryAfter === "function" ? config.retryAfter(request, response) : config.retryAfter;
1012
+ const retryAfter = await retrieveRetryAfter;
1013
+ setRetryAfterHeader(response, info, config.windowMs, retryAfter);
1011
1014
  }
1012
1015
  config.handler(request, response, next, options);
1013
1016
  return;
@@ -1,4 +1,4 @@
1
- # MIT License
1
+ MIT License
2
2
 
3
3
  Copyright 2023 Nathan Friedly, Vedant K
4
4
 
@@ -13,8 +13,9 @@ The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "8.6.2",
3
+ "version": "8.7.0",
4
4
  "description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",
5
5
  "author": {
6
6
  "name": "Nathan Friedly",
@@ -90,16 +90,16 @@
90
90
  "@types/debug": "4.1.13",
91
91
  "@types/express": "5.0.6",
92
92
  "@types/jest": "30.0.0",
93
- "@types/node": "26.1.2",
93
+ "@types/node": "26.2.0",
94
94
  "@types/supertest": "7.2.1",
95
95
  "del-cli": "7.0.0",
96
96
  "dts-bundle-generator": "8.1.2",
97
- "esbuild": "0.28.1",
97
+ "esbuild": "0.28.2",
98
98
  "express": "5.2.1",
99
99
  "husky": "9.1.7",
100
100
  "jest": "30.4.2",
101
- "lint-staged": "17.2.0",
102
- "mintlify": "4.2.743",
101
+ "lint-staged": "17.3.0",
102
+ "mintlify": "4.2.817",
103
103
  "npm-run-all": "4.1.5",
104
104
  "prettier": "3.9.6",
105
105
  "ratelimit-header-parser": "0.1.0",
@@ -5,6 +5,7 @@
5
5
  [![tests](https://img.shields.io/github/actions/workflow/status/express-rate-limit/express-rate-limit/ci.yaml)](https://github.com/express-rate-limit/express-rate-limit/actions/workflows/ci.yaml)
6
6
  [![npm version](https://img.shields.io/npm/v/express-rate-limit.svg)](https://npmjs.org/package/express-rate-limit 'View this project on NPM')
7
7
  [![npm downloads](https://img.shields.io/npm/dm/express-rate-limit)](https://www.npmjs.com/package/express-rate-limit)
8
+ [![inspect.software](https://raw.githubusercontent.com/inspect-software/badges/main/v1/e/express-rate-limit/express-rate-limit.svg)](https://inspect.software/software/express-rate-limit/express-rate-limit)
8
9
  [![license](https://img.shields.io/npm/l/express-rate-limit)](license.md)
9
10
 
10
11
  </div>
@@ -16,6 +16,7 @@ A [blazing fast](#benchmarks) deep object copier
16
16
  - [`copyStrict`](#copystrict)
17
17
  - [`createCopier`](#createcopier)
18
18
  - [`createCache`](#createcache)
19
+ - [`maxDepth`](#maxdepth)
19
20
  - [`methods`](#methods)
20
21
  - [Copier state](#copier-state)
21
22
  - [`cache`](#cache)
@@ -100,6 +101,7 @@ import { LRUCache } from 'lru-cache';
100
101
 
101
102
  const copyShallowStrict = createCopier({
102
103
  createCache: () => new LRUCache(),
104
+ maxDepth: 32,
103
105
  methods: {
104
106
  array: (array) => [...array],
105
107
  map: (map) => new Map(map.entries()),
@@ -115,6 +117,56 @@ const copyShallowStrict = createCopier({
115
117
  Method that creates the internal [`cache`](#cache) in the [Copier state](#copier-state). Defaults to creating a new
116
118
  `WeakMap` instance.
117
119
 
120
+ #### `maxDepth`
121
+
122
+ The maximum number of nested objects traversed before a `MaxDepthExceededError` is thrown. Defaults to `1000`.
123
+
124
+ Because copying is recursive, a value nested more deeply than the JavaScript engine's call stack allows will exhaust the
125
+ stack. The default limit sits below that threshold, so deeply-nested values fail with a descriptive, catchable error
126
+ instead of a raw `RangeError`:
127
+
128
+ ```js
129
+ import { copy, MaxDepthExceededError } from 'fast-copy';
130
+
131
+ try {
132
+ copy(untrustedPayload);
133
+ } catch (error) {
134
+ if (error instanceof MaxDepthExceededError) {
135
+ // `error.maxDepth` is the limit that was exceeded
136
+ }
137
+ }
138
+ ```
139
+
140
+ `MaxDepthExceededError` extends `RangeError`, so existing handling of the native stack-exhaustion error continues to
141
+ work.
142
+
143
+ The limit is configured when the copier is created, so [`copy`](#copy) and [`copyStrict`](#copystrict) always use the
144
+ default. If you copy values that are legitimately nested more deeply, create a copier with the limit you need and use it
145
+ in their place; pass `Infinity` to remove the limit entirely, in which case sufficiently-deep values will again throw a
146
+ native `RangeError`.
147
+
148
+ ```js
149
+ import { createCopier } from 'fast-copy';
150
+
151
+ export const copy = createCopier({ maxDepth: 5000 });
152
+ export const copyStrict = createCopier({ maxDepth: 5000, strict: true });
153
+ ```
154
+
155
+ The default of `1000` assumes the stack available to a standard Node.js or browser main thread, where the native limit
156
+ falls somewhere between roughly 1,800 and 4,000 levels depending on the copier used and the JIT's state. Environments
157
+ configured with a smaller stack, such as a worker started with a reduced `stackSizeMb`, can exhaust it sooner, so lower
158
+ the limit to suit the environment if you copy deeply-nested values in one.
159
+
160
+ ```js
161
+ const copyInWorker = createCopier({ maxDepth: 250 });
162
+ ```
163
+
164
+ The failure when the limit is set too high for the environment is the same native `RangeError` thrown prior to this
165
+ option existing, so too high a limit is never worse than having none.
166
+
167
+ **NOTE**: The depth counts nested objects only. Primitives and values already present in the [`cache`](#cache) (circular
168
+ references) do not contribute to it.
169
+
118
170
  #### `methods`
119
171
 
120
172
  Methods used for copying specific object types. A list of the methods and which object types they handle:
@@ -1,5 +1,19 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * Error thrown when the copier traverses deeper than the configured `maxDepth`.
5
+ *
6
+ * @note
7
+ * Extends `RangeError` for backwards compatibility, since exceeding the maximum depth
8
+ * previously surfaced as a native `RangeError` from stack exhaustion.
9
+ */
10
+ class MaxDepthExceededError extends RangeError {
11
+ constructor(maxDepth) {
12
+ super(`Maximum copy depth of ${String(maxDepth)} exceeded; the value copied is nested too deeply.`);
13
+ this.maxDepth = maxDepth;
14
+ this.name = 'MaxDepthExceededError';
15
+ }
16
+ }
3
17
  // eslint-disable-next-line @typescript-eslint/unbound-method
4
18
  const toStringFunction = Function.prototype.toString;
5
19
  // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -206,10 +220,19 @@ function copySetStrict(set, state) {
206
220
  return copyOwnPropertiesStrict(set, copySetLoose(set, state), state);
207
221
  }
208
222
 
223
+ /**
224
+ * The maximum depth traversed when none is provided.
225
+ *
226
+ * @note
227
+ * This is deliberately below the depth at which the native call stack is exhausted
228
+ * (~1875 for strict copies in node), so that untrusted, deeply-nested values fail with a
229
+ * catchable, descriptive error instead of a raw `RangeError`.
230
+ */
231
+ const DEFAULT_MAX_DEPTH = 1000;
209
232
  function createDefaultCache() {
210
233
  return new WeakMap();
211
234
  }
212
- function getOptions({ createCache: createCacheOverride, methods: methodsOverride, strict, }) {
235
+ function getOptions({ createCache: createCacheOverride, maxDepth, methods: methodsOverride, strict, }) {
213
236
  const defaultMethods = {
214
237
  array: strict ? copyArrayStrict : copyArrayLoose,
215
238
  arrayBuffer: copyArrayBuffer,
@@ -233,7 +256,13 @@ function getOptions({ createCache: createCacheOverride, methods: methodsOverride
233
256
  if (!copiers.Object || !copiers.Array) {
234
257
  throw new Error('An object and array copier must be provided.');
235
258
  }
236
- return { createCache, copiers, methods, strict: Boolean(strict) };
259
+ return {
260
+ createCache,
261
+ copiers,
262
+ maxDepth: maxDepth == null ? DEFAULT_MAX_DEPTH : maxDepth,
263
+ methods,
264
+ strict: Boolean(strict),
265
+ };
237
266
  }
238
267
  /**
239
268
  * Get the copiers used for each specific object tag.
@@ -280,7 +309,7 @@ function getTagSpecificCopiers(methods) {
280
309
  * - `strict` mode to copy all properties with their descriptors
281
310
  */
282
311
  function createCopier(options = {}) {
283
- const { createCache, copiers } = getOptions(options);
312
+ const { createCache, copiers, maxDepth } = getOptions(options);
284
313
  const { Array: copyArray, Object: copyObject } = copiers;
285
314
  function copier(value, state) {
286
315
  state.prototype = state.Constructor = undefined;
@@ -290,30 +319,43 @@ function createCopier(options = {}) {
290
319
  if (state.cache.has(value)) {
291
320
  return state.cache.get(value);
292
321
  }
322
+ // Bound the traversal of nested objects, so that values nested more deeply than the
323
+ // call stack can handle fail with a descriptive error instead of a raw `RangeError`.
324
+ if (++state.depth > maxDepth) {
325
+ throw new MaxDepthExceededError(maxDepth);
326
+ }
293
327
  state.prototype = Object.getPrototypeOf(value);
294
328
  // Using logical AND for speed, since optional chaining transforms to
295
329
  // a local variable usage.
296
330
  // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
297
331
  state.Constructor = state.prototype && state.prototype.constructor;
332
+ let clone;
298
333
  // plain objects
299
334
  if (!state.Constructor || state.Constructor === Object) {
300
- return copyObject(value, state);
335
+ clone = copyObject(value, state);
301
336
  }
302
- // arrays
303
- if (Array.isArray(value)) {
304
- return copyArray(value, state);
337
+ else if (Array.isArray(value)) {
338
+ // arrays
339
+ clone = copyArray(value, state);
305
340
  }
306
- const tagSpecificCopier = copiers[getTag(value)];
307
- if (tagSpecificCopier) {
308
- return tagSpecificCopier(value, state);
341
+ else {
342
+ const tagSpecificCopier = copiers[getTag(value)];
343
+ if (tagSpecificCopier) {
344
+ clone = tagSpecificCopier(value, state);
345
+ }
346
+ else {
347
+ clone = typeof value.then === 'function' ? value : copyObject(value, state);
348
+ }
309
349
  }
310
- return typeof value.then === 'function' ? value : copyObject(value, state);
350
+ --state.depth;
351
+ return clone;
311
352
  }
312
353
  return function copy(value) {
313
354
  return copier(value, {
314
355
  Constructor: undefined,
315
356
  cache: createCache(),
316
357
  copier,
358
+ depth: 0,
317
359
  prototype: undefined,
318
360
  });
319
361
  };
@@ -329,6 +371,7 @@ const copyStrict = createCopier({ strict: true });
329
371
  */
330
372
  const copy = createCopier();
331
373
 
374
+ exports.MaxDepthExceededError = MaxDepthExceededError;
332
375
  exports.copy = copy;
333
376
  exports.copyStrict = copyStrict;
334
377
  exports.createCopier = createCopier;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/utils.ts","../../../src/copier.ts","../../../src/options.ts","../../../src/index.ts"],"sourcesContent":["export interface Cache {\n has: (value: any) => boolean;\n set: (key: any, value: any) => void;\n get: (key: any) => any;\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst toStringFunction = Function.prototype.toString;\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst toStringObject = Object.prototype.toString;\n\n/**\n * Get an empty version of the object with the same prototype it has.\n */\nexport function getCleanClone(prototype: any): any {\n if (!prototype) {\n return Object.create(null);\n }\n\n const Constructor = prototype.constructor;\n\n if (Constructor === Object) {\n return prototype === Object.prototype ? {} : Object.create(prototype as object | null);\n }\n\n if (Constructor && ~toStringFunction.call(Constructor).indexOf('[native code]')) {\n try {\n return new Constructor();\n } catch {\n // Ignore\n }\n }\n\n return Object.create(prototype as object | null);\n}\n\n/**\n * Get the tag of the value passed, so that the correct copier can be used.\n */\nexport function getTag(value: any): string {\n const stringTag = value[Symbol.toStringTag];\n\n if (stringTag) {\n return stringTag;\n }\n\n const type = toStringObject.call(value);\n\n return type.substring(8, type.length - 1);\n}\n","import { getCleanClone } from './utils.js';\nimport type { Cache } from './utils.ts';\n\nexport type InternalCopier<Value> = (value: Value, state: State) => Value;\n\nexport interface State {\n Constructor: any;\n cache: Cache;\n copier: InternalCopier<any>;\n prototype: any;\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst { propertyIsEnumerable } = Object.prototype;\n\nfunction copyOwnDescriptor<Value extends object>(\n original: Value,\n clone: Value,\n property: string | symbol,\n state: State,\n): void {\n const ownDescriptor = Object.getOwnPropertyDescriptor(original, property) || {\n configurable: true,\n enumerable: true,\n value: original[property as keyof Value],\n writable: true,\n };\n const descriptor =\n ownDescriptor.get || ownDescriptor.set\n ? ownDescriptor\n : {\n configurable: ownDescriptor.configurable,\n enumerable: ownDescriptor.enumerable,\n value: state.copier(ownDescriptor.value, state),\n writable: ownDescriptor.writable,\n };\n\n try {\n Object.defineProperty(clone, property, descriptor);\n } catch {\n // The above can fail on node in extreme edge cases, so fall back to the loose assignment.\n clone[property as keyof Value] = descriptor.get ? descriptor.get() : descriptor.value;\n }\n}\n\n/**\n * Strictly copy all properties contained on the object.\n */\nfunction copyOwnPropertiesStrict<Value extends object>(value: Value, clone: Value, state: State): Value {\n for (const name of Object.getOwnPropertyNames(value)) {\n copyOwnDescriptor(value, clone, name, state);\n }\n\n for (const symbol of Object.getOwnPropertySymbols(value)) {\n copyOwnDescriptor(value, clone, symbol, state);\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the indexed values in the array.\n */\nexport function copyArrayLoose(array: any[], state: State) {\n const clone = new state.Constructor();\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n for (let index = 0; index < array.length; ++index) {\n clone[index] = state.copier(array[index], state);\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the indexed values in the array, as well as any custom properties.\n */\nexport function copyArrayStrict<Value extends any[]>(array: Value, state: State) {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n return copyOwnPropertiesStrict(array, clone, state);\n}\n\n/**\n * Copy the contents of the ArrayBuffer.\n */\nexport function copyArrayBuffer<Value extends ArrayBufferLike>(arrayBuffer: Value, _state: State): Value {\n return arrayBuffer.slice(0) as Value;\n}\n\n/**\n * Create a new Blob with the contents of the original.\n */\nexport function copyBlob<Value extends Blob>(blob: Value, _state: State): Value {\n return blob.slice(0, blob.size, blob.type) as Value;\n}\n\n/**\n * Create a new DataView with the contents of the original.\n */\nexport function copyDataView<Value extends DataView>(dataView: Value, state: State): Value {\n return new state.Constructor(copyArrayBuffer(dataView.buffer, state));\n}\n\n/**\n * Create a new Date based on the time of the original.\n */\nexport function copyDate<Value extends Date>(date: Value, state: State): Value {\n return new state.Constructor(date.getTime());\n}\n\n/**\n * Deeply copy the keys and values of the original.\n */\nexport function copyMapLoose<Value extends Map<any, any>>(map: Value, state: State): Value {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(map, clone);\n\n for (const [key, value] of map) {\n clone.set(key, state.copier(value, state));\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the keys and values of the original, as well as any custom properties.\n */\nexport function copyMapStrict<Value extends Map<any, any>>(map: Value, state: State) {\n return copyOwnPropertiesStrict(map, copyMapLoose(map, state), state);\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original.\n */\nexport function copyObjectLoose<Value extends Record<string, any>>(object: Value, state: State): Value {\n const clone = getCleanClone(state.prototype);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n for (const key of Object.keys(object)) {\n clone[key] = state.copier(object[key], state);\n }\n\n for (const symbol of Object.getOwnPropertySymbols(object)) {\n if (propertyIsEnumerable.call(object, symbol)) {\n clone[symbol] = state.copier((object as any)[symbol], state);\n }\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original, as well\n * as any hidden or non-enumerable properties.\n */\nexport function copyObjectStrict<Value extends Record<string, any>>(object: Value, state: State): Value {\n const clone = getCleanClone(state.prototype);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n return copyOwnPropertiesStrict(object, clone, state);\n}\n\n/**\n * Create a new primitive wrapper from the value of the original.\n */\nexport function copyPrimitiveWrapper<\n // Specifically use the object constructor types\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Value extends Boolean | Number | String,\n>(primitiveObject: Value, state: State): Value {\n return new state.Constructor(primitiveObject.valueOf());\n}\n\n/**\n * Create a new RegExp based on the value and flags of the original.\n */\nexport function copyRegExp<Value extends RegExp>(regExp: Value, state: State): Value {\n const clone = new state.Constructor(regExp.source, regExp.flags) as Value;\n\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n}\n\n/**\n * Return the original value (an identity function).\n *\n * @note\n * THis is used for objects that cannot be copied, such as WeakMap.\n */\nexport function copySelf<Value>(value: Value, _state: State): Value {\n return value;\n}\n\n/**\n * Deeply copy the values of the original.\n */\nexport function copySetLoose<Value extends Set<any>>(set: Value, state: State): Value {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(set, clone);\n\n for (const value of set) {\n clone.add(state.copier(value, state));\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the values of the original, as well as any custom properties.\n */\nexport function copySetStrict<Value extends Set<any>>(set: Value, state: State): Value {\n return copyOwnPropertiesStrict(set, copySetLoose(set, state), state);\n}\n","import {\n copyArrayBuffer,\n copyArrayLoose,\n copyArrayStrict,\n copyBlob,\n copyDataView,\n copyDate,\n copyMapLoose,\n copyMapStrict,\n copyObjectLoose,\n copyObjectStrict,\n copyPrimitiveWrapper,\n copyRegExp,\n copySelf,\n copySetLoose,\n copySetStrict,\n} from './copier.js';\nimport type { InternalCopier } from './copier.ts';\nimport type { Cache } from './utils.ts';\n\nexport interface CopierMethods {\n array?: InternalCopier<any[]>;\n arrayBuffer?: InternalCopier<ArrayBuffer>;\n asyncGenerator?: InternalCopier<AsyncGenerator>;\n blob?: InternalCopier<Blob>;\n dataView?: InternalCopier<DataView>;\n date?: InternalCopier<Date>;\n error?: InternalCopier<Error>;\n generator?: InternalCopier<Generator>;\n map?: InternalCopier<Map<any, any>>;\n object?: InternalCopier<Record<string, any>>;\n regExp?: InternalCopier<RegExp>;\n set?: InternalCopier<Set<any>>;\n}\n\ninterface Copiers {\n [key: string]: InternalCopier<any> | undefined;\n\n Arguments: InternalCopier<Record<string, any>>;\n Array: InternalCopier<any[]>;\n ArrayBuffer: InternalCopier<ArrayBuffer>;\n AsyncGenerator: InternalCopier<AsyncGenerator>;\n BigInt64Array: InternalCopier<ArrayBuffer>;\n BigUint64Array: InternalCopier<ArrayBuffer>;\n Blob: InternalCopier<Blob>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Boolean: InternalCopier<Boolean>;\n DataView: InternalCopier<DataView>;\n Date: InternalCopier<Date>;\n Error: InternalCopier<Error>;\n Float32Array: InternalCopier<ArrayBuffer>;\n Float64Array: InternalCopier<ArrayBuffer>;\n Generator: InternalCopier<Generator>;\n Int8Array: InternalCopier<ArrayBuffer>;\n Int16Array: InternalCopier<ArrayBuffer>;\n Int32Array: InternalCopier<ArrayBuffer>;\n Map: InternalCopier<Map<any, any>>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Number: InternalCopier<Number>;\n Object: InternalCopier<Record<string, any>>;\n Promise: InternalCopier<Promise<any>>;\n RegExp: InternalCopier<RegExp>;\n Set: InternalCopier<Set<any>>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n String: InternalCopier<String>;\n WeakMap: InternalCopier<WeakMap<any, any>>;\n WeakSet: InternalCopier<WeakSet<any>>;\n Uint8Array: InternalCopier<ArrayBuffer>;\n Uint8ClampedArray: InternalCopier<ArrayBuffer>;\n Uint16Array: InternalCopier<ArrayBuffer>;\n Uint32Array: InternalCopier<ArrayBuffer>;\n}\n\nexport interface CreateCopierOptions {\n createCache?: () => Cache;\n methods?: CopierMethods;\n strict?: boolean;\n}\n\nexport interface RequiredCreateCopierOptions extends Omit<Required<CreateCopierOptions>, 'methods'> {\n copiers: Copiers;\n methods: Required<CopierMethods>;\n}\n\nexport function createDefaultCache(): Cache {\n return new WeakMap();\n}\n\nexport function getOptions({\n createCache: createCacheOverride,\n methods: methodsOverride,\n strict,\n}: CreateCopierOptions): RequiredCreateCopierOptions {\n const defaultMethods = {\n array: strict ? copyArrayStrict : copyArrayLoose,\n arrayBuffer: copyArrayBuffer,\n asyncGenerator: copySelf,\n blob: copyBlob,\n dataView: copyDataView,\n date: copyDate,\n error: copySelf,\n generator: copySelf,\n map: strict ? copyMapStrict : copyMapLoose,\n object: strict ? copyObjectStrict : copyObjectLoose,\n regExp: copyRegExp,\n set: strict ? copySetStrict : copySetLoose,\n };\n\n const methods = methodsOverride ? Object.assign(defaultMethods, methodsOverride) : defaultMethods;\n const copiers = getTagSpecificCopiers(methods);\n const createCache = createCacheOverride || createDefaultCache;\n\n // Extra safety check to ensure that object and array copiers are always provided,\n // avoiding runtime errors.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!copiers.Object || !copiers.Array) {\n throw new Error('An object and array copier must be provided.');\n }\n\n return { createCache, copiers, methods, strict: Boolean(strict) };\n}\n\n/**\n * Get the copiers used for each specific object tag.\n */\nexport function getTagSpecificCopiers(methods: Required<CopierMethods>): Copiers {\n return {\n Arguments: methods.object,\n Array: methods.array,\n ArrayBuffer: methods.arrayBuffer,\n AsyncGenerator: methods.asyncGenerator,\n BigInt64Array: methods.arrayBuffer,\n BigUint64Array: methods.arrayBuffer,\n Blob: methods.blob,\n Boolean: copyPrimitiveWrapper,\n DataView: methods.dataView,\n Date: methods.date,\n Error: methods.error,\n Float32Array: methods.arrayBuffer,\n Float64Array: methods.arrayBuffer,\n Generator: methods.generator,\n Int8Array: methods.arrayBuffer,\n Int16Array: methods.arrayBuffer,\n Int32Array: methods.arrayBuffer,\n Map: methods.map,\n Number: copyPrimitiveWrapper,\n Object: methods.object,\n Promise: copySelf,\n RegExp: methods.regExp,\n Set: methods.set,\n String: copyPrimitiveWrapper,\n WeakMap: copySelf,\n WeakSet: copySelf,\n Uint8Array: methods.arrayBuffer,\n Uint8ClampedArray: methods.arrayBuffer,\n Uint16Array: methods.arrayBuffer,\n Uint32Array: methods.arrayBuffer,\n };\n}\n","import type { State } from './copier.ts';\nimport { getOptions } from './options.js';\nimport type { CreateCopierOptions } from './options.ts';\nimport { getTag } from './utils.js';\n\nexport type { State } from './copier.ts';\nexport type { CreateCopierOptions } from './options.ts';\n\n/**\n * Create a custom copier based on custom options for any of the following:\n * - `createCache` method to create a cache for copied objects\n * - custom copier `methods` for specific object types\n * - `strict` mode to copy all properties with their descriptors\n */\nexport function createCopier(options: CreateCopierOptions = {}) {\n const { createCache, copiers } = getOptions(options);\n const { Array: copyArray, Object: copyObject } = copiers;\n\n function copier(value: any, state: State): any {\n state.prototype = state.Constructor = undefined;\n\n if (!value || typeof value !== 'object') {\n return value;\n }\n\n if (state.cache.has(value)) {\n return state.cache.get(value);\n }\n\n state.prototype = Object.getPrototypeOf(value);\n // Using logical AND for speed, since optional chaining transforms to\n // a local variable usage.\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n state.Constructor = state.prototype && state.prototype.constructor;\n\n // plain objects\n if (!state.Constructor || state.Constructor === Object) {\n return copyObject(value as Record<string, any>, state);\n }\n\n // arrays\n if (Array.isArray(value)) {\n return copyArray(value, state);\n }\n\n const tagSpecificCopier = copiers[getTag(value)];\n\n if (tagSpecificCopier) {\n return tagSpecificCopier(value, state);\n }\n\n return typeof value.then === 'function' ? value : copyObject(value as Record<string, any>, state);\n }\n\n return function copy<Value>(value: Value): Value {\n return copier(value, {\n Constructor: undefined,\n cache: createCache(),\n copier,\n prototype: undefined,\n });\n };\n}\n\n/**\n * Copy an value deeply as much as possible, where strict recreation of object properties\n * are maintained. All properties (including non-enumerable ones) are copied with their\n * original property descriptors on both objects and arrays.\n */\nexport const copyStrict = createCopier({ strict: true });\n\n/**\n * Copy an value deeply as much as possible.\n */\nexport const copy = createCopier();\n"],"names":[],"mappings":";;AAMA;AACA,MAAM,gBAAgB,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ;AACpD;AACA,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ;AAEhD;;AAEG;AACG,SAAU,aAAa,CAAC,SAAc,EAAA;IAC1C,IAAI,CAAC,SAAS,EAAE;AACd,QAAA,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAC5B;AAEA,IAAA,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW;AAEzC,IAAA,IAAI,WAAW,KAAK,MAAM,EAAE;AAC1B,QAAA,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,SAA0B,CAAC;IACxF;AAEA,IAAA,IAAI,WAAW,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC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AC,WAAW,KAAK,MAAM,EAAE;AACtD,YAAA,OAAO,UAAU,CAAC,KAA4B,EAAE,KAAK,CAAC;QACxD;;AAGA,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACxB,YAAA,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;QAChC;QAEA,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAEhD,IAAI,iBAAiB,EAAE;AACrB,YAAA,OAAO,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC;QACxC;AAEA,QAAA,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,GAAG,KAAK,GAAG,UAAU,CAAC,KAA4B,EAAE,KAAK,CAAC;IACnG;IAEA,OAAO,SAAS,IAAI,CAAQ,KAAY,EAAA;QACtC,OAAO,MAAM,CAAC,KAAK,EAAE;AACnB,YAAA,WAAW,EAAE,SAAS;YACtB,KAAK,EAAE,WAAW,EAAE;YACpB,MAAM;AACN,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;AACJ,IAAA,CAAC;AACH;AAEA;;;;AAIG;AACI,MAAM,UAAU,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE;AAEvD;;AAEG;AACI,MAAM,IAAI,GAAG,YAAY;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/utils.ts","../../../src/copier.ts","../../../src/options.ts","../../../src/index.ts"],"sourcesContent":["export interface Cache {\n has: (value: any) => boolean;\n set: (key: any, value: any) => void;\n get: (key: any) => any;\n}\n\n/**\n * Error thrown when the copier traverses deeper than the configured `maxDepth`.\n *\n * @note\n * Extends `RangeError` for backwards compatibility, since exceeding the maximum depth\n * previously surfaced as a native `RangeError` from stack exhaustion.\n */\nexport class MaxDepthExceededError extends RangeError {\n readonly maxDepth: number;\n\n constructor(maxDepth: number) {\n super(`Maximum copy depth of ${String(maxDepth)} exceeded; the value copied is nested too deeply.`);\n\n this.maxDepth = maxDepth;\n this.name = 'MaxDepthExceededError';\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst toStringFunction = Function.prototype.toString;\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst toStringObject = Object.prototype.toString;\n\n/**\n * Get an empty version of the object with the same prototype it has.\n */\nexport function getCleanClone(prototype: any): any {\n if (!prototype) {\n return Object.create(null);\n }\n\n const Constructor = prototype.constructor;\n\n if (Constructor === Object) {\n return prototype === Object.prototype ? {} : Object.create(prototype as object | null);\n }\n\n if (Constructor && ~toStringFunction.call(Constructor).indexOf('[native code]')) {\n try {\n return new Constructor();\n } catch {\n // Ignore\n }\n }\n\n return Object.create(prototype as object | null);\n}\n\n/**\n * Get the tag of the value passed, so that the correct copier can be used.\n */\nexport function getTag(value: any): string {\n const stringTag = value[Symbol.toStringTag];\n\n if (stringTag) {\n return stringTag;\n }\n\n const type = toStringObject.call(value);\n\n return type.substring(8, type.length - 1);\n}\n","import { getCleanClone } from './utils.js';\nimport type { Cache } from './utils.ts';\n\nexport type InternalCopier<Value> = (value: Value, state: State) => Value;\n\nexport interface State {\n /**\n * The constructor of the value currently being copied, derived from its `prototype`.\n * Used to construct the clone for values that are not plain objects, such as subclasses\n * of `Array` or custom classes.\n *\n * @note\n * This is `undefined` for primitives and for values already present in the `cache`. It is\n * also reassigned for every value copied, so it must be read before any recursive\n * `copier` call is made, not after.\n */\n Constructor: any;\n /**\n * The cache of values already copied, mapping each original to its clone. Copiers should\n * populate it with the clone _before_ copying that value's contents, so that circular\n * references resolve to the clone rather than recursing infinitely.\n */\n cache: Cache;\n /**\n * The copier used for nested values. Call it as `state.copier(value, state)` to deeply\n * copy the contents of the value being copied.\n */\n copier: InternalCopier<any>;\n /**\n * The number of nested objects currently being copied, used to bound traversal of\n * deeply-nested values before the call stack is exhausted.\n *\n * @note\n * This is maintained by the copier itself; custom methods should not modify it.\n */\n depth: number;\n /**\n * The prototype of the value currently being copied, used to create a clone that\n * maintains the original's prototype chain.\n *\n * @note\n * This is `undefined` for primitives and for values already present in the `cache`. It is\n * also reassigned for every value copied, so it must be read before any recursive\n * `copier` call is made, not after.\n */\n prototype: any;\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst { propertyIsEnumerable } = Object.prototype;\n\nfunction copyOwnDescriptor<Value extends object>(\n original: Value,\n clone: Value,\n property: string | symbol,\n state: State,\n): void {\n const ownDescriptor = Object.getOwnPropertyDescriptor(original, property) || {\n configurable: true,\n enumerable: true,\n value: original[property as keyof Value],\n writable: true,\n };\n const descriptor =\n ownDescriptor.get || ownDescriptor.set\n ? ownDescriptor\n : {\n configurable: ownDescriptor.configurable,\n enumerable: ownDescriptor.enumerable,\n value: state.copier(ownDescriptor.value, state),\n writable: ownDescriptor.writable,\n };\n\n try {\n Object.defineProperty(clone, property, descriptor);\n } catch {\n // The above can fail on node in extreme edge cases, so fall back to the loose assignment.\n clone[property as keyof Value] = descriptor.get ? descriptor.get() : descriptor.value;\n }\n}\n\n/**\n * Strictly copy all properties contained on the object.\n */\nfunction copyOwnPropertiesStrict<Value extends object>(value: Value, clone: Value, state: State): Value {\n for (const name of Object.getOwnPropertyNames(value)) {\n copyOwnDescriptor(value, clone, name, state);\n }\n\n for (const symbol of Object.getOwnPropertySymbols(value)) {\n copyOwnDescriptor(value, clone, symbol, state);\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the indexed values in the array.\n */\nexport function copyArrayLoose(array: any[], state: State) {\n const clone = new state.Constructor();\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n for (let index = 0; index < array.length; ++index) {\n clone[index] = state.copier(array[index], state);\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the indexed values in the array, as well as any custom properties.\n */\nexport function copyArrayStrict<Value extends any[]>(array: Value, state: State) {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n return copyOwnPropertiesStrict(array, clone, state);\n}\n\n/**\n * Copy the contents of the ArrayBuffer.\n */\nexport function copyArrayBuffer<Value extends ArrayBufferLike>(arrayBuffer: Value, _state: State): Value {\n return arrayBuffer.slice(0) as Value;\n}\n\n/**\n * Create a new Blob with the contents of the original.\n */\nexport function copyBlob<Value extends Blob>(blob: Value, _state: State): Value {\n return blob.slice(0, blob.size, blob.type) as Value;\n}\n\n/**\n * Create a new DataView with the contents of the original.\n */\nexport function copyDataView<Value extends DataView>(dataView: Value, state: State): Value {\n return new state.Constructor(copyArrayBuffer(dataView.buffer, state));\n}\n\n/**\n * Create a new Date based on the time of the original.\n */\nexport function copyDate<Value extends Date>(date: Value, state: State): Value {\n return new state.Constructor(date.getTime());\n}\n\n/**\n * Deeply copy the keys and values of the original.\n */\nexport function copyMapLoose<Value extends Map<any, any>>(map: Value, state: State): Value {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(map, clone);\n\n for (const [key, value] of map) {\n clone.set(key, state.copier(value, state));\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the keys and values of the original, as well as any custom properties.\n */\nexport function copyMapStrict<Value extends Map<any, any>>(map: Value, state: State) {\n return copyOwnPropertiesStrict(map, copyMapLoose(map, state), state);\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original.\n */\nexport function copyObjectLoose<Value extends Record<string, any>>(object: Value, state: State): Value {\n const clone = getCleanClone(state.prototype);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n for (const key of Object.keys(object)) {\n clone[key] = state.copier(object[key], state);\n }\n\n for (const symbol of Object.getOwnPropertySymbols(object)) {\n if (propertyIsEnumerable.call(object, symbol)) {\n clone[symbol] = state.copier((object as any)[symbol], state);\n }\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original, as well\n * as any hidden or non-enumerable properties.\n */\nexport function copyObjectStrict<Value extends Record<string, any>>(object: Value, state: State): Value {\n const clone = getCleanClone(state.prototype);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n return copyOwnPropertiesStrict(object, clone, state);\n}\n\n/**\n * Create a new primitive wrapper from the value of the original.\n */\nexport function copyPrimitiveWrapper<\n // Specifically use the object constructor types\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Value extends Boolean | Number | String,\n>(primitiveObject: Value, state: State): Value {\n return new state.Constructor(primitiveObject.valueOf());\n}\n\n/**\n * Create a new RegExp based on the value and flags of the original.\n */\nexport function copyRegExp<Value extends RegExp>(regExp: Value, state: State): Value {\n const clone = new state.Constructor(regExp.source, regExp.flags) as Value;\n\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n}\n\n/**\n * Return the original value (an identity function).\n *\n * @note\n * THis is used for objects that cannot be copied, such as WeakMap.\n */\nexport function copySelf<Value>(value: Value, _state: State): Value {\n return value;\n}\n\n/**\n * Deeply copy the values of the original.\n */\nexport function copySetLoose<Value extends Set<any>>(set: Value, state: State): Value {\n const clone = new state.Constructor() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(set, clone);\n\n for (const value of set) {\n clone.add(state.copier(value, state));\n }\n\n return clone;\n}\n\n/**\n * Deeply copy the values of the original, as well as any custom properties.\n */\nexport function copySetStrict<Value extends Set<any>>(set: Value, state: State): Value {\n return copyOwnPropertiesStrict(set, copySetLoose(set, state), state);\n}\n","import {\n copyArrayBuffer,\n copyArrayLoose,\n copyArrayStrict,\n copyBlob,\n copyDataView,\n copyDate,\n copyMapLoose,\n copyMapStrict,\n copyObjectLoose,\n copyObjectStrict,\n copyPrimitiveWrapper,\n copyRegExp,\n copySelf,\n copySetLoose,\n copySetStrict,\n} from './copier.js';\nimport type { InternalCopier } from './copier.ts';\nimport type { Cache } from './utils.ts';\n\nexport interface CopierMethods {\n array?: InternalCopier<any[]>;\n arrayBuffer?: InternalCopier<ArrayBuffer>;\n asyncGenerator?: InternalCopier<AsyncGenerator>;\n blob?: InternalCopier<Blob>;\n dataView?: InternalCopier<DataView>;\n date?: InternalCopier<Date>;\n error?: InternalCopier<Error>;\n generator?: InternalCopier<Generator>;\n map?: InternalCopier<Map<any, any>>;\n object?: InternalCopier<Record<string, any>>;\n regExp?: InternalCopier<RegExp>;\n set?: InternalCopier<Set<any>>;\n}\n\ninterface Copiers {\n [key: string]: InternalCopier<any> | undefined;\n\n Arguments: InternalCopier<Record<string, any>>;\n Array: InternalCopier<any[]>;\n ArrayBuffer: InternalCopier<ArrayBuffer>;\n AsyncGenerator: InternalCopier<AsyncGenerator>;\n BigInt64Array: InternalCopier<ArrayBuffer>;\n BigUint64Array: InternalCopier<ArrayBuffer>;\n Blob: InternalCopier<Blob>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Boolean: InternalCopier<Boolean>;\n DataView: InternalCopier<DataView>;\n Date: InternalCopier<Date>;\n Error: InternalCopier<Error>;\n Float32Array: InternalCopier<ArrayBuffer>;\n Float64Array: InternalCopier<ArrayBuffer>;\n Generator: InternalCopier<Generator>;\n Int8Array: InternalCopier<ArrayBuffer>;\n Int16Array: InternalCopier<ArrayBuffer>;\n Int32Array: InternalCopier<ArrayBuffer>;\n Map: InternalCopier<Map<any, any>>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n Number: InternalCopier<Number>;\n Object: InternalCopier<Record<string, any>>;\n Promise: InternalCopier<Promise<any>>;\n RegExp: InternalCopier<RegExp>;\n Set: InternalCopier<Set<any>>;\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n String: InternalCopier<String>;\n WeakMap: InternalCopier<WeakMap<any, any>>;\n WeakSet: InternalCopier<WeakSet<any>>;\n Uint8Array: InternalCopier<ArrayBuffer>;\n Uint8ClampedArray: InternalCopier<ArrayBuffer>;\n Uint16Array: InternalCopier<ArrayBuffer>;\n Uint32Array: InternalCopier<ArrayBuffer>;\n}\n\nexport interface CreateCopierOptions {\n /**\n * Creates the cache used to track values already copied, which is what allows circular\n * references to resolve to their clone instead of recursing infinitely. A new cache is\n * created for each top-level copy. Since it only needs to satisfy the `has` / `get` /\n * `set` contract, a bounded implementation such as an LRU cache can be used to trade\n * circular reference handling for a smaller memory footprint.\n *\n * @default () => new WeakMap()\n */\n createCache?: () => Cache;\n /**\n * The maximum number of nested objects to traverse before throwing a\n * `MaxDepthExceededError`. Pass `Infinity` to traverse without a limit.\n *\n * @default 1000\n */\n maxDepth?: number;\n /**\n * Overrides of the copiers used for specific object types, allowing custom copy\n * semantics for those types. Any type not overridden uses its default copier. Each\n * method receives the value to copy and the current `State`, and is responsible for\n * populating `state.cache` and recursing via `state.copier` if it wants circular\n * reference handling and deep copies respectively.\n */\n methods?: CopierMethods;\n /**\n * Copies all own properties with their original property descriptors, including\n * non-enumerable properties, symbols, and non-index properties on arrays.\n *\n * @note\n * This is significantly slower than the default \"loose\" copy, so it should only be used\n * when the exact shape of the original must be replicated.\n *\n * @default false\n */\n strict?: boolean;\n}\n\nexport interface RequiredCreateCopierOptions extends Omit<Required<CreateCopierOptions>, 'methods'> {\n copiers: Copiers;\n methods: Required<CopierMethods>;\n}\n\n/**\n * The maximum depth traversed when none is provided.\n *\n * @note\n * This is deliberately below the depth at which the native call stack is exhausted\n * (~1875 for strict copies in node), so that untrusted, deeply-nested values fail with a\n * catchable, descriptive error instead of a raw `RangeError`.\n */\nexport const DEFAULT_MAX_DEPTH = 1000;\n\nexport function createDefaultCache(): Cache {\n return new WeakMap();\n}\n\nexport function getOptions({\n createCache: createCacheOverride,\n maxDepth,\n methods: methodsOverride,\n strict,\n}: CreateCopierOptions): RequiredCreateCopierOptions {\n const defaultMethods = {\n array: strict ? copyArrayStrict : copyArrayLoose,\n arrayBuffer: copyArrayBuffer,\n asyncGenerator: copySelf,\n blob: copyBlob,\n dataView: copyDataView,\n date: copyDate,\n error: copySelf,\n generator: copySelf,\n map: strict ? copyMapStrict : copyMapLoose,\n object: strict ? copyObjectStrict : copyObjectLoose,\n regExp: copyRegExp,\n set: strict ? copySetStrict : copySetLoose,\n };\n\n const methods = methodsOverride ? Object.assign(defaultMethods, methodsOverride) : defaultMethods;\n const copiers = getTagSpecificCopiers(methods);\n const createCache = createCacheOverride || createDefaultCache;\n\n // Extra safety check to ensure that object and array copiers are always provided,\n // avoiding runtime errors.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!copiers.Object || !copiers.Array) {\n throw new Error('An object and array copier must be provided.');\n }\n\n return {\n createCache,\n copiers,\n maxDepth: maxDepth == null ? DEFAULT_MAX_DEPTH : maxDepth,\n methods,\n strict: Boolean(strict),\n };\n}\n\n/**\n * Get the copiers used for each specific object tag.\n */\nexport function getTagSpecificCopiers(methods: Required<CopierMethods>): Copiers {\n return {\n Arguments: methods.object,\n Array: methods.array,\n ArrayBuffer: methods.arrayBuffer,\n AsyncGenerator: methods.asyncGenerator,\n BigInt64Array: methods.arrayBuffer,\n BigUint64Array: methods.arrayBuffer,\n Blob: methods.blob,\n Boolean: copyPrimitiveWrapper,\n DataView: methods.dataView,\n Date: methods.date,\n Error: methods.error,\n Float32Array: methods.arrayBuffer,\n Float64Array: methods.arrayBuffer,\n Generator: methods.generator,\n Int8Array: methods.arrayBuffer,\n Int16Array: methods.arrayBuffer,\n Int32Array: methods.arrayBuffer,\n Map: methods.map,\n Number: copyPrimitiveWrapper,\n Object: methods.object,\n Promise: copySelf,\n RegExp: methods.regExp,\n Set: methods.set,\n String: copyPrimitiveWrapper,\n WeakMap: copySelf,\n WeakSet: copySelf,\n Uint8Array: methods.arrayBuffer,\n Uint8ClampedArray: methods.arrayBuffer,\n Uint16Array: methods.arrayBuffer,\n Uint32Array: methods.arrayBuffer,\n };\n}\n","import type { State } from './copier.ts';\nimport { getOptions } from './options.js';\nimport type { CreateCopierOptions } from './options.ts';\nimport { getTag, MaxDepthExceededError } from './utils.js';\n\nexport type { State } from './copier.ts';\nexport type { CreateCopierOptions } from './options.ts';\nexport { MaxDepthExceededError } from './utils.js';\n\n/**\n * Create a custom copier based on custom options for any of the following:\n * - `createCache` method to create a cache for copied objects\n * - custom copier `methods` for specific object types\n * - `strict` mode to copy all properties with their descriptors\n */\nexport function createCopier(options: CreateCopierOptions = {}) {\n const { createCache, copiers, maxDepth } = getOptions(options);\n const { Array: copyArray, Object: copyObject } = copiers;\n\n function copier(value: any, state: State): any {\n state.prototype = state.Constructor = undefined;\n\n if (!value || typeof value !== 'object') {\n return value;\n }\n\n if (state.cache.has(value)) {\n return state.cache.get(value);\n }\n\n // Bound the traversal of nested objects, so that values nested more deeply than the\n // call stack can handle fail with a descriptive error instead of a raw `RangeError`.\n if (++state.depth > maxDepth) {\n throw new MaxDepthExceededError(maxDepth);\n }\n\n state.prototype = Object.getPrototypeOf(value);\n // Using logical AND for speed, since optional chaining transforms to\n // a local variable usage.\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n state.Constructor = state.prototype && state.prototype.constructor;\n\n let clone: any;\n\n // plain objects\n if (!state.Constructor || state.Constructor === Object) {\n clone = copyObject(value as Record<string, any>, state);\n } else if (Array.isArray(value)) {\n // arrays\n clone = copyArray(value, state);\n } else {\n const tagSpecificCopier = copiers[getTag(value)];\n\n if (tagSpecificCopier) {\n clone = tagSpecificCopier(value, state);\n } else {\n clone = typeof value.then === 'function' ? value : copyObject(value as Record<string, any>, state);\n }\n }\n\n --state.depth;\n\n return clone;\n }\n\n return function copy<Value>(value: Value): Value {\n return copier(value, {\n Constructor: undefined,\n cache: createCache(),\n copier,\n depth: 0,\n prototype: undefined,\n });\n };\n}\n\n/**\n * Copy an value deeply as much as possible, where strict recreation of object properties\n * are maintained. All properties (including non-enumerable ones) are copied with their\n * original property descriptors on both objects and arrays.\n */\nexport const copyStrict = createCopier({ strict: true });\n\n/**\n * Copy an value deeply as much as possible.\n */\nexport const copy = createCopier();\n"],"names":[],"mappings":";;AAMA;;;;;;AAMG;AACG,MAAO,qBAAsB,SAAQ,UAAU,CAAA;AAGnD,IAAA,WAAA,CAAY,QAAgB,EAAA;QAC1B,KAAK,CAAC,yBAAyB,MAAM,CAAC,Q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,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAEhD,IAAI,iBAAiB,EAAE;AACrB,gBAAA,KAAK,GAAG,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC;YACzC;iBAAO;gBACL,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,GAAG,KAAK,GAAG,UAAU,CAAC,KAA4B,EAAE,KAAK,CAAC;YACpG;QACF;QAEA,EAAE,KAAK,CAAC,KAAK;AAEb,QAAA,OAAO,KAAK;IACd;IAEA,OAAO,SAAS,IAAI,CAAQ,KAAY,EAAA;QACtC,OAAO,MAAM,CAAC,KAAK,EAAE;AACnB,YAAA,WAAW,EAAE,SAAS;YACtB,KAAK,EAAE,WAAW,EAAE;YACpB,MAAM;AACN,YAAA,KAAK,EAAE,CAAC;AACR,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;AACJ,IAAA,CAAC;AACH;AAEA;;;;AAIG;AACI,MAAM,UAAU,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE;AAEvD;;AAEG;AACI,MAAM,IAAI,GAAG,YAAY;;;;;;;"}
@@ -3,12 +3,59 @@ interface Cache {
3
3
  set: (key: any, value: any) => void;
4
4
  get: (key: any) => any;
5
5
  }
6
+ /**
7
+ * Error thrown when the copier traverses deeper than the configured `maxDepth`.
8
+ *
9
+ * @note
10
+ * Extends `RangeError` for backwards compatibility, since exceeding the maximum depth
11
+ * previously surfaced as a native `RangeError` from stack exhaustion.
12
+ */
13
+ declare class MaxDepthExceededError extends RangeError {
14
+ readonly maxDepth: number;
15
+ constructor(maxDepth: number);
16
+ }
6
17
 
7
18
  type InternalCopier<Value> = (value: Value, state: State) => Value;
8
19
  interface State {
20
+ /**
21
+ * The constructor of the value currently being copied, derived from its `prototype`.
22
+ * Used to construct the clone for values that are not plain objects, such as subclasses
23
+ * of `Array` or custom classes.
24
+ *
25
+ * @note
26
+ * This is `undefined` for primitives and for values already present in the `cache`. It is
27
+ * also reassigned for every value copied, so it must be read before any recursive
28
+ * `copier` call is made, not after.
29
+ */
9
30
  Constructor: any;
31
+ /**
32
+ * The cache of values already copied, mapping each original to its clone. Copiers should
33
+ * populate it with the clone _before_ copying that value's contents, so that circular
34
+ * references resolve to the clone rather than recursing infinitely.
35
+ */
10
36
  cache: Cache;
37
+ /**
38
+ * The copier used for nested values. Call it as `state.copier(value, state)` to deeply
39
+ * copy the contents of the value being copied.
40
+ */
11
41
  copier: InternalCopier<any>;
42
+ /**
43
+ * The number of nested objects currently being copied, used to bound traversal of
44
+ * deeply-nested values before the call stack is exhausted.
45
+ *
46
+ * @note
47
+ * This is maintained by the copier itself; custom methods should not modify it.
48
+ */
49
+ depth: number;
50
+ /**
51
+ * The prototype of the value currently being copied, used to create a clone that
52
+ * maintains the original's prototype chain.
53
+ *
54
+ * @note
55
+ * This is `undefined` for primitives and for values already present in the `cache`. It is
56
+ * also reassigned for every value copied, so it must be read before any recursive
57
+ * `copier` call is made, not after.
58
+ */
12
59
  prototype: any;
13
60
  }
14
61
 
@@ -27,8 +74,41 @@ interface CopierMethods {
27
74
  set?: InternalCopier<Set<any>>;
28
75
  }
29
76
  interface CreateCopierOptions {
77
+ /**
78
+ * Creates the cache used to track values already copied, which is what allows circular
79
+ * references to resolve to their clone instead of recursing infinitely. A new cache is
80
+ * created for each top-level copy. Since it only needs to satisfy the `has` / `get` /
81
+ * `set` contract, a bounded implementation such as an LRU cache can be used to trade
82
+ * circular reference handling for a smaller memory footprint.
83
+ *
84
+ * @default () => new WeakMap()
85
+ */
30
86
  createCache?: () => Cache;
87
+ /**
88
+ * The maximum number of nested objects to traverse before throwing a
89
+ * `MaxDepthExceededError`. Pass `Infinity` to traverse without a limit.
90
+ *
91
+ * @default 1000
92
+ */
93
+ maxDepth?: number;
94
+ /**
95
+ * Overrides of the copiers used for specific object types, allowing custom copy
96
+ * semantics for those types. Any type not overridden uses its default copier. Each
97
+ * method receives the value to copy and the current `State`, and is responsible for
98
+ * populating `state.cache` and recursing via `state.copier` if it wants circular
99
+ * reference handling and deep copies respectively.
100
+ */
31
101
  methods?: CopierMethods;
102
+ /**
103
+ * Copies all own properties with their original property descriptors, including
104
+ * non-enumerable properties, symbols, and non-index properties on arrays.
105
+ *
106
+ * @note
107
+ * This is significantly slower than the default "loose" copy, so it should only be used
108
+ * when the exact shape of the original must be replicated.
109
+ *
110
+ * @default false
111
+ */
32
112
  strict?: boolean;
33
113
  }
34
114
 
@@ -50,5 +130,5 @@ declare const copyStrict: <Value>(value: Value) => Value;
50
130
  */
51
131
  declare const copy: <Value>(value: Value) => Value;
52
132
 
53
- export { copy, copyStrict, createCopier };
133
+ export { MaxDepthExceededError, copy, copyStrict, createCopier };
54
134
  export type { CreateCopierOptions, State };