Skip to content

Commit

Permalink
wip: use quicktype for typegen; add schemas for common, DS
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Feb 4, 2025
1 parent 2fc53f8 commit af33562
Show file tree
Hide file tree
Showing 39 changed files with 2,267 additions and 17 deletions.
15 changes: 15 additions & 0 deletions messages/common/IRpcRequest.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "IRpcRequest",
"x-typescript-type": "IRpcRequest",
"description": "Interface for RPC request objects",
"type": "object",
"properties": {
"command": {
"type": "string"
}
},
"required": [
"command"
]
}
13 changes: 13 additions & 0 deletions messages/common/IRpcResponse.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "IRpcResponse",
"x-typescript-type": "IRpcResponse",
"description": "Interface for RPC response objects",
"type": "object",
"properties": {
"success": {
"type": "boolean"
}
},
"required": []
}
20 changes: 20 additions & 0 deletions messages/ds/ListDatasets/Request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Request",
"x-typescript-type": "ListDatasets.Request",
"description": "Request to list datasets matching a pattern",
"type": "object",
"properties": {
"pattern": {
"type": "string",
"description": "Dataset name pattern to match"
},
"attributes": {
"type": "boolean",
"description": "Whether to include dataset attributes"
}
},
"required": [
"pattern"
]
}
41 changes: 41 additions & 0 deletions messages/ds/ListDatasets/Response.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ListDatasetsResponse",
"x-typescript-type": "ListDatasets.Response",
"description": "Response containing list of datasets",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcResponse.schema.json"
}
],
"properties": {
"items": {
"type": "array",
"items": {
"title": "Dataset",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"dsorg": {
"type": "string"
},
"volser": {
"type": "string"
}
},
"required": ["name", "dsorg", "volser"]
}
},
"returnedRows": {
"type": "integer",
"description": "Number of datasets returned"
}
},
"required": [
"items",
"returnedRows"
]
}
22 changes: 22 additions & 0 deletions messages/ds/ListDsMembers/Request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Request",
"x-typescript-type": "ListDsMembers.Request",
"description": "Request to list members of a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcRequest.schema.json"
}
],
"properties": {
"dsname": {
"type": "string",
"description": "Dataset name to list members from"
}
},
"required": [
"command",
"dsname"
]
}
34 changes: 34 additions & 0 deletions messages/ds/ListDsMembers/Response.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Response",
"x-typescript-type": "ListDsMembers.Response",
"description": "Response containing list of dataset members",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcResponse.schema.json"
}
],
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
},
"returnedRows": {
"type": "integer",
"description": "Number of members returned"
}
},
"required": [
"items",
"returnedRows"
]
}
26 changes: 26 additions & 0 deletions messages/ds/ReadDataset/Request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Request",
"x-typescript-type": "ReadDataset.Request",
"description": "Request to read contents of a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcRequest.schema.json"
}
],
"properties": {
"dsname": {
"type": "string",
"description": "Dataset name to read"
},
"encoding": {
"type": "string",
"description": "Encoding to use when reading the dataset"
}
},
"required": [
"command",
"dsname"
]
}
37 changes: 37 additions & 0 deletions messages/ds/ReadDataset/Response.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Response",
"x-typescript-type": "ReadDataset.Response",
"description": "Response containing dataset contents",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcResponse.schema.json"
}
],
"properties": {
"data": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"description": "Buffer object containing UTF-8 data"
}
]
},
"dsname": {
"type": "string",
"description": "Dataset name that was read"
},
"encoding": {
"type": "string",
"description": "Encoding used when reading the dataset"
}
},
"required": [
"data",
"dsname"
]
}
22 changes: 22 additions & 0 deletions messages/ds/RestoreDataset/Request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Request",
"x-typescript-type": "RestoreDataset.Request",
"description": "Request to restore a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcRequest.schema.json"
}
],
"properties": {
"dataset": {
"type": "string",
"description": "Dataset name to restore"
}
},
"required": [
"command",
"dataset"
]
}
21 changes: 21 additions & 0 deletions messages/ds/RestoreDataset/Response.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Response",
"x-typescript-type": "RestoreDataset.Response",
"description": "Response from restoring a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcResponse.schema.json"
}
],
"properties": {
"success": {
"type": "boolean",
"description": "Whether the restore operation was successful"
}
},
"required": [
"success"
]
}
38 changes: 38 additions & 0 deletions messages/ds/WriteDataset/Request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Request",
"x-typescript-type": "WriteDataset.Request",
"description": "Request to write contents to a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcRequest.schema.json"
}
],
"properties": {
"dsname": {
"type": "string",
"description": "Dataset name to write to"
},
"contents": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"description": "Buffer object containing UTF-8 data"
}
]
},
"encoding": {
"type": "string",
"description": "Encoding to use when writing the dataset"
}
},
"required": [
"command",
"dsname",
"contents"
]
}
26 changes: 26 additions & 0 deletions messages/ds/WriteDataset/Response.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Response",
"x-typescript-type": "WriteDataset.Response",
"description": "Response from writing to a dataset",
"type": "object",
"allOf": [
{
"$ref": "../../common/IRpcResponse.schema.json"
}
],
"properties": {
"dsname": {
"type": "string",
"description": "Dataset name that was written to"
},
"success": {
"type": "boolean",
"description": "Whether the write operation was successful"
}
},
"required": [
"dsname",
"success"
]
}
42 changes: 42 additions & 0 deletions native/golang/doc/common/IRpcRequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// iRPCRequest, err := UnmarshalIRPCRequest(bytes)
// bytes, err = iRPCRequest.Marshal()
//
// iRPCResponse, err := UnmarshalIRPCResponse(bytes)
// bytes, err = iRPCResponse.Marshal()

package doc

import "encoding/json"

func UnmarshalIRPCRequest(data []byte) (IRPCRequest, error) {
var r IRPCRequest
err := json.Unmarshal(data, &r)
return r, err
}

func (r *IRPCRequest) Marshal() ([]byte, error) {
return json.Marshal(r)
}

func UnmarshalIRPCResponse(data []byte) (IRPCResponse, error) {
var r IRPCResponse
err := json.Unmarshal(data, &r)
return r, err
}

func (r *IRPCResponse) Marshal() ([]byte, error) {
return json.Marshal(r)
}

// Interface for RPC request objects
type IRPCRequest struct {
Command string `json:"command"`
}

// Interface for RPC response objects
type IRPCResponse struct {
Success *bool `json:"success,omitempty"`
}
Loading

0 comments on commit af33562

Please sign in to comment.