-
Notifications
You must be signed in to change notification settings - Fork 310
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
Device Support for JS SDK #278
Conversation
Concerning the removal of |
sdk/js/src/util/marshaler.js
Outdated
@@ -82,12 +90,51 @@ class Marshaler { | |||
return this.payloadSingleResponse(result, transform) | |||
} | |||
|
|||
static unwrapDevices (result, transform) { | |||
return this.payloadListResponse(result, transform) |
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.
return this.payloadListResponse(result, transform) | |
return this.payloadListResponse('devices', result, transform) |
you are passing the transform
function instead of the result
object to payloadListResponse
sdk/js/src/api/index.js
Outdated
|
||
const routeParams = params.route || {} | ||
const queryParams = params.query || {} | ||
this[serviceName][rpcName] = function ({ routeParams = {}, queryParams = {}, fieldMask = []}, payload) { |
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.
why would you pass the field mask separately?
i expect it to be in the payload already in delete/put/post requests and in the query in get requests
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.
Exactly because of this distinction between GET
and POST/PATCH/etc
. Before we appended a querified object directly to the url, but axios actually provides an API to do this via passingconfig.params
to the request method. We should use that because it is directly integrated and also saves us a dependency (query-string
).
I was detaching the field mask from the payload then to simplify the logic of passing this to get/non-get (either via config.params
or payload
) correctly.
But yeah, looking at it again, we can likely simplify this by treating it as part of the payload again and passing the payload as config.params
in case of GET
.
sdk/js/src/api/index.js
Outdated
|
||
return connector[endpoint.method](route, body) | ||
return connector[endpoint.method](route, payload, { queryParams, fieldMask }) |
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.
arent query parameters only for get requests?
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.
No, they can be used always. Though we probably won't face that in the API. As such I will remove them – makes things easier as well.
sdk/js/src/service/applications.js
Outdated
import Link from './link' | ||
import DeviceService from './devices' | ||
|
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.
redundant new line
sdk/js/src/service/applications.js
Outdated
'application.ids.application_id': id, | ||
}, | ||
async updateById (id, patch, selector) { | ||
const fieldMask = selector |
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.
why? do you change anything in the Application service? this doesnt seem to be related to devices
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.
Agreed. This is not necessary and I will remove it. However, we actually need to change the getById
method to accept selectors (as intermediate to field masks), otherwise, we won't get e.g. name
or description
field by default, which is the case at the moment. I would add that in this PR as well, as it is a small change.
|
||
import crypto from 'crypto' | ||
|
||
export default function randomByteString (len, type = 'hex') { |
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.
so this is just a stub?
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.
This is following the cli command:
https://github.com/TheThingsNetwork/lorawan-stack/blob/master/cmd/ttn-lw-cli/commands/end_devices.go#L101-L105
I think this will be enhanced at a later stage.
sdk/js/src/api/http.js
Outdated
const component = this._parseStackComponent(endpoint) | ||
try { | ||
return await this[component][method](endpoint, payload) | ||
if (method === 'get') { | ||
return await this[component][method](endpoint, config) |
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.
why not passing an empty payload here?
why do we need that separation?
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.
To me, it seemed weird to define a get function with a payload argument that is always discarded.
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.
Disregard the above, I actually mixed that up. You are right indeed. I wrongfully thought, the different signature of the get method would make that necessary.
After trying it out, it actually is necessary when using the method aliases because get()
doesn't accept more than two arguments. We can still get rid of the if check by using the plain axios function.
6ffbc7d
to
4f40c96
Compare
4f40c96
to
7086da0
Compare
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.
This branch breaks several pieces of functionality of the console, for example, linking, editing application data.
Error:
{"code":3,"message":"json: cannot unmarshal array into Go value of type map[string]json.RawMessage"}
sdk/js/src/service/applications.js
Outdated
import Application from '../entity/application' | ||
import ApiKeys from './api-keys' | ||
import ApiKeysService from './api-keys' |
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.
why?
sdk/js/src/service/applications.js
Outdated
import Link from './link' | ||
import Device from './devices' |
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.
inconsistent naming. DeviceService
, Device
, DevicesService
, Devices
?
Right. We need another merge strategy here, as merging to master would break the console. This is mostly because of slight changes in the signatures of the service functions. I will follow up with a description of these changes tomorrow. |
7086da0
to
0afcc01
Compare
So after checking this, there aren't actually breaking changes, as the new function signatures are only extending the argument list and provide defaults. The errors you experienced were caused by faulty handling of field masks, which I have fixed now. |
0afcc01
to
00d7381
Compare
00d7381
to
40b4db5
Compare
40b4db5
to
a5a2050
Compare
a5a2050
to
7a7699b
Compare
Summary:
Closes #131.
This PR adds the first implementation for supporting device crud in the SDK. It follows the logic of the cli commands for doing device CRUD, including merging of entity parts from different components, based on the field mask paths.
It also simplifies the SDK implementation and streamlines marshaling of field masks and unwrapping of api responses, along with other improvements.
Changes:
get
andset/update
withId()
shorthandNotes for Reviewers:
Release Notes: (optional)
Added Device support to JS SDK.