persisted metrics

This commit is contained in:
boufni95 2025-01-09 16:03:27 +00:00
parent 0bf7a37b6c
commit 6a22e3439a
9 changed files with 230 additions and 25 deletions

View file

@ -1291,7 +1291,9 @@ The nostr server will send back a message response, and inside the body there wi
- __validate_in_nano__: _number_
### UsageMetricTlv
- __available_chunks__: ARRAY of: _number_
- __base_64_tlvs__: ARRAY of: _string_
- __current_chunk__: _number_
### UsageMetrics
- __apps__: MAP with key: _string_ and value: _[AppUsageMetrics](#AppUsageMetrics)_

View file

@ -555,7 +555,9 @@ type UsageMetric struct {
Validate_in_nano int64 `json:"validate_in_nano"`
}
type UsageMetricTlv struct {
Base_64_tlvs []string `json:"base_64_tlvs"`
Available_chunks []int64 `json:"available_chunks"`
Base_64_tlvs []string `json:"base_64_tlvs"`
Current_chunk int64 `json:"current_chunk"`
}
type UsageMetrics struct {
Apps map[string]AppUsageMetrics `json:"apps"`

View file

@ -3162,23 +3162,36 @@ export const UsageMetricValidate = (o?: UsageMetric, opts: UsageMetricOptions =
}
export type UsageMetricTlv = {
available_chunks: number[]
base_64_tlvs: string[]
current_chunk: number
}
export const UsageMetricTlvOptionalFields: [] = []
export type UsageMetricTlvOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
available_chunks_CustomCheck?: (v: number[]) => boolean
base_64_tlvs_CustomCheck?: (v: string[]) => boolean
current_chunk_CustomCheck?: (v: number) => boolean
}
export const UsageMetricTlvValidate = (o?: UsageMetricTlv, opts: UsageMetricTlvOptions = {}, path: string = 'UsageMetricTlv::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (!Array.isArray(o.available_chunks)) return new Error(`${path}.available_chunks: is not an array`)
for (let index = 0; index < o.available_chunks.length; index++) {
if (typeof o.available_chunks[index] !== 'number') return new Error(`${path}.available_chunks[${index}]: is not a number`)
}
if (opts.available_chunks_CustomCheck && !opts.available_chunks_CustomCheck(o.available_chunks)) return new Error(`${path}.available_chunks: custom check failed`)
if (!Array.isArray(o.base_64_tlvs)) return new Error(`${path}.base_64_tlvs: is not an array`)
for (let index = 0; index < o.base_64_tlvs.length; index++) {
if (typeof o.base_64_tlvs[index] !== 'string') return new Error(`${path}.base_64_tlvs[${index}]: is not a string`)
}
if (opts.base_64_tlvs_CustomCheck && !opts.base_64_tlvs_CustomCheck(o.base_64_tlvs)) return new Error(`${path}.base_64_tlvs: custom check failed`)
if (typeof o.current_chunk !== 'number') return new Error(`${path}.current_chunk: is not a number`)
if (opts.current_chunk_CustomCheck && !opts.current_chunk_CustomCheck(o.current_chunk)) return new Error(`${path}.current_chunk: custom check failed`)
return null
}

View file

@ -35,6 +35,9 @@ message UsageMetric {
message UsageMetricTlv {
repeated string base_64_tlvs = 1;
int64 current_chunk = 2;
repeated int64 available_chunks = 3;
}
message AppUsageMetrics {