mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-20 14:54:47 -07:00
global: snapshot
This commit is contained in:
15
Cargo.lock
generated
15
Cargo.lock
generated
@@ -393,6 +393,7 @@ dependencies = [
|
|||||||
"brk_parser",
|
"brk_parser",
|
||||||
"brk_query",
|
"brk_query",
|
||||||
"brk_server",
|
"brk_server",
|
||||||
|
"brk_state",
|
||||||
"brk_store",
|
"brk_store",
|
||||||
"brk_vec",
|
"brk_vec",
|
||||||
]
|
]
|
||||||
@@ -434,6 +435,7 @@ dependencies = [
|
|||||||
"brk_indexer",
|
"brk_indexer",
|
||||||
"brk_logger",
|
"brk_logger",
|
||||||
"brk_parser",
|
"brk_parser",
|
||||||
|
"brk_state",
|
||||||
"brk_vec",
|
"brk_vec",
|
||||||
"clap",
|
"clap",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -583,6 +585,19 @@ dependencies = [
|
|||||||
"zip",
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "brk_state"
|
||||||
|
version = "0.0.40"
|
||||||
|
dependencies = [
|
||||||
|
"brk_core",
|
||||||
|
"brk_store",
|
||||||
|
"brk_vec",
|
||||||
|
"rayon",
|
||||||
|
"serde",
|
||||||
|
"zerocopy",
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "brk_store"
|
name = "brk_store"
|
||||||
version = "0.0.40"
|
version = "0.0.40"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ brk_logger = { version = "0", path = "crates/brk_logger" }
|
|||||||
brk_parser = { version = "0", path = "crates/brk_parser" }
|
brk_parser = { version = "0", path = "crates/brk_parser" }
|
||||||
brk_query = { version = "0", path = "crates/brk_query" }
|
brk_query = { version = "0", path = "crates/brk_query" }
|
||||||
brk_server = { version = "0", path = "crates/brk_server" }
|
brk_server = { version = "0", path = "crates/brk_server" }
|
||||||
|
brk_state = { version = "0", path = "crates/brk_state" }
|
||||||
brk_store = { version = "0", path = "crates/brk_store" }
|
brk_store = { version = "0", path = "crates/brk_store" }
|
||||||
brk_vec = { version = "0", path = "crates/brk_vec" }
|
brk_vec = { version = "0", path = "crates/brk_vec" }
|
||||||
byteview = "0.7.0"
|
byteview = "0.7.0"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ full = [
|
|||||||
"parser",
|
"parser",
|
||||||
"query",
|
"query",
|
||||||
"server",
|
"server",
|
||||||
|
"state",
|
||||||
"store",
|
"store",
|
||||||
"vec",
|
"vec",
|
||||||
]
|
]
|
||||||
@@ -30,6 +31,7 @@ logger = ["brk_logger"]
|
|||||||
parser = ["brk_parser"]
|
parser = ["brk_parser"]
|
||||||
query = ["brk_query"]
|
query = ["brk_query"]
|
||||||
server = ["brk_server"]
|
server = ["brk_server"]
|
||||||
|
state = ["brk_state"]
|
||||||
store = ["brk_store"]
|
store = ["brk_store"]
|
||||||
vec = ["brk_vec"]
|
vec = ["brk_vec"]
|
||||||
|
|
||||||
@@ -44,6 +46,7 @@ brk_logger = { workspace = true, optional = true }
|
|||||||
brk_parser = { workspace = true, optional = true }
|
brk_parser = { workspace = true, optional = true }
|
||||||
brk_query = { workspace = true, optional = true }
|
brk_query = { workspace = true, optional = true }
|
||||||
brk_server = { workspace = true, optional = true }
|
brk_server = { workspace = true, optional = true }
|
||||||
|
brk_state = { workspace = true, optional = true }
|
||||||
brk_store = { workspace = true, optional = true }
|
brk_store = { workspace = true, optional = true }
|
||||||
brk_vec = { workspace = true, optional = true }
|
brk_vec = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ pub use brk_query as query;
|
|||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use brk_server as server;
|
pub use brk_server as server;
|
||||||
|
|
||||||
|
#[cfg(feature = "state")]
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use brk_state as state;
|
||||||
|
|
||||||
#[cfg(feature = "store")]
|
#[cfg(feature = "store")]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use brk_store as store;
|
pub use brk_store as store;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ brk_fetcher = { workspace = true }
|
|||||||
brk_indexer = { workspace = true }
|
brk_indexer = { workspace = true }
|
||||||
brk_logger = { workspace = true }
|
brk_logger = { workspace = true }
|
||||||
brk_parser = { workspace = true }
|
brk_parser = { workspace = true }
|
||||||
|
brk_state = { workspace = true }
|
||||||
brk_vec = { workspace = true }
|
brk_vec = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
clap_derive = { workspace = true }
|
clap_derive = { workspace = true }
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use brk_fetcher::Fetcher;
|
|||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_vec::{AnyCollectableVec, Compressed, Computation};
|
use brk_vec::{AnyCollectableVec, Compressed, Computation};
|
||||||
|
|
||||||
mod states;
|
|
||||||
mod stores;
|
mod stores;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod vecs;
|
mod vecs;
|
||||||
|
|||||||
@@ -5,18 +5,16 @@ use brk_core::{
|
|||||||
};
|
};
|
||||||
use brk_exit::Exit;
|
use brk_exit::Exit;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
|
use brk_state::{CohortState, RealizedState};
|
||||||
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation, EagerVec, VecIterator};
|
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation, EagerVec, VecIterator};
|
||||||
|
|
||||||
use crate::{
|
use crate::vecs::{
|
||||||
states::{CohortState, RealizedState},
|
Indexes, fetched,
|
||||||
vecs::{
|
grouped::{
|
||||||
Indexes, fetched,
|
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
|
||||||
grouped::{
|
StorableVecGeneatorOptions,
|
||||||
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
|
|
||||||
StorableVecGeneatorOptions,
|
|
||||||
},
|
|
||||||
indexes,
|
|
||||||
},
|
},
|
||||||
|
indexes,
|
||||||
};
|
};
|
||||||
|
|
||||||
const VERSION: Version = Version::ZERO;
|
const VERSION: Version = Version::ZERO;
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ use brk_vec::{
|
|||||||
GenericStoredVec, StoredIndex, StoredVec, UnsafeSlice, VecIterator,
|
GenericStoredVec, StoredIndex, StoredVec, UnsafeSlice, VecIterator,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use outputs::OutputCohorts;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::states::{
|
use brk_state::{
|
||||||
BlockState, OutputFilter, Outputs, OutputsByEpoch, OutputsByFrom, OutputsByRange,
|
BlockState, OutputFilter, Outputs, OutputsByEpoch, OutputsByFrom, OutputsByRange,
|
||||||
OutputsBySize, OutputsBySpendableType, OutputsByTerm, OutputsByUpTo, SupplyState, Transacted,
|
OutputsBySize, OutputsBySpendableType, OutputsByTerm, OutputsByUpTo, SupplyState, Transacted,
|
||||||
};
|
};
|
||||||
@@ -22,6 +23,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub mod cohort;
|
pub mod cohort;
|
||||||
|
mod outputs;
|
||||||
|
|
||||||
const VERSION: Version = Version::ZERO;
|
const VERSION: Version = Version::ZERO;
|
||||||
const BYSIZE_VERSION: Version = Version::ONE;
|
const BYSIZE_VERSION: Version = Version::ONE;
|
||||||
|
|||||||
@@ -1,69 +1,20 @@
|
|||||||
use brk_vec::StoredIndex;
|
|
||||||
use rayon::prelude::*;
|
|
||||||
use std::{collections::BTreeMap, ops::ControlFlow};
|
use std::{collections::BTreeMap, ops::ControlFlow};
|
||||||
|
|
||||||
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Timestamp};
|
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Timestamp};
|
||||||
|
use brk_state::{BlockState, OutputFilter, Outputs, Transacted};
|
||||||
|
use brk_vec::StoredIndex;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
mod by_epoch;
|
use super::cohort;
|
||||||
mod by_from;
|
|
||||||
mod by_range;
|
|
||||||
mod by_size;
|
|
||||||
mod by_spendable_type;
|
|
||||||
mod by_term;
|
|
||||||
mod by_type;
|
|
||||||
mod by_unspendable_type;
|
|
||||||
mod by_up_to;
|
|
||||||
// mod by_value;
|
|
||||||
mod filter;
|
|
||||||
|
|
||||||
pub use by_epoch::*;
|
pub trait OutputCohorts {
|
||||||
pub use by_from::*;
|
fn tick_tock_next_block(&mut self, chain_state: &[BlockState], timestamp: Timestamp);
|
||||||
pub use by_range::*;
|
fn send(&mut self, height_to_sent: BTreeMap<Height, Transacted>, chain_state: &[BlockState]);
|
||||||
pub use by_size::*;
|
fn receive(&mut self, received: Transacted, height: Height, price: Option<Dollars>);
|
||||||
pub use by_spendable_type::*;
|
|
||||||
pub use by_term::*;
|
|
||||||
pub use by_type::*;
|
|
||||||
pub use by_unspendable_type::*;
|
|
||||||
pub use by_up_to::*;
|
|
||||||
// pub use by_value::*;
|
|
||||||
pub use filter::*;
|
|
||||||
|
|
||||||
use crate::vecs;
|
|
||||||
|
|
||||||
use super::{BlockState, Transacted};
|
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
|
||||||
pub struct Outputs<T> {
|
|
||||||
pub all: T,
|
|
||||||
pub by_term: OutputsByTerm<T>,
|
|
||||||
pub by_up_to: OutputsByUpTo<T>,
|
|
||||||
pub by_from: OutputsByFrom<T>,
|
|
||||||
pub by_range: OutputsByRange<T>,
|
|
||||||
pub by_epoch: OutputsByEpoch<T>,
|
|
||||||
pub by_type: OutputsBySpendableType<T>,
|
|
||||||
pub by_size: OutputsBySize<T>,
|
|
||||||
// // Needs whole UTXO set, TODO later
|
|
||||||
// // pub by_value: OutputsByValue<T>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Outputs<T> {
|
impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
|
||||||
pub fn as_mut_vec(&mut self) -> Vec<&mut T> {
|
fn tick_tock_next_block(&mut self, chain_state: &[BlockState], timestamp: Timestamp) {
|
||||||
[&mut self.all]
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.by_term.as_mut_vec())
|
|
||||||
.chain(self.by_up_to.as_mut_vec())
|
|
||||||
.chain(self.by_from.as_mut_vec())
|
|
||||||
.chain(self.by_range.as_mut_vec())
|
|
||||||
.chain(self.by_epoch.as_mut_vec())
|
|
||||||
.chain(self.by_size.as_mut_vec())
|
|
||||||
.chain(self.by_type.as_mut_vec())
|
|
||||||
// // .chain(self.by_value.as_mut_vec())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Outputs<(OutputFilter, vecs::statefull::cohort::Vecs)> {
|
|
||||||
pub fn tick_tock_next_block(&mut self, chain_state: &[BlockState], timestamp: Timestamp) {
|
|
||||||
if chain_state.is_empty() {
|
if chain_state.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,11 +68,7 @@ impl Outputs<(OutputFilter, vecs::statefull::cohort::Vecs)> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(
|
fn send(&mut self, height_to_sent: BTreeMap<Height, Transacted>, chain_state: &[BlockState]) {
|
||||||
&mut self,
|
|
||||||
height_to_sent: BTreeMap<Height, Transacted>,
|
|
||||||
chain_state: &[BlockState],
|
|
||||||
) {
|
|
||||||
let mut time_based_vecs = self
|
let mut time_based_vecs = self
|
||||||
.by_term
|
.by_term
|
||||||
.as_mut_vec()
|
.as_mut_vec()
|
||||||
@@ -195,7 +142,7 @@ impl Outputs<(OutputFilter, vecs::statefull::cohort::Vecs)> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive(&mut self, received: Transacted, height: Height, price: Option<Dollars>) {
|
fn receive(&mut self, received: Transacted, height: Height, price: Option<Dollars>) {
|
||||||
let supply_state = received.spendable_supply;
|
let supply_state = received.spendable_supply;
|
||||||
|
|
||||||
[
|
[
|
||||||
@@ -233,36 +180,3 @@ impl Outputs<(OutputFilter, vecs::statefull::cohort::Vecs)> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Outputs<(OutputFilter, T)> {
|
|
||||||
pub fn vecs(&self) -> Vec<&T> {
|
|
||||||
[&self.all.1]
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.by_term.vecs())
|
|
||||||
.chain(self.by_up_to.vecs())
|
|
||||||
.chain(self.by_from.vecs())
|
|
||||||
.chain(self.by_range.vecs())
|
|
||||||
.chain(self.by_epoch.vecs())
|
|
||||||
.chain(self.by_size.vecs())
|
|
||||||
// // .chain(self.by_value.vecs())
|
|
||||||
.chain(self.by_type.vecs())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<Outputs<T>> for Outputs<(OutputFilter, T)> {
|
|
||||||
fn from(value: Outputs<T>) -> Self {
|
|
||||||
Self {
|
|
||||||
all: (OutputFilter::All, value.all),
|
|
||||||
by_term: OutputsByTerm::from(value.by_term),
|
|
||||||
by_up_to: OutputsByUpTo::from(value.by_up_to),
|
|
||||||
by_from: OutputsByFrom::from(value.by_from),
|
|
||||||
by_range: OutputsByRange::from(value.by_range),
|
|
||||||
by_epoch: OutputsByEpoch::from(value.by_epoch),
|
|
||||||
by_size: OutputsBySize::from(value.by_size),
|
|
||||||
// // Needs whole UTXO set, TODO later
|
|
||||||
// // by_value: OutputsByValue<T>,
|
|
||||||
by_type: OutputsBySpendableType::from(value.by_type),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
16
crates/brk_state/Cargo.toml
Normal file
16
crates/brk_state/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "brk_state"
|
||||||
|
description = "States used primarily by the computer"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
brk_core = { workspace = true }
|
||||||
|
brk_vec = { workspace = true }
|
||||||
|
brk_store = { workspace = true }
|
||||||
|
rayon = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
zerocopy = { workspace = true }
|
||||||
|
zerocopy-derive = { workspace = true }
|
||||||
86
crates/brk_state/src/outputs/mod.rs
Normal file
86
crates/brk_state/src/outputs/mod.rs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
mod by_epoch;
|
||||||
|
mod by_from;
|
||||||
|
mod by_range;
|
||||||
|
mod by_size;
|
||||||
|
mod by_spendable_type;
|
||||||
|
mod by_term;
|
||||||
|
mod by_type;
|
||||||
|
mod by_unspendable_type;
|
||||||
|
mod by_up_to;
|
||||||
|
// mod by_value;
|
||||||
|
mod filter;
|
||||||
|
|
||||||
|
pub use by_epoch::*;
|
||||||
|
pub use by_from::*;
|
||||||
|
pub use by_range::*;
|
||||||
|
pub use by_size::*;
|
||||||
|
pub use by_spendable_type::*;
|
||||||
|
pub use by_term::*;
|
||||||
|
pub use by_type::*;
|
||||||
|
pub use by_unspendable_type::*;
|
||||||
|
pub use by_up_to::*;
|
||||||
|
// pub use by_value::*;
|
||||||
|
pub use filter::*;
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
|
pub struct Outputs<T> {
|
||||||
|
pub all: T,
|
||||||
|
pub by_term: OutputsByTerm<T>,
|
||||||
|
pub by_up_to: OutputsByUpTo<T>,
|
||||||
|
pub by_from: OutputsByFrom<T>,
|
||||||
|
pub by_range: OutputsByRange<T>,
|
||||||
|
pub by_epoch: OutputsByEpoch<T>,
|
||||||
|
pub by_type: OutputsBySpendableType<T>,
|
||||||
|
pub by_size: OutputsBySize<T>,
|
||||||
|
// // Needs whole UTXO set, TODO later
|
||||||
|
// // pub by_value: OutputsByValue<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Outputs<T> {
|
||||||
|
pub fn as_mut_vec(&mut self) -> Vec<&mut T> {
|
||||||
|
[&mut self.all]
|
||||||
|
.into_iter()
|
||||||
|
.chain(self.by_term.as_mut_vec())
|
||||||
|
.chain(self.by_up_to.as_mut_vec())
|
||||||
|
.chain(self.by_from.as_mut_vec())
|
||||||
|
.chain(self.by_range.as_mut_vec())
|
||||||
|
.chain(self.by_epoch.as_mut_vec())
|
||||||
|
.chain(self.by_size.as_mut_vec())
|
||||||
|
.chain(self.by_type.as_mut_vec())
|
||||||
|
// // .chain(self.by_value.as_mut_vec())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Outputs<(OutputFilter, T)> {
|
||||||
|
pub fn vecs(&self) -> Vec<&T> {
|
||||||
|
[&self.all.1]
|
||||||
|
.into_iter()
|
||||||
|
.chain(self.by_term.vecs())
|
||||||
|
.chain(self.by_up_to.vecs())
|
||||||
|
.chain(self.by_from.vecs())
|
||||||
|
.chain(self.by_range.vecs())
|
||||||
|
.chain(self.by_epoch.vecs())
|
||||||
|
.chain(self.by_size.vecs())
|
||||||
|
// // .chain(self.by_value.vecs())
|
||||||
|
.chain(self.by_type.vecs())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<Outputs<T>> for Outputs<(OutputFilter, T)> {
|
||||||
|
fn from(value: Outputs<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
all: (OutputFilter::All, value.all),
|
||||||
|
by_term: OutputsByTerm::from(value.by_term),
|
||||||
|
by_up_to: OutputsByUpTo::from(value.by_up_to),
|
||||||
|
by_from: OutputsByFrom::from(value.by_from),
|
||||||
|
by_range: OutputsByRange::from(value.by_range),
|
||||||
|
by_epoch: OutputsByEpoch::from(value.by_epoch),
|
||||||
|
by_size: OutputsBySize::from(value.by_size),
|
||||||
|
// // Needs whole UTXO set, TODO later
|
||||||
|
// // by_value: OutputsByValue<T>,
|
||||||
|
by_type: OutputsBySpendableType::from(value.by_type),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -875,9 +875,9 @@ function createPartialOptions(colors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {"-ratio"} RatioCapSuffix
|
* @typedef {"-ratio-zscore"} RatioZScoreCapSuffix
|
||||||
* @typedef {EndsWith<RatioCapSuffix>} VecIdRatioCap
|
* @typedef {EndsWith<RatioZScoreCapSuffix>} VecIdRatioZScoreCap
|
||||||
* @typedef {WithoutSuffix<VecIdRatioCap, RatioCapSuffix>} VecIdRatioCapBase
|
* @typedef {WithoutSuffix<VecIdRatioZScoreCap, RatioZScoreCapSuffix>} VecIdRatioZScoreCapBase
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -886,7 +886,7 @@ function createPartialOptions(colors) {
|
|||||||
* @param {string} args.name
|
* @param {string} args.name
|
||||||
* @param {string} args.legend
|
* @param {string} args.legend
|
||||||
* @param {string} args.title
|
* @param {string} args.title
|
||||||
* @param {VecIdRatioCapBase} args.key
|
* @param {VecIdRatioZScoreCapBase} args.key
|
||||||
* @param {Color} [args.color]
|
* @param {Color} [args.color]
|
||||||
*/
|
*/
|
||||||
function createPriceWithRatio({ name, title, legend, key, color }) {
|
function createPriceWithRatio({ name, title, legend, key, color }) {
|
||||||
@@ -1230,7 +1230,7 @@ function createPartialOptions(colors) {
|
|||||||
color: useGroupName ? color : colors.green,
|
color: useGroupName ? color : colors.green,
|
||||||
}),
|
}),
|
||||||
createBaseSeries({
|
createBaseSeries({
|
||||||
key: `${key}realized-profit-sum`,
|
key: `${key}realized-profit`,
|
||||||
name: useGroupName ? name : "Profit",
|
name: useGroupName ? name : "Profit",
|
||||||
color: useGroupName ? color : colors.green,
|
color: useGroupName ? color : colors.green,
|
||||||
}),
|
}),
|
||||||
@@ -1249,7 +1249,7 @@ function createPartialOptions(colors) {
|
|||||||
color: useGroupName ? color : colors.red,
|
color: useGroupName ? color : colors.red,
|
||||||
}),
|
}),
|
||||||
createBaseSeries({
|
createBaseSeries({
|
||||||
key: `${key}realized-loss-sum`,
|
key: `${key}realized-loss`,
|
||||||
name: useGroupName ? name : "Loss",
|
name: useGroupName ? name : "Loss",
|
||||||
color: useGroupName ? color : colors.red,
|
color: useGroupName ? color : colors.red,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
const version = "v1";
|
const version = "v1";
|
||||||
|
|
||||||
self.addEventListener("install", (_event) => {
|
/** @type {ServiceWorkerGlobalScope} */
|
||||||
|
const sw = /** @type {any} */ (self);
|
||||||
|
|
||||||
|
sw.addEventListener("install", (_event) => {
|
||||||
console.log("sw: install");
|
console.log("sw: install");
|
||||||
// The worker skips waiting and becomes active immediately
|
sw.skipWaiting();
|
||||||
self.skipWaiting();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("activate", (event) => {
|
sw.addEventListener("activate", (event) => {
|
||||||
console.log("sw: active");
|
console.log("sw: active");
|
||||||
event.waitUntil(
|
event.waitUntil(sw.clients.claim());
|
||||||
// Claim clients, so the SW starts controlling pages immediately
|
|
||||||
self.clients.claim(),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("fetch", (_event) => {
|
sw.addEventListener("fetch", (event) => {
|
||||||
const event = /** @type {any} */ (_event);
|
|
||||||
|
|
||||||
/** @type {Request} */
|
|
||||||
let request = event.request;
|
let request = event.request;
|
||||||
const method = request.method;
|
const method = request.method;
|
||||||
let url = request.url;
|
let url = request.url;
|
||||||
@@ -67,7 +63,13 @@ self.addEventListener("fetch", (_event) => {
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log("service-worker: offline");
|
console.log("service-worker: offline");
|
||||||
|
|
||||||
return cachedResponse;
|
return (
|
||||||
|
cachedResponse ||
|
||||||
|
new Response("Offline", {
|
||||||
|
status: 503,
|
||||||
|
statusText: "Service Unavailable",
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"outDir": "/tmp/kibo"
|
"outDir": "/tmp/kibo",
|
||||||
|
"lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"]
|
||||||
},
|
},
|
||||||
"exclude": ["assets", "packages", "ignore"]
|
"exclude": ["assets", "packages", "ignore"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user