-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search param builder #509
Merged
Merged
Search param builder #509
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3dd95a
inital prototype of param builder
patrickarlt 7bf9fa3
passing tests for SearchQueryBuilder
patrickarlt 2b040fb
passing tests for SearchQueryBuilder, IParamBuilder and IParamsBuilder
patrickarlt 8091c02
export SearchQueryBuilder
patrickarlt aaa2cbc
refactor searchItems to drop searchForm option
patrickarlt f9225db
refactor searchItems to drop searchForm option
patrickarlt eb297cb
remove params builder support
patrickarlt 99300a8
use new appendCustomParams consistently
jgravois 82fddd5
more tests
jgravois 63a326e
tslib isnt a peerDep
jgravois 5ed5de1
Merge remote-tracking branch 'upstream/v2.0.0' into chore/search-para…
jgravois 3a56a23
readd auth as peerDep of feature-service
jgravois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/arcgis-rest-common/src/util/append-custom-params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { IRequestOptions } from "@esri/arcgis-rest-request"; | ||
|
||
/** | ||
* Helper for methods with lots of first order request options to pass through as request parameters. | ||
*/ | ||
export function appendCustomParams<T extends IRequestOptions>( | ||
customOptions: T, | ||
keys: Array<keyof T>, | ||
baseOptions?: Partial<T> | ||
): IRequestOptions { | ||
const requestOptionsKeys = [ | ||
"params", | ||
"httpMethod", | ||
"rawResponse", | ||
"authentication", | ||
"portal", | ||
"fetch", | ||
"maxUrlLength", | ||
"headers" | ||
]; | ||
|
||
const options: T = { | ||
...{ params: {} }, | ||
...baseOptions, | ||
...customOptions | ||
}; | ||
|
||
// merge all keys in customOptions into options.params | ||
options.params = keys.reduce((value, key) => { | ||
if (customOptions[key] || typeof customOptions[key] === "boolean") { | ||
value[key as any] = customOptions[key]; | ||
} | ||
return value; | ||
}, options.params); | ||
|
||
// now remove all properties in options that don't exist in IRequestOptions | ||
return requestOptionsKeys.reduce( | ||
(value, key) => { | ||
if (options[key]) { | ||
value[key] = options[key]; | ||
} | ||
return value; | ||
}, | ||
{} as IRequestOptions | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/arcgis-rest-common/test/append-custom-params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { appendCustomParams } from "../src/util/append-custom-params"; | ||
import { IRequestOptions } from "@esri/arcgis-rest-request/src"; | ||
|
||
describe("appendCustomParams() helper", () => { | ||
it("should assign custom params from a sub class of IRequestOptions", () => { | ||
interface ICustomOptions extends IRequestOptions { | ||
foo: string; | ||
} | ||
|
||
expect( | ||
appendCustomParams<ICustomOptions>({ foo: "bar" }, ["foo"], { | ||
httpMethod: "GET" | ||
}) | ||
).toEqual({ | ||
httpMethod: "GET", | ||
params: { | ||
foo: "bar" | ||
} | ||
}); | ||
}); | ||
|
||
it("should assign custom params even if theyre falsey", () => { | ||
interface IFalseyCustomOptions extends IRequestOptions { | ||
foo: boolean; | ||
} | ||
|
||
expect( | ||
appendCustomParams<IFalseyCustomOptions>({ foo: false }, ["foo"], { | ||
httpMethod: "GET" | ||
}) | ||
).toEqual({ | ||
httpMethod: "GET", | ||
params: { | ||
foo: false | ||
} | ||
}); | ||
}); | ||
|
||
it("should pass through manual params if nothing is present to overwrite them", () => { | ||
interface IEmptyCustomOptions extends IRequestOptions { | ||
foo?: boolean; | ||
} | ||
|
||
expect( | ||
appendCustomParams<IEmptyCustomOptions>({}, ["foo"], { | ||
httpMethod: "GET", | ||
params: { | ||
foo: "bar" | ||
} | ||
}) | ||
).toEqual({ | ||
httpMethod: "GET", | ||
params: { | ||
foo: "bar" | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a
devDependency
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd say yes. fixed in 99300a8