@azure-tools/rlc-common
Advanced tools
Comparing version 1.0.0-alpha.2.20221028.1 to 1.0.0-alpha.2.20221031.1
@@ -10,3 +10,3 @@ { | ||
"packages/rlc-common/src/buildIndexFile.ts": "51d58678165108fc34e3e3a9fa23e6ec1f7be7a1", | ||
"packages/rlc-common/src/buildIsUnexpectedHelper.ts": "a082e70dc1360a141c8427a064bc23586a6af4ae", | ||
"packages/rlc-common/src/buildIsUnexpectedHelper.ts": "804a661e373dbff8ced2f95d1b8978c60c55a831", | ||
"packages/rlc-common/src/buildMethodShortcuts.ts": "5a4f96895b17402b9570c2600b227421035db052", | ||
@@ -13,0 +13,0 @@ "packages/rlc-common/src/buildObjectTypes.ts": "1fa988b1adc981eab3d3642e6f38c674989a2f3f", |
@@ -94,3 +94,3 @@ // Copyright (c) Microsoft Corporation. | ||
hasTemplate | ||
? "pathDetails = geParametrizedPathSuccess(method, url.pathname);" | ||
? "pathDetails = getParametrizedPathSuccess(method, url.pathname);" | ||
: `return true;`, | ||
@@ -105,3 +105,3 @@ ` } | ||
isExported: false, | ||
name: "geParametrizedPathSuccess", | ||
name: "getParametrizedPathSuccess", | ||
parameters: [ | ||
@@ -120,38 +120,53 @@ { | ||
` | ||
const pathParts = path.split("/"); | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// If the candidate and actual paths don't match in size | ||
// we move on to the next candidate path | ||
if ( | ||
candidateParts.length === pathParts.length && | ||
hasParametrizedPath(key) | ||
) { | ||
const pathParts = path.split("/"); | ||
// Traverse list to match the longest candidate | ||
// matchedLen: the length of candidate path | ||
// matchedValue: the matched status code array | ||
let matchedLen = -1, | ||
matchedValue: string[] = []; | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// track if we have found a match to return the values found. | ||
let found = true; | ||
for (let i = 0; i < candidateParts.length; i++) { | ||
for ( | ||
let i = candidateParts.length - 1, j = pathParts.length - 1; | ||
i >= 1 && j >= 1; | ||
i--, j-- | ||
) { | ||
if ( | ||
candidateParts[i]?.startsWith("{") && | ||
candidateParts[i]?.endsWith("}") | ||
candidateParts[i]?.indexOf("}") !== -1 | ||
) { | ||
const start = candidateParts[i]!.indexOf("}") + 1, | ||
end = candidateParts[i]?.length; | ||
// If the current part of the candidate is a "template" part | ||
// it is a match with the actual path part on hand | ||
// skip as the parameterized part can match anything | ||
// Try to use the suffix of pattern to match the path | ||
// {guid} ==> $ | ||
// {guid}:export ==> :export$ | ||
const isMatched = new RegExp( | ||
\`\${candidateParts[i]?.slice(start, end)}\` | ||
).test(pathParts[j] || ''); | ||
if (!isMatched) { | ||
found = false; | ||
break; | ||
} | ||
continue; | ||
} | ||
// If the candidate part is not a template and | ||
// the parts don't match mark the candidate as not found | ||
// to move on with the next candidate path. | ||
if (candidateParts[i] !== pathParts[i]) { | ||
if (candidateParts[i] !== pathParts[j]) { | ||
found = false; | ||
@@ -161,14 +176,12 @@ break; | ||
} | ||
// We finished evaluating the current candidate parts | ||
// if all parts matched we return the success values form | ||
// the path mapping. | ||
if (found) { | ||
return value; | ||
// Update the matched value if and only if we found the longer pattern | ||
if (found && candidatePath.length > matchedLen) { | ||
matchedLen = candidatePath.length; | ||
matchedValue = value; | ||
} | ||
} | ||
} | ||
// No match was found, return an empty array. | ||
return []; | ||
return matchedValue; | ||
` | ||
@@ -179,14 +192,2 @@ ] | ||
isExported: false, | ||
name: "hasParametrizedPath", | ||
parameters: [ | ||
{ | ||
name: "path", | ||
type: "string" | ||
} | ||
], | ||
returnType: `boolean`, | ||
statements: [`return path.includes("/{");`] | ||
}); | ||
isErrorHelper.addFunction({ | ||
isExported: false, | ||
name: "getPathFromMapKey", | ||
@@ -193,0 +194,0 @@ parameters: [ |
@@ -97,3 +97,3 @@ "use strict"; | ||
hasTemplate | ||
? "pathDetails = geParametrizedPathSuccess(method, url.pathname);" | ||
? "pathDetails = getParametrizedPathSuccess(method, url.pathname);" | ||
: `return true;`, | ||
@@ -108,3 +108,3 @@ ` } | ||
isExported: false, | ||
name: "geParametrizedPathSuccess", | ||
name: "getParametrizedPathSuccess", | ||
parameters: [ | ||
@@ -123,38 +123,53 @@ { | ||
` | ||
const pathParts = path.split("/"); | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// If the candidate and actual paths don't match in size | ||
// we move on to the next candidate path | ||
if ( | ||
candidateParts.length === pathParts.length && | ||
hasParametrizedPath(key) | ||
) { | ||
const pathParts = path.split("/"); | ||
// Traverse list to match the longest candidate | ||
// matchedLen: the length of candidate path | ||
// matchedValue: the matched status code array | ||
let matchedLen = -1, | ||
matchedValue: string[] = []; | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// track if we have found a match to return the values found. | ||
let found = true; | ||
for (let i = 0; i < candidateParts.length; i++) { | ||
for ( | ||
let i = candidateParts.length - 1, j = pathParts.length - 1; | ||
i >= 1 && j >= 1; | ||
i--, j-- | ||
) { | ||
if ( | ||
candidateParts[i]?.startsWith("{") && | ||
candidateParts[i]?.endsWith("}") | ||
candidateParts[i]?.indexOf("}") !== -1 | ||
) { | ||
const start = candidateParts[i]!.indexOf("}") + 1, | ||
end = candidateParts[i]?.length; | ||
// If the current part of the candidate is a "template" part | ||
// it is a match with the actual path part on hand | ||
// skip as the parameterized part can match anything | ||
// Try to use the suffix of pattern to match the path | ||
// {guid} ==> $ | ||
// {guid}:export ==> :export$ | ||
const isMatched = new RegExp( | ||
\`\${candidateParts[i]?.slice(start, end)}\` | ||
).test(pathParts[j] || ''); | ||
if (!isMatched) { | ||
found = false; | ||
break; | ||
} | ||
continue; | ||
} | ||
// If the candidate part is not a template and | ||
// the parts don't match mark the candidate as not found | ||
// to move on with the next candidate path. | ||
if (candidateParts[i] !== pathParts[i]) { | ||
if (candidateParts[i] !== pathParts[j]) { | ||
found = false; | ||
@@ -164,14 +179,12 @@ break; | ||
} | ||
// We finished evaluating the current candidate parts | ||
// if all parts matched we return the success values form | ||
// the path mapping. | ||
if (found) { | ||
return value; | ||
// Update the matched value if and only if we found the longer pattern | ||
if (found && candidatePath.length > matchedLen) { | ||
matchedLen = candidatePath.length; | ||
matchedValue = value; | ||
} | ||
} | ||
} | ||
// No match was found, return an empty array. | ||
return []; | ||
return matchedValue; | ||
` | ||
@@ -182,14 +195,2 @@ ] | ||
isExported: false, | ||
name: "hasParametrizedPath", | ||
parameters: [ | ||
{ | ||
name: "path", | ||
type: "string" | ||
} | ||
], | ||
returnType: `boolean`, | ||
statements: [`return path.includes("/{");`] | ||
}); | ||
isErrorHelper.addFunction({ | ||
isExported: false, | ||
name: "getPathFromMapKey", | ||
@@ -196,0 +197,0 @@ parameters: [ |
{ | ||
"name": "@azure-tools/rlc-common", | ||
"version": "1.0.0-alpha.2.20221028.1", | ||
"version": "1.0.0-alpha.2.20221031.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -115,3 +115,3 @@ // Copyright (c) Microsoft Corporation. | ||
hasTemplate | ||
? "pathDetails = geParametrizedPathSuccess(method, url.pathname);" | ||
? "pathDetails = getParametrizedPathSuccess(method, url.pathname);" | ||
: `return true;`, | ||
@@ -126,3 +126,3 @@ ` } | ||
isExported: false, | ||
name: "geParametrizedPathSuccess", | ||
name: "getParametrizedPathSuccess", | ||
parameters: [ | ||
@@ -141,38 +141,53 @@ { | ||
` | ||
const pathParts = path.split("/"); | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// If the candidate and actual paths don't match in size | ||
// we move on to the next candidate path | ||
if ( | ||
candidateParts.length === pathParts.length && | ||
hasParametrizedPath(key) | ||
) { | ||
const pathParts = path.split("/"); | ||
// Traverse list to match the longest candidate | ||
// matchedLen: the length of candidate path | ||
// matchedValue: the matched status code array | ||
let matchedLen = -1, | ||
matchedValue: string[] = []; | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// track if we have found a match to return the values found. | ||
let found = true; | ||
for (let i = 0; i < candidateParts.length; i++) { | ||
for ( | ||
let i = candidateParts.length - 1, j = pathParts.length - 1; | ||
i >= 1 && j >= 1; | ||
i--, j-- | ||
) { | ||
if ( | ||
candidateParts[i]?.startsWith("{") && | ||
candidateParts[i]?.endsWith("}") | ||
candidateParts[i]?.indexOf("}") !== -1 | ||
) { | ||
const start = candidateParts[i]!.indexOf("}") + 1, | ||
end = candidateParts[i]?.length; | ||
// If the current part of the candidate is a "template" part | ||
// it is a match with the actual path part on hand | ||
// skip as the parameterized part can match anything | ||
// Try to use the suffix of pattern to match the path | ||
// {guid} ==> $ | ||
// {guid}:export ==> :export$ | ||
const isMatched = new RegExp( | ||
\`\${candidateParts[i]?.slice(start, end)}\` | ||
).test(pathParts[j] || ''); | ||
if (!isMatched) { | ||
found = false; | ||
break; | ||
} | ||
continue; | ||
} | ||
// If the candidate part is not a template and | ||
// the parts don't match mark the candidate as not found | ||
// to move on with the next candidate path. | ||
if (candidateParts[i] !== pathParts[i]) { | ||
if (candidateParts[i] !== pathParts[j]) { | ||
found = false; | ||
@@ -182,14 +197,12 @@ break; | ||
} | ||
// We finished evaluating the current candidate parts | ||
// if all parts matched we return the success values form | ||
// the path mapping. | ||
if (found) { | ||
return value; | ||
// Update the matched value if and only if we found the longer pattern | ||
if (found && candidatePath.length > matchedLen) { | ||
matchedLen = candidatePath.length; | ||
matchedValue = value; | ||
} | ||
} | ||
} | ||
// No match was found, return an empty array. | ||
return []; | ||
return matchedValue; | ||
` | ||
@@ -201,15 +214,2 @@ ] | ||
isExported: false, | ||
name: "hasParametrizedPath", | ||
parameters: [ | ||
{ | ||
name: "path", | ||
type: "string" | ||
} | ||
], | ||
returnType: `boolean`, | ||
statements: [`return path.includes("/{");`] | ||
}); | ||
isErrorHelper.addFunction({ | ||
isExported: false, | ||
name: "getPathFromMapKey", | ||
@@ -216,0 +216,0 @@ parameters: [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
602457
10754