...
This commit is contained in:
@@ -8,7 +8,7 @@ import os
|
||||
|
||||
const openrpc_path = os.join_path(os.dir(@FILE), 'openrpc.json')
|
||||
|
||||
pub fn new_heromodels_handler() !openrpc.Handler {
|
||||
pub fn new() !openrpc.Handler {
|
||||
mut openrpc_handler := openrpc.Handler {
|
||||
specification: openrpc.new(path: openrpc_path)!
|
||||
}
|
||||
@@ -18,11 +18,10 @@ pub fn new_heromodels_handler() !openrpc.Handler {
|
||||
openrpc_handler.register_procedure_handle('comment_delete', comment_delete)
|
||||
openrpc_handler.register_procedure_handle('comment_list', comment_list)
|
||||
|
||||
// openrpc_handler.register_procedure_handle('calendar_get', calendar_get)
|
||||
// openrpc_handler.register_procedure_handle('calendar_set', calendar_set)
|
||||
// openrpc_handler.register_procedure_handle('calendar_delete', calendar_delete)
|
||||
// openrpc_handler.register_procedure_handle('calendar_list', calendar_list)
|
||||
openrpc_handler.register_procedure_handle('calendar_get', calendar_get)
|
||||
openrpc_handler.register_procedure_handle('calendar_set', calendar_set)
|
||||
openrpc_handler.register_procedure_handle('calendar_delete', calendar_delete)
|
||||
openrpc_handler.register_procedure_handle('calendar_list', calendar_list)
|
||||
|
||||
return openrpc_handler
|
||||
}
|
||||
|
||||
|
||||
@@ -1,117 +1,87 @@
|
||||
{
|
||||
"openrpc": "1.0.0-rc1",
|
||||
"openrpc": "1.0.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "HeroModels OpenRPC API",
|
||||
"description": "OpenRPC API for HeroModels comment management over Unix socket",
|
||||
"contact": {
|
||||
"name": "HeroLib Team",
|
||||
"url": "https://github.com/freeflowuniverse/herolib"
|
||||
}
|
||||
"title": "Hero Models API",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"name": "Unix Socket Server",
|
||||
"url": "${server.socket_path}",
|
||||
"description": "Unix domain socket server for HeroModels"
|
||||
}
|
||||
],
|
||||
"methods": [
|
||||
{
|
||||
"name": "comment_get",
|
||||
"description": "Retrieve comments by ID, author, or parent",
|
||||
"summary": "Get a comment by ID",
|
||||
"params": [
|
||||
{
|
||||
"name": "args",
|
||||
"description": "Comment search arguments",
|
||||
"name": "id",
|
||||
"description": "ID of comment to fetch",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "Comment ID to retrieve"
|
||||
},
|
||||
"author": {
|
||||
"type": "integer",
|
||||
"description": "Author ID to filter by"
|
||||
},
|
||||
"parent": {
|
||||
"type": "integer",
|
||||
"description": "Parent comment ID to filter by"
|
||||
}
|
||||
}
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "comments",
|
||||
"description": "Comment(s) matching the criteria",
|
||||
"name": "comment",
|
||||
"description": "Comment object",
|
||||
"schema": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$$ref": "#/components/schemas/Comment"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$$ref": "#/components/schemas/Comment"
|
||||
}
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/Comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "comment_set",
|
||||
"description": "Create a new comment",
|
||||
"summary": "Create or update a comment",
|
||||
"params": [
|
||||
{
|
||||
"name": "comment",
|
||||
"description": "Comment data to create",
|
||||
"description": "Comment text",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$$ref": "#/components/schemas/CommentArg"
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "parent",
|
||||
"description": "ID of parent comment if any, 0 means none",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "author",
|
||||
"description": "ID of the author user",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "result",
|
||||
"description": "Created comment ID",
|
||||
"name": "id",
|
||||
"description": "ID of the created/updated comment",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "ID of the created comment"
|
||||
}
|
||||
}
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "comment_delete",
|
||||
"description": "Delete a comment by ID",
|
||||
"summary": "Delete a comment by ID",
|
||||
"params": [
|
||||
{
|
||||
"name": "args",
|
||||
"description": "Comment deletion arguments",
|
||||
"name": "id",
|
||||
"description": "ID of comment to delete",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "ID of comment to delete"
|
||||
}
|
||||
},
|
||||
"required": ["id"]
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "result",
|
||||
"description": "Deletion result",
|
||||
"description": "Success result with deleted comment ID",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -119,7 +89,8 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,86 +98,235 @@
|
||||
},
|
||||
{
|
||||
"name": "comment_list",
|
||||
"description": "List all comment IDs",
|
||||
"summary": "List all comments",
|
||||
"params": [],
|
||||
"result": {
|
||||
"name": "ids",
|
||||
"description": "Array of all comment IDs",
|
||||
"name": "comments",
|
||||
"description": "List of all comment objects",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
"$ref": "#/components/schemas/Comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "discover",
|
||||
"description": "Get the OpenRPC specification for this service",
|
||||
"name": "calendar_get",
|
||||
"summary": "Get a calendar by ID",
|
||||
"params": [
|
||||
{
|
||||
"name": "id",
|
||||
"description": "ID of calendar to fetch",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "calendar",
|
||||
"description": "Calendar object",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Calendar"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "calendar_set",
|
||||
"summary": "Create or update a calendar",
|
||||
"params": [
|
||||
{
|
||||
"name": "name",
|
||||
"description": "Name of the calendar",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"description": "Description of the calendar",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "color",
|
||||
"description": "Hex color code for the calendar",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timezone",
|
||||
"description": "Timezone of the calendar",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"description": "Whether the calendar is public",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "events",
|
||||
"description": "IDs of calendar events",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "id",
|
||||
"description": "ID of the created/updated calendar",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "calendar_delete",
|
||||
"summary": "Delete a calendar by ID",
|
||||
"params": [
|
||||
{
|
||||
"name": "id",
|
||||
"description": "ID of calendar to delete",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "result",
|
||||
"description": "Success result with deleted calendar ID",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "calendar_list",
|
||||
"summary": "List all calendars",
|
||||
"params": [],
|
||||
"result": {
|
||||
"name": "spec",
|
||||
"description": "OpenRPC specification",
|
||||
"name": "calendars",
|
||||
"description": "List of all calendar objects",
|
||||
"schema": {
|
||||
"type": "object"
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/Calendar"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Comment": {
|
||||
"Base": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "Unique comment identifier"
|
||||
"minimum": 0
|
||||
},
|
||||
"comment": {
|
||||
"type": "string",
|
||||
"description": "Comment text content"
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"parent": {
|
||||
"type": "integer",
|
||||
"description": "Parent comment ID (0 if top-level)"
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "integer"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "integer",
|
||||
"description": "Unix timestamp of last update"
|
||||
"type": "integer"
|
||||
},
|
||||
"author": {
|
||||
"securitypolicy": {
|
||||
"type": "integer",
|
||||
"description": "Author user ID"
|
||||
"minimum": 0
|
||||
},
|
||||
"tags": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"comments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"comment",
|
||||
"parent",
|
||||
"updated_at",
|
||||
"author"
|
||||
]
|
||||
}
|
||||
},
|
||||
"CommentArg": {
|
||||
"type": "object",
|
||||
"Comment": {
|
||||
"title": "Comment",
|
||||
"description": "A comment object",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Base"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"comment": {
|
||||
"type": "string",
|
||||
"description": "Comment text content"
|
||||
"type": "string"
|
||||
},
|
||||
"parent": {
|
||||
"type": "integer",
|
||||
"description": "Parent comment ID (0 if top-level)"
|
||||
"minimum": 0
|
||||
},
|
||||
"author": {
|
||||
"type": "integer",
|
||||
"description": "Author user ID"
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"comment",
|
||||
"author"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Calendar": {
|
||||
"title": "Calendar",
|
||||
"description": "A calendar object",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Base"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"events": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
},
|
||||
"timezone": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_public": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,69 @@ import freeflowuniverse.herolib.schemas.jsonrpc
|
||||
import freeflowuniverse.herolib.hero.heromodels
|
||||
import freeflowuniverse.herolib.schemas.jsonrpc
|
||||
|
||||
//TODO implement calendar rpc methods
|
||||
// Calendar-specific argument structures
|
||||
@[params]
|
||||
pub struct CalendarGetArgs {
|
||||
pub mut:
|
||||
id u32 @[required]
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct CalendarSetArgs {
|
||||
pub mut:
|
||||
name string @[required]
|
||||
description string
|
||||
color string
|
||||
timezone string
|
||||
is_public bool
|
||||
events []u32
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct CalendarDeleteArgs {
|
||||
pub mut:
|
||||
id u32 @[required]
|
||||
}
|
||||
|
||||
pub fn calendar_get(request jsonrpc.Request) !jsonrpc.Response {
|
||||
payload := jsonrpc.decode_payload[CalendarGetArgs](request.params) or { return jsonrpc.invalid_params }
|
||||
|
||||
mut mydb := heromodels.new()!
|
||||
calendar := mydb.calendar.get(payload.id)!
|
||||
|
||||
return jsonrpc.new_response(request.id, json.encode(calendar))
|
||||
}
|
||||
|
||||
pub fn calendar_set(request jsonrpc.Request) !jsonrpc.Response {
|
||||
payload := jsonrpc.decode_payload[CalendarSetArgs](request.params) or { return jsonrpc.invalid_params }
|
||||
|
||||
mut mydb := heromodels.new()!
|
||||
mut calendar_obj := mydb.calendar.new(
|
||||
name: payload.name
|
||||
description: payload.description
|
||||
color: payload.color
|
||||
timezone: payload.timezone
|
||||
is_public: payload.is_public
|
||||
events: payload.events
|
||||
)!
|
||||
|
||||
id := mydb.calendar.set(calendar_obj)!
|
||||
|
||||
return jsonrpc.new_response(request.id, json.encode({'id': id}))
|
||||
}
|
||||
|
||||
pub fn calendar_delete(request jsonrpc.Request) !jsonrpc.Response {
|
||||
payload := jsonrpc.decode_payload[CalendarDeleteArgs](request.params) or { return jsonrpc.invalid_params }
|
||||
|
||||
mut mydb := heromodels.new()!
|
||||
mydb.calendar.delete(payload.id)!
|
||||
|
||||
return jsonrpc.new_response(request.id, json.encode({'success': true, 'id': payload.id}))
|
||||
}
|
||||
|
||||
pub fn calendar_list(request jsonrpc.Request) !jsonrpc.Response {
|
||||
mut mydb := heromodels.new()!
|
||||
calendars := mydb.calendar.list()!
|
||||
|
||||
return jsonrpc.new_response(request.id, json.encode(calendars))
|
||||
}
|
||||
|
||||
@@ -66,9 +66,3 @@ pub fn comment_list(request jsonrpc.Request) !jsonrpc.Response {
|
||||
|
||||
return jsonrpc.new_response(request.id, json.encode(comments))
|
||||
}
|
||||
|
||||
pub fn calendar_get(request jsonrpc.Request) !jsonrpc.Response {
|
||||
payload := jsonrpc.decode_payload[u32](request.params) or { return jsonrpc.invalid_params }
|
||||
result := heromodels.get[heromodels.Calendar](payload) or { return jsonrpc.internal_error }
|
||||
return jsonrpc.new_response(request.id, json.encode(result))
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ pub mut:
|
||||
socket_path string = '/tmp/heromodels'
|
||||
}
|
||||
|
||||
pub fn start_unix_server(handler Handler, params UNIXServerParams) ! {
|
||||
mut server := new_unix_server(handler, params)!
|
||||
server.start()!
|
||||
}
|
||||
|
||||
pub fn new_unix_server(handler Handler, params UNIXServerParams) !&UNIXServer {
|
||||
// Remove existing socket file if it exists
|
||||
if os.exists(params.socket_path) {
|
||||
|
||||
Reference in New Issue
Block a user