agent-relay 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +599 -197
- package/dist/packages/sdk/src/provisioner/local-jwks.d.ts +25 -0
- package/dist/packages/sdk/src/provisioner/local-jwks.d.ts.map +1 -0
- package/dist/packages/sdk/src/provisioner/local-jwks.js +70 -0
- package/dist/packages/sdk/src/provisioner/local-jwks.js.map +1 -0
- package/dist/packages/sdk/src/provisioner/token.d.ts +6 -3
- package/dist/packages/sdk/src/provisioner/token.d.ts.map +1 -1
- package/dist/packages/sdk/src/provisioner/token.js +11 -8
- package/dist/packages/sdk/src/provisioner/token.js.map +1 -1
- package/dist/src/cli/commands/on/provision.d.ts +2 -1
- package/dist/src/cli/commands/on/provision.d.ts.map +1 -1
- package/dist/src/cli/commands/on/provision.js +5 -4
- package/dist/src/cli/commands/on/provision.js.map +1 -1
- package/dist/src/cli/commands/on/services.d.ts +1 -0
- package/dist/src/cli/commands/on/services.d.ts.map +1 -1
- package/dist/src/cli/commands/on/services.js +9 -0
- package/dist/src/cli/commands/on/services.js.map +1 -1
- package/dist/src/cli/commands/on/start.d.ts +6 -3
- package/dist/src/cli/commands/on/start.d.ts.map +1 -1
- package/dist/src/cli/commands/on/start.js +310 -297
- package/dist/src/cli/commands/on/start.js.map +1 -1
- package/dist/src/cli/commands/on/token.d.ts +3 -1
- package/dist/src/cli/commands/on/token.d.ts.map +1 -1
- package/dist/src/cli/commands/on/token.js +3 -3
- package/dist/src/cli/commands/on/token.js.map +1 -1
- package/node_modules/@agent-relay/broker-darwin-arm64/README.md +11 -0
- package/node_modules/@agent-relay/broker-darwin-arm64/package.json +17 -0
- package/node_modules/@agent-relay/broker-darwin-x64/README.md +11 -0
- package/node_modules/@agent-relay/broker-darwin-x64/bin/.gitkeep +0 -0
- package/node_modules/@agent-relay/broker-darwin-x64/package.json +17 -0
- package/node_modules/@agent-relay/broker-linux-arm64/README.md +12 -0
- package/node_modules/@agent-relay/broker-linux-arm64/bin/.gitkeep +0 -0
- package/node_modules/@agent-relay/broker-linux-arm64/package.json +17 -0
- package/node_modules/@agent-relay/broker-linux-x64/README.md +12 -0
- package/node_modules/@agent-relay/broker-linux-x64/bin/.gitkeep +0 -0
- package/node_modules/@agent-relay/broker-linux-x64/package.json +17 -0
- package/node_modules/@agent-relay/broker-win32-x64/README.md +11 -0
- package/node_modules/@agent-relay/broker-win32-x64/bin/.gitkeep +0 -0
- package/node_modules/@agent-relay/broker-win32-x64/package.json +17 -0
- package/node_modules/@agent-relay/cloud/package.json +2 -2
- package/node_modules/@agent-relay/config/dist/cli-registry.generated.d.ts +353 -157
- package/node_modules/@agent-relay/config/dist/cli-registry.generated.d.ts.map +1 -1
- package/node_modules/@agent-relay/config/dist/cli-registry.generated.js +356 -160
- package/node_modules/@agent-relay/config/dist/cli-registry.generated.js.map +1 -1
- package/node_modules/@agent-relay/config/package.json +1 -1
- package/node_modules/@agent-relay/hooks/package.json +4 -4
- package/node_modules/@agent-relay/sdk/dist/broker-path.d.ts +18 -7
- package/node_modules/@agent-relay/sdk/dist/broker-path.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/broker-path.js +92 -20
- package/node_modules/@agent-relay/sdk/dist/broker-path.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/client.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/client.js +9 -2
- package/node_modules/@agent-relay/sdk/dist/client.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/audit.test.js +2 -2
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/audit.test.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/token-factory.test.js +29 -17
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/token-factory.test.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/token.test.js +8 -3
- package/node_modules/@agent-relay/sdk/dist/provisioner/__tests__/token.test.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/index.d.ts +1 -0
- package/node_modules/@agent-relay/sdk/dist/provisioner/index.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/index.js +5 -2
- package/node_modules/@agent-relay/sdk/dist/provisioner/index.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/local-jwks.d.ts +25 -0
- package/node_modules/@agent-relay/sdk/dist/provisioner/local-jwks.d.ts.map +1 -0
- package/node_modules/@agent-relay/sdk/dist/provisioner/local-jwks.js +70 -0
- package/node_modules/@agent-relay/sdk/dist/provisioner/local-jwks.js.map +1 -0
- package/node_modules/@agent-relay/sdk/dist/provisioner/token.d.ts +6 -3
- package/node_modules/@agent-relay/sdk/dist/provisioner/token.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/token.js +11 -8
- package/node_modules/@agent-relay/sdk/dist/provisioner/token.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/provisioner/types.d.ts +3 -2
- package/node_modules/@agent-relay/sdk/dist/provisioner/types.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/__tests__/sibling-links.test.d.ts +2 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/__tests__/sibling-links.test.d.ts.map +1 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/__tests__/sibling-links.test.js +166 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/__tests__/sibling-links.test.js.map +1 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/index.d.ts +2 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/index.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/index.js +1 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/index.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/runner.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/runner.js +18 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/runner.js.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/sibling-links.d.ts +100 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/sibling-links.d.ts.map +1 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/sibling-links.js +205 -0
- package/node_modules/@agent-relay/sdk/dist/workflows/sibling-links.js.map +1 -0
- package/node_modules/@agent-relay/sdk/package.json +10 -3
- package/node_modules/@agent-relay/telemetry/package.json +1 -1
- package/node_modules/@agent-relay/trajectory/package.json +2 -2
- package/node_modules/@agent-relay/user-directory/package.json +2 -2
- package/node_modules/@agent-relay/utils/package.json +2 -2
- package/node_modules/@aws-sdk/core/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-flexible-checksums/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +5 -5
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +4 -4
- package/node_modules/@aws-sdk/nested-clients/package.json +14 -14
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
- package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@nodable/entities/README.md +41 -0
- package/node_modules/@nodable/entities/package.json +54 -0
- package/node_modules/@nodable/entities/src/EntityDecoder.js +543 -0
- package/node_modules/@nodable/entities/src/EntityEncoder.js +194 -0
- package/node_modules/@nodable/entities/src/entities.js +1177 -0
- package/node_modules/@nodable/entities/src/entityTries.js +49 -0
- package/node_modules/@nodable/entities/src/index.d.ts +264 -0
- package/node_modules/@nodable/entities/src/index.js +29 -0
- package/node_modules/@smithy/core/package.json +2 -2
- package/node_modules/@smithy/middleware-endpoint/package.json +3 -3
- package/node_modules/@smithy/middleware-retry/package.json +4 -4
- package/node_modules/@smithy/middleware-serde/package.json +2 -2
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +27 -16
- package/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +5 -0
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +22 -16
- package/node_modules/@smithy/node-http-handler/dist-types/http2/ClientHttp2SessionRef.d.ts +4 -0
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +2 -4
- package/node_modules/@smithy/node-http-handler/package.json +1 -1
- package/node_modules/@smithy/smithy-client/package.json +4 -4
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/node_modules/@smithy/util-retry/dist-cjs/index.js +20 -10
- package/node_modules/@smithy/util-retry/dist-es/StandardRetryStrategy.js +20 -10
- package/node_modules/@smithy/util-retry/dist-types/StandardRetryStrategy.d.ts +12 -4
- package/node_modules/@smithy/util-retry/package.json +1 -1
- package/node_modules/@smithy/util-stream/package.json +2 -2
- package/node_modules/fast-xml-parser/CHANGELOG.md +53 -0
- package/node_modules/fast-xml-parser/README.md +8 -28
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.d.cts +172 -6
- package/node_modules/fast-xml-parser/lib/fxp.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -1
- package/node_modules/fast-xml-parser/package.json +5 -4
- package/node_modules/fast-xml-parser/src/fxp.d.ts +162 -3
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +2 -5
- package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +15 -11
- package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +168 -244
- package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +1 -1
- package/package.json +9 -10
- package/packages/cloud/package.json +2 -2
- package/packages/config/dist/cli-registry.generated.d.ts +353 -157
- package/packages/config/dist/cli-registry.generated.d.ts.map +1 -1
- package/packages/config/dist/cli-registry.generated.js +356 -160
- package/packages/config/dist/cli-registry.generated.js.map +1 -1
- package/packages/config/package.json +1 -1
- package/packages/hooks/package.json +4 -4
- package/packages/sdk/dist/broker-path.d.ts +18 -7
- package/packages/sdk/dist/broker-path.d.ts.map +1 -1
- package/packages/sdk/dist/broker-path.js +92 -20
- package/packages/sdk/dist/broker-path.js.map +1 -1
- package/packages/sdk/dist/client.d.ts.map +1 -1
- package/packages/sdk/dist/client.js +9 -2
- package/packages/sdk/dist/client.js.map +1 -1
- package/packages/sdk/dist/provisioner/__tests__/audit.test.js +2 -2
- package/packages/sdk/dist/provisioner/__tests__/audit.test.js.map +1 -1
- package/packages/sdk/dist/provisioner/__tests__/token-factory.test.js +29 -17
- package/packages/sdk/dist/provisioner/__tests__/token-factory.test.js.map +1 -1
- package/packages/sdk/dist/provisioner/__tests__/token.test.js +8 -3
- package/packages/sdk/dist/provisioner/__tests__/token.test.js.map +1 -1
- package/packages/sdk/dist/provisioner/index.d.ts +1 -0
- package/packages/sdk/dist/provisioner/index.d.ts.map +1 -1
- package/packages/sdk/dist/provisioner/index.js +5 -2
- package/packages/sdk/dist/provisioner/index.js.map +1 -1
- package/packages/sdk/dist/provisioner/local-jwks.d.ts +25 -0
- package/packages/sdk/dist/provisioner/local-jwks.d.ts.map +1 -0
- package/packages/sdk/dist/provisioner/local-jwks.js +70 -0
- package/packages/sdk/dist/provisioner/local-jwks.js.map +1 -0
- package/packages/sdk/dist/provisioner/token.d.ts +6 -3
- package/packages/sdk/dist/provisioner/token.d.ts.map +1 -1
- package/packages/sdk/dist/provisioner/token.js +11 -8
- package/packages/sdk/dist/provisioner/token.js.map +1 -1
- package/packages/sdk/dist/provisioner/types.d.ts +3 -2
- package/packages/sdk/dist/provisioner/types.d.ts.map +1 -1
- package/packages/sdk/dist/workflows/__tests__/sibling-links.test.d.ts +2 -0
- package/packages/sdk/dist/workflows/__tests__/sibling-links.test.d.ts.map +1 -0
- package/packages/sdk/dist/workflows/__tests__/sibling-links.test.js +166 -0
- package/packages/sdk/dist/workflows/__tests__/sibling-links.test.js.map +1 -0
- package/packages/sdk/dist/workflows/index.d.ts +2 -0
- package/packages/sdk/dist/workflows/index.d.ts.map +1 -1
- package/packages/sdk/dist/workflows/index.js +1 -0
- package/packages/sdk/dist/workflows/index.js.map +1 -1
- package/packages/sdk/dist/workflows/runner.d.ts.map +1 -1
- package/packages/sdk/dist/workflows/runner.js +18 -1
- package/packages/sdk/dist/workflows/runner.js.map +1 -1
- package/packages/sdk/dist/workflows/sibling-links.d.ts +100 -0
- package/packages/sdk/dist/workflows/sibling-links.d.ts.map +1 -0
- package/packages/sdk/dist/workflows/sibling-links.js +205 -0
- package/packages/sdk/dist/workflows/sibling-links.js.map +1 -0
- package/packages/sdk/package.json +10 -3
- package/packages/telemetry/package.json +1 -1
- package/packages/trajectory/package.json +2 -2
- package/packages/user-directory/package.json +2 -2
- package/packages/utils/package.json +2 -2
- package/scripts/postinstall.js +9 -146
- package/bin/agent-relay-broker-darwin-arm64 +0 -0
- package/bin/agent-relay-broker-darwin-x64 +0 -0
- package/bin/agent-relay-broker-linux-arm64 +0 -0
- package/bin/agent-relay-broker-linux-x64 +0 -0
- package/node_modules/fast-xml-parser/lib/pem.d.cts +0 -148
- package/node_modules/fast-xml-parser/src/pem.d.ts +0 -135
- /package/{bin → node_modules/@agent-relay/broker-darwin-arm64/bin}/.gitkeep +0 -0
|
@@ -187,6 +187,11 @@ class DefaultRetryToken {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
const refusal = {
|
|
191
|
+
incompatible: 1,
|
|
192
|
+
attempts: 2,
|
|
193
|
+
capacity: 3,
|
|
194
|
+
};
|
|
190
195
|
class StandardRetryStrategy {
|
|
191
196
|
mode = exports.RETRY_MODES.STANDARD;
|
|
192
197
|
capacity = INITIAL_RETRY_TOKENS;
|
|
@@ -214,8 +219,10 @@ class StandardRetryStrategy {
|
|
|
214
219
|
}
|
|
215
220
|
async refreshRetryTokenForRetry(token, errorInfo) {
|
|
216
221
|
const maxAttempts = await this.getMaxAttempts();
|
|
217
|
-
const
|
|
218
|
-
|
|
222
|
+
const retryCode = this.retryCode(token, errorInfo, maxAttempts);
|
|
223
|
+
const shouldRetry = retryCode === 0;
|
|
224
|
+
const isLongPoll = token.isLongPoll?.();
|
|
225
|
+
if (shouldRetry || isLongPoll) {
|
|
219
226
|
const errorType = errorInfo.errorType;
|
|
220
227
|
this.retryBackoffStrategy.setDelayBase(errorType === "THROTTLING" ? Retry.throttlingDelay() : this.baseDelay);
|
|
221
228
|
const delayFromErrorType = this.retryBackoffStrategy.computeNextBackoffDelay(token.getRetryCount());
|
|
@@ -224,7 +231,9 @@ class StandardRetryStrategy {
|
|
|
224
231
|
retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
|
|
225
232
|
}
|
|
226
233
|
if (!shouldRetry) {
|
|
227
|
-
throw Object.assign(new Error("No retry token available"), {
|
|
234
|
+
throw Object.assign(new Error("No retry token available"), {
|
|
235
|
+
$backoff: Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0,
|
|
236
|
+
});
|
|
228
237
|
}
|
|
229
238
|
else {
|
|
230
239
|
const capacityCost = this.getCapacityCost(errorType);
|
|
@@ -240,6 +249,9 @@ class StandardRetryStrategy {
|
|
|
240
249
|
getCapacity() {
|
|
241
250
|
return this.capacity;
|
|
242
251
|
}
|
|
252
|
+
async maxAttempts() {
|
|
253
|
+
return this.maxAttemptsProvider();
|
|
254
|
+
}
|
|
243
255
|
async getMaxAttempts() {
|
|
244
256
|
try {
|
|
245
257
|
return await this.maxAttemptsProvider();
|
|
@@ -249,11 +261,12 @@ class StandardRetryStrategy {
|
|
|
249
261
|
return DEFAULT_MAX_ATTEMPTS;
|
|
250
262
|
}
|
|
251
263
|
}
|
|
252
|
-
|
|
264
|
+
retryCode(tokenToRenew, errorInfo, maxAttempts) {
|
|
253
265
|
const attempts = tokenToRenew.getRetryCount() + 1;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
266
|
+
const retryableStatus = this.isRetryableError(errorInfo.errorType) ? 0 : refusal.incompatible;
|
|
267
|
+
const attemptStatus = attempts < maxAttempts ? 0 : refusal.attempts;
|
|
268
|
+
const capacityStatus = this.capacity >= this.getCapacityCost(errorInfo.errorType) ? 0 : refusal.capacity;
|
|
269
|
+
return retryableStatus || attemptStatus || capacityStatus;
|
|
257
270
|
}
|
|
258
271
|
getCapacityCost(errorType) {
|
|
259
272
|
return errorType === Retry.modifiedCostType() ? Retry.throttlingCost() : Retry.cost();
|
|
@@ -261,9 +274,6 @@ class StandardRetryStrategy {
|
|
|
261
274
|
isRetryableError(errorType) {
|
|
262
275
|
return errorType === "THROTTLING" || errorType === "TRANSIENT";
|
|
263
276
|
}
|
|
264
|
-
async maxAttempts() {
|
|
265
|
-
return this.maxAttemptsProvider();
|
|
266
|
-
}
|
|
267
277
|
}
|
|
268
278
|
|
|
269
279
|
class AdaptiveRetryStrategy {
|
|
@@ -3,6 +3,11 @@ import { INITIAL_RETRY_TOKENS, NO_RETRY_INCREMENT } from "./constants";
|
|
|
3
3
|
import { DefaultRetryBackoffStrategy } from "./DefaultRetryBackoffStrategy";
|
|
4
4
|
import { DefaultRetryToken } from "./DefaultRetryToken";
|
|
5
5
|
import { Retry } from "./retries-2026-config";
|
|
6
|
+
const refusal = {
|
|
7
|
+
incompatible: 1,
|
|
8
|
+
attempts: 2,
|
|
9
|
+
capacity: 3,
|
|
10
|
+
};
|
|
6
11
|
export class StandardRetryStrategy {
|
|
7
12
|
mode = RETRY_MODES.STANDARD;
|
|
8
13
|
capacity = INITIAL_RETRY_TOKENS;
|
|
@@ -30,8 +35,10 @@ export class StandardRetryStrategy {
|
|
|
30
35
|
}
|
|
31
36
|
async refreshRetryTokenForRetry(token, errorInfo) {
|
|
32
37
|
const maxAttempts = await this.getMaxAttempts();
|
|
33
|
-
const
|
|
34
|
-
|
|
38
|
+
const retryCode = this.retryCode(token, errorInfo, maxAttempts);
|
|
39
|
+
const shouldRetry = retryCode === 0;
|
|
40
|
+
const isLongPoll = token.isLongPoll?.();
|
|
41
|
+
if (shouldRetry || isLongPoll) {
|
|
35
42
|
const errorType = errorInfo.errorType;
|
|
36
43
|
this.retryBackoffStrategy.setDelayBase(errorType === "THROTTLING" ? Retry.throttlingDelay() : this.baseDelay);
|
|
37
44
|
const delayFromErrorType = this.retryBackoffStrategy.computeNextBackoffDelay(token.getRetryCount());
|
|
@@ -40,7 +47,9 @@ export class StandardRetryStrategy {
|
|
|
40
47
|
retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
|
|
41
48
|
}
|
|
42
49
|
if (!shouldRetry) {
|
|
43
|
-
throw Object.assign(new Error("No retry token available"), {
|
|
50
|
+
throw Object.assign(new Error("No retry token available"), {
|
|
51
|
+
$backoff: Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0,
|
|
52
|
+
});
|
|
44
53
|
}
|
|
45
54
|
else {
|
|
46
55
|
const capacityCost = this.getCapacityCost(errorType);
|
|
@@ -56,6 +65,9 @@ export class StandardRetryStrategy {
|
|
|
56
65
|
getCapacity() {
|
|
57
66
|
return this.capacity;
|
|
58
67
|
}
|
|
68
|
+
async maxAttempts() {
|
|
69
|
+
return this.maxAttemptsProvider();
|
|
70
|
+
}
|
|
59
71
|
async getMaxAttempts() {
|
|
60
72
|
try {
|
|
61
73
|
return await this.maxAttemptsProvider();
|
|
@@ -65,11 +77,12 @@ export class StandardRetryStrategy {
|
|
|
65
77
|
return DEFAULT_MAX_ATTEMPTS;
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
|
-
|
|
80
|
+
retryCode(tokenToRenew, errorInfo, maxAttempts) {
|
|
69
81
|
const attempts = tokenToRenew.getRetryCount() + 1;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
const retryableStatus = this.isRetryableError(errorInfo.errorType) ? 0 : refusal.incompatible;
|
|
83
|
+
const attemptStatus = attempts < maxAttempts ? 0 : refusal.attempts;
|
|
84
|
+
const capacityStatus = this.capacity >= this.getCapacityCost(errorInfo.errorType) ? 0 : refusal.capacity;
|
|
85
|
+
return retryableStatus || attemptStatus || capacityStatus;
|
|
73
86
|
}
|
|
74
87
|
getCapacityCost(errorType) {
|
|
75
88
|
return errorType === Retry.modifiedCostType() ? Retry.throttlingCost() : Retry.cost();
|
|
@@ -77,7 +90,4 @@ export class StandardRetryStrategy {
|
|
|
77
90
|
isRetryableError(errorType) {
|
|
78
91
|
return errorType === "THROTTLING" || errorType === "TRANSIENT";
|
|
79
92
|
}
|
|
80
|
-
async maxAttempts() {
|
|
81
|
-
return this.maxAttemptsProvider();
|
|
82
|
-
}
|
|
83
93
|
}
|
|
@@ -36,13 +36,21 @@ export declare class StandardRetryStrategy implements RetryStrategyV2 {
|
|
|
36
36
|
* @returns the current available retry capacity.
|
|
37
37
|
*/
|
|
38
38
|
getCapacity(): number;
|
|
39
|
-
private getMaxAttempts;
|
|
40
|
-
private shouldRetry;
|
|
41
|
-
private getCapacityCost;
|
|
42
|
-
private isRetryableError;
|
|
43
39
|
/**
|
|
44
40
|
* There is an existing integration which accesses this field.
|
|
45
41
|
* @deprecated
|
|
46
42
|
*/
|
|
47
43
|
maxAttempts(): Promise<number>;
|
|
44
|
+
private getMaxAttempts;
|
|
45
|
+
/**
|
|
46
|
+
* 0 - OK to retry.
|
|
47
|
+
* 1 - error is not classified as retryable.
|
|
48
|
+
* 2 - attempt count exhausted.
|
|
49
|
+
* 3 - no capacity left (retry tokens exhausted).
|
|
50
|
+
*
|
|
51
|
+
* @returns 0 or the number of the highest priority (lowest integer) reason why retry is not possible.
|
|
52
|
+
*/
|
|
53
|
+
private retryCode;
|
|
54
|
+
private getCapacityCost;
|
|
55
|
+
private isRetryableError;
|
|
48
56
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/util-stream",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.25",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
|
|
6
6
|
"build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline util-stream",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@smithy/fetch-http-handler": "^5.3.17",
|
|
32
|
-
"@smithy/node-http-handler": "^4.6.
|
|
32
|
+
"@smithy/node-http-handler": "^4.6.1",
|
|
33
33
|
"@smithy/types": "^4.14.1",
|
|
34
34
|
"@smithy/util-base64": "^4.3.2",
|
|
35
35
|
"@smithy/util-buffer-from": "^4.2.2",
|
|
@@ -2,6 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
Note: Due to some last quick changes on v4, detail of v4.5.3 & v4.5.4 are not updated here. v4.5.4x is the last tag of v4 in github repository. I'm extremely sorry for the confusion
|
|
4
4
|
|
|
5
|
+
**5.7.0 / 2026-04-17**
|
|
6
|
+
- Use `@nodable/entities` v2.1.0
|
|
7
|
+
- breaking changes
|
|
8
|
+
- single entity scan. You're not allowed to user entity value to form another entity name.
|
|
9
|
+
- you cant add numeric external entity
|
|
10
|
+
- entity error message when expantion limit is crossed might change
|
|
11
|
+
- typings are updated for new options related to process entity
|
|
12
|
+
- please follow documentation of `@nodable/entities` for more detail.
|
|
13
|
+
- performance
|
|
14
|
+
- if processEntities is false, then there should not be impact on performance.
|
|
15
|
+
- if processEntities is true, but you dont pass entity decoder separately then performance may degrade by approx 8-10%
|
|
16
|
+
- if processEntities is true, and you pass entity decoder separately
|
|
17
|
+
- if no entity then performance should be same as before
|
|
18
|
+
- if there are entities then performance should be increased from past versions
|
|
19
|
+
- ignoreAttributes is not required to be set to set xml version for NCR entity value
|
|
20
|
+
- update 'fast-xml-builder' to sanitize malicious CDATA and comment's content
|
|
21
|
+
|
|
22
|
+
**5.6.0 / 2026-04-15**
|
|
23
|
+
- fix: entity replacement for numeric entities
|
|
24
|
+
- use @nodable/entities to replace entities
|
|
25
|
+
- this may change some error messages related to entities expansion limit or inavlid use
|
|
26
|
+
- post check would be exposed in future version
|
|
27
|
+
|
|
28
|
+
**5.5.12 / 2026-04-13**
|
|
29
|
+
- Performance Improvement: update path-expression-matcher
|
|
30
|
+
- use proxy pattern than Proxy class
|
|
31
|
+
|
|
32
|
+
**5.5.11 / 2026-04-08**
|
|
33
|
+
- Performance Improvement
|
|
34
|
+
- integrate ExpressionSet for stopNodes
|
|
35
|
+
|
|
36
|
+
**5.5.10 / 2026-04-03**
|
|
37
|
+
- increase default entity explansion limit as many projects demand for that
|
|
38
|
+
- performance improvement
|
|
39
|
+
- reduce calls to toString
|
|
40
|
+
- early return when entities are not present
|
|
41
|
+
- prepare rawAttrsForMatcher only if user sets `jPath: false`
|
|
42
|
+
|
|
43
|
+
**5.5.9 / 2026-03-23**
|
|
44
|
+
- combine typing files
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
**4.5.5 / 2026-03-22**
|
|
48
|
+
|
|
49
|
+
apply fixes from v5 (legacy maintenance branch v4-maintenance)
|
|
50
|
+
|
|
51
|
+
- support maxEntityCount
|
|
52
|
+
- support onDangerousProperty
|
|
53
|
+
- support maxNestedTags
|
|
54
|
+
- handle prototype pollution
|
|
55
|
+
- fix incorrect entity name replacement
|
|
56
|
+
- fix incorrect condition for entity expansion
|
|
57
|
+
|
|
5
58
|
**5.5.8 / 2026-03-20**
|
|
6
59
|
- pass read only matcher in callback
|
|
7
60
|
|
|
@@ -16,13 +16,17 @@ It can handle big files (tested up to 100mb). XML Entities, HTML entities, and D
|
|
|
16
16
|
---
|
|
17
17
|
# Your Support, Our Motivation
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Please join [Discord community](https://discord.gg/X4Qp9u6Vz) for pre release announcements and discussions. This will prevent us to release breaking changes.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<!-- ## Try out our New Thoughts
|
|
20
24
|
|
|
21
25
|
- WishIn - You need it if negative thoughts take over all the time <br>
|
|
22
26
|
<a href="https://play.google.com/store/apps/details?id=com.solothought.wishin"> <img src="https://solothought.com/products/assets/images/wishin/YouTubeThumbnail.png" width="500px"/> </a>
|
|
23
27
|
- **Flowgger**: 90% less logs size and 90% less debugging time<br>
|
|
24
28
|
<a href="https://github.com/solothought/flowgger"> <img src="static/img/flowgger_h.webp" alt="Flowgger Logging Framework" width="300px"/></a>
|
|
25
|
-
- [Text2Chart](https://solothought.com/text2chart/flow): interactive flow chart out of simple text.
|
|
29
|
+
- [Text2Chart](https://solothought.com/text2chart/flow): interactive flow chart out of simple text. -->
|
|
26
30
|
|
|
27
31
|
## Financial Support
|
|
28
32
|
|
|
@@ -34,38 +38,14 @@ Sponsor this project
|
|
|
34
38
|
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
|
|
35
39
|
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=180 />
|
|
36
40
|
</a>
|
|
37
|
-
<a href="https://paypal.me/naturalintelligence"> <img src="static/img/support_paypal.svg" alt="donate button" width="180"/></a>
|
|
38
41
|
<br>
|
|
39
42
|
<br>
|
|
40
43
|
<br>
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
### Current Sponsors
|
|
44
|
-
|
|
45
|
-
Check the complete list at [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our sponsors and supporters.
|
|
46
|
-
|
|
47
|
-
Through Github
|
|
48
|
-
|
|
49
|
-
<a href="https://github.com/skunkteam" target="_blank"><img src="https://avatars.githubusercontent.com/u/46373671?s=60" width="60px"></a>
|
|
50
|
-
<a href="https://github.com/getsentry" target="_blank"><img src="https://avatars.githubusercontent.com/u/1396951?s=60" width="60px"></a>
|
|
51
|
-
|
|
52
|
-
Through OpenCollective
|
|
53
|
-
|
|
54
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/0/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/0/avatar.svg"></a>
|
|
55
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/1/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/1/avatar.svg"></a>
|
|
56
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/2/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/2/avatar.svg"></a>
|
|
57
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/3/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/3/avatar.svg"></a>
|
|
58
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/4/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/4/avatar.svg"></a>
|
|
59
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/5/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/5/avatar.svg"></a>
|
|
60
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/6/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/6/avatar.svg"></a>
|
|
61
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/7/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/7/avatar.svg"></a>
|
|
62
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/8/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/8/avatar.svg"></a>
|
|
63
|
-
<a href="https://opencollective.com/fast-xml-parser/sponsor/9/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/9/avatar.svg"></a>
|
|
64
|
-
-->
|
|
45
|
+
> This is a donation. No goods or services are expected in return. Any requests for refunds for those purposes will be rejected.
|
|
65
46
|
|
|
66
47
|

|
|
67
|
-
|
|
68
|
-
> This is a donation. No goods or services are expected in return. Any requests for refunds for those purposes will be rejected.
|
|
48
|
+
> This image update once in 6 months mostly
|
|
69
49
|
|
|
70
50
|
## Users
|
|
71
51
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>y});class i{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,s="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(s.trim()&&(e.push(this._parseSegment(s.trim())),s=""),e.push({type:"deep-wildcard"}),i+=2):(s.trim()&&e.push(this._parseSegment(s.trim())),s="",i++):(s+=t[i],i++);return s.trim()&&e.push(this._parseSegment(s.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,s=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(s=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let r,o,a=s;if(s.includes("::")){const e=s.indexOf("::");if(r=s.substring(0,e).trim(),a=s.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(h){const t=h.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=h}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}const s=new Set(["push","pop","reset","updateCurrent","restore"]);class n{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=null){this.path.length>0&&(this.path[this.path.length-1].values=void 0);const s=this.path.length;this.siblingStacks[s]||(this.siblingStacks[s]=new Map);const n=this.siblingStacks[s],r=i?`${i}:${t}`:t,o=n.get(r)||0;let a=0;for(const t of n.values())a+=t;n.set(r,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0===this.path.length)return;const e=this.path[this.path.length-1];return e.values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++){const i=t[e],s=this.path[e],n=e===this.path.length-1;if(!this._matchSegment(i,s,n))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const s=t[i];if("deep-wildcard"===s.type){if(i--,i<0)return!0;const s=t[i];let n=!1;for(let t=e;t>=0;t--){const r=t===this.path.length-1;if(this._matchSegment(s,this.path[t],r)){e=t-1,i--,n=!0;break}}if(!n)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(s,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const s=e.counter??0;if("first"===t.position&&0!==s)return!1;if("odd"===t.position&&s%2!=1)return!1;if("even"===t.position&&s%2!=0)return!1;if("nth"===t.position&&s!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return new Proxy(this,{get(t,e,i){if(s.has(e))return()=>{throw new TypeError(`Cannot call '${e}' on a read-only Matcher. Obtain a writable instance to mutate state.`)};const n=Reflect.get(t,e,i);return"path"===e||"siblingStacks"===e?Object.freeze(Array.isArray(n)?n.map(t=>t instanceof Map?Object.freeze(new Map(t)):Object.freeze({...t})):n):"function"==typeof n?n.bind(t):n},set(t,e){throw new TypeError(`Cannot set property '${String(e)}' on a read-only Matcher.`)},deleteProperty(t,e){throw new TypeError(`Cannot delete property '${String(e)}' from a read-only Matcher.`)}})}}function r(t,e){let s="";e.format&&e.indentBy.length>0&&(s="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const s=e.stopNodes[t];"string"==typeof s?r.push(new i(s)):s instanceof i&&r.push(s)}return o(t,e,s,new n,r)}function o(t,e,i,s,n){let r="",p=!1;if(e.maxNestedTags&&s.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=d(i,e),i}return""}for(let f=0;f<t.length;f++){const g=t[f],m=u(g);if(void 0===m)continue;const b=a(g[":@"],e);s.push(m,b);const N=c(s,n);if(m===e.textNodeName){let t=g[m];N||(t=e.tagValueProcessor(m,t),t=d(t,e)),p&&(r+=i),r+=t,p=!1,s.pop();continue}if(m===e.cdataPropName){p&&(r+=i),r+=`<![CDATA[${g[m][0][e.textNodeName]}]]>`,p=!1,s.pop();continue}if(m===e.commentPropName){r+=i+`\x3c!--${g[m][0][e.textNodeName]}--\x3e`,p=!0,s.pop();continue}if("?"===m[0]){const t=l(g[":@"],e,N),n="?xml"===m?"":i;let o=g[m][0][e.textNodeName];o=0!==o.length?" "+o:"",r+=n+`<${m}${o}${t}?>`,p=!0,s.pop();continue}let y=i;""!==y&&(y+=e.indentBy);const x=i+`<${m}${l(g[":@"],e,N)}`;let P;P=N?h(g[m],e):o(g[m],e,y,s,n),-1!==e.unpairedTags.indexOf(m)?e.suppressUnpairedNode?r+=x+">":r+=x+"/>":P&&0!==P.length||!e.suppressEmptyNode?P&&P.endsWith(">")?r+=x+`>${P}${i}</${m}>`:(r+=x+">",P&&""!==i&&(P.includes("/>")||P.includes("</"))?r+=i+e.indentBy+P+i:r+=P,r+=`</${m}>`):r+=x+"/>",p=!0,s.pop()}return r}function a(t,e){if(!t||e.ignoreAttributes)return null;const i={};let s=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=t[n],s=!0);return s?i:null}function h(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let s=0;s<t.length;s++){const n=t[s],r=u(n);if(r===e.textNodeName)i+=n[r];else if(r===e.cdataPropName)i+=n[r][0][e.textNodeName];else if(r===e.commentPropName)i+=n[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=p(n[":@"],e),s=h(n[r],e);s&&0!==s.length?i+=`<${r}${t}>${s}</${r}>`:i+=`<${r}${t}/>`}}}return i}function p(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=t[s];!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function u(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function l(t,e,i){let s="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let r;i?r=t[n]:(r=e.attributeValueProcessor(n,t[n]),r=d(r,e)),!0===r&&e.suppressBooleanAttributes?s+=` ${n.substr(e.attributeNamePrefix.length)}`:s+=` ${n.substr(e.attributeNamePrefix.length)}="${r}"`}return s}function c(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function d(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const f={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0};function g(t){if(this.options=Object.assign({},f,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new i(e)):e instanceof i&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=N),this.processTextOrObjNode=m,this.options.format?(this.indentate=b,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function m(t,e,i,s){const n=this.extractAttributes(t);if(s.push(e,n),this.checkStopNode(s)){const n=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return s.pop(),this.buildObjectNode(n,e,r,i)}const r=this.j2x(t,i+1,s);return s.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i,s):this.buildObjectNode(r.val,e,r.attrStr,i)}function b(t){return this.options.indentBy.repeat(t)}function N(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}g.prototype.build=function(t){if(this.options.preserveOrder)return r(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new n;return this.j2x(t,0,e).val}},g.prototype.j2x=function(t,e,i){let s="",n="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const r=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(n+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?n+="":"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)n+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const h=this.isAttribute(a);if(h&&!this.ignoreAttributesFn(h,r))s+=this.buildAttrPairStr(h,""+t[a],o);else if(!h)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);n+=this.replaceEntitiesValue(e)}else{i.push(a);const s=this.checkStopNode(i);if(i.pop(),s){const i=""+t[a];n+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else n+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const s=t[a].length;let r="",o="";for(let h=0;h<s;h++){const s=t[a][h];if(void 0===s);else if(null===s)"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof s)if(this.options.oneListGroup){i.push(a);const t=this.j2x(s,e+1,i);i.pop(),r+=t.val,this.options.attributesGroupName&&s.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(s,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,s);t=this.replaceEntitiesValue(t),r+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+s;r+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else r+=this.buildTextValNode(s,a,"",e,i)}}this.options.oneListGroup&&(r=this.buildObjectNode(r,a,o,e)),n+=r}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let n=0;n<i;n++)s+=this.buildAttrPairStr(e[n],""+t[a][e[n]],o)}else n+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:s,val:n}},g.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},g.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const s=t[this.options.attributesGroupName];for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=s[t],i=!0)}else for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;const n=this.isAttribute(s);n&&(e[n]=t[s],i=!0)}return i?e:null},g.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const s=t[i];if(i===this.options.textNodeName)e+=s;else if(Array.isArray(s)){for(let t of s)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const s=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===s?`<${i}${n}/>`:`<${i}${n}>${s}</${i}>`}}else if("object"==typeof s&&null!==s){const t=this.buildRawContent(s),n=this.buildAttributesForStopNode(s);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${s}</${i}>`}return e},g.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const s=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const s=this.isAttribute(i);if(s){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}return e},g.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+r+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+r+">"+t+n}},g.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},g.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},g.prototype.buildTextValNode=function(t,e,i,s,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(s)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},g.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const y=g;return e})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>y});class i{constructor(t,e={},i){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=i,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,s="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(s.trim()&&(e.push(this._parseSegment(s.trim())),s=""),e.push({type:"deep-wildcard"}),i+=2):(s.trim()&&e.push(this._parseSegment(s.trim())),s="",i++):(s+=t[i],i++);return s.trim()&&e.push(this._parseSegment(s.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,s=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(s=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let r,o,a=s;if(s.includes("::")){const e=s.indexOf("::");if(r=s.substring(0,e).trim(),a=s.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(h){const t=h.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=h}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class s{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){const e=this._matcher.path;if(0!==e.length)return e[e.length-1].values?.[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const i=e[e.length-1];return void 0!==i.values&&t in i.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class n{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new s(this)}push(t,e=null,i=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const s=this.path.length;this.siblingStacks[s]||(this.siblingStacks[s]=new Map);const n=this.siblingStacks[s],r=i?`${i}:${t}`:t,o=n.get(r)||0;let a=0;for(const t of n.values())a+=t;n.set(r,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0!==this.path.length)return this.path[this.path.length-1].values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;if(i===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const s=t[i];if("deep-wildcard"===s.type){if(i--,i<0)return!0;const s=t[i];let n=!1;for(let t=e;t>=0;t--)if(this._matchSegment(s,this.path[t],t===this.path.length-1)){e=t-1,i--,n=!0;break}if(!n)return!1}else{if(!this._matchSegment(s,this.path[e],e===this.path.length-1))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!i)return!1;const s=e.counter??0;if("first"===t.position&&0!==s)return!1;if("odd"===t.position&&s%2!=1)return!1;if("even"===t.position&&s%2!=0)return!1;if("nth"===t.position&&s!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function r(t,e){let s="";e.format&&e.indentBy.length>0&&(s="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const s=e.stopNodes[t];"string"==typeof s?r.push(new i(s)):s instanceof i&&r.push(s)}return o(t,e,s,new n,r)}function o(t,e,i,s,n){let r="",p=!1;if(e.maxNestedTags&&s.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=g(i,e),i}return""}for(let d=0;d<t.length;d++){const f=t[d],m=u(f);if(void 0===m)continue;const b=a(f[":@"],e);s.push(m,b);const N=c(s,n);if(m===e.textNodeName){let t=f[m];N||(t=e.tagValueProcessor(m,t),t=g(t,e)),p&&(r+=i),r+=t,p=!1,s.pop();continue}if(m===e.cdataPropName){p&&(r+=i);const t=f[m][0][e.textNodeName];r+=`<![CDATA[${String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}]]>`,p=!1,s.pop();continue}if(m===e.commentPropName){const t=f[m][0][e.textNodeName];r+=i+`\x3c!--${String(t).replace(/--/g,"- -").replace(/-$/,"- ")}--\x3e`,p=!0,s.pop();continue}if("?"===m[0]){const t=l(f[":@"],e,N),n="?xml"===m?"":i;let o=f[m][0][e.textNodeName];o=0!==o.length?" "+o:"",r+=n+`<${m}${o}${t}?>`,p=!0,s.pop();continue}let y=i;""!==y&&(y+=e.indentBy);const x=i+`<${m}${l(f[":@"],e,N)}`;let A;A=N?h(f[m],e):o(f[m],e,y,s,n),-1!==e.unpairedTags.indexOf(m)?e.suppressUnpairedNode?r+=x+">":r+=x+"/>":A&&0!==A.length||!e.suppressEmptyNode?A&&A.endsWith(">")?r+=x+`>${A}${i}</${m}>`:(r+=x+">",A&&""!==i&&(A.includes("/>")||A.includes("</"))?r+=i+e.indentBy+A+i:r+=A,r+=`</${m}>`):r+=x+"/>",p=!0,s.pop()}return r}function a(t,e){if(!t||e.ignoreAttributes)return null;const i={};let s=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=t[n],s=!0);return s?i:null}function h(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let s=0;s<t.length;s++){const n=t[s],r=u(n);if(r===e.textNodeName)i+=n[r];else if(r===e.cdataPropName)i+=n[r][0][e.textNodeName];else if(r===e.commentPropName)i+=n[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=p(n[":@"],e),s=h(n[r],e);s&&0!==s.length?i+=`<${r}${t}>${s}</${r}>`:i+=`<${r}${t}/>`}}}return i}function p(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=t[s];!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function u(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function l(t,e,i){let s="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let r;i?r=t[n]:(r=e.attributeValueProcessor(n,t[n]),r=g(r,e)),!0===r&&e.suppressBooleanAttributes?s+=` ${n.substr(e.attributeNamePrefix.length)}`:s+=` ${n.substr(e.attributeNamePrefix.length)}="${r}"`}return s}function c(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function g(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const d={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0};function f(t){if(this.options=Object.assign({},d,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new i(e)):e instanceof i&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=N),this.processTextOrObjNode=m,this.options.format?(this.indentate=b,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function m(t,e,i,s){const n=this.extractAttributes(t);if(s.push(e,n),this.checkStopNode(s)){const n=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return s.pop(),this.buildObjectNode(n,e,r,i)}const r=this.j2x(t,i+1,s);return s.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i,s):this.buildObjectNode(r.val,e,r.attrStr,i)}function b(t){return this.options.indentBy.repeat(t)}function N(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}f.prototype.build=function(t){if(this.options.preserveOrder)return r(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new n;return this.j2x(t,0,e).val}},f.prototype.j2x=function(t,e,i){let s="",n="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const r=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(n+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?n+="":"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)n+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const h=this.isAttribute(a);if(h&&!this.ignoreAttributesFn(h,r))s+=this.buildAttrPairStr(h,""+t[a],o);else if(!h)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);n+=this.replaceEntitiesValue(e)}else{i.push(a);const s=this.checkStopNode(i);if(i.pop(),s){const i=""+t[a];n+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else n+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const s=t[a].length;let r="",o="";for(let h=0;h<s;h++){const s=t[a][h];if(void 0===s);else if(null===s)"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof s)if(this.options.oneListGroup){i.push(a);const t=this.j2x(s,e+1,i);i.pop(),r+=t.val,this.options.attributesGroupName&&s.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(s,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,s);t=this.replaceEntitiesValue(t),r+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+s;r+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else r+=this.buildTextValNode(s,a,"",e,i)}}this.options.oneListGroup&&(r=this.buildObjectNode(r,a,o,e)),n+=r}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let n=0;n<i;n++)s+=this.buildAttrPairStr(e[n],""+t[a][e[n]],o)}else n+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:s,val:n}},f.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},f.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const s=t[this.options.attributesGroupName];for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=s[t],i=!0)}else for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;const n=this.isAttribute(s);n&&(e[n]=t[s],i=!0)}return i?e:null},f.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const s=t[i];if(i===this.options.textNodeName)e+=s;else if(Array.isArray(s)){for(let t of s)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const s=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===s?`<${i}${n}/>`:`<${i}${n}>${s}</${i}>`}}else if("object"==typeof s&&null!==s){const t=this.buildRawContent(s),n=this.buildAttributesForStopNode(s);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${s}</${i}>`}return e},f.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const s=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const s=this.isAttribute(i);if(s){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}return e},f.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+r+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+r+">"+t+n}},f.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},f.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},f.prototype.buildTextValNode=function(t,e,i,s,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName){const e=String(t).replace(/\]\]>/g,"]]]]><![CDATA[>");return this.indentate(s)+`<![CDATA[${e}]]>`+this.newLine}if(!1!==this.options.commentPropName&&e===this.options.commentPropName){const e=String(t).replace(/--/g,"- -").replace(/-$/,"- ");return this.indentate(s)+`\x3c!--${e}--\x3e`+this.newLine}if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},f.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const y=f;return e})());
|
|
2
2
|
//# sourceMappingURL=fxbuilder.min.js.map
|