@zuplo/cli 7.15.26 → 7.15.30
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.
- package/dist/source/ai-gateway/catalog.json +170 -1
- package/dist/source/ai-gateway/planner.d.ts +2 -2
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwks/remote.js +2 -2
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/encrypt.js +5 -8
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +1 -1
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +2 -2
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +1 -1
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key.js +2 -0
- package/node_modules/@modelcontextprotocol/client/node_modules/jose/package.json +1 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +2 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/encrypt.js +5 -8
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +1 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +2 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +1 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +2 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +1 -1
- package/node_modules/@posthog/core/dist/gzip.d.ts +2 -0
- package/node_modules/@posthog/core/dist/gzip.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/gzip.js +17 -1
- package/node_modules/@posthog/core/dist/gzip.mjs +15 -2
- package/node_modules/@posthog/core/package.json +2 -2
- package/node_modules/@posthog/core/src/gzip.ts +21 -4
- package/node_modules/@posthog/types/dist/posthog-config.d.ts +82 -0
- package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
- package/node_modules/@posthog/types/package.json +1 -1
- package/node_modules/@posthog/types/src/posthog-config.ts +84 -0
- package/node_modules/@zuplo/core/customer.cli.minified.js +296 -296
- package/node_modules/@zuplo/core/index.minified.js +305 -305
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/{chunk-I65Y62VQ.js → chunk-3ITT2MYM.js} +10 -10
- package/node_modules/@zuplo/runtime/out/esm/chunk-3ITT2MYM.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/{chunk-5XXEIH5B.js → chunk-A7HRIAHJ.js} +2 -2
- package/node_modules/@zuplo/runtime/out/esm/{chunk-6KHAYHSW.js → chunk-C4ZTXG6P.js} +4 -4
- package/node_modules/@zuplo/runtime/out/esm/chunk-C4ZTXG6P.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/{chunk-APWLPHXH.js → chunk-JAY7SQGG.js} +2 -2
- package/node_modules/@zuplo/runtime/out/esm/{chunk-MWNVPFFM.js → chunk-YTDIY7PP.js} +2 -2
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp/messages/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +16 -0
- package/node_modules/@zuplo/runtime/out/types/internal/index.d.ts +16 -0
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/express-rate-limit/dist/index.cjs +6 -4
- package/node_modules/express-rate-limit/dist/index.mjs +6 -4
- package/node_modules/express-rate-limit/package.json +1 -1
- package/node_modules/fast-copy/README.md +15 -0
- package/node_modules/fast-copy/dist/cjs/index.cjs +33 -8
- package/node_modules/fast-copy/dist/cjs/index.cjs.map +1 -1
- package/node_modules/fast-copy/dist/es/index.mjs +33 -8
- package/node_modules/fast-copy/dist/es/index.mjs.map +1 -1
- package/node_modules/fast-copy/dist/umd/index.js +33 -8
- package/node_modules/fast-copy/dist/umd/index.js.map +1 -1
- package/node_modules/fast-copy/package.json +1 -1
- package/node_modules/object-inspect/CHANGELOG.md +31 -0
- package/node_modules/object-inspect/index.js +326 -24
- package/node_modules/object-inspect/package.json +22 -13
- package/node_modules/object-inspect/readme.markdown +4 -1
- package/node_modules/object-inspect/stringWidth.js +68 -0
- package/node_modules/object-inspect/stringWidthRanges.js +38 -0
- package/package.json +11 -11
- package/node_modules/@zuplo/runtime/out/esm/chunk-6KHAYHSW.js.map +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-I65Y62VQ.js.map +0 -1
- package/node_modules/object-inspect/.eslintrc +0 -53
- package/node_modules/object-inspect/.nycrc +0 -13
- package/node_modules/object-inspect/example/all.js +0 -23
- package/node_modules/object-inspect/example/circular.js +0 -6
- package/node_modules/object-inspect/example/fn.js +0 -5
- package/node_modules/object-inspect/example/inspect.js +0 -10
- package/node_modules/object-inspect/test/bigint.js +0 -58
- package/node_modules/object-inspect/test/browser/dom.js +0 -15
- package/node_modules/object-inspect/test/circular.js +0 -16
- package/node_modules/object-inspect/test/deep.js +0 -12
- package/node_modules/object-inspect/test/element.js +0 -53
- package/node_modules/object-inspect/test/err.js +0 -48
- package/node_modules/object-inspect/test/fakes.js +0 -29
- package/node_modules/object-inspect/test/fn.js +0 -76
- package/node_modules/object-inspect/test/global.js +0 -17
- package/node_modules/object-inspect/test/has.js +0 -15
- package/node_modules/object-inspect/test/holes.js +0 -15
- package/node_modules/object-inspect/test/indent-option.js +0 -271
- package/node_modules/object-inspect/test/inspect.js +0 -139
- package/node_modules/object-inspect/test/lowbyte.js +0 -12
- package/node_modules/object-inspect/test/number.js +0 -58
- package/node_modules/object-inspect/test/quoteStyle.js +0 -26
- package/node_modules/object-inspect/test/toStringTag.js +0 -40
- package/node_modules/object-inspect/test/undef.js +0 -12
- package/node_modules/object-inspect/test/values.js +0 -261
- package/node_modules/object-inspect/test-core-js.js +0 -26
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-I65Y62VQ.js.LEGAL.txt → chunk-3ITT2MYM.js.LEGAL.txt} +0 -0
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-5XXEIH5B.js.map → chunk-A7HRIAHJ.js.map} +0 -0
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-6KHAYHSW.js.LEGAL.txt → chunk-C4ZTXG6P.js.LEGAL.txt} +0 -0
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-APWLPHXH.js.map → chunk-JAY7SQGG.js.map} +0 -0
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-MWNVPFFM.js.map → chunk-YTDIY7PP.js.map} +0 -0
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* See https://zuplo.com/legal/eula for more information.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import{P as p,V as c,Z as u}from"../chunk-
|
|
12
|
+
import{P as p,V as c,Z as u}from"../chunk-C4ZTXG6P.js";import"../chunk-KZBZ5KM5.js";import{a as d}from"../chunk-JAY7SQGG.js";import"../chunk-R6UNMRUU.js";import"../chunk-A7HRIAHJ.js";import"../chunk-5JGLAPFA.js";import{Y as i}from"../chunk-3ITT2MYM.js";import{a as o}from"../chunk-VXPFMOL5.js";function w(l={request:new Request("https://api.example.com")}){let e=[];function t(s){e.push(Promise.resolve(s))}return o(t,"waitUntil"),{context:new a({event:{waitUntil:t},route:l.route,originalRequest:l.request}),invokeResponse:o(async()=>{await Promise.all(e)},"invokeResponse")}}o(w,"createMockContext");var g={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:o(()=>({}),"raw")},a=class extends EventTarget{static{o(this,"MockZuploContext")}#e;#t;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:t=g,parentContext:n,originalRequest:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:i.console.info,log:i.console.log,debug:i.console.debug,warn:i.console.warn,error:i.console.error,setLogProperties:o(()=>{},"setLogProperties")},this.custom={},this.route=t,this.incomingRequestProperties={ip:"203.0.113.7",asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0,clientCert:void 0,clientMtlsVerificationStatus:void 0,clientMtlsVerificationReason:void 0,clientCertFingerprintSha256:void 0,clientCertNotBefore:void 0,clientCertNotAfter:void 0,clientCertIssuerDn:void 0,clientCertSubjectDn:void 0},this.parentContext=n,this.#e=e,this.#t=r,this.analyticsContext=new c(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,t){throw new Error("Not implemented")}invokeOutboundPolicy(e,t,n){throw new Error("Not implemented")}invokeRoute(e,t){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addPreRequestHandler(e,t){let n;try{n=u.getContextExtensions(this)}catch{n=u.initialize(this,new d(this.#t??new Request("https://api.example.com")))}n.preRequestPhase??="active",p(this,n,e,t)}get preRequestHandlers(){let e;try{e=u.getContextExtensions(this)}catch{return[]}return(e.preRequestState?.entries??[]).map(t=>({policyName:t.policyName,name:t.name}))}addEventListener(e,t,n){let r=o(s=>{try{typeof t=="function"?t(s):t.handleEvent(s)}catch(m){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),m}},"wrapped");super.addEventListener(e,r,n)}};export{a as MockZuploContext,w as createMockContext};
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* See https://zuplo.com/legal/eula for more information.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import{H as a,I as l,J as c,K as o,N as p,O as y,P as m}from"../../chunk-
|
|
12
|
+
import{H as a,I as l,J as c,K as o,N as p,O as y,P as m}from"../../chunk-A7HRIAHJ.js";import"../../chunk-5JGLAPFA.js";import"../../chunk-3ITT2MYM.js";import{a as i}from"../../chunk-VXPFMOL5.js";async function g(r,e){let t=typeof e.credentials=="function"?await e.credentials():e.credentials,n=r.method,d=n!=="GET"&&n!=="HEAD"&&r.body!=null?await r.arrayBuffer():null,s=await new o({method:n,url:r.url,headers:r.headers,body:d,accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,sessionToken:t.sessionToken,service:e.service,region:e.region,signQuery:e.signQuery}).sign();return new Request(s.url.toString(),{method:s.method,headers:s.headers,body:s.body})}i(g,"signRequest");export{c as AwsClient,o as AwsV4Signer,p as fromTemporaryCredentials,y as fromWebToken,m as fromZuploIdentity,l as getAwsCredentialProvider,a as setAwsCredentialProvider,g as signRequest};
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -4702,6 +4702,22 @@ declare interface CompatibilityFlags {
|
|
|
4702
4702
|
* @compatibilityDate 2026-11-06
|
|
4703
4703
|
*/
|
|
4704
4704
|
mcpGraphQLToolsV2: boolean;
|
|
4705
|
+
/**
|
|
4706
|
+
* Whether final hooks (`context.addResponseSendingFinalHook` and
|
|
4707
|
+
* `runtime.addResponseSendingFinalHook`) receive the response sent to the
|
|
4708
|
+
* client.
|
|
4709
|
+
*
|
|
4710
|
+
* Before this flag: final hooks receive the response from before the
|
|
4711
|
+
* `responseSending` listeners and the response-sending hooks ran. When a
|
|
4712
|
+
* response-sending hook returns a new `Response`, final hooks see a status,
|
|
4713
|
+
* headers and body that the client never received.
|
|
4714
|
+
*
|
|
4715
|
+
* After this flag: final hooks receive the response the response-sending
|
|
4716
|
+
* hooks returned, which is the response sent to the client.
|
|
4717
|
+
*
|
|
4718
|
+
* See `packages/runtime/specs/compat-pass-sent-response-to-final-hooks.md`.
|
|
4719
|
+
*/
|
|
4720
|
+
passSentResponseToFinalHooks: boolean;
|
|
4705
4721
|
}
|
|
4706
4722
|
|
|
4707
4723
|
declare interface CompletionsFallbacks {
|
|
@@ -575,6 +575,22 @@ declare interface CompatibilityFlags {
|
|
|
575
575
|
* @compatibilityDate 2026-11-06
|
|
576
576
|
*/
|
|
577
577
|
mcpGraphQLToolsV2: boolean;
|
|
578
|
+
/**
|
|
579
|
+
* Whether final hooks (`context.addResponseSendingFinalHook` and
|
|
580
|
+
* `runtime.addResponseSendingFinalHook`) receive the response sent to the
|
|
581
|
+
* client.
|
|
582
|
+
*
|
|
583
|
+
* Before this flag: final hooks receive the response from before the
|
|
584
|
+
* `responseSending` listeners and the response-sending hooks ran. When a
|
|
585
|
+
* response-sending hook returns a new `Response`, final hooks see a status,
|
|
586
|
+
* headers and body that the client never received.
|
|
587
|
+
*
|
|
588
|
+
* After this flag: final hooks receive the response the response-sending
|
|
589
|
+
* hooks returned, which is the response sent to the client.
|
|
590
|
+
*
|
|
591
|
+
* See `packages/runtime/specs/compat-pass-sent-response-to-final-hooks.md`.
|
|
592
|
+
*/
|
|
593
|
+
passSentResponseToFinalHooks: boolean;
|
|
578
594
|
}
|
|
579
595
|
|
|
580
596
|
/**
|
|
@@ -307,7 +307,7 @@ var setRetryAfterHeader = (response, info, windowMs, retryAfter) => {
|
|
|
307
307
|
|
|
308
308
|
// source/utils.ts
|
|
309
309
|
var omitUndefinedProperties = (passedOptions) => {
|
|
310
|
-
const omittedOptions =
|
|
310
|
+
const omittedOptions = /* @__PURE__ */ Object.create(null);
|
|
311
311
|
for (const k of Object.keys(passedOptions)) {
|
|
312
312
|
const key = k;
|
|
313
313
|
if (passedOptions[key] !== void 0) {
|
|
@@ -787,7 +787,7 @@ var getOptionsFromConfig = (config) => {
|
|
|
787
787
|
};
|
|
788
788
|
var parseOptions = (passedOptions) => {
|
|
789
789
|
const notUndefinedOptions = omitUndefinedProperties(passedOptions);
|
|
790
|
-
const logger =
|
|
790
|
+
const logger = notUndefinedOptions.logger ?? ConsoleLogger;
|
|
791
791
|
const validations2 = getValidations(
|
|
792
792
|
notUndefinedOptions?.validate ?? true,
|
|
793
793
|
logger
|
|
@@ -808,11 +808,11 @@ var parseOptions = (passedOptions) => {
|
|
|
808
808
|
if (standardHeaders === true) standardHeaders = "draft-6";
|
|
809
809
|
const config = {
|
|
810
810
|
windowMs: 60 * 1e3,
|
|
811
|
-
limit:
|
|
811
|
+
limit: notUndefinedOptions.max ?? 5,
|
|
812
812
|
// `max` is deprecated, but support it anyways.
|
|
813
813
|
message: "Too many requests, please try again later.",
|
|
814
814
|
statusCode: 429,
|
|
815
|
-
legacyHeaders:
|
|
815
|
+
legacyHeaders: notUndefinedOptions.headers ?? true,
|
|
816
816
|
identifier(request, _response) {
|
|
817
817
|
let duration = "";
|
|
818
818
|
const property = config.requestPropertyName;
|
|
@@ -856,6 +856,8 @@ var parseOptions = (passedOptions) => {
|
|
|
856
856
|
if (!response.writableEnded) response.send(message);
|
|
857
857
|
},
|
|
858
858
|
passOnStoreError: false,
|
|
859
|
+
// Options without a default would otherwise fall through to Object.prototype.
|
|
860
|
+
retryAfter: void 0,
|
|
859
861
|
// Allow the default options to be overridden by the passed options.
|
|
860
862
|
...notUndefinedOptions,
|
|
861
863
|
// `standardHeaders` is resolved into a draft version above, use that.
|
|
@@ -264,7 +264,7 @@ var setRetryAfterHeader = (response, info, windowMs, retryAfter) => {
|
|
|
264
264
|
|
|
265
265
|
// source/utils.ts
|
|
266
266
|
var omitUndefinedProperties = (passedOptions) => {
|
|
267
|
-
const omittedOptions =
|
|
267
|
+
const omittedOptions = /* @__PURE__ */ Object.create(null);
|
|
268
268
|
for (const k of Object.keys(passedOptions)) {
|
|
269
269
|
const key = k;
|
|
270
270
|
if (passedOptions[key] !== void 0) {
|
|
@@ -744,7 +744,7 @@ var getOptionsFromConfig = (config) => {
|
|
|
744
744
|
};
|
|
745
745
|
var parseOptions = (passedOptions) => {
|
|
746
746
|
const notUndefinedOptions = omitUndefinedProperties(passedOptions);
|
|
747
|
-
const logger =
|
|
747
|
+
const logger = notUndefinedOptions.logger ?? ConsoleLogger;
|
|
748
748
|
const validations2 = getValidations(
|
|
749
749
|
notUndefinedOptions?.validate ?? true,
|
|
750
750
|
logger
|
|
@@ -765,11 +765,11 @@ var parseOptions = (passedOptions) => {
|
|
|
765
765
|
if (standardHeaders === true) standardHeaders = "draft-6";
|
|
766
766
|
const config = {
|
|
767
767
|
windowMs: 60 * 1e3,
|
|
768
|
-
limit:
|
|
768
|
+
limit: notUndefinedOptions.max ?? 5,
|
|
769
769
|
// `max` is deprecated, but support it anyways.
|
|
770
770
|
message: "Too many requests, please try again later.",
|
|
771
771
|
statusCode: 429,
|
|
772
|
-
legacyHeaders:
|
|
772
|
+
legacyHeaders: notUndefinedOptions.headers ?? true,
|
|
773
773
|
identifier(request, _response) {
|
|
774
774
|
let duration = "";
|
|
775
775
|
const property = config.requestPropertyName;
|
|
@@ -813,6 +813,8 @@ var parseOptions = (passedOptions) => {
|
|
|
813
813
|
if (!response.writableEnded) response.send(message);
|
|
814
814
|
},
|
|
815
815
|
passOnStoreError: false,
|
|
816
|
+
// Options without a default would otherwise fall through to Object.prototype.
|
|
817
|
+
retryAfter: void 0,
|
|
816
818
|
// Allow the default options to be overridden by the passed options.
|
|
817
819
|
...notUndefinedOptions,
|
|
818
820
|
// `standardHeaders` is resolved into a draft version above, use that.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-rate-limit",
|
|
3
|
-
"version": "8.7.
|
|
3
|
+
"version": "8.7.5",
|
|
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",
|
|
@@ -28,6 +28,7 @@ A [blazing fast](#benchmarks) deep object copier
|
|
|
28
28
|
- [Error references are copied directly, instead of creating a new `*Error` object](#error-references-are-copied-directly-instead-of-creating-a-new-error-object)
|
|
29
29
|
- [The constructor of the original object is used, instead of using known globals](#the-constructor-of-the-original-object-is-used-instead-of-using-known-globals)
|
|
30
30
|
- [Sparse arrays are copied densely, unless using `copyStrict`](#sparse-arrays-are-copied-densely-unless-using-copystrict)
|
|
31
|
+
- [Properties are copied as a snapshot of their values, unless using `copyStrict`](#properties-are-copied-as-a-snapshot-of-their-values-unless-using-copystrict)
|
|
31
32
|
- [References are shared when circular references are possible](#references-are-shared-when-circular-references-are-possible)
|
|
32
33
|
- [Typed arrays copy only the memory they view](#typed-arrays-copy-only-the-memory-they-view)
|
|
33
34
|
- [Benchmarks](#benchmarks)
|
|
@@ -370,6 +371,20 @@ the contract differs.
|
|
|
370
371
|
For performance, [`copy`](#copy) copies every index up to `length`, so holes in sparse arrays become explicit
|
|
371
372
|
`undefined` values (e.g., `copy([, 1])` has the key `0`). [`copyStrict`](#copystrict) preserves holes.
|
|
372
373
|
|
|
374
|
+
### Properties are copied as a snapshot of their values, unless using `copyStrict`
|
|
375
|
+
|
|
376
|
+
[`copy`](#copy) reads each enumerable own property once and stores the copied value on the clone as a standard property
|
|
377
|
+
(configurable, enumerable, and writable), regardless of how it was defined on the original. The result is a static
|
|
378
|
+
snapshot of the original at the time of copying:
|
|
379
|
+
|
|
380
|
+
- Getters are called, and the value they return is copied in place of the getter
|
|
381
|
+
- Setters are dropped, so writing to the copy only changes its stored value
|
|
382
|
+
- Read-only and non-configurable properties become writable and configurable
|
|
383
|
+
|
|
384
|
+
Because values are assigned to the clone, a setter inherited from the clone's prototype for the same key receives the
|
|
385
|
+
copied value instead of an own property being created. [`copyStrict`](#copystrict) preserves the original property
|
|
386
|
+
descriptors, including getters and setters, if you need them retained.
|
|
387
|
+
|
|
373
388
|
### References are shared when circular references are possible
|
|
374
389
|
|
|
375
390
|
Values with nested contents (objects, arrays, `Map`s, and `Set`s) can contain circular references, so they are tracked
|
|
@@ -87,6 +87,17 @@ function copyOwnDescriptor(original, clone, property, state) {
|
|
|
87
87
|
clone[property] = descriptor.get ? descriptor.get() : descriptor.value;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Define the value as a standard (configurable, enumerable, writable) own property of the clone.
|
|
92
|
+
*/
|
|
93
|
+
function defineOwnValue(clone, property, value) {
|
|
94
|
+
Object.defineProperty(clone, property, {
|
|
95
|
+
configurable: true,
|
|
96
|
+
enumerable: true,
|
|
97
|
+
value,
|
|
98
|
+
writable: true,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
90
101
|
/**
|
|
91
102
|
* Strictly copy all properties contained on the object, starting with the name at the `start` index.
|
|
92
103
|
*
|
|
@@ -233,31 +244,45 @@ function copyMapStrict(map, state) {
|
|
|
233
244
|
}
|
|
234
245
|
/**
|
|
235
246
|
* Deeply copy the properties (keys and symbols) and values of the original.
|
|
247
|
+
*
|
|
248
|
+
* @note
|
|
249
|
+
* Values are assigned for performance, but assignment respects the prototype chain, so it throws
|
|
250
|
+
* when the key shadows an inherited read-only or getter-only property. In that case the value is
|
|
251
|
+
* defined directly, still producing the standard own property expected in loose mode. This relies
|
|
252
|
+
* on the source running in strict mode, where a failed assignment throws instead of being silently
|
|
253
|
+
* ignored.
|
|
236
254
|
*/
|
|
237
255
|
function copyObject(object, state) {
|
|
238
256
|
const clone = getCleanClone(state.prototype);
|
|
239
257
|
// set in the cache immediately to be able to reuse the object recursively
|
|
240
258
|
state.cache.set(object, clone);
|
|
241
259
|
for (const key of Object.keys(object)) {
|
|
260
|
+
const value = state.copier(object[key], state);
|
|
242
261
|
if (key === '__proto__') {
|
|
243
262
|
// Native assignment would attempt to use `Object.setPropertyOf` under the hood, when this
|
|
244
263
|
// property has been explicitly set as a standard property. Using `defineProperty` ensures
|
|
245
264
|
// its treatment in the clone is unchanged from the source.
|
|
246
|
-
|
|
247
|
-
configurable: true,
|
|
248
|
-
enumerable: true,
|
|
249
|
-
value: state.copier(object[key], state),
|
|
250
|
-
writable: true,
|
|
251
|
-
});
|
|
265
|
+
defineOwnValue(clone, key, value);
|
|
252
266
|
}
|
|
253
267
|
else {
|
|
254
|
-
|
|
268
|
+
try {
|
|
269
|
+
clone[key] = value;
|
|
270
|
+
}
|
|
271
|
+
catch (_a) {
|
|
272
|
+
defineOwnValue(clone, key, value);
|
|
273
|
+
}
|
|
255
274
|
}
|
|
256
275
|
}
|
|
257
276
|
for (const symbol of Object.getOwnPropertySymbols(object)) {
|
|
258
277
|
// Only copy enumerable symbols in loose mode, to align with handling of `keys`.
|
|
259
278
|
if (Object.prototype.propertyIsEnumerable.call(object, symbol)) {
|
|
260
|
-
|
|
279
|
+
const value = state.copier(object[symbol], state);
|
|
280
|
+
try {
|
|
281
|
+
clone[symbol] = value;
|
|
282
|
+
}
|
|
283
|
+
catch (_b) {
|
|
284
|
+
defineOwnValue(clone, symbol, value);
|
|
285
|
+
}
|
|
261
286
|
}
|
|
262
287
|
}
|
|
263
288
|
return clone;
|
|
@@ -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/**\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 // 2026-10-10: Prototype constructor properties may contain ordinary data.\n if (typeof Constructor === 'function' && ~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, getTag } 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/**\n * The shared `%TypedArray%.prototype.slice`, which every typed array inherits.\n *\n * @note\n * This is used instead of the `slice` found on the value itself because subclasses can\n * override it with one that does not copy. `Buffer` is the notable case: its `slice`\n * returns a view over the same memory, so copying through it would alias the original.\n */\nconst sliceTypedArray = Object.getPrototypeOf(Int8Array.prototype).slice as (\n this: ArrayBufferView,\n start: number,\n) => ArrayBufferView;\n\n/**\n * Copy the descriptor from the original value to the clone.\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, starting with the name at the `start` index.\n *\n * @note\n * `Object.getOwnPropertyNames` lists integer keys first in ascending order, so array-like values\n * whose indices are already copied can pass their count as `start` to skip them.\n */\nfunction copyOwnPropertiesStrict<Value extends object>(\n value: Value,\n clone: Value,\n state: State,\n names: string[],\n start: number,\n): Value {\n for (let index = start; index < names.length; ++index) {\n copyOwnDescriptor(value, clone, names[index]!, 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 copyArray<Value extends any[]>(array: Value, state: State): Value {\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): 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(array, clone);\n\n // Indices are copied by descriptor rather than by assignment, unlike typed arrays and strings,\n // because array indices can be holes, accessors, or non-writable / non-enumerable values.\n return copyOwnPropertiesStrict(array, clone, state, Object.getOwnPropertyNames(array), 0);\n}\n\n/**\n * Copy the contents of the ArrayBuffer, or of the typed array viewing one.\n *\n * @note\n * `slice` always returns a fixed-length buffer, so a resizable or growable buffer that can change\n * size is instead constructed with the same `maxByteLength` and has its contents copied in.\n */\nexport function copyArrayBuffer<Value extends ArrayBufferLike | ArrayBufferView>(\n arrayBuffer: Value,\n state: State,\n): Value {\n if (ArrayBuffer.isView(arrayBuffer)) {\n return sliceTypedArray.call(arrayBuffer, 0) as Value;\n }\n\n if ((arrayBuffer as ArrayBuffer).resizable || (arrayBuffer as SharedArrayBuffer).growable) {\n const maxByteLength = (arrayBuffer as ArrayBuffer).maxByteLength;\n const clone = new state.Constructor(arrayBuffer.byteLength, { maxByteLength });\n\n // The new buffer is zero-filled, and buffers can only be read or written through a view, so\n // copy the original's bytes into it through byte-level views of both. Without this, the clone\n // would have the right size but be all zeros.\n new Uint8Array(clone).set(new Uint8Array(arrayBuffer));\n\n return clone as Value;\n }\n\n // V8 throws when slicing an empty, fixed-length SharedArrayBuffer.\n if (!arrayBuffer.byteLength && getTag(arrayBuffer) === 'SharedArrayBuffer') {\n return new state.Constructor(0) as Value;\n }\n\n return arrayBuffer.slice(0) as Value;\n}\n\n/**\n * Copy the contents of the ArrayBuffer, or of the typed array viewing one, as well as\n * any custom properties.\n */\nexport function copyArrayBufferStrict<Value extends ArrayBufferLike | ArrayBufferView>(\n arrayBuffer: Value,\n state: State,\n): Value {\n const clone = copyArrayBuffer(arrayBuffer, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(arrayBuffer, clone);\n\n // Typed arrays list their indices first, but unlike arrays have no own `length` to skip. The\n // fresh clone is read, since the original may have an own `length` that shadows the real one.\n const start = ArrayBuffer.isView(clone) ? (clone as unknown as ArrayLike<unknown>).length || 0 : 0;\n\n return copyOwnPropertiesStrict(arrayBuffer, clone, state, Object.getOwnPropertyNames(arrayBuffer), start);\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 Blob with the contents of the original, and copy any custom properties.\n */\nexport const copyBlobStrict = createStrictHandler(copyBlob);\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(state.copier(dataView.buffer, state), dataView.byteOffset, dataView.byteLength);\n}\n\n/**\n * Create a new DataView with the contents of the original, and copy any custom properties.\n *\n * @note\n * The buffer is shared with any other reference to it in the value being copied, and has\n * its own custom properties copied, the same as if it were reached directly.\n */\nexport function copyDataViewStrict<Value extends DataView>(dataView: Value, state: State): Value {\n const { buffer } = dataView;\n const { cache, Constructor } = state;\n const bufferCopied = cache.has(buffer);\n const bufferClone = bufferCopied ? cache.get(buffer) : state.copier(buffer, state);\n\n // The buffer's custom properties may reference this DataView, in which case copying the buffer\n // already created and cached its clone. Reuse it so that every reference resolves to one clone.\n if (!bufferCopied && cache.has(dataView)) {\n return cache.get(dataView);\n }\n\n const clone = new Constructor(bufferClone, dataView.byteOffset, dataView.byteLength) as Value;\n\n // set in the cache immediately to be able to reuse the object recursively.\n state.cache.set(dataView, clone);\n\n return copyOwnPropertiesStrict(dataView, clone, state, Object.getOwnPropertyNames(dataView), 0);\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 * Create a new Date based on the time of the original, and copy any custom properties.\n */\nexport const copyDateStrict = createStrictHandler(copyDate);\n\n/**\n * Deeply copy the keys and values of the original.\n */\nexport function copyMap<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): Value {\n return copyOwnPropertiesStrict(map, copyMap(map, state), state, Object.getOwnPropertyNames(map), 0);\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original.\n */\nexport function copyObject<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 if (key === '__proto__') {\n // Native assignment would attempt to use `Object.setPropertyOf` under the hood, when this\n // property has been explicitly set as a standard property. Using `defineProperty` ensures\n // its treatment in the clone is unchanged from the source.\n Object.defineProperty(clone, key, {\n configurable: true,\n enumerable: true,\n value: state.copier(object[key], state),\n writable: true,\n });\n } else {\n clone[key] = state.copier(object[key], state);\n }\n }\n\n for (const symbol of Object.getOwnPropertySymbols(object)) {\n // Only copy enumerable symbols in loose mode, to align with handling of `keys`.\n if (Object.prototype.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, Object.getOwnPropertyNames(object), 0);\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 primitive wrapper from the value of the original, and copy any\n * custom properties.\n */\nexport const copyPrimitiveWrapperStrict = createStrictHandler(copyPrimitiveWrapper);\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 // `lastIndex` is not retained when constructing anew, so manually copy it.\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n}\n\n/**\n * Copy the original RegExp, as well as any custom properties.\n */\nexport const copyRegExpStrict = createStrictHandler(copyRegExp);\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 copySet<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, copySet(set, state), state, Object.getOwnPropertyNames(set), 0);\n}\n\n/**\n * Copy the original value based on the handler passed, and also copy custom properties.\n *\n * @note\n * The handlers used here have no nested values to copy, so they skip the cache to keep loose\n * copies fast. Custom properties can reference the value itself, so the clone is cached here\n * before they are copied.\n */\nfunction createStrictHandler<Value extends object>(handler: (value: Value, state: State) => Value) {\n return (value: Value, state: State): Value => {\n const clone = handler(value, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(value, clone);\n\n return copyOwnPropertiesStrict(value, clone, state, Object.getOwnPropertyNames(value), 0);\n };\n}\n\n/**\n * Create a new String wrapper from the value of the original, and copy custom properties.\n */\n// `String` primitive constructor is intentional.\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nexport function copyStringStrict<Value extends String>(string: Value, state: State): Value {\n const clone = copyPrimitiveWrapper(string, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(string, clone);\n\n const { length } = string;\n const names = Object.getOwnPropertyNames(string);\n // Custom integer keys beyond the string's length are listed before `length`, so only skip\n // `length` when it directly follows the characters.\n const start = names[length] === 'length' ? length + 1 : length;\n\n return copyOwnPropertiesStrict(string, clone, state, names, start);\n}\n","import {\n copyArrayBuffer,\n copyArrayBufferStrict,\n copyArray,\n copyArrayStrict,\n copyBlob,\n copyBlobStrict,\n copyDataView,\n copyDataViewStrict,\n copyDate,\n copyDateStrict,\n copyMap,\n copyMapStrict,\n copyObject,\n copyObjectStrict,\n copyPrimitiveWrapper,\n copyPrimitiveWrapperStrict,\n copyRegExp,\n copyRegExpStrict,\n copySelf,\n copySet,\n copySetStrict,\n copyStringStrict,\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 SharedArrayBuffer: InternalCopier<SharedArrayBuffer>;\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 : copyArray,\n arrayBuffer: strict ? copyArrayBufferStrict : copyArrayBuffer,\n asyncGenerator: copySelf,\n blob: strict ? copyBlobStrict : copyBlob,\n dataView: strict ? copyDataViewStrict : copyDataView,\n date: strict ? copyDateStrict : copyDate,\n error: copySelf,\n generator: copySelf,\n map: strict ? copyMapStrict : copyMap,\n object: strict ? copyObjectStrict : copyObject,\n regExp: strict ? copyRegExpStrict : copyRegExp,\n set: strict ? copySetStrict : copySet,\n };\n\n const methods = methodsOverride ? Object.assign(defaultMethods, methodsOverride) : defaultMethods;\n const copiers = getTagSpecificCopiers(methods, strict);\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>, strict: boolean | undefined): Copiers {\n const copyPrimitive = strict ? copyPrimitiveWrapperStrict : copyPrimitiveWrapper;\n\n // A `null` prototype is used so that a value carrying a custom `Symbol.toStringTag`\n // cannot resolve to an inherited `Object.prototype` member as its copier. Without it,\n // a tag such as `toString` or `valueOf` finds a function on the prototype chain and\n // that function is invoked in place of a real copier.\n return Object.assign(Object.create(null) as Copiers, {\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: copyPrimitive,\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: copyPrimitive,\n Object: methods.object,\n Promise: copySelf,\n RegExp: methods.regExp,\n Set: methods.set,\n SharedArrayBuffer: methods.arrayBuffer,\n String: strict ? copyStringStrict : 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,C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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 // 2026-10-10: Prototype constructor properties may contain ordinary data.\n if (typeof Constructor === 'function' && ~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, getTag } 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/**\n * The shared `%TypedArray%.prototype.slice`, which every typed array inherits.\n *\n * @note\n * This is used instead of the `slice` found on the value itself because subclasses can\n * override it with one that does not copy. `Buffer` is the notable case: its `slice`\n * returns a view over the same memory, so copying through it would alias the original.\n */\nconst sliceTypedArray = Object.getPrototypeOf(Int8Array.prototype).slice as (\n this: ArrayBufferView,\n start: number,\n) => ArrayBufferView;\n\n/**\n * Copy the descriptor from the original value to the clone.\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 * Define the value as a standard (configurable, enumerable, writable) own property of the clone.\n */\nfunction defineOwnValue(clone: object, property: string | symbol, value: unknown): void {\n Object.defineProperty(clone, property, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n}\n\n/**\n * Strictly copy all properties contained on the object, starting with the name at the `start` index.\n *\n * @note\n * `Object.getOwnPropertyNames` lists integer keys first in ascending order, so array-like values\n * whose indices are already copied can pass their count as `start` to skip them.\n */\nfunction copyOwnPropertiesStrict<Value extends object>(\n value: Value,\n clone: Value,\n state: State,\n names: string[],\n start: number,\n): Value {\n for (let index = start; index < names.length; ++index) {\n copyOwnDescriptor(value, clone, names[index]!, 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 copyArray<Value extends any[]>(array: Value, state: State): Value {\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): 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(array, clone);\n\n // Indices are copied by descriptor rather than by assignment, unlike typed arrays and strings,\n // because array indices can be holes, accessors, or non-writable / non-enumerable values.\n return copyOwnPropertiesStrict(array, clone, state, Object.getOwnPropertyNames(array), 0);\n}\n\n/**\n * Copy the contents of the ArrayBuffer, or of the typed array viewing one.\n *\n * @note\n * `slice` always returns a fixed-length buffer, so a resizable or growable buffer that can change\n * size is instead constructed with the same `maxByteLength` and has its contents copied in.\n */\nexport function copyArrayBuffer<Value extends ArrayBufferLike | ArrayBufferView>(\n arrayBuffer: Value,\n state: State,\n): Value {\n if (ArrayBuffer.isView(arrayBuffer)) {\n return sliceTypedArray.call(arrayBuffer, 0) as Value;\n }\n\n if ((arrayBuffer as ArrayBuffer).resizable || (arrayBuffer as SharedArrayBuffer).growable) {\n const maxByteLength = (arrayBuffer as ArrayBuffer).maxByteLength;\n const clone = new state.Constructor(arrayBuffer.byteLength, { maxByteLength });\n\n // The new buffer is zero-filled, and buffers can only be read or written through a view, so\n // copy the original's bytes into it through byte-level views of both. Without this, the clone\n // would have the right size but be all zeros.\n new Uint8Array(clone).set(new Uint8Array(arrayBuffer));\n\n return clone as Value;\n }\n\n // V8 throws when slicing an empty, fixed-length SharedArrayBuffer.\n if (!arrayBuffer.byteLength && getTag(arrayBuffer) === 'SharedArrayBuffer') {\n return new state.Constructor(0) as Value;\n }\n\n return arrayBuffer.slice(0) as Value;\n}\n\n/**\n * Copy the contents of the ArrayBuffer, or of the typed array viewing one, as well as\n * any custom properties.\n */\nexport function copyArrayBufferStrict<Value extends ArrayBufferLike | ArrayBufferView>(\n arrayBuffer: Value,\n state: State,\n): Value {\n const clone = copyArrayBuffer(arrayBuffer, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(arrayBuffer, clone);\n\n // Typed arrays list their indices first, but unlike arrays have no own `length` to skip. The\n // fresh clone is read, since the original may have an own `length` that shadows the real one.\n const start = ArrayBuffer.isView(clone) ? (clone as unknown as ArrayLike<unknown>).length || 0 : 0;\n\n return copyOwnPropertiesStrict(arrayBuffer, clone, state, Object.getOwnPropertyNames(arrayBuffer), start);\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 Blob with the contents of the original, and copy any custom properties.\n */\nexport const copyBlobStrict = createStrictHandler(copyBlob);\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(state.copier(dataView.buffer, state), dataView.byteOffset, dataView.byteLength);\n}\n\n/**\n * Create a new DataView with the contents of the original, and copy any custom properties.\n *\n * @note\n * The buffer is shared with any other reference to it in the value being copied, and has\n * its own custom properties copied, the same as if it were reached directly.\n */\nexport function copyDataViewStrict<Value extends DataView>(dataView: Value, state: State): Value {\n const { buffer } = dataView;\n const { cache, Constructor } = state;\n const bufferCopied = cache.has(buffer);\n const bufferClone = bufferCopied ? cache.get(buffer) : state.copier(buffer, state);\n\n // The buffer's custom properties may reference this DataView, in which case copying the buffer\n // already created and cached its clone. Reuse it so that every reference resolves to one clone.\n if (!bufferCopied && cache.has(dataView)) {\n return cache.get(dataView);\n }\n\n const clone = new Constructor(bufferClone, dataView.byteOffset, dataView.byteLength) as Value;\n\n // set in the cache immediately to be able to reuse the object recursively.\n state.cache.set(dataView, clone);\n\n return copyOwnPropertiesStrict(dataView, clone, state, Object.getOwnPropertyNames(dataView), 0);\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 * Create a new Date based on the time of the original, and copy any custom properties.\n */\nexport const copyDateStrict = createStrictHandler(copyDate);\n\n/**\n * Deeply copy the keys and values of the original.\n */\nexport function copyMap<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): Value {\n return copyOwnPropertiesStrict(map, copyMap(map, state), state, Object.getOwnPropertyNames(map), 0);\n}\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original.\n *\n * @note\n * Values are assigned for performance, but assignment respects the prototype chain, so it throws\n * when the key shadows an inherited read-only or getter-only property. In that case the value is\n * defined directly, still producing the standard own property expected in loose mode. This relies\n * on the source running in strict mode, where a failed assignment throws instead of being silently\n * ignored.\n */\nexport function copyObject<Value extends Record<string, any>>(object: Value, state: State): Value {\n const clone: Record<string | symbol, unknown> = 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 const value = state.copier(object[key], state);\n\n if (key === '__proto__') {\n // Native assignment would attempt to use `Object.setPropertyOf` under the hood, when this\n // property has been explicitly set as a standard property. Using `defineProperty` ensures\n // its treatment in the clone is unchanged from the source.\n defineOwnValue(clone, key, value);\n } else {\n try {\n clone[key] = value;\n } catch {\n defineOwnValue(clone, key, value);\n }\n }\n }\n\n for (const symbol of Object.getOwnPropertySymbols(object)) {\n // Only copy enumerable symbols in loose mode, to align with handling of `keys`.\n if (Object.prototype.propertyIsEnumerable.call(object, symbol)) {\n const value = state.copier((object as any)[symbol], state);\n\n try {\n clone[symbol] = value;\n } catch {\n defineOwnValue(clone, symbol, value);\n }\n }\n }\n\n return clone as Value;\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, Object.getOwnPropertyNames(object), 0);\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 primitive wrapper from the value of the original, and copy any\n * custom properties.\n */\nexport const copyPrimitiveWrapperStrict = createStrictHandler(copyPrimitiveWrapper);\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 // `lastIndex` is not retained when constructing anew, so manually copy it.\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n}\n\n/**\n * Copy the original RegExp, as well as any custom properties.\n */\nexport const copyRegExpStrict = createStrictHandler(copyRegExp);\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 copySet<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, copySet(set, state), state, Object.getOwnPropertyNames(set), 0);\n}\n\n/**\n * Copy the original value based on the handler passed, and also copy custom properties.\n *\n * @note\n * The handlers used here have no nested values to copy, so they skip the cache to keep loose\n * copies fast. Custom properties can reference the value itself, so the clone is cached here\n * before they are copied.\n */\nfunction createStrictHandler<Value extends object>(handler: (value: Value, state: State) => Value) {\n return (value: Value, state: State): Value => {\n const clone = handler(value, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(value, clone);\n\n return copyOwnPropertiesStrict(value, clone, state, Object.getOwnPropertyNames(value), 0);\n };\n}\n\n/**\n * Create a new String wrapper from the value of the original, and copy custom properties.\n */\n// `String` primitive constructor is intentional.\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nexport function copyStringStrict<Value extends String>(string: Value, state: State): Value {\n const clone = copyPrimitiveWrapper(string, state);\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(string, clone);\n\n const { length } = string;\n const names = Object.getOwnPropertyNames(string);\n // Custom integer keys beyond the string's length are listed before `length`, so only skip\n // `length` when it directly follows the characters.\n const start = names[length] === 'length' ? length + 1 : length;\n\n return copyOwnPropertiesStrict(string, clone, state, names, start);\n}\n","import {\n copyArrayBuffer,\n copyArrayBufferStrict,\n copyArray,\n copyArrayStrict,\n copyBlob,\n copyBlobStrict,\n copyDataView,\n copyDataViewStrict,\n copyDate,\n copyDateStrict,\n copyMap,\n copyMapStrict,\n copyObject,\n copyObjectStrict,\n copyPrimitiveWrapper,\n copyPrimitiveWrapperStrict,\n copyRegExp,\n copyRegExpStrict,\n copySelf,\n copySet,\n copySetStrict,\n copyStringStrict,\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 SharedArrayBuffer: InternalCopier<SharedArrayBuffer>;\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 : copyArray,\n arrayBuffer: strict ? copyArrayBufferStrict : copyArrayBuffer,\n asyncGenerator: copySelf,\n blob: strict ? copyBlobStrict : copyBlob,\n dataView: strict ? copyDataViewStrict : copyDataView,\n date: strict ? copyDateStrict : copyDate,\n error: copySelf,\n generator: copySelf,\n map: strict ? copyMapStrict : copyMap,\n object: strict ? copyObjectStrict : copyObject,\n regExp: strict ? copyRegExpStrict : copyRegExp,\n set: strict ? copySetStrict : copySet,\n };\n\n const methods = methodsOverride ? Object.assign(defaultMethods, methodsOverride) : defaultMethods;\n const copiers = getTagSpecificCopiers(methods, strict);\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>, strict: boolean | undefined): Copiers {\n const copyPrimitive = strict ? copyPrimitiveWrapperStrict : copyPrimitiveWrapper;\n\n // A `null` prototype is used so that a value carrying a custom `Symbol.toStringTag`\n // cannot resolve to an inherited `Object.prototype` member as its copier. Without it,\n // a tag such as `toString` or `valueOf` finds a function on the prototype chain and\n // that function is invoked in place of a real copier.\n return Object.assign(Object.create(null) as Copiers, {\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: copyPrimitive,\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: copyPrimitive,\n Object: methods.object,\n Promise: copySelf,\n RegExp: methods.regExp,\n Set: methods.set,\n SharedArrayBuffer: methods.arrayBuffer,\n String: strict ? copyStringStrict : 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,QAAQ,CAAC,CAAA,iDAAA,CAAmD,CAAC;AAEnG,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACxB,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB;IACrC;AACD;AAED;AACA,MAAM,gBAAgB,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ;AACpD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,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;;;;;"}
|
|
@@ -85,6 +85,17 @@ function copyOwnDescriptor(original, clone, property, state) {
|
|
|
85
85
|
clone[property] = descriptor.get ? descriptor.get() : descriptor.value;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Define the value as a standard (configurable, enumerable, writable) own property of the clone.
|
|
90
|
+
*/
|
|
91
|
+
function defineOwnValue(clone, property, value) {
|
|
92
|
+
Object.defineProperty(clone, property, {
|
|
93
|
+
configurable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
value,
|
|
96
|
+
writable: true,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
88
99
|
/**
|
|
89
100
|
* Strictly copy all properties contained on the object, starting with the name at the `start` index.
|
|
90
101
|
*
|
|
@@ -231,31 +242,45 @@ function copyMapStrict(map, state) {
|
|
|
231
242
|
}
|
|
232
243
|
/**
|
|
233
244
|
* Deeply copy the properties (keys and symbols) and values of the original.
|
|
245
|
+
*
|
|
246
|
+
* @note
|
|
247
|
+
* Values are assigned for performance, but assignment respects the prototype chain, so it throws
|
|
248
|
+
* when the key shadows an inherited read-only or getter-only property. In that case the value is
|
|
249
|
+
* defined directly, still producing the standard own property expected in loose mode. This relies
|
|
250
|
+
* on the source running in strict mode, where a failed assignment throws instead of being silently
|
|
251
|
+
* ignored.
|
|
234
252
|
*/
|
|
235
253
|
function copyObject(object, state) {
|
|
236
254
|
const clone = getCleanClone(state.prototype);
|
|
237
255
|
// set in the cache immediately to be able to reuse the object recursively
|
|
238
256
|
state.cache.set(object, clone);
|
|
239
257
|
for (const key of Object.keys(object)) {
|
|
258
|
+
const value = state.copier(object[key], state);
|
|
240
259
|
if (key === '__proto__') {
|
|
241
260
|
// Native assignment would attempt to use `Object.setPropertyOf` under the hood, when this
|
|
242
261
|
// property has been explicitly set as a standard property. Using `defineProperty` ensures
|
|
243
262
|
// its treatment in the clone is unchanged from the source.
|
|
244
|
-
|
|
245
|
-
configurable: true,
|
|
246
|
-
enumerable: true,
|
|
247
|
-
value: state.copier(object[key], state),
|
|
248
|
-
writable: true,
|
|
249
|
-
});
|
|
263
|
+
defineOwnValue(clone, key, value);
|
|
250
264
|
}
|
|
251
265
|
else {
|
|
252
|
-
|
|
266
|
+
try {
|
|
267
|
+
clone[key] = value;
|
|
268
|
+
}
|
|
269
|
+
catch (_a) {
|
|
270
|
+
defineOwnValue(clone, key, value);
|
|
271
|
+
}
|
|
253
272
|
}
|
|
254
273
|
}
|
|
255
274
|
for (const symbol of Object.getOwnPropertySymbols(object)) {
|
|
256
275
|
// Only copy enumerable symbols in loose mode, to align with handling of `keys`.
|
|
257
276
|
if (Object.prototype.propertyIsEnumerable.call(object, symbol)) {
|
|
258
|
-
|
|
277
|
+
const value = state.copier(object[symbol], state);
|
|
278
|
+
try {
|
|
279
|
+
clone[symbol] = value;
|
|
280
|
+
}
|
|
281
|
+
catch (_b) {
|
|
282
|
+
defineOwnValue(clone, symbol, value);
|
|
283
|
+
}
|
|
259
284
|
}
|
|
260
285
|
}
|
|
261
286
|
return clone;
|