This commit is contained in:
parent
bf1a71a58b
commit
d06f43682a
7 changed files with 784 additions and 15 deletions
1
.tokeignore
Normal file
1
.tokeignore
Normal file
|
@ -0,0 +1 @@
|
|||
pnpm-lock.yaml
|
0
LICENSE
Normal file
0
LICENSE
Normal file
89
lib/ndjsonStream.ts
Normal file
89
lib/ndjsonStream.ts
Normal file
|
@ -0,0 +1,89 @@
|
|||
// Adapted from https://github.com/canjs/can-ndjson-stream/blob/master/can-ndjson-stream.js
|
||||
// Did not use the package because it had a useless dependency on can-namespace which was unlicensed
|
||||
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright 2017 Justin Meyer (justinbmeyer@gmail.com), Fang Lu
|
||||
// (cc2lufang@gmail.com), Siyao Wu (wusiyao@umich.edu), Shang Jiang
|
||||
// (mrjiangshang@gmail.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
export default function ndjsonStream(stream: ReadableStream) {
|
||||
// For cancellation
|
||||
let is_reader: ReadableStreamDefaultReader | undefined = undefined;
|
||||
let cancellationRequest = false;
|
||||
return new ReadableStream({
|
||||
start: (controller) => {
|
||||
const reader = stream.getReader();
|
||||
is_reader = reader;
|
||||
const decoder = new TextDecoder();
|
||||
let data_buf = "";
|
||||
|
||||
reader.read().then(function processResult(result) {
|
||||
if (result.done) {
|
||||
if (cancellationRequest) {
|
||||
// Immediately exit
|
||||
return;
|
||||
}
|
||||
|
||||
data_buf = data_buf.trim();
|
||||
if (data_buf.length !== 0) {
|
||||
try {
|
||||
const data_l = JSON.parse(data_buf);
|
||||
controller.enqueue(data_l);
|
||||
} catch (e) {
|
||||
controller.error(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = decoder.decode(result.value, { stream: true });
|
||||
data_buf += data;
|
||||
const lines = data_buf.split("\n");
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const l = lines[i].trim();
|
||||
if (l.length > 0) {
|
||||
try {
|
||||
const data_line = JSON.parse(l);
|
||||
controller.enqueue(data_line);
|
||||
} catch (e) {
|
||||
controller.error(e);
|
||||
cancellationRequest = true;
|
||||
reader.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
data_buf = lines[lines.length - 1];
|
||||
|
||||
return reader.read().then(processResult);
|
||||
});
|
||||
},
|
||||
|
||||
cancel: (reason) => {
|
||||
console.log("Cancel registered due to ", reason);
|
||||
cancellationRequest = true;
|
||||
is_reader.cancel();
|
||||
},
|
||||
});
|
||||
}
|
23
lib/stepcharts/LICENSE
Normal file
23
lib/stepcharts/LICENSE
Normal file
|
@ -0,0 +1,23 @@
|
|||
Files in this directory were adapted from https://github.com/city41/stepcharts
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 Matt Greer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"name": "DDRCompanion",
|
||||
"name": "ddr-companion",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"license": "AGPL-3.0-only",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
@ -12,7 +13,6 @@
|
|||
"type": "module",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^1.7.3",
|
||||
"@types/ndjson": "^2.0.4",
|
||||
|
@ -22,6 +22,7 @@
|
|||
"@vitejs/plugin-basic-ssl": "^1.1.0",
|
||||
"@vitejs/plugin-react-swc": "^3.6.0",
|
||||
"fraction.js": "^4.3.7",
|
||||
"js-green-licenses": "^4.0.0",
|
||||
"sass": "^1.77.1",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^5.2.11",
|
||||
|
@ -34,7 +35,6 @@
|
|||
"@mui/icons-material": "^5.15.17",
|
||||
"@mui/material": "^5.15.17",
|
||||
"@tanstack/react-query": "^5.36.1",
|
||||
"can-ndjson-stream": "^1.0.2",
|
||||
"ndjson": "^2.0.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
|
|
678
pnpm-lock.yaml
678
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
import stepchartsUrl from "../data/stepData.ndjson?url";
|
||||
import ndjsonStream from "../lib/ndjsonStream";
|
||||
import { APP_DATA_VERSION, CHART_STORE_CREATION_EVENT } from "./globals";
|
||||
import ndjsonStream from "can-ndjson-stream";
|
||||
|
||||
export async function importCharts() {
|
||||
const {
|
||||
|
|
Loading…
Reference in a new issue