diff --git a/api.swagger.json b/api.swagger.json index 10f15ce..dc9826f 100644 --- a/api.swagger.json +++ b/api.swagger.json @@ -1,13 +1,10 @@ { "swagger": "2.0", "info": { - "title": "handsfree/handsfree.proto", + "title": "node/access/access.proto", "version": "version not set" }, "tags": [ - { - "name": "HandsfreeService" - }, { "name": "ShadowService" }, @@ -26,6 +23,12 @@ { "name": "InternalService" }, + { + "name": "EventsService" + }, + { + "name": "HandsfreeService" + }, { "name": "PluginsService" }, @@ -3039,6 +3042,42 @@ } } }, + "eventbusEvent": { + "type": "object", + "properties": { + "eventKind": { + "$ref": "#/definitions/eventbusEventKind" + }, + "account": { + "$ref": "#/definitions/accountsAccount" + }, + "namespace": { + "$ref": "#/definitions/namespacesNamespace" + }, + "device": { + "$ref": "#/definitions/devicesDevice" + }, + "meta": { + "type": "object" + } + } + }, + "eventbusEventKind": { + "type": "string", + "enum": [ + "NONE", + "ACCOUNT_CREATE", + "ACCOUNT_UPDATE", + "ACCOUNT_DELETE", + "NAMESPACE_CREATE", + "NAMESPACE_UPDATE", + "NAMESPACE_DELETE", + "DEVICE_CREATE", + "DEVICE_UPDATE", + "DEVICE_DELETE" + ], + "default": "NONE" + }, "handsfreeCode": { "type": "string", "enum": [ diff --git a/build/es/eventbus/eventbus_connect.d.ts b/build/es/eventbus/eventbus_connect.d.ts new file mode 100644 index 0000000..957e4f3 --- /dev/null +++ b/build/es/eventbus/eventbus_connect.d.ts @@ -0,0 +1,27 @@ +// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=js+dts" +// @generated from file eventbus/eventbus.proto (package infinimesh.eventbus, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { EmptyMessage } from "../node/node_pb.js"; +import { Event } from "./eventbus_pb.js"; +import { MethodKind } from "@bufbuild/protobuf"; + +/** + * @generated from service infinimesh.eventbus.EventsService + */ +export declare const EventsService: { + readonly typeName: "infinimesh.eventbus.EventsService", + readonly methods: { + /** + * @generated from rpc infinimesh.eventbus.EventsService.Subscribe + */ + readonly subscribe: { + readonly name: "Subscribe", + readonly I: typeof EmptyMessage, + readonly O: typeof Event, + readonly kind: MethodKind.ServerStreaming, + }, + } +}; + diff --git a/build/es/eventbus/eventbus_connect.js b/build/es/eventbus/eventbus_connect.js new file mode 100644 index 0000000..e802c7b --- /dev/null +++ b/build/es/eventbus/eventbus_connect.js @@ -0,0 +1,27 @@ +// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=js+dts" +// @generated from file eventbus/eventbus.proto (package infinimesh.eventbus, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { EmptyMessage } from "../node/node_pb.js"; +import { Event } from "./eventbus_pb.js"; +import { MethodKind } from "@bufbuild/protobuf"; + +/** + * @generated from service infinimesh.eventbus.EventsService + */ +export const EventsService = { + typeName: "infinimesh.eventbus.EventsService", + methods: { + /** + * @generated from rpc infinimesh.eventbus.EventsService.Subscribe + */ + subscribe: { + name: "Subscribe", + I: EmptyMessage, + O: Event, + kind: MethodKind.ServerStreaming, + }, + } +}; + diff --git a/build/es/eventbus/eventbus_pb.d.ts b/build/es/eventbus/eventbus_pb.d.ts new file mode 100644 index 0000000..605cf40 --- /dev/null +++ b/build/es/eventbus/eventbus_pb.d.ts @@ -0,0 +1,118 @@ +// @generated by protoc-gen-es v1.7.2 with parameter "target=js+dts" +// @generated from file eventbus/eventbus.proto (package infinimesh.eventbus, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage, Struct } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; +import type { Account } from "../node/accounts/accounts_pb.js"; +import type { Namespace } from "../node/namespaces/namespaces_pb.js"; +import type { Device } from "../node/devices/devices_pb.js"; + +/** + * @generated from enum infinimesh.eventbus.EventKind + */ +export declare enum EventKind { + /** + * @generated from enum value: NONE = 0; + */ + NONE = 0, + + /** + * @generated from enum value: ACCOUNT_CREATE = 1; + */ + ACCOUNT_CREATE = 1, + + /** + * @generated from enum value: ACCOUNT_UPDATE = 2; + */ + ACCOUNT_UPDATE = 2, + + /** + * @generated from enum value: ACCOUNT_DELETE = 3; + */ + ACCOUNT_DELETE = 3, + + /** + * @generated from enum value: NAMESPACE_CREATE = 4; + */ + NAMESPACE_CREATE = 4, + + /** + * @generated from enum value: NAMESPACE_UPDATE = 5; + */ + NAMESPACE_UPDATE = 5, + + /** + * @generated from enum value: NAMESPACE_DELETE = 6; + */ + NAMESPACE_DELETE = 6, + + /** + * @generated from enum value: DEVICE_CREATE = 7; + */ + DEVICE_CREATE = 7, + + /** + * @generated from enum value: DEVICE_UPDATE = 8; + */ + DEVICE_UPDATE = 8, + + /** + * @generated from enum value: DEVICE_DELETE = 9; + */ + DEVICE_DELETE = 9, +} + +/** + * @generated from message infinimesh.eventbus.Event + */ +export declare class Event extends Message { + /** + * @generated from field: infinimesh.eventbus.EventKind event_kind = 1; + */ + eventKind: EventKind; + + /** + * @generated from oneof infinimesh.eventbus.Event.entity + */ + entity: { + /** + * @generated from field: infinimesh.node.accounts.Account account = 2; + */ + value: Account; + case: "account"; + } | { + /** + * @generated from field: infinimesh.node.namespaces.Namespace namespace = 3; + */ + value: Namespace; + case: "namespace"; + } | { + /** + * @generated from field: infinimesh.node.devices.Device device = 4; + */ + value: Device; + case: "device"; + } | { case: undefined; value?: undefined }; + + /** + * @generated from field: google.protobuf.Struct meta = 5; + */ + meta?: Struct; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "infinimesh.eventbus.Event"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Event; + + static fromJson(jsonValue: JsonValue, options?: Partial): Event; + + static fromJsonString(jsonString: string, options?: Partial): Event; + + static equals(a: Event | PlainMessage | undefined, b: Event | PlainMessage | undefined): boolean; +} + diff --git a/build/es/eventbus/eventbus_pb.js b/build/es/eventbus/eventbus_pb.js new file mode 100644 index 0000000..fffbe60 --- /dev/null +++ b/build/es/eventbus/eventbus_pb.js @@ -0,0 +1,43 @@ +// @generated by protoc-gen-es v1.7.2 with parameter "target=js+dts" +// @generated from file eventbus/eventbus.proto (package infinimesh.eventbus, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { proto3, Struct } from "@bufbuild/protobuf"; +import { Account } from "../node/accounts/accounts_pb.js"; +import { Namespace } from "../node/namespaces/namespaces_pb.js"; +import { Device } from "../node/devices/devices_pb.js"; + +/** + * @generated from enum infinimesh.eventbus.EventKind + */ +export const EventKind = proto3.makeEnum( + "infinimesh.eventbus.EventKind", + [ + {no: 0, name: "NONE"}, + {no: 1, name: "ACCOUNT_CREATE"}, + {no: 2, name: "ACCOUNT_UPDATE"}, + {no: 3, name: "ACCOUNT_DELETE"}, + {no: 4, name: "NAMESPACE_CREATE"}, + {no: 5, name: "NAMESPACE_UPDATE"}, + {no: 6, name: "NAMESPACE_DELETE"}, + {no: 7, name: "DEVICE_CREATE"}, + {no: 8, name: "DEVICE_UPDATE"}, + {no: 9, name: "DEVICE_DELETE"}, + ], +); + +/** + * @generated from message infinimesh.eventbus.Event + */ +export const Event = proto3.makeMessageType( + "infinimesh.eventbus.Event", + () => [ + { no: 1, name: "event_kind", kind: "enum", T: proto3.getEnumType(EventKind) }, + { no: 2, name: "account", kind: "message", T: Account, oneof: "entity" }, + { no: 3, name: "namespace", kind: "message", T: Namespace, oneof: "entity" }, + { no: 4, name: "device", kind: "message", T: Device, oneof: "entity" }, + { no: 5, name: "meta", kind: "message", T: Struct }, + ], +); + diff --git a/eventbus/eventbus.pb.go b/eventbus/eventbus.pb.go new file mode 100644 index 0000000..ec74bca --- /dev/null +++ b/eventbus/eventbus.pb.go @@ -0,0 +1,361 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.32.0 +// protoc (unknown) +// source: eventbus/eventbus.proto + +package eventbus + +import ( + node "github.com/infinimesh/proto/node" + accounts "github.com/infinimesh/proto/node/accounts" + devices "github.com/infinimesh/proto/node/devices" + namespaces "github.com/infinimesh/proto/node/namespaces" + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + structpb "google.golang.org/protobuf/types/known/structpb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type EventKind int32 + +const ( + EventKind_NONE EventKind = 0 + EventKind_ACCOUNT_CREATE EventKind = 1 + EventKind_ACCOUNT_UPDATE EventKind = 2 + EventKind_ACCOUNT_DELETE EventKind = 3 + EventKind_NAMESPACE_CREATE EventKind = 4 + EventKind_NAMESPACE_UPDATE EventKind = 5 + EventKind_NAMESPACE_DELETE EventKind = 6 + EventKind_DEVICE_CREATE EventKind = 7 + EventKind_DEVICE_UPDATE EventKind = 8 + EventKind_DEVICE_DELETE EventKind = 9 +) + +// Enum value maps for EventKind. +var ( + EventKind_name = map[int32]string{ + 0: "NONE", + 1: "ACCOUNT_CREATE", + 2: "ACCOUNT_UPDATE", + 3: "ACCOUNT_DELETE", + 4: "NAMESPACE_CREATE", + 5: "NAMESPACE_UPDATE", + 6: "NAMESPACE_DELETE", + 7: "DEVICE_CREATE", + 8: "DEVICE_UPDATE", + 9: "DEVICE_DELETE", + } + EventKind_value = map[string]int32{ + "NONE": 0, + "ACCOUNT_CREATE": 1, + "ACCOUNT_UPDATE": 2, + "ACCOUNT_DELETE": 3, + "NAMESPACE_CREATE": 4, + "NAMESPACE_UPDATE": 5, + "NAMESPACE_DELETE": 6, + "DEVICE_CREATE": 7, + "DEVICE_UPDATE": 8, + "DEVICE_DELETE": 9, + } +) + +func (x EventKind) Enum() *EventKind { + p := new(EventKind) + *p = x + return p +} + +func (x EventKind) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (EventKind) Descriptor() protoreflect.EnumDescriptor { + return file_eventbus_eventbus_proto_enumTypes[0].Descriptor() +} + +func (EventKind) Type() protoreflect.EnumType { + return &file_eventbus_eventbus_proto_enumTypes[0] +} + +func (x EventKind) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use EventKind.Descriptor instead. +func (EventKind) EnumDescriptor() ([]byte, []int) { + return file_eventbus_eventbus_proto_rawDescGZIP(), []int{0} +} + +type Event struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + EventKind EventKind `protobuf:"varint,1,opt,name=event_kind,json=eventKind,proto3,enum=infinimesh.eventbus.EventKind" json:"event_kind,omitempty"` + // Types that are assignable to Entity: + // + // *Event_Account + // *Event_Namespace + // *Event_Device + Entity isEvent_Entity `protobuf_oneof:"entity"` + Meta *structpb.Struct `protobuf:"bytes,5,opt,name=meta,proto3" json:"meta,omitempty"` +} + +func (x *Event) Reset() { + *x = Event{} + if protoimpl.UnsafeEnabled { + mi := &file_eventbus_eventbus_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_eventbus_eventbus_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Event.ProtoReflect.Descriptor instead. +func (*Event) Descriptor() ([]byte, []int) { + return file_eventbus_eventbus_proto_rawDescGZIP(), []int{0} +} + +func (x *Event) GetEventKind() EventKind { + if x != nil { + return x.EventKind + } + return EventKind_NONE +} + +func (m *Event) GetEntity() isEvent_Entity { + if m != nil { + return m.Entity + } + return nil +} + +func (x *Event) GetAccount() *accounts.Account { + if x, ok := x.GetEntity().(*Event_Account); ok { + return x.Account + } + return nil +} + +func (x *Event) GetNamespace() *namespaces.Namespace { + if x, ok := x.GetEntity().(*Event_Namespace); ok { + return x.Namespace + } + return nil +} + +func (x *Event) GetDevice() *devices.Device { + if x, ok := x.GetEntity().(*Event_Device); ok { + return x.Device + } + return nil +} + +func (x *Event) GetMeta() *structpb.Struct { + if x != nil { + return x.Meta + } + return nil +} + +type isEvent_Entity interface { + isEvent_Entity() +} + +type Event_Account struct { + Account *accounts.Account `protobuf:"bytes,2,opt,name=account,proto3,oneof"` +} + +type Event_Namespace struct { + Namespace *namespaces.Namespace `protobuf:"bytes,3,opt,name=namespace,proto3,oneof"` +} + +type Event_Device struct { + Device *devices.Device `protobuf:"bytes,4,opt,name=device,proto3,oneof"` +} + +func (*Event_Account) isEvent_Entity() {} + +func (*Event_Namespace) isEvent_Entity() {} + +func (*Event_Device) isEvent_Entity() {} + +var File_eventbus_eventbus_proto protoreflect.FileDescriptor + +var file_eventbus_eventbus_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x62, 0x75, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x69, 0x6e, 0x66, 0x69, 0x6e, + 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x1a, 0x1c, + 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x6e, 0x6f, + 0x64, 0x65, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1a, + 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x64, 0x65, 0x76, + 0x69, 0x63, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x6e, 0x6f, 0x64, 0x65, + 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbe, 0x02, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x12, 0x3d, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x6b, 0x69, 0x6e, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, + 0x73, 0x68, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x2e, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4b, 0x69, 0x6e, 0x64, + 0x12, 0x3d, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2e, 0x6e, + 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x45, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2e, + 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2e, + 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x48, 0x00, 0x52, 0x09, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, + 0x65, 0x73, 0x68, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x2e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x48, 0x00, 0x52, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x2b, 0x0a, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x42, 0x08, + 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2a, 0xcc, 0x01, 0x0a, 0x09, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, + 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x43, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x5f, 0x43, 0x52, 0x45, 0x41, + 0x54, 0x45, 0x10, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x43, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x5f, + 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x43, 0x43, 0x4f, + 0x55, 0x4e, 0x54, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, + 0x4e, 0x41, 0x4d, 0x45, 0x53, 0x50, 0x41, 0x43, 0x45, 0x5f, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, + 0x10, 0x04, 0x12, 0x14, 0x0a, 0x10, 0x4e, 0x41, 0x4d, 0x45, 0x53, 0x50, 0x41, 0x43, 0x45, 0x5f, + 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x05, 0x12, 0x14, 0x0a, 0x10, 0x4e, 0x41, 0x4d, 0x45, + 0x53, 0x50, 0x41, 0x43, 0x45, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x06, 0x12, 0x11, + 0x0a, 0x0d, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x10, + 0x07, 0x12, 0x11, 0x0a, 0x0d, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x55, 0x50, 0x44, 0x41, + 0x54, 0x45, 0x10, 0x08, 0x12, 0x11, 0x0a, 0x0d, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x44, + 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x09, 0x32, 0x59, 0x0a, 0x0d, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x48, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, + 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, + 0x73, 0x68, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x1a, 0x1a, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, 0x73, + 0x68, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x30, 0x01, 0x42, 0xbb, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x6e, 0x66, 0x69, 0x6e, + 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x42, 0x0d, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x69, + 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x62, 0x75, 0x73, 0xa2, 0x02, 0x03, 0x49, 0x45, 0x58, 0xaa, 0x02, 0x13, 0x49, 0x6e, + 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, + 0x73, 0xca, 0x02, 0x13, 0x49, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x5c, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0xe2, 0x02, 0x1f, 0x49, 0x6e, 0x66, 0x69, 0x6e, 0x69, + 0x6d, 0x65, 0x73, 0x68, 0x5c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x49, 0x6e, 0x66, 0x69, + 0x6e, 0x69, 0x6d, 0x65, 0x73, 0x68, 0x3a, 0x3a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x62, 0x75, 0x73, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_eventbus_eventbus_proto_rawDescOnce sync.Once + file_eventbus_eventbus_proto_rawDescData = file_eventbus_eventbus_proto_rawDesc +) + +func file_eventbus_eventbus_proto_rawDescGZIP() []byte { + file_eventbus_eventbus_proto_rawDescOnce.Do(func() { + file_eventbus_eventbus_proto_rawDescData = protoimpl.X.CompressGZIP(file_eventbus_eventbus_proto_rawDescData) + }) + return file_eventbus_eventbus_proto_rawDescData +} + +var file_eventbus_eventbus_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_eventbus_eventbus_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_eventbus_eventbus_proto_goTypes = []interface{}{ + (EventKind)(0), // 0: infinimesh.eventbus.EventKind + (*Event)(nil), // 1: infinimesh.eventbus.Event + (*accounts.Account)(nil), // 2: infinimesh.node.accounts.Account + (*namespaces.Namespace)(nil), // 3: infinimesh.node.namespaces.Namespace + (*devices.Device)(nil), // 4: infinimesh.node.devices.Device + (*structpb.Struct)(nil), // 5: google.protobuf.Struct + (*node.EmptyMessage)(nil), // 6: infinimesh.node.EmptyMessage +} +var file_eventbus_eventbus_proto_depIdxs = []int32{ + 0, // 0: infinimesh.eventbus.Event.event_kind:type_name -> infinimesh.eventbus.EventKind + 2, // 1: infinimesh.eventbus.Event.account:type_name -> infinimesh.node.accounts.Account + 3, // 2: infinimesh.eventbus.Event.namespace:type_name -> infinimesh.node.namespaces.Namespace + 4, // 3: infinimesh.eventbus.Event.device:type_name -> infinimesh.node.devices.Device + 5, // 4: infinimesh.eventbus.Event.meta:type_name -> google.protobuf.Struct + 6, // 5: infinimesh.eventbus.EventsService.Subscribe:input_type -> infinimesh.node.EmptyMessage + 1, // 6: infinimesh.eventbus.EventsService.Subscribe:output_type -> infinimesh.eventbus.Event + 6, // [6:7] is the sub-list for method output_type + 5, // [5:6] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_eventbus_eventbus_proto_init() } +func file_eventbus_eventbus_proto_init() { + if File_eventbus_eventbus_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_eventbus_eventbus_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Event); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_eventbus_eventbus_proto_msgTypes[0].OneofWrappers = []interface{}{ + (*Event_Account)(nil), + (*Event_Namespace)(nil), + (*Event_Device)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_eventbus_eventbus_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_eventbus_eventbus_proto_goTypes, + DependencyIndexes: file_eventbus_eventbus_proto_depIdxs, + EnumInfos: file_eventbus_eventbus_proto_enumTypes, + MessageInfos: file_eventbus_eventbus_proto_msgTypes, + }.Build() + File_eventbus_eventbus_proto = out.File + file_eventbus_eventbus_proto_rawDesc = nil + file_eventbus_eventbus_proto_goTypes = nil + file_eventbus_eventbus_proto_depIdxs = nil +} diff --git a/eventbus/eventbus.pb.validate.go b/eventbus/eventbus.pb.validate.go new file mode 100644 index 0000000..0636082 --- /dev/null +++ b/eventbus/eventbus.pb.validate.go @@ -0,0 +1,293 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: eventbus/eventbus.proto + +package eventbus + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on Event with the rules defined in the +// proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *Event) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on Event with the rules defined in the +// proto definition for this message. If any rules are violated, the result is +// a list of violation errors wrapped in EventMultiError, or nil if none found. +func (m *Event) ValidateAll() error { + return m.validate(true) +} + +func (m *Event) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for EventKind + + if all { + switch v := interface{}(m.GetMeta()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EventValidationError{ + field: "Meta", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EventValidationError{ + field: "Meta", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetMeta()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EventValidationError{ + field: "Meta", + reason: "embedded message failed validation", + cause: err, + } + } + } + + switch v := m.Entity.(type) { + case *Event_Account: + if v == nil { + err := EventValidationError{ + field: "Entity", + reason: "oneof value cannot be a typed-nil", + } + if !all { + return err + } + errors = append(errors, err) + } + + if all { + switch v := interface{}(m.GetAccount()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EventValidationError{ + field: "Account", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EventValidationError{ + field: "Account", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetAccount()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EventValidationError{ + field: "Account", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case *Event_Namespace: + if v == nil { + err := EventValidationError{ + field: "Entity", + reason: "oneof value cannot be a typed-nil", + } + if !all { + return err + } + errors = append(errors, err) + } + + if all { + switch v := interface{}(m.GetNamespace()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EventValidationError{ + field: "Namespace", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EventValidationError{ + field: "Namespace", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetNamespace()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EventValidationError{ + field: "Namespace", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case *Event_Device: + if v == nil { + err := EventValidationError{ + field: "Entity", + reason: "oneof value cannot be a typed-nil", + } + if !all { + return err + } + errors = append(errors, err) + } + + if all { + switch v := interface{}(m.GetDevice()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EventValidationError{ + field: "Device", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EventValidationError{ + field: "Device", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetDevice()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EventValidationError{ + field: "Device", + reason: "embedded message failed validation", + cause: err, + } + } + } + + default: + _ = v // ensures v is used + } + + if len(errors) > 0 { + return EventMultiError(errors) + } + + return nil +} + +// EventMultiError is an error wrapping multiple validation errors returned by +// Event.ValidateAll() if the designated constraints aren't met. +type EventMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m EventMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m EventMultiError) AllErrors() []error { return m } + +// EventValidationError is the validation error returned by Event.Validate if +// the designated constraints aren't met. +type EventValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e EventValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e EventValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e EventValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e EventValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e EventValidationError) ErrorName() string { return "EventValidationError" } + +// Error satisfies the builtin error interface +func (e EventValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sEvent.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = EventValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = EventValidationError{} diff --git a/eventbus/eventbus.proto b/eventbus/eventbus.proto new file mode 100644 index 0000000..c7f0cba --- /dev/null +++ b/eventbus/eventbus.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package infinimesh.eventbus; + +import "node/accounts/accounts.proto"; +import "node/namespaces/namespaces.proto"; +import "node/devices/devices.proto"; +import "node/node.proto"; +import "google/protobuf/struct.proto"; +import "google/api/annotations.proto"; + +enum EventKind{ + NONE = 0; + ACCOUNT_CREATE = 1; + ACCOUNT_UPDATE = 2; + ACCOUNT_DELETE = 3; + NAMESPACE_CREATE = 4; + NAMESPACE_UPDATE = 5; + NAMESPACE_DELETE = 6; + DEVICE_CREATE = 7; + DEVICE_UPDATE = 8; + DEVICE_DELETE = 9; +} + +message Event { + EventKind event_kind = 1; + oneof entity { + node.accounts.Account account = 2; + node.namespaces.Namespace namespace = 3; + node.devices.Device device = 4; + } + google.protobuf.Struct meta = 5; +} + +service EventsService{ + rpc Subscribe (node.EmptyMessage) returns (stream Event); +} \ No newline at end of file diff --git a/eventbus/eventbus_grpc.pb.go b/eventbus/eventbus_grpc.pb.go new file mode 100644 index 0000000..d06d71a --- /dev/null +++ b/eventbus/eventbus_grpc.pb.go @@ -0,0 +1,137 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: eventbus/eventbus.proto + +package eventbus + +import ( + context "context" + node "github.com/infinimesh/proto/node" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + EventsService_Subscribe_FullMethodName = "/infinimesh.eventbus.EventsService/Subscribe" +) + +// EventsServiceClient is the client API for EventsService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type EventsServiceClient interface { + Subscribe(ctx context.Context, in *node.EmptyMessage, opts ...grpc.CallOption) (EventsService_SubscribeClient, error) +} + +type eventsServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewEventsServiceClient(cc grpc.ClientConnInterface) EventsServiceClient { + return &eventsServiceClient{cc} +} + +func (c *eventsServiceClient) Subscribe(ctx context.Context, in *node.EmptyMessage, opts ...grpc.CallOption) (EventsService_SubscribeClient, error) { + stream, err := c.cc.NewStream(ctx, &EventsService_ServiceDesc.Streams[0], EventsService_Subscribe_FullMethodName, opts...) + if err != nil { + return nil, err + } + x := &eventsServiceSubscribeClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type EventsService_SubscribeClient interface { + Recv() (*Event, error) + grpc.ClientStream +} + +type eventsServiceSubscribeClient struct { + grpc.ClientStream +} + +func (x *eventsServiceSubscribeClient) Recv() (*Event, error) { + m := new(Event) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// EventsServiceServer is the server API for EventsService service. +// All implementations must embed UnimplementedEventsServiceServer +// for forward compatibility +type EventsServiceServer interface { + Subscribe(*node.EmptyMessage, EventsService_SubscribeServer) error + mustEmbedUnimplementedEventsServiceServer() +} + +// UnimplementedEventsServiceServer must be embedded to have forward compatible implementations. +type UnimplementedEventsServiceServer struct { +} + +func (UnimplementedEventsServiceServer) Subscribe(*node.EmptyMessage, EventsService_SubscribeServer) error { + return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") +} +func (UnimplementedEventsServiceServer) mustEmbedUnimplementedEventsServiceServer() {} + +// UnsafeEventsServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to EventsServiceServer will +// result in compilation errors. +type UnsafeEventsServiceServer interface { + mustEmbedUnimplementedEventsServiceServer() +} + +func RegisterEventsServiceServer(s grpc.ServiceRegistrar, srv EventsServiceServer) { + s.RegisterService(&EventsService_ServiceDesc, srv) +} + +func _EventsService_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(node.EmptyMessage) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(EventsServiceServer).Subscribe(m, &eventsServiceSubscribeServer{stream}) +} + +type EventsService_SubscribeServer interface { + Send(*Event) error + grpc.ServerStream +} + +type eventsServiceSubscribeServer struct { + grpc.ServerStream +} + +func (x *eventsServiceSubscribeServer) Send(m *Event) error { + return x.ServerStream.SendMsg(m) +} + +// EventsService_ServiceDesc is the grpc.ServiceDesc for EventsService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var EventsService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "infinimesh.eventbus.EventsService", + HandlerType: (*EventsServiceServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "Subscribe", + Handler: _EventsService_Subscribe_Handler, + ServerStreams: true, + }, + }, + Metadata: "eventbus/eventbus.proto", +} diff --git a/eventbus/eventbusconnect/eventbus.connect.go b/eventbus/eventbusconnect/eventbus.connect.go new file mode 100644 index 0000000..9668e34 --- /dev/null +++ b/eventbus/eventbusconnect/eventbus.connect.go @@ -0,0 +1,113 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: eventbus/eventbus.proto + +package eventbusconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + eventbus "github.com/infinimesh/proto/eventbus" + node "github.com/infinimesh/proto/node" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // EventsServiceName is the fully-qualified name of the EventsService service. + EventsServiceName = "infinimesh.eventbus.EventsService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // EventsServiceSubscribeProcedure is the fully-qualified name of the EventsService's Subscribe RPC. + EventsServiceSubscribeProcedure = "/infinimesh.eventbus.EventsService/Subscribe" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + eventsServiceServiceDescriptor = eventbus.File_eventbus_eventbus_proto.Services().ByName("EventsService") + eventsServiceSubscribeMethodDescriptor = eventsServiceServiceDescriptor.Methods().ByName("Subscribe") +) + +// EventsServiceClient is a client for the infinimesh.eventbus.EventsService service. +type EventsServiceClient interface { + Subscribe(context.Context, *connect.Request[node.EmptyMessage]) (*connect.ServerStreamForClient[eventbus.Event], error) +} + +// NewEventsServiceClient constructs a client for the infinimesh.eventbus.EventsService service. By +// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, +// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewEventsServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) EventsServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &eventsServiceClient{ + subscribe: connect.NewClient[node.EmptyMessage, eventbus.Event]( + httpClient, + baseURL+EventsServiceSubscribeProcedure, + connect.WithSchema(eventsServiceSubscribeMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// eventsServiceClient implements EventsServiceClient. +type eventsServiceClient struct { + subscribe *connect.Client[node.EmptyMessage, eventbus.Event] +} + +// Subscribe calls infinimesh.eventbus.EventsService.Subscribe. +func (c *eventsServiceClient) Subscribe(ctx context.Context, req *connect.Request[node.EmptyMessage]) (*connect.ServerStreamForClient[eventbus.Event], error) { + return c.subscribe.CallServerStream(ctx, req) +} + +// EventsServiceHandler is an implementation of the infinimesh.eventbus.EventsService service. +type EventsServiceHandler interface { + Subscribe(context.Context, *connect.Request[node.EmptyMessage], *connect.ServerStream[eventbus.Event]) error +} + +// NewEventsServiceHandler builds an HTTP handler from the service implementation. It returns the +// path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewEventsServiceHandler(svc EventsServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + eventsServiceSubscribeHandler := connect.NewServerStreamHandler( + EventsServiceSubscribeProcedure, + svc.Subscribe, + connect.WithSchema(eventsServiceSubscribeMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/infinimesh.eventbus.EventsService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case EventsServiceSubscribeProcedure: + eventsServiceSubscribeHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedEventsServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedEventsServiceHandler struct{} + +func (UnimplementedEventsServiceHandler) Subscribe(context.Context, *connect.Request[node.EmptyMessage], *connect.ServerStream[eventbus.Event]) error { + return connect.NewError(connect.CodeUnimplemented, errors.New("infinimesh.eventbus.EventsService.Subscribe is not implemented")) +}