-
Notifications
You must be signed in to change notification settings - Fork 245
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
feat(go): support direct implementation of jsii interfaces #2614
Conversation
421d175
to
8c7b37b
Compare
Pure go implementations of jsii interfaces are detected upon being passed as a parameter to a JavaScript call. When this happens, a `create` call is sent to the `@jsii/kernel` process with the correct list of implemented interface FQNs, and all necessary overrides records. The object is then registered into the new `ObjectStore` for later reference. When a callback request interrupts the normal request/response flow, the `kernel.Client` will handle the callback by getting the appropriate receiver object, invoking the designated go implementation, and sending the result to the `@jsii/kernel` process before resuming normal response handling.
8c7b37b
to
95cf675
Compare
|
||
type Callback struct { | ||
CallbackID *string `json:"cbid"` | ||
Cookie *string `json:"cookie"` | ||
Invoke InvokeCallback `json:"invoke"` | ||
Get GetCallback `json:"get"` | ||
Set SetCallback `json:"set"` | ||
} | ||
|
||
type InvokeCallback struct { | ||
Method string `json:"method"` | ||
Arguments []interface{} `json:"args"` | ||
ObjRef ObjectRef `json:"objref"` | ||
} | ||
|
||
type GetCallback struct { | ||
Property string `json:"property"` | ||
ObjRef ObjectRef `json:"objref"` | ||
} | ||
|
||
type SetCallback struct { | ||
Property string `json:"property"` | ||
Value interface{} `json:"value"` | ||
ObjRef ObjectRef `json:"objref"` | ||
} |
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.
Those were all moved & hidden as implementation details of the kernel response unmarshaling.
JsiiMethod string `json:"method"` | ||
GoMethod string `json:"cookie"` |
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.
Renamed for better go-local semantics.
JsiiProperty string `json:"property"` | ||
GoGetter string `json:"cookie"` |
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.
Renamed for better go-local semantics.
@@ -1,20 +1,146 @@ | |||
package kernel |
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 file was changed to no longer actually expose a user-accessible API... The reason being there is no use for users to call Callbacks
directly, as this feature is currently unused, and in any case should be hidden from end-user code, and entirely managed by the runtime library.
This now handles "inline callback requests" received as part of the standard request-response flow, and does not actually handle asynchronous methods anymore (this is unused - and would be re-introduced in the future if needed).
types typeregistry.TypeRegistry | ||
objects map[reflect.Value]string | ||
types *typeregistry.TypeRegistry | ||
objects *objectstore.ObjectStore |
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.
Re-factored into separate module, as keying on reflect.Value
resulted in bugs, because they compare ==
if their values are ==
, regardless of whether they are distinct object instances... But this map actually should track individual instances (i.e: pointers).
# Conflicts: # packages/@jsii/go-runtime/go.sum # packages/@jsii/go-runtime/jsii-runtime-go/kernel/callbacks.go # packages/@jsii/go-runtime/jsii-runtime-go/kernel/client.go # packages/@jsii/go-runtime/jsii-runtime-go/kernel/conversions.go # packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/registration.go # packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/type-registry.go
e2e25f9
to
f42e13f
Compare
for fqn, members := range t.typeMembers { | ||
iface := t.fqnToType[fqn] | ||
if iface.Kind == classType || !vt.AssignableTo(iface.Type) { | ||
continue | ||
} |
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 might be expensive (I don't know). I decided to KISS for now, but we should be able to add a cache layer around this to mitigate the cost.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
# Conflicts: # packages/@jsii/go-runtime/jsii-runtime-go/internal/api/api.go # packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/callbacks.go # packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client.go # packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/json.go # packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/registration.go # packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/type-registry.go # packages/@jsii/go-runtime/jsii-runtime-go/runtime.go
Pure go implementations of jsii interfaces are detected upon being
passed as a parameter to a JavaScript call. When this happens, a
create
call is sent to the@jsii/kernel
process with the correctlist of implemented interface FQNs, and all necessary overrides records.
The object is then registered into the new
ObjectStore
for laterreference.
When a callback request interrupts the normal request/response flow, the
kernel.Client
will handle the callback by getting the appropriatereceiver object, invoking the designated go implementation, and sending
the result to the
@jsii/kernel
process before resuming normal responsehandling.
Related to #2048 (partial support)
Minor additional content:
yarn doc
will startgodoc
(serving the go documentation - includingfor the runtime modules - at
localhost:6060
)yarn lint
now runsgolint
on top ofgo vet
, for improved code qualityBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.