global: MASSIVE snapshot

This commit is contained in:
nym21
2026-01-07 01:16:37 +01:00
parent e832ffbe23
commit cb0abc324e
487 changed files with 21155 additions and 13627 deletions

View File

@@ -2,7 +2,7 @@
use std::fmt::Write;
use crate::{Endpoint, Parameter, to_camel_case};
use crate::{Endpoint, Parameter, generators::MANUAL_GENERIC_TYPES, to_camel_case};
/// Generate API methods for the BrkClient class.
pub fn generate_api_methods(output: &mut String, endpoints: &[Endpoint]) {
@@ -12,7 +12,7 @@ pub fn generate_api_methods(output: &mut String, endpoints: &[Endpoint]) {
}
let method_name = endpoint_to_method_name(endpoint);
let return_type = endpoint.response_type.as_deref().unwrap_or("*");
let return_type = normalize_return_type(endpoint.response_type.as_deref().unwrap_or("*"));
writeln!(output, " /**").unwrap();
if let Some(summary) = &endpoint.summary {
@@ -110,3 +110,12 @@ fn build_path_template(path: &str, path_params: &[Parameter]) -> String {
}
result
}
/// Replace generic types with their Any variants in return types.
fn normalize_return_type(return_type: &str) -> String {
let mut result = return_type.to_string();
for type_name in MANUAL_GENERIC_TYPES {
result = result.replace(type_name, &format!("Any{}", type_name));
}
result
}

View File

@@ -49,6 +49,16 @@ class BrkError extends Error {{
}}
}}
/**
* @template T
* @typedef {{Object}} MetricData
* @property {{number}} total - Total number of data points
* @property {{number}} from - Start index (inclusive)
* @property {{number}} to - End index (exclusive)
* @property {{T[]}} data - The metric data
*/
/** @typedef {{MetricData<unknown>}} AnyMetricData */
/**
* @template T
* @typedef {{Object}} MetricEndpoint

View File

@@ -136,9 +136,56 @@ pub fn generate_main_client(
generate_api_methods(output, endpoints);
// Instance method: mergeMetricPatterns
writeln!(output, r#"
/**
* Merge multiple MetricPatterns into a single pattern.
* Throws if any two patterns have overlapping indexes.
* @template T
* @param {{...MetricPattern<T>}} patterns - The patterns to merge
* @returns {{MetricPattern<T>}} A new merged pattern
*/
mergeMetricPatterns(...patterns) {{
if (patterns.length === 0) {{
throw new BrkError('mergeMetricPatterns requires at least one pattern');
}}
if (patterns.length === 1) {{
return patterns[0];
}}
const seenIndexes = /** @type {{Map<Index, string>}} */ (new Map());
const mergedBy = /** @type {{Partial<Record<Index, MetricEndpoint<T>>>}} */ ({{}});
for (const pattern of patterns) {{
for (const index of pattern.indexes()) {{
const existing = seenIndexes.get(index);
if (existing !== undefined) {{
throw new BrkError(`Index '${{index}}' exists in both '${{existing}}' and '${{pattern.name}}'`);
}}
seenIndexes.set(index, pattern.name);
Object.defineProperty(mergedBy, index, {{
get() {{ return pattern.get(index); }},
enumerable: true,
configurable: true,
}});
}}
}}
const allIndexes = /** @type {{Index[]}} */ ([...seenIndexes.keys()]);
const firstName = patterns[0].name;
return {{
name: firstName,
by: mergedBy,
indexes() {{ return allIndexes; }},
get(index) {{ return mergedBy[index]; }},
}};
}}
"#).unwrap();
writeln!(output, "}}\n").unwrap();
writeln!(output, "export {{ BrkClient, BrkClientBase, BrkError }};").unwrap();
writeln!(output, "export {{ BrkClient, BrkError }};").unwrap();
}
fn generate_tree_initializer(

View File

@@ -4,7 +4,7 @@ use std::fmt::Write;
use serde_json::Value;
use crate::{TypeSchemas, ref_to_type_name, to_camel_case};
use crate::{TypeSchemas, generators::MANUAL_GENERIC_TYPES, ref_to_type_name, to_camel_case};
/// Generate JSDoc type definitions from OpenAPI schemas.
pub fn generate_type_definitions(output: &mut String, schemas: &TypeSchemas) {
@@ -15,6 +15,10 @@ pub fn generate_type_definitions(output: &mut String, schemas: &TypeSchemas) {
writeln!(output, "// Type definitions\n").unwrap();
for (name, schema) in schemas {
if MANUAL_GENERIC_TYPES.contains(&name.as_str()) {
continue;
}
let js_type = schema_to_js_type(schema, Some(name));
if is_primitive_alias(schema) {