Compare commits
39 Commits
jazz-react
...
fix/exampl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95f51ea783 | ||
|
|
82b0268c4d | ||
|
|
f97ef696e3 | ||
|
|
ad65cb8ab5 | ||
|
|
8d8131410a | ||
|
|
7491711b72 | ||
|
|
5933aa59c1 | ||
|
|
da96bec465 | ||
|
|
483422c0e9 | ||
|
|
3df93cc147 | ||
|
|
d686edfa6c | ||
|
|
497b0ade1f | ||
|
|
86acbcd0d6 | ||
|
|
9111c85445 | ||
|
|
1d87879787 | ||
|
|
7c777f2bdf | ||
|
|
aa8067b8d0 | ||
|
|
bd66cdeb78 | ||
|
|
8d29e50669 | ||
|
|
5a7398d242 | ||
|
|
74b984fbe6 | ||
|
|
f8e00204b4 | ||
|
|
76543df765 | ||
|
|
15d4b2a5f7 | ||
|
|
2e67f91fe0 | ||
|
|
0eb21a3471 | ||
|
|
99e88d3497 | ||
|
|
f09ce70d3c | ||
|
|
7d62e2735f | ||
|
|
5863badbb0 | ||
|
|
56d26222e7 | ||
|
|
bd34084104 | ||
|
|
f5e6fe927d | ||
|
|
93c49639c2 | ||
|
|
aabe7bef34 | ||
|
|
909165d813 | ||
|
|
789cf66de2 | ||
|
|
efbf3d84ac | ||
|
|
b90393b43e |
@@ -1,5 +1,52 @@
|
||||
# chat-rn-clerk
|
||||
|
||||
## 1.0.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react-native@0.9.15
|
||||
- jazz-react-native-auth-clerk@0.9.15
|
||||
- jazz-react-native-media-images@0.9.15
|
||||
|
||||
## 1.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react-native@0.9.14
|
||||
- jazz-react-native-auth-clerk@0.9.14
|
||||
- jazz-react-native-media-images@0.9.14
|
||||
|
||||
## 1.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.13
|
||||
- jazz-react-native-auth-clerk@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-react-native-media-images@0.9.13
|
||||
|
||||
## 1.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.12
|
||||
- jazz-react-native-auth-clerk@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-react-native-media-images@0.9.12
|
||||
|
||||
## 1.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.11
|
||||
- jazz-react-native-auth-clerk@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-react-native-media-images@0.9.11
|
||||
|
||||
## 1.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "chat-rn-clerk",
|
||||
"main": "index.js",
|
||||
"version": "1.0.51",
|
||||
"version": "1.0.56",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { useClerk, useUser } from "@clerk/clerk-expo";
|
||||
import { JazzProvider, setupKvStore } from "jazz-react-native";
|
||||
import { useJazzClerkAuth } from "jazz-react-native-auth-clerk";
|
||||
import React, {
|
||||
createContext,
|
||||
PropsWithChildren,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
const AuthContext = createContext<{
|
||||
isAuthenticated: boolean;
|
||||
@@ -27,15 +21,7 @@ export function JazzAndAuth({ children }: PropsWithChildren) {
|
||||
const { isSignedIn, isLoaded: isClerkLoaded } = useUser();
|
||||
const clerk = useClerk();
|
||||
const [auth, state] = useJazzClerkAuth(clerk, kvStore);
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSignedIn && isClerkLoaded && auth) {
|
||||
setIsAuthenticated(true);
|
||||
} else {
|
||||
setIsAuthenticated(false);
|
||||
}
|
||||
}, [isSignedIn, isClerkLoaded, auth]);
|
||||
const isAuthenticated = Boolean(isSignedIn && isClerkLoaded && auth);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# chat-rn
|
||||
|
||||
## 1.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react-native@0.9.15
|
||||
|
||||
## 1.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react-native@0.9.14
|
||||
|
||||
## 1.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 1.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 1.0.49
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 1.0.48
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn",
|
||||
"version": "1.0.48",
|
||||
"version": "1.0.53",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# chat-vue
|
||||
|
||||
## 0.0.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser@0.9.15
|
||||
- jazz-vue@0.9.15
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser@0.9.14
|
||||
- jazz-vue@0.9.14
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-vue@0.9.13
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-vue@0.9.12
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-vue@0.9.11
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-vue",
|
||||
"version": "0.0.35",
|
||||
"version": "0.0.40",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-example-chat
|
||||
|
||||
## 0.0.136
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.135
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.134
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.133
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.132
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.131
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-chat",
|
||||
"private": true,
|
||||
"version": "0.0.131",
|
||||
"version": "0.0.136",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# minimal-auth-clerk
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
- jazz-react-auth-clerk@0.9.15
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
- jazz-react-auth-clerk@0.9.14
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-react-auth-clerk@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-react-auth-clerk@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-react-auth-clerk@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -15,11 +15,11 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npm create jazz-app@latest --start clerk --project-name clerk
|
||||
npm create jazz-app@latest --example clerk --project-name clerk
|
||||
```
|
||||
or
|
||||
```bash
|
||||
npx create-jazz-app@latest --start clerk --project-name clerk
|
||||
npx create-jazz-app@latest --example clerk --project-name clerk
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clerk",
|
||||
"private": true,
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.35",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -13,7 +13,7 @@
|
||||
"dependencies": {
|
||||
"@clerk/clerk-react": "^5.4.1",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-react-auth-clerk": "workspace:0.9.10",
|
||||
"jazz-react-auth-clerk": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# file-share-svelte
|
||||
|
||||
## 0.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-svelte@0.9.15
|
||||
|
||||
## 0.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-svelte@0.9.14
|
||||
|
||||
## 0.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "file-share-svelte",
|
||||
"version": "0.0.15",
|
||||
"version": "0.0.20",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# form
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -28,11 +28,11 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npm create jazz-app@latest --start form --project-name form
|
||||
npm create jazz-app@latest --example form --project-name form
|
||||
```
|
||||
or
|
||||
```bash
|
||||
npx create-jazz-app@latest --start form --project-name form
|
||||
npx create-jazz-app@latest --example form --project-name form
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "form",
|
||||
"private": true,
|
||||
"version": "0.0.26",
|
||||
"version": "0.0.31",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# image-upload
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "image-upload",
|
||||
"private": true,
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.33",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
# jazz-example-inspector
|
||||
|
||||
## 0.0.98
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson-transport-ws@0.9.13
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.0.97
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson-transport-ws@0.9.12
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.0.96
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- cojson-transport-ws@0.9.11
|
||||
|
||||
## 0.0.95
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-inspector",
|
||||
"name": "jazz-inspector-app",
|
||||
"private": true,
|
||||
"version": "0.0.95",
|
||||
"version": "0.0.98",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -16,8 +16,8 @@
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"cojson": "workspace:0.9.10",
|
||||
"cojson-transport-ws": "workspace:0.9.10",
|
||||
"cojson": "workspace:0.9.13",
|
||||
"cojson-transport-ws": "workspace:0.9.13",
|
||||
"hash-slash": "workspace:0.2.1",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-example-musicplayer
|
||||
|
||||
## 0.0.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-inspector@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-inspector@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.9.13
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.9.12
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.9.11
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-music-player",
|
||||
"private": true,
|
||||
"version": "0.0.51",
|
||||
"version": "0.0.56",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -18,8 +18,9 @@
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"jazz-react": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"jazz-react": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"lucide-react": "^0.274.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Toaster } from "@/components/ui/toaster";
|
||||
import { JazzInspector } from "jazz-inspector";
|
||||
/* eslint-disable react-refresh/only-export-components */
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
@@ -71,6 +72,7 @@ function JazzAndAuth({ children }: { children: React.ReactNode }) {
|
||||
AccountSchema={MusicaAccount}
|
||||
>
|
||||
{children}
|
||||
<JazzInspector />
|
||||
</JazzProvider>
|
||||
<DemoAuthBasicUI appName="Jazz Music Player" state={state} />
|
||||
</>
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-example-onboarding
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-onboarding",
|
||||
"private": true,
|
||||
"version": "0.0.32",
|
||||
"version": "0.0.37",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# organization
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "organization",
|
||||
"private": true,
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.29",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,35 @@
|
||||
# passkey-svelte
|
||||
|
||||
## 0.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.15
|
||||
|
||||
## 0.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.14
|
||||
|
||||
## 0.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.13
|
||||
|
||||
## 0.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.12
|
||||
|
||||
## 0.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.11
|
||||
|
||||
## 0.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "passkey-svelte",
|
||||
"version": "0.0.19",
|
||||
"version": "0.0.24",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# minimal-auth-passkey
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "passkey",
|
||||
"private": true,
|
||||
"version": "0.0.29",
|
||||
"version": "0.0.34",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# jazz-password-manager
|
||||
|
||||
## 0.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-password-manager",
|
||||
"private": true,
|
||||
"version": "0.0.50",
|
||||
"version": "0.0.55",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -12,8 +12,8 @@
|
||||
"clean-install": "rm -rf node_modules pnpm-lock.yaml && pnpm install"
|
||||
},
|
||||
"dependencies": {
|
||||
"jazz-react": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"jazz-react": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.41.5",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-example-pets
|
||||
|
||||
## 0.0.153
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.152
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.151
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.150
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.149
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.148
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-pets",
|
||||
"private": true,
|
||||
"version": "0.0.148",
|
||||
"version": "0.0.153",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -19,9 +19,9 @@
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"jazz-browser-media-images": "workspace:0.9.10",
|
||||
"jazz-react": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"jazz-browser-media-images": "workspace:0.9.15",
|
||||
"jazz-react": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.3.1",
|
||||
@@ -41,7 +41,7 @@
|
||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"is-ci": "^3.0.1",
|
||||
"jazz-run": "workspace:0.9.10",
|
||||
"jazz-run": "workspace:0.9.15",
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.4.15",
|
||||
"typescript": "~5.6.2",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# reactions
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser-media-images@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser-media-images@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-browser-media-images@0.9.13
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-browser-media-images@0.9.12
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-browser-media-images@0.9.11
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "reactions",
|
||||
"private": true,
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.33",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# todo-vue
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser@0.9.15
|
||||
- jazz-vue@0.9.15
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser@0.9.14
|
||||
- jazz-vue@0.9.14
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
- jazz-vue@0.9.13
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
- jazz-vue@0.9.12
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
- jazz-vue@0.9.11
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "todo-vue",
|
||||
"version": "0.0.33",
|
||||
"version": "0.0.38",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# jazz-example-todo
|
||||
|
||||
## 0.0.152
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.151
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.150
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.149
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.148
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.147
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-todo",
|
||||
"private": true,
|
||||
"version": "0.0.147",
|
||||
"version": "0.0.152",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -16,8 +16,8 @@
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"jazz-react": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"jazz-react": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# version-history
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react@0.9.15
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react@0.9.14
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "version-history",
|
||||
"private": true,
|
||||
"version": "0.0.25",
|
||||
"version": "0.0.30",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
# cojson-storage-indexeddb
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson-storage@0.9.13
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson-storage@0.9.12
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- cojson-storage@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cojson-storage-indexeddb",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.13",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
# cojson-storage-sqlite
|
||||
|
||||
## 0.8.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson-storage@0.9.13
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.8.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson-storage@0.9.12
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.8.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- cojson-storage@0.9.11
|
||||
|
||||
## 0.8.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cojson-storage-rn-sqlite",
|
||||
"type": "module",
|
||||
"version": "0.8.53",
|
||||
"version": "0.8.56",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# cojson-storage-sqlite
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8d29e50: Restore the logger wrapper and adapt the API to pino
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson-storage@0.9.13
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 15d4b2a: Revert the custom logger
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson-storage@0.9.12
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- cojson-storage@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "cojson-storage-sqlite",
|
||||
"type": "module",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.13",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^11.7.0",
|
||||
"cojson": "workspace:0.9.10",
|
||||
"cojson": "workspace:0.9.13",
|
||||
"cojson-storage": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Database as DatabaseT } from "better-sqlite3";
|
||||
import { CojsonInternalTypes, OutgoingSyncQueue, SessionID } from "cojson";
|
||||
import {
|
||||
CojsonInternalTypes,
|
||||
OutgoingSyncQueue,
|
||||
SessionID,
|
||||
logger,
|
||||
} from "cojson";
|
||||
import RawCoID = CojsonInternalTypes.RawCoID;
|
||||
import Signature = CojsonInternalTypes.Signature;
|
||||
import Transaction = CojsonInternalTypes.Transaction;
|
||||
@@ -23,6 +28,10 @@ export type RawTransactionRow = {
|
||||
tx: string;
|
||||
};
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
return error instanceof Error ? error.message : "Unknown error";
|
||||
}
|
||||
|
||||
export class SQLiteClient implements DBClientInterface {
|
||||
private readonly db: DatabaseT;
|
||||
private readonly toLocalNode: OutgoingSyncQueue;
|
||||
@@ -48,7 +57,10 @@ export class SQLiteClient implements DBClientInterface {
|
||||
header: parsedHeader,
|
||||
};
|
||||
} catch (e) {
|
||||
console.warn(coValueId, "Invalid JSON in header", e, coValueRow?.header);
|
||||
const headerValue = coValueRow?.header ?? "";
|
||||
logger.warn("Invalid JSON in header: " + headerValue, {
|
||||
id: coValueId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +87,7 @@ export class SQLiteClient implements DBClientInterface {
|
||||
tx: JSON.parse(transactionRow.tx) as Transaction,
|
||||
}));
|
||||
} catch (e) {
|
||||
console.warn("Invalid JSON in transaction", e);
|
||||
logger.warn("Invalid JSON in transaction");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
OutgoingSyncQueue,
|
||||
Peer,
|
||||
cojsonInternals,
|
||||
logger,
|
||||
} from "cojson";
|
||||
import { SyncManager, TransactionRow } from "cojson-storage";
|
||||
import { SQLiteClient } from "./sqliteClient.js";
|
||||
@@ -40,24 +41,21 @@ export class SQLiteNode {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(
|
||||
new Error(
|
||||
`Error reading from localNode, handling msg\n\n${JSON.stringify(
|
||||
msg,
|
||||
(k, v) =>
|
||||
k === "changes" || k === "encryptedChanges"
|
||||
? v.slice(0, 20) + "..."
|
||||
: v,
|
||||
)}`,
|
||||
{ cause: e },
|
||||
),
|
||||
logger.error(
|
||||
`Error reading from localNode, handling msg\n\n${JSON.stringify(
|
||||
msg,
|
||||
(k, v) =>
|
||||
k === "changes" || k === "encryptedChanges"
|
||||
? v.slice(0, 20) + "..."
|
||||
: v,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
processMessages().catch((e) =>
|
||||
console.error("Error in processMessages in sqlite", e),
|
||||
logger.error("Error in processMessages in sqlite", e),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,10 +95,7 @@ export class SQLiteNode {
|
||||
db.pragma("user_version") as [{ user_version: number }]
|
||||
)[0].user_version as number;
|
||||
|
||||
console.log("DB version", oldVersion);
|
||||
|
||||
if (oldVersion === 0) {
|
||||
console.log("Migration 0 -> 1: Basic schema");
|
||||
db.prepare(
|
||||
`CREATE TABLE IF NOT EXISTS transactions (
|
||||
ses INTEGER,
|
||||
@@ -138,15 +133,10 @@ export class SQLiteNode {
|
||||
).run();
|
||||
|
||||
db.pragma("user_version = 1");
|
||||
console.log("Migration 0 -> 1: Basic schema - done");
|
||||
}
|
||||
|
||||
if (oldVersion <= 1) {
|
||||
// fix embarrassing off-by-one error for transaction indices
|
||||
console.log(
|
||||
"Migration 1 -> 2: Fix off-by-one error for transaction indices",
|
||||
);
|
||||
|
||||
const txs = db
|
||||
.prepare(`SELECT * FROM transactions`)
|
||||
.all() as TransactionRow[];
|
||||
@@ -163,14 +153,9 @@ export class SQLiteNode {
|
||||
}
|
||||
|
||||
db.pragma("user_version = 2");
|
||||
console.log(
|
||||
"Migration 1 -> 2: Fix off-by-one error for transaction indices - done",
|
||||
);
|
||||
}
|
||||
|
||||
if (oldVersion <= 2) {
|
||||
console.log("Migration 2 -> 3: Add signatureAfter");
|
||||
|
||||
db.prepare(
|
||||
`CREATE TABLE IF NOT EXISTS signatureAfter (
|
||||
ses INTEGER,
|
||||
@@ -185,7 +170,6 @@ export class SQLiteNode {
|
||||
).run();
|
||||
|
||||
db.pragma("user_version = 3");
|
||||
console.log("Migration 2 -> 3: Add signatureAfter - done!!");
|
||||
}
|
||||
|
||||
return new SQLiteNode(db, fromLocalNode, toLocalNode);
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
# cojson-storage
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8d29e50: Restore the logger wrapper and adapt the API to pino
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 15d4b2a: Revert the custom logger
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cojson-storage",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.13",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
SyncMessage,
|
||||
cojsonInternals,
|
||||
emptyKnownState,
|
||||
logger,
|
||||
} from "cojson";
|
||||
import { collectNewTxs, getDependedOnCoValues } from "./syncUtils.js";
|
||||
import { DBClientInterface, StoredSessionRow } from "./types.js";
|
||||
@@ -314,7 +315,7 @@ export class SyncManager {
|
||||
return this.toLocalNode
|
||||
.push(msg)
|
||||
.catch((e) =>
|
||||
console.error(`Error sending ${msg.action} state, id ${msg.id}`, e),
|
||||
logger.error(`Error sending ${msg.action} state, id ${msg.id}`, e),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
# cojson-transport-nodejs-ws
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8d29e50: Restore the logger wrapper and adapt the API to pino
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 15d4b2a: Revert the custom logger
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cojson-transport-ws",
|
||||
"type": "module",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.13",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:0.9.10",
|
||||
"cojson": "workspace:0.9.13",
|
||||
"typescript": "~5.6.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -4,9 +4,10 @@ import {
|
||||
PingTimeoutError,
|
||||
SyncMessage,
|
||||
cojsonInternals,
|
||||
logger,
|
||||
} from "cojson";
|
||||
import { BatchedOutgoingMessages } from "./BatchedOutgoingMessages.js";
|
||||
import { deserializeMessages } from "./serialization.js";
|
||||
import { deserializeMessages, getErrorMessage } from "./serialization.js";
|
||||
import { AnyWebSocket } from "./types.js";
|
||||
|
||||
export const BUFFER_LIMIT = 100_000;
|
||||
@@ -136,7 +137,7 @@ export function createWebSocketPeer({
|
||||
function handleClose() {
|
||||
incoming
|
||||
.push("Disconnected")
|
||||
.catch((e) => console.error("Error while pushing disconnect msg", e));
|
||||
.catch((e) => logger.error("Error while pushing disconnect msg", e));
|
||||
emitClosedEvent();
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ export function createWebSocketPeer({
|
||||
const pingTimeout = createPingTimeoutListener(expectPings, () => {
|
||||
incoming
|
||||
.push("PingTimeout")
|
||||
.catch((e) => console.error("Error while pushing ping timeout", e));
|
||||
.catch((e) => logger.error("Error while pushing ping timeout", e));
|
||||
emitClosedEvent();
|
||||
});
|
||||
|
||||
@@ -156,17 +157,14 @@ export function createWebSocketPeer({
|
||||
|
||||
function handleIncomingMsg(event: { data: unknown }) {
|
||||
if (event.data === "") {
|
||||
console.log("client", id, "sent empty message");
|
||||
return;
|
||||
}
|
||||
|
||||
const result = deserializeMessages(event.data);
|
||||
|
||||
if (!result.ok) {
|
||||
console.error(
|
||||
"Error while deserializing messages",
|
||||
event.data,
|
||||
result.error,
|
||||
logger.warn(
|
||||
"Error while deserializing messages: " + getErrorMessage(result.error),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -184,7 +182,7 @@ export function createWebSocketPeer({
|
||||
if (msg && "action" in msg) {
|
||||
incoming
|
||||
.push(msg)
|
||||
.catch((e) => console.error("Error while pushing incoming msg", e));
|
||||
.catch((e) => logger.error("Error while pushing incoming msg", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +195,6 @@ export function createWebSocketPeer({
|
||||
outgoing: {
|
||||
push: outgoingMessages.sendMessage,
|
||||
close() {
|
||||
console.log("Trying to close", id, websocket.readyState);
|
||||
outgoingMessages.close();
|
||||
|
||||
websocket.removeEventListener("message", handleIncomingMsg);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { SyncMessage } from "cojson";
|
||||
import { SyncMessage, logger } from "cojson";
|
||||
import { PingMsg } from "./types.js";
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
return error instanceof Error ? error.message : "Unknown error";
|
||||
}
|
||||
|
||||
export function addMessageToBacklog(backlog: string, message: SyncMessage) {
|
||||
if (!backlog) {
|
||||
return JSON.stringify(message);
|
||||
@@ -24,7 +28,7 @@ export function deserializeMessages(messages: unknown) {
|
||||
| PingMsg[],
|
||||
} as const;
|
||||
} catch (e) {
|
||||
console.error("Error while deserializing messages", e);
|
||||
logger.error("Error while deserializing messages: " + getErrorMessage(e));
|
||||
return {
|
||||
ok: false,
|
||||
error: e,
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# cojson
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8d29e50: Restore the logger wrapper and adapt the API to pino
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 15d4b2a: Revert the custom logger
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- efbf3d8: Optimize queue management
|
||||
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.13",
|
||||
"devDependencies": {
|
||||
"@opentelemetry/sdk-metrics": "^1.29.0",
|
||||
"@types/jest": "^29.5.3",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from "./PriorityBasedMessageQueue.js";
|
||||
import { TryAddTransactionsError } from "./coValueCore.js";
|
||||
import { RawCoID } from "./ids.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { CO_VALUE_PRIORITY } from "./priority.js";
|
||||
import { Peer, SyncMessage } from "./sync.js";
|
||||
|
||||
@@ -92,7 +93,7 @@ export class PeerState {
|
||||
|
||||
this.processing = true;
|
||||
|
||||
let entry: QueueEntry | undefined;
|
||||
let entry: QueueEntry<SyncMessage> | undefined;
|
||||
while ((entry = this.queue.pull())) {
|
||||
// Awaiting the push to send one message at a time
|
||||
// This way when the peer is "under pressure" we can enqueue all
|
||||
@@ -129,7 +130,7 @@ export class PeerState {
|
||||
}
|
||||
|
||||
private closeQueue() {
|
||||
let entry: QueueEntry | undefined;
|
||||
let entry: QueueEntry<SyncMessage> | undefined;
|
||||
while ((entry = this.queue.pull())) {
|
||||
// Using resolve here to avoid unnecessary noise in the logs
|
||||
entry.resolve();
|
||||
@@ -137,7 +138,10 @@ export class PeerState {
|
||||
}
|
||||
|
||||
gracefulShutdown() {
|
||||
console.debug("Gracefully closing", this.id);
|
||||
logger.debug("Gracefully closing", {
|
||||
peerId: this.id,
|
||||
peerRole: this.role,
|
||||
});
|
||||
this.closeQueue();
|
||||
this.peer.outgoing.close();
|
||||
this.closed = true;
|
||||
|
||||
@@ -18,11 +18,12 @@ function promiseWithResolvers<R>() {
|
||||
};
|
||||
}
|
||||
|
||||
export type QueueEntry = {
|
||||
msg: SyncMessage;
|
||||
export type QueueEntry<V> = {
|
||||
msg: V;
|
||||
promise: Promise<void>;
|
||||
resolve: () => void;
|
||||
reject: (_: unknown) => void;
|
||||
next: QueueEntry<V> | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -33,10 +34,68 @@ type Tuple<T, N extends number, A extends unknown[] = []> = A extends {
|
||||
}
|
||||
? A
|
||||
: Tuple<T, N, [...A, T]>;
|
||||
type QueueTuple = Tuple<QueueEntry[], 8>;
|
||||
type QueueTuple = Tuple<Queue<SyncMessage>, 8>;
|
||||
|
||||
class Queue<V> {
|
||||
head: QueueEntry<V> | undefined = undefined;
|
||||
tail: QueueEntry<V> | undefined = undefined;
|
||||
|
||||
push(msg: V) {
|
||||
const { promise, resolve, reject } = promiseWithResolvers<void>();
|
||||
const entry: QueueEntry<V> = {
|
||||
msg,
|
||||
promise,
|
||||
resolve,
|
||||
reject,
|
||||
next: undefined,
|
||||
};
|
||||
|
||||
if (this.head === undefined) {
|
||||
this.head = entry;
|
||||
} else {
|
||||
if (this.tail === undefined) {
|
||||
throw new Error("Tail is null but head is not");
|
||||
}
|
||||
|
||||
this.tail.next = entry;
|
||||
}
|
||||
|
||||
this.tail = entry;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
pull() {
|
||||
const entry = this.head;
|
||||
|
||||
if (entry) {
|
||||
this.head = entry.next;
|
||||
}
|
||||
|
||||
if (this.head === undefined) {
|
||||
this.tail = undefined;
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
isNonEmpty() {
|
||||
return this.head !== undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class PriorityBasedMessageQueue {
|
||||
private queues: QueueTuple = [[], [], [], [], [], [], [], []];
|
||||
private queues: QueueTuple = [
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
new Queue(),
|
||||
];
|
||||
|
||||
queueSizeCounter = metrics
|
||||
.getMeter("cojson")
|
||||
.createUpDownCounter("jazz.messagequeue.size", {
|
||||
@@ -52,22 +111,19 @@ export class PriorityBasedMessageQueue {
|
||||
constructor(private defaultPriority: CoValuePriority) {}
|
||||
|
||||
public push(msg: SyncMessage) {
|
||||
const { promise, resolve, reject } = promiseWithResolvers<void>();
|
||||
const entry: QueueEntry = { msg, promise, resolve, reject };
|
||||
|
||||
const priority = "priority" in msg ? msg.priority : this.defaultPriority;
|
||||
|
||||
this.getQueue(priority).push(entry);
|
||||
const entry = this.getQueue(priority).push(msg);
|
||||
|
||||
this.queueSizeCounter.add(1, {
|
||||
priority,
|
||||
});
|
||||
|
||||
return promise;
|
||||
return entry.promise;
|
||||
}
|
||||
|
||||
public pull() {
|
||||
const priority = this.queues.findIndex((queue) => queue.length > 0);
|
||||
const priority = this.queues.findIndex((queue) => queue.isNonEmpty());
|
||||
|
||||
if (priority === -1) {
|
||||
return;
|
||||
@@ -77,6 +133,6 @@ export class PriorityBasedMessageQueue {
|
||||
priority,
|
||||
});
|
||||
|
||||
return this.queues[priority]?.shift();
|
||||
return this.queues[priority]?.pull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,7 @@ export function bytesToBase64url(bytes: Uint8Array) {
|
||||
let base64 = decoder.decode(new Uint8Array(encoded.buffer, 0, n));
|
||||
if (k === 1) base64 += "==";
|
||||
if (k === 2) base64 += "=";
|
||||
// const after = performance.now();
|
||||
// console.log(
|
||||
// "bytesToBase64url bandwidth in MB/s for length",
|
||||
// (1000 * bytes.length / (after - before)) / (1024 * 1024),
|
||||
// bytes.length
|
||||
// );
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import { Stringified, parseJSON, stableStringify } from "./jsonStringify.js";
|
||||
import { JsonObject, JsonValue } from "./jsonValue.js";
|
||||
import { LocalNode, ResolveAccountAgentError } from "./localNode.js";
|
||||
import { logger } from "./logger.js";
|
||||
import {
|
||||
PermissionsDef as RulesetDef,
|
||||
determineValidTransactions,
|
||||
@@ -209,16 +210,10 @@ export class CoValueCore {
|
||||
.andThen((agent) => {
|
||||
const signerID = this.crypto.getAgentSignerID(agent);
|
||||
|
||||
// const beforeHash = performance.now();
|
||||
const { expectedNewHash, newStreamingHash } = this.expectedNewHashAfter(
|
||||
sessionID,
|
||||
newTransactions,
|
||||
);
|
||||
// const afterHash = performance.now();
|
||||
// console.log(
|
||||
// "Hashing took",
|
||||
// afterHash - beforeHash
|
||||
// );
|
||||
|
||||
if (givenExpectedNewHash && givenExpectedNewHash !== expectedNewHash) {
|
||||
return err({
|
||||
@@ -391,7 +386,6 @@ export class CoValueCore {
|
||||
streamingHash.update(transaction);
|
||||
const after = performance.now();
|
||||
if (after - before > 1) {
|
||||
// console.log("Hashing blocked for", after - before);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
before = performance.now();
|
||||
}
|
||||
@@ -540,7 +534,7 @@ export class CoValueCore {
|
||||
}
|
||||
|
||||
if (!decryptedChanges) {
|
||||
console.error("Failed to decrypt transaction despite having key");
|
||||
logger.error("Failed to decrypt transaction despite having key");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -685,7 +679,7 @@ export class CoValueCore {
|
||||
if (secret) {
|
||||
return secret as KeySecret;
|
||||
} else {
|
||||
console.error(
|
||||
logger.warn(
|
||||
`Encrypting ${encryptingKeyID} key didn't decrypt ${keyID}`,
|
||||
);
|
||||
}
|
||||
@@ -725,7 +719,7 @@ export class CoValueCore {
|
||||
if (secret) {
|
||||
return secret as KeySecret;
|
||||
} else {
|
||||
console.error(
|
||||
logger.warn(
|
||||
`Encrypting parent ${parentKey.id} key didn't decrypt ${keyID}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { PeerState } from "./PeerState.js";
|
||||
import { CoValueCore } from "./coValueCore.js";
|
||||
import { RawCoID } from "./ids.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { PeerID } from "./sync.js";
|
||||
|
||||
export const CO_VALUE_LOADING_MAX_RETRIES = 5;
|
||||
@@ -282,7 +283,7 @@ async function loadCoValueFromPeers(
|
||||
...coValueEntry.state.coValue.knownState(),
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Failed to push load message to peer ${peer.id}`, err);
|
||||
logger.warn(`Failed to push load message to peer ${peer.id}`, err);
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
@@ -296,14 +297,17 @@ async function loadCoValueFromPeers(
|
||||
sessions: {},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Failed to push load message to peer ${peer.id}`, err);
|
||||
logger.warn(`Failed to push load message to peer ${peer.id}`, err);
|
||||
});
|
||||
}
|
||||
|
||||
if (coValueEntry.state.type === "loading") {
|
||||
const timeout = setTimeout(() => {
|
||||
if (coValueEntry.state.type === "loading") {
|
||||
console.error("Failed to load coValue from peer", peer.id);
|
||||
logger.warn("Failed to load coValue from peer", {
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
});
|
||||
coValueEntry.dispatch({
|
||||
type: "not-found-in-peer",
|
||||
peerId: peer.id,
|
||||
@@ -356,7 +360,7 @@ function sleep(ms: number) {
|
||||
function getPeersWithoutErrors(peers: PeerState[], coValueId: RawCoID) {
|
||||
return peers.filter((p) => {
|
||||
if (p.erroredCoValues.has(coValueId)) {
|
||||
console.error(
|
||||
logger.warn(
|
||||
`Skipping load on errored coValue ${coValueId} from peer ${p.id}`,
|
||||
);
|
||||
return false;
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { AgentID } from "../ids.js";
|
||||
import { JsonObject } from "../jsonValue.js";
|
||||
import { LocalNode } from "../localNode.js";
|
||||
import { logger } from "../logger.js";
|
||||
import type { AccountRole } from "../permissions.js";
|
||||
import { RawCoMap } from "./coMap.js";
|
||||
import { InviteSecret, RawGroup } from "./group.js";
|
||||
@@ -59,7 +60,7 @@ export class RawAccount<
|
||||
);
|
||||
|
||||
if (agents.length !== 1) {
|
||||
console.warn("Account has " + agents.length + " agents", this.id);
|
||||
logger.warn("Account has " + agents.length + " agents", { id: this.id });
|
||||
}
|
||||
|
||||
this._cachedCurrentAgentID = agents[0];
|
||||
|
||||
@@ -133,10 +133,6 @@ export class RawCoListView<
|
||||
change.before.txIndex
|
||||
]?.[change.before.changeIdx];
|
||||
if (!beforeEntry) {
|
||||
// console.error(
|
||||
// "Insertion before missing op " +
|
||||
// change.before
|
||||
// );
|
||||
continue;
|
||||
}
|
||||
beforeEntry.predecessors.splice(0, 0, {
|
||||
@@ -156,9 +152,6 @@ export class RawCoListView<
|
||||
change.after.txIndex
|
||||
]?.[change.after.changeIdx];
|
||||
if (!afterEntry) {
|
||||
// console.error(
|
||||
// "Insertion after missing op " + change.after
|
||||
// );
|
||||
continue;
|
||||
}
|
||||
afterEntry.successors.push({
|
||||
|
||||
@@ -3,6 +3,7 @@ import { CoID, RawCoValue } from "../coValue.js";
|
||||
import { CoValueCore } from "../coValueCore.js";
|
||||
import { AgentID, SessionID, TransactionID } from "../ids.js";
|
||||
import { JsonObject, JsonValue } from "../jsonValue.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { CoValueKnownState } from "../sync.js";
|
||||
import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
|
||||
import { isAccountID } from "../typeUtils/isAccountID.js";
|
||||
@@ -309,7 +310,7 @@ export class RawBinaryCoStreamView<
|
||||
const start = items[0];
|
||||
|
||||
if (start?.type !== "start") {
|
||||
console.error("Invalid binary stream start", start);
|
||||
logger.error("Invalid binary stream start", start);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -328,7 +329,7 @@ export class RawBinaryCoStreamView<
|
||||
}
|
||||
|
||||
if (item.type !== "chunk") {
|
||||
console.error("Invalid binary stream chunk", item);
|
||||
logger.error("Invalid binary stream chunk", item);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -382,7 +383,6 @@ export class RawBinaryCoStream<
|
||||
chunk: Uint8Array,
|
||||
privacy: "private" | "trusting" = "private",
|
||||
): void {
|
||||
// const before = performance.now();
|
||||
this.push(
|
||||
{
|
||||
type: "chunk",
|
||||
@@ -391,11 +391,6 @@ export class RawBinaryCoStream<
|
||||
privacy,
|
||||
false,
|
||||
);
|
||||
// const after = performance.now();
|
||||
// console.log(
|
||||
// "pushBinaryStreamChunk bandwidth in MB/s",
|
||||
// (1000 * chunk.length) / (after - before) / (1024 * 1024)
|
||||
// );
|
||||
}
|
||||
|
||||
endBinaryStream(privacy: "private" | "trusting" = "private") {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
isParentGroupReference,
|
||||
} from "../ids.js";
|
||||
import { JsonObject } from "../jsonValue.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { AccountRole, Role } from "../permissions.js";
|
||||
import { expectGroup } from "../typeUtils/expectGroup.js";
|
||||
import {
|
||||
@@ -153,7 +154,7 @@ export class RawGroup<
|
||||
child.state.type === "unavailable"
|
||||
) {
|
||||
child.loadFromPeers(peers).catch(() => {
|
||||
console.error(`Failed to load child group ${id}`);
|
||||
logger.error(`Failed to load child group ${id}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -321,7 +322,7 @@ export class RawGroup<
|
||||
const secret = this.core.getReadKey(keyID);
|
||||
|
||||
if (!secret) {
|
||||
console.error("Can't find key", keyID);
|
||||
logger.error("Can't find key " + keyID);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { base64URLtoBytes, bytesToBase64url } from "../base64url.js";
|
||||
import { RawCoID, TransactionID } from "../ids.js";
|
||||
import { Stringified, stableStringify } from "../jsonStringify.js";
|
||||
import { JsonValue } from "../jsonValue.js";
|
||||
import { logger } from "../logger.js";
|
||||
import {
|
||||
CryptoProvider,
|
||||
Encrypted,
|
||||
@@ -192,7 +193,9 @@ export class PureJSCrypto extends CryptoProvider<Blake3State> {
|
||||
try {
|
||||
return JSON.parse(textDecoder.decode(plaintext));
|
||||
} catch (e) {
|
||||
console.error("Failed to decrypt/parse sealed message", e);
|
||||
logger.error(
|
||||
"Failed to decrypt/parse sealed message: " + (e as Error)?.message,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { base64URLtoBytes, bytesToBase64url } from "../base64url.js";
|
||||
import { RawCoID, TransactionID } from "../ids.js";
|
||||
import { Stringified, stableStringify } from "../jsonStringify.js";
|
||||
import { JsonValue } from "../jsonValue.js";
|
||||
import { logger } from "../logger.js";
|
||||
import {
|
||||
CryptoProvider,
|
||||
Encrypted,
|
||||
@@ -240,8 +241,9 @@ export class WasmCrypto extends CryptoProvider<Uint8Array> {
|
||||
try {
|
||||
return JSON.parse(textDecoder.decode(plaintext));
|
||||
} catch (e) {
|
||||
console.error("Failed to decrypt/parse sealed message", e);
|
||||
return undefined;
|
||||
logger.error(
|
||||
"Failed to decrypt/parse sealed message: " + (e as Error)?.message,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { AgentID, RawCoID, TransactionID } from "../ids.js";
|
||||
import { SessionID } from "../ids.js";
|
||||
import { Stringified, parseJSON, stableStringify } from "../jsonStringify.js";
|
||||
import { JsonValue } from "../jsonValue.js";
|
||||
import { logger } from "../logger.js";
|
||||
|
||||
export type SignerSecret = `signerSecret_z${string}`;
|
||||
export type SignerID = `signer_z${string}`;
|
||||
@@ -159,7 +160,7 @@ export abstract class CryptoProvider<Blake3State = any> {
|
||||
try {
|
||||
return parseJSON(this.decryptRaw(encrypted, keySecret, nOnceMaterial));
|
||||
} catch (e) {
|
||||
console.error("Decryption error", e);
|
||||
logger.error("Decryption error: " + (e as Error)?.message);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -305,10 +306,7 @@ export class StreamingHash {
|
||||
|
||||
update(value: JsonValue): Uint8Array {
|
||||
const encoded = textEncoder.encode(stableStringify(value));
|
||||
// const before = performance.now();
|
||||
this.state = this.crypto.blake3IncrementalUpdate(this.state, encoded);
|
||||
// const after = performance.now();
|
||||
// console.log(`Hashing throughput in MB/s`, 1000 * (encoded.length / (after - before)) / (1024 * 1024));
|
||||
return encoded;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ import {
|
||||
|
||||
type Value = JsonValue | AnyRawCoValue;
|
||||
|
||||
import { logger } from "./logger.js";
|
||||
import { getPriorityFromHeader } from "./priority.js";
|
||||
import { FileSystem } from "./storage/FileSystem.js";
|
||||
import { BlockFilename, LSMStorage, WalFilename } from "./storage/index.js";
|
||||
@@ -141,6 +142,7 @@ export {
|
||||
emptyKnownState,
|
||||
RawCoPlainText,
|
||||
stringifyOpID,
|
||||
logger,
|
||||
};
|
||||
|
||||
export type {
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from "./coValues/group.js";
|
||||
import { AgentSecret, CryptoProvider } from "./crypto/crypto.js";
|
||||
import { AgentID, RawCoID, SessionID, isAgentID } from "./ids.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { Peer, PeerID, SyncManager } from "./sync.js";
|
||||
import { expectGroup } from "./typeUtils/expectGroup.js";
|
||||
|
||||
@@ -230,7 +231,7 @@ export class LocalNode {
|
||||
|
||||
return node;
|
||||
} catch (e) {
|
||||
console.error("Error withLoadedAccount", e);
|
||||
logger.error("Error withLoadedAccount: " + (e as Error)?.message);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -269,7 +270,9 @@ export class LocalNode {
|
||||
this.syncManager.getServerAndStoragePeers(skipLoadingFromPeer);
|
||||
|
||||
await entry.loadFromPeers(peers).catch((e) => {
|
||||
console.error("Error loading from peers", id, e);
|
||||
logger.error("Error loading from peers: " + (e as Error)?.message, {
|
||||
id,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -311,8 +314,6 @@ export class LocalNode {
|
||||
let stopped = false;
|
||||
let unsubscribe!: () => void;
|
||||
|
||||
// console.log("Subscribing to " + id);
|
||||
|
||||
this.load(id)
|
||||
.then((coValue) => {
|
||||
if (stopped) {
|
||||
@@ -325,11 +326,12 @@ export class LocalNode {
|
||||
unsubscribe = coValue.subscribe(callback);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Error subscribing to ", id, e);
|
||||
logger.error(
|
||||
"Error subscribing to " + id + ": " + (e as Error)?.message,
|
||||
);
|
||||
});
|
||||
|
||||
return () => {
|
||||
console.log("Unsubscribing from " + id);
|
||||
stopped = true;
|
||||
unsubscribe?.();
|
||||
};
|
||||
@@ -390,9 +392,7 @@ export class LocalNode {
|
||||
(existingRole === "reader" && inviteRole === "readerInvite") ||
|
||||
(existingRole && inviteRole === "writeOnlyInvite")
|
||||
) {
|
||||
console.debug(
|
||||
"Not accepting invite that would replace or downgrade role",
|
||||
);
|
||||
logger.debug("Not accepting invite that would replace or downgrade role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
80
packages/cojson/src/logger.ts
Normal file
80
packages/cojson/src/logger.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
|
||||
export enum LogLevel {
|
||||
DEBUG = 0,
|
||||
INFO = 1,
|
||||
WARN = 2,
|
||||
ERROR = 3,
|
||||
NONE = 4,
|
||||
}
|
||||
|
||||
export interface LogSystem {
|
||||
debug(message: string, attributes?: Record<string, JsonValue>): void;
|
||||
info(message: string, attributes?: Record<string, JsonValue>): void;
|
||||
warn(message: string, attributes?: Record<string, JsonValue>): void;
|
||||
error(message: string, attributes?: Record<string, JsonValue>): void;
|
||||
}
|
||||
|
||||
// Default console-based logging system
|
||||
export class ConsoleLogSystem implements LogSystem {
|
||||
debug(message: string, attributes?: Record<string, JsonValue>) {
|
||||
console.debug(message, attributes);
|
||||
}
|
||||
info(message: string, attributes?: Record<string, JsonValue>) {
|
||||
console.info(message, attributes);
|
||||
}
|
||||
warn(message: string, attributes?: Record<string, JsonValue>) {
|
||||
console.warn(message, attributes);
|
||||
}
|
||||
error(message: string, attributes?: Record<string, JsonValue>) {
|
||||
console.error(message, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
export class Logger {
|
||||
private level: LogLevel;
|
||||
private logSystem: LogSystem;
|
||||
|
||||
constructor(
|
||||
level: LogLevel = LogLevel.INFO,
|
||||
logSystem: LogSystem = new ConsoleLogSystem(),
|
||||
) {
|
||||
this.level = level;
|
||||
this.logSystem = logSystem;
|
||||
}
|
||||
|
||||
setLevel(level: LogLevel) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
setLogSystem(logSystem: LogSystem) {
|
||||
this.logSystem = logSystem;
|
||||
}
|
||||
|
||||
debug(message: string, attributes?: Record<string, JsonValue>) {
|
||||
if (this.level <= LogLevel.DEBUG) {
|
||||
this.logSystem.debug(message, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
info(message: string, attributes?: Record<string, JsonValue>) {
|
||||
if (this.level <= LogLevel.INFO) {
|
||||
this.logSystem.info(message, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
warn(message: string, attributes?: Record<string, JsonValue>) {
|
||||
if (this.level <= LogLevel.WARN) {
|
||||
this.logSystem.warn(message, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
error(message: string, attributes?: Record<string, JsonValue>) {
|
||||
if (this.level <= LogLevel.ERROR) {
|
||||
this.logSystem.error(message, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create default logger instance
|
||||
export const logger = new Logger();
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from "./ids.js";
|
||||
import { parseJSON } from "./jsonStringify.js";
|
||||
import { JsonValue } from "./jsonValue.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
|
||||
import { expectGroup } from "./typeUtils/expectGroup.js";
|
||||
|
||||
@@ -41,12 +42,15 @@ export function disablePermissionErrors() {
|
||||
logPermissionErrors = false;
|
||||
}
|
||||
|
||||
function logPermissionError(...args: unknown[]) {
|
||||
function logPermissionError(
|
||||
message: string,
|
||||
attributes?: Record<string, JsonValue>,
|
||||
) {
|
||||
if (logPermissionErrors === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn(...args);
|
||||
logger.warn("Permission error: " + message, attributes);
|
||||
}
|
||||
|
||||
export function determineValidTransactions(
|
||||
@@ -204,7 +208,6 @@ function determineValidTransactionsForGroup(
|
||||
const writeKeys = new Set<string>();
|
||||
|
||||
for (const { sessionID, txIndex, tx } of allTransactionsSorted) {
|
||||
// console.log("before", { memberState, validTransactions });
|
||||
const transactor = accountOrAgentIDfromSessionID(sessionID);
|
||||
|
||||
if (tx.privacy === "private") {
|
||||
@@ -227,17 +230,10 @@ function determineValidTransactionsForGroup(
|
||||
try {
|
||||
changes = parseJSON(tx.changes);
|
||||
} catch (e) {
|
||||
logPermissionError(
|
||||
coValue.id,
|
||||
"Invalid JSON in transaction",
|
||||
e,
|
||||
logPermissionError("Invalid JSON in transaction", {
|
||||
id: coValue.id,
|
||||
tx,
|
||||
JSON.stringify(tx.changes, (k, v) =>
|
||||
k === "changes" || k === "encryptedChanges"
|
||||
? v.slice(0, 20) + "..."
|
||||
: v,
|
||||
),
|
||||
);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -458,8 +454,6 @@ function determineValidTransactionsForGroup(
|
||||
|
||||
memberState[affectedMember] = change.value;
|
||||
validTransactions.push({ txID: { sessionID, txIndex }, tx });
|
||||
|
||||
// console.log("after", { memberState, validTransactions });
|
||||
}
|
||||
|
||||
return { validTransactions, memberState };
|
||||
@@ -473,7 +467,7 @@ function agentInAccountOrMemberInGroup(
|
||||
return groupAtTime.currentAgentID().match(
|
||||
(agentID) => agentID,
|
||||
(e) => {
|
||||
console.error(
|
||||
logger.error(
|
||||
"Error while determining current agent ID in valid transactions",
|
||||
e,
|
||||
);
|
||||
|
||||
@@ -87,26 +87,15 @@ export async function writeBlock<WH, RH, FS extends FileSystem<WH, RH>>(
|
||||
const headerBytes = textEncoder.encode(JSON.stringify(blockHeader));
|
||||
await fs.append(file, headerBytes);
|
||||
|
||||
// console.log(
|
||||
// "full file",
|
||||
// yield* $(
|
||||
// fs.read(file as unknown as RH, 0, offset + headerBytes.length),
|
||||
// ),
|
||||
// );
|
||||
|
||||
const filename: BlockFilename = `L${level}-${(blockNumber + "").padStart(
|
||||
3,
|
||||
"0",
|
||||
)}-${hash.digest().replace("hash_", "").slice(0, 15)}-H${
|
||||
headerBytes.length
|
||||
}.jsonl`;
|
||||
// console.log("renaming to" + filename);
|
||||
await fs.closeAndRename(file, filename);
|
||||
|
||||
return filename;
|
||||
|
||||
// console.log("Wrote block", filename, blockHeader);
|
||||
// console.log("IDs in block", blockHeader.map(e => e.id));
|
||||
}
|
||||
|
||||
export async function writeToWal<WH, RH, FS extends FileSystem<WH, RH>>(
|
||||
@@ -120,6 +109,5 @@ export async function writeToWal<WH, RH, FS extends FileSystem<WH, RH>>(
|
||||
...chunk,
|
||||
};
|
||||
const bytes = textEncoder.encode(JSON.stringify(walEntry) + "\n");
|
||||
console.log("writing to WAL", handle, id, bytes.length);
|
||||
return fs.append(handle, bytes);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { CoID, RawCoValue } from "../coValue.js";
|
||||
import { CoValueHeader, Transaction } from "../coValueCore.js";
|
||||
import { Signature } from "../crypto/crypto.js";
|
||||
import { RawCoID } from "../ids.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { connectedPeers } from "../streamUtils.js";
|
||||
import {
|
||||
CoValueKnownState,
|
||||
@@ -68,7 +69,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
|
||||
const processMessages = async () => {
|
||||
for await (const msg of fromLocalNode) {
|
||||
console.log("Storage msg start", nMsg);
|
||||
try {
|
||||
if (msg === "Disconnected" || msg === "PingTimeout") {
|
||||
throw new Error("Unexpected Disconnected message");
|
||||
@@ -83,32 +83,30 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
await this.sendNewContent(msg.id, msg, undefined);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(
|
||||
new Error(
|
||||
`Error reading from localNode, handling msg\n\n${JSON.stringify(
|
||||
msg,
|
||||
(k, v) =>
|
||||
k === "changes" || k === "encryptedChanges"
|
||||
? v.slice(0, 20) + "..."
|
||||
: v,
|
||||
)}`,
|
||||
{ cause: e },
|
||||
),
|
||||
logger.error(
|
||||
`Error reading from localNode, handling msg\n\n${JSON.stringify(
|
||||
msg,
|
||||
(k, v) =>
|
||||
k === "changes" || k === "encryptedChanges"
|
||||
? v.slice(0, 20) + "..."
|
||||
: v,
|
||||
)}
|
||||
Error: ${e instanceof Error ? e.message : "Unknown error"},
|
||||
`,
|
||||
);
|
||||
}
|
||||
console.log("Storage msg end", nMsg);
|
||||
nMsg++;
|
||||
}
|
||||
};
|
||||
|
||||
processMessages().catch((e) =>
|
||||
console.error("Error in processMessages in storage", e),
|
||||
logger.error("Error in processMessages in storage", e),
|
||||
);
|
||||
|
||||
setTimeout(
|
||||
() =>
|
||||
this.compact().catch((e) => {
|
||||
console.error("Error while compacting", e);
|
||||
logger.error("Error while compacting", e);
|
||||
}),
|
||||
20000,
|
||||
);
|
||||
@@ -134,7 +132,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
sessions: {},
|
||||
asDependencyOf,
|
||||
})
|
||||
.catch((e) => console.error("Error while pushing known", e));
|
||||
.catch((e) => logger.error("Error while pushing known", e));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -190,13 +188,13 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
...ourKnown,
|
||||
asDependencyOf,
|
||||
})
|
||||
.catch((e) => console.error("Error while pushing known", e));
|
||||
.catch((e) => logger.error("Error while pushing known", e));
|
||||
|
||||
for (const message of newContentMessages) {
|
||||
if (Object.keys(message.new).length === 0) continue;
|
||||
this.toLocalNode
|
||||
.push(message)
|
||||
.catch((e) => console.error("Error while pushing new content", e));
|
||||
.catch((e) => logger.error("Error while pushing new content", e));
|
||||
}
|
||||
|
||||
this.coValues[id] = coValue;
|
||||
@@ -232,14 +230,13 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
|
||||
if (!coValue) {
|
||||
if (newContent.header) {
|
||||
// console.log("Creating in WAL", newContent.id);
|
||||
await this.withWAL((wal) =>
|
||||
writeToWal(wal, this.fs, newContent.id, newContentAsChunk),
|
||||
);
|
||||
|
||||
this.coValues[newContent.id] = newContentAsChunk;
|
||||
} else {
|
||||
console.warn("Incontiguous incoming update for " + newContent.id);
|
||||
logger.warn("Incontiguous incoming update for " + newContent.id);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -264,7 +261,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// console.log("Appending to WAL", newContent.id);
|
||||
await this.withWAL((wal) =>
|
||||
writeToWal(wal, this.fs, newContent.id, newContentAsChunk),
|
||||
);
|
||||
@@ -301,8 +297,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
|
||||
const { handle, size } = await this.getBlockHandle(blockFile, fs);
|
||||
|
||||
// console.log("Attempting to load", id, blockFile);
|
||||
|
||||
if (!cachedHeader) {
|
||||
cachedHeader = {};
|
||||
const header = await readHeader(blockFile, handle, size, fs);
|
||||
@@ -317,8 +311,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
}
|
||||
const headerEntry = cachedHeader[id];
|
||||
|
||||
// console.log("Header entry", id, headerEntry);
|
||||
|
||||
if (headerEntry) {
|
||||
const nextChunk = await readChunk(handle, headerEntry, fs);
|
||||
if (result) {
|
||||
@@ -354,7 +346,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
|
||||
const coValues = new Map<RawCoID, CoValueChunk>();
|
||||
|
||||
console.log("Compacting WAL files", walFiles);
|
||||
if (walFiles.length === 0) return;
|
||||
|
||||
const oldWal = this.currentWal;
|
||||
@@ -411,8 +402,6 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
return acc;
|
||||
}, 0);
|
||||
|
||||
console.log([...coValues.keys()], fileNames, highestBlockNumber);
|
||||
|
||||
await writeBlock(coValues, MAX_N_LEVELS, highestBlockNumber + 1, this.fs);
|
||||
|
||||
for (const walFile of walFiles) {
|
||||
@@ -438,15 +427,11 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
blockFilesByLevelInOrder[level]!.push(blockFile);
|
||||
}
|
||||
|
||||
console.log(blockFilesByLevelInOrder);
|
||||
|
||||
for (let level = MAX_N_LEVELS; level > 0; level--) {
|
||||
const nBlocksDesired = Math.pow(2, level);
|
||||
const blocksInLevel = blockFilesByLevelInOrder[level];
|
||||
|
||||
if (blocksInLevel && blocksInLevel.length > nBlocksDesired) {
|
||||
console.log("Compacting blocks in level", level, blocksInLevel);
|
||||
|
||||
const coValues = new Map<RawCoID, CoValueChunk>();
|
||||
|
||||
for (const blockFile of blocksInLevel) {
|
||||
@@ -517,7 +502,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
||||
setTimeout(
|
||||
() =>
|
||||
this.compact().catch((e) => {
|
||||
console.error("Error while compacting", e);
|
||||
logger.error("Error while compacting", e);
|
||||
}),
|
||||
5000,
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ import { CoValueCore } from "./coValueCore.js";
|
||||
import { Signature } from "./crypto/crypto.js";
|
||||
import { RawCoID, SessionID } from "./ids.js";
|
||||
import { LocalNode } from "./localNode.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { CoValuePriority } from "./priority.js";
|
||||
|
||||
export type CoValueKnownState = {
|
||||
@@ -22,6 +23,10 @@ export function emptyKnownState(id: RawCoID): CoValueKnownState {
|
||||
};
|
||||
}
|
||||
|
||||
function getErrorMessage(e: unknown) {
|
||||
return e instanceof Error ? e.message : "Unknown error";
|
||||
}
|
||||
|
||||
export type SyncMessage =
|
||||
| LoadMessage
|
||||
| KnownStateMessage
|
||||
@@ -150,7 +155,7 @@ export class SyncManager {
|
||||
|
||||
async handleSyncMessage(msg: SyncMessage, peer: PeerState) {
|
||||
if (peer.erroredCoValues.has(msg.id)) {
|
||||
console.error(
|
||||
logger.warn(
|
||||
`Skipping message ${msg.action} on errored coValue ${msg.id} from peer ${peer.id}`,
|
||||
);
|
||||
return;
|
||||
@@ -182,7 +187,7 @@ export class SyncManager {
|
||||
|
||||
if (entry.state.type !== "available") {
|
||||
entry.loadFromPeers([peer]).catch((e: unknown) => {
|
||||
console.error("Error sending load", e);
|
||||
logger.error("Error sending load: " + getErrorMessage(e));
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -199,7 +204,7 @@ export class SyncManager {
|
||||
action: "load",
|
||||
...coValue.knownState(),
|
||||
}).catch((e: unknown) => {
|
||||
console.error("Error sending load", e);
|
||||
logger.error("Error sending load: " + getErrorMessage(e));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -229,7 +234,7 @@ export class SyncManager {
|
||||
asDependencyOf,
|
||||
...coValue.knownState(),
|
||||
}).catch((e: unknown) => {
|
||||
console.error("Error sending known state", e);
|
||||
logger.error("Error sending known state: " + getErrorMessage(e));
|
||||
});
|
||||
|
||||
peer.toldKnownState.add(id);
|
||||
@@ -256,15 +261,8 @@ export class SyncManager {
|
||||
const sendPieces = async () => {
|
||||
let lastYield = performance.now();
|
||||
for (const [_i, piece] of newContentPieces.entries()) {
|
||||
// console.log(
|
||||
// `${id} -> ${peer.id}: Sending content piece ${i + 1}/${
|
||||
// newContentPieces.length
|
||||
// } header: ${!!piece.header}`,
|
||||
// // Object.values(piece.new).map((s) => s.newTransactions)
|
||||
// );
|
||||
|
||||
this.trySendToPeer(peer, piece).catch((e: unknown) => {
|
||||
console.error("Error sending content piece", e);
|
||||
logger.error("Error sending content piece: " + getErrorMessage(e));
|
||||
});
|
||||
|
||||
if (performance.now() - lastYield > 10) {
|
||||
@@ -277,7 +275,7 @@ export class SyncManager {
|
||||
};
|
||||
|
||||
sendPieces().catch((e) => {
|
||||
console.error("Error sending new content piece, retrying", e);
|
||||
logger.error("Error sending new content piece, retrying", e);
|
||||
peer.optimisticKnownStates.dispatch({
|
||||
type: "SET",
|
||||
id,
|
||||
@@ -337,7 +335,10 @@ export class SyncManager {
|
||||
return;
|
||||
}
|
||||
if (msg === "PingTimeout") {
|
||||
console.error("Ping timeout from peer", peer.id);
|
||||
logger.error("Ping timeout from peer", {
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -360,13 +361,22 @@ export class SyncManager {
|
||||
processMessages()
|
||||
.then(() => {
|
||||
if (peer.crashOnClose) {
|
||||
console.error("Unexepcted close from peer", peer.id);
|
||||
logger.error("Unexepcted close from peer", {
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
});
|
||||
this.local.crashed = new Error("Unexpected close from peer");
|
||||
throw new Error("Unexpected close from peer");
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Error processing messages from peer", peer.id, e);
|
||||
logger.error(
|
||||
"Error processing messages from peer: " + getErrorMessage(e),
|
||||
{
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
},
|
||||
);
|
||||
if (peer.crashOnClose) {
|
||||
this.local.crashed = e;
|
||||
throw new Error(e);
|
||||
@@ -406,13 +416,13 @@ export class SyncManager {
|
||||
// where we can get informations about the coValue
|
||||
if (msg.header || Object.keys(msg.sessions).length > 0) {
|
||||
entry.loadFromPeers([peer]).catch((e) => {
|
||||
console.error("Error loading coValue in handleLoad", e);
|
||||
logger.error("Error loading coValue in handleLoad", e);
|
||||
});
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
this.local.loadCoValueCore(msg.id, peer.id).catch((e) => {
|
||||
console.error("Error loading coValue in handleLoad", e);
|
||||
logger.error("Error loading coValue in handleLoad", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -439,7 +449,7 @@ export class SyncManager {
|
||||
header: false,
|
||||
sessions: {},
|
||||
}).catch((e) => {
|
||||
console.error("Error sending known state back", e);
|
||||
logger.error("Error sending known state back", e);
|
||||
});
|
||||
|
||||
return;
|
||||
@@ -449,7 +459,7 @@ export class SyncManager {
|
||||
await this.sendNewContentIncludingDependencies(msg.id, peer);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Error loading coValue in handleLoad loading state", e);
|
||||
logger.error("Error loading coValue in handleLoad loading state", e);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -484,7 +494,7 @@ export class SyncManager {
|
||||
peer.role === "storage" ? undefined : peer.id,
|
||||
)
|
||||
.catch((e) => {
|
||||
console.error(
|
||||
logger.error(
|
||||
`Error loading coValue ${msg.id} to create loading state, as dependency of ${msg.asDependencyOf}`,
|
||||
e,
|
||||
);
|
||||
@@ -521,7 +531,7 @@ export class SyncManager {
|
||||
|
||||
if (entry.state.type !== "available") {
|
||||
if (!msg.header) {
|
||||
console.error("Expected header to be sent in first message");
|
||||
logger.error("Expected header to be sent in first message");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -584,7 +594,7 @@ export class SyncManager {
|
||||
: t.changes.length,
|
||||
)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
console.log(
|
||||
logger.debug(
|
||||
`Adding incoming transactions took ${(after - before).toFixed(
|
||||
2,
|
||||
)}ms for ${totalTxLength} bytes = bandwidth: ${(
|
||||
@@ -602,17 +612,11 @@ export class SyncManager {
|
||||
// );
|
||||
|
||||
if (result.isErr()) {
|
||||
console.error(
|
||||
"Failed to add transactions from",
|
||||
peer.id,
|
||||
result.error,
|
||||
msg.id,
|
||||
newTransactions.length + " new transactions",
|
||||
"after: " + newContentForSession.after,
|
||||
"our last known tx idx initially: " + ourKnownTxIdx,
|
||||
"our last known tx idx now: " +
|
||||
coValue.sessionLogs.get(sessionID)?.transactions.length,
|
||||
);
|
||||
logger.error("Failed to add transactions: " + result.error.type, {
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
id: msg.id,
|
||||
});
|
||||
peer.erroredCoValues.set(msg.id, result.error);
|
||||
continue;
|
||||
}
|
||||
@@ -633,7 +637,13 @@ export class SyncManager {
|
||||
isCorrection: true,
|
||||
...coValue.knownState(),
|
||||
}).catch((e) => {
|
||||
console.error("Error sending known state correction", e);
|
||||
logger.error(
|
||||
"Error sending known state correction: " + getErrorMessage(e),
|
||||
{
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
},
|
||||
);
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
@@ -647,7 +657,10 @@ export class SyncManager {
|
||||
action: "known",
|
||||
...coValue.knownState(),
|
||||
}).catch((e: unknown) => {
|
||||
console.error("Error sending known state", e);
|
||||
logger.error("Error sending known state: " + getErrorMessage(e), {
|
||||
peerId: peer.id,
|
||||
peerRole: peer.role,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -681,9 +694,6 @@ export class SyncManager {
|
||||
const done = new Promise<void>((resolve) => {
|
||||
queueMicrotask(async () => {
|
||||
delete this.requestedSyncs[coValue.id];
|
||||
// if (entry.nRequestsThisTick >= 2) {
|
||||
// console.log("Syncing", coValue.id, "for", entry.nRequestsThisTick, "requests");
|
||||
// }
|
||||
await this.actuallySyncCoValue(coValue);
|
||||
resolve();
|
||||
});
|
||||
|
||||
@@ -49,12 +49,9 @@ describe("PeerState", () => {
|
||||
|
||||
test("should perform graceful shutdown", () => {
|
||||
const { mockPeer, peerState } = setup();
|
||||
const consoleSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
||||
peerState.gracefulShutdown();
|
||||
expect(mockPeer.outgoing.close).toHaveBeenCalled();
|
||||
expect(peerState.closed).toBe(true);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Gracefully closing", "test-peer");
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
test("should empty the queue when closing", async () => {
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("PriorityBasedMessageQueue", () => {
|
||||
const { queue } = setup();
|
||||
expect(queue["defaultPriority"]).toBe(CO_VALUE_PRIORITY.MEDIUM);
|
||||
expect(queue["queues"].length).toBe(8);
|
||||
expect(queue["queues"].every((q) => q.length === 0)).toBe(true);
|
||||
expect(queue["queues"].every((q) => !q.isNonEmpty())).toBe(true);
|
||||
});
|
||||
|
||||
test("should push message with default priority", async () => {
|
||||
|
||||
149
packages/cojson/src/tests/logger.test.ts
Normal file
149
packages/cojson/src/tests/logger.test.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { LogLevel, Logger } from "../logger";
|
||||
|
||||
describe("Logger", () => {
|
||||
describe("Log Level Filtering", () => {
|
||||
test("should respect log level hierarchy", () => {
|
||||
const mockLogSystem = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const logger = new Logger(LogLevel.WARN, mockLogSystem);
|
||||
|
||||
logger.debug("Debug message");
|
||||
logger.info("Info message");
|
||||
logger.warn("Warning message");
|
||||
logger.error("Error message");
|
||||
|
||||
expect(mockLogSystem.debug).not.toHaveBeenCalled();
|
||||
expect(mockLogSystem.info).not.toHaveBeenCalled();
|
||||
expect(mockLogSystem.warn).toHaveBeenCalledWith(
|
||||
"Warning message",
|
||||
undefined,
|
||||
);
|
||||
expect(mockLogSystem.error).toHaveBeenCalledWith(
|
||||
"Error message",
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
test("should pass additional arguments to log system", () => {
|
||||
const mockLogSystem = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const logger = new Logger(LogLevel.DEBUG, mockLogSystem);
|
||||
|
||||
logger.debug("Debug message", { foo: "bar" });
|
||||
|
||||
expect(mockLogSystem.debug).toHaveBeenCalledWith("Debug message", {
|
||||
foo: "bar",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Log System Configuration", () => {
|
||||
test("should allow changing log level at runtime", () => {
|
||||
const mockLogSystem = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const logger = new Logger(LogLevel.ERROR, mockLogSystem);
|
||||
|
||||
logger.warn("Warning 1"); // Should not log
|
||||
expect(mockLogSystem.warn).not.toHaveBeenCalled();
|
||||
|
||||
logger.setLevel(LogLevel.WARN);
|
||||
logger.warn("Warning 2"); // Should log
|
||||
expect(mockLogSystem.warn).toHaveBeenCalledWith("Warning 2", undefined);
|
||||
});
|
||||
|
||||
test("should allow changing log system at runtime", () => {
|
||||
const mockLogSystem1 = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const mockLogSystem2 = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const logger = new Logger(LogLevel.INFO, mockLogSystem1);
|
||||
|
||||
logger.info("Message 1");
|
||||
expect(mockLogSystem1.info).toHaveBeenCalledWith("Message 1", undefined);
|
||||
expect(mockLogSystem2.info).not.toHaveBeenCalled();
|
||||
|
||||
logger.setLogSystem(mockLogSystem2);
|
||||
logger.info("Message 2");
|
||||
expect(mockLogSystem2.info).toHaveBeenCalledWith("Message 2", undefined);
|
||||
expect(mockLogSystem1.info).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default Console Log System", () => {
|
||||
test("should use console methods by default", () => {
|
||||
const consoleSpy = {
|
||||
debug: vi.spyOn(console, "debug").mockImplementation(() => {}),
|
||||
info: vi.spyOn(console, "info").mockImplementation(() => {}),
|
||||
warn: vi.spyOn(console, "warn").mockImplementation(() => {}),
|
||||
error: vi.spyOn(console, "error").mockImplementation(() => {}),
|
||||
};
|
||||
|
||||
const logger = new Logger();
|
||||
logger.setLevel(LogLevel.DEBUG);
|
||||
const testMessage = "Test message";
|
||||
const testArgs = { data: "test" };
|
||||
|
||||
logger.debug(testMessage, testArgs);
|
||||
logger.info(testMessage, testArgs);
|
||||
logger.warn(testMessage, testArgs);
|
||||
logger.error(testMessage, testArgs);
|
||||
|
||||
expect(consoleSpy.debug).toHaveBeenCalledWith(testMessage, testArgs);
|
||||
expect(consoleSpy.info).toHaveBeenCalledWith(testMessage, testArgs);
|
||||
expect(consoleSpy.warn).toHaveBeenCalledWith(testMessage, testArgs);
|
||||
expect(consoleSpy.error).toHaveBeenCalledWith(testMessage, testArgs);
|
||||
|
||||
// Cleanup
|
||||
Object.values(consoleSpy).forEach((spy) => spy.mockRestore());
|
||||
});
|
||||
});
|
||||
|
||||
describe("Log Level NONE", () => {
|
||||
test("should not log anything when level is NONE", () => {
|
||||
const mockLogSystem = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
const logger = new Logger(LogLevel.NONE, mockLogSystem);
|
||||
|
||||
logger.debug("Debug message");
|
||||
logger.info("Info message");
|
||||
logger.warn("Warning message");
|
||||
logger.error("Error message");
|
||||
|
||||
expect(mockLogSystem.debug).not.toHaveBeenCalled();
|
||||
expect(mockLogSystem.info).not.toHaveBeenCalled();
|
||||
expect(mockLogSystem.warn).not.toHaveBeenCalled();
|
||||
expect(mockLogSystem.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,49 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser@0.9.15
|
||||
|
||||
## 0.9.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser@0.9.14
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson@0.9.13
|
||||
- jazz-browser@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson@0.9.12
|
||||
- jazz-browser@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- jazz-browser@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "jazz-browser-auth-clerk",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.15",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:0.9.10",
|
||||
"jazz-browser": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10"
|
||||
"cojson": "workspace:0.9.13",
|
||||
"jazz-browser": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15"
|
||||
},
|
||||
"scripts": {
|
||||
"format-and-lint": "biome check .",
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-browser@0.9.15
|
||||
|
||||
## 0.9.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-browser@0.9.14
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-browser-media-images",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.15",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
@@ -8,8 +8,8 @@
|
||||
"dependencies": {
|
||||
"@types/image-blob-reduce": "^4.1.1",
|
||||
"image-blob-reduce": "^4.1.0",
|
||||
"jazz-browser": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"jazz-browser": "workspace:0.9.15",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"pica": "^9.0.1",
|
||||
"typescript": "~5.6.2"
|
||||
},
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# jazz-browser
|
||||
|
||||
## 0.9.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
|
||||
## 0.9.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson-transport-ws@0.9.13
|
||||
- cojson@0.9.13
|
||||
- cojson-storage-indexeddb@0.9.13
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson-transport-ws@0.9.12
|
||||
- cojson@0.9.12
|
||||
- cojson-storage-indexeddb@0.9.12
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- cojson-transport-ws@0.9.11
|
||||
- cojson-storage-indexeddb@0.9.11
|
||||
- jazz-tools@0.9.11
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "jazz-browser",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.15",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@scure/bip39": "^1.3.0",
|
||||
"cojson": "workspace:0.9.10",
|
||||
"cojson-storage-indexeddb": "workspace:0.9.10",
|
||||
"cojson-transport-ws": "workspace:0.9.10",
|
||||
"jazz-tools": "workspace:0.9.10",
|
||||
"cojson": "workspace:0.9.13",
|
||||
"cojson-storage-indexeddb": "workspace:0.9.13",
|
||||
"cojson-transport-ws": "workspace:0.9.13",
|
||||
"jazz-tools": "workspace:0.9.15",
|
||||
"typescript": "~5.6.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
26
packages/jazz-inspector/.gitignore
vendored
Normal file
26
packages/jazz-inspector/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
sync-db/
|
||||
45
packages/jazz-inspector/CHANGELOG.md
Normal file
45
packages/jazz-inspector/CHANGELOG.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# jazz-inspector
|
||||
|
||||
## 0.9.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7491711]
|
||||
- jazz-tools@0.9.15
|
||||
- jazz-react-core@0.8.56
|
||||
|
||||
## 0.9.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3df93cc]
|
||||
- jazz-tools@0.9.14
|
||||
- jazz-react-core@0.8.55
|
||||
|
||||
## 0.9.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8d29e50]
|
||||
- cojson@0.9.13
|
||||
- jazz-react-core@0.8.54
|
||||
- jazz-tools@0.9.13
|
||||
|
||||
## 0.9.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [15d4b2a]
|
||||
- cojson@0.9.12
|
||||
- jazz-react-core@0.8.53
|
||||
- jazz-tools@0.9.12
|
||||
|
||||
## 0.9.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efbf3d8]
|
||||
- Updated dependencies [5863bad]
|
||||
- cojson@0.9.11
|
||||
- jazz-react-core@0.8.52
|
||||
- jazz-tools@0.9.11
|
||||
5
packages/jazz-inspector/README.md
Normal file
5
packages/jazz-inspector/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Jazz Inspector
|
||||
|
||||
Use this to visually inspect a Jazz account or other CoValue.
|
||||
|
||||
Still unstable, you will very likely encounter bugs.
|
||||
30
packages/jazz-inspector/package.json
Normal file
30
packages/jazz-inspector/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "jazz-inspector",
|
||||
"version": "0.9.15",
|
||||
"type": "module",
|
||||
"main": "./dist/jazz-inspector.js",
|
||||
"types": "./src/app.tsx",
|
||||
"scripts": {
|
||||
"dev": "vite build --watch",
|
||||
"build": "tsc && vite build",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"cojson": "workspace:*",
|
||||
"jazz-react-core": "workspace:*",
|
||||
"jazz-tools": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.0 || ^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||
"rollup-plugin-node-externals": "^8.0.0",
|
||||
"typescript": "~5.6.2",
|
||||
"vite": "^5.4.10"
|
||||
}
|
||||
}
|
||||
BIN
packages/jazz-inspector/public/jazz-logo.png
Normal file
BIN
packages/jazz-inspector/public/jazz-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
1
packages/jazz-inspector/src/app.tsx
Normal file
1
packages/jazz-inspector/src/app.tsx
Normal file
@@ -0,0 +1 @@
|
||||
export { JazzInspector } from "./viewer/new-app.tsx";
|
||||
18
packages/jazz-inspector/src/link-icon.tsx
Normal file
18
packages/jazz-inspector/src/link-icon.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
export function LinkIcon() {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
strokeWidth={1.5}
|
||||
stroke="currentColor"
|
||||
className="w-3 h-3"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
85
packages/jazz-inspector/src/viewer/breadcrumbs.tsx
Normal file
85
packages/jazz-inspector/src/viewer/breadcrumbs.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
import React from "react";
|
||||
import { PageInfo } from "./types.ts";
|
||||
|
||||
interface BreadcrumbsProps {
|
||||
path: PageInfo[];
|
||||
onBreadcrumbClick: (index: number) => void;
|
||||
}
|
||||
|
||||
export const Breadcrumbs: React.FC<BreadcrumbsProps> = ({
|
||||
path,
|
||||
onBreadcrumbClick,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
zIndex: 20,
|
||||
backgroundColor: "rgba(129, 140, 248, 0.1)", // indigo-400/10 equivalent
|
||||
backdropFilter: "blur(4px)",
|
||||
borderRadius: "0.5rem",
|
||||
display: "inline-flex",
|
||||
paddingLeft: "0.5rem",
|
||||
paddingRight: "0.5rem",
|
||||
paddingTop: "0.25rem",
|
||||
paddingBottom: "0.25rem",
|
||||
whiteSpace: "pre",
|
||||
transition: "all",
|
||||
alignItems: "center",
|
||||
gap: "0.25rem",
|
||||
minHeight: "2.5rem",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
onClick={() => onBreadcrumbClick(-1)}
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
padding: "0.25rem",
|
||||
borderRadius: "0.125rem",
|
||||
transition: "colors",
|
||||
}}
|
||||
onMouseOver={(e) =>
|
||||
(e.currentTarget.style.backgroundColor = "rgba(99, 102, 241, 0.1)")
|
||||
}
|
||||
onMouseOut={(e) =>
|
||||
(e.currentTarget.style.backgroundColor = "transparent")
|
||||
}
|
||||
aria-label="Go to home"
|
||||
>
|
||||
Start
|
||||
</button>
|
||||
{path.map((page, index) => {
|
||||
return (
|
||||
<span
|
||||
key={index}
|
||||
style={{
|
||||
display: "inline-block",
|
||||
paddingLeft: index === 0 ? "0.25rem" : "0",
|
||||
paddingRight: index === path.length - 1 ? "0.25rem" : "0",
|
||||
}}
|
||||
>
|
||||
{index === 0 ? null : (
|
||||
<span style={{ color: "rgba(99, 102, 241, 0.3)" }}>{" / "}</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => onBreadcrumbClick(index)}
|
||||
style={{
|
||||
color: "rgb(67, 56, 202)",
|
||||
}}
|
||||
onMouseOver={(e) =>
|
||||
(e.currentTarget.style.textDecoration = "underline")
|
||||
}
|
||||
onMouseOut={(e) =>
|
||||
(e.currentTarget.style.textDecoration = "none")
|
||||
}
|
||||
>
|
||||
{index === 0 ? page.name || "Root" : page.name}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
389
packages/jazz-inspector/src/viewer/co-stream-view.tsx
Normal file
389
packages/jazz-inspector/src/viewer/co-stream-view.tsx
Normal file
@@ -0,0 +1,389 @@
|
||||
import {
|
||||
CoID,
|
||||
LocalNode,
|
||||
RawBinaryCoStream,
|
||||
RawCoStream,
|
||||
RawCoValue,
|
||||
} from "cojson";
|
||||
import { base64URLtoBytes } from "cojson/src/base64url.ts";
|
||||
import {
|
||||
BinaryStreamItem,
|
||||
BinaryStreamStart,
|
||||
CoStreamItem,
|
||||
} from "cojson/src/coValues/coStream.ts";
|
||||
import type { JsonObject, JsonValue } from "cojson/src/jsonValue.ts";
|
||||
import { useEffect, useState } from "react";
|
||||
import { PageInfo } from "./types.ts";
|
||||
import { AccountOrGroupPreview } from "./value-renderer.tsx";
|
||||
|
||||
// typeguard for BinaryStreamStart
|
||||
function isBinaryStreamStart(item: unknown): item is BinaryStreamStart {
|
||||
return (
|
||||
typeof item === "object" &&
|
||||
item !== null &&
|
||||
"type" in item &&
|
||||
item.type === "start"
|
||||
);
|
||||
}
|
||||
|
||||
function detectCoStreamType(value: RawCoStream | RawBinaryCoStream) {
|
||||
const firstKey = Object.keys(value.items)[0];
|
||||
if (!firstKey)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
|
||||
const items = value.items[firstKey as never]?.map((v) => v.value);
|
||||
|
||||
if (!items)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
const firstItem = items[0];
|
||||
if (!firstItem)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
// This is a binary stream
|
||||
if (isBinaryStreamStart(firstItem)) {
|
||||
return {
|
||||
type: "binary",
|
||||
items: items as BinaryStreamItem[],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "coStream",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function getBlobFromCoStream({
|
||||
items,
|
||||
onlyFirstChunk = false,
|
||||
}: {
|
||||
items: BinaryStreamItem[];
|
||||
onlyFirstChunk?: boolean;
|
||||
}) {
|
||||
if (onlyFirstChunk && items.length > 1) {
|
||||
items = items.slice(0, 2);
|
||||
}
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
|
||||
const binary_U_prefixLength = 8;
|
||||
|
||||
let lastProgressUpdate = Date.now();
|
||||
|
||||
for (const item of items.slice(1)) {
|
||||
if (item.type === "end") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.type !== "chunk") {
|
||||
console.error("Invalid binary stream chunk", item);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const chunk = base64URLtoBytes(item.chunk.slice(binary_U_prefixLength));
|
||||
// totalLength += chunk.length;
|
||||
chunks.push(chunk);
|
||||
|
||||
if (Date.now() - lastProgressUpdate > 100) {
|
||||
lastProgressUpdate = Date.now();
|
||||
}
|
||||
}
|
||||
const defaultMime = "mimeType" in items[0] ? items[0].mimeType : null;
|
||||
|
||||
const blob = new Blob(chunks, defaultMime ? { type: defaultMime } : {});
|
||||
|
||||
const mimeType =
|
||||
defaultMime === "" ? await detectPDFMimeType(blob) : defaultMime;
|
||||
|
||||
return {
|
||||
blob,
|
||||
mimeType: mimeType as string,
|
||||
unfinishedChunks: items.length > 1,
|
||||
totalSize:
|
||||
"totalSizeBytes" in items[0]
|
||||
? (items[0].totalSizeBytes as number)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const detectPDFMimeType = async (blob: Blob): Promise<string> => {
|
||||
const arrayBuffer = await blob.slice(0, 4).arrayBuffer();
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
const header = uint8Array.reduce(
|
||||
(acc, byte) => acc + String.fromCharCode(byte),
|
||||
"",
|
||||
);
|
||||
|
||||
if (header === "%PDF") {
|
||||
return "application/pdf";
|
||||
}
|
||||
return "application/octet-stream";
|
||||
};
|
||||
|
||||
const BinaryDownloadButton = ({
|
||||
pdfBlob,
|
||||
fileName = "document",
|
||||
label,
|
||||
mimeType,
|
||||
}: {
|
||||
pdfBlob: Blob;
|
||||
mimeType?: string;
|
||||
fileName?: string;
|
||||
label: string;
|
||||
}) => {
|
||||
const downloadFile = () => {
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([pdfBlob], mimeType ? { type: mimeType } : {}),
|
||||
);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download =
|
||||
mimeType === "application/pdf" ? `${fileName}.pdf` : fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<button onClick={downloadFile}>
|
||||
⬇️ {label}
|
||||
{/* Download {mimeType === "application/pdf" ? "PDF" : "File"} */}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const LabelContentPair = ({
|
||||
label,
|
||||
content,
|
||||
}: {
|
||||
label: string;
|
||||
content: React.ReactNode;
|
||||
}) => {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "0.375rem" }}>
|
||||
<span>{label}</span>
|
||||
<span>{content}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function RenderCoBinaryStream({
|
||||
value,
|
||||
items,
|
||||
}: {
|
||||
items: BinaryStreamItem[];
|
||||
value: RawBinaryCoStream;
|
||||
}) {
|
||||
const [file, setFile] = useState<
|
||||
| {
|
||||
blob: Blob;
|
||||
mimeType: string;
|
||||
unfinishedChunks: boolean;
|
||||
totalSize: number | undefined;
|
||||
}
|
||||
| undefined
|
||||
| null
|
||||
>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// load only the first chunk to get the mime type and size
|
||||
getBlobFromCoStream({
|
||||
items,
|
||||
onlyFirstChunk: true,
|
||||
})
|
||||
.then((v) => {
|
||||
if (v) {
|
||||
setFile(v);
|
||||
if (v.mimeType.includes("image")) {
|
||||
// If it's an image, load the full blob
|
||||
getBlobFromCoStream({
|
||||
items,
|
||||
}).then((s) => {
|
||||
if (s) setFile(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
}, [items]);
|
||||
|
||||
if (!isLoading && !file) return <div>No blob</div>;
|
||||
|
||||
if (isLoading) return <div>Loading...</div>;
|
||||
if (!file) return <div>No blob</div>;
|
||||
|
||||
const { blob, mimeType } = file;
|
||||
|
||||
const sizeInKB = (file.totalSize || 0) / 1024;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
marginTop: "2rem",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "2rem",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(3, 1fr)",
|
||||
gap: "0.5rem",
|
||||
maxWidth: "48rem",
|
||||
}}
|
||||
>
|
||||
<LabelContentPair
|
||||
label="Mime Type"
|
||||
content={
|
||||
<span
|
||||
style={{
|
||||
fontFamily: "monospace",
|
||||
backgroundColor: "rgb(243 244 246)",
|
||||
borderRadius: "0.25rem",
|
||||
padding: "0.25rem 0.5rem",
|
||||
fontSize: "0.875rem",
|
||||
}}
|
||||
>
|
||||
{mimeType || "No mime type"}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<LabelContentPair
|
||||
label="Size"
|
||||
content={<span>{sizeInKB.toFixed(2)} KB</span>}
|
||||
/>
|
||||
<LabelContentPair
|
||||
label="Download"
|
||||
content={
|
||||
<BinaryDownloadButton
|
||||
fileName={value.id.toString()}
|
||||
pdfBlob={blob}
|
||||
mimeType={mimeType}
|
||||
label={
|
||||
mimeType === "application/pdf"
|
||||
? "Download PDF"
|
||||
: "Download File"
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{mimeType === "image/png" || mimeType === "image/jpeg" ? (
|
||||
<LabelContentPair
|
||||
label="Preview"
|
||||
content={
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: "rgb(249 250 251)",
|
||||
padding: "0.75rem",
|
||||
borderRadius: "0.125rem",
|
||||
}}
|
||||
>
|
||||
<RenderBlobImage blob={blob} />
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RenderCoStream({
|
||||
value,
|
||||
node,
|
||||
}: {
|
||||
value: RawCoStream;
|
||||
node: LocalNode;
|
||||
}) {
|
||||
const streamPerUser = Object.keys(value.items);
|
||||
const userCoIds = streamPerUser.map((stream) => stream.split("_session")[0]);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(3, 1fr)",
|
||||
gap: "0.5rem",
|
||||
}}
|
||||
>
|
||||
{userCoIds.map((id, idx) => (
|
||||
<div
|
||||
style={{
|
||||
padding: "0.75rem",
|
||||
borderRadius: "0.5rem",
|
||||
overflow: "hidden",
|
||||
backgroundColor: "white",
|
||||
border: "1px solid #e5e7eb",
|
||||
cursor: "pointer",
|
||||
boxShadow: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
|
||||
transition: "background-color 0.2s",
|
||||
}}
|
||||
onMouseOver={(e) =>
|
||||
(e.currentTarget.style.backgroundColor =
|
||||
"rgba(243, 244, 246, 0.05)")
|
||||
}
|
||||
onMouseOut={(e) => (e.currentTarget.style.backgroundColor = "white")}
|
||||
key={id}
|
||||
>
|
||||
<AccountOrGroupPreview coId={id as CoID<RawCoValue>} node={node} />
|
||||
{/* @ts-expect-error - TODO: fix types */}
|
||||
{value.items[streamPerUser[idx]]?.map(
|
||||
(item: CoStreamItem<JsonValue>) => (
|
||||
<div>
|
||||
{new Date(item.madeAt).toLocaleString()}{" "}
|
||||
{JSON.stringify(item.value)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CoStreamView({
|
||||
value,
|
||||
node,
|
||||
}: {
|
||||
data: JsonObject;
|
||||
onNavigate: (pages: PageInfo[]) => void;
|
||||
node: LocalNode;
|
||||
value: RawCoStream;
|
||||
}) {
|
||||
// if (!value) return <div>No value</div>;
|
||||
|
||||
const streamType = detectCoStreamType(value);
|
||||
|
||||
if (streamType.type === "binary") {
|
||||
if (streamType.items === undefined) {
|
||||
return <div>No binary stream</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<RenderCoBinaryStream
|
||||
value={value as RawBinaryCoStream}
|
||||
items={streamType.items}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (streamType.type === "coStream") {
|
||||
return <RenderCoStream value={value} node={node} />;
|
||||
}
|
||||
|
||||
if (streamType.type === "unknown") return <div>Unknown stream type</div>;
|
||||
|
||||
return <div>Unknown stream type</div>;
|
||||
}
|
||||
|
||||
function RenderBlobImage({ blob }: { blob: Blob }) {
|
||||
const urlCreator = window.URL || window.webkitURL;
|
||||
return <img src={urlCreator.createObjectURL(blob)} />;
|
||||
}
|
||||
103
packages/jazz-inspector/src/viewer/grid-view.tsx
Normal file
103
packages/jazz-inspector/src/viewer/grid-view.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||
import { JsonObject } from "cojson/src/jsonValue.ts";
|
||||
import { ResolveIcon } from "./type-icon.tsx";
|
||||
import { PageInfo, isCoId } from "./types.ts";
|
||||
import { CoMapPreview, ValueRenderer } from "./value-renderer.tsx";
|
||||
|
||||
export function GridView({
|
||||
data,
|
||||
onNavigate,
|
||||
node,
|
||||
}: {
|
||||
data: JsonObject;
|
||||
onNavigate: (pages: PageInfo[]) => void;
|
||||
node: LocalNode;
|
||||
}) {
|
||||
const entries = Object.entries(data);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "1fr",
|
||||
gap: "1rem",
|
||||
padding: "0.5rem",
|
||||
}}
|
||||
>
|
||||
{entries.map(([key, child], childIndex) => (
|
||||
<div
|
||||
key={childIndex}
|
||||
style={{
|
||||
padding: "0.75rem",
|
||||
borderRadius: "0.5rem",
|
||||
overflow: "hidden",
|
||||
transition: "background-color 0.2s",
|
||||
...(isCoId(child)
|
||||
? {
|
||||
backgroundColor: "white",
|
||||
border: "1px solid #e5e7eb",
|
||||
cursor: "pointer",
|
||||
boxShadow: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
|
||||
":hover": {
|
||||
backgroundColor: "rgba(243, 244, 246, 0.05)",
|
||||
},
|
||||
}
|
||||
: {
|
||||
backgroundColor: "rgb(249, 250, 251)",
|
||||
}),
|
||||
}}
|
||||
onClick={() =>
|
||||
isCoId(child) &&
|
||||
onNavigate([{ coId: child as CoID<RawCoValue>, name: key }])
|
||||
}
|
||||
>
|
||||
<h3
|
||||
style={{
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{isCoId(child) ? (
|
||||
<span
|
||||
style={{
|
||||
fontWeight: 500,
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
}}
|
||||
>
|
||||
{key}
|
||||
|
||||
<div
|
||||
style={{
|
||||
padding: "0.25rem 0.5rem",
|
||||
fontSize: "0.75rem",
|
||||
backgroundColor: "rgb(243, 244, 246)",
|
||||
borderRadius: "0.25rem",
|
||||
}}
|
||||
>
|
||||
<ResolveIcon coId={child as CoID<RawCoValue>} node={node} />
|
||||
</div>
|
||||
</span>
|
||||
) : (
|
||||
<span>{key}</span>
|
||||
)}
|
||||
</h3>
|
||||
<div style={{ marginTop: "0.5rem", fontSize: "0.875rem" }}>
|
||||
{isCoId(child) ? (
|
||||
<CoMapPreview coId={child as CoID<RawCoValue>} node={node} />
|
||||
) : (
|
||||
<ValueRenderer
|
||||
json={child}
|
||||
onCoIDClick={(coId) => {
|
||||
onNavigate([{ coId, name: key }]);
|
||||
}}
|
||||
compact
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
164
packages/jazz-inspector/src/viewer/new-app.tsx
Normal file
164
packages/jazz-inspector/src/viewer/new-app.tsx
Normal file
@@ -0,0 +1,164 @@
|
||||
import { CoID, RawCoValue } from "cojson";
|
||||
import { createUseAccountHooks } from "jazz-react-core";
|
||||
import React, { useState } from "react";
|
||||
import { Breadcrumbs } from "./breadcrumbs.tsx";
|
||||
import { PageStack } from "./page-stack.tsx";
|
||||
import { usePagePath } from "./use-page-path.ts";
|
||||
|
||||
const { useAccount } = createUseAccountHooks();
|
||||
|
||||
export function JazzInspector() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [coValueId, setCoValueId] = useState<CoID<RawCoValue> | "">("");
|
||||
const { path, addPages, goToIndex, goBack, setPage } = usePagePath();
|
||||
|
||||
const { me } = useAccount();
|
||||
const localNode = me._raw.core.node;
|
||||
|
||||
const handleCoValueIdSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (coValueId) {
|
||||
setPage(coValueId);
|
||||
}
|
||||
};
|
||||
|
||||
if (!open) {
|
||||
return (
|
||||
<button
|
||||
onClick={() => setOpen(true)}
|
||||
style={{
|
||||
position: "fixed",
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
margin: "1rem",
|
||||
backgroundColor: "white",
|
||||
border: "1px solid #e5e7eb",
|
||||
borderRadius: "0.5rem",
|
||||
padding: "6px",
|
||||
}}
|
||||
>
|
||||
Jazz Inspector
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: "fixed",
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
width: "100%",
|
||||
backgroundColor: "white",
|
||||
borderTop: "1px solid #e5e7eb",
|
||||
padding: "1rem",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "1rem",
|
||||
}}
|
||||
>
|
||||
<Breadcrumbs path={path} onBreadcrumbClick={goToIndex} />
|
||||
<button onClick={() => setOpen(false)}>Close</button>
|
||||
</div>
|
||||
|
||||
<PageStack
|
||||
path={path}
|
||||
node={localNode}
|
||||
goBack={goBack}
|
||||
addPages={addPages}
|
||||
>
|
||||
<form
|
||||
onSubmit={handleCoValueIdSubmit}
|
||||
aria-hidden={path.length !== 0}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
gap: "0.5rem",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
marginBottom: "5rem",
|
||||
transition: "all 150ms",
|
||||
opacity: path.length > 0 ? 0 : 1,
|
||||
transform:
|
||||
path.length > 0 ? "translateY(-0.5rem) scale(0.95)" : "none",
|
||||
}}
|
||||
>
|
||||
<fieldset
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "0.5rem",
|
||||
fontSize: "0.875rem",
|
||||
}}
|
||||
>
|
||||
<h2
|
||||
style={{
|
||||
fontSize: "1.875rem",
|
||||
fontWeight: 500,
|
||||
color: "#030712",
|
||||
textAlign: "center",
|
||||
marginBottom: "1rem",
|
||||
}}
|
||||
>
|
||||
Jazz CoValue Inspector
|
||||
</h2>
|
||||
<input
|
||||
style={{
|
||||
border: "1px solid #e5e7eb",
|
||||
padding: "1rem",
|
||||
borderRadius: "0.5rem",
|
||||
minWidth: "21rem",
|
||||
fontFamily: "monospace",
|
||||
}}
|
||||
placeholder="co_z1234567890abcdef123456789"
|
||||
value={coValueId}
|
||||
onChange={(e) => setCoValueId(e.target.value as CoID<RawCoValue>)}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
style={{
|
||||
backgroundColor: "rgb(99 102 241)",
|
||||
color: "white",
|
||||
padding: "0.5rem 1rem",
|
||||
borderRadius: "0.375rem",
|
||||
}}
|
||||
onMouseOver={(e) =>
|
||||
(e.currentTarget.style.backgroundColor =
|
||||
"rgba(99 102 241, 0.8)")
|
||||
}
|
||||
onMouseOut={(e) =>
|
||||
(e.currentTarget.style.backgroundColor = "rgb(99 102 241)")
|
||||
}
|
||||
>
|
||||
Inspect
|
||||
</button>
|
||||
<hr />
|
||||
<button
|
||||
type="button"
|
||||
style={{
|
||||
border: "1px solid #e5e7eb",
|
||||
display: "inline-block",
|
||||
padding: "0.375rem 0.5rem",
|
||||
color: "black",
|
||||
borderRadius: "0.375rem",
|
||||
}}
|
||||
onClick={() => {
|
||||
setCoValueId(me._raw.id);
|
||||
setPage(me._raw.id);
|
||||
}}
|
||||
>
|
||||
Inspect My Account
|
||||
</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</PageStack>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user