-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Frontend2 URL Support for single model urls (#58)
* feat: Adds FE2 Url support for single model urls * fix: Minor formatting changes
- Loading branch information
Showing
4 changed files
with
97 additions
and
32 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
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,2 +1,2 @@ | ||
// Use this file to write queries to test your data connector | ||
let result = Speckle.GetByUrl("https://latest.speckle.dev/streams/4e51c4025f/commits/766c20c5fb") in result | ||
let result = Speckle.GetByUrl("https://app.speckle.systems/projects/e2988234fb/models/60b2300470@b1f31a351a") in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
let | ||
Speckle.Api.Fetch = Extension.LoadFunction("Api.Fetch.pqm"), | ||
Extension.LoadFunction = (fileName as text) => | ||
let | ||
binary = Extension.Contents(fileName), asText = Text.FromBinary(binary) | ||
in | ||
try | ||
Expression.Evaluate(asText, #shared) catch (e) => | ||
error | ||
[ | ||
Reason = "Extension.LoadFunction Failure", | ||
Message.Format = "Loading '#{0}' failed - '#{1}': '#{2}'", | ||
Message.Parameters = {fileName, e[Reason], e[Message]}, | ||
Detail = [File = fileName, Error = e] | ||
] | ||
in | ||
(server as text, projectId as text, modelId as text) => | ||
let | ||
query = "query Project($projectId: String!, $modelId: String!) { | ||
project(id: $projectId) { | ||
model(id: $modelId) { | ||
name | ||
} | ||
} | ||
}", | ||
variables = [ | ||
projectId = projectId, | ||
modelId = modelId | ||
] | ||
in | ||
// Read receipts should fail gracefully no matter what | ||
try Speckle.Api.Fetch(server, query, variables)[project][model] otherwise 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 |
---|---|---|
@@ -1,27 +1,51 @@ | ||
(url as text) as record => | ||
let | ||
// Get server and streamId, and branchName / commitId / objectid from the input url | ||
server = Text.Combine({Uri.Parts(url)[Scheme], "://", Uri.Parts(url)[Host]}), | ||
segments = Text.Split(Text.AfterDelimiter(Uri.Parts(url)[Path], "/", 0), "/"), | ||
streamId = segments{1}, | ||
branchName = if (List.Count(segments) = 4 and segments{2} = "branches") then segments{3} else null, | ||
commitId = if (List.Count(segments) = 4 and segments{2} = "commits") then segments{3} else null, | ||
objectId = if (List.Count(segments) = 4 and segments{2} = "objects") then segments{3} else null, | ||
urlType = | ||
if (commitId <> null) then | ||
"Commit" | ||
else if (objectId <> null) then | ||
"Object" | ||
else if (branchName <> null) then | ||
"Branch" | ||
else | ||
"Stream" | ||
in | ||
[ | ||
urlType = urlType, | ||
server = server, | ||
id = streamId, | ||
branch = branchName, | ||
commit = commitId, | ||
object = objectId | ||
] | ||
let | ||
GetModel = Extension.LoadFunction("Api.GetModel.pqm"), | ||
Extension.LoadFunction = (fileName as text) => | ||
let | ||
binary = Extension.Contents(fileName), asText = Text.FromBinary(binary) | ||
in | ||
try | ||
Expression.Evaluate(asText, #shared) catch (e) => | ||
error | ||
[ | ||
Reason = "Extension.LoadFunction Failure", | ||
Message.Format = "Loading '#{0}' failed - '#{1}': '#{2}'", | ||
Message.Parameters = {fileName, e[Reason], e[Message]}, | ||
Detail = [File = fileName, Error = e] | ||
] | ||
in | ||
(url as text) as record => | ||
let | ||
// Get server and streamId, and branchName / commitId / objectid from the input url | ||
server = Text.Combine({Uri.Parts(url)[Scheme], "://", Uri.Parts(url)[Host]}), | ||
segments = Text.Split(Text.AfterDelimiter(Uri.Parts(url)[Path], "/", 0), "/"), | ||
streamId = segments{1}, | ||
modelList = if (List.Count(segments) = 4 and segments{2} = "models") then segments{3} else null, | ||
firstModel = Text.Split(modelList, ","){0}, | ||
modelAndVersion = Text.Split(firstModel, "@"), | ||
modelId = modelAndVersion{0}, | ||
versionId = if (List.Count(modelAndVersion) > 1) then modelAndVersion{1} else null, | ||
model = if (modelId <> null) then GetModel(server, streamId, modelId) else null, | ||
branchName = if (List.Count(segments) = 4 and segments{2} = "branches") then segments{3} else null, | ||
commitId = if (List.Count(segments) = 4 and segments{2} = "commits") then segments{3} else null, | ||
objectId = if (List.Count(segments) = 4 and segments{2} = "objects") then segments{3} else null, | ||
modelOrBranchName = if (model <> null) then model[name] else branchName, | ||
commitOrVersion = if (versionId <> null) then versionId else commitId, | ||
urlType = | ||
if (commitOrVersion <> null) then | ||
"Commit" | ||
else if (objectId <> null) then | ||
"Object" | ||
else if (modelOrBranchName <> null) then | ||
"Branch" | ||
else | ||
"Stream" | ||
in | ||
[ | ||
urlType = urlType, | ||
server = server, | ||
id = streamId, | ||
branch = modelOrBranchName, | ||
commit = commitOrVersion, | ||
object = objectId | ||
] |