@cdklabs/cdk-ssm-documents 0.0.55 → 0.0.56
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/.jsii +12 -12
- package/lib/construct/synth-utils.js +1 -1
- package/lib/document/automation-document.js +1 -1
- package/lib/document/command-document.js +1 -1
- package/lib/document/document-builder.js +2 -2
- package/lib/document/ssm-document.js +1 -1
- package/lib/domain/aws-service.js +1 -1
- package/lib/domain/choice.js +1 -1
- package/lib/domain/data-type.js +1 -1
- package/lib/domain/enum/install-action.js +2 -2
- package/lib/domain/enum/install-uninstall-repair.js +2 -2
- package/lib/domain/enum/installation-type.js +2 -2
- package/lib/domain/enum/package-name.js +2 -2
- package/lib/domain/input.js +1 -1
- package/lib/domain/operation.js +1 -1
- package/lib/domain/platform.js +1 -1
- package/lib/domain/precondition.js +1 -1
- package/lib/incident-response/incident-response.js +3 -3
- package/lib/interface/approve-hook.js +2 -2
- package/lib/interface/auth-method.js +3 -3
- package/lib/interface/aws-invoker.js +2 -2
- package/lib/interface/downloadable-content.js +8 -8
- package/lib/interface/environment.js +3 -3
- package/lib/interface/execute-automation-hook/api-execute-automation-hook.js +1 -1
- package/lib/interface/observer.js +1 -1
- package/lib/interface/on-failure.js +6 -6
- package/lib/interface/pause-hook.js +2 -2
- package/lib/interface/run-command-hook/api-run-command-hook.js +1 -1
- package/lib/interface/run-document-location.js +2 -2
- package/lib/interface/sleep-hook.js +2 -2
- package/lib/interface/step-ref.js +1 -1
- package/lib/interface/variables/boolean-variable.js +2 -2
- package/lib/interface/variables/map-list-variable.js +2 -2
- package/lib/interface/variables/number-variable.js +2 -2
- package/lib/interface/variables/secure-string-variable.js +4 -4
- package/lib/interface/variables/string-list-variable.js +2 -2
- package/lib/interface/variables/string-map-variable.js +2 -2
- package/lib/interface/variables/string-variable.js +4 -4
- package/lib/interface/variables/variable.js +2 -2
- package/lib/interface/webhook.js +1 -1
- package/lib/parent-steps/automation/approve-step.js +1 -1
- package/lib/parent-steps/automation/assert-aws-resource-step.js +1 -1
- package/lib/parent-steps/automation/aws-api-step.js +1 -1
- package/lib/parent-steps/automation/branch-step.js +1 -1
- package/lib/parent-steps/automation/change-instance-state-step.js +3 -3
- package/lib/parent-steps/automation/copy-image-step.js +1 -1
- package/lib/parent-steps/automation/create-image-step.js +1 -1
- package/lib/parent-steps/automation/create-stack-step.js +3 -3
- package/lib/parent-steps/automation/create-tags-step.js +3 -3
- package/lib/parent-steps/automation/delete-image-step.js +1 -1
- package/lib/parent-steps/automation/delete-stack-step.js +1 -1
- package/lib/parent-steps/automation/execute-automation-step.js +1 -1
- package/lib/parent-steps/automation/execute-script-step.js +5 -5
- package/lib/parent-steps/automation/execute-state-machine-step.js +1 -1
- package/lib/parent-steps/automation/invoke-lambda-function-step.js +1 -1
- package/lib/parent-steps/automation/invoke-webhook-step.js +1 -1
- package/lib/parent-steps/automation/pause-step.js +1 -1
- package/lib/parent-steps/automation/run-command-step.js +3 -3
- package/lib/parent-steps/automation/run-instance-step.js +1 -1
- package/lib/parent-steps/automation/sleep-step.js +1 -1
- package/lib/parent-steps/automation/update-variable.js +1 -1
- package/lib/parent-steps/automation/wait-for-resource-step.js +1 -1
- package/lib/parent-steps/automation-step.js +1 -1
- package/lib/parent-steps/command/applications-step.js +1 -1
- package/lib/parent-steps/command/configure-docker-step.js +1 -1
- package/lib/parent-steps/command/configure-package-step.js +1 -1
- package/lib/parent-steps/command/domain-join-step.js +1 -1
- package/lib/parent-steps/command/download-content-step.js +1 -1
- package/lib/parent-steps/command/ps-module-step.js +1 -1
- package/lib/parent-steps/command/run-docker-action-step.js +1 -1
- package/lib/parent-steps/command/run-document-step.js +1 -1
- package/lib/parent-steps/command/run-powershell-script-step.js +1 -1
- package/lib/parent-steps/command/run-shell-script-step.js +1 -1
- package/lib/parent-steps/command/software-inventory-step.js +1 -1
- package/lib/parent-steps/command/update-agent-step.js +1 -1
- package/lib/parent-steps/command/update-ssm-agent-step.js +1 -1
- package/lib/parent-steps/command-step.js +1 -1
- package/lib/parent-steps/step.js +1 -1
- package/lib/patterns/automation/composite-step.js +2 -2
- package/lib/patterns/automation/reboot-instance-and-wait.js +1 -1
- package/lib/patterns/automation/string-step.js +1 -1
- package/lib/patterns/document/string-document.js +1 -1
- package/lib/patterns/document/timed-document.js +1 -1
- package/lib/samples/hello-world.js +1 -1
- package/lib/simulation/automation/approve-simulation.js +1 -1
- package/lib/simulation/automation/assert-aws-resource-simulation.js +1 -1
- package/lib/simulation/automation/automation-simulation-base.js +1 -1
- package/lib/simulation/automation/aws-api-simulation.js +1 -1
- package/lib/simulation/automation/branch-simulation.js +1 -1
- package/lib/simulation/automation/change-instance-state-simulation.js +1 -1
- package/lib/simulation/automation/copy-image-simulation.js +1 -1
- package/lib/simulation/automation/create-image-simulation.js +1 -1
- package/lib/simulation/automation/create-stack-simulation.js +1 -1
- package/lib/simulation/automation/create-tags-simulation.js +1 -1
- package/lib/simulation/automation/delete-image-simulation.js +1 -1
- package/lib/simulation/automation/delete-stack-simulation.js +1 -1
- package/lib/simulation/automation/execute-script-simulation.js +1 -1
- package/lib/simulation/automation/execute-state-machine-simulation.js +1 -1
- package/lib/simulation/automation/invoke-lambda-function-simulation.js +1 -1
- package/lib/simulation/automation/invoke-webhook-simulation.js +1 -1
- package/lib/simulation/automation/pause-simulation.js +1 -1
- package/lib/simulation/automation/run-command-simulation.js +1 -1
- package/lib/simulation/automation/run-instance-simulation.js +1 -1
- package/lib/simulation/automation/sleep-simulation.js +1 -1
- package/lib/simulation/automation/update-variable-simulation.js +1 -1
- package/lib/simulation/automation/wait-for-resource-simulation.js +1 -1
- package/lib/simulation/automation-step-simulation.js +1 -1
- package/lib/simulation/command/command-simulation-base.js +1 -1
- package/lib/simulation/command/ps-module-simulation.js +1 -1
- package/lib/simulation/command/run-powershell-script-simulation.js +1 -1
- package/lib/simulation/command/run-shell-script-simulation.js +1 -1
- package/lib/simulation/command-step-simulation.js +1 -1
- package/lib/simulation/document/automation-simulation.js +1 -1
- package/lib/simulation/document/command-simulation.js +1 -1
- package/lib/simulation/simulation.js +1 -1
- package/node_modules/@aws-sdk/client-cloudformation/package.json +34 -34
- package/node_modules/@aws-sdk/client-cloudwatch/package.json +36 -36
- package/node_modules/@aws-sdk/client-ec2/README.md +14 -0
- package/node_modules/@aws-sdk/client-ec2/dist-cjs/index.js +41 -0
- package/node_modules/@aws-sdk/client-ec2/dist-cjs/schemas/schemas_0.js +156 -78
- package/node_modules/@aws-sdk/client-ec2/dist-es/EC2.js +6 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/commands/GetCapacityManagerMonitoredTagKeysCommand.js +16 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/commands/UpdateCapacityManagerMonitoredTagKeysCommand.js +16 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/commands/index.js +2 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/models/enums.js +8 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/pagination/GetCapacityManagerMonitoredTagKeysPaginator.js +4 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/pagination/index.js +1 -0
- package/node_modules/@aws-sdk/client-ec2/dist-es/schemas/schemas_0.js +96 -18
- package/node_modules/@aws-sdk/client-ec2/dist-types/EC2.d.ts +23 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/EC2Client.d.ts +4 -2
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/GetCapacityManagerMetricDataCommand.d.ts +9 -2
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/GetCapacityManagerMetricDimensionsCommand.d.ts +9 -2
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/GetCapacityManagerMonitoredTagKeysCommand.d.ts +87 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/GetConsoleScreenshotCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/GetDeclarativePoliciesReportSummaryCommand.d.ts +1 -2
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/ModifyTrafficMirrorFilterNetworkServicesCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/ModifyTrafficMirrorFilterRuleCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/UpdateCapacityManagerMonitoredTagKeysCommand.d.ts +91 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/commands/index.d.ts +2 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/models/enums.d.ts +16 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/models/models_5.d.ts +126 -79
- package/node_modules/@aws-sdk/client-ec2/dist-types/models/models_6.d.ts +81 -122
- package/node_modules/@aws-sdk/client-ec2/dist-types/models/models_7.d.ts +168 -3
- package/node_modules/@aws-sdk/client-ec2/dist-types/pagination/GetCapacityManagerMonitoredTagKeysPaginator.d.ts +7 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/pagination/index.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/schemas/schemas_0.d.ts +8 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/EC2.d.ts +55 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/EC2Client.d.ts +12 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/GetCapacityManagerMonitoredTagKeysCommand.d.ts +51 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/GetConsoleScreenshotCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/GetDeclarativePoliciesReportSummaryCommand.d.ts +4 -2
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/ModifyTrafficMirrorFilterNetworkServicesCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/ModifyTrafficMirrorFilterRuleCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/UpdateCapacityManagerMonitoredTagKeysCommand.d.ts +51 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/commands/index.d.ts +2 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/models/enums.d.ts +10 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/models/models_5.d.ts +23 -18
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/models/models_6.d.ts +19 -34
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/models/models_7.d.ts +43 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/pagination/GetCapacityManagerMonitoredTagKeysPaginator.d.ts +11 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/pagination/index.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ec2/dist-types/ts3.4/schemas/schemas_0.d.ts +8 -0
- package/node_modules/@aws-sdk/client-ec2/package.json +36 -36
- package/node_modules/@aws-sdk/client-iam/package.json +35 -35
- package/node_modules/@aws-sdk/client-lambda/dist-cjs/models/errors.js +52 -1
- package/node_modules/@aws-sdk/client-lambda/dist-cjs/schemas/schemas_0.js +29 -8
- package/node_modules/@aws-sdk/client-lambda/dist-es/models/errors.js +48 -0
- package/node_modules/@aws-sdk/client-lambda/dist-es/schemas/schemas_0.js +22 -1
- package/node_modules/@aws-sdk/client-lambda/dist-types/commands/InvokeCommand.d.ts +9 -0
- package/node_modules/@aws-sdk/client-lambda/dist-types/commands/InvokeWithResponseStreamCommand.d.ts +9 -0
- package/node_modules/@aws-sdk/client-lambda/dist-types/models/errors.d.ts +66 -0
- package/node_modules/@aws-sdk/client-lambda/dist-types/models/models_0.d.ts +6 -6
- package/node_modules/@aws-sdk/client-lambda/dist-types/schemas/schemas_0.d.ts +3 -0
- package/node_modules/@aws-sdk/client-lambda/dist-types/ts3.4/models/errors.d.ts +30 -0
- package/node_modules/@aws-sdk/client-lambda/dist-types/ts3.4/schemas/schemas_0.d.ts +3 -0
- package/node_modules/@aws-sdk/client-lambda/package.json +38 -38
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +5 -0
- package/node_modules/@aws-sdk/client-s3/dist-es/models/enums.js +5 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/CreateBucketCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/GetBucketLocationCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-s3/dist-types/models/enums.d.ts +5 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/ts3.4/models/enums.d.ts +5 -0
- package/node_modules/@aws-sdk/client-s3/package.json +50 -50
- package/node_modules/@aws-sdk/client-sns/package.json +33 -33
- package/node_modules/@aws-sdk/client-sqs/dist-cjs/index.js +2 -0
- package/node_modules/@aws-sdk/client-sqs/dist-es/commands/ReceiveMessageCommand.js +2 -0
- package/node_modules/@aws-sdk/client-sqs/package.json +36 -36
- package/node_modules/@aws-sdk/client-ssm/package.json +34 -34
- package/node_modules/@aws-sdk/core/dist-cjs/index.js +17 -0
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +17 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.js +1 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/longPollMiddleware.js +15 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/longPollMiddleware.d.ts +14 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/longPollMiddleware.d.ts +15 -0
- package/node_modules/@aws-sdk/core/package.json +11 -11
- package/node_modules/@aws-sdk/crc64-nvme/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-http/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +14 -14
- package/node_modules/@aws-sdk/credential-provider-login/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +7 -7
- package/node_modules/@aws-sdk/middleware-bucket-endpoint/package.json +5 -5
- package/node_modules/@aws-sdk/middleware-expect-continue/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-flexible-checksums/package.json +10 -10
- package/node_modules/@aws-sdk/middleware-host-header/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-location-constraint/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-logger/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-sdk-ec2/package.json +8 -8
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +11 -11
- package/node_modules/@aws-sdk/middleware-sdk-sqs/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-ssec/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +8 -8
- package/node_modules/@aws-sdk/nested-clients/package.json +32 -32
- package/node_modules/@aws-sdk/region-config-resolver/package.json +5 -5
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +6 -6
- package/node_modules/@aws-sdk/token-providers/package.json +7 -7
- package/node_modules/@aws-sdk/types/package.json +2 -2
- package/node_modules/@aws-sdk/util-endpoints/package.json +5 -5
- package/node_modules/@aws-sdk/util-format-url/package.json +4 -4
- package/node_modules/@aws-sdk/util-user-agent-browser/package.json +3 -3
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +5 -5
- package/node_modules/{strnum → @aws-sdk/xml-builder/node_modules/strnum}/package.json +1 -1
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@smithy/config-resolver/package.json +2 -2
- package/node_modules/@smithy/middleware-retry/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/node_modules/@smithy/util-endpoints/dist-cjs/index.js +154 -61
- package/node_modules/@smithy/util-endpoints/dist-es/bdd/BinaryDecisionDiagram.js +15 -0
- package/node_modules/@smithy/util-endpoints/dist-es/decideEndpoint.js +41 -0
- package/node_modules/@smithy/util-endpoints/dist-es/index.js +2 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/coalesce.js +8 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/index.js +3 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/ite.js +3 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/split.js +13 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/substring.js +1 -1
- package/node_modules/@smithy/util-endpoints/dist-es/utils/endpointFunctions.js +4 -1
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateExpression.js +20 -5
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateTemplate.js +3 -6
- package/node_modules/@smithy/util-endpoints/dist-es/utils/getReferenceValue.js +1 -5
- package/node_modules/@smithy/util-endpoints/dist-types/bdd/BinaryDecisionDiagram.d.ts +22 -0
- package/node_modules/@smithy/util-endpoints/dist-types/decideEndpoint.d.ts +7 -0
- package/node_modules/@smithy/util-endpoints/dist-types/index.d.ts +2 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/coalesce.d.ts +7 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/index.d.ts +3 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/ite.d.ts +6 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/split.d.ts +11 -0
- package/node_modules/@smithy/util-endpoints/dist-types/utils/endpointFunctions.d.ts +4 -0
- package/node_modules/@smithy/util-endpoints/dist-types/utils/getReferenceValue.d.ts +3 -1
- package/node_modules/@smithy/util-endpoints/package.json +1 -1
- package/node_modules/@smithy/util-retry/dist-cjs/index.js +6 -0
- package/node_modules/@smithy/util-retry/dist-es/AdaptiveRetryStrategy.js +3 -0
- package/node_modules/@smithy/util-retry/dist-es/StandardRetryStrategy.js +3 -0
- package/node_modules/@smithy/util-retry/dist-types/AdaptiveRetryStrategy.d.ts +5 -0
- package/node_modules/@smithy/util-retry/dist-types/StandardRetryStrategy.d.ts +5 -0
- package/node_modules/@smithy/util-retry/package.json +1 -1
- package/node_modules/path-expression-matcher/README.md +214 -62
- package/node_modules/path-expression-matcher/lib/pem.cjs +1 -1
- package/node_modules/path-expression-matcher/lib/pem.d.cts +111 -0
- package/node_modules/path-expression-matcher/lib/pem.min.js +1 -1
- package/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -1
- package/node_modules/path-expression-matcher/package.json +1 -1
- package/node_modules/path-expression-matcher/src/Expression.js +2 -2
- package/node_modules/path-expression-matcher/src/ExpressionSet.js +209 -0
- package/node_modules/path-expression-matcher/src/Matcher.js +235 -177
- package/node_modules/path-expression-matcher/src/index.d.ts +199 -194
- package/node_modules/path-expression-matcher/src/index.js +3 -2
- package/package.json +10 -10
- package/node_modules/strnum/.github/SECURITY.md +0 -5
- package/node_modules/strnum/.vscode/launch.json +0 -25
- package/node_modules/strnum/algo.stflow +0 -84
- package/node_modules/strnum/tests/infinity_test.js +0 -18
- package/node_modules/strnum/tests/strnum_test.js +0 -175
- package/node_modules/strnum/tests/temp.js +0 -8
- /package/node_modules/{strnum → @aws-sdk/xml-builder/node_modules/strnum}/CHANGELOG.md +0 -0
- /package/node_modules/{strnum → @aws-sdk/xml-builder/node_modules/strnum}/LICENSE +0 -0
- /package/node_modules/{strnum → @aws-sdk/xml-builder/node_modules/strnum}/README.md +0 -0
- /package/node_modules/{strnum → @aws-sdk/xml-builder/node_modules/strnum}/strnum.js +0 -0
|
@@ -1,54 +1,203 @@
|
|
|
1
|
+
import ExpressionSet from "./ExpressionSet.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MatcherView - A lightweight read-only view over a Matcher's internal state.
|
|
5
|
+
*
|
|
6
|
+
* Created once by Matcher and reused across all callbacks. Holds a direct
|
|
7
|
+
* reference to the parent Matcher so it always reflects current parser state
|
|
8
|
+
* with zero copying or freezing overhead.
|
|
9
|
+
*
|
|
10
|
+
* Users receive this via {@link Matcher#readOnly} or directly from parser
|
|
11
|
+
* callbacks. It exposes all query and matching methods but has no mutation
|
|
12
|
+
* methods — misuse is caught at the TypeScript level rather than at runtime.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const matcher = new Matcher();
|
|
16
|
+
* const view = matcher.readOnly();
|
|
17
|
+
*
|
|
18
|
+
* matcher.push("root", {});
|
|
19
|
+
* view.getCurrentTag(); // "root"
|
|
20
|
+
* view.getDepth(); // 1
|
|
21
|
+
*/
|
|
22
|
+
export class MatcherView {
|
|
23
|
+
/**
|
|
24
|
+
* @param {Matcher} matcher - The parent Matcher instance to read from.
|
|
25
|
+
*/
|
|
26
|
+
constructor(matcher) {
|
|
27
|
+
this._matcher = matcher;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the path separator used by the parent matcher.
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
get separator() {
|
|
35
|
+
return this._matcher.separator;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get current tag name.
|
|
40
|
+
* @returns {string|undefined}
|
|
41
|
+
*/
|
|
42
|
+
getCurrentTag() {
|
|
43
|
+
const path = this._matcher.path;
|
|
44
|
+
return path.length > 0 ? path[path.length - 1].tag : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get current namespace.
|
|
49
|
+
* @returns {string|undefined}
|
|
50
|
+
*/
|
|
51
|
+
getCurrentNamespace() {
|
|
52
|
+
const path = this._matcher.path;
|
|
53
|
+
return path.length > 0 ? path[path.length - 1].namespace : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get current node's attribute value.
|
|
58
|
+
* @param {string} attrName
|
|
59
|
+
* @returns {*}
|
|
60
|
+
*/
|
|
61
|
+
getAttrValue(attrName) {
|
|
62
|
+
const path = this._matcher.path;
|
|
63
|
+
if (path.length === 0) return undefined;
|
|
64
|
+
return path[path.length - 1].values?.[attrName];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if current node has an attribute.
|
|
69
|
+
* @param {string} attrName
|
|
70
|
+
* @returns {boolean}
|
|
71
|
+
*/
|
|
72
|
+
hasAttr(attrName) {
|
|
73
|
+
const path = this._matcher.path;
|
|
74
|
+
if (path.length === 0) return false;
|
|
75
|
+
const current = path[path.length - 1];
|
|
76
|
+
return current.values !== undefined && attrName in current.values;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get current node's sibling position (child index in parent).
|
|
81
|
+
* @returns {number}
|
|
82
|
+
*/
|
|
83
|
+
getPosition() {
|
|
84
|
+
const path = this._matcher.path;
|
|
85
|
+
if (path.length === 0) return -1;
|
|
86
|
+
return path[path.length - 1].position ?? 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get current node's repeat counter (occurrence count of this tag name).
|
|
91
|
+
* @returns {number}
|
|
92
|
+
*/
|
|
93
|
+
getCounter() {
|
|
94
|
+
const path = this._matcher.path;
|
|
95
|
+
if (path.length === 0) return -1;
|
|
96
|
+
return path[path.length - 1].counter ?? 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get current node's sibling index (alias for getPosition).
|
|
101
|
+
* @returns {number}
|
|
102
|
+
* @deprecated Use getPosition() or getCounter() instead
|
|
103
|
+
*/
|
|
104
|
+
getIndex() {
|
|
105
|
+
return this.getPosition();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get current path depth.
|
|
110
|
+
* @returns {number}
|
|
111
|
+
*/
|
|
112
|
+
getDepth() {
|
|
113
|
+
return this._matcher.path.length;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get path as string.
|
|
118
|
+
* @param {string} [separator] - Optional separator (uses default if not provided)
|
|
119
|
+
* @param {boolean} [includeNamespace=true]
|
|
120
|
+
* @returns {string}
|
|
121
|
+
*/
|
|
122
|
+
toString(separator, includeNamespace = true) {
|
|
123
|
+
return this._matcher.toString(separator, includeNamespace);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get path as array of tag names.
|
|
128
|
+
* @returns {string[]}
|
|
129
|
+
*/
|
|
130
|
+
toArray() {
|
|
131
|
+
return this._matcher.path.map(n => n.tag);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Match current path against an Expression.
|
|
136
|
+
* @param {Expression} expression
|
|
137
|
+
* @returns {boolean}
|
|
138
|
+
*/
|
|
139
|
+
matches(expression) {
|
|
140
|
+
return this._matcher.matches(expression);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Match any expression in the given set against the current path.
|
|
145
|
+
* @param {ExpressionSet} exprSet
|
|
146
|
+
* @returns {boolean}
|
|
147
|
+
*/
|
|
148
|
+
matchesAny(exprSet) {
|
|
149
|
+
return exprSet.matchesAny(this._matcher);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
1
153
|
/**
|
|
2
|
-
* Matcher - Tracks current path in XML/JSON tree and matches against Expressions
|
|
3
|
-
*
|
|
154
|
+
* Matcher - Tracks current path in XML/JSON tree and matches against Expressions.
|
|
155
|
+
*
|
|
4
156
|
* The matcher maintains a stack of nodes representing the current path from root to
|
|
5
157
|
* current tag. It only stores attribute values for the current (top) node to minimize
|
|
6
158
|
* memory usage. Sibling tracking is used to auto-calculate position and counter.
|
|
7
|
-
*
|
|
159
|
+
*
|
|
160
|
+
* Use {@link Matcher#readOnly} to obtain a {@link MatcherView} safe to pass to
|
|
161
|
+
* user callbacks — it always reflects current state with no Proxy overhead.
|
|
162
|
+
*
|
|
8
163
|
* @example
|
|
9
164
|
* const matcher = new Matcher();
|
|
10
165
|
* matcher.push("root", {});
|
|
11
166
|
* matcher.push("users", {});
|
|
12
167
|
* matcher.push("user", { id: "123", type: "admin" });
|
|
13
|
-
*
|
|
168
|
+
*
|
|
14
169
|
* const expr = new Expression("root.users.user");
|
|
15
170
|
* matcher.matches(expr); // true
|
|
16
171
|
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Names of methods that mutate Matcher state.
|
|
20
|
-
* Any attempt to call these on a read-only view throws a TypeError.
|
|
21
|
-
* @type {Set<string>}
|
|
22
|
-
*/
|
|
23
|
-
const MUTATING_METHODS = new Set(['push', 'pop', 'reset', 'updateCurrent', 'restore']);
|
|
24
|
-
|
|
25
172
|
export default class Matcher {
|
|
26
173
|
/**
|
|
27
|
-
* Create a new Matcher
|
|
28
|
-
* @param {Object} options
|
|
29
|
-
* @param {string} options.separator - Default path separator
|
|
174
|
+
* Create a new Matcher.
|
|
175
|
+
* @param {Object} [options={}]
|
|
176
|
+
* @param {string} [options.separator='.'] - Default path separator
|
|
30
177
|
*/
|
|
31
178
|
constructor(options = {}) {
|
|
32
179
|
this.separator = options.separator || '.';
|
|
33
180
|
this.path = [];
|
|
34
181
|
this.siblingStacks = [];
|
|
35
|
-
// Each path node: { tag
|
|
182
|
+
// Each path node: { tag, values, position, counter, namespace? }
|
|
36
183
|
// values only present for current (last) node
|
|
37
184
|
// Each siblingStacks entry: Map<tagName, count> tracking occurrences at each level
|
|
185
|
+
this._pathStringCache = null;
|
|
186
|
+
this._view = new MatcherView(this);
|
|
38
187
|
}
|
|
39
188
|
|
|
40
189
|
/**
|
|
41
|
-
* Push a new tag onto the path
|
|
42
|
-
* @param {string} tagName
|
|
43
|
-
* @param {Object} attrValues
|
|
44
|
-
* @param {string} namespace
|
|
190
|
+
* Push a new tag onto the path.
|
|
191
|
+
* @param {string} tagName
|
|
192
|
+
* @param {Object|null} [attrValues=null]
|
|
193
|
+
* @param {string|null} [namespace=null]
|
|
45
194
|
*/
|
|
46
195
|
push(tagName, attrValues = null, namespace = null) {
|
|
47
|
-
this._pathStringCache = null;
|
|
196
|
+
this._pathStringCache = null;
|
|
197
|
+
|
|
48
198
|
// Remove values from previous current node (now becoming ancestor)
|
|
49
199
|
if (this.path.length > 0) {
|
|
50
|
-
|
|
51
|
-
prev.values = undefined;
|
|
200
|
+
this.path[this.path.length - 1].values = undefined;
|
|
52
201
|
}
|
|
53
202
|
|
|
54
203
|
// Get or create sibling tracking for current level
|
|
@@ -81,12 +230,10 @@ export default class Matcher {
|
|
|
81
230
|
counter: counter
|
|
82
231
|
};
|
|
83
232
|
|
|
84
|
-
// Store namespace if provided
|
|
85
233
|
if (namespace !== null && namespace !== undefined) {
|
|
86
234
|
node.namespace = namespace;
|
|
87
235
|
}
|
|
88
236
|
|
|
89
|
-
// Store values only for current node
|
|
90
237
|
if (attrValues !== null && attrValues !== undefined) {
|
|
91
238
|
node.values = attrValues;
|
|
92
239
|
}
|
|
@@ -95,19 +242,15 @@ export default class Matcher {
|
|
|
95
242
|
}
|
|
96
243
|
|
|
97
244
|
/**
|
|
98
|
-
* Pop the last tag from the path
|
|
245
|
+
* Pop the last tag from the path.
|
|
99
246
|
* @returns {Object|undefined} The popped node
|
|
100
247
|
*/
|
|
101
248
|
pop() {
|
|
102
|
-
if (this.path.length === 0)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this._pathStringCache = null; // invalidate
|
|
249
|
+
if (this.path.length === 0) return undefined;
|
|
250
|
+
this._pathStringCache = null;
|
|
251
|
+
|
|
106
252
|
const node = this.path.pop();
|
|
107
253
|
|
|
108
|
-
// Clean up sibling tracking for levels deeper than current
|
|
109
|
-
// After pop, path.length is the new depth
|
|
110
|
-
// We need to clean up siblingStacks[path.length + 1] and beyond
|
|
111
254
|
if (this.siblingStacks.length > this.path.length + 1) {
|
|
112
255
|
this.siblingStacks.length = this.path.length + 1;
|
|
113
256
|
}
|
|
@@ -116,9 +259,9 @@ export default class Matcher {
|
|
|
116
259
|
}
|
|
117
260
|
|
|
118
261
|
/**
|
|
119
|
-
* Update current node's attribute values
|
|
120
|
-
* Useful when attributes are parsed after push
|
|
121
|
-
* @param {Object} attrValues
|
|
262
|
+
* Update current node's attribute values.
|
|
263
|
+
* Useful when attributes are parsed after push.
|
|
264
|
+
* @param {Object} attrValues
|
|
122
265
|
*/
|
|
123
266
|
updateCurrent(attrValues) {
|
|
124
267
|
if (this.path.length > 0) {
|
|
@@ -130,7 +273,7 @@ export default class Matcher {
|
|
|
130
273
|
}
|
|
131
274
|
|
|
132
275
|
/**
|
|
133
|
-
* Get current tag name
|
|
276
|
+
* Get current tag name.
|
|
134
277
|
* @returns {string|undefined}
|
|
135
278
|
*/
|
|
136
279
|
getCurrentTag() {
|
|
@@ -138,7 +281,7 @@ export default class Matcher {
|
|
|
138
281
|
}
|
|
139
282
|
|
|
140
283
|
/**
|
|
141
|
-
* Get current namespace
|
|
284
|
+
* Get current namespace.
|
|
142
285
|
* @returns {string|undefined}
|
|
143
286
|
*/
|
|
144
287
|
getCurrentNamespace() {
|
|
@@ -146,19 +289,18 @@ export default class Matcher {
|
|
|
146
289
|
}
|
|
147
290
|
|
|
148
291
|
/**
|
|
149
|
-
* Get current node's attribute value
|
|
150
|
-
* @param {string} attrName
|
|
151
|
-
* @returns {*}
|
|
292
|
+
* Get current node's attribute value.
|
|
293
|
+
* @param {string} attrName
|
|
294
|
+
* @returns {*}
|
|
152
295
|
*/
|
|
153
296
|
getAttrValue(attrName) {
|
|
154
297
|
if (this.path.length === 0) return undefined;
|
|
155
|
-
|
|
156
|
-
return current.values?.[attrName];
|
|
298
|
+
return this.path[this.path.length - 1].values?.[attrName];
|
|
157
299
|
}
|
|
158
300
|
|
|
159
301
|
/**
|
|
160
|
-
* Check if current node has an attribute
|
|
161
|
-
* @param {string} attrName
|
|
302
|
+
* Check if current node has an attribute.
|
|
303
|
+
* @param {string} attrName
|
|
162
304
|
* @returns {boolean}
|
|
163
305
|
*/
|
|
164
306
|
hasAttr(attrName) {
|
|
@@ -168,7 +310,7 @@ export default class Matcher {
|
|
|
168
310
|
}
|
|
169
311
|
|
|
170
312
|
/**
|
|
171
|
-
* Get current node's sibling position (child index in parent)
|
|
313
|
+
* Get current node's sibling position (child index in parent).
|
|
172
314
|
* @returns {number}
|
|
173
315
|
*/
|
|
174
316
|
getPosition() {
|
|
@@ -177,7 +319,7 @@ export default class Matcher {
|
|
|
177
319
|
}
|
|
178
320
|
|
|
179
321
|
/**
|
|
180
|
-
* Get current node's repeat counter (occurrence count of this tag name)
|
|
322
|
+
* Get current node's repeat counter (occurrence count of this tag name).
|
|
181
323
|
* @returns {number}
|
|
182
324
|
*/
|
|
183
325
|
getCounter() {
|
|
@@ -186,7 +328,7 @@ export default class Matcher {
|
|
|
186
328
|
}
|
|
187
329
|
|
|
188
330
|
/**
|
|
189
|
-
* Get current node's sibling index (alias for getPosition
|
|
331
|
+
* Get current node's sibling index (alias for getPosition).
|
|
190
332
|
* @returns {number}
|
|
191
333
|
* @deprecated Use getPosition() or getCounter() instead
|
|
192
334
|
*/
|
|
@@ -195,7 +337,7 @@ export default class Matcher {
|
|
|
195
337
|
}
|
|
196
338
|
|
|
197
339
|
/**
|
|
198
|
-
* Get current path depth
|
|
340
|
+
* Get current path depth.
|
|
199
341
|
* @returns {number}
|
|
200
342
|
*/
|
|
201
343
|
getDepth() {
|
|
@@ -203,9 +345,9 @@ export default class Matcher {
|
|
|
203
345
|
}
|
|
204
346
|
|
|
205
347
|
/**
|
|
206
|
-
* Get path as string
|
|
207
|
-
* @param {string} separator - Optional separator (uses default if not provided)
|
|
208
|
-
* @param {boolean} includeNamespace
|
|
348
|
+
* Get path as string.
|
|
349
|
+
* @param {string} [separator] - Optional separator (uses default if not provided)
|
|
350
|
+
* @param {boolean} [includeNamespace=true]
|
|
209
351
|
* @returns {string}
|
|
210
352
|
*/
|
|
211
353
|
toString(separator, includeNamespace = true) {
|
|
@@ -213,24 +355,23 @@ export default class Matcher {
|
|
|
213
355
|
const isDefault = (sep === this.separator && includeNamespace === true);
|
|
214
356
|
|
|
215
357
|
if (isDefault) {
|
|
216
|
-
if (this._pathStringCache !== null
|
|
358
|
+
if (this._pathStringCache !== null) {
|
|
217
359
|
return this._pathStringCache;
|
|
218
360
|
}
|
|
219
361
|
const result = this.path.map(n =>
|
|
220
|
-
(
|
|
362
|
+
(n.namespace) ? `${n.namespace}:${n.tag}` : n.tag
|
|
221
363
|
).join(sep);
|
|
222
364
|
this._pathStringCache = result;
|
|
223
365
|
return result;
|
|
224
366
|
}
|
|
225
367
|
|
|
226
|
-
// Non-default separator or includeNamespace=false: don't cache (rare case)
|
|
227
368
|
return this.path.map(n =>
|
|
228
369
|
(includeNamespace && n.namespace) ? `${n.namespace}:${n.tag}` : n.tag
|
|
229
370
|
).join(sep);
|
|
230
371
|
}
|
|
231
372
|
|
|
232
373
|
/**
|
|
233
|
-
* Get path as array of tag names
|
|
374
|
+
* Get path as array of tag names.
|
|
234
375
|
* @returns {string[]}
|
|
235
376
|
*/
|
|
236
377
|
toArray() {
|
|
@@ -238,18 +379,18 @@ export default class Matcher {
|
|
|
238
379
|
}
|
|
239
380
|
|
|
240
381
|
/**
|
|
241
|
-
* Reset the path to empty
|
|
382
|
+
* Reset the path to empty.
|
|
242
383
|
*/
|
|
243
384
|
reset() {
|
|
244
|
-
this._pathStringCache = null;
|
|
385
|
+
this._pathStringCache = null;
|
|
245
386
|
this.path = [];
|
|
246
387
|
this.siblingStacks = [];
|
|
247
388
|
}
|
|
248
389
|
|
|
249
390
|
/**
|
|
250
|
-
* Match current path against an Expression
|
|
251
|
-
* @param {Expression} expression
|
|
252
|
-
* @returns {boolean}
|
|
391
|
+
* Match current path against an Expression.
|
|
392
|
+
* @param {Expression} expression
|
|
393
|
+
* @returns {boolean}
|
|
253
394
|
*/
|
|
254
395
|
matches(expression) {
|
|
255
396
|
const segments = expression.segments;
|
|
@@ -258,32 +399,23 @@ export default class Matcher {
|
|
|
258
399
|
return false;
|
|
259
400
|
}
|
|
260
401
|
|
|
261
|
-
// Handle deep wildcard patterns
|
|
262
402
|
if (expression.hasDeepWildcard()) {
|
|
263
403
|
return this._matchWithDeepWildcard(segments);
|
|
264
404
|
}
|
|
265
405
|
|
|
266
|
-
// Simple path matching (no deep wildcards)
|
|
267
406
|
return this._matchSimple(segments);
|
|
268
407
|
}
|
|
269
408
|
|
|
270
409
|
/**
|
|
271
|
-
* Match simple path (no deep wildcards)
|
|
272
410
|
* @private
|
|
273
411
|
*/
|
|
274
412
|
_matchSimple(segments) {
|
|
275
|
-
// Path must be same length as segments
|
|
276
413
|
if (this.path.length !== segments.length) {
|
|
277
414
|
return false;
|
|
278
415
|
}
|
|
279
416
|
|
|
280
|
-
// Match each segment bottom-to-top
|
|
281
417
|
for (let i = 0; i < segments.length; i++) {
|
|
282
|
-
|
|
283
|
-
const node = this.path[i];
|
|
284
|
-
const isCurrentNode = (i === this.path.length - 1);
|
|
285
|
-
|
|
286
|
-
if (!this._matchSegment(segment, node, isCurrentNode)) {
|
|
418
|
+
if (!this._matchSegment(segments[i], this.path[i], i === this.path.length - 1)) {
|
|
287
419
|
return false;
|
|
288
420
|
}
|
|
289
421
|
}
|
|
@@ -292,32 +424,27 @@ export default class Matcher {
|
|
|
292
424
|
}
|
|
293
425
|
|
|
294
426
|
/**
|
|
295
|
-
* Match path with deep wildcards
|
|
296
427
|
* @private
|
|
297
428
|
*/
|
|
298
429
|
_matchWithDeepWildcard(segments) {
|
|
299
|
-
let pathIdx = this.path.length - 1;
|
|
300
|
-
let segIdx = segments.length - 1;
|
|
430
|
+
let pathIdx = this.path.length - 1;
|
|
431
|
+
let segIdx = segments.length - 1;
|
|
301
432
|
|
|
302
433
|
while (segIdx >= 0 && pathIdx >= 0) {
|
|
303
434
|
const segment = segments[segIdx];
|
|
304
435
|
|
|
305
436
|
if (segment.type === 'deep-wildcard') {
|
|
306
|
-
// ".." matches zero or more levels
|
|
307
437
|
segIdx--;
|
|
308
438
|
|
|
309
439
|
if (segIdx < 0) {
|
|
310
|
-
// Pattern ends with "..", always matches
|
|
311
440
|
return true;
|
|
312
441
|
}
|
|
313
442
|
|
|
314
|
-
// Find where next segment matches in the path
|
|
315
443
|
const nextSeg = segments[segIdx];
|
|
316
444
|
let found = false;
|
|
317
445
|
|
|
318
446
|
for (let i = pathIdx; i >= 0; i--) {
|
|
319
|
-
|
|
320
|
-
if (this._matchSegment(nextSeg, this.path[i], isCurrentNode)) {
|
|
447
|
+
if (this._matchSegment(nextSeg, this.path[i], i === this.path.length - 1)) {
|
|
321
448
|
pathIdx = i - 1;
|
|
322
449
|
segIdx--;
|
|
323
450
|
found = true;
|
|
@@ -329,9 +456,7 @@ export default class Matcher {
|
|
|
329
456
|
return false;
|
|
330
457
|
}
|
|
331
458
|
} else {
|
|
332
|
-
|
|
333
|
-
const isCurrentNode = (pathIdx === this.path.length - 1);
|
|
334
|
-
if (!this._matchSegment(segment, this.path[pathIdx], isCurrentNode)) {
|
|
459
|
+
if (!this._matchSegment(segment, this.path[pathIdx], pathIdx === this.path.length - 1)) {
|
|
335
460
|
return false;
|
|
336
461
|
}
|
|
337
462
|
pathIdx--;
|
|
@@ -339,38 +464,25 @@ export default class Matcher {
|
|
|
339
464
|
}
|
|
340
465
|
}
|
|
341
466
|
|
|
342
|
-
// All segments must be consumed
|
|
343
467
|
return segIdx < 0;
|
|
344
468
|
}
|
|
345
469
|
|
|
346
470
|
/**
|
|
347
|
-
* Match a single segment against a node
|
|
348
471
|
* @private
|
|
349
|
-
* @param {Object} segment - Segment from Expression
|
|
350
|
-
* @param {Object} node - Node from path
|
|
351
|
-
* @param {boolean} isCurrentNode - Whether this is the current (last) node
|
|
352
|
-
* @returns {boolean}
|
|
353
472
|
*/
|
|
354
473
|
_matchSegment(segment, node, isCurrentNode) {
|
|
355
|
-
// Match tag name (* is wildcard)
|
|
356
474
|
if (segment.tag !== '*' && segment.tag !== node.tag) {
|
|
357
475
|
return false;
|
|
358
476
|
}
|
|
359
477
|
|
|
360
|
-
// Match namespace if specified in segment
|
|
361
478
|
if (segment.namespace !== undefined) {
|
|
362
|
-
// Segment has namespace - node must match it
|
|
363
479
|
if (segment.namespace !== '*' && segment.namespace !== node.namespace) {
|
|
364
480
|
return false;
|
|
365
481
|
}
|
|
366
482
|
}
|
|
367
|
-
// If segment has no namespace, it matches nodes with or without namespace
|
|
368
483
|
|
|
369
|
-
// Match attribute name (check if node has this attribute)
|
|
370
|
-
// Can only check for current node since ancestors don't have values
|
|
371
484
|
if (segment.attrName !== undefined) {
|
|
372
485
|
if (!isCurrentNode) {
|
|
373
|
-
// Can't check attributes for ancestor nodes (values not stored)
|
|
374
486
|
return false;
|
|
375
487
|
}
|
|
376
488
|
|
|
@@ -378,20 +490,15 @@ export default class Matcher {
|
|
|
378
490
|
return false;
|
|
379
491
|
}
|
|
380
492
|
|
|
381
|
-
// Match attribute value (only possible for current node)
|
|
382
493
|
if (segment.attrValue !== undefined) {
|
|
383
|
-
|
|
384
|
-
// Both should be strings
|
|
385
|
-
if (String(actualValue) !== String(segment.attrValue)) {
|
|
494
|
+
if (String(node.values[segment.attrName]) !== String(segment.attrValue)) {
|
|
386
495
|
return false;
|
|
387
496
|
}
|
|
388
497
|
}
|
|
389
498
|
}
|
|
390
499
|
|
|
391
|
-
// Match position (only for current node)
|
|
392
500
|
if (segment.position !== undefined) {
|
|
393
501
|
if (!isCurrentNode) {
|
|
394
|
-
// Can't check position for ancestor nodes
|
|
395
502
|
return false;
|
|
396
503
|
}
|
|
397
504
|
|
|
@@ -403,10 +510,8 @@ export default class Matcher {
|
|
|
403
510
|
return false;
|
|
404
511
|
} else if (segment.position === 'even' && counter % 2 !== 0) {
|
|
405
512
|
return false;
|
|
406
|
-
} else if (segment.position === 'nth') {
|
|
407
|
-
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
513
|
+
} else if (segment.position === 'nth' && counter !== segment.positionValue) {
|
|
514
|
+
return false;
|
|
410
515
|
}
|
|
411
516
|
}
|
|
412
517
|
|
|
@@ -414,8 +519,17 @@ export default class Matcher {
|
|
|
414
519
|
}
|
|
415
520
|
|
|
416
521
|
/**
|
|
417
|
-
*
|
|
418
|
-
* @
|
|
522
|
+
* Match any expression in the given set against the current path.
|
|
523
|
+
* @param {ExpressionSet} exprSet
|
|
524
|
+
* @returns {boolean}
|
|
525
|
+
*/
|
|
526
|
+
matchesAny(exprSet) {
|
|
527
|
+
return exprSet.matchesAny(this);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Create a snapshot of current state.
|
|
532
|
+
* @returns {Object}
|
|
419
533
|
*/
|
|
420
534
|
snapshot() {
|
|
421
535
|
return {
|
|
@@ -425,88 +539,32 @@ export default class Matcher {
|
|
|
425
539
|
}
|
|
426
540
|
|
|
427
541
|
/**
|
|
428
|
-
* Restore state from snapshot
|
|
429
|
-
* @param {Object} snapshot
|
|
542
|
+
* Restore state from snapshot.
|
|
543
|
+
* @param {Object} snapshot
|
|
430
544
|
*/
|
|
431
545
|
restore(snapshot) {
|
|
432
|
-
this._pathStringCache = null;
|
|
546
|
+
this._pathStringCache = null;
|
|
433
547
|
this.path = snapshot.path.map(node => ({ ...node }));
|
|
434
548
|
this.siblingStacks = snapshot.siblingStacks.map(map => new Map(map));
|
|
435
549
|
}
|
|
436
550
|
|
|
437
551
|
/**
|
|
438
|
-
* Return
|
|
552
|
+
* Return the read-only {@link MatcherView} for this matcher.
|
|
439
553
|
*
|
|
440
|
-
* The returned
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
* are allowed but the returned arrays/objects are frozen so callers cannot
|
|
444
|
-
* mutate internal state through them either.
|
|
554
|
+
* The same instance is returned on every call — no allocation occurs.
|
|
555
|
+
* It always reflects the current parser state and is safe to pass to
|
|
556
|
+
* user callbacks without risk of accidental mutation.
|
|
445
557
|
*
|
|
446
|
-
* @returns {
|
|
558
|
+
* @returns {MatcherView}
|
|
447
559
|
*
|
|
448
560
|
* @example
|
|
449
|
-
* const
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
* ro.getCurrentTag(); // ✓ works
|
|
455
|
-
* ro.push("child", {}); // ✗ throws TypeError
|
|
456
|
-
* ro.reset(); // ✗ throws TypeError
|
|
561
|
+
* const view = matcher.readOnly();
|
|
562
|
+
* // pass view to callbacks — it stays in sync automatically
|
|
563
|
+
* view.matches(expr); // ✓
|
|
564
|
+
* view.getCurrentTag(); // ✓
|
|
565
|
+
* // view.push(...) // ✗ method does not exist — caught by TypeScript
|
|
457
566
|
*/
|
|
458
567
|
readOnly() {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return new Proxy(self, {
|
|
462
|
-
get(target, prop, receiver) {
|
|
463
|
-
// Block mutating methods
|
|
464
|
-
if (MUTATING_METHODS.has(prop)) {
|
|
465
|
-
return () => {
|
|
466
|
-
throw new TypeError(
|
|
467
|
-
`Cannot call '${prop}' on a read-only Matcher. ` +
|
|
468
|
-
`Obtain a writable instance to mutate state.`
|
|
469
|
-
);
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const value = Reflect.get(target, prop, receiver);
|
|
474
|
-
|
|
475
|
-
// Freeze array/object properties so callers can't mutate internal
|
|
476
|
-
// state through direct property access (e.g. matcher.path.push(...))
|
|
477
|
-
if (prop === 'path' || prop === 'siblingStacks') {
|
|
478
|
-
return Object.freeze(
|
|
479
|
-
Array.isArray(value)
|
|
480
|
-
? value.map(item =>
|
|
481
|
-
item instanceof Map
|
|
482
|
-
? Object.freeze(new Map(item)) // freeze a copy of each Map
|
|
483
|
-
: Object.freeze({ ...item }) // freeze a copy of each node
|
|
484
|
-
)
|
|
485
|
-
: value
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// Bind methods so `this` inside them still refers to the real Matcher
|
|
490
|
-
if (typeof value === 'function') {
|
|
491
|
-
return value.bind(target);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return value;
|
|
495
|
-
},
|
|
496
|
-
|
|
497
|
-
// Prevent any property assignment on the read-only view
|
|
498
|
-
set(_target, prop) {
|
|
499
|
-
throw new TypeError(
|
|
500
|
-
`Cannot set property '${String(prop)}' on a read-only Matcher.`
|
|
501
|
-
);
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
// Prevent property deletion
|
|
505
|
-
deleteProperty(_target, prop) {
|
|
506
|
-
throw new TypeError(
|
|
507
|
-
`Cannot delete property '${String(prop)}' from a read-only Matcher.`
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
});
|
|
568
|
+
return this._view;
|
|
511
569
|
}
|
|
512
570
|
}
|