vovk-rust 0.0.1-draft.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/index.d.ts +16 -0
- package/index.js +534 -0
- package/package.json +33 -0
- package/requirements.txt +4 -0
- package/template/Cargo.toml.ejs +83 -0
- package/template/README.md.ejs +35 -0
- package/template/src/http_request.rs +488 -0
- package/template/src/lib.rs.ejs +81 -0
- package/template/src/read_full_schema.rs +88 -0
- package/vovk.config.test.mjs +26 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
use std::fs::File;
|
|
2
|
+
use std::io::BufReader;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
use std::collections::HashMap;
|
|
5
|
+
use serde::{Deserialize, Serialize};
|
|
6
|
+
use serde_json::Value;
|
|
7
|
+
|
|
8
|
+
/// Validation schema structure
|
|
9
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
10
|
+
pub struct ValidationSchema {
|
|
11
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
12
|
+
pub body: Option<Value>,
|
|
13
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
14
|
+
pub query: Option<Value>,
|
|
15
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
16
|
+
pub params: Option<Value>,
|
|
17
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
18
|
+
pub output: Option<Value>,
|
|
19
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
20
|
+
pub iteration: Option<Value>,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// OpenAPI documentation
|
|
24
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
25
|
+
pub struct OpenApiDocs {
|
|
26
|
+
pub summary: Option<String>,
|
|
27
|
+
pub description: Option<String>,
|
|
28
|
+
#[serde(flatten)]
|
|
29
|
+
pub additional_fields: HashMap<String, Value>,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Handler schema
|
|
33
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
34
|
+
#[allow(non_snake_case)]
|
|
35
|
+
pub struct HandlerSchema {
|
|
36
|
+
pub path: String,
|
|
37
|
+
pub httpMethod: String,
|
|
38
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
39
|
+
pub validation: Option<ValidationSchema>,
|
|
40
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
41
|
+
pub openapi: Option<OpenApiDocs>,
|
|
42
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
43
|
+
pub misc: Option<HashMap<String, Value>>,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Controller schema
|
|
47
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
48
|
+
#[allow(non_snake_case)]
|
|
49
|
+
pub struct ControllerSchema {
|
|
50
|
+
pub rpcModuleName: String,
|
|
51
|
+
pub originalControllerName: String,
|
|
52
|
+
pub prefix: String,
|
|
53
|
+
pub handlers: HashMap<String, HandlerSchema>,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Schema for individual segment
|
|
57
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
58
|
+
#[allow(non_snake_case)]
|
|
59
|
+
pub struct VovkSegmentSchema {
|
|
60
|
+
pub emitSchema: bool,
|
|
61
|
+
pub segmentName: String,
|
|
62
|
+
pub controllers: HashMap<String, ControllerSchema>,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Complete Vovk schema with meta and multiple segments
|
|
66
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
67
|
+
pub struct VovkSchema {
|
|
68
|
+
pub meta: HashMap<String, Value>,
|
|
69
|
+
pub segments: HashMap<String, VovkSegmentSchema>,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// Read the complete Vovk schema from a JSON file
|
|
73
|
+
pub fn read_full_schema() -> Result<VovkSchema, Box<dyn std::error::Error>> {
|
|
74
|
+
// Get the path to the project root (where Cargo.toml is)
|
|
75
|
+
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
76
|
+
|
|
77
|
+
// Build the full path to the data file
|
|
78
|
+
let json_path = Path::new(manifest_dir).join("data/schema.json");
|
|
79
|
+
|
|
80
|
+
// Open the file
|
|
81
|
+
let file = File::open(&json_path)?;
|
|
82
|
+
let reader = BufReader::new(file);
|
|
83
|
+
|
|
84
|
+
// Parse the JSON
|
|
85
|
+
let schema: VovkSchema = serde_json::from_reader(reader)?;
|
|
86
|
+
|
|
87
|
+
Ok(schema)
|
|
88
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @type {import('vovk').VovkConfig} */
|
|
3
|
+
const vovkConfig = {
|
|
4
|
+
logLevel: 'debug',
|
|
5
|
+
origin: `http://localhost:${process.env.PORT}`,
|
|
6
|
+
clientTemplateDefs: {
|
|
7
|
+
rs: {
|
|
8
|
+
extends: 'rs',
|
|
9
|
+
templatePath: '../packages/vovk-rust/template/',
|
|
10
|
+
composedClient: {
|
|
11
|
+
outDir: '../packages/vovk-rust/generated_rust_client',
|
|
12
|
+
package: {
|
|
13
|
+
name: 'generated_rust_client',
|
|
14
|
+
version: '0.1.0',
|
|
15
|
+
license: 'MIT',
|
|
16
|
+
description: 'Vovk Rust Client',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
composedClient: {
|
|
22
|
+
fromTemplates: ['rs'],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default vovkConfig;
|