@featurevisor/core 2.26.1 → 3.0.1
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/CHANGELOG.md +8 -0
- package/coverage/clover.xml +4991 -3130
- package/coverage/coverage-final.json +63 -39
- package/coverage/lcov-report/block-navigation.js +1 -1
- package/coverage/lcov-report/index.html +248 -98
- package/coverage/lcov-report/sorter.js +21 -7
- package/coverage/lcov-report/src/assess-distribution/index.html +116 -0
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +754 -0
- package/coverage/lcov-report/{list → src/benchmark}/index.html +30 -30
- package/coverage/lcov-report/src/benchmark/index.ts.html +793 -0
- package/coverage/lcov-report/{builder → src/builder}/allocator.ts.html +38 -38
- package/coverage/lcov-report/{builder/buildScopedConditions.ts.html → src/builder/applyContextToConditions.ts.html} +80 -65
- package/coverage/lcov-report/{builder/buildScopedDatafile.ts.html → src/builder/applyContextToDatafile.ts.html} +92 -92
- package/coverage/lcov-report/{builder/buildScopedSegments.ts.html → src/builder/applyContextToSegments.ts.html} +103 -67
- package/coverage/lcov-report/{builder → src/builder}/buildDatafile.ts.html +336 -306
- package/coverage/lcov-report/src/builder/buildProject.ts.html +1117 -0
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +256 -0
- package/coverage/lcov-report/{builder → src/builder}/getFeatureRanges.ts.html +22 -22
- package/coverage/lcov-report/{builder → src/builder}/hashes.ts.html +50 -50
- package/coverage/lcov-report/{builder → src/builder}/index.html +114 -84
- package/coverage/lcov-report/{tester/cliFormat.ts.html → src/builder/index.ts.html} +17 -29
- package/coverage/lcov-report/{builder → src/builder}/mutateVariables.ts.html +55 -55
- package/coverage/lcov-report/{builder → src/builder}/mutator.ts.html +118 -118
- package/coverage/lcov-report/{builder → src/builder}/revision.ts.html +15 -15
- package/coverage/lcov-report/{builder → src/builder}/traffic.ts.html +86 -86
- package/coverage/lcov-report/src/cli/cli.ts.html +400 -0
- package/coverage/lcov-report/{tester → src/cli}/index.html +41 -41
- package/coverage/lcov-report/src/cli/plugins.ts.html +214 -0
- package/coverage/lcov-report/{config → src/config}/index.html +31 -31
- package/coverage/lcov-report/{config → src/config}/index.ts.html +12 -12
- package/coverage/lcov-report/{config → src/config}/projectConfig.ts.html +312 -96
- package/coverage/lcov-report/{datasource → src/datasource}/adapter.ts.html +28 -73
- package/coverage/lcov-report/{datasource → src/datasource}/datasource.ts.html +191 -104
- package/coverage/lcov-report/{datasource → src/datasource}/filesystemAdapter.ts.html +233 -635
- package/coverage/lcov-report/{datasource → src/datasource}/index.html +48 -48
- package/coverage/lcov-report/{datasource → src/datasource}/index.ts.html +14 -14
- package/coverage/lcov-report/src/evaluate/index.html +116 -0
- package/coverage/lcov-report/src/evaluate/index.ts.html +814 -0
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +313 -0
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +131 -0
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +307 -0
- package/coverage/lcov-report/src/find-usage/index.html +116 -0
- package/coverage/lcov-report/src/find-usage/index.ts.html +1780 -0
- package/coverage/lcov-report/src/generate-code/index.html +131 -0
- package/coverage/lcov-report/src/generate-code/index.ts.html +403 -0
- package/coverage/lcov-report/{generate-code → src/generate-code}/typescript.ts.html +266 -1361
- package/coverage/lcov-report/{generate-code → src}/index.html +38 -23
- package/coverage/lcov-report/src/info/index.html +116 -0
- package/coverage/lcov-report/src/info/index.ts.html +472 -0
- package/coverage/lcov-report/src/init/index.html +116 -0
- package/coverage/lcov-report/src/init/index.ts.html +280 -0
- package/coverage/lcov-report/{linter → src/linter}/attributeSchema.ts.html +160 -157
- package/coverage/lcov-report/{linter → src/linter}/checkCircularDependency.ts.html +25 -25
- package/coverage/lcov-report/{linter → src/linter}/checkPercentageExceedingSlot.ts.html +42 -42
- package/coverage/lcov-report/{linter → src/linter}/conditionSchema.ts.html +207 -207
- package/coverage/lcov-report/{linter → src/linter}/featureSchema.ts.html +462 -471
- package/coverage/lcov-report/{linter → src/linter}/groupSchema.ts.html +25 -22
- package/coverage/lcov-report/{linter → src/linter}/index.html +129 -99
- package/coverage/lcov-report/src/linter/index.ts.html +88 -0
- package/coverage/lcov-report/{linter → src/linter}/lintProject.ts.html +740 -332
- package/coverage/lcov-report/{linter → src/linter}/mutationNotation.ts.html +130 -130
- package/coverage/lcov-report/{linter → src/linter}/printError.ts.html +27 -27
- package/coverage/lcov-report/{linter → src/linter}/schema.ts.html +153 -150
- package/coverage/lcov-report/{linter → src/linter}/segmentSchema.ts.html +18 -15
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +223 -0
- package/coverage/lcov-report/{linter → src/linter}/testSchema.ts.html +54 -48
- package/coverage/lcov-report/{linter → src/linter}/zodHelpers.ts.html +17 -17
- package/coverage/lcov-report/src/list/index.html +131 -0
- package/coverage/lcov-report/src/list/index.ts.html +2065 -0
- package/coverage/lcov-report/{list → src/list}/matrix.ts.html +43 -58
- package/coverage/lcov-report/src/promoter/index.html +116 -0
- package/coverage/lcov-report/src/promoter/index.ts.html +3883 -0
- package/coverage/lcov-report/src/sets.ts.html +313 -0
- package/coverage/lcov-report/src/targeting.ts.html +403 -0
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +133 -0
- package/coverage/lcov-report/{tester → src/tester}/helpers.ts.html +15 -15
- package/coverage/lcov-report/src/tester/index.html +206 -0
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +187 -0
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +337 -0
- package/coverage/lcov-report/src/tester/testFeature.ts.html +1186 -0
- package/coverage/lcov-report/src/tester/testProject.ts.html +1018 -0
- package/coverage/lcov-report/src/tester/testSegment.ts.html +316 -0
- package/coverage/lcov-report/{utils → src/utils}/extractKeys.ts.html +68 -68
- package/coverage/lcov-report/{utils → src/utils}/git.ts.html +44 -68
- package/coverage/lcov-report/{utils → src/utils}/index.html +44 -44
- package/coverage/lcov-report/{utils → src/utils}/index.ts.html +14 -14
- package/coverage/lcov-report/{utils → src/utils}/pretty.ts.html +20 -20
- package/coverage/lcov.info +10121 -5723
- package/jest.config.js +13 -4
- package/lib/assess-distribution/index.d.ts +1 -1
- package/lib/assess-distribution/index.js +59 -40
- package/lib/assess-distribution/index.js.map +1 -1
- package/lib/benchmark/index.d.ts +8 -5
- package/lib/benchmark/index.js +82 -65
- package/lib/benchmark/index.js.map +1 -1
- package/lib/builder/applyContextToConditions.d.ts +5 -0
- package/lib/builder/{buildScopedConditions.js → applyContextToConditions.js} +19 -14
- package/lib/builder/applyContextToConditions.js.map +1 -0
- package/lib/builder/applyContextToDatafile.d.ts +2 -0
- package/lib/builder/{buildScopedDatafile.js → applyContextToDatafile.js} +26 -26
- package/lib/builder/applyContextToDatafile.js.map +1 -0
- package/lib/builder/applyContextToSegments.d.ts +5 -0
- package/lib/builder/{buildScopedSegments.js → applyContextToSegments.js} +19 -14
- package/lib/builder/applyContextToSegments.js.map +1 -0
- package/lib/builder/buildDatafile.d.ts +9 -6
- package/lib/builder/buildDatafile.js +86 -51
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/builder/buildProject.d.ts +17 -3
- package/lib/builder/buildProject.js +151 -59
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/buildRuntimeDatafiles.d.ts +12 -0
- package/lib/builder/buildRuntimeDatafiles.js +35 -0
- package/lib/builder/buildRuntimeDatafiles.js.map +1 -0
- package/lib/builder/getFeatureRanges.js +34 -1
- package/lib/builder/getFeatureRanges.js.map +1 -1
- package/lib/builder/hashes.js +34 -1
- package/lib/builder/hashes.js.map +1 -1
- package/lib/builder/index.d.ts +0 -1
- package/lib/builder/index.js +0 -1
- package/lib/builder/index.js.map +1 -1
- package/lib/cli/cli.js +0 -4
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/plugins.js +7 -2
- package/lib/cli/plugins.js.map +1 -1
- package/lib/config/projectConfig.d.ts +17 -17
- package/lib/config/projectConfig.js +101 -15
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/datasource/adapter.d.ts +7 -9
- package/lib/datasource/adapter.js +0 -7
- package/lib/datasource/adapter.js.map +1 -1
- package/lib/datasource/datasource.d.ts +15 -5
- package/lib/datasource/datasource.js +37 -9
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/filesystemAdapter.d.ts +4 -10
- package/lib/datasource/filesystemAdapter.js +111 -149
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/evaluate/index.d.ts +1 -7
- package/lib/evaluate/index.js +81 -67
- package/lib/evaluate/index.js.map +1 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js +34 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
- package/lib/find-duplicate-segments/index.js +21 -13
- package/lib/find-duplicate-segments/index.js.map +1 -1
- package/lib/find-usage/index.js +57 -41
- package/lib/find-usage/index.js.map +1 -1
- package/lib/generate-code/index.d.ts +1 -1
- package/lib/generate-code/index.js +64 -21
- package/lib/generate-code/index.js.map +1 -1
- package/lib/generate-code/typescript.d.ts +1 -1
- package/lib/generate-code/typescript.js +59 -333
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/info/index.js +57 -16
- package/lib/info/index.js.map +1 -1
- package/lib/init/index.d.ts +2 -2
- package/lib/init/index.js +39 -3
- package/lib/init/index.js.map +1 -1
- package/lib/linter/attributeSchema.d.ts +1 -0
- package/lib/linter/attributeSchema.js +1 -0
- package/lib/linter/attributeSchema.js.map +1 -1
- package/lib/linter/conditionSchema.js +5 -5
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/featureSchema.d.ts +4 -1
- package/lib/linter/featureSchema.js +15 -13
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/groupSchema.d.ts +1 -0
- package/lib/linter/groupSchema.js +1 -0
- package/lib/linter/groupSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +1 -3
- package/lib/linter/lintProject.js +198 -68
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/schema.js +1 -0
- package/lib/linter/schema.js.map +1 -1
- package/lib/linter/segmentSchema.d.ts +1 -0
- package/lib/linter/segmentSchema.js +1 -0
- package/lib/linter/segmentSchema.js.map +1 -1
- package/lib/linter/targetSchema.d.ts +16 -0
- package/lib/linter/targetSchema.js +40 -0
- package/lib/linter/targetSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +4 -3
- package/lib/linter/testSchema.js +9 -4
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/list/index.d.ts +1 -0
- package/lib/list/index.js +131 -12
- package/lib/list/index.js.map +1 -1
- package/lib/list/matrix.js +3 -7
- package/lib/list/matrix.js.map +1 -1
- package/lib/promoter/index.d.ts +50 -0
- package/lib/promoter/index.js +880 -0
- package/lib/promoter/index.js.map +1 -0
- package/lib/sets.d.ts +11 -0
- package/lib/sets.js +81 -0
- package/lib/sets.js.map +1 -0
- package/lib/targeting.d.ts +14 -0
- package/lib/targeting.js +82 -0
- package/lib/targeting.js.map +1 -0
- package/lib/tester/cliFormat.d.ts +7 -1
- package/lib/tester/cliFormat.js +11 -2
- package/lib/tester/cliFormat.js.map +1 -1
- package/lib/tester/printTestResult.js +2 -2
- package/lib/tester/printTestResult.js.map +1 -1
- package/lib/tester/testFeature.d.ts +0 -1
- package/lib/tester/testFeature.js +8 -25
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +2 -3
- package/lib/tester/testProject.js +93 -86
- package/lib/tester/testProject.js.map +1 -1
- package/lib/tester/testSegment.d.ts +1 -1
- package/lib/tester/testSegment.js +3 -21
- package/lib/tester/testSegment.js.map +1 -1
- package/lib/utils/git.js +45 -19
- package/lib/utils/git.js.map +1 -1
- package/package.json +12 -12
- package/src/assess-distribution/index.ts +72 -52
- package/src/benchmark/index.ts +124 -91
- package/src/builder/{buildScopedConditions.spec.ts → applyContextToConditions.spec.ts} +160 -142
- package/src/builder/{buildScopedConditions.ts → applyContextToConditions.ts} +19 -14
- package/src/builder/{buildScopedDatafile.spec.ts → applyContextToDatafile.spec.ts} +141 -81
- package/src/builder/{buildScopedDatafile.ts → applyContextToDatafile.ts} +33 -33
- package/src/builder/{buildScopedSegments.spec.ts → applyContextToSegments.spec.ts} +171 -151
- package/src/builder/{buildScopedSegments.ts → applyContextToSegments.ts} +26 -14
- package/src/builder/buildDatafile.spec.ts +192 -14
- package/src/builder/buildDatafile.ts +74 -64
- package/src/builder/buildProject.ts +171 -86
- package/src/builder/buildRuntimeDatafiles.ts +57 -0
- package/src/builder/index.ts +0 -1
- package/src/cli/cli.ts +0 -5
- package/src/cli/plugins.ts +7 -2
- package/src/config/projectConfig.spec.ts +171 -8
- package/src/config/projectConfig.ts +100 -28
- package/src/datasource/adapter.ts +8 -23
- package/src/datasource/datasource.ts +50 -21
- package/src/datasource/filesystemAdapter.spec.ts +133 -74
- package/src/datasource/filesystemAdapter.ts +93 -227
- package/src/evaluate/index.ts +109 -97
- package/src/find-duplicate-segments/index.ts +34 -16
- package/src/find-usage/index.ts +89 -44
- package/src/generate-code/index.ts +36 -24
- package/src/generate-code/typescript.spec.ts +106 -0
- package/src/generate-code/typescript.ts +33 -398
- package/src/index.ts +2 -1
- package/src/info/index.ts +72 -16
- package/src/init/index.ts +1 -1
- package/src/linter/attributeSchema.ts +1 -0
- package/src/linter/conditionSchema.spec.ts +23 -3
- package/src/linter/conditionSchema.ts +5 -5
- package/src/linter/featureSchema.spec.ts +107 -18
- package/src/linter/featureSchema.ts +25 -28
- package/src/linter/groupSchema.ts +1 -0
- package/src/linter/lintProject.spec.ts +131 -92
- package/src/linter/lintProject.ts +233 -97
- package/src/linter/schema.ts +1 -0
- package/src/linter/segmentSchema.spec.ts +5 -3
- package/src/linter/segmentSchema.ts +1 -0
- package/src/linter/targetSchema.spec.ts +159 -0
- package/src/linter/targetSchema.ts +46 -0
- package/src/linter/testSchema.spec.ts +70 -5
- package/src/linter/testSchema.ts +12 -10
- package/src/list/index.spec.ts +135 -0
- package/src/list/index.ts +188 -12
- package/src/list/matrix.ts +3 -8
- package/src/promoter/index.spec.ts +617 -0
- package/src/promoter/index.ts +1266 -0
- package/src/sets.ts +76 -0
- package/src/targeting.spec.ts +74 -0
- package/src/targeting.ts +106 -0
- package/src/tester/cliFormat.ts +11 -1
- package/src/tester/printTestResult.ts +12 -3
- package/src/tester/testFeature.ts +10 -36
- package/src/tester/testProject.spec.ts +50 -0
- package/src/tester/testProject.ts +89 -140
- package/src/tester/testSegment.ts +5 -22
- package/src/utils/git.ts +13 -21
- package/tsconfig.cjs.json +5 -1
- package/tsconfig.typecheck.json +9 -0
- package/coverage/lcov-report/builder/convertToV1.ts.html +0 -583
- package/lib/builder/allocator.spec.d.ts +0 -1
- package/lib/builder/allocator.spec.js +0 -85
- package/lib/builder/allocator.spec.js.map +0 -1
- package/lib/builder/buildDatafile.spec.d.ts +0 -1
- package/lib/builder/buildDatafile.spec.js +0 -233
- package/lib/builder/buildDatafile.spec.js.map +0 -1
- package/lib/builder/buildScopedConditions.d.ts +0 -5
- package/lib/builder/buildScopedConditions.js.map +0 -1
- package/lib/builder/buildScopedConditions.spec.d.ts +0 -1
- package/lib/builder/buildScopedConditions.spec.js +0 -2167
- package/lib/builder/buildScopedConditions.spec.js.map +0 -1
- package/lib/builder/buildScopedDatafile.d.ts +0 -2
- package/lib/builder/buildScopedDatafile.js.map +0 -1
- package/lib/builder/buildScopedDatafile.spec.d.ts +0 -1
- package/lib/builder/buildScopedDatafile.spec.js +0 -2277
- package/lib/builder/buildScopedDatafile.spec.js.map +0 -1
- package/lib/builder/buildScopedSegments.d.ts +0 -5
- package/lib/builder/buildScopedSegments.js.map +0 -1
- package/lib/builder/buildScopedSegments.spec.d.ts +0 -1
- package/lib/builder/buildScopedSegments.spec.js +0 -1062
- package/lib/builder/buildScopedSegments.spec.js.map +0 -1
- package/lib/builder/convertToV1.d.ts +0 -10
- package/lib/builder/convertToV1.js +0 -119
- package/lib/builder/convertToV1.js.map +0 -1
- package/lib/builder/mutateVariables.spec.d.ts +0 -1
- package/lib/builder/mutateVariables.spec.js +0 -1074
- package/lib/builder/mutateVariables.spec.js.map +0 -1
- package/lib/builder/mutator.spec.d.ts +0 -1
- package/lib/builder/mutator.spec.js +0 -368
- package/lib/builder/mutator.spec.js.map +0 -1
- package/lib/builder/revision.spec.d.ts +0 -1
- package/lib/builder/revision.spec.js +0 -21
- package/lib/builder/revision.spec.js.map +0 -1
- package/lib/builder/traffic.spec.d.ts +0 -1
- package/lib/builder/traffic.spec.js +0 -872
- package/lib/builder/traffic.spec.js.map +0 -1
- package/lib/config/projectConfig.spec.d.ts +0 -1
- package/lib/config/projectConfig.spec.js +0 -24
- package/lib/config/projectConfig.spec.js.map +0 -1
- package/lib/datasource/filesystemAdapter.spec.d.ts +0 -1
- package/lib/datasource/filesystemAdapter.spec.js +0 -88
- package/lib/datasource/filesystemAdapter.spec.js.map +0 -1
- package/lib/generate-code/typescript.spec.d.ts +0 -1
- package/lib/generate-code/typescript.spec.js +0 -78
- package/lib/generate-code/typescript.spec.js.map +0 -1
- package/lib/linter/attributeSchema.spec.d.ts +0 -1
- package/lib/linter/attributeSchema.spec.js +0 -266
- package/lib/linter/attributeSchema.spec.js.map +0 -1
- package/lib/linter/conditionSchema.spec.d.ts +0 -1
- package/lib/linter/conditionSchema.spec.js +0 -380
- package/lib/linter/conditionSchema.spec.js.map +0 -1
- package/lib/linter/featureSchema.spec.d.ts +0 -1
- package/lib/linter/featureSchema.spec.js +0 -1552
- package/lib/linter/featureSchema.spec.js.map +0 -1
- package/lib/linter/lintProject.spec.d.ts +0 -1
- package/lib/linter/lintProject.spec.js +0 -211
- package/lib/linter/lintProject.spec.js.map +0 -1
- package/lib/linter/mutationNotation.spec.d.ts +0 -1
- package/lib/linter/mutationNotation.spec.js +0 -598
- package/lib/linter/mutationNotation.spec.js.map +0 -1
- package/lib/linter/schema.spec.d.ts +0 -1
- package/lib/linter/schema.spec.js +0 -535
- package/lib/linter/schema.spec.js.map +0 -1
- package/lib/linter/segmentSchema.spec.d.ts +0 -1
- package/lib/linter/segmentSchema.spec.js +0 -303
- package/lib/linter/segmentSchema.spec.js.map +0 -1
- package/lib/linter/testSchema.spec.d.ts +0 -1
- package/lib/linter/testSchema.spec.js +0 -162
- package/lib/linter/testSchema.spec.js.map +0 -1
- package/lib/list/matrix.spec.d.ts +0 -1
- package/lib/list/matrix.spec.js +0 -42
- package/lib/list/matrix.spec.js.map +0 -1
- package/lib/site/exportSite.d.ts +0 -2
- package/lib/site/exportSite.js +0 -30
- package/lib/site/exportSite.js.map +0 -1
- package/lib/site/generateHistory.d.ts +0 -3
- package/lib/site/generateHistory.js +0 -31
- package/lib/site/generateHistory.js.map +0 -1
- package/lib/site/generateSiteSearchIndex.d.ts +0 -4
- package/lib/site/generateSiteSearchIndex.js +0 -195
- package/lib/site/generateSiteSearchIndex.js.map +0 -1
- package/lib/site/getLastModifiedFromHistory.d.ts +0 -2
- package/lib/site/getLastModifiedFromHistory.js +0 -18
- package/lib/site/getLastModifiedFromHistory.js.map +0 -1
- package/lib/site/getOwnerAndRepoFromUrl.d.ts +0 -4
- package/lib/site/getOwnerAndRepoFromUrl.js +0 -20
- package/lib/site/getOwnerAndRepoFromUrl.js.map +0 -1
- package/lib/site/getRelativePaths.d.ts +0 -6
- package/lib/site/getRelativePaths.js +0 -15
- package/lib/site/getRelativePaths.js.map +0 -1
- package/lib/site/getRepoDetails.d.ts +0 -8
- package/lib/site/getRepoDetails.js +0 -48
- package/lib/site/getRepoDetails.js.map +0 -1
- package/lib/site/index.d.ts +0 -2
- package/lib/site/index.js +0 -43
- package/lib/site/index.js.map +0 -1
- package/lib/site/serveSite.d.ts +0 -2
- package/lib/site/serveSite.js +0 -54
- package/lib/site/serveSite.js.map +0 -1
- package/lib/tester/helpers.spec.d.ts +0 -1
- package/lib/tester/helpers.spec.js +0 -115
- package/lib/tester/helpers.spec.js.map +0 -1
- package/src/builder/convertToV1.ts +0 -166
- package/src/site/exportSite.ts +0 -42
- package/src/site/generateHistory.ts +0 -40
- package/src/site/generateSiteSearchIndex.ts +0 -258
- package/src/site/getLastModifiedFromHistory.ts +0 -21
- package/src/site/getOwnerAndRepoFromUrl.ts +0 -17
- package/src/site/getRelativePaths.ts +0 -24
- package/src/site/getRepoDetails.ts +0 -62
- package/src/site/index.ts +0 -46
- package/src/site/serveSite.ts +0 -58
|
@@ -1,1074 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mutateVariables_1 = require("./mutateVariables");
|
|
4
|
-
describe("mutateVariables", function () {
|
|
5
|
-
describe("resolveMutationsForMultipleVariables", function () {
|
|
6
|
-
test("is a function", function () {
|
|
7
|
-
expect(mutateVariables_1.resolveMutationsForMultipleVariables).toBeInstanceOf(Function);
|
|
8
|
-
});
|
|
9
|
-
describe("returns undefined when", function () {
|
|
10
|
-
test("overrides is undefined", function () {
|
|
11
|
-
const schema = {
|
|
12
|
-
foo: { type: "string", defaultValue: "default" },
|
|
13
|
-
};
|
|
14
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)(schema, undefined)).toBeUndefined();
|
|
15
|
-
});
|
|
16
|
-
test("overrides is null", function () {
|
|
17
|
-
const schema = {
|
|
18
|
-
foo: { type: "string", defaultValue: "default" },
|
|
19
|
-
};
|
|
20
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)(schema, null)).toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
test("overrides is empty object", function () {
|
|
23
|
-
const schema = {
|
|
24
|
-
foo: { type: "string", defaultValue: "default" },
|
|
25
|
-
};
|
|
26
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)(schema, {})).toBeUndefined();
|
|
27
|
-
});
|
|
28
|
-
test("variablesSchema is undefined", function () {
|
|
29
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)(undefined, { foo: "bar" })).toBeUndefined();
|
|
30
|
-
});
|
|
31
|
-
test("variablesSchema is empty object", function () {
|
|
32
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)({}, { foo: "bar" })).toBeUndefined();
|
|
33
|
-
});
|
|
34
|
-
test("every override key refers to a variable not in schema", function () {
|
|
35
|
-
const schema = {
|
|
36
|
-
foo: { type: "string", defaultValue: "x" },
|
|
37
|
-
};
|
|
38
|
-
expect((0, mutateVariables_1.resolveMutationsForMultipleVariables)(schema, { bar: "y", baz: "z" })).toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe("returns only overridden variables (not all from schema)", function () {
|
|
42
|
-
test("single override includes only that variable", function () {
|
|
43
|
-
const variablesSchema = {
|
|
44
|
-
foo: { type: "string", defaultValue: "defaultFoo" },
|
|
45
|
-
bar: { type: "string", defaultValue: "defaultBar" },
|
|
46
|
-
baz: { type: "string", defaultValue: "defaultBaz" },
|
|
47
|
-
};
|
|
48
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
49
|
-
bar: "overriddenBar",
|
|
50
|
-
});
|
|
51
|
-
expect(result).toEqual({ bar: "overriddenBar" });
|
|
52
|
-
expect(Object.keys(result).sort()).toEqual(["bar"]);
|
|
53
|
-
});
|
|
54
|
-
test("multiple overrides include only those variables", function () {
|
|
55
|
-
const variablesSchema = {
|
|
56
|
-
a: { type: "string", defaultValue: "a" },
|
|
57
|
-
b: { type: "string", defaultValue: "b" },
|
|
58
|
-
c: { type: "string", defaultValue: "c" },
|
|
59
|
-
};
|
|
60
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
61
|
-
a: "A",
|
|
62
|
-
c: "C",
|
|
63
|
-
});
|
|
64
|
-
expect(result).toEqual({ a: "A", c: "C" });
|
|
65
|
-
expect(Object.keys(result).sort()).toEqual(["a", "c"]);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe("exact key override (whole variable replacement)", function () {
|
|
69
|
-
test("replaces entire value with override", function () {
|
|
70
|
-
const variablesSchema = {
|
|
71
|
-
foo: { type: "object", defaultValue: { a: 1, b: 2 } },
|
|
72
|
-
};
|
|
73
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
74
|
-
foo: { x: 10, y: 20 },
|
|
75
|
-
});
|
|
76
|
-
expect(result).toEqual({ foo: { x: 10, y: 20 } });
|
|
77
|
-
});
|
|
78
|
-
test("replaces string default", function () {
|
|
79
|
-
const variablesSchema = {
|
|
80
|
-
name: { type: "string", defaultValue: "default" },
|
|
81
|
-
};
|
|
82
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { name: "custom" });
|
|
83
|
-
expect(result).toEqual({ name: "custom" });
|
|
84
|
-
});
|
|
85
|
-
test("replaces number default", function () {
|
|
86
|
-
const variablesSchema = {
|
|
87
|
-
count: { type: "integer", defaultValue: 0 },
|
|
88
|
-
};
|
|
89
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { count: 42 });
|
|
90
|
-
expect(result).toEqual({ count: 42 });
|
|
91
|
-
});
|
|
92
|
-
test("replaces array default", function () {
|
|
93
|
-
const variablesSchema = {
|
|
94
|
-
list: { type: "array", defaultValue: [1, 2, 3] },
|
|
95
|
-
};
|
|
96
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { list: [10, 20] });
|
|
97
|
-
expect(result).toEqual({ list: [10, 20] });
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("dot-notation override (mutates default)", function () {
|
|
101
|
-
test("sets nested path on object default", function () {
|
|
102
|
-
const variablesSchema = {
|
|
103
|
-
config: {
|
|
104
|
-
type: "object",
|
|
105
|
-
defaultValue: { a: 1, b: 2, c: 3 },
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
109
|
-
"config.b": 20,
|
|
110
|
-
});
|
|
111
|
-
expect(result).toEqual({ config: { a: 1, b: 20, c: 3 } });
|
|
112
|
-
});
|
|
113
|
-
test("sets deep nested path", function () {
|
|
114
|
-
const variablesSchema = {
|
|
115
|
-
foo: {
|
|
116
|
-
type: "object",
|
|
117
|
-
defaultValue: { level1: { level2: { value: "old" } } },
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
121
|
-
"foo.level1.level2.value": "new",
|
|
122
|
-
});
|
|
123
|
-
expect(result).toEqual({
|
|
124
|
-
foo: { level1: { level2: { value: "new" } } },
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
test("multiple dot-notation overrides for same variable merge", function () {
|
|
128
|
-
const variablesSchema = {
|
|
129
|
-
obj: {
|
|
130
|
-
type: "object",
|
|
131
|
-
defaultValue: { a: 1, b: 2, c: 3 },
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
135
|
-
"obj.a": 10,
|
|
136
|
-
"obj.c": 30,
|
|
137
|
-
});
|
|
138
|
-
expect(result).toEqual({ obj: { a: 10, b: 2, c: 30 } });
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
describe("order of application", function () {
|
|
142
|
-
test("full key then nested: nested wins on that path", function () {
|
|
143
|
-
const variablesSchema = {
|
|
144
|
-
foo: { type: "object", defaultValue: { a: 1, b: 2 } },
|
|
145
|
-
};
|
|
146
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
147
|
-
foo: { a: 100, b: 200 },
|
|
148
|
-
"foo.b": 999,
|
|
149
|
-
});
|
|
150
|
-
expect(result).toEqual({ foo: { a: 100, b: 999 } });
|
|
151
|
-
});
|
|
152
|
-
test("nested then full key: full key applied first (shorter), then nested", function () {
|
|
153
|
-
const variablesSchema = {
|
|
154
|
-
foo: { type: "object", defaultValue: { a: 1, b: 2 } },
|
|
155
|
-
};
|
|
156
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
157
|
-
"foo.a": 10,
|
|
158
|
-
foo: { x: 1 },
|
|
159
|
-
});
|
|
160
|
-
expect(result).toEqual({ foo: { x: 1, a: 10 } });
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
describe("defaultValue handling", function () {
|
|
164
|
-
test("uses clone of defaultValue (does not mutate schema)", function () {
|
|
165
|
-
const defaultValue = { a: 1 };
|
|
166
|
-
const variablesSchema = {
|
|
167
|
-
foo: { type: "object", defaultValue },
|
|
168
|
-
};
|
|
169
|
-
(0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { "foo.a": 2 });
|
|
170
|
-
expect(defaultValue).toEqual({ a: 1 });
|
|
171
|
-
});
|
|
172
|
-
test("variable with undefined defaultValue and nested override leaves value undefined", function () {
|
|
173
|
-
const variablesSchema = {
|
|
174
|
-
foo: { type: "object", defaultValue: undefined },
|
|
175
|
-
};
|
|
176
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
177
|
-
"foo.a": 1,
|
|
178
|
-
});
|
|
179
|
-
expect(result).toEqual({ foo: undefined });
|
|
180
|
-
});
|
|
181
|
-
test("variable with null defaultValue and exact override", function () {
|
|
182
|
-
const variablesSchema = {
|
|
183
|
-
foo: { type: "string", defaultValue: null },
|
|
184
|
-
};
|
|
185
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { foo: "set" });
|
|
186
|
-
expect(result).toEqual({ foo: "set" });
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe("override key not in schema", function () {
|
|
190
|
-
test("ignores unknown variable key (no entry in result)", function () {
|
|
191
|
-
const variablesSchema = {
|
|
192
|
-
foo: { type: "string", defaultValue: "x" },
|
|
193
|
-
};
|
|
194
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
195
|
-
foo: "ok",
|
|
196
|
-
unknownVar: "ignored",
|
|
197
|
-
});
|
|
198
|
-
expect(result).toEqual({ foo: "ok" });
|
|
199
|
-
});
|
|
200
|
-
test("ignores dotted path whose first segment is not in schema", function () {
|
|
201
|
-
const variablesSchema = {
|
|
202
|
-
foo: { type: "string", defaultValue: "x" },
|
|
203
|
-
};
|
|
204
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
205
|
-
"other.deep.path": 1,
|
|
206
|
-
});
|
|
207
|
-
expect(result).toBeUndefined();
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
describe("does not mutate inputs", function () {
|
|
211
|
-
test("overrides object is not mutated", function () {
|
|
212
|
-
const variablesSchema = {
|
|
213
|
-
foo: { type: "object", defaultValue: {} },
|
|
214
|
-
};
|
|
215
|
-
const overrides = { foo: { key: "value" } };
|
|
216
|
-
(0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, overrides);
|
|
217
|
-
expect(overrides.foo).toEqual({ key: "value" });
|
|
218
|
-
});
|
|
219
|
-
test("schema defaultValues are not mutated", function () {
|
|
220
|
-
const defaultValue = { nested: { x: 1 } };
|
|
221
|
-
const variablesSchema = {
|
|
222
|
-
foo: { type: "object", defaultValue },
|
|
223
|
-
};
|
|
224
|
-
(0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { "foo.nested.x": 2 });
|
|
225
|
-
expect(defaultValue).toEqual({ nested: { x: 1 } });
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("multiple variables with dot notation", function () {
|
|
229
|
-
test("resolves each overridden variable independently", function () {
|
|
230
|
-
const variablesSchema = {
|
|
231
|
-
theme: {
|
|
232
|
-
type: "object",
|
|
233
|
-
defaultValue: { primary: "blue", secondary: "gray" },
|
|
234
|
-
},
|
|
235
|
-
count: { type: "integer", defaultValue: 0 },
|
|
236
|
-
};
|
|
237
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
238
|
-
"theme.primary": "red",
|
|
239
|
-
count: 5,
|
|
240
|
-
});
|
|
241
|
-
expect(result).toEqual({
|
|
242
|
-
theme: { primary: "red", secondary: "gray" },
|
|
243
|
-
count: 5,
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
describe("edge cases", function () {
|
|
248
|
-
test("override key with single segment (no dot)", function () {
|
|
249
|
-
const variablesSchema = {
|
|
250
|
-
x: { type: "string", defaultValue: "default" },
|
|
251
|
-
};
|
|
252
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, { x: "y" });
|
|
253
|
-
expect(result).toEqual({ x: "y" });
|
|
254
|
-
});
|
|
255
|
-
test("override key with multiple dots", function () {
|
|
256
|
-
const variablesSchema = {
|
|
257
|
-
a: { type: "object", defaultValue: { b: { c: 0 } } },
|
|
258
|
-
};
|
|
259
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
260
|
-
"a.b.c": 1,
|
|
261
|
-
});
|
|
262
|
-
expect(result).toEqual({ a: { b: { c: 1 } } });
|
|
263
|
-
});
|
|
264
|
-
test("same variable overridden by exact and dotted keys (shorter key applied first)", function () {
|
|
265
|
-
const variablesSchema = {
|
|
266
|
-
v: { type: "object", defaultValue: { p: 1, q: 2 } },
|
|
267
|
-
};
|
|
268
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
269
|
-
"v.p": 10,
|
|
270
|
-
v: { p: 100, q: 200 },
|
|
271
|
-
});
|
|
272
|
-
expect(result).toEqual({ v: { p: 10, q: 200 } });
|
|
273
|
-
});
|
|
274
|
-
test("returns undefined when result is empty (all override keys unknown)", function () {
|
|
275
|
-
const variablesSchema = {
|
|
276
|
-
known: { type: "string", defaultValue: "v" },
|
|
277
|
-
};
|
|
278
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
279
|
-
unknown: "x",
|
|
280
|
-
"another.thing": 1,
|
|
281
|
-
});
|
|
282
|
-
expect(result).toBeUndefined();
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe("complex: deeply nested objects", function () {
|
|
286
|
-
test("object with multiple branches, override one leaf", function () {
|
|
287
|
-
const variablesSchema = {
|
|
288
|
-
root: {
|
|
289
|
-
type: "object",
|
|
290
|
-
defaultValue: {
|
|
291
|
-
left: { a: 1, b: 2 },
|
|
292
|
-
right: { x: 10, y: 20 },
|
|
293
|
-
center: { p: 100, q: 200 },
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
298
|
-
"root.right.y": 99,
|
|
299
|
-
});
|
|
300
|
-
expect(result).toEqual({
|
|
301
|
-
root: {
|
|
302
|
-
left: { a: 1, b: 2 },
|
|
303
|
-
right: { x: 10, y: 99 },
|
|
304
|
-
center: { p: 100, q: 200 },
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
test("override multiple leaves in different branches", function () {
|
|
309
|
-
const variablesSchema = {
|
|
310
|
-
tree: {
|
|
311
|
-
type: "object",
|
|
312
|
-
defaultValue: {
|
|
313
|
-
l: { l: { v: 1 }, r: { v: 2 } },
|
|
314
|
-
r: { l: { v: 3 }, r: { v: 4 } },
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
319
|
-
"tree.l.l.v": 10,
|
|
320
|
-
"tree.r.r.v": 40,
|
|
321
|
-
});
|
|
322
|
-
expect(result).toEqual({
|
|
323
|
-
tree: {
|
|
324
|
-
l: { l: { v: 10 }, r: { v: 2 } },
|
|
325
|
-
r: { l: { v: 3 }, r: { v: 40 } },
|
|
326
|
-
},
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
test("four levels deep with override at each level", function () {
|
|
330
|
-
const variablesSchema = {
|
|
331
|
-
d: {
|
|
332
|
-
type: "object",
|
|
333
|
-
defaultValue: {
|
|
334
|
-
l1: {
|
|
335
|
-
l2: { l3: { l4: "deep" } },
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
};
|
|
340
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
341
|
-
"d.l1.l2.l3.l4": "updated",
|
|
342
|
-
});
|
|
343
|
-
expect(result).toEqual({
|
|
344
|
-
d: {
|
|
345
|
-
l1: {
|
|
346
|
-
l2: { l3: { l4: "updated" } },
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
test("replace whole branch with exact key then override nested under it", function () {
|
|
352
|
-
const variablesSchema = {
|
|
353
|
-
cfg: {
|
|
354
|
-
type: "object",
|
|
355
|
-
defaultValue: {
|
|
356
|
-
api: { url: "old", timeout: 5 },
|
|
357
|
-
ui: { theme: "light" },
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
};
|
|
361
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
362
|
-
cfg: { api: { url: "https://new", timeout: 10 }, ui: { theme: "dark" } },
|
|
363
|
-
"cfg.api.timeout": 30,
|
|
364
|
-
});
|
|
365
|
-
expect(result).toEqual({
|
|
366
|
-
cfg: {
|
|
367
|
-
api: { url: "https://new", timeout: 30 },
|
|
368
|
-
ui: { theme: "dark" },
|
|
369
|
-
},
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
describe("complex: arrays", function () {
|
|
374
|
-
test("override element at index", function () {
|
|
375
|
-
const variablesSchema = {
|
|
376
|
-
list: { type: "array", defaultValue: [10, 20, 30] },
|
|
377
|
-
};
|
|
378
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
379
|
-
"list[1]": 99,
|
|
380
|
-
});
|
|
381
|
-
expect(result).toEqual({ list: [10, 99, 30] });
|
|
382
|
-
});
|
|
383
|
-
test("override first and last index", function () {
|
|
384
|
-
const variablesSchema = {
|
|
385
|
-
arr: { type: "array", defaultValue: ["a", "b", "c", "d"] },
|
|
386
|
-
};
|
|
387
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
388
|
-
"arr[0]": "A",
|
|
389
|
-
"arr[3]": "D",
|
|
390
|
-
});
|
|
391
|
-
expect(result).toEqual({ arr: ["A", "b", "c", "D"] });
|
|
392
|
-
});
|
|
393
|
-
test("array of primitives replaced entirely with exact key", function () {
|
|
394
|
-
const variablesSchema = {
|
|
395
|
-
ids: { type: "array", defaultValue: [1, 2, 3] },
|
|
396
|
-
};
|
|
397
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
398
|
-
ids: [100, 200, 300],
|
|
399
|
-
});
|
|
400
|
-
expect(result).toEqual({ ids: [100, 200, 300] });
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
describe("complex: arrays of objects", function () {
|
|
404
|
-
test("override property of object at index", function () {
|
|
405
|
-
const variablesSchema = {
|
|
406
|
-
items: {
|
|
407
|
-
type: "array",
|
|
408
|
-
defaultValue: [
|
|
409
|
-
{ id: 1, name: "first" },
|
|
410
|
-
{ id: 2, name: "second" },
|
|
411
|
-
{ id: 3, name: "third" },
|
|
412
|
-
],
|
|
413
|
-
},
|
|
414
|
-
};
|
|
415
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
416
|
-
"items[0].name": "First",
|
|
417
|
-
"items[2].id": 30,
|
|
418
|
-
});
|
|
419
|
-
expect(result).toEqual({
|
|
420
|
-
items: [
|
|
421
|
-
{ id: 1, name: "First" },
|
|
422
|
-
{ id: 2, name: "second" },
|
|
423
|
-
{ id: 30, name: "third" },
|
|
424
|
-
],
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
test("override nested property inside object at index", function () {
|
|
428
|
-
const variablesSchema = {
|
|
429
|
-
users: {
|
|
430
|
-
type: "array",
|
|
431
|
-
defaultValue: [
|
|
432
|
-
{ id: 1, profile: { displayName: "Alice", role: "admin" } },
|
|
433
|
-
{ id: 2, profile: { displayName: "Bob", role: "user" } },
|
|
434
|
-
],
|
|
435
|
-
},
|
|
436
|
-
};
|
|
437
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
438
|
-
"users[0].profile.displayName": "Alicia",
|
|
439
|
-
"users[1].profile.role": "editor",
|
|
440
|
-
});
|
|
441
|
-
expect(result).toEqual({
|
|
442
|
-
users: [
|
|
443
|
-
{ id: 1, profile: { displayName: "Alicia", role: "admin" } },
|
|
444
|
-
{ id: 2, profile: { displayName: "Bob", role: "editor" } },
|
|
445
|
-
],
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
test("override multiple properties of same object at index", function () {
|
|
449
|
-
const variablesSchema = {
|
|
450
|
-
rows: {
|
|
451
|
-
type: "array",
|
|
452
|
-
defaultValue: [
|
|
453
|
-
{ a: 1, b: 2, c: 3 },
|
|
454
|
-
{ a: 4, b: 5, c: 6 },
|
|
455
|
-
],
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
459
|
-
"rows[1].a": 40,
|
|
460
|
-
"rows[1].c": 60,
|
|
461
|
-
});
|
|
462
|
-
expect(result).toEqual({
|
|
463
|
-
rows: [
|
|
464
|
-
{ a: 1, b: 2, c: 3 },
|
|
465
|
-
{ a: 40, b: 5, c: 60 },
|
|
466
|
-
],
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
test("replace whole array of objects with exact key", function () {
|
|
470
|
-
const variablesSchema = {
|
|
471
|
-
list: {
|
|
472
|
-
type: "array",
|
|
473
|
-
defaultValue: [{ id: 1 }, { id: 2 }],
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
477
|
-
list: [
|
|
478
|
-
{ id: 10, name: "x" },
|
|
479
|
-
{ id: 20, name: "y" },
|
|
480
|
-
],
|
|
481
|
-
});
|
|
482
|
-
expect(result).toEqual({
|
|
483
|
-
list: [
|
|
484
|
-
{ id: 10, name: "x" },
|
|
485
|
-
{ id: 20, name: "y" },
|
|
486
|
-
],
|
|
487
|
-
});
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
describe("complex: object containing arrays of objects", function () {
|
|
491
|
-
test("config with sections and items", function () {
|
|
492
|
-
const variablesSchema = {
|
|
493
|
-
config: {
|
|
494
|
-
type: "object",
|
|
495
|
-
defaultValue: {
|
|
496
|
-
title: "App",
|
|
497
|
-
sections: [
|
|
498
|
-
{ id: "s1", label: "Section 1", items: [{ name: "a" }, { name: "b" }] },
|
|
499
|
-
{ id: "s2", label: "Section 2", items: [{ name: "c" }] },
|
|
500
|
-
],
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
};
|
|
504
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
505
|
-
"config.title": "My App",
|
|
506
|
-
"config.sections[0].label": "First",
|
|
507
|
-
"config.sections[0].items[1].name": "B",
|
|
508
|
-
"config.sections[1].items[0].name": "C",
|
|
509
|
-
});
|
|
510
|
-
expect(result).toEqual({
|
|
511
|
-
config: {
|
|
512
|
-
title: "My App",
|
|
513
|
-
sections: [
|
|
514
|
-
{ id: "s1", label: "First", items: [{ name: "a" }, { name: "B" }] },
|
|
515
|
-
{ id: "s2", label: "Section 2", items: [{ name: "C" }] },
|
|
516
|
-
],
|
|
517
|
-
},
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
test("feature flags style: rules array with variables", function () {
|
|
521
|
-
const variablesSchema = {
|
|
522
|
-
payload: {
|
|
523
|
-
type: "object",
|
|
524
|
-
defaultValue: {
|
|
525
|
-
enabled: true,
|
|
526
|
-
rules: [
|
|
527
|
-
{ id: "r1", percentage: 50, config: { theme: "light", size: "md" } },
|
|
528
|
-
{ id: "r2", percentage: 50, config: { theme: "dark", size: "sm" } },
|
|
529
|
-
],
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
};
|
|
533
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
534
|
-
"payload.rules[0].config.theme": "blue",
|
|
535
|
-
"payload.rules[1].percentage": 100,
|
|
536
|
-
});
|
|
537
|
-
expect(result).toEqual({
|
|
538
|
-
payload: {
|
|
539
|
-
enabled: true,
|
|
540
|
-
rules: [
|
|
541
|
-
{ id: "r1", percentage: 50, config: { theme: "blue", size: "md" } },
|
|
542
|
-
{ id: "r2", percentage: 100, config: { theme: "dark", size: "sm" } },
|
|
543
|
-
],
|
|
544
|
-
},
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
describe("complex: multiple variables with mixed structures", function () {
|
|
549
|
-
test("two variables: one nested object, one array of objects", function () {
|
|
550
|
-
const variablesSchema = {
|
|
551
|
-
settings: {
|
|
552
|
-
type: "object",
|
|
553
|
-
defaultValue: {
|
|
554
|
-
theme: "light",
|
|
555
|
-
layout: { sidebar: true, width: 240 },
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
items: {
|
|
559
|
-
type: "array",
|
|
560
|
-
defaultValue: [
|
|
561
|
-
{ id: 1, label: "One" },
|
|
562
|
-
{ id: 2, label: "Two" },
|
|
563
|
-
],
|
|
564
|
-
},
|
|
565
|
-
};
|
|
566
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
567
|
-
"settings.layout.width": 320,
|
|
568
|
-
"items[1].label": "Two Updated",
|
|
569
|
-
});
|
|
570
|
-
expect(result).toEqual({
|
|
571
|
-
settings: {
|
|
572
|
-
theme: "light",
|
|
573
|
-
layout: { sidebar: true, width: 320 },
|
|
574
|
-
},
|
|
575
|
-
items: [
|
|
576
|
-
{ id: 1, label: "One" },
|
|
577
|
-
{ id: 2, label: "Two Updated" },
|
|
578
|
-
],
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
test("three variables overridden with different depth", function () {
|
|
582
|
-
const variablesSchema = {
|
|
583
|
-
flat: { type: "string", defaultValue: "v1" },
|
|
584
|
-
nested: {
|
|
585
|
-
type: "object",
|
|
586
|
-
defaultValue: { a: { b: "old" } },
|
|
587
|
-
},
|
|
588
|
-
list: { type: "array", defaultValue: [{ x: 1 }, { x: 2 }] },
|
|
589
|
-
};
|
|
590
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
591
|
-
flat: "V1",
|
|
592
|
-
"nested.a.b": "new",
|
|
593
|
-
"list[0].x": 10,
|
|
594
|
-
});
|
|
595
|
-
expect(result).toEqual({
|
|
596
|
-
flat: "V1",
|
|
597
|
-
nested: { a: { b: "new" } },
|
|
598
|
-
list: [{ x: 10 }, { x: 2 }],
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
describe("complex: edge cases for arrays and nesting", function () {
|
|
603
|
-
test("empty array default, override index (mutator creates/updates)", function () {
|
|
604
|
-
const variablesSchema = {
|
|
605
|
-
arr: { type: "array", defaultValue: [] },
|
|
606
|
-
};
|
|
607
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
608
|
-
"arr[0]": "first",
|
|
609
|
-
});
|
|
610
|
-
expect(result).toEqual({ arr: ["first"] });
|
|
611
|
-
});
|
|
612
|
-
test("object with empty array property, override inside array", function () {
|
|
613
|
-
const variablesSchema = {
|
|
614
|
-
data: {
|
|
615
|
-
type: "object",
|
|
616
|
-
defaultValue: { tags: [] },
|
|
617
|
-
},
|
|
618
|
-
};
|
|
619
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
620
|
-
"data.tags[0]": "new-tag",
|
|
621
|
-
});
|
|
622
|
-
expect(result).toEqual({ data: { tags: ["new-tag"] } });
|
|
623
|
-
});
|
|
624
|
-
test("array of objects with nested array", function () {
|
|
625
|
-
const variablesSchema = {
|
|
626
|
-
groups: {
|
|
627
|
-
type: "array",
|
|
628
|
-
defaultValue: [
|
|
629
|
-
{ name: "G1", ids: [1, 2, 3] },
|
|
630
|
-
{ name: "G2", ids: [4, 5] },
|
|
631
|
-
],
|
|
632
|
-
},
|
|
633
|
-
};
|
|
634
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
635
|
-
"groups[0].ids[1]": 20,
|
|
636
|
-
"groups[1].name": "Group 2",
|
|
637
|
-
});
|
|
638
|
-
expect(result).toEqual({
|
|
639
|
-
groups: [
|
|
640
|
-
{ name: "G1", ids: [1, 20, 3] },
|
|
641
|
-
{ name: "Group 2", ids: [4, 5] },
|
|
642
|
-
],
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
test("deep chain: object with array of objects with nested object", function () {
|
|
646
|
-
const variablesSchema = {
|
|
647
|
-
root: {
|
|
648
|
-
type: "object",
|
|
649
|
-
defaultValue: {
|
|
650
|
-
items: [
|
|
651
|
-
{ id: 1, meta: { count: 0, label: "a" } },
|
|
652
|
-
{ id: 2, meta: { count: 0, label: "b" } },
|
|
653
|
-
],
|
|
654
|
-
},
|
|
655
|
-
},
|
|
656
|
-
};
|
|
657
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
658
|
-
"root.items[0].meta.count": 5,
|
|
659
|
-
"root.items[1].meta.label": "B",
|
|
660
|
-
});
|
|
661
|
-
expect(result).toEqual({
|
|
662
|
-
root: {
|
|
663
|
-
items: [
|
|
664
|
-
{ id: 1, meta: { count: 5, label: "a" } },
|
|
665
|
-
{ id: 2, meta: { count: 0, label: "B" } },
|
|
666
|
-
],
|
|
667
|
-
},
|
|
668
|
-
});
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
describe("complex: many overrides on single variable", function () {
|
|
672
|
-
test("single variable with 5+ dotted overrides", function () {
|
|
673
|
-
const variablesSchema = {
|
|
674
|
-
state: {
|
|
675
|
-
type: "object",
|
|
676
|
-
defaultValue: {
|
|
677
|
-
a: 1,
|
|
678
|
-
b: 2,
|
|
679
|
-
c: 3,
|
|
680
|
-
d: 4,
|
|
681
|
-
e: 5,
|
|
682
|
-
f: 6,
|
|
683
|
-
},
|
|
684
|
-
},
|
|
685
|
-
};
|
|
686
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
687
|
-
"state.a": 10,
|
|
688
|
-
"state.c": 30,
|
|
689
|
-
"state.e": 50,
|
|
690
|
-
});
|
|
691
|
-
expect(result).toEqual({
|
|
692
|
-
state: { a: 10, b: 2, c: 30, d: 4, e: 50, f: 6 },
|
|
693
|
-
});
|
|
694
|
-
});
|
|
695
|
-
test("single variable: mix of exact key and dotted overrides (order by length)", function () {
|
|
696
|
-
const variablesSchema = {
|
|
697
|
-
v: {
|
|
698
|
-
type: "object",
|
|
699
|
-
defaultValue: { x: 0, y: 0 },
|
|
700
|
-
},
|
|
701
|
-
};
|
|
702
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
703
|
-
"v.x": 1,
|
|
704
|
-
v: { x: 100, y: 200, z: 300 },
|
|
705
|
-
"v.y": 2,
|
|
706
|
-
});
|
|
707
|
-
expect(result).toEqual({ v: { x: 1, y: 2, z: 300 } });
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
describe("complex: schema with multiple variables, only some overridden", function () {
|
|
711
|
-
test("six variables in schema, override two with complex paths", function () {
|
|
712
|
-
const variablesSchema = {
|
|
713
|
-
a: { type: "string", defaultValue: "a" },
|
|
714
|
-
b: { type: "object", defaultValue: { b1: 1, b2: 2 } },
|
|
715
|
-
c: { type: "array", defaultValue: [1, 2, 3] },
|
|
716
|
-
d: {
|
|
717
|
-
type: "object",
|
|
718
|
-
defaultValue: { nested: { value: "d" } },
|
|
719
|
-
},
|
|
720
|
-
e: {
|
|
721
|
-
type: "array",
|
|
722
|
-
defaultValue: [
|
|
723
|
-
{ id: 1, name: "e1" },
|
|
724
|
-
{ id: 2, name: "e2" },
|
|
725
|
-
],
|
|
726
|
-
},
|
|
727
|
-
f: { type: "integer", defaultValue: 0 },
|
|
728
|
-
};
|
|
729
|
-
const result = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variablesSchema, {
|
|
730
|
-
"b.b2": 20,
|
|
731
|
-
"d.nested.value": "D",
|
|
732
|
-
"e[0].name": "E1",
|
|
733
|
-
});
|
|
734
|
-
expect(result).toEqual({
|
|
735
|
-
b: { b1: 1, b2: 20 },
|
|
736
|
-
d: { nested: { value: "D" } },
|
|
737
|
-
e: [
|
|
738
|
-
{ id: 1, name: "E1" },
|
|
739
|
-
{ id: 2, name: "e2" },
|
|
740
|
-
],
|
|
741
|
-
});
|
|
742
|
-
expect(Object.keys(result).sort()).toEqual(["b", "d", "e"]);
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
describe("resolveMutationsForSingleVariable", function () {
|
|
747
|
-
test("is a function", function () {
|
|
748
|
-
expect(mutateVariables_1.resolveMutationsForSingleVariable).toBeInstanceOf(Function);
|
|
749
|
-
});
|
|
750
|
-
describe("returns overrideValue unchanged when", function () {
|
|
751
|
-
test("variablesSchema is undefined", function () {
|
|
752
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(undefined, "foo", "bar")).toBe("bar");
|
|
753
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(undefined, "foo", { a: 1 })).toEqual({ a: 1 });
|
|
754
|
-
});
|
|
755
|
-
test("variablesSchema is empty (no variableKey)", function () {
|
|
756
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)({}, "foo", "bar")).toBe("bar");
|
|
757
|
-
});
|
|
758
|
-
test("variableKey is not in variablesSchema", function () {
|
|
759
|
-
const schema = {
|
|
760
|
-
bar: { type: "string", defaultValue: "x" },
|
|
761
|
-
};
|
|
762
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", "value")).toBe("value");
|
|
763
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", { nested: 1 })).toEqual({
|
|
764
|
-
nested: 1,
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
test("overrideValue is null", function () {
|
|
768
|
-
const schema = {
|
|
769
|
-
foo: { type: "string", defaultValue: "default" },
|
|
770
|
-
};
|
|
771
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", null)).toBeNull();
|
|
772
|
-
});
|
|
773
|
-
test("overrideValue is undefined", function () {
|
|
774
|
-
const schema = {
|
|
775
|
-
foo: { type: "string", defaultValue: "default" },
|
|
776
|
-
};
|
|
777
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", undefined)).toBeUndefined();
|
|
778
|
-
});
|
|
779
|
-
test("overrideValue is a string (full replacement)", function () {
|
|
780
|
-
const schema = {
|
|
781
|
-
name: { type: "string", defaultValue: "default" },
|
|
782
|
-
};
|
|
783
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "name", "custom")).toBe("custom");
|
|
784
|
-
});
|
|
785
|
-
test("overrideValue is a number (full replacement)", function () {
|
|
786
|
-
const schema = {
|
|
787
|
-
count: { type: "integer", defaultValue: 0 },
|
|
788
|
-
};
|
|
789
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "count", 42)).toBe(42);
|
|
790
|
-
});
|
|
791
|
-
test("overrideValue is a boolean (full replacement)", function () {
|
|
792
|
-
const schema = {
|
|
793
|
-
flag: { type: "boolean", defaultValue: false },
|
|
794
|
-
};
|
|
795
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "flag", true)).toBe(true);
|
|
796
|
-
});
|
|
797
|
-
test("overrideValue is an array (full replacement, not path map)", function () {
|
|
798
|
-
const schema = {
|
|
799
|
-
list: { type: "array", defaultValue: [1, 2, 3] },
|
|
800
|
-
};
|
|
801
|
-
const arr = [10, 20];
|
|
802
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "list", arr)).toEqual([10, 20]);
|
|
803
|
-
expect((0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "list", [])).toEqual([]);
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
describe("plain object as path map (merge with default)", function () {
|
|
807
|
-
test("single path key merges with default", function () {
|
|
808
|
-
const schema = {
|
|
809
|
-
theme: {
|
|
810
|
-
type: "object",
|
|
811
|
-
defaultValue: { primary: "blue", secondary: "gray" },
|
|
812
|
-
},
|
|
813
|
-
};
|
|
814
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "theme", {
|
|
815
|
-
primary: "red",
|
|
816
|
-
});
|
|
817
|
-
expect(result).toEqual({ primary: "red", secondary: "gray" });
|
|
818
|
-
});
|
|
819
|
-
test("multiple path keys merge with default", function () {
|
|
820
|
-
const schema = {
|
|
821
|
-
config: {
|
|
822
|
-
type: "object",
|
|
823
|
-
defaultValue: { a: 1, b: 2, c: 3 },
|
|
824
|
-
},
|
|
825
|
-
};
|
|
826
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "config", {
|
|
827
|
-
a: 10,
|
|
828
|
-
c: 30,
|
|
829
|
-
});
|
|
830
|
-
expect(result).toEqual({ a: 10, b: 2, c: 30 });
|
|
831
|
-
});
|
|
832
|
-
test("nested path in path map", function () {
|
|
833
|
-
const schema = {
|
|
834
|
-
obj: {
|
|
835
|
-
type: "object",
|
|
836
|
-
defaultValue: { level1: { level2: { v: "old" } } },
|
|
837
|
-
},
|
|
838
|
-
};
|
|
839
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "obj", {
|
|
840
|
-
"level1.level2.v": "new",
|
|
841
|
-
});
|
|
842
|
-
expect(result).toEqual({ level1: { level2: { v: "new" } } });
|
|
843
|
-
});
|
|
844
|
-
test("exact variableKey key in path map replaces entire value", function () {
|
|
845
|
-
const schema = {
|
|
846
|
-
theme: {
|
|
847
|
-
type: "object",
|
|
848
|
-
defaultValue: { primary: "blue", secondary: "gray" },
|
|
849
|
-
},
|
|
850
|
-
};
|
|
851
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "theme", {
|
|
852
|
-
theme: { primary: "red", accent: "yellow" },
|
|
853
|
-
});
|
|
854
|
-
expect(result).toEqual({ primary: "red", accent: "yellow" });
|
|
855
|
-
});
|
|
856
|
-
test("variableKey key and path keys: full value applied first then paths (order)", function () {
|
|
857
|
-
const schema = {
|
|
858
|
-
v: {
|
|
859
|
-
type: "object",
|
|
860
|
-
defaultValue: { a: 1, b: 2 },
|
|
861
|
-
},
|
|
862
|
-
};
|
|
863
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "v", {
|
|
864
|
-
v: { a: 100, b: 200 },
|
|
865
|
-
b: 999,
|
|
866
|
-
});
|
|
867
|
-
expect(result).toEqual({ a: 100, b: 999 });
|
|
868
|
-
});
|
|
869
|
-
test("array index in path map", function () {
|
|
870
|
-
const schema = {
|
|
871
|
-
items: {
|
|
872
|
-
type: "array",
|
|
873
|
-
defaultValue: [
|
|
874
|
-
{ id: 1, name: "a" },
|
|
875
|
-
{ id: 2, name: "b" },
|
|
876
|
-
],
|
|
877
|
-
},
|
|
878
|
-
};
|
|
879
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "items", {
|
|
880
|
-
"[0].name": "A",
|
|
881
|
-
"[1].id": 20,
|
|
882
|
-
});
|
|
883
|
-
expect(result).toEqual([
|
|
884
|
-
{ id: 1, name: "A" },
|
|
885
|
-
{ id: 20, name: "b" },
|
|
886
|
-
]);
|
|
887
|
-
});
|
|
888
|
-
test("deep path and array index", function () {
|
|
889
|
-
const schema = {
|
|
890
|
-
data: {
|
|
891
|
-
type: "object",
|
|
892
|
-
defaultValue: {
|
|
893
|
-
list: [{ x: 1 }, { x: 2 }],
|
|
894
|
-
},
|
|
895
|
-
},
|
|
896
|
-
};
|
|
897
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "data", {
|
|
898
|
-
"list[0].x": 10,
|
|
899
|
-
});
|
|
900
|
-
expect(result).toEqual({
|
|
901
|
-
list: [{ x: 10 }, { x: 2 }],
|
|
902
|
-
});
|
|
903
|
-
});
|
|
904
|
-
test("empty path map returns default merged (no overrides)", function () {
|
|
905
|
-
const schema = {
|
|
906
|
-
foo: { type: "object", defaultValue: { a: 1 } },
|
|
907
|
-
};
|
|
908
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", {});
|
|
909
|
-
expect(result).toEqual({});
|
|
910
|
-
});
|
|
911
|
-
test("uses provided baseValue instead of defaultValue for path mutations", function () {
|
|
912
|
-
const schema = {
|
|
913
|
-
cfg: {
|
|
914
|
-
type: "object",
|
|
915
|
-
defaultValue: { source: "default", nested: { value: 1 } },
|
|
916
|
-
},
|
|
917
|
-
};
|
|
918
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "cfg", {
|
|
919
|
-
"nested.value": 2,
|
|
920
|
-
}, { source: "rule", nested: { value: 10 }, extra: true });
|
|
921
|
-
expect(result).toEqual({
|
|
922
|
-
source: "rule",
|
|
923
|
-
nested: { value: 2 },
|
|
924
|
-
extra: true,
|
|
925
|
-
});
|
|
926
|
-
});
|
|
927
|
-
test("baseValue with full replacement key still applies replacement first", function () {
|
|
928
|
-
const schema = {
|
|
929
|
-
cfg: {
|
|
930
|
-
type: "object",
|
|
931
|
-
defaultValue: { a: 1, b: 2 },
|
|
932
|
-
},
|
|
933
|
-
};
|
|
934
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "cfg", {
|
|
935
|
-
cfg: { a: 100, c: 300 },
|
|
936
|
-
c: 999,
|
|
937
|
-
}, { a: 10, b: 20 });
|
|
938
|
-
expect(result).toEqual({ a: 100, c: 999 });
|
|
939
|
-
});
|
|
940
|
-
});
|
|
941
|
-
describe("does not mutate input", function () {
|
|
942
|
-
test("overrideValue object is not mutated", function () {
|
|
943
|
-
const schema = {
|
|
944
|
-
foo: { type: "object", defaultValue: {} },
|
|
945
|
-
};
|
|
946
|
-
const pathMap = { a: 1, b: 2 };
|
|
947
|
-
(0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", pathMap);
|
|
948
|
-
expect(pathMap).toEqual({ a: 1, b: 2 });
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
describe("edge cases", function () {
|
|
952
|
-
test("variableKey with same name as path segment", function () {
|
|
953
|
-
const schema = {
|
|
954
|
-
theme: {
|
|
955
|
-
type: "object",
|
|
956
|
-
defaultValue: { theme: "light", color: "white" },
|
|
957
|
-
},
|
|
958
|
-
};
|
|
959
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "theme", {
|
|
960
|
-
color: "black",
|
|
961
|
-
});
|
|
962
|
-
expect(result).toEqual({ theme: "light", color: "black" });
|
|
963
|
-
});
|
|
964
|
-
test("multiple variables in schema, only one resolved", function () {
|
|
965
|
-
const schema = {
|
|
966
|
-
a: { type: "object", defaultValue: { x: 1 } },
|
|
967
|
-
b: { type: "object", defaultValue: { y: 2 } },
|
|
968
|
-
};
|
|
969
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "a", {
|
|
970
|
-
x: 10,
|
|
971
|
-
});
|
|
972
|
-
expect(result).toEqual({ x: 10 });
|
|
973
|
-
});
|
|
974
|
-
test("path map with only variableKey key (full replacement)", function () {
|
|
975
|
-
const schema = {
|
|
976
|
-
foo: { type: "object", defaultValue: { a: 1, b: 2 } },
|
|
977
|
-
};
|
|
978
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", {
|
|
979
|
-
foo: { x: 1 },
|
|
980
|
-
});
|
|
981
|
-
expect(result).toEqual({ x: 1 });
|
|
982
|
-
});
|
|
983
|
-
test("primitive default with path map (path overwrites)", function () {
|
|
984
|
-
const schema = {
|
|
985
|
-
value: { type: "string", defaultValue: "default" },
|
|
986
|
-
};
|
|
987
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "value", {
|
|
988
|
-
value: "overridden",
|
|
989
|
-
});
|
|
990
|
-
expect(result).toEqual("overridden");
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
describe("complex: object path maps", function () {
|
|
994
|
-
test("path map with three-level nested path", function () {
|
|
995
|
-
const schema = {
|
|
996
|
-
cfg: {
|
|
997
|
-
type: "object",
|
|
998
|
-
defaultValue: { a: { b: { c: 0 } } },
|
|
999
|
-
},
|
|
1000
|
-
};
|
|
1001
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "cfg", {
|
|
1002
|
-
"a.b.c": 1,
|
|
1003
|
-
});
|
|
1004
|
-
expect(result).toEqual({ a: { b: { c: 1 } } });
|
|
1005
|
-
});
|
|
1006
|
-
test("path map with array index then property", function () {
|
|
1007
|
-
const schema = {
|
|
1008
|
-
rows: {
|
|
1009
|
-
type: "array",
|
|
1010
|
-
defaultValue: [
|
|
1011
|
-
{ id: 1, label: "a" },
|
|
1012
|
-
{ id: 2, label: "b" },
|
|
1013
|
-
],
|
|
1014
|
-
},
|
|
1015
|
-
};
|
|
1016
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "rows", {
|
|
1017
|
-
"[0].label": "A",
|
|
1018
|
-
"[1].id": 20,
|
|
1019
|
-
});
|
|
1020
|
-
expect(result).toEqual([
|
|
1021
|
-
{ id: 1, label: "A" },
|
|
1022
|
-
{ id: 20, label: "b" },
|
|
1023
|
-
]);
|
|
1024
|
-
});
|
|
1025
|
-
test("path map full replacement then path (order: full first)", function () {
|
|
1026
|
-
const schema = {
|
|
1027
|
-
v: {
|
|
1028
|
-
type: "object",
|
|
1029
|
-
defaultValue: { x: 0, y: 0 },
|
|
1030
|
-
},
|
|
1031
|
-
};
|
|
1032
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "v", {
|
|
1033
|
-
v: { x: 1, y: 2, z: 3 },
|
|
1034
|
-
y: 20,
|
|
1035
|
-
});
|
|
1036
|
-
expect(result).toEqual({ x: 1, y: 20, z: 3 });
|
|
1037
|
-
});
|
|
1038
|
-
test("path map with mixed path styles", function () {
|
|
1039
|
-
const schema = {
|
|
1040
|
-
data: {
|
|
1041
|
-
type: "object",
|
|
1042
|
-
defaultValue: { count: 0, nested: { value: "old" } },
|
|
1043
|
-
},
|
|
1044
|
-
};
|
|
1045
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "data", {
|
|
1046
|
-
count: 5,
|
|
1047
|
-
"nested.value": "new",
|
|
1048
|
-
});
|
|
1049
|
-
expect(result).toEqual({ count: 5, nested: { value: "new" } });
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
describe("schema default handling", function () {
|
|
1053
|
-
test("defaultValue null with path map leaves value undefined (mutator cannot mutate null)", function () {
|
|
1054
|
-
const schema = {
|
|
1055
|
-
foo: { type: "object", defaultValue: null },
|
|
1056
|
-
};
|
|
1057
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", {
|
|
1058
|
-
a: 1,
|
|
1059
|
-
});
|
|
1060
|
-
expect(result).toBeUndefined();
|
|
1061
|
-
});
|
|
1062
|
-
test("defaultValue undefined with path map leaves value undefined (mutator cannot mutate undefined)", function () {
|
|
1063
|
-
const schema = {
|
|
1064
|
-
foo: { type: "object", defaultValue: undefined },
|
|
1065
|
-
};
|
|
1066
|
-
const result = (0, mutateVariables_1.resolveMutationsForSingleVariable)(schema, "foo", {
|
|
1067
|
-
a: 1,
|
|
1068
|
-
});
|
|
1069
|
-
expect(result).toBeUndefined();
|
|
1070
|
-
});
|
|
1071
|
-
});
|
|
1072
|
-
});
|
|
1073
|
-
});
|
|
1074
|
-
//# sourceMappingURL=mutateVariables.spec.js.map
|