Compare commits
1 Commits
jazz-react
...
not-found-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b426342c02 |
5
.changeset/afraid-queens-bathe.md
Normal file
5
.changeset/afraid-queens-bathe.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"cojson": patch
|
||||
---
|
||||
|
||||
Export the coValue loading config to reduce the timeout on tests
|
||||
8
.changeset/silent-turtles-obey.md
Normal file
8
.changeset/silent-turtles-obey.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"jazz-react-core": minor
|
||||
"jazz-svelte": minor
|
||||
"jazz-tools": minor
|
||||
"jazz-vue": minor
|
||||
---
|
||||
|
||||
Return null when a coValue is not found
|
||||
@@ -1,25 +1,5 @@
|
||||
# chat-rn-clerk
|
||||
|
||||
## 1.0.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react-native@0.9.21
|
||||
- jazz-react-native-auth-clerk@0.9.21
|
||||
- jazz-react-native-media-images@0.9.21
|
||||
|
||||
## 1.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react-native@0.9.20
|
||||
- jazz-react-native-auth-clerk@0.9.20
|
||||
- jazz-react-native-media-images@0.9.20
|
||||
|
||||
## 1.0.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "chat-rn-clerk",
|
||||
"main": "index.js",
|
||||
"version": "1.0.62",
|
||||
"version": "1.0.60",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# chat-rn
|
||||
|
||||
## 1.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react-native@0.9.21
|
||||
|
||||
## 1.0.58
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react-native@0.9.20
|
||||
|
||||
## 1.0.57
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn",
|
||||
"version": "1.0.59",
|
||||
"version": "1.0.57",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# chat-vue
|
||||
|
||||
## 0.0.46
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
- jazz-vue@0.9.21
|
||||
|
||||
## 0.0.45
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
- jazz-vue@0.9.20
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-vue",
|
||||
"version": "0.0.46",
|
||||
"version": "0.0.44",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-example-chat
|
||||
|
||||
## 0.0.142
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.141
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.140
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-chat",
|
||||
"private": true,
|
||||
"version": "0.0.142",
|
||||
"version": "0.0.140",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# minimal-auth-clerk
|
||||
|
||||
## 0.0.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
- jazz-react-auth-clerk@0.9.21
|
||||
|
||||
## 0.0.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
- jazz-react-auth-clerk@0.9.20
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clerk",
|
||||
"private": true,
|
||||
"version": "0.0.41",
|
||||
"version": "0.0.39",
|
||||
"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.21",
|
||||
"jazz-react-auth-clerk": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# file-share-svelte
|
||||
|
||||
## 0.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-svelte@0.9.21
|
||||
|
||||
## 0.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-svelte@0.9.20
|
||||
|
||||
## 0.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "file-share-svelte",
|
||||
"version": "0.0.26",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# form
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "form",
|
||||
"private": true,
|
||||
"version": "0.0.37",
|
||||
"version": "0.0.35",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# image-upload
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "image-upload",
|
||||
"private": true,
|
||||
"version": "0.0.39",
|
||||
"version": "0.0.37",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-example-musicplayer
|
||||
|
||||
## 0.0.63
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-inspector@0.9.22
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-inspector@0.9.21
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-music-player",
|
||||
"private": true,
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.61",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -18,8 +18,8 @@
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"jazz-react": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-react": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"lucide-react": "^0.274.0",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-example-onboarding
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-onboarding",
|
||||
"private": true,
|
||||
"version": "0.0.43",
|
||||
"version": "0.0.41",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# organization
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "organization",
|
||||
"private": true,
|
||||
"version": "0.0.35",
|
||||
"version": "0.0.33",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
# passkey-svelte
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.21
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.9.20
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "passkey-svelte",
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.28",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# minimal-auth-passkey
|
||||
|
||||
## 0.0.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "passkey",
|
||||
"private": true,
|
||||
"version": "0.0.40",
|
||||
"version": "0.0.38",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-password-manager
|
||||
|
||||
## 0.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-password-manager",
|
||||
"private": true,
|
||||
"version": "0.0.61",
|
||||
"version": "0.0.59",
|
||||
"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.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-react": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.41.5",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-example-pets
|
||||
|
||||
## 0.0.159
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.158
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.157
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-pets",
|
||||
"private": true,
|
||||
"version": "0.0.159",
|
||||
"version": "0.0.157",
|
||||
"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.21",
|
||||
"jazz-react": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-browser-media-images": "workspace:0.9.19",
|
||||
"jazz-react": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"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.21",
|
||||
"jazz-run": "workspace:0.9.19",
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.4.15",
|
||||
"typescript": "~5.6.2",
|
||||
|
||||
@@ -7,7 +7,7 @@ import QRCode from "qrcode";
|
||||
|
||||
import { Button, useToast } from "../basicComponents";
|
||||
|
||||
export function ShareButton({ petPost }: { petPost?: PetPost }) {
|
||||
export function ShareButton({ petPost }: { petPost?: PetPost | null }) {
|
||||
const [existingInviteLink, setExistingInviteLink] = useState<string>();
|
||||
const { toast } = useToast();
|
||||
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# reactions
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-media-images@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-media-images@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "reactions",
|
||||
"private": true,
|
||||
"version": "0.0.39",
|
||||
"version": "0.0.37",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# todo-vue
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
- jazz-vue@0.9.21
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
- jazz-vue@0.9.20
|
||||
|
||||
## 0.0.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "todo-vue",
|
||||
"version": "0.0.44",
|
||||
"version": "0.0.42",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-example-todo
|
||||
|
||||
## 0.0.158
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.157
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.156
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-todo",
|
||||
"private": true,
|
||||
"version": "0.0.158",
|
||||
"version": "0.0.156",
|
||||
"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.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-react": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -10,7 +10,7 @@ export function InviteButton<T extends CoValue>({
|
||||
value,
|
||||
valueHint,
|
||||
}: {
|
||||
value?: T;
|
||||
value?: T | null;
|
||||
valueHint?: string;
|
||||
}) {
|
||||
const [existingInviteLink, setExistingInviteLink] = useState<string>();
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# version-history
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "version-history",
|
||||
"private": true,
|
||||
"version": "0.0.36",
|
||||
"version": "0.0.34",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
12
flake.lock
generated
12
flake.lock
generated
@@ -5,11 +5,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"lastModified": 1726560853,
|
||||
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1737885589,
|
||||
"narHash": "sha256-Zf0hSrtzaM1DEz8//+Xs51k/wdSajticVrATqDrfQjg=",
|
||||
"lastModified": 1730785428,
|
||||
"narHash": "sha256-Zwl8YgTVJTEum+L+0zVAWvXAGbWAuXHax3KzuejaDyo=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "852ff1d9e153d8875a83602e03fdef8a63f0ecf8",
|
||||
"rev": "4aa36568d413aca0ea84a1684d2d46f55dbabad7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
buildInputs = with pkgs; [
|
||||
nodejs_22
|
||||
nodePackages.pnpm
|
||||
git
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo ""
|
||||
echo "Welcome to the Jazz development environment!"
|
||||
echo "Run 'pnpm install' to install the dependencies."
|
||||
echo ""
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
3
homepage/homepage/.gitignore
vendored
3
homepage/homepage/.gitignore
vendored
@@ -40,6 +40,3 @@ codeSamples
|
||||
.turbo
|
||||
|
||||
.env
|
||||
|
||||
# LLM docs
|
||||
public/llms*.txt
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DocsLayout from "@/app/docs/[framework]/(others)/layout";
|
||||
import { TableOfContents } from "@/components/docs/TableOfContents";
|
||||
import ComingSoonPage from "@/components/docs/coming-soon.mdx";
|
||||
import { docNavigationItems } from "@/lib/docNavigationItems.js";
|
||||
import { docNavigationItems } from "@/lib/docNavigationItems";
|
||||
import { Framework, frameworks } from "@/lib/framework";
|
||||
import type { Toc } from "@stefanprobst/rehype-extract-toc";
|
||||
import { Prose } from "gcmp-design-system/src/app/components/molecules/Prose";
|
||||
|
||||
@@ -39,20 +39,7 @@ Sync and persist your data by setting up a [sync and storage infrastructure](/do
|
||||
|
||||
Learn how to structure your data using [collaborative values](/docs/schemas/covalues).
|
||||
|
||||
## API Reference
|
||||
|
||||
Many of the packages provided are documented in the [API Reference](/api-reference).
|
||||
|
||||
## LLM Docs
|
||||
|
||||
We support the [llms.txt](https://llmstxt.org/) convention for making documentation available to large language models and the applications that make use of them.
|
||||
|
||||
We currently have:
|
||||
|
||||
- [/llms.txt](/llms.txt) - A overview listing of the available packages and their documentation
|
||||
- [/llms-full.txt](/llms-full.txt) - Full documentation for our packages
|
||||
|
||||
## Get support
|
||||
|
||||
If you have any questions or need assistance, please don't hesitate to reach out to us on [Discord](https://discord.gg/utDMjHYg42).
|
||||
We would love to help you get started.
|
||||
We would love to help you get started.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { SideNav } from "@/components/SideNav";
|
||||
import { SideNavHeader } from "@/components/SideNavHeader";
|
||||
import { FrameworkSelect } from "@/components/docs/FrameworkSelect";
|
||||
import { docNavigationItems } from "@/lib/docNavigationItems.js";
|
||||
import { docNavigationItems } from "@/lib/docNavigationItems";
|
||||
import { useFramework } from "@/lib/use-framework";
|
||||
import { clsx } from "clsx";
|
||||
|
||||
|
||||
@@ -156,14 +156,8 @@ export function FnDecl({
|
||||
doc: ReactNode;
|
||||
example: ReactNode;
|
||||
}) {
|
||||
// Extract the method name from the signature (everything before the first parenthesis or type parameter)
|
||||
const methodName = signature.match(/^[^(<]+/)?.[0];
|
||||
|
||||
return (
|
||||
<div
|
||||
id={methodName}
|
||||
className="text-sm flex flex-col gap-3 my-2 p-3 rounded bg-stone-50 dark:bg-stone-925"
|
||||
>
|
||||
<div className="text-sm flex flex-col gap-3 my-2 p-3 rounded bg-stone-50 dark:bg-stone-925">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div>
|
||||
{<Highlight>{signature + ":"}</Highlight>}{" "}
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
import { Application } from "typedoc";
|
||||
import { PACKAGES } from "./utils/config.mjs";
|
||||
|
||||
for (const { packageName, entryPoint, tsconfig, typedocOptions } of PACKAGES) {
|
||||
for (const { packageName, entryPoint, tsconfig, typedocOptions } of [
|
||||
{
|
||||
packageName: "jazz-tools",
|
||||
entryPoint: "exports.ts",
|
||||
},
|
||||
{
|
||||
packageName: "jazz-react",
|
||||
entryPoint: "index.ts",
|
||||
typedocOptions: {
|
||||
skipErrorChecking: true, // TODO: remove this. Temporary workaround
|
||||
},
|
||||
},
|
||||
{ packageName: "jazz-browser" },
|
||||
{ packageName: "jazz-browser-media-images" },
|
||||
{ packageName: "jazz-nodejs" },
|
||||
]) {
|
||||
const app = await Application.bootstrapWithPlugins({
|
||||
entryPoints: [
|
||||
`../../packages/${packageName}/src/${entryPoint || "index.ts"}`,
|
||||
@@ -1,511 +0,0 @@
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { Deserializer, ReflectionKind } from "typedoc";
|
||||
import { DOC_SECTIONS, PACKAGES } from "./utils/config.mjs";
|
||||
import {
|
||||
getPackageDescription,
|
||||
loadTypedocFiles,
|
||||
writeDocsFile,
|
||||
} from "./utils/index.mjs";
|
||||
|
||||
function formatType(type) {
|
||||
if (!type) return "unknown";
|
||||
|
||||
// Handle type aliases and references
|
||||
if (type.type === "reference") {
|
||||
const name = type.package ? `${type.package}.${type.name}` : type.name;
|
||||
return (
|
||||
name +
|
||||
(type.typeArguments
|
||||
? `<${type.typeArguments.map(formatType).join(", ")}>`
|
||||
: "")
|
||||
);
|
||||
}
|
||||
|
||||
// Handle union types
|
||||
if (type.type === "union") {
|
||||
return type.types.map(formatType).join(" | ");
|
||||
}
|
||||
|
||||
// Handle array types
|
||||
if (type.type === "array") {
|
||||
return `${formatType(type.elementType)}[]`;
|
||||
}
|
||||
|
||||
// Handle basic types
|
||||
if (type.type === "intrinsic" || type.type === "literal") {
|
||||
return typeof type.value !== "undefined"
|
||||
? JSON.stringify(type.value)
|
||||
: type.name;
|
||||
}
|
||||
|
||||
// Handle tuple types
|
||||
if (type.type === "tuple") {
|
||||
return `[${type.elements.map(formatType).join(", ")}]`;
|
||||
}
|
||||
|
||||
// Handle intersection types
|
||||
if (type.type === "intersection") {
|
||||
return type.types.map(formatType).join(" & ");
|
||||
}
|
||||
|
||||
// Handle template literal types
|
||||
if (type.type === "template-literal") {
|
||||
return `\`${type.head}${type.tail.map((t) => `\${${formatType(t[0])}}${t[1]}`).join("")}\``;
|
||||
}
|
||||
|
||||
// Handle reflection types (object types and function types)
|
||||
if (type.type === "reflection") {
|
||||
if (type.declaration.signatures) {
|
||||
const sig = type.declaration.signatures[0];
|
||||
const params =
|
||||
sig.parameters
|
||||
?.map(
|
||||
(p) =>
|
||||
`${p.name}${p.flags?.isOptional ? "?" : ""}: ${formatType(p.type)}`,
|
||||
)
|
||||
.join(", ") || "";
|
||||
return `(${params}) => ${formatType(sig.type)}`;
|
||||
}
|
||||
|
||||
if (type.declaration.children) {
|
||||
return (
|
||||
"{ " +
|
||||
type.declaration.children
|
||||
.map((child) => {
|
||||
const optional = child.flags?.isOptional ? "?" : "";
|
||||
return `${child.name}${optional}: ${formatType(child.type)}`;
|
||||
})
|
||||
.join("; ") +
|
||||
" }"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle query types
|
||||
if (type.type === "query") {
|
||||
return `typeof ${formatType(type.queryType)}`;
|
||||
}
|
||||
|
||||
// Handle conditional types
|
||||
if (type.type === "conditional") {
|
||||
return `${formatType(type.checkType)} extends ${formatType(type.extendsType)} ? ${formatType(type.trueType)} : ${formatType(type.falseType)}`;
|
||||
}
|
||||
|
||||
// Handle index access types
|
||||
if (type.type === "indexedAccess") {
|
||||
return `${formatType(type.objectType)}[${formatType(type.indexType)}]`;
|
||||
}
|
||||
|
||||
// Handle mapped types
|
||||
if (type.type === "mapped") {
|
||||
const readonly = type.readonlyModifier === "+" ? "readonly " : "";
|
||||
const optional = type.optionalModifier === "+" ? "?" : "";
|
||||
return `{ ${readonly}[${type.parameter} in ${formatType(type.parameterType)}]${optional}: ${formatType(type.templateType)} }`;
|
||||
}
|
||||
|
||||
// Handle type operators
|
||||
if (type.type === "typeOperator") {
|
||||
return `${type.operator} ${formatType(type.target)}`;
|
||||
}
|
||||
|
||||
// Handle predicate types
|
||||
if (type.type === "predicate") {
|
||||
return `${type.name} is ${formatType(type.targetType)}`;
|
||||
}
|
||||
|
||||
// Handle inferred types
|
||||
if (type.type === "inferred") {
|
||||
return `infer ${type.name}`;
|
||||
}
|
||||
|
||||
// Handle rest types
|
||||
if (type.type === "rest") {
|
||||
return `...${formatType(type.elementType)}`;
|
||||
}
|
||||
|
||||
// Handle unknown types with more detail
|
||||
if (type.toString) {
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
function formatComment(comment) {
|
||||
if (!comment) return "";
|
||||
|
||||
let text =
|
||||
comment.summary
|
||||
?.map((part) => part.text)
|
||||
.join("")
|
||||
.trim() || "";
|
||||
|
||||
// Add parameter descriptions if available
|
||||
if (comment.blockTags) {
|
||||
const params = comment.blockTags
|
||||
.filter((tag) => tag.tag === "@param")
|
||||
.map((tag) => {
|
||||
const paramName = tag.param;
|
||||
let description = "";
|
||||
let codeExample = "";
|
||||
|
||||
tag.content.forEach((part) => {
|
||||
if (part.kind === "code") {
|
||||
// Don't wrap in code blocks since examples are already wrapped
|
||||
codeExample += "\n" + part.text + "\n";
|
||||
} else {
|
||||
description += part.text;
|
||||
}
|
||||
});
|
||||
|
||||
return `- ${paramName}: ${description.trim()}${codeExample}`;
|
||||
});
|
||||
|
||||
if (params.length > 0) {
|
||||
text += "\n\nParameters:\n" + params.join("\n");
|
||||
}
|
||||
|
||||
// Add remarks if available
|
||||
const remarks = comment.blockTags
|
||||
.filter((tag) => tag.tag === "@remarks")
|
||||
.map((tag) =>
|
||||
tag.content
|
||||
.map((part) => part.text)
|
||||
.join("")
|
||||
.trim(),
|
||||
);
|
||||
|
||||
if (remarks.length > 0) {
|
||||
text += "\n\nRemarks:\n" + remarks.join("\n");
|
||||
}
|
||||
|
||||
// Add examples
|
||||
const examples = comment.blockTags
|
||||
.filter((tag) => tag.tag === "@example")
|
||||
.map((tag) =>
|
||||
tag.content
|
||||
.map((part) => {
|
||||
if (part.kind === "code") {
|
||||
// Don't wrap in code blocks since examples are already wrapped
|
||||
return "\n" + part.text + "\n";
|
||||
}
|
||||
return part.text;
|
||||
})
|
||||
.join("")
|
||||
.trim(),
|
||||
);
|
||||
|
||||
if (examples.length > 0) {
|
||||
text += "\n\nExamples:\n" + examples.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
async function readMdxContent(url) {
|
||||
try {
|
||||
// Special case for the introduction
|
||||
if (url === "/docs") {
|
||||
const introPath = path.join(
|
||||
process.cwd(),
|
||||
"components/docs/docs-intro.mdx",
|
||||
);
|
||||
try {
|
||||
const content = await fs.readFile(introPath, "utf8");
|
||||
// Remove imports and exports
|
||||
return content
|
||||
.replace(/^import[^\n]*\n/gm, "")
|
||||
.replace(/export const metadata[^;]*;/, "")
|
||||
.trim();
|
||||
} catch (err) {
|
||||
if (err.code !== "ENOENT") throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert URL to file path
|
||||
// Remove leading slash and 'docs' from URL
|
||||
const relativePath = url.replace(/^\/docs\/?/, "");
|
||||
|
||||
// Base directory for docs
|
||||
const baseDir = path.join(process.cwd(), "app/docs/[framework]/[...slug]");
|
||||
|
||||
// If it's a directory, try to read all framework variants
|
||||
const fullPath = path.join(baseDir, relativePath);
|
||||
try {
|
||||
const stats = await fs.stat(fullPath);
|
||||
if (stats.isDirectory()) {
|
||||
// Read all MDX files in the directory
|
||||
const files = await fs.readdir(fullPath);
|
||||
const mdxFiles = files.filter((f) => f.endsWith(".mdx"));
|
||||
|
||||
if (mdxFiles.length === 0) return null;
|
||||
|
||||
// Combine content from all framework variants
|
||||
const contents = await Promise.all(
|
||||
mdxFiles.map(async (file) => {
|
||||
const content = await fs.readFile(
|
||||
path.join(fullPath, file),
|
||||
"utf8",
|
||||
);
|
||||
// Remove imports and exports
|
||||
const cleanContent = content
|
||||
.replace(/^import[^\n]*\n/gm, "")
|
||||
.replace(/export const metadata[^;]*;/, "")
|
||||
.trim();
|
||||
return `### ${path.basename(file, ".mdx")} Implementation\n\n${cleanContent}`;
|
||||
}),
|
||||
);
|
||||
|
||||
return contents.join("\n\n---\n\n");
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code !== "ENOENT") throw err;
|
||||
}
|
||||
|
||||
// Try as a single MDX file
|
||||
const mdxPath = fullPath + ".mdx";
|
||||
try {
|
||||
const content = await fs.readFile(mdxPath, "utf8");
|
||||
// Remove imports and exports
|
||||
return content
|
||||
.replace(/^import[^\n]*\n/gm, "")
|
||||
.replace(/export const metadata[^;]*;/, "")
|
||||
.trim();
|
||||
} catch (err) {
|
||||
if (err.code !== "ENOENT") throw err;
|
||||
}
|
||||
|
||||
console.warn(`Could not find MDX content for ${url} at ${fullPath}`);
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.warn(`Error reading MDX content for ${url}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function generateDetailedDocs(docs) {
|
||||
const output = [];
|
||||
const deserializer = new Deserializer();
|
||||
|
||||
// Project title
|
||||
output.push("# Jazz\n");
|
||||
|
||||
// Documentation sections with full content
|
||||
output.push("## Documentation\n");
|
||||
for (const section of DOC_SECTIONS) {
|
||||
output.push(`### ${section.title}\n`);
|
||||
|
||||
for (const page of section.pages) {
|
||||
output.push(`#### ${page.title}\n`);
|
||||
const content = await readMdxContent(page.url);
|
||||
console.log(content);
|
||||
if (content) {
|
||||
// If the content contains framework-specific implementations, they're already properly formatted
|
||||
// Otherwise, just add the content directly
|
||||
output.push(content + "\n");
|
||||
}
|
||||
output.push("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// API Reference by package
|
||||
output.push("## API Reference\n\n");
|
||||
// for (const [packageName, packageDocs] of Object.entries(docs)) {
|
||||
// const project = deserializer.reviveProject(packageDocs, packageName);
|
||||
|
||||
// // Add package heading with description
|
||||
// output.push(`### ${packageName}\n`);
|
||||
// output.push(`${getPackageDescription(packageName)}\n\n`);
|
||||
// output.push(
|
||||
// `[API Reference](https://jazz.tools/api-reference/${packageName})\n\n`,
|
||||
// );
|
||||
|
||||
// // Process each category
|
||||
// project.categories?.forEach((category) => {
|
||||
// output.push(`#### ${category.title}\n`);
|
||||
|
||||
// category.children.forEach((child) => {
|
||||
// // Add name, kind, and API reference link
|
||||
// const apiLink = `[API Reference](https://jazz.tools/api-reference/${packageName}#${child.name})`;
|
||||
// output.push(
|
||||
// `##### ${child.name} (${ReflectionKind[child.kind]}) ${apiLink}\n`,
|
||||
// );
|
||||
|
||||
// // Add description if available
|
||||
// const description = formatComment(child.comment);
|
||||
// if (description) {
|
||||
// output.push(`${description}\n`);
|
||||
// }
|
||||
|
||||
// output.push("\n");
|
||||
|
||||
// // Add properties for classes/interfaces
|
||||
// if (child.children) {
|
||||
// output.push("Properties:\n");
|
||||
|
||||
// // Group overloaded methods by name
|
||||
// const methodGroups = new Map();
|
||||
// child.children.forEach((prop) => {
|
||||
// if (prop.signatures?.length > 0) {
|
||||
// const existing = methodGroups.get(prop.name) || [];
|
||||
// methodGroups.set(prop.name, [...existing, prop]);
|
||||
// }
|
||||
// });
|
||||
|
||||
// child.children.forEach((prop) => {
|
||||
// // Skip if this is an overloaded method that we'll handle later
|
||||
// if (
|
||||
// prop.signatures?.length > 0 &&
|
||||
// methodGroups.get(prop.name)?.length > 1
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const type = formatType(prop.type);
|
||||
// const description = formatComment(prop.comment);
|
||||
|
||||
// // Output the property name and type, but skip the type for methods since we'll show signatures
|
||||
// if (prop.signatures?.length > 0) {
|
||||
// output.push(
|
||||
// `- ${prop.name}${description ? ` - ${description}` : ""}\n`,
|
||||
// );
|
||||
// } else {
|
||||
// output.push(
|
||||
// `- ${prop.name}: ${type}${description ? ` - ${description}` : ""}\n`,
|
||||
// );
|
||||
// }
|
||||
|
||||
// // Handle method signatures with proper indentation
|
||||
// if (prop.signatures) {
|
||||
// prop.signatures.forEach((sig) => {
|
||||
// const params = sig.parameters
|
||||
// ?.map((p) => {
|
||||
// const paramType = formatType(p.type);
|
||||
// return `${p.name}: ${paramType}`;
|
||||
// })
|
||||
// .join(", ");
|
||||
|
||||
// output.push(
|
||||
// ` Method signature: \`(${params || ""}) => ${formatType(sig.type)}\`\n`,
|
||||
// );
|
||||
|
||||
// // Add API reference URL for the method
|
||||
// output.push(
|
||||
// ` [API Reference](https://jazz.tools/api-reference/${packageName}#${child.name}.${prop.name})\n`,
|
||||
// );
|
||||
|
||||
// const methodDesc = formatComment(sig.comment);
|
||||
// if (methodDesc) {
|
||||
// // Indent each line of the description
|
||||
// const indentedDesc = methodDesc
|
||||
// .split("\n")
|
||||
// .map((line) => ` ${line}`)
|
||||
// .join("\n");
|
||||
// output.push(`${indentedDesc}\n`);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Handle overloaded methods
|
||||
// methodGroups.forEach((props, name) => {
|
||||
// if (props.length <= 1) return;
|
||||
|
||||
// const firstProp = props[0];
|
||||
// const description = formatComment(firstProp.comment);
|
||||
|
||||
// output.push(`- ${name}${description ? ` - ${description}` : ""}\n`);
|
||||
|
||||
// // Combine all signatures with proper indentation
|
||||
// const allSignatures = props.flatMap((p) => p.signatures || []);
|
||||
// allSignatures.forEach((sig) => {
|
||||
// const params = sig.parameters
|
||||
// ?.map((p) => {
|
||||
// const paramType = formatType(p.type);
|
||||
// return `${p.name}: ${paramType}`;
|
||||
// })
|
||||
// .join(", ");
|
||||
|
||||
// output.push(
|
||||
// ` Method signature: \`(${params || ""}) => ${formatType(sig.type)}\`\n`,
|
||||
// );
|
||||
|
||||
// // Add API reference URL for the overloaded method
|
||||
// output.push(
|
||||
// ` [API Reference](https://jazz.tools/api-reference/${packageName}#${child.name}.${name})\n`,
|
||||
// );
|
||||
|
||||
// const methodDesc = formatComment(sig.comment);
|
||||
// if (methodDesc) {
|
||||
// // Indent each line of the description
|
||||
// const indentedDesc = methodDesc
|
||||
// .split("\n")
|
||||
// .map((line) => ` ${line}`)
|
||||
// .join("\n");
|
||||
// output.push(`${indentedDesc}\n`);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Add signatures for functions/methods
|
||||
// if (child.signatures) {
|
||||
// child.signatures.forEach((sig) => {
|
||||
// const params = sig.parameters
|
||||
// ?.map((p) => {
|
||||
// const type = formatType(p.type);
|
||||
// const desc = formatComment(p.comment);
|
||||
// return `${p.name}: ${type}${desc ? ` - ${desc}` : ""}`;
|
||||
// })
|
||||
// .join(", ");
|
||||
|
||||
// output.push(`Signature: ${child.name}(${params || ""})`);
|
||||
|
||||
// if (sig.type) {
|
||||
// output.push(`Returns: ${formatType(sig.type)}`);
|
||||
// if (sig.comment?.returns) {
|
||||
// output.push(
|
||||
// `Return description: ${sig.comment.returns
|
||||
// .map((part) => part.text)
|
||||
// .join("")
|
||||
// .trim()}`,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// const sigComment = formatComment(sig.comment);
|
||||
// if (sigComment) {
|
||||
// output.push(`\n${sigComment}`);
|
||||
// }
|
||||
|
||||
// output.push("\n");
|
||||
// });
|
||||
// }
|
||||
|
||||
// output.push("\n");
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// Optional section for additional resources
|
||||
output.push("## Resources\n\n");
|
||||
output.push(
|
||||
"- [Documentation](https://jazz.tools/docs): Detailed documentation about Jazz\n",
|
||||
);
|
||||
output.push(
|
||||
"- [Examples](https://jazz.tools/examples): Code examples and tutorials\n",
|
||||
);
|
||||
|
||||
await writeDocsFile("llms-full.txt", output.join("\n"));
|
||||
}
|
||||
|
||||
// Main execution
|
||||
async function main() {
|
||||
console.log("Generating detailed LLM docs...");
|
||||
const docs = await loadTypedocFiles();
|
||||
await generateDetailedDocs(docs);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,80 +0,0 @@
|
||||
import { Deserializer } from "typedoc";
|
||||
import { DOC_SECTIONS, PACKAGES } from "./utils/config.mjs";
|
||||
import {
|
||||
cleanDescription,
|
||||
loadTypedocFiles,
|
||||
writeDocsFile,
|
||||
} from "./utils/index.mjs";
|
||||
|
||||
async function generateConciseDocs(docs) {
|
||||
const output = [];
|
||||
const deserializer = new Deserializer();
|
||||
|
||||
// Project title
|
||||
output.push("# Jazz\n");
|
||||
|
||||
// Documentation sections
|
||||
output.push("## Documentation\n");
|
||||
DOC_SECTIONS.forEach((section) => {
|
||||
output.push(`### ${section.title}\n`);
|
||||
section.pages.forEach((page) => {
|
||||
output.push(`- [${page.title}](https://jazz.tools${page.url})\n`);
|
||||
});
|
||||
output.push("\n");
|
||||
});
|
||||
|
||||
// API Reference by package
|
||||
for (const [packageName, packageDocs] of Object.entries(docs)) {
|
||||
const project = deserializer.reviveProject(packageDocs, packageName);
|
||||
|
||||
// Add package heading
|
||||
output.push(`## ${packageName}\n`);
|
||||
|
||||
// Process each category and its exports with direct links
|
||||
if (project.categories) {
|
||||
const seen = new Set(); // Track seen names to avoid duplicates
|
||||
project.categories.forEach((category) => {
|
||||
category.children.forEach((child) => {
|
||||
if (seen.has(child.name)) return;
|
||||
seen.add(child.name);
|
||||
|
||||
// Get and clean up description
|
||||
let description = child.comment?.summary
|
||||
? cleanDescription(child.comment.summary)
|
||||
: "";
|
||||
|
||||
// Truncate description if it's too long
|
||||
if (description && description.length > 150) {
|
||||
description = description.substring(0, 147) + "...";
|
||||
}
|
||||
|
||||
// Create the line without wrapping
|
||||
output.push(
|
||||
`- [${child.name}](https://jazz.tools/api-reference/${packageName}#${child.name})${description ? `: ${description}` : ""}\n`,
|
||||
);
|
||||
});
|
||||
});
|
||||
output.push("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Optional section for additional resources
|
||||
output.push("## Optional\n");
|
||||
output.push(
|
||||
"- [Documentation](https://jazz.tools/docs): Detailed documentation about Jazz\n",
|
||||
);
|
||||
output.push(
|
||||
"- [Examples](https://jazz.tools/examples): Code examples and tutorials\n",
|
||||
);
|
||||
|
||||
await writeDocsFile("llms.txt", output.join(""));
|
||||
}
|
||||
|
||||
// Main execution
|
||||
async function main() {
|
||||
console.log("Generating concise LLM docs...");
|
||||
const docs = await loadTypedocFiles();
|
||||
await generateConciseDocs(docs);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,47 +0,0 @@
|
||||
import { docNavigationItems } from "../../lib/docNavigationItems.js";
|
||||
|
||||
// Transform docNavigationItems into the format we need
|
||||
function transformNavItems() {
|
||||
return docNavigationItems
|
||||
.map((section) => ({
|
||||
title: section.name,
|
||||
pages: section.items
|
||||
.filter((item) => item.done !== 0) // Skip not-yet-written docs
|
||||
.map((item) => ({
|
||||
title: item.name,
|
||||
url: item.href,
|
||||
})),
|
||||
}))
|
||||
.filter((section) => section.pages.length > 0); // Only include sections with pages
|
||||
}
|
||||
|
||||
export const DOC_SECTIONS = transformNavItems();
|
||||
|
||||
export const PACKAGES = [
|
||||
{
|
||||
packageName: "jazz-tools",
|
||||
entryPoint: "exports.ts",
|
||||
description:
|
||||
"The base implementation for Jazz, a framework for distributed state. Provides a high-level API around the CoJSON protocol.",
|
||||
},
|
||||
{
|
||||
packageName: "jazz-react",
|
||||
entryPoint: "index.ts",
|
||||
description: "React bindings for Jazz, a framework for distributed state.",
|
||||
typedocOptions: {
|
||||
skipErrorChecking: true, // TODO: remove this. Temporary workaround
|
||||
},
|
||||
},
|
||||
{
|
||||
packageName: "jazz-browser",
|
||||
description: "Browser (Vanilla JavaScript) bindings for Jazz",
|
||||
},
|
||||
{
|
||||
packageName: "jazz-browser-media-images",
|
||||
description: "Image handling utilities for Jazz in the browser",
|
||||
},
|
||||
{
|
||||
packageName: "jazz-nodejs",
|
||||
description: "NodeJS/Bun server worker bindings for Jazz",
|
||||
},
|
||||
];
|
||||
@@ -1,58 +0,0 @@
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { PACKAGES } from "./config.mjs";
|
||||
|
||||
// Common configuration
|
||||
export const PACKAGE_DESCRIPTIONS = {
|
||||
"jazz-tools":
|
||||
"The base implementation for Jazz, a framework for distributed state. Provides a high-level API around the CoJSON protocol.",
|
||||
"jazz-react": "React bindings for Jazz, a framework for distributed state.",
|
||||
"jazz-browser": "Browser (Vanilla JavaScript) bindings for Jazz",
|
||||
"jazz-browser-media-images":
|
||||
"Image handling utilities for Jazz in the browser",
|
||||
"jazz-nodejs": "NodeJS/Bun server worker bindings for Jazz",
|
||||
};
|
||||
|
||||
// Helper functions
|
||||
export async function loadTypedocFiles() {
|
||||
const docs = {};
|
||||
for (const { packageName } of PACKAGES) {
|
||||
docs[packageName] = JSON.parse(
|
||||
await fs.readFile(
|
||||
path.join(process.cwd(), "typedoc", packageName + ".json"),
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
|
||||
export function getPackageDescription(packageName) {
|
||||
const pkg = PACKAGES.find((p) => p.packageName === packageName);
|
||||
return pkg?.description || "";
|
||||
}
|
||||
|
||||
export function cleanDescription(description) {
|
||||
if (!description) return "";
|
||||
return (
|
||||
description
|
||||
.map((part) => part.text)
|
||||
.join(" ")
|
||||
.trim()
|
||||
// Remove code blocks
|
||||
.replace(/```[\s\S]*?```/g, "")
|
||||
// Remove line breaks and extra spaces
|
||||
.replace(/\s+/g, " ")
|
||||
// Clean up backticks
|
||||
.replace(/\`/g, "'")
|
||||
);
|
||||
}
|
||||
|
||||
export async function writeDocsFile(filename, content) {
|
||||
await fs.writeFile(
|
||||
path.join(process.cwd(), "public", filename),
|
||||
content,
|
||||
"utf8",
|
||||
);
|
||||
console.log(`Documentation generated at 'public/${filename}'`);
|
||||
}
|
||||
@@ -5,15 +5,11 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "NODE_OPTIONS=--max-old-space-size=8192 next dev",
|
||||
"build:generate-docs": "pnpm run generate:docs && pnpm run generate:llm-docs:all",
|
||||
"build:generate-docs": "node genDocs.mjs --build",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"generate:docs": "node generate-docs/typedocs.mjs --build",
|
||||
"generate:llm-docs:all": "pnpm run generate:llm-docs:concise && pnpm run generate:llm-docs:full",
|
||||
"generate:llm-docs:concise": "node generate-docs/llms.mjs",
|
||||
"generate:llm-docs:full": "node generate-docs/llms-full.mjs"
|
||||
"format-and-lint:fix": "biome check . --write"
|
||||
},
|
||||
"packageManager": "pnpm@9.14.0",
|
||||
"dependencies": {
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
"mdx.d.ts",
|
||||
"lib/docNavigationItems.js"
|
||||
"mdx.d.ts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
"version": "0.9.19",
|
||||
"devDependencies": {
|
||||
"@opentelemetry/sdk-metrics": "^1.29.0",
|
||||
"@types/jest": "^29.5.3",
|
||||
"typescript": "~5.6.2",
|
||||
"vitest": "1.5.3"
|
||||
},
|
||||
|
||||
@@ -4,8 +4,10 @@ import { RawCoID } from "./ids.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { PeerID } from "./sync.js";
|
||||
|
||||
export const CO_VALUE_LOADING_MAX_RETRIES = 5;
|
||||
export const CO_VALUE_LOADING_TIMEOUT = 30_000;
|
||||
export const CO_VALUE_LOADING_CONFIG = {
|
||||
MAX_RETRIES: 5,
|
||||
TIMEOUT: 30_000,
|
||||
};
|
||||
|
||||
export class CoValueUnknownState {
|
||||
type = "unknown" as const;
|
||||
@@ -227,7 +229,7 @@ export class CoValueState {
|
||||
this.getCoValue(),
|
||||
runWithRetry(
|
||||
() => doLoad(peersWithRetry),
|
||||
CO_VALUE_LOADING_MAX_RETRIES,
|
||||
CO_VALUE_LOADING_CONFIG.MAX_RETRIES,
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -313,7 +315,7 @@ async function loadCoValueFromPeers(
|
||||
peerId: peer.id,
|
||||
});
|
||||
}
|
||||
}, CO_VALUE_LOADING_TIMEOUT);
|
||||
}, CO_VALUE_LOADING_CONFIG.TIMEOUT);
|
||||
await coValueEntry.state.waitForPeer(peer.id);
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ import {
|
||||
|
||||
type Value = JsonValue | AnyRawCoValue;
|
||||
|
||||
import { CO_VALUE_LOADING_CONFIG } from "./coValueState.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { getPriorityFromHeader } from "./priority.js";
|
||||
import { FileSystem } from "./storage/FileSystem.js";
|
||||
@@ -103,6 +104,7 @@ export const cojsonInternals = {
|
||||
getGroupDependentKeyList,
|
||||
getGroupDependentKey,
|
||||
disablePermissionErrors,
|
||||
CO_VALUE_LOADING_CONFIG,
|
||||
};
|
||||
|
||||
export {
|
||||
|
||||
@@ -1,36 +1,43 @@
|
||||
import { beforeEach, describe, expect, onTestFinished, test, vi } from "vitest";
|
||||
import { describe, expect, onTestFinished, test, vi } from "vitest";
|
||||
import {
|
||||
GlobalSyncStateListenerCallback,
|
||||
PeerSyncStateListenerCallback,
|
||||
} from "../SyncStateManager.js";
|
||||
import { accountHeaderForInitialAgentSecret } from "../coValues/account.js";
|
||||
import { connectedPeers } from "../streamUtils.js";
|
||||
import { emptyKnownState } from "../sync.js";
|
||||
import {
|
||||
blockMessageTypeOnOutgoingPeer,
|
||||
connectNodeToSyncServer,
|
||||
createTestNode,
|
||||
createTwoConnectedNodes,
|
||||
loadCoValueOrFail,
|
||||
setupSyncServer,
|
||||
waitFor,
|
||||
} from "./testUtils.js";
|
||||
|
||||
let jazzCloud = setupSyncServer();
|
||||
|
||||
beforeEach(async () => {
|
||||
jazzCloud = setupSyncServer();
|
||||
});
|
||||
|
||||
describe("SyncStateManager", () => {
|
||||
test("subscribeToUpdates receives updates when peer state changes", async () => {
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const { nodeToServerPeer } = connectNodeToSyncServer(client);
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
// Connect nodes
|
||||
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
||||
"clientConnection",
|
||||
"jazzCloudConnection",
|
||||
{
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
},
|
||||
);
|
||||
|
||||
client.syncManager.addPeer(jazzCloudAsPeer);
|
||||
jazzCloud.syncManager.addPeer(clientAsPeer);
|
||||
|
||||
const subscriptionManager = client.syncManager.syncState;
|
||||
|
||||
const updateSpy: GlobalSyncStateListenerCallback = vi.fn();
|
||||
@@ -39,21 +46,21 @@ describe("SyncStateManager", () => {
|
||||
await client.syncManager.actuallySyncCoValue(map.core);
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
emptyKnownState(map.core.id),
|
||||
{ uploaded: false },
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
return subscriptionManager.getCurrentSyncState(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded;
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith(
|
||||
nodeToServerPeer.id,
|
||||
client.syncManager.peers[nodeToServerPeer.id]!.knownStates.get(
|
||||
"jazzCloudConnection",
|
||||
client.syncManager.peers["jazzCloudConnection"]!.knownStates.get(
|
||||
map.core.id,
|
||||
)!,
|
||||
{ uploaded: true },
|
||||
@@ -66,30 +73,42 @@ describe("SyncStateManager", () => {
|
||||
test("subscribeToPeerUpdates receives updates only for specific peer", async () => {
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const { nodeToServerPeer } = connectNodeToSyncServer(client);
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
// Connect nodes
|
||||
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
||||
"clientConnection",
|
||||
"jazzCloudConnection",
|
||||
{
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
},
|
||||
);
|
||||
|
||||
const [clientStoragePeer] = connectedPeers("clientStorage", "unusedPeer", {
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
});
|
||||
|
||||
client.syncManager.addPeer(jazzCloudAsPeer);
|
||||
client.syncManager.addPeer(clientStoragePeer);
|
||||
jazzCloud.syncManager.addPeer(clientAsPeer);
|
||||
|
||||
const subscriptionManager = client.syncManager.syncState;
|
||||
|
||||
const updateToJazzCloudSpy: PeerSyncStateListenerCallback = vi.fn();
|
||||
const updateToStorageSpy: PeerSyncStateListenerCallback = vi.fn();
|
||||
const unsubscribe1 = subscriptionManager.subscribeToPeerUpdates(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
updateToJazzCloudSpy,
|
||||
);
|
||||
const unsubscribe2 = subscriptionManager.subscribeToPeerUpdates(
|
||||
clientStoragePeer.id,
|
||||
"clientStorage",
|
||||
updateToStorageSpy,
|
||||
);
|
||||
|
||||
@@ -107,13 +126,13 @@ describe("SyncStateManager", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
return subscriptionManager.getCurrentSyncState(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded;
|
||||
});
|
||||
|
||||
expect(updateToJazzCloudSpy).toHaveBeenLastCalledWith(
|
||||
client.syncManager.peers[nodeToServerPeer.id]!.knownStates.get(
|
||||
client.syncManager.peers["jazzCloudConnection"]!.knownStates.get(
|
||||
map.core.id,
|
||||
)!,
|
||||
{ uploaded: true },
|
||||
@@ -128,50 +147,80 @@ describe("SyncStateManager", () => {
|
||||
test("getIsCoValueFullyUploadedIntoPeer returns correct status", async () => {
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const { nodeToServerPeer } = connectNodeToSyncServer(client);
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
// Connect nodes
|
||||
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
||||
"clientConnection",
|
||||
"jazzCloudConnection",
|
||||
{
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
},
|
||||
);
|
||||
|
||||
client.syncManager.addPeer(jazzCloudAsPeer);
|
||||
jazzCloud.syncManager.addPeer(clientAsPeer);
|
||||
|
||||
await client.syncManager.actuallySyncCoValue(map.core);
|
||||
|
||||
const subscriptionManager = client.syncManager.syncState;
|
||||
|
||||
expect(
|
||||
subscriptionManager.getCurrentSyncState(nodeToServerPeer.id, map.core.id)
|
||||
.uploaded,
|
||||
subscriptionManager.getCurrentSyncState(
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded,
|
||||
).toBe(false);
|
||||
|
||||
await waitFor(() => {
|
||||
return subscriptionManager.getCurrentSyncState(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded;
|
||||
});
|
||||
|
||||
expect(
|
||||
subscriptionManager.getCurrentSyncState(nodeToServerPeer.id, map.core.id)
|
||||
.uploaded,
|
||||
subscriptionManager.getCurrentSyncState(
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("unsubscribe stops receiving updates", async () => {
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const { nodeToServerPeer } = connectNodeToSyncServer(client);
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
// Connect nodes
|
||||
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
||||
"clientConnection",
|
||||
"jazzCloudConnection",
|
||||
{
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
},
|
||||
);
|
||||
|
||||
client.syncManager.addPeer(jazzCloudAsPeer);
|
||||
jazzCloud.syncManager.addPeer(clientAsPeer);
|
||||
|
||||
const subscriptionManager = client.syncManager.syncState;
|
||||
const anyUpdateSpy = vi.fn();
|
||||
const unsubscribe1 = subscriptionManager.subscribeToUpdates(anyUpdateSpy);
|
||||
const unsubscribe2 = subscriptionManager.subscribeToPeerUpdates(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
anyUpdateSpy,
|
||||
);
|
||||
|
||||
@@ -184,7 +233,7 @@ describe("SyncStateManager", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
return subscriptionManager.getCurrentSyncState(
|
||||
nodeToServerPeer.id,
|
||||
"jazzCloudConnection",
|
||||
map.core.id,
|
||||
).uploaded;
|
||||
});
|
||||
@@ -194,21 +243,22 @@ describe("SyncStateManager", () => {
|
||||
|
||||
test("getCurrentSyncState should return the correct state", async () => {
|
||||
// Setup nodes
|
||||
const clientNode = createTestNode();
|
||||
const serverNode = jazzCloud;
|
||||
const {
|
||||
nodeToServerPeer: clientToServerPeer,
|
||||
serverToNodePeer: serverToClientPeer,
|
||||
} = connectNodeToSyncServer(clientNode);
|
||||
node1: clientNode,
|
||||
node2: serverNode,
|
||||
node1ToNode2Peer: clientToServerPeer,
|
||||
node2ToNode1Peer: serverToClientPeer,
|
||||
} = await createTwoConnectedNodes("client", "server");
|
||||
|
||||
// Create test data
|
||||
const group = clientNode.createGroup();
|
||||
const group = clientNode.node.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
group.addMember("everyone", "writer");
|
||||
|
||||
// Initially should not be synced
|
||||
expect(
|
||||
clientNode.syncManager.syncState.getCurrentSyncState(
|
||||
clientNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
clientToServerPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
@@ -218,13 +268,13 @@ describe("SyncStateManager", () => {
|
||||
await map.core.waitForSync();
|
||||
|
||||
expect(
|
||||
clientNode.syncManager.syncState.getCurrentSyncState(
|
||||
clientNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
clientToServerPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
).toEqual({ uploaded: true });
|
||||
|
||||
const mapOnServer = await loadCoValueOrFail(serverNode, map.id);
|
||||
const mapOnServer = await loadCoValueOrFail(serverNode.node, map.id);
|
||||
|
||||
// Block the content messages so the client won't fully sync immediately
|
||||
const outgoing = blockMessageTypeOnOutgoingPeer(
|
||||
@@ -235,14 +285,14 @@ describe("SyncStateManager", () => {
|
||||
mapOnServer.set("key2", "value2", "trusting");
|
||||
|
||||
expect(
|
||||
clientNode.syncManager.syncState.getCurrentSyncState(
|
||||
clientNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
clientToServerPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
).toEqual({ uploaded: true });
|
||||
|
||||
expect(
|
||||
serverNode.syncManager.syncState.getCurrentSyncState(
|
||||
serverNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
serverToClientPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
@@ -254,14 +304,14 @@ describe("SyncStateManager", () => {
|
||||
await mapOnServer.core.waitForSync();
|
||||
|
||||
expect(
|
||||
clientNode.syncManager.syncState.getCurrentSyncState(
|
||||
clientNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
clientToServerPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
).toEqual({ uploaded: true });
|
||||
|
||||
expect(
|
||||
serverNode.syncManager.syncState.getCurrentSyncState(
|
||||
serverNode.node.syncManager.syncState.getCurrentSyncState(
|
||||
serverToClientPeer.id,
|
||||
map.core.id,
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { PeerState } from "../PeerState";
|
||||
import { CoValueCore } from "../coValueCore";
|
||||
import { CO_VALUE_LOADING_MAX_RETRIES, CoValueState } from "../coValueState";
|
||||
import { CO_VALUE_LOADING_CONFIG, CoValueState } from "../coValueState";
|
||||
import { RawCoID } from "../ids";
|
||||
import { Peer } from "../sync";
|
||||
|
||||
@@ -92,18 +92,18 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
// Should attempt CO_VALUE_LOADING_MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
// Should attempt CO_VALUE_LOADING_CONFIG.MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
|
||||
await loadPromise;
|
||||
|
||||
expect(peer1.pushOutgoingMessage).toHaveBeenCalledTimes(
|
||||
CO_VALUE_LOADING_MAX_RETRIES,
|
||||
CO_VALUE_LOADING_CONFIG.MAX_RETRIES,
|
||||
);
|
||||
expect(peer2.pushOutgoingMessage).toHaveBeenCalledTimes(
|
||||
CO_VALUE_LOADING_MAX_RETRIES,
|
||||
CO_VALUE_LOADING_CONFIG.MAX_RETRIES,
|
||||
);
|
||||
expect(state.state.type).toBe("unavailable");
|
||||
await expect(state.getCoValue()).resolves.toBe("unavailable");
|
||||
@@ -145,8 +145,8 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
// Should attempt CO_VALUE_LOADING_MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
// Should attempt CO_VALUE_LOADING_CONFIG.MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ describe("CoValueState", () => {
|
||||
|
||||
expect(peer1.pushOutgoingMessage).toHaveBeenCalledTimes(1);
|
||||
expect(peer2.pushOutgoingMessage).toHaveBeenCalledTimes(
|
||||
CO_VALUE_LOADING_MAX_RETRIES,
|
||||
CO_VALUE_LOADING_CONFIG.MAX_RETRIES,
|
||||
);
|
||||
expect(state.state.type).toBe("unavailable");
|
||||
await expect(state.getCoValue()).resolves.toBe("unavailable");
|
||||
@@ -194,8 +194,8 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
// Should attempt CO_VALUE_LOADING_MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
// Should attempt CO_VALUE_LOADING_CONFIG.MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ describe("CoValueState", () => {
|
||||
|
||||
expect(peer1.pushOutgoingMessage).toHaveBeenCalledTimes(1);
|
||||
expect(peer2.pushOutgoingMessage).toHaveBeenCalledTimes(
|
||||
CO_VALUE_LOADING_MAX_RETRIES,
|
||||
CO_VALUE_LOADING_CONFIG.MAX_RETRIES,
|
||||
);
|
||||
expect(state.state.type).toBe("unavailable");
|
||||
await expect(state.getCoValue()).resolves.toEqual("unavailable");
|
||||
@@ -244,8 +244,8 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
// Should attempt CO_VALUE_LOADING_MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES + 1; i++) {
|
||||
// Should attempt CO_VALUE_LOADING_CONFIG.MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES + 1; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
|
||||
@@ -278,8 +278,8 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
// Should attempt CO_VALUE_LOADING_MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
// Should attempt CO_VALUE_LOADING_CONFIG.MAX_RETRIES retries
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers(mockPeers);
|
||||
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
await loadPromise;
|
||||
@@ -372,7 +372,7 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers([peer1, peer2]);
|
||||
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
await loadPromise;
|
||||
@@ -421,7 +421,7 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers([peer1, peer2]);
|
||||
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
await loadPromise;
|
||||
@@ -449,7 +449,7 @@ describe("CoValueState", () => {
|
||||
const state = CoValueState.Unknown(mockCoValueId);
|
||||
const loadPromise = state.loadFromPeers([peer1]);
|
||||
|
||||
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES * 2; i++) {
|
||||
for (let i = 0; i < CO_VALUE_LOADING_CONFIG.MAX_RETRIES * 2; i++) {
|
||||
await vi.runAllTimersAsync();
|
||||
}
|
||||
await loadPromise;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { expectMap } from "../coValue.js";
|
||||
import type { CoValueHeader } from "../coValueCore.js";
|
||||
import type { RawAccountID } from "../coValues/account.js";
|
||||
@@ -12,27 +12,17 @@ import { connectedPeers, newQueuePair } from "../streamUtils.js";
|
||||
import type { SyncMessage } from "../sync.js";
|
||||
import {
|
||||
blockMessageTypeOnOutgoingPeer,
|
||||
connectNodeToSyncServer,
|
||||
connectTwoPeers,
|
||||
createConnectedTestAgentNode,
|
||||
createConnectedTestNode,
|
||||
createTestMetricReader,
|
||||
createTestNode,
|
||||
loadCoValueOrFail,
|
||||
randomAnonymousAccountAndSessionID,
|
||||
setupSyncServer,
|
||||
tearDownTestMetricReader,
|
||||
waitFor,
|
||||
} from "./testUtils.js";
|
||||
|
||||
const Crypto = await WasmCrypto.create();
|
||||
|
||||
let jazzCloud = setupSyncServer();
|
||||
|
||||
beforeEach(async () => {
|
||||
jazzCloud = setupSyncServer();
|
||||
});
|
||||
|
||||
test("Node replies with initial tx and header to empty subscribe", async () => {
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
const node = new LocalNode(admin, session, Crypto);
|
||||
@@ -871,34 +861,111 @@ test.skip("When loading a coValue on one node, the server node it is requested f
|
||||
});
|
||||
|
||||
test("Can sync a coValue through a server to another client", async () => {
|
||||
const { node: client1 } = await createConnectedTestNode();
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
const client1 = new LocalNode(admin, session, Crypto);
|
||||
|
||||
const group = client1.createGroup();
|
||||
|
||||
const map = group.createMap();
|
||||
map.set("hello", "world", "trusting");
|
||||
|
||||
const { node: client2 } = await createConnectedTestNode();
|
||||
const [serverUser, serverSession] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
const mapOnClient2 = await loadCoValueOrFail(client2, map.id);
|
||||
const server = new LocalNode(serverUser, serverSession, Crypto);
|
||||
|
||||
expect(mapOnClient2.get("hello")).toEqual("world");
|
||||
const [serverAsPeerForClient1, client1AsPeer] = connectedPeers(
|
||||
"serverFor1",
|
||||
"client1",
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
// trace: true,
|
||||
},
|
||||
);
|
||||
|
||||
client1.syncManager.addPeer(serverAsPeerForClient1);
|
||||
server.syncManager.addPeer(client1AsPeer);
|
||||
|
||||
const client2 = new LocalNode(
|
||||
admin,
|
||||
Crypto.newRandomSessionID(admin.id),
|
||||
Crypto,
|
||||
);
|
||||
|
||||
const [serverAsPeerForClient2, client2AsPeer] = connectedPeers(
|
||||
"serverFor2",
|
||||
"client2",
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
// trace: true,
|
||||
},
|
||||
);
|
||||
|
||||
client2.syncManager.addPeer(serverAsPeerForClient2);
|
||||
server.syncManager.addPeer(client2AsPeer);
|
||||
|
||||
const mapOnClient2 = await client2.loadCoValueCore(map.core.id);
|
||||
if (mapOnClient2 === "unavailable") {
|
||||
throw new Error("Map is unavailable");
|
||||
}
|
||||
|
||||
expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
|
||||
"world",
|
||||
);
|
||||
});
|
||||
|
||||
test("Can sync a coValue with private transactions through a server to another client", async () => {
|
||||
const { node: client1 } = await createConnectedTestNode();
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
const client1 = new LocalNode(admin, session, Crypto);
|
||||
|
||||
const group = client1.createGroup();
|
||||
|
||||
const map = group.createMap();
|
||||
map.set("hello", "world", "private");
|
||||
group.addMember("everyone", "reader");
|
||||
|
||||
const { node: client2 } = await createConnectedTestNode();
|
||||
const [serverUser, serverSession] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
const mapOnClient2 = await loadCoValueOrFail(client2, map.id);
|
||||
const server = new LocalNode(serverUser, serverSession, Crypto);
|
||||
|
||||
expect(mapOnClient2.get("hello")).toEqual("world");
|
||||
const [serverAsPeer, client1AsPeer] = connectedPeers("server", "client1", {
|
||||
// trace: true,
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
});
|
||||
|
||||
client1.syncManager.addPeer(serverAsPeer);
|
||||
server.syncManager.addPeer(client1AsPeer);
|
||||
|
||||
const client2 = new LocalNode(
|
||||
admin,
|
||||
client1.crypto.newRandomSessionID(admin.id),
|
||||
Crypto,
|
||||
);
|
||||
|
||||
const [serverAsOtherPeer, client2AsPeer] = connectedPeers(
|
||||
"server",
|
||||
"client2",
|
||||
{
|
||||
// trace: true,
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
},
|
||||
);
|
||||
|
||||
client2.syncManager.addPeer(serverAsOtherPeer);
|
||||
server.syncManager.addPeer(client2AsPeer);
|
||||
|
||||
const mapOnClient2 = await client2.loadCoValueCore(map.core.id);
|
||||
if (mapOnClient2 === "unavailable") {
|
||||
throw new Error("Map is unavailable");
|
||||
}
|
||||
|
||||
expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
|
||||
"world",
|
||||
);
|
||||
});
|
||||
|
||||
test.skip("When a peer's incoming/readable stream closes, we remove the peer", async () => {
|
||||
@@ -956,32 +1023,111 @@ test.skip("When a peer's incoming/readable stream closes, we remove the peer", a
|
||||
*/
|
||||
});
|
||||
|
||||
test.skip("When a peer's outgoing/writable stream closes, we remove the peer", async () => {
|
||||
/*
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
const node = new LocalNode(admin, session, Crypto);
|
||||
|
||||
const group = node.createGroup();
|
||||
|
||||
const [inRx] = await Effect.runPromise(newStreamPair());
|
||||
const [outRx, outTx] = await Effect.runPromise(newStreamPair());
|
||||
|
||||
node.syncManager.addPeer({
|
||||
id: "test",
|
||||
incoming: inRx,
|
||||
outgoing: outTx,
|
||||
role: "server",
|
||||
});
|
||||
|
||||
// expect(yield* Queue.take(outRxQ)).toMatchObject({
|
||||
// action: "load",
|
||||
// id: admin.id,
|
||||
// });
|
||||
expect(yield * Queue.take(outRxQ)).toMatchObject({
|
||||
action: "load",
|
||||
id: group.core.id,
|
||||
});
|
||||
|
||||
const map = group.createMap();
|
||||
|
||||
const mapSubscribeMsg = await reader.read();
|
||||
|
||||
expect(mapSubscribeMsg.value).toEqual({
|
||||
action: "load",
|
||||
...map.core.knownState(),
|
||||
} satisfies SyncMessage);
|
||||
|
||||
// expect(yield* Queue.take(outRxQ)).toMatchObject(admContEx(admin.id));
|
||||
expect(yield * Queue.take(outRxQ)).toMatchObject(groupContentEx(group));
|
||||
|
||||
const mapContentMsg = await reader.read();
|
||||
|
||||
expect(mapContentMsg.value).toEqual({
|
||||
action: "content",
|
||||
id: map.core.id,
|
||||
header: map.core.header,
|
||||
new: {},
|
||||
} satisfies SyncMessage);
|
||||
|
||||
reader.releaseLock();
|
||||
await outRx.cancel();
|
||||
|
||||
map.set("hello", "world", "trusting");
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(node.syncManager.peers["test"]).toBeUndefined();
|
||||
*/
|
||||
});
|
||||
|
||||
test("If we start loading a coValue before connecting to a peer that has it, it will load it once we connect", async () => {
|
||||
const { node: node1 } = await createConnectedTestNode();
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
const node1 = new LocalNode(admin, session, Crypto);
|
||||
|
||||
const group = node1.createGroup();
|
||||
|
||||
const map = group.createMap();
|
||||
map.set("hello", "world", "trusting");
|
||||
|
||||
const node2 = createTestNode();
|
||||
const node2 = new LocalNode(
|
||||
admin,
|
||||
Crypto.newRandomSessionID(admin.id),
|
||||
Crypto,
|
||||
);
|
||||
|
||||
const mapOnNode2Promise = loadCoValueOrFail(node2, map.id);
|
||||
const [node1asPeer, node2asPeer] = connectedPeers("peer1", "peer2", {
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
// trace: true,
|
||||
});
|
||||
|
||||
node1.syncManager.addPeer(node2asPeer);
|
||||
|
||||
const mapOnNode2Promise = node2.loadCoValueCore(map.core.id);
|
||||
|
||||
expect(node2.coValuesStore.get(map.core.id).state.type).toEqual("unknown");
|
||||
|
||||
connectNodeToSyncServer(node2);
|
||||
node2.syncManager.addPeer(node1asPeer);
|
||||
|
||||
const mapOnNode2 = await mapOnNode2Promise;
|
||||
if (mapOnNode2 === "unavailable") {
|
||||
throw new Error("Map is unavailable");
|
||||
}
|
||||
|
||||
expect(mapOnNode2.get("hello")).toEqual("world");
|
||||
expect(expectMap(mapOnNode2.getCurrentContent()).get("hello")).toEqual(
|
||||
"world",
|
||||
);
|
||||
});
|
||||
|
||||
test("should keep the peer state when the peer closes", async () => {
|
||||
const client = createTestNode();
|
||||
|
||||
const { nodeToServerPeer, serverToNodePeer } =
|
||||
connectNodeToSyncServer(client);
|
||||
const {
|
||||
client,
|
||||
jazzCloud,
|
||||
jazzCloudConnectionAsPeer,
|
||||
connectionWithClientAsPeer,
|
||||
} = createTwoConnectedNodes();
|
||||
|
||||
const group = jazzCloud.createGroup();
|
||||
const map = group.createMap();
|
||||
@@ -990,23 +1136,25 @@ test("should keep the peer state when the peer closes", async () => {
|
||||
await client.loadCoValueCore(map.core.id);
|
||||
|
||||
const syncManager = client.syncManager;
|
||||
const peerState = syncManager.peers[nodeToServerPeer.id];
|
||||
const peerState = syncManager.peers[jazzCloudConnectionAsPeer.id];
|
||||
|
||||
// @ts-expect-error Simulating a peer closing, leveraging the direct connection between the client/server peers
|
||||
await serverToNodePeer.outgoing.push("Disconnected");
|
||||
await connectionWithClientAsPeer.outgoing.push("Disconnected");
|
||||
|
||||
await waitFor(() => peerState?.closed);
|
||||
|
||||
expect(syncManager.peers[nodeToServerPeer.id]).not.toBeUndefined();
|
||||
expect(syncManager.peers[jazzCloudConnectionAsPeer.id]).not.toBeUndefined();
|
||||
});
|
||||
|
||||
test("should delete the peer state when the peer closes if deletePeerStateOnClose is true", async () => {
|
||||
const client = createTestNode();
|
||||
const {
|
||||
client,
|
||||
jazzCloud,
|
||||
jazzCloudConnectionAsPeer,
|
||||
connectionWithClientAsPeer,
|
||||
} = createTwoConnectedNodes();
|
||||
|
||||
const { nodeToServerPeer, serverToNodePeer } =
|
||||
connectNodeToSyncServer(client);
|
||||
|
||||
nodeToServerPeer.deletePeerStateOnClose = true;
|
||||
jazzCloudConnectionAsPeer.deletePeerStateOnClose = true;
|
||||
|
||||
const group = jazzCloud.createGroup();
|
||||
const map = group.createMap();
|
||||
@@ -1016,14 +1164,14 @@ test("should delete the peer state when the peer closes if deletePeerStateOnClos
|
||||
|
||||
const syncManager = client.syncManager;
|
||||
|
||||
const peerState = syncManager.peers[nodeToServerPeer.id];
|
||||
const peerState = syncManager.peers[jazzCloudConnectionAsPeer.id];
|
||||
|
||||
// @ts-expect-error Simulating a peer closing, leveraging the direct connection between the client/server peers
|
||||
await serverToNodePeer.outgoing.push("Disconnected");
|
||||
await connectionWithClientAsPeer.outgoing.push("Disconnected");
|
||||
|
||||
await waitFor(() => peerState?.closed);
|
||||
|
||||
expect(syncManager.peers[nodeToServerPeer.id]).toBeUndefined();
|
||||
expect(syncManager.peers[jazzCloudConnectionAsPeer.id]).toBeUndefined();
|
||||
});
|
||||
|
||||
describe("sync - extra tests", () => {
|
||||
@@ -1476,6 +1624,29 @@ describe("sync - extra tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function createTwoConnectedNodes() {
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Connect nodes initially
|
||||
const [connectionWithClientAsPeer, jazzCloudConnectionAsPeer] =
|
||||
connectedPeers("connectionWithClient", "jazzCloudConnection", {
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
});
|
||||
|
||||
client.syncManager.addPeer(jazzCloudConnectionAsPeer);
|
||||
jazzCloud.syncManager.addPeer(connectionWithClientAsPeer);
|
||||
|
||||
return {
|
||||
client,
|
||||
jazzCloud,
|
||||
connectionWithClientAsPeer,
|
||||
jazzCloudConnectionAsPeer,
|
||||
};
|
||||
}
|
||||
|
||||
test("a value created on one node can be loaded on anotehr node even if not directly connected", async () => {
|
||||
const userA = createTestNode();
|
||||
const userB = createTestNode();
|
||||
@@ -1500,7 +1671,7 @@ test("a value created on one node can be loaded on anotehr node even if not dire
|
||||
|
||||
describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
test("knownStates and optimisticKnownStates are the same when the coValue is fully synced", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client, jazzCloud } = createTwoConnectedNodes();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
@@ -1512,8 +1683,9 @@ describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
// Wait for the full sync to complete
|
||||
await mapOnClient.core.waitForSync();
|
||||
|
||||
const peerStateClient = client.syncManager.getPeers()[0]!;
|
||||
const peerStateJazzCloud = jazzCloud.syncManager.getPeers()[0]!;
|
||||
const peerStateClient = client.syncManager.peers["jazzCloudConnection"]!;
|
||||
const peerStateJazzCloud =
|
||||
jazzCloud.syncManager.peers["connectionWithClient"]!;
|
||||
|
||||
// The optimisticKnownStates should be the same as the knownStates after the full sync is complete
|
||||
expect(
|
||||
@@ -1527,7 +1699,7 @@ describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
});
|
||||
|
||||
test("optimisticKnownStates is updated as new transactions are sent, while knownStates only when the updates are acknowledged", async () => {
|
||||
const { node: client, nodeToServerPeer } = await createConnectedTestNode();
|
||||
const { client, jazzCloudConnectionAsPeer } = createTwoConnectedNodes();
|
||||
|
||||
// Create test data and sync the first change
|
||||
// We want that both the nodes know about the coValue so we can test
|
||||
@@ -1545,7 +1717,7 @@ describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
// while knownStates is only updated when we receive the "known" messages
|
||||
// that are acknowledging the receipt of the content messages
|
||||
const outgoing = blockMessageTypeOnOutgoingPeer(
|
||||
nodeToServerPeer,
|
||||
jazzCloudConnectionAsPeer,
|
||||
"content",
|
||||
);
|
||||
|
||||
@@ -1553,7 +1725,8 @@ describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
|
||||
await client.syncManager.actuallySyncCoValue(map.core);
|
||||
|
||||
const peerState = client.syncManager.peers[nodeToServerPeer.id]!;
|
||||
const peerState = client.syncManager.peers["jazzCloudConnection"]!;
|
||||
|
||||
expect(peerState.optimisticKnownStates.get(map.core.id)).not.toEqual(
|
||||
peerState.knownStates.get(map.core.id),
|
||||
);
|
||||
@@ -1574,7 +1747,7 @@ describe("SyncManager - knownStates vs optimisticKnownStates", () => {
|
||||
|
||||
describe("SyncManager.addPeer", () => {
|
||||
test("new peer gets a copy of previous peer's knownStates when replacing it", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client } = createTwoConnectedNodes();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
@@ -1586,24 +1759,26 @@ describe("SyncManager.addPeer", () => {
|
||||
// Wait for initial sync
|
||||
await map.core.waitForSync();
|
||||
|
||||
const firstPeerState = client.syncManager.getPeers()[0]!;
|
||||
|
||||
// Store the initial known states
|
||||
const initialKnownStates = firstPeerState.knownStates;
|
||||
const initialKnownStates =
|
||||
client.syncManager.peers["jazzCloudConnection"]!.knownStates;
|
||||
|
||||
// Create new connection with same ID
|
||||
const [secondPeer] = connectedPeers(firstPeerState.id, "unusedPeer", {
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
});
|
||||
const [jazzCloudConnectionAsPeer2] = connectedPeers(
|
||||
"jazzCloudConnection",
|
||||
"unusedPeer",
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
},
|
||||
);
|
||||
|
||||
// Add new peer with same ID
|
||||
client.syncManager.addPeer(secondPeer);
|
||||
|
||||
const newPeerState = client.syncManager.getPeers()[0]!;
|
||||
client.syncManager.addPeer(jazzCloudConnectionAsPeer2);
|
||||
|
||||
// Verify that the new peer has a copy of the previous known states
|
||||
const newPeerKnownStates = newPeerState.knownStates;
|
||||
const newPeerKnownStates =
|
||||
client.syncManager.peers["jazzCloudConnection"]!.knownStates;
|
||||
|
||||
expect(newPeerKnownStates).not.toBe(initialKnownStates); // Should be a different instance
|
||||
expect(newPeerKnownStates.get(map.core.id)).toEqual(
|
||||
@@ -1612,7 +1787,7 @@ describe("SyncManager.addPeer", () => {
|
||||
});
|
||||
|
||||
test("new peer with new ID starts with empty knownStates", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client } = createTwoConnectedNodes();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
@@ -1640,19 +1815,23 @@ describe("SyncManager.addPeer", () => {
|
||||
});
|
||||
|
||||
test("when adding a peer with the same ID as a previous peer, the previous peer is closed", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client } = createTwoConnectedNodes();
|
||||
|
||||
// Store reference to first peer
|
||||
const firstPeer = client.syncManager.getPeers()[0]!;
|
||||
const firstPeer = client.syncManager.peers["jazzCloudConnection"]!;
|
||||
const closeSpy = vi.spyOn(firstPeer, "gracefulShutdown");
|
||||
|
||||
// Create and add replacement peer
|
||||
const [secondPeer] = connectedPeers(firstPeer.id, "unusedPeer", {
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
});
|
||||
const [jazzCloudConnectionAsPeer2] = connectedPeers(
|
||||
"jazzCloudConnection",
|
||||
"unusedPeer",
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
},
|
||||
);
|
||||
|
||||
client.syncManager.addPeer(secondPeer);
|
||||
client.syncManager.addPeer(jazzCloudConnectionAsPeer2);
|
||||
|
||||
// Verify thet the first peer had ben closed correctly
|
||||
expect(closeSpy).toHaveBeenCalled();
|
||||
@@ -1660,21 +1839,25 @@ describe("SyncManager.addPeer", () => {
|
||||
});
|
||||
|
||||
test("when adding a peer with the same ID as a previous peer and the previous peer is closed, do not attempt to close it again", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client } = createTwoConnectedNodes();
|
||||
|
||||
// Store reference to first peer
|
||||
const firstPeer = client.syncManager.getPeers()[0]!;
|
||||
const firstPeer = client.syncManager.peers["jazzCloudConnection"]!;
|
||||
|
||||
firstPeer.gracefulShutdown();
|
||||
const closeSpy = vi.spyOn(firstPeer, "gracefulShutdown");
|
||||
|
||||
// Create and add replacement peer
|
||||
const [secondPeer] = connectedPeers(firstPeer.id, "unusedPeer", {
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
});
|
||||
const [jazzCloudConnectionAsPeer2] = connectedPeers(
|
||||
"jazzCloudConnection",
|
||||
"unusedPeer",
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
},
|
||||
);
|
||||
|
||||
client.syncManager.addPeer(secondPeer);
|
||||
client.syncManager.addPeer(jazzCloudConnectionAsPeer2);
|
||||
|
||||
// Verify thet the first peer had not been closed again
|
||||
expect(closeSpy).not.toHaveBeenCalled();
|
||||
@@ -1682,15 +1865,24 @@ describe("SyncManager.addPeer", () => {
|
||||
});
|
||||
|
||||
test("when adding a server peer the local coValues should be sent to it", async () => {
|
||||
const { node: client, addServerPeer } = await createConnectedTestNode({
|
||||
connected: false,
|
||||
});
|
||||
// Setup nodes
|
||||
const client = createTestNode();
|
||||
const jazzCloud = createTestNode();
|
||||
|
||||
// Connect nodes initially
|
||||
const [connectionWithClientAsPeer, jazzCloudConnectionAsPeer] =
|
||||
connectedPeers("connectionWithClient", "jazzCloudConnection", {
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
});
|
||||
|
||||
jazzCloud.syncManager.addPeer(connectionWithClientAsPeer);
|
||||
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
addServerPeer();
|
||||
client.syncManager.addPeer(jazzCloudConnectionAsPeer);
|
||||
|
||||
await map.core.waitForSync();
|
||||
|
||||
@@ -1700,8 +1892,18 @@ describe("SyncManager.addPeer", () => {
|
||||
|
||||
describe("loadCoValueCore with retry", () => {
|
||||
test("should load the value if available on the server", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { node: anotherClient } = await createConnectedTestNode();
|
||||
const { client, jazzCloud } = createTwoConnectedNodes();
|
||||
|
||||
const anotherClient = createTestNode();
|
||||
const [
|
||||
connectionWithAnotherClientAsPeer,
|
||||
jazzCloudConnectionAsPeerForAnotherClient,
|
||||
] = connectedPeers("connectionWithAnotherClient", "jazzCloudConnection", {
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
});
|
||||
|
||||
jazzCloud.syncManager.addPeer(connectionWithAnotherClientAsPeer);
|
||||
|
||||
const group = anotherClient.createGroup();
|
||||
const map = group.createMap();
|
||||
@@ -1709,12 +1911,25 @@ describe("loadCoValueCore with retry", () => {
|
||||
|
||||
const promise = client.loadCoValueCore(map.id);
|
||||
|
||||
anotherClient.syncManager.addPeer(
|
||||
jazzCloudConnectionAsPeerForAnotherClient,
|
||||
);
|
||||
await expect(promise).resolves.not.toBe("unavailable");
|
||||
});
|
||||
|
||||
test("should handle correctly two subsequent loads", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { node: anotherClient } = await createConnectedTestNode();
|
||||
const { client, jazzCloud } = createTwoConnectedNodes();
|
||||
|
||||
const anotherClient = createTestNode();
|
||||
const [
|
||||
connectionWithAnotherClientAsPeer,
|
||||
jazzCloudConnectionAsPeerForAnotherClient,
|
||||
] = connectedPeers("connectionWithAnotherClient", "jazzCloudConnection", {
|
||||
peer1role: "client",
|
||||
peer2role: "server",
|
||||
});
|
||||
|
||||
jazzCloud.syncManager.addPeer(connectionWithAnotherClientAsPeer);
|
||||
|
||||
const group = anotherClient.createGroup();
|
||||
const map = group.createMap();
|
||||
@@ -1723,6 +1938,10 @@ describe("loadCoValueCore with retry", () => {
|
||||
const promise1 = client.loadCoValueCore(map.id);
|
||||
const promise2 = client.loadCoValueCore(map.id);
|
||||
|
||||
anotherClient.syncManager.addPeer(
|
||||
jazzCloudConnectionAsPeerForAnotherClient,
|
||||
);
|
||||
|
||||
await expect(promise1).resolves.not.toBe("unavailable");
|
||||
await expect(promise2).resolves.not.toBe("unavailable");
|
||||
});
|
||||
@@ -1730,7 +1949,8 @@ describe("loadCoValueCore with retry", () => {
|
||||
|
||||
describe("waitForSyncWithPeer", () => {
|
||||
test("should resolve when the coValue is fully uploaded into the peer", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client, jazzCloudConnectionAsPeer: peer } =
|
||||
createTwoConnectedNodes();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
@@ -1739,32 +1959,21 @@ describe("waitForSyncWithPeer", () => {
|
||||
|
||||
await client.syncManager.actuallySyncCoValue(map.core);
|
||||
|
||||
const peer = client.syncManager.getPeers()[0];
|
||||
|
||||
if (!peer) {
|
||||
throw new Error("No peer found");
|
||||
}
|
||||
|
||||
await expect(
|
||||
client.syncManager.waitForSyncWithPeer(peer.id, map.core.id, 100),
|
||||
).resolves.toBe(true);
|
||||
});
|
||||
|
||||
test("should not resolve when the coValue is not synced", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
|
||||
const peer = client.syncManager.getPeers()[0];
|
||||
|
||||
if (!peer) {
|
||||
throw new Error("No peer found");
|
||||
}
|
||||
const { client, jazzCloudConnectionAsPeer: peer } =
|
||||
createTwoConnectedNodes();
|
||||
|
||||
// Create test data
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("key1", "value1", "trusting");
|
||||
|
||||
vi.spyOn(peer, "pushOutgoingMessage").mockImplementation(async () => {
|
||||
vi.spyOn(peer.outgoing, "push").mockImplementation(async () => {
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
@@ -1777,7 +1986,7 @@ describe("waitForSyncWithPeer", () => {
|
||||
});
|
||||
|
||||
test("Should not crash when syncing an unknown coValue type", async () => {
|
||||
const { node: client } = await createConnectedTestNode();
|
||||
const { client, jazzCloud } = createTwoConnectedNodes();
|
||||
|
||||
const coValue = client.createCoValue({
|
||||
type: "ooops" as any,
|
||||
@@ -1788,10 +1997,8 @@ test("Should not crash when syncing an unknown coValue type", async () => {
|
||||
|
||||
await coValue.waitForSync();
|
||||
|
||||
const { node: anotherClient } = await createConnectedTestNode();
|
||||
|
||||
const coValueOnTheOtherNode = await loadCoValueOrFail(
|
||||
anotherClient,
|
||||
jazzCloud,
|
||||
coValue.getCurrentContent().id,
|
||||
);
|
||||
expect(coValueOnTheOtherNode.id).toBe(coValue.id);
|
||||
@@ -1885,163 +2092,6 @@ describe("metrics", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("sync protocol", () => {
|
||||
test("should have the correct messages exchanged between client and server", async () => {
|
||||
// Creating the account from agent to simplify the messages exchange
|
||||
const { node: client, messages } = await createConnectedTestAgentNode();
|
||||
|
||||
const group = client.createGroup();
|
||||
const map = group.createMap();
|
||||
map.set("hello", "world", "trusting");
|
||||
|
||||
const mapOnJazzCloud = await loadCoValueOrFail(jazzCloud, map.id);
|
||||
expect(mapOnJazzCloud.get("hello")).toEqual("world");
|
||||
|
||||
expect(messages).toEqual([
|
||||
{
|
||||
from: "client",
|
||||
msg: {
|
||||
action: "load",
|
||||
header: true,
|
||||
id: group.id,
|
||||
sessions: {
|
||||
[client.currentSessionID]: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "server",
|
||||
msg: {
|
||||
action: "load",
|
||||
header: false,
|
||||
id: group.id,
|
||||
sessions: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "client",
|
||||
msg: {
|
||||
action: "load",
|
||||
header: true,
|
||||
id: map.id,
|
||||
sessions: {
|
||||
[client.currentSessionID]: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "server",
|
||||
msg: {
|
||||
action: "load",
|
||||
header: false,
|
||||
id: map.id,
|
||||
sessions: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "client",
|
||||
msg: {
|
||||
action: "content",
|
||||
header: {
|
||||
createdAt: expect.any(String),
|
||||
meta: null,
|
||||
ruleset: {
|
||||
initialAdmin: client.account.id,
|
||||
type: "group",
|
||||
},
|
||||
type: "comap",
|
||||
uniqueness: expect.any(String),
|
||||
},
|
||||
id: group.id,
|
||||
new: {
|
||||
[client.currentSessionID]: {
|
||||
after: 0,
|
||||
lastSignature: expect.any(String),
|
||||
newTransactions: expect.any(Array),
|
||||
},
|
||||
},
|
||||
priority: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "client",
|
||||
msg: {
|
||||
action: "content",
|
||||
header: {
|
||||
createdAt: expect.any(String),
|
||||
meta: null,
|
||||
ruleset: {
|
||||
group: group.id,
|
||||
type: "ownedByGroup",
|
||||
},
|
||||
type: "comap",
|
||||
uniqueness: expect.any(String),
|
||||
},
|
||||
id: map.id,
|
||||
new: {
|
||||
[client.currentSessionID]: {
|
||||
after: 0,
|
||||
lastSignature: expect.any(String),
|
||||
newTransactions: expect.any(Array),
|
||||
},
|
||||
},
|
||||
priority: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
from: "server",
|
||||
msg: {
|
||||
action: "known",
|
||||
header: true,
|
||||
id: group.id,
|
||||
sessions: {
|
||||
[client.currentSessionID]: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// TODO: This is a redundant message, we should remove it
|
||||
from: "client",
|
||||
msg: {
|
||||
action: "content",
|
||||
header: {
|
||||
createdAt: expect.any(String),
|
||||
meta: null,
|
||||
ruleset: {
|
||||
group: group.id,
|
||||
type: "ownedByGroup",
|
||||
},
|
||||
type: "comap",
|
||||
uniqueness: expect.any(String),
|
||||
},
|
||||
id: map.id,
|
||||
new: {
|
||||
[client.currentSessionID]: {
|
||||
after: 0,
|
||||
lastSignature: expect.any(String),
|
||||
newTransactions: expect.any(Array),
|
||||
},
|
||||
},
|
||||
priority: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
// TODO: This is a redundant message, we should remove it
|
||||
from: "server",
|
||||
msg: {
|
||||
action: "known",
|
||||
asDependencyOf: undefined,
|
||||
header: true,
|
||||
id: group.id,
|
||||
sessions: {
|
||||
[client.currentSessionID]: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
function groupContentEx(group: RawGroup) {
|
||||
return {
|
||||
action: "content",
|
||||
@@ -2049,9 +2099,27 @@ function groupContentEx(group: RawGroup) {
|
||||
};
|
||||
}
|
||||
|
||||
function _admContEx(adminID: RawAccountID) {
|
||||
return {
|
||||
action: "content",
|
||||
id: adminID,
|
||||
};
|
||||
}
|
||||
|
||||
function groupStateEx(group: RawGroup) {
|
||||
return {
|
||||
action: "known",
|
||||
id: group.core.id,
|
||||
};
|
||||
}
|
||||
|
||||
function _admStateEx(adminID: RawAccountID) {
|
||||
return {
|
||||
action: "known",
|
||||
id: adminID,
|
||||
};
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
@@ -17,12 +17,6 @@ import { expectGroup } from "../typeUtils/expectGroup.js";
|
||||
|
||||
const Crypto = await WasmCrypto.create();
|
||||
|
||||
const syncServer: {
|
||||
current: undefined | LocalNode;
|
||||
} = {
|
||||
current: undefined,
|
||||
};
|
||||
|
||||
export function randomAnonymousAccountAndSessionID(): [
|
||||
ControlledAgent,
|
||||
SessionID,
|
||||
@@ -39,6 +33,25 @@ export function createTestNode() {
|
||||
return new LocalNode(admin, session, Crypto);
|
||||
}
|
||||
|
||||
export function connectTwoPeers(
|
||||
a: LocalNode,
|
||||
b: LocalNode,
|
||||
aRole: "client" | "server",
|
||||
bRole: "client" | "server",
|
||||
) {
|
||||
const [aAsPeer, bAsPeer] = connectedPeers(
|
||||
"peer:" + a.account.id,
|
||||
"peer:" + b.account.id,
|
||||
{
|
||||
peer1role: aRole,
|
||||
peer2role: bRole,
|
||||
},
|
||||
);
|
||||
|
||||
a.syncManager.addPeer(bAsPeer);
|
||||
b.syncManager.addPeer(aAsPeer);
|
||||
}
|
||||
|
||||
export async function createTwoConnectedNodes(
|
||||
node1Role: Peer["role"],
|
||||
node2Role: Peer["role"],
|
||||
@@ -136,25 +149,6 @@ export async function createThreeConnectedNodes(
|
||||
};
|
||||
}
|
||||
|
||||
export function connectTwoPeers(
|
||||
a: LocalNode,
|
||||
b: LocalNode,
|
||||
aRole: "client" | "server",
|
||||
bRole: "client" | "server",
|
||||
) {
|
||||
const [aAsPeer, bAsPeer] = connectedPeers(
|
||||
"peer:" + a.account.id,
|
||||
"peer:" + b.account.id,
|
||||
{
|
||||
peer1role: aRole,
|
||||
peer2role: bRole,
|
||||
},
|
||||
);
|
||||
|
||||
a.syncManager.addPeer(bAsPeer);
|
||||
b.syncManager.addPeer(aAsPeer);
|
||||
}
|
||||
|
||||
export function newGroup() {
|
||||
const [admin, sessionID] = randomAnonymousAccountAndSessionID();
|
||||
|
||||
@@ -374,90 +368,3 @@ export function createTestMetricReader() {
|
||||
export function tearDownTestMetricReader() {
|
||||
metrics.disable();
|
||||
}
|
||||
|
||||
export function setupSyncServer() {
|
||||
syncServer.current = createTestNode();
|
||||
return syncServer.current;
|
||||
}
|
||||
|
||||
export async function createConnectedTestAgentNode(opts = { connected: true }) {
|
||||
if (!syncServer.current) {
|
||||
throw new Error("Sync server not initialized");
|
||||
}
|
||||
|
||||
const [admin, session] = randomAnonymousAccountAndSessionID();
|
||||
const node = new LocalNode(admin, session, Crypto);
|
||||
|
||||
const { nodeToServerPeer, serverToNodePeer, messages, addServerPeer } =
|
||||
connectNodeToSyncServer(node, opts.connected);
|
||||
|
||||
return { node, nodeToServerPeer, serverToNodePeer, messages, addServerPeer };
|
||||
}
|
||||
|
||||
export async function createConnectedTestNode(opts = { connected: true }) {
|
||||
if (!syncServer.current) {
|
||||
throw new Error("Sync server not initialized");
|
||||
}
|
||||
|
||||
const ctx = await LocalNode.withNewlyCreatedAccount({
|
||||
peersToLoadFrom: [],
|
||||
crypto: Crypto,
|
||||
creationProps: { name: "Client" },
|
||||
});
|
||||
|
||||
const { nodeToServerPeer, serverToNodePeer, messages, addServerPeer } =
|
||||
connectNodeToSyncServer(ctx.node, opts.connected);
|
||||
|
||||
return {
|
||||
node: ctx.node,
|
||||
accountID: ctx.accountID,
|
||||
nodeToServerPeer,
|
||||
serverToNodePeer,
|
||||
messages,
|
||||
addServerPeer,
|
||||
};
|
||||
}
|
||||
|
||||
export function connectNodeToSyncServer(node: LocalNode, connected = true) {
|
||||
if (!syncServer.current) {
|
||||
throw new Error("Sync server not initialized");
|
||||
}
|
||||
|
||||
const [nodeToServerPeer, serverToNodePeer] = connectedPeers(
|
||||
syncServer.current.account.id,
|
||||
node.account.id,
|
||||
{
|
||||
peer1role: "server",
|
||||
peer2role: "client",
|
||||
},
|
||||
);
|
||||
|
||||
const messages: {
|
||||
from: "client" | "server";
|
||||
msg: SyncMessage;
|
||||
}[] = [];
|
||||
|
||||
const serverPush = serverToNodePeer.outgoing.push;
|
||||
serverToNodePeer.outgoing.push = (msg) => {
|
||||
messages.push({ from: "server", msg });
|
||||
return serverPush.call(serverToNodePeer.outgoing, msg);
|
||||
};
|
||||
|
||||
const clientPush = nodeToServerPeer.outgoing.push;
|
||||
nodeToServerPeer.outgoing.push = (msg) => {
|
||||
messages.push({ from: "client", msg });
|
||||
return clientPush.call(nodeToServerPeer.outgoing, msg);
|
||||
};
|
||||
|
||||
syncServer.current.syncManager.addPeer(serverToNodePeer);
|
||||
if (connected) {
|
||||
node.syncManager.addPeer(nodeToServerPeer);
|
||||
}
|
||||
|
||||
return {
|
||||
nodeToServerPeer,
|
||||
serverToNodePeer,
|
||||
messages,
|
||||
addServerPeer: () => node.syncManager.addPeer(nodeToServerPeer),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "jazz-browser-auth-clerk",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:0.9.19",
|
||||
"jazz-browser": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.21"
|
||||
"jazz-browser": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19"
|
||||
},
|
||||
"scripts": {
|
||||
"format-and-lint": "biome check .",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-browser-media-images",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"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.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-browser": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"pica": "^9.0.1",
|
||||
"typescript": "~5.6.2"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createJazzTestAccount, setActiveAccount } from "jazz-tools/testing";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createImage } from "../index.js";
|
||||
|
||||
beforeEach(async () => {
|
||||
const account = await createJazzTestAccount();
|
||||
setActiveAccount(account);
|
||||
});
|
||||
|
||||
vi.mock("pica", () => {
|
||||
return {
|
||||
default: vi.fn().mockImplementation(() => ({
|
||||
resize: vi.fn().mockResolvedValue({}),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
const originalWidth = 400;
|
||||
const originalHeight = 300;
|
||||
|
||||
// Mock ImageBlobReduce
|
||||
vi.mock("image-blob-reduce", () => {
|
||||
return {
|
||||
default: vi.fn().mockImplementation(() => ({
|
||||
toCanvas: vi.fn().mockImplementation(async () => ({
|
||||
toDataURL: () => "data:image/png;base64,mockedBase64Data",
|
||||
})),
|
||||
toBlob: vi.fn().mockImplementation(async (blob, { max }) => {
|
||||
// Return a new blob with mock dimensions based on max size
|
||||
return new Blob(["reduced-image-data"], { type: "image/jpeg" });
|
||||
}),
|
||||
after: vi.fn().mockImplementation((event, callback) => {
|
||||
// Simulate the _blob_to_image callback with mock dimensions
|
||||
callback({
|
||||
image: { width: originalWidth, height: originalHeight },
|
||||
orientation: 1,
|
||||
});
|
||||
}),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
describe("createImage", () => {
|
||||
it("should create an image definition with correct dimensions", async () => {
|
||||
// Create a test blob that simulates a 400x300 image
|
||||
const blob = new Blob(["fake-image-data"], { type: "image/jpeg" });
|
||||
Object.defineProperty(blob, "size", { value: 1024 * 50 }); // 50KB
|
||||
|
||||
const imageDefinition = await createImage(blob);
|
||||
|
||||
expect(imageDefinition.originalSize).toEqual([
|
||||
originalWidth,
|
||||
originalHeight,
|
||||
]);
|
||||
expect(imageDefinition.placeholderDataURL).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,5 @@
|
||||
# jazz-browser
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-browser",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
@@ -10,7 +10,7 @@
|
||||
"cojson": "workspace:0.9.19",
|
||||
"cojson-storage-indexeddb": "workspace:0.9.19",
|
||||
"cojson-transport-ws": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"typescript": "~5.6.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-inspector
|
||||
|
||||
## 0.9.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react-core@0.9.21
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react-core@0.9.20
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
{
|
||||
"name": "jazz-inspector",
|
||||
"version": "0.9.22",
|
||||
"version": "0.9.20",
|
||||
"type": "module",
|
||||
"main": "./dist/app.js",
|
||||
"types": "./dist/app.d.ts",
|
||||
"files": [
|
||||
"dist/**",
|
||||
"src"
|
||||
],
|
||||
"files": ["dist/**", "src"],
|
||||
"scripts": {
|
||||
"dev": "vite build --watch",
|
||||
"build": "rm -rf ./dist && tsc --sourceMap --outDir dist",
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
# jazz-autosub
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
"types": "src/index.ts",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:0.9.19",
|
||||
"cojson-transport-ws": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser-auth-clerk@0.9.21
|
||||
- jazz-react@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser-auth-clerk@0.9.20
|
||||
- jazz-react@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "jazz-react-auth-clerk",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.tsx",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:0.9.19",
|
||||
"jazz-browser-auth-clerk": "workspace:0.9.21",
|
||||
"jazz-react": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.21"
|
||||
"jazz-browser-auth-clerk": "workspace:0.9.19",
|
||||
"jazz-react": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.2.0"
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
# jazz-react-core
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
|
||||
## 0.8.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-core",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -30,7 +30,7 @@ export function useCoState<V extends CoValue, D>(
|
||||
Schema: CoValueClass<V>,
|
||||
id: ID<V> | undefined,
|
||||
depth: D & DepthsIn<V> = [] as D & DepthsIn<V>,
|
||||
): DeeplyLoaded<V, D> | undefined {
|
||||
): DeeplyLoaded<V, D> | undefined | null {
|
||||
const context = useJazzContext();
|
||||
|
||||
const [observable] = React.useState(() =>
|
||||
@@ -39,14 +39,19 @@ export function useCoState<V extends CoValue, D>(
|
||||
}),
|
||||
);
|
||||
|
||||
const value = React.useSyncExternalStore<DeeplyLoaded<V, D> | undefined>(
|
||||
const value = React.useSyncExternalStore<
|
||||
DeeplyLoaded<V, D> | undefined | null
|
||||
>(
|
||||
React.useCallback(
|
||||
(callback) => {
|
||||
if (!id) return () => {};
|
||||
|
||||
const agent = "me" in context ? context.me : context.guest;
|
||||
|
||||
return observable.subscribe(Schema, id, agent, depth, callback);
|
||||
return observable.subscribe(Schema, id, agent, depth, callback, () => {
|
||||
console.log("unavailable");
|
||||
callback();
|
||||
});
|
||||
},
|
||||
[Schema, id, context],
|
||||
),
|
||||
@@ -54,6 +59,8 @@ export function useCoState<V extends CoValue, D>(
|
||||
() => observable.getCurrentValue(),
|
||||
);
|
||||
|
||||
console.log("value", value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -64,10 +71,10 @@ export function createUseAccountHooks<Acc extends Account>() {
|
||||
};
|
||||
function useAccount<D extends DepthsIn<Acc>>(
|
||||
depth: D,
|
||||
): { me: DeeplyLoaded<Acc, D> | undefined; logOut: () => void };
|
||||
): { me: DeeplyLoaded<Acc, D> | undefined | null; logOut: () => void };
|
||||
function useAccount<D extends DepthsIn<Acc>>(
|
||||
depth?: D,
|
||||
): { me: Acc | DeeplyLoaded<Acc, D> | undefined; logOut: () => void } {
|
||||
): { me: Acc | DeeplyLoaded<Acc, D> | undefined | null; logOut: () => void } {
|
||||
const context = useJazzContext<Acc>();
|
||||
|
||||
if (!("me" in context)) {
|
||||
@@ -89,10 +96,12 @@ export function createUseAccountHooks<Acc extends Account>() {
|
||||
};
|
||||
function useAccountOrGuest<D extends DepthsIn<Acc>>(
|
||||
depth: D,
|
||||
): { me: DeeplyLoaded<Acc, D> | undefined | AnonymousJazzAgent };
|
||||
): { me: DeeplyLoaded<Acc, D> | undefined | null | AnonymousJazzAgent };
|
||||
function useAccountOrGuest<D extends DepthsIn<Acc>>(
|
||||
depth?: D,
|
||||
): { me: Acc | DeeplyLoaded<Acc, D> | undefined | AnonymousJazzAgent } {
|
||||
): {
|
||||
me: Acc | DeeplyLoaded<Acc, D> | undefined | null | AnonymousJazzAgent;
|
||||
} {
|
||||
const context = useJazzContext<Acc>();
|
||||
|
||||
const contextMe = "me" in context ? context.me : undefined;
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { cojsonInternals } from "cojson";
|
||||
import { CoMap, co } from "jazz-tools";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { useCoState } from "../index.js";
|
||||
import { createJazzTestAccount } from "../testing.js";
|
||||
import { act, renderHook } from "./testUtils.js";
|
||||
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
||||
import { act, renderHook, waitFor } from "./testUtils.js";
|
||||
|
||||
beforeEach(async () => {
|
||||
await setupJazzTestSync();
|
||||
|
||||
await createJazzTestAccount({
|
||||
isCurrentActiveAccount: true,
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cojsonInternals.CO_VALUE_LOADING_CONFIG.MAX_RETRIES = 1;
|
||||
cojsonInternals.CO_VALUE_LOADING_CONFIG.TIMEOUT = 1;
|
||||
});
|
||||
|
||||
describe("useCoState", () => {
|
||||
it("should return the correct value", async () => {
|
||||
@@ -116,4 +130,31 @@ describe("useCoState", () => {
|
||||
expect(result.current?.value).toBe("123");
|
||||
expect(result.current?.nested?.value).toBe("456");
|
||||
});
|
||||
|
||||
it("should return null if the coValue is not found", async () => {
|
||||
class TestMap extends CoMap {
|
||||
value = co.string;
|
||||
}
|
||||
|
||||
const map = TestMap.create({
|
||||
value: "123",
|
||||
});
|
||||
|
||||
const account = await createJazzTestAccount({
|
||||
isCurrentActiveAccount: true,
|
||||
});
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useCoState(TestMap, (map.id + "123") as any, {}),
|
||||
{
|
||||
account,
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-react-native-auth-clerk
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react-native@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react-native@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-native-auth-clerk",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
# jazz-browser-media-images
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-native-media-images",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-browser
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-react-core@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-react-core@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-native",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# jazz-react
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
- jazz-react-core@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
- jazz-react-core@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
@@ -18,8 +18,8 @@
|
||||
"dependencies": {
|
||||
"@scure/bip39": "^1.3.0",
|
||||
"cojson": "workspace:0.9.19",
|
||||
"jazz-browser": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-browser": "workspace:0.9.19",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"jazz-react-core": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
# jazz-run
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"bin": "./dist/index.js",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"exports": {
|
||||
"./startSyncServer": {
|
||||
"import": "./dist/startSyncServer.js",
|
||||
@@ -32,7 +32,7 @@
|
||||
"cojson-storage-sqlite": "workspace:0.9.19",
|
||||
"cojson-transport-ws": "workspace:0.9.19",
|
||||
"effect": "^3.6.5",
|
||||
"jazz-tools": "workspace:0.9.21",
|
||||
"jazz-tools": "workspace:0.9.19",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# jazz-svelte
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1be017d]
|
||||
- jazz-tools@0.9.21
|
||||
- jazz-browser@0.9.21
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b01cc1f]
|
||||
- jazz-tools@0.9.20
|
||||
- jazz-browser@0.9.20
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-svelte",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build && npm run package",
|
||||
|
||||
@@ -47,7 +47,7 @@ export type RegisteredAccount = Register extends { Account: infer Acc }
|
||||
export function useAccount(): { me: RegisteredAccount; logOut: () => void };
|
||||
export function useAccount<D extends DepthsIn<RegisteredAccount>>(
|
||||
depth: D
|
||||
): { me: DeeplyLoaded<RegisteredAccount, D> | undefined; logOut: () => void };
|
||||
): { me: DeeplyLoaded<RegisteredAccount, D> | undefined | null; logOut: () => void };
|
||||
/**
|
||||
* Use the current account with a optional depth.
|
||||
* @param depth - The depth.
|
||||
@@ -55,7 +55,7 @@ export function useAccount<D extends DepthsIn<RegisteredAccount>>(
|
||||
*/
|
||||
export function useAccount<D extends DepthsIn<RegisteredAccount>>(
|
||||
depth?: D
|
||||
): { me: RegisteredAccount | DeeplyLoaded<RegisteredAccount, D> | undefined; logOut: () => void } {
|
||||
): { me: RegisteredAccount | DeeplyLoaded<RegisteredAccount, D> | undefined | null; logOut: () => void } {
|
||||
const ctx = getJazzContext<RegisteredAccount>();
|
||||
if (!ctx?.current) {
|
||||
throw new Error('useAccount must be used within a JazzProvider');
|
||||
@@ -98,7 +98,7 @@ export function useAccount<D extends DepthsIn<RegisteredAccount>>(
|
||||
export function useAccountOrGuest(): { me: RegisteredAccount | AnonymousJazzAgent };
|
||||
export function useAccountOrGuest<D extends DepthsIn<RegisteredAccount>>(
|
||||
depth: D
|
||||
): { me: DeeplyLoaded<RegisteredAccount, D> | undefined | AnonymousJazzAgent };
|
||||
): { me: DeeplyLoaded<RegisteredAccount, D> | undefined | null | AnonymousJazzAgent };
|
||||
/**
|
||||
* Use the current account or guest with a optional depth.
|
||||
* @param depth - The depth.
|
||||
@@ -106,7 +106,7 @@ export function useAccountOrGuest<D extends DepthsIn<RegisteredAccount>>(
|
||||
*/
|
||||
export function useAccountOrGuest<D extends DepthsIn<RegisteredAccount>>(
|
||||
depth?: D
|
||||
): { me: RegisteredAccount | DeeplyLoaded<RegisteredAccount, D> | undefined | AnonymousJazzAgent } {
|
||||
): { me: RegisteredAccount | DeeplyLoaded<RegisteredAccount, D> | undefined | null | AnonymousJazzAgent } {
|
||||
const ctx = getJazzContext<RegisteredAccount>();
|
||||
|
||||
if (!ctx?.current) {
|
||||
@@ -153,12 +153,12 @@ export function useCoState<V extends CoValue, D extends DepthsIn<V> = []>(
|
||||
id: ID<V> | undefined,
|
||||
depth: D = [] as D
|
||||
): {
|
||||
current?: DeeplyLoaded<V, D>;
|
||||
current?: DeeplyLoaded<V, D> | null;
|
||||
} {
|
||||
const ctx = getJazzContext<RegisteredAccount>();
|
||||
|
||||
// Create state and a stable observable
|
||||
let state = $state.raw<DeeplyLoaded<V, D> | undefined>(undefined);
|
||||
let state = $state.raw<DeeplyLoaded<V, D> | undefined | null>(undefined);
|
||||
|
||||
// Effect to handle subscription
|
||||
$effect(() => {
|
||||
@@ -178,7 +178,9 @@ export function useCoState<V extends CoValue, D extends DepthsIn<V> = []>(
|
||||
// Get current value from our stable observable
|
||||
state = value;
|
||||
},
|
||||
undefined,
|
||||
() => {
|
||||
state = null;
|
||||
},
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
import { render } from "@testing-library/svelte";
|
||||
import { Account, CoMap, co, type CoValue, type CoValueClass, type DepthsIn } from "jazz-tools";
|
||||
import { render, waitFor } from "@testing-library/svelte";
|
||||
import { Account, CoMap, co, cojsonInternals, type CoValue, type CoValueClass, type DepthsIn } from "jazz-tools";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createJazzTestAccount, createJazzTestContext } from "../testing.js";
|
||||
import { createJazzTestAccount, createJazzTestContext, setupJazzTestSync } from "../testing.js";
|
||||
import UseCoState from "./components/useCoState.svelte";
|
||||
|
||||
beforeEach(async () => {
|
||||
await setupJazzTestSync();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cojsonInternals.CO_VALUE_LOADING_CONFIG.MAX_RETRIES = 1;
|
||||
cojsonInternals.CO_VALUE_LOADING_CONFIG.TIMEOUT = 1;
|
||||
});
|
||||
|
||||
function setup<T extends CoValue>(options: {
|
||||
account: Account;
|
||||
map: T;
|
||||
@@ -148,4 +157,34 @@ describe("useCoState", () => {
|
||||
expect(result.current?.value).toBe("123");
|
||||
expect(result.current?.nested?.value).toBe("456");
|
||||
});
|
||||
});
|
||||
|
||||
it("should return null if the coValue is not found", async () => {
|
||||
class TestMap extends CoMap {
|
||||
value = co.string;
|
||||
}
|
||||
|
||||
const unreachableAccount = await createJazzTestAccount({
|
||||
});
|
||||
|
||||
const map = TestMap.create({
|
||||
value: "123",
|
||||
}, unreachableAccount);
|
||||
|
||||
unreachableAccount._raw.core.node.gracefulShutdown();
|
||||
|
||||
const account = await createJazzTestAccount({
|
||||
isCurrentActiveAccount: true,
|
||||
});
|
||||
|
||||
const result = setup({
|
||||
account,
|
||||
map,
|
||||
});
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
# jazz-tools
|
||||
|
||||
## 0.9.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1be017d: Account.isMe now indicates whether an account is the currently active account. To check if an account is the owner of the local node use isLocalNodeOwner instead.
|
||||
|
||||
## 0.9.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b01cc1f: Switches from symbols to prefixes strings for private properties
|
||||
|
||||
## 0.9.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.19",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:*"
|
||||
},
|
||||
|
||||
@@ -73,7 +73,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
return this as Account;
|
||||
}
|
||||
get _loadedAs(): Account | AnonymousJazzAgent {
|
||||
if (this.isLocalNodeOwner) return this;
|
||||
if (this.isMe) return this;
|
||||
|
||||
const rawAccount = this._raw.core.node.account;
|
||||
|
||||
@@ -120,17 +120,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this account is the currently active account.
|
||||
*/
|
||||
get isMe() {
|
||||
return activeAccountContext.get().id === this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this account is the owner of the local node.
|
||||
*/
|
||||
isLocalNodeOwner: boolean;
|
||||
isMe: boolean;
|
||||
sessionID: SessionID | undefined;
|
||||
|
||||
constructor(options: { fromRaw: RawAccount | RawControlledAccount }) {
|
||||
@@ -138,8 +128,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
if (!("fromRaw" in options)) {
|
||||
throw new Error("Can only construct account from raw or with .create()");
|
||||
}
|
||||
this.isLocalNodeOwner =
|
||||
options.fromRaw.id == options.fromRaw.core.node.account.id;
|
||||
this.isMe = options.fromRaw.id == options.fromRaw.core.node.account.id;
|
||||
|
||||
Object.defineProperties(this, {
|
||||
id: {
|
||||
@@ -150,7 +139,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
_type: { value: "Account", enumerable: false },
|
||||
});
|
||||
|
||||
if (this.isLocalNodeOwner) {
|
||||
if (this.isMe) {
|
||||
this.sessionID = options.fromRaw.core.node.currentSessionID;
|
||||
}
|
||||
|
||||
@@ -158,7 +147,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
}
|
||||
|
||||
myRole(): "admin" | undefined {
|
||||
if (this.isLocalNodeOwner) {
|
||||
if (this.isMe) {
|
||||
return "admin";
|
||||
}
|
||||
}
|
||||
@@ -168,7 +157,7 @@ export class Account extends CoValueBase implements CoValue {
|
||||
inviteSecret: InviteSecret,
|
||||
coValueClass: CoValueClass<V>,
|
||||
) {
|
||||
if (!this.isLocalNodeOwner) {
|
||||
if (!this.isMe) {
|
||||
throw new Error("Only a controlled account can accept invites");
|
||||
}
|
||||
|
||||
@@ -444,11 +433,11 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
||||
|
||||
/** @category Identity & Permissions */
|
||||
export function isControlledAccount(account: Account): account is Account & {
|
||||
isLocalNodeOwner: true;
|
||||
isMe: true;
|
||||
sessionID: SessionID;
|
||||
_raw: RawControlledAccount;
|
||||
} {
|
||||
return account.isLocalNodeOwner;
|
||||
return account.isMe;
|
||||
}
|
||||
|
||||
export type AccountClass<Acc extends Account> = CoValueClass<Acc> & {
|
||||
|
||||
@@ -708,29 +708,6 @@ export class FileStream extends CoValueBase implements CoValue {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new empty `FileStream` instance.
|
||||
*
|
||||
* @param options - Configuration options for the new FileStream
|
||||
* @param options.owner - The Account or Group that will own this FileStream and control access rights
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create owned by an account
|
||||
* const stream = FileStream.create({ owner: myAccount });
|
||||
*
|
||||
* // Create owned by a group
|
||||
* const stream = FileStream.create({ owner: teamGroup });
|
||||
*
|
||||
* // Create with implicit owner
|
||||
* const stream = FileStream.create(myAccount);
|
||||
* ```
|
||||
*
|
||||
* @remarks
|
||||
* For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
|
||||
*
|
||||
* @category Creation
|
||||
*/
|
||||
static create<S extends FileStream>(
|
||||
this: CoValueClass<S>,
|
||||
options?: { owner?: Account | Group } | Account | Group,
|
||||
|
||||
@@ -28,7 +28,7 @@ export type InboxRoot = RawCoMap<{
|
||||
}>;
|
||||
|
||||
export function createInboxRoot(account: Account) {
|
||||
if (!account.isLocalNodeOwner) {
|
||||
if (!account.isMe) {
|
||||
throw new Error("Account is not controlled");
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ async function acceptInvite(invite: string, account?: Account) {
|
||||
throw new Error("Invalid inbox ticket");
|
||||
}
|
||||
|
||||
if (!account.isLocalNodeOwner) {
|
||||
if (!account.isMe) {
|
||||
throw new Error("Account is not controlled");
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user