actr-web-protoc-codegen 0.3.1

Protoc plugin for generating actr-web code from protobuf definitions
Documentation
//! Code generation templates.

use handlebars::Handlebars;

/// Initialize the template engine.
#[allow(dead_code)]
pub fn init_templates() -> Handlebars<'static> {
    // Register built-in templates.
    // TODO: Add concrete templates.

    Handlebars::new()
}

/// Built-in Rust actor template.
#[allow(dead_code)]
pub const RUST_ACTOR_TEMPLATE: &str = r#"
//! Auto-generated actor code
//! Service: {{service_name}}
//! Package: {{package}}
//!
//! Do not edit this file manually.

use wasm_bindgen::prelude::*;
use serde::{Serialize, Deserialize};

/// {{service_name}} Actor
#[wasm_bindgen]
pub struct {{service_name}}Actor {
    // Actor state
}

#[wasm_bindgen]
impl {{service_name}}Actor {
    /// Create a new actor instance.
    #[wasm_bindgen(constructor)]
    pub fn new() -> Self {
        Self {}
    }

    {{#each methods}}
    /// {{this.name}} method.
    pub async fn {{this.name}}(&self, request: {{this.input_type}}) -> Result<{{this.output_type}}, JsValue> {
        // TODO: Implement method logic.
        unimplemented!()
    }
    {{/each}}
}
"#;

/// Built-in TypeScript type template.
#[allow(dead_code)]
pub const TS_TYPES_TEMPLATE: &str = r#"
/**
 * Auto-generated type definitions
 * Service: {{service_name}}
 * Package: {{package}}
 *
 * Do not edit this file manually.
 */

{{#each messages}}
export interface {{this.name}} {
  {{#each this.fields}}
  {{this.name}}{{#if this.is_optional}}?{{/if}}: {{this.field_type}}{{#if this.is_repeated}}[]{{/if}};
  {{/each}}
}
{{/each}}
"#;

/// Built-in ActorRef template.
#[allow(dead_code)]
pub const ACTOR_REF_TEMPLATE: &str = r#"
/**
 * Auto-generated ActorRef wrapper
 * Service: {{service_name}}
 *
 * Do not edit this file manually.
 */

import { ActorRef } from '@actr/web';
import type { {{#each messages}}{{this.name}}, {{/each}} } from './{{file_name}}.types';

/**
 * {{service_name}} actor reference
 */
export class {{service_name}}ActorRef extends ActorRef {
  /**
   * Create a new ActorRef instance
   */
  constructor(actorId: string) {
    super(actorId);
  }

  {{#each methods}}
  /**
   * {{this.name}} method
   */
  async {{this.name}}(request: {{this.input_type}}): Promise<{{this.output_type}}> {
    return this.call('{{../service_name}}', '{{this.name}}', request);
  }
  {{/each}}

  {{#each streams}}
  /**
   * Subscribe to the {{this.name}} stream
   */
  subscribe{{this.name}}(callback: (data: {{this.stream_type}}) => void): () => void {
    return this.subscribe('{{this.topic}}', callback);
  }
  {{/each}}
}
"#;