-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from open-rpc/feat/generate-method-id
feat(ids): upgrade the content descriptor id generators
- Loading branch information
Showing
7 changed files
with
83 additions
and
67 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { generateMethodParamId, generateMethodResultId } from "./generate-method-id"; | ||
import { types } from "@open-rpc/meta-schema"; | ||
|
||
describe("methodParamId", () => { | ||
it("returns an id for params", () => { | ||
const method = { | ||
name: "foo", | ||
params: [{ name: "bar" }], | ||
result: { name: "baz" }, | ||
}; | ||
const result = generateMethodParamId(method, method.params[0]); | ||
expect(result).toBe("foo/0"); | ||
}); | ||
|
||
it("index by name when the method paramStructure is by-name", () => { | ||
const method = { | ||
name: "foo", | ||
paramStructure: "by-name", | ||
params: [{ name: "bar" }], | ||
result: { name: "baz" }, | ||
} as types.MethodObject; | ||
|
||
expect(generateMethodParamId(method, { name: "bar" })).toBe("foo/bar"); | ||
}); | ||
|
||
describe("throws when the content descriptor is not found in the params", () => { | ||
it("by-position", () => { | ||
const method = { | ||
name: "foo", | ||
params: [{ name: "u will never get dis" }], | ||
result: { name: "baz" }, | ||
} as types.MethodObject; | ||
|
||
expect(() => generateMethodParamId(method, { name: "123" })) | ||
.toThrow("Content Descriptor not found in method."); | ||
}); | ||
|
||
it("by-name", () => { | ||
const method = { | ||
name: "foo", | ||
paramStructure: "by-name", | ||
params: [{ name: "bar" }], | ||
result: { name: "baz" }, | ||
} as types.MethodObject; | ||
|
||
expect(() => generateMethodParamId(method, { name: "123" })).toThrow(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("methodResultId", () => { | ||
it("returns an id for result", () => { | ||
const method = { | ||
name: "foo", | ||
params: [{ name: "bar" }], | ||
result: { name: "baz" }, | ||
}; | ||
const result = generateMethodResultId(method, method.result); | ||
expect(result).toBe("foo/result"); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { parse } from "./parse"; | ||
export { makeIdForMethodParam } from "./make-id-for-method-param"; | ||
export { generateMethodParamId, generateMethodResultId } from "./generate-method-id"; | ||
export { getValidationErrors } from "./get-validation-errors"; | ||
export { MethodCallValidator, ParameterValidationError } from "./method-call-validator"; |
This file was deleted.
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