Skip to content

Commit

Permalink
Merge branch 'master' into dev-eventbus
Browse files Browse the repository at this point in the history
  • Loading branch information
loathedrobot authored Feb 20, 2024
2 parents a5c86b6 + ebc91d8 commit 32a8350
Show file tree
Hide file tree
Showing 11 changed files with 509 additions and 321 deletions.
553 changes: 315 additions & 238 deletions api.swagger.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion build/es/node/devices/devices_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage, Struct } from "@bufbuild/protobuf";
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage, Struct, Timestamp } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";
import type { Access } from "../access/access_pb.js";

Expand Down Expand Up @@ -71,6 +71,11 @@ export declare class Device extends Message<Device> {
*/
config?: Struct;

/**
* @generated from field: google.protobuf.Timestamp last_updated = 10;
*/
lastUpdated?: Timestamp;

constructor(data?: PartialMessage<Device>);

static readonly runtime: typeof proto3;
Expand Down
3 changes: 2 additions & 1 deletion build/es/node/devices/devices_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/* eslint-disable */
// @ts-nocheck

import { proto3, Struct } from "@bufbuild/protobuf";
import { proto3, Struct, Timestamp } from "@bufbuild/protobuf";
import { Access } from "../access/access_pb.js";

/**
Expand All @@ -36,6 +36,7 @@ export const Device = proto3.makeMessageType(
{ no: 7, name: "token", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 8, name: "access", kind: "message", T: Access, opt: true },
{ no: 9, name: "config", kind: "message", T: Struct },
{ no: 10, name: "last_updated", kind: "message", T: Timestamp },
],
);

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/infinimesh/proto
go 1.18

require (
connectrpc.com/connect v1.14.0
connectrpc.com/connect v1.15.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
google.golang.org/grpc v1.61.1
Expand All @@ -12,8 +12,8 @@ require (

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
connectrpc.com/connect v1.14.0 h1:PDS+J7uoz5Oui2VEOMcfz6Qft7opQM9hPiKvtGC01pA=
connectrpc.com/connect v1.14.0/go.mod h1:uoAq5bmhhn43TwhaKdGKN/bZcGtzPW1v+ngDTn5u+8s=
connectrpc.com/connect v1.15.0 h1:lFdeCbZrVVDydAqwr4xGV2y+ULn+0Z73s5JBj2LikWo=
connectrpc.com/connect v1.15.0/go.mod h1:bQmjpDY8xItMnttnurVgOkHUBMRT9cpsNi2O4AjKhmA=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
10 changes: 0 additions & 10 deletions mocks/es/shadow.ts

This file was deleted.

63 changes: 63 additions & 0 deletions mocks/es/shadows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Struct, Timestamp } from '@bufbuild/protobuf'
import { createPromiseClient, createRouterTransport } from '@connectrpc/connect'
import { DevicesService, ShadowService } from 'infinimesh-proto/build/es/node/node_connect'
import { QueryRequest } from 'infinimesh-proto/build/es/node/node_pb'
import { ConnectionState, GetResponse, Shadow, State } from 'infinimesh-proto/build/es/shadow/shadow_pb'
import { transport as devicesTransport } from './devices.ts'

export const transport = createRouterTransport(({ service }) => {
const devicesApi = createPromiseClient(DevicesService, devicesTransport)
const shadows = new Map<string, Shadow>()

devicesApi.list(new QueryRequest()).then(({ devices }) => {
devices.forEach(({ uuid }) => {
const length = Math.floor(Math.random() * 6)
const timestamp = new Timestamp({ seconds: BigInt(Math.round(Date.now() / 1000)) })

shadows.set(uuid, new Shadow({
connection: new ConnectionState({
clientId: `${length}`, connected: true, timestamp
}),
desired: new State({ data: new Struct(), timestamp }),
reported: new State({ data: new Struct(), timestamp }),
device: uuid
}))
})
})

service(ShadowService, {
get (request) {
return new GetResponse({
shadows: request.pool.map((uuid) => shadows.get(uuid)) as Shadow[]
})
},
patch (request) {
shadows.set(request.device, request)
return new Shadow(request)
},
remove (request) {
const result = shadows.get(request.device)

shadows.delete(request.device)
return new Shadow(result)
},
streamShadow (request) {
return {
[Symbol.asyncIterator]: () => ({
next: async () => (request.devices.length > 0)
? { value: new Shadow(shadows.get(request.devices.pop() as string)), done: false }
: { value: null, done: true }
})
}
},
streamShadowSync (request) {
return {
[Symbol.asyncIterator]: () => ({
next: async () => (request.devices.length < 1)
? { value: new Shadow(shadows.get(request.devices.pop() as string)), done: false }
: { value: null, done: true }
})
}
}
})
})
105 changes: 61 additions & 44 deletions node/devices/devices.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions node/devices/devices.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32a8350

Please sign in to comment.