general: snapshot

This commit is contained in:
k
2024-07-20 23:13:41 +02:00
parent d8a5b4a2e6
commit a145b35ad1
100 changed files with 5402 additions and 2967 deletions

View File

@@ -12,22 +12,24 @@ export function createScaleDatasets<Scale extends ResourceScale>({
type Key = keyof typeof groupedKeysToURLPath;
type ResourceData = ReturnType<typeof createResourceDataset<Scale>>;
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
type ResourceDatasets = Record<Exclude<Key, "price">, ResourceData>;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as unknown as Exclude<Key, "ohlc">] = createResourceDataset({
scale,
path: groupedKeysToURLPath[key as Key] as any,
});
if ((key as Key) !== "price") {
datasets[key as unknown as Exclude<Key, "price">] = createResourceDataset(
{
scale,
path: groupedKeysToURLPath[key as Key] as any,
},
);
}
}
const price = createResourceDataset<Scale, OHLC>({
scale,
path: `/${scale}-to-ohlc`,
path: `/${scale}-to-price`,
});
Object.assign(datasets, { price });

View File

@@ -10,13 +10,13 @@ export function createDateDatasets({
type Key = keyof typeof groupedKeysToURLPath;
type ResourceData = ReturnType<typeof createResourceDataset<"date">>;
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
type ResourceDatasets = Record<Exclude<Key, "price">, ResourceData>;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"date">({
if ((key as Key) !== "price") {
datasets[key as Exclude<Key, "price">] = createResourceDataset<"date">({
scale: "date",
path: groupedKeysToURLPath[key as Key],
});
@@ -25,7 +25,7 @@ export function createDateDatasets({
const price = createResourceDataset<"date", OHLC>({
scale: "date",
path: "/date-to-ohlc",
path: "/date-to-price",
});
Object.assign(datasets, { price });

View File

@@ -8,13 +8,13 @@ export function createHeightDatasets({
type Key = keyof typeof groupedKeysToURLPath;
type ResourceData = ReturnType<typeof createResourceDataset<"height">>;
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
type ResourceDatasets = Record<Exclude<Key, "price">, ResourceData>;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"height">({
if ((key as Key) !== "price") {
datasets[key as Exclude<Key, "price">] = createResourceDataset<"height">({
scale: "height",
path: groupedKeysToURLPath[key as Key],
});
@@ -23,7 +23,7 @@ export function createHeightDatasets({
const price = createResourceDataset<"height", OHLC>({
scale: "height",
path: "/height-to-ohlc",
path: "/height-to-price",
});
Object.assign(datasets, { price });

View File

@@ -22,7 +22,7 @@ export function createDatasets() {
let dataset: ResourceDataset<Scale, any>;
if (path === `/${scale}-to-ohlc`) {
if (path === `/${scale}-to-price`) {
dataset = createResourceDataset<Scale, OHLC>({
scale,
path,

View File

@@ -4,29 +4,27 @@ import { createRWS } from "/src/solid/rws";
import { HEIGHT_CHUNK_SIZE } from ".";
const USE_LOCAL_URL = true;
const LOCAL_URL = "http://localhost:3111";
const WEB_URL = "https://api.satonomics.xyz";
const BACKUP_WEB_URL = "https://api-bkp.satonomics.xyz";
export function createResourceDataset<
Scale extends ResourceScale,
Type extends OHLC | number = number,
>({ scale, path }: { scale: Scale; path: string }) {
type Dataset = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>;
type Value = DatasetValue<
Type extends number ? SingleValueData : CandlestickData
>;
const baseURL = `${
location.hostname === "localhost"
? "http://localhost:3110"
: "https://api.satonomics.xyz"
// "https://api.satonomics.xyz"
USE_LOCAL_URL && location.hostname === "localhost" ? LOCAL_URL : WEB_URL
}${path}`;
const backupURL = `${
location.hostname === "localhost"
? "http://localhost:3110"
: "https://api-bkp.satonomics.xyz"
USE_LOCAL_URL && location.hostname === "localhost"
? LOCAL_URL
: BACKUP_WEB_URL
}${path}`;
return createRoot((dispose) => {
@@ -36,14 +34,14 @@ export function createResourceDataset<
)
.fill(null)
.map((): FetchedResult<Scale, Type> => {
const json = createRWS<FetchedJSON<Scale, Type, Dataset> | null>(null);
const json = createRWS<FetchedJSON<Scale, Type> | null>(null);
return {
at: null,
json,
loading: false,
vec: createMemo(() => {
const map = json()?.dataset.map || null;
const map = json()?.dataset.map;
if (!map) {
return null;
@@ -186,7 +184,7 @@ export function createResourceDataset<
console.log(`fetch: ${path}?chunk=${id}`);
const previousMap = fetched.json()?.dataset.map;
const previousMap = fetched.json()?.dataset;
const newMap = json.dataset.map;
const previousLength = Object.keys(previousMap || []).length;

View File

@@ -7,14 +7,6 @@ type DatasetValue<T> = T & Valued;
interface ResourceDataset<
Scale extends ResourceScale,
Type extends OHLC | number = number,
FetchedDataset extends
| FetchedDateDataset<Type>
| FetchedHeightDataset<Type> = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>,
Value extends SingleValueData | CandlestickData = Type extends number
? SingleValueData
: CandlestickData,
> {
scale: Scale;
url: string;
@@ -26,33 +18,20 @@ interface ResourceDataset<
interface FetchedResult<
Scale extends ResourceScale,
Type extends number | OHLC,
Dataset extends
| FetchedDateDataset<Type>
| FetchedHeightDataset<Type> = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>,
Value extends DatasetValue<SingleValueData | CandlestickData> = DatasetValue<
Type extends number ? SingleValueData : CandlestickData
>,
> {
at: Date | null;
json: RWS<FetchedJSON<Scale, Type, Dataset> | null>;
json: RWS<FetchedJSON<Scale, Type> | null>;
vec: Accessor<Value[] | null>;
loading: boolean;
}
interface FetchedJSON<
Scale extends ResourceScale,
Type extends number | OHLC,
Dataset extends
| FetchedDateDataset<Type>
| FetchedHeightDataset<Type> = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>,
> {
interface FetchedJSON<Scale extends ResourceScale, Type extends number | OHLC> {
source: FetchedSource;
chunk: FetchedChunk;
dataset: FetchedDataset<Scale, Type, Dataset>;
dataset: FetchedDataset<Scale, Type>;
}
type FetchedSource = string;
@@ -63,21 +42,24 @@ interface FetchedChunk {
next: string | null;
}
interface FetchedDataset<
type FetchedDataset<
Scale extends ResourceScale,
Type extends number | OHLC,
Dataset extends
| FetchedDateDataset<Type>
| FetchedHeightDataset<Type> = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>,
> {
> = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>;
interface Versioned {
version: number;
map: Dataset;
}
type FetchedDateDataset<T> = Record<string, T>;
type FetchedHeightDataset<T> = T[];
interface FetchedDateDataset<Type> extends Versioned {
map: Record<string, Type>;
}
interface FetchedHeightDataset<Type> extends Versioned {
map: Type[];
}
interface OHLC {
open: number;

View File

@@ -215,7 +215,7 @@ export function applySeriesList({
if (chartIndex === 0) {
const datasetPath =
priceDataset || (`/${scale}-to-ohlc` satisfies AnyDatasetPath);
priceDataset || (`/${scale}-to-price` satisfies AnyDatasetPath);
const dataset = datasets.getOrImport(scale, datasetPath);