global: snapshot

This commit is contained in:
nym21
2026-01-14 16:38:53 +01:00
parent ddb1db7a8e
commit d75c2a881b
226 changed files with 7776 additions and 20942 deletions

View File

@@ -110,7 +110,7 @@ class BrkError extends Error {{
* @typedef {{Object}} MetricPattern
* @property {{string}} name - The metric name
* @property {{Readonly<Partial<Record<Index, MetricEndpointBuilder<T>>>>}} by - Index endpoints as lazy getters. Access via .by.dateindex or .by['dateindex']
* @property {{() => Index[]}} indexes - Get the list of available indexes
* @property {{() => readonly Index[]}} indexes - Get the list of available indexes
* @property {{(index: Index) => MetricEndpointBuilder<T>|undefined}} get - Get an endpoint for a specific index
*/
@@ -333,14 +333,14 @@ pub fn generate_index_accessors(output: &mut String, patterns: &[IndexSetPattern
// Generate index array constants (e.g., _i1 = ["dateindex", "height"])
for (i, pattern) in patterns.iter().enumerate() {
write!(output, "const _i{} = [", i + 1).unwrap();
write!(output, "const _i{} = /** @type {{const}} */ ([", i + 1).unwrap();
for (j, index) in pattern.indexes.iter().enumerate() {
if j > 0 {
write!(output, ", ").unwrap();
}
write!(output, "\"{}\"", index.serialize_long()).unwrap();
}
writeln!(output, "];").unwrap();
writeln!(output, "]);").unwrap();
}
writeln!(output).unwrap();
@@ -352,11 +352,10 @@ pub fn generate_index_accessors(output: &mut String, patterns: &[IndexSetPattern
* @template T
* @param {{BrkClientBase}} client
* @param {{string}} name - The metric vec name
* @param {{readonly string[]}} indexes - The supported indexes
* @returns {{MetricPattern<T>}}
* @param {{readonly Index[]}} indexes - The supported indexes
*/
function _mp(client, name, indexes) {{
const by = {{}};
const by = /** @type {{any}} */ ({{}});
for (const idx of indexes) {{
Object.defineProperty(by, idx, {{
get() {{ return _endpoint(client, name, idx); }},
@@ -368,6 +367,7 @@ function _mp(client, name, indexes) {{
name,
by,
indexes() {{ return indexes; }},
/** @param {{Index}} index */
get(index) {{ return indexes.includes(index) ? _endpoint(client, name, index) : undefined; }}
}};
}}
@@ -392,7 +392,7 @@ function _mp(client, name, indexes) {{
writeln!(
output,
"/** @template T @typedef {{{{ name: string, by: {}, indexes: () => Index[], get: (index: Index) => MetricEndpointBuilder<T>|undefined }}}} {} */",
"/** @template T @typedef {{{{ name: string, by: {}, indexes: () => readonly Index[], get: (index: Index) => MetricEndpointBuilder<T>|undefined }}}} {} */",
by_type, pattern.name
)
.unwrap();

View File

@@ -2,7 +2,10 @@ use std::{collections::BTreeMap, io};
use crate::ref_to_type_name;
use oas3::Spec;
use oas3::spec::{ObjectOrReference, ObjectSchema, Operation, ParameterIn, PathItem, Schema, SchemaType, SchemaTypeSet};
use oas3::spec::{
ObjectOrReference, ObjectSchema, Operation, ParameterIn, PathItem, Schema, SchemaType,
SchemaTypeSet,
};
use serde_json::Value;
/// Type schema extracted from OpenAPI components
@@ -156,7 +159,7 @@ pub fn extract_endpoints(spec: &Spec) -> Vec<Endpoint> {
for (path, path_item) in paths {
for (method, operation) in get_operations(path_item) {
if let Some(endpoint) = extract_endpoint(path, &method, operation) {
if let Some(endpoint) = extract_endpoint(path, method, operation) {
endpoints.push(endpoint);
}
}
@@ -218,11 +221,7 @@ fn extract_path_parameters(path: &str, operation: &Operation) -> Vec<Parameter>
// Extract parameter names from the path in order (e.g., "/api/metric/{metric}/{index}" -> ["metric", "index"])
let path_order: Vec<&str> = path
.split('/')
.filter_map(|segment| {
segment
.strip_prefix('{')
.and_then(|s| s.strip_suffix('}'))
})
.filter_map(|segment| segment.strip_prefix('{').and_then(|s| s.strip_suffix('}')))
.collect();
// Get all path parameters from the operation