-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Normalizer versioning fix * Fix error * add logic to find newest service * Add util-semver package * Move logic to normalizeServices
- Loading branch information
Showing
25 changed files
with
367 additions
and
96 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@onflow/fcl": patch | ||
--- | ||
|
||
Fix version normalization of services in FCL |
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
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,3 +1,14 @@ | ||
import * as semver from "@onflow/util-semver" | ||
|
||
export function serviceOfType(services = [], type) { | ||
return services.find(service => service.type === type) | ||
// Find the greatest version of the service type | ||
return services.reduce( | ||
(mostRecent, service) => | ||
service.type === type | ||
? !mostRecent || semver.compare(service.f_vsn, mostRecent.f_vsn) > 0 | ||
? service | ||
: mostRecent | ||
: mostRecent, | ||
null | ||
) | ||
} |
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,40 @@ | ||
import {serviceOfType} from "./service-of-type" | ||
|
||
describe("service-of-type", () => { | ||
it("should choose the most recent version of a service", () => { | ||
const services = [ | ||
{ | ||
type: "authn", | ||
f_vsn: "1.0.0", | ||
}, | ||
{ | ||
type: "authn", | ||
f_vsn: "2.0.0", | ||
}, | ||
] | ||
|
||
const service = serviceOfType(services, "authn") | ||
|
||
expect(service).toEqual({ | ||
type: "authn", | ||
f_vsn: "2.0.0", | ||
}) | ||
}) | ||
|
||
it("should return null if no service of type exists", () => { | ||
const services = [ | ||
{ | ||
type: "authn", | ||
f_vsn: "1.0.0", | ||
}, | ||
{ | ||
type: "authn", | ||
f_vsn: "2.0.0", | ||
}, | ||
] | ||
|
||
const service = serviceOfType(services, "non-existent") | ||
|
||
expect(service).toBe(null) | ||
}) | ||
}) |
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
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
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.